Align context trimming to tool groups and take the N2 WP1 pins #86

Merged
weichen merged 1 commits from feature/n2-context-wp1 into main 2026-10-07 13:13:09 +00:00
Owner

Why: trimOldest dropped single messages without tool-pair awareness — after leading users were evicted it could orphan tool results or leave dangling calls (acceptance clause 2 product-side gap, N2 plan WP1).

What: oldestDrop → oldestDropRange — assistant-with-tool_calls and its contiguous tool results evict as one group; a leading orphan tool-result run evicts as one group; when a group would cross the current turn the trimmer stops (window may be slightly exceeded, pairing never broken). Tests pin both directions plus PrefixHash stability. Nested native/squad pins carry Agent-Native#25 (spill + cache contract).

Evidence: go test -count=1 ./... green; TestTrimOldestKeepsToolPairs asserts pairing across repeated trims.

Impact: trimming semantics change is intentional and documented in the card; no schema/API changes.

Refs: Agent-Native#25, Agent-Squad#29, Agent-System-Documents#42

Why: trimOldest dropped single messages without tool-pair awareness — after leading users were evicted it could orphan tool results or leave dangling calls (acceptance clause 2 product-side gap, N2 plan WP1). What: oldestDrop → oldestDropRange — assistant-with-tool_calls and its contiguous tool results evict as one group; a leading orphan tool-result run evicts as one group; when a group would cross the current turn the trimmer stops (window may be slightly exceeded, pairing never broken). Tests pin both directions plus PrefixHash stability. Nested native/squad pins carry Agent-Native#25 (spill + cache contract). Evidence: go test -count=1 ./... green; TestTrimOldestKeepsToolPairs asserts pairing across repeated trims. Impact: trimming semantics change is intentional and documented in the card; no schema/API changes. Refs: Agent-Native#25, Agent-Squad#29, Agent-System-Documents#42
weichen added 1 commit 2026-10-07 13:12:01 +00:00
Align context trimming to tool groups and take the N2 WP1 pins
ci / vet-and-test (pull_request) Successful in 44s
7acbefd60d
Why: trimOldest dropped single messages without tool-pair awareness —
after leading users were evicted it could orphan tool results or leave
dangling calls (acceptance clause 2's product-side gap).
Evidence: go test -count=1 ./... green; TestTrimOldestKeepsToolPairs
(pairing holds across repeated trims), TestTrimOldestDropsLeadingOrphanToolRun,
TestTrimOldestStopsWhenGroupCrossesCurrentTurn, TestPrefixHashStableForIdenticalInput;
native pins carry the spill and cache-contract work (Agent-Native#25).
Impact: trimming now evicts whole tool groups; the window may be
slightly exceeded when a group would cross the current turn — pairing
is never broken. Report.Truncations still records the count.
Refs: Agent-Native#25, Agent-Squad#29, N2 plan WP1
weichen merged commit 8858ca9b8a into main 2026-10-07 13:13:09 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weichen/Agent-System-Backend#86