Claude accounts: route the request with the chat's native session id
The account requests carry the chat in a claude_account body, which the multi-machine gateway neither routed by nor stripped of its chat@ prefix, so the server refused them as 'a valid chat session id is required'. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,3 +20,8 @@ String federatedChatId(String server, String native) =>
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Whether a request field is a chat-scoped body whose `session_id` names a
|
||||
/// chat: every `chat_*` body, plus the chat's Claude account requests.
|
||||
bool isChatScopedField(String key) =>
|
||||
key.startsWith('chat_') || key == 'claude_account';
|
||||
|
||||
@@ -62,7 +62,7 @@ class ChatServerGateway implements ApiGateway, EndpointGateway {
|
||||
for (final entry in fields.entries)
|
||||
entry.key: entry.key == 'attention_acks' && entry.value is Map
|
||||
? _acks(entry.value as Map, incoming: false)
|
||||
: entry.key.startsWith('chat_') && entry.value is Map
|
||||
: isChatScopedField(entry.key) && entry.value is Map
|
||||
? _owner(entry.value as Map, incoming: false)
|
||||
: entry.value,
|
||||
};
|
||||
|
||||
@@ -136,7 +136,7 @@ class FederatedChatGateway implements ApiGateway {
|
||||
}
|
||||
final ids = <String>{};
|
||||
for (final entry in fields.entries) {
|
||||
if (entry.key.startsWith('chat_') && entry.value is Map) {
|
||||
if (isChatScopedField(entry.key) && entry.value is Map) {
|
||||
final session = (entry.value as Map)['session_id'];
|
||||
if (session is String) {
|
||||
if (session.startsWith('chat@') &&
|
||||
|
||||
@@ -336,4 +336,33 @@ void main() {
|
||||
await machine.events.close();
|
||||
},
|
||||
);
|
||||
|
||||
test('a chat\'s Claude account request reaches its own machine with the '
|
||||
'native session id', () async {
|
||||
final a = Machine(), b = Machine();
|
||||
final sources = {
|
||||
'a': ChatServerGateway(server('a'), a),
|
||||
'b': ChatServerGateway(server('b'), b),
|
||||
};
|
||||
final all = FederatedChatGateway(
|
||||
() => sources,
|
||||
() => 'a',
|
||||
const Stream.empty(),
|
||||
);
|
||||
for (final type in ['claude_accounts', 'claude_account_use']) {
|
||||
await all.call(type, {
|
||||
'claude_account': {
|
||||
'session_id': federatedChatId('b', 'collision'),
|
||||
'name': 'second',
|
||||
},
|
||||
});
|
||||
final (sent, fields) = b.calls.last;
|
||||
expect(sent, type);
|
||||
expect(fields['claude_account'], {
|
||||
'session_id': 'collision',
|
||||
'name': 'second',
|
||||
});
|
||||
}
|
||||
expect(a.calls.where((c) => c.$1.startsWith('claude_')), isEmpty);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user