feat(compact): prune tool results before summarization (round 1)

This commit is contained in:
Hypatia May
2026-07-16 18:02:15 +08:00
parent 231aeabe55
commit ce96104a77
42 changed files with 1093 additions and 52 deletions

View File

@@ -232,6 +232,17 @@ function validateEvent(trace: SessionTrace, event: SessionEvent): SessionTraceTr
break
}
case 'tool/result': {
// A replacement rewrites an already-executed result whose recorded
// turn/step can be closed. Surface provenance above validates the rewrite;
// only fresh appends consume an open step's pending call.
if (se.surfaceOp !== undefined && se.surfaceOp !== 'append') {
if (trace.openTurn === null) {
throw new InvariantError(
'tool/result surface replacement appended outside any open turn',
)
}
break
}
requireOpenStep(trace, 'tool/result', event.data.turn, event.data.step)
// A result needs a prior matching call in the same step. (The converse
// does NOT hold: a call may have no result — a throwing tool-execution