Skip to content

fix(ai-accounts): use per-step usage_update and cap replay transcript for Antigravity ACP - #294

Merged
neolectron merged 3 commits into
astahmer:mainfrom
OzakIOne:fix/antigravity-usage-and-compaction
Nov 24, 2026
Merged

neolectron merged 3 commits into
astahmer:mainfrom
OzakIOne:fix/antigravity-usage-and-compaction

Conversation

@OzakIOne

@OzakIOne OzakIOne commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes two compounding bugs in AntigravityAcpSessions (plugins/@dshfiles/ai-accounts/src/antigravity-acp.ts) that caused long Antigravity (agy acp) sessions to hit false CONTEXT_WINDOW_EXCEEDED errors at 1.5M–2.9M reported tokens and fail every automatic and manual compaction with summarization produced no text summary content:

  1. Cumulative multi-step result.usage triggered false CONTEXT_WINDOW_EXCEEDED:

    • Inside a multi-step tool-calling turn, agy acp emits per-step usage_update notifications ({ used, size }), while the final session/prompt result.usage sums tokens across every LLM step in that prompt (e.g. 40 steps × ~73k = 2.92M tokens).
    • Previously antigravity-acp.ts ignored usage_update (leaving every toolUse step at 0 tokens) and copied the cumulative result.usage into the final step's output.usage. pi-ai's isContextOverflow saw input + cacheRead > 1_048_576 and converted the completed turn into CONTEXT_WINDOW_EXCEEDED.
    • Now antigravity-acp.ts listens to usage_update, reports live per-step used tokens on toolUse steps, and uses the latest usage_update.used instead of cumulative result.usage whenever the prompt spanned multiple steps.
    • The latest used value is kept on the session, not on the DSH step that received it, so a final step whose LLM call sends no fresh usage_update reports the last known context size instead of falling back to the cumulative usage. Cumulative result.usage is used only when agy sent no usage_update during the whole prompt.
  2. Unbounded transcript replay exceeded agy acp's ~192 KB single-prompt limit and dropped the compaction instruction:

    • agy acp hard-truncates a single session/prompt past ~192 KB (<truncated N bytes>), wiping out trailing prompt blocks.
    • During compaction (and long-thread process restarts), CliBridge.renderTranscript(earlier) easily exceeded 192 KB, so agy truncated away the trailing COMPACTION_INSTRUCTION block. Seeing a truncated coding transcript with DSH's MCP tools attached, the model called a tool (toolUse) with no text, causing @deepseek-ai/dsh-compaction-basic to fail with summarization produced no text summary content.
    • Now attach() budgets the rendered replay transcript (MAX_PROMPT_BYTES = 160_000 minus the trailing prompt blocks), keeping head (25%) + omission marker + tail (75%) on UTF-8 byte boundaries so trailing instructions/messages are never truncated by agy.
    • The budget counts image blocks too, and when the pending prompt leaves no budget the omission marker is still sent so the model knows earlier history was dropped.

Not covered here

Tracked in #296: the replay cap keeps only part of a long history, a compaction request appears to share and stop the conversation's own agy process, and compaction requests still offer DSH's tools to the model.

Verification

  • pnpm exec oxlint --config .oxlintrc.json plugins/@dshfiles/ai-accounts/src/antigravity-acp.ts plugins/@dshfiles/ai-accounts/src/antigravity-acp.test.ts — 0 warnings, 0 errors
  • pnpm exec oxfmt --check --config .oxfmtrc.json plugins/@dshfiles/ai-accounts/src/antigravity-acp.ts plugins/@dshfiles/ai-accounts/src/antigravity-acp.test.ts — clean
  • pnpm --dir plugins/@dshfiles/ai-accounts run typecheck — 0 errors
  • pnpm --dir plugins/@dshfiles/ai-accounts exec vitest run src/antigravity-acp.test.ts — 15/15 passed (including 3 new regression tests: per-step usage_update, a final step with no fresh usage_update, and replay transcript capping)
  • pnpm exec turbo run typecheck test --filter=@dshfiles/ai-accounts — 38/38 tasks successful

The latest usage_update now lives on the session instead of the DSH step
that received it. A final step whose LLM call sends no fresh usage_update
reports the last known context size instead of falling back to the
cumulative prompt usage that triggered false CONTEXT_WINDOW_EXCEEDED.

The replay budget also counts image blocks, and a pending prompt that
leaves no budget keeps the omission marker so the model knows earlier
history was dropped.
Resolves the conflict with astahmer#295: both sides appended tests to
antigravity-acp.test.ts, so both blocks are kept.
@neolectron
neolectron merged commit 3113cc3 into astahmer:main Nov 24, 2026
10 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants