fix(coding-agent): admit prompts using projected context after compaction

Merged
CO
11d ago
+341-36

Summary

Fixes #3137.

All pre-provider admission decisions, including timeout retry, use shared usage-provenance accounting. A compaction or context edit invalidates earlier usage; fresh usage uses cached canonical context without calling buildSessionProjection. When projection is necessary, the estimator caches it by branch identity. The existing first-response exemption is preserved.

This also repairs the virtual-model per-request projection regression reported by CI at eb1760eb71. System/tool prefix accounting remains out of scope and is tracked in #3159. Both previously resized owning-suite fixture files remain unchanged from base cbae378629.

Verification

Head: 8ec28a1ef5814c112e7b725a155646b22ee51937.

One GREEN run, --maxWorkers=2: 10 files passed, 148 tests passed, exit 0:

  • test/suite/virtual-models.test.ts
  • test/suite/regressions/3137-preprompt-projected-usage.test.ts
  • test/suite/regressions/3062-resume-gate-projected-usage.test.ts
  • test/suite/regressions/531-compaction-cooldown-admission.test.ts
  • test/suite/regressions/pre-prompt-compaction-no-continue.test.ts
  • test/suite/agent-session-compaction.test.ts
  • test/suite/regressions/compaction-generation-stale-revision.test.ts
  • test/suite/compaction-race.test.ts
  • test/suite/regressions/extension-command-immediate-dispatch.test.ts
  • test/suite/agent-session-boundaries.test.ts

The existing virtual-model test requires zero buildSessionProjection calls during its routed prompt. A new public prompt test after accepted compaction records projection calls by branch identity and verifies no repeated projection for an unchanged branch. Both pass. Only formatting of the estimator return expression changed after GREEN.

RED used the full current #3137 regression file with only agent-session.ts reverted to cbae378629. Tested/base source blobs matched: 462fa00f70eaabe39b6597931c0d0a27e6bf13f3. Result: 5 failed, 9 passed, exit 1. The 400k/500k extension-tail cases, context-edit case, and cache test's public compacted prompt failed with RequiredCompactionError. Timeout retry emitted unsuccessful auto_retry_end with the same compaction-threshold error. No private-method failures. The fix was restored before committing.

Scoped Biome, git diff --check, and changelog gate against cbae378629 passed. Final source blob: 0eb0b8cf33d7f172cdeeedc4004d6deeedfe0168. No dependency or lock changes.

Unverified

Full typecheck/build and live CLI QA were not run in this focused-test task. LSP initialization remains unavailable (valid TypeScript installation not found). CI at this new head and Opus review are not yet verified. No READY declaration or merge.