reattach a refreshed browser to a running turn
Refreshing mid-turn appeared to kill the agent's output. It never did: the session survives a dropped socket, the agent keeps generating into it and keeps committing durable events, and `close` only detaches the socket and arms an hour-long idle timer. What broke was purely delivery — and the reconnect path that would have fixed it could not fire, because the browser came back having forgotten officer's session key. It lived in page state. The only id left was Claude's transcript uuid in the URL, and nothing accepted that. So accept it. `attach` carries the uuid, and the agent's on-disk session map — the single record relating the two — turns it back into the key everything else is written in terms of. The uuid now also goes out at `system.init` rather than only at `result`, which is what makes the first turn recoverable at all: until now a chat had no address until it had finished, and a long first turn is exactly the one worth reconnecting to. `sync:live` deliberately carries no messages. The harness writes its transcript as it goes, so the HTTP load on landing already supplies the past; sending the server's record of the same messages on top of it would duplicate them, and there is no shared id to reconcile the two by. Attach hands over the rest of the turn, the half-written paragraph the transcript cannot hold, and the session's cursor head — that last one so a *later* drop replays from the head instead of re-delivering the whole conversation from zero. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,27 @@ describe('createTurnStream', () => {
|
||||
expect(durable).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('the transcript id goes out live but is never persisted', () => {
|
||||
// Durable would put a second copy of the answer inside the question: the only way to replay this log
|
||||
// is to ask for it by the very id the event carries.
|
||||
const { all, durable, types } = run([{ type: 'session', claudeSessionId: 'claude-uuid-1' }]);
|
||||
expect(types).toEqual(['session:claude']);
|
||||
expect(all[0]!.msg).toEqual({ type: 'session:claude', claudeSessionId: 'claude-uuid-1' });
|
||||
expect(durable).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('the transcript id does not disturb an open delta buffer', () => {
|
||||
// It arrives at `system.init`, but a resumed turn can re-announce it mid-flight, and flushing there
|
||||
// would split one paragraph into two messages.
|
||||
const { durable } = run([
|
||||
{ type: 'delta', text: 'half ' },
|
||||
{ type: 'session', claudeSessionId: 'claude-uuid-1' },
|
||||
{ type: 'delta', text: 'a sentence' },
|
||||
{ type: 'result', cost: COST },
|
||||
]);
|
||||
expect(durable[0]).toEqual({ type: 'assistant:text', text: 'half a sentence' });
|
||||
});
|
||||
|
||||
test('an explicit text event wins over the deltas that produced it', () => {
|
||||
const { durable } = run([
|
||||
{ type: 'delta', text: 'par' },
|
||||
|
||||
Reference in New Issue
Block a user