fix(agent): preserve lifecycle recovery boundaries (PR3 round 2)

This commit is contained in:
Hypatia May
2026-07-15 17:43:33 +08:00
parent dffe51dbf0
commit d66c926d7a
6 changed files with 151 additions and 42 deletions
+2 -4
View File
@@ -650,7 +650,8 @@ async function runStep(
session, turn, step, message.content, assembler.usage, chunkSeqs,
)
// Tool execution stays sequential; recheck abort around each normalized result.
// Tool execution stays sequential; cancellation latches synthetic results for
// every remaining call while preserving one complete result batch.
const toolCalls = message.content.filter(block => block.type === 'tool-call')
// Buffer context until all results are appended to preserve call/result adjacency.
const pendingContext: HookContext[] = []
@@ -693,9 +694,6 @@ async function runStep(
if (signal.aborted) aborted = true
}
/* v8 ignore next -- signal.reason always set by cancellation or disposal. */
if (aborted) throw new Error(String(signal.reason ?? 'aborted'))
// Append buffered context after the complete result batch.
for (const context of pendingContext) {
agent.inject(context.content, { source: context.source })