You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix context accounting, terminal hangs, and sub-agent workspaces - #7
resolve compaction limits from active-model metadata and include tool schemas in request-size estimates
normalise per-call context size by provider instead of double-counting cached prompt tokens
preserve cache-read/write counters separately for billing and analytics
prevent persistent terminal sessions from inheriting non-POSIX shells such as fish
reset dashboard activity timing per tool/turn state and make Stop interrupt the backend
inherit the parent project for background workers and honour isolated worktrees
add regression coverage for context/cache semantics, compaction estimation, shell completion, and sub-agent workspace inheritance/isolation
Reproductions
Cached context gauge
In session ses_52aed4a75b7997bc6d6d, an OpenAI-compatible usage record reported input_tokens=145878 and cached_tokens=145408. OpenAI defines cached tokens as a subset of prompt tokens, but the gauge added both and showed roughly 279k/256k (100%). The real context was about 145.9k/256k (~57%). Provider adapters now expose a normalised context size: OpenAI/Gemini use total prompt tokens, while Anthropic includes its separately reported cache read/write tokens.
Terminal hang
In session ses_206f9da8, $SHELL=/bin/fish rejected the POSIX $? completion sentinel, so completed commands waited until the 300-second timeout.
Background sub-agent workspace
In parent session ses_52aed4a75b7997bc6d6d, task task_e5b480030e8ab5c79713 created child ses_73594af85e6d0c9e0274 in the global Antares workspace instead of /home/nvdorman/captcha-solver, making the first file tools fail as outside the workspace. Background delegation now shares the synchronous workspace/isolation path.
Verification
go test ./internal/llm ./internal/agent
go test ./internal/agent ./internal/worktree ./internal/tools ./internal/server
Merged — thank you, @nvdorman. This is a well-reasoned fix with real reproductions and solid test coverage, and I reviewed it carefully before integrating.
The per-provider context normalization is exactly right: OpenAI/Gemini/Codex report cached tokens as a subset of the prompt (so they must not be added), while Anthropic reports cache read/creation separately (so they must be summed) — verified across all four adapters. The ContextSize() helper with its conservative InputTokens fallback is the clean way to express that. The estimateRequestTokens change to count tool schemas is a genuinely good catch — large tool packs really can delay compaction until the provider rejects the request. The sub-agent workspace refactor also tightens write confinement on the isolation-failure path, and the fish-shell fix is spot on.
Integration note: this landed alongside a parallel in-progress fix for the same runaway-gauge symptom, so I merged by hand rather than a straight fast-forward. Your ContextSize() value won on the usage emit (it's the more provider-aware one), the tools parameter was kept on maybeCompact, and it was reconciled with a per-model context-window lookup (so e.g. glm-5.2 reports its real 1M window). Everything builds and the full llm/agent/tools/worktree/server suites pass. 🙏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reproductions
Cached context gauge
In session
ses_52aed4a75b7997bc6d6d, an OpenAI-compatible usage record reportedinput_tokens=145878andcached_tokens=145408. OpenAI defines cached tokens as a subset of prompt tokens, but the gauge added both and showed roughly279k/256k (100%). The real context was about145.9k/256k(~57%). Provider adapters now expose a normalised context size: OpenAI/Gemini use total prompt tokens, while Anthropic includes its separately reported cache read/write tokens.Terminal hang
In session
ses_206f9da8,$SHELL=/bin/fishrejected the POSIX$?completion sentinel, so completed commands waited until the 300-second timeout.Background sub-agent workspace
In parent session
ses_52aed4a75b7997bc6d6d, tasktask_e5b480030e8ab5c79713created childses_73594af85e6d0c9e0274in the global Antares workspace instead of/home/nvdorman/captcha-solver, making the first file tools fail as outside the workspace. Background delegation now shares the synchronous workspace/isolation path.Verification
go test ./internal/llm ./internal/agentgo test ./internal/agent ./internal/worktree ./internal/tools ./internal/servermake checkbun run build