fix: resolve session race condition and follow-up turn output loss
Two bugs fixed: 1. agent-runner error path race condition: when agent process exited with error, the promise resolved immediately without waiting for outputChain, allowing a late wrappedOnOutput to re-persist a stale session ID after clearSession had already run. 2. follow-up turn state not resetting: when a follow-up IPC message joined an active run, turn-level flags (finalOutputSentToUser, sawNonProgressOutput) from the first turn prevented the last progress from being promoted to a final message. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -681,10 +681,15 @@ export async function runAgentProcess(
|
||||
},
|
||||
'Agent exited with error',
|
||||
);
|
||||
resolve({
|
||||
status: 'error',
|
||||
result: null,
|
||||
error: `Agent exited with code ${code}: ${stderr.slice(-200)}`,
|
||||
// Wait for any queued streamed-output handlers to finish so a late
|
||||
// newSessionId cannot be persisted after the caller clears a poisoned
|
||||
// session.
|
||||
outputChain.then(() => {
|
||||
resolve({
|
||||
status: 'error',
|
||||
result: null,
|
||||
error: `Agent exited with code ${code}: ${stderr.slice(-200)}`,
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user