Skip to content

Fix session context occupancy and profile account usage eligibility - #380

Merged
Tryanks merged 4 commits into
mainfrom
fix/usage-occupancy-quota
Sep 8, 2026
Merged

Tryanks merged 4 commits into
mainfrom
fix/usage-occupancy-quota

Conversation

@Tryanks

@Tryanks Tryanks commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Claude's context meter previously replaced request observations with completed-turn traffic, allowing a multi-request turn to appear to exceed its context window. Request-start usage was discarded, output-only deltas erased input/cache fields, and unknown values rendered as zero. Account quota rows also treated a compatible harness as proof that a custom endpoint supported the native vendor's subscription API.

This change keeps those concerns separate:

  • The Claude adapter merges cumulative streaming fields within a message ID, replaces request state at new IDs, ignores subagent context and duplicate result IDs, and reports turn traffic separately. The timeline alone accumulates Claude lifetime traffic, including restored history and a fresh adapter process.
  • The meter uses the latest main-request input/cache observation. Result aggregates cannot replace occupancy. Unknown, last-known, compacting and awaiting-observation states are explicit. Legacy persisted records without freshness remain unverified rather than relabeling a historical aggregate as current context.
  • Compaction retains its existing wire tag with optional lifecycle, trigger, pre/post-token, dropped-token and duration metadata. Older literal records remain readable. Completion invalidates occupancy until the next observation; post-compaction size is not treated as a fresh request measurement.
  • Resolved profiles own account-usage eligibility based on endpoint/auth configuration. Refresh, Settings and composer use the same decision. Unsupported configurations are omitted without hiding session usage; supported sign-in/network failures remain errors. Configuration and secret changes invalidate cached limits and reject stale in-flight results without finishing a newer probe.
  • Both locales and the UI design contract are updated. Long divider labels can wrap at narrow widths.

Fixes #367. Fixes #357.

Validation and evidence:

  • Red: cargo test -p agent --locked streaming_usage_keeps_request_scope_at_completion failed because a literal message start reporting 550 input/cache tokens emitted no usage event. Green after the fix; output-only deltas retain 550 while 4,001,200 processed tokens remain separate.
  • An additional red/green case proves that an output delta without a message-start in a new turn cannot reuse the preceding request identity or relabel last-known usage as current. The new turn now clears request identity before receiving any stream fields.
  • Red: cargo test -p tcode-core --locked resolved_custom_endpoint_is_not_a_native_account failed on the original harness-only filter. Green with resolved endpoint/auth eligibility; renaming the profile does not change support.
  • A timestamp-free history regression failed with 100 processed tokens instead of 120. Using the existing open-turn predicate prevents reopening a completed untimestamped turn; sparse completions also retain known capacity. The existing late-tool-transition timing test still protects against attributing a ghost tool to the next turn.
  • The production subprocess adapter → timeline → composer replay covers multiple requests, repeated message/result IDs, subagents, compaction, a deterministic interrupt, a fresh resumed adapter, persisted replay, duplicate completion, custom capacity and a legacy 4.1M record. Independent literal expectations verify lifetime traffic across all three replayed streams.
  • New isolated Claude Code 2.1.263 sessions supplied redacted live fixtures: request contexts 20,250 / 20,635 / 20,764 versus 62,084 turn traffic, and manual compaction from 19,555 to 2,948 tokens. Fixture provenance and redaction are documented in crates/agent/tests/fixtures/claude/USAGE.md.
  • The existing ignored live native account test was run explicitly: both Codex and Claude returned non-empty windows without an error. Supported temporary errors and sensitive-secret/probe races are covered deterministically.
  • Workspace formatting, Clippy with warnings denied, build and tests passed, as did dependency hygiene using the installed cargo-machete 0.9.2 executable directly. The local cargo machete subcommand incorrectly forwards its own name as a directory; no dependencies or installed tools were changed to bypass that invocation problem.

iOS simulator, Web and Android checks also passed with RUSTFLAGS='-D warnings'; Android used the installed CI-pinned NDK 27.1.12297006 via an explicit ANDROID_NDK_HOME. The initial default Android invocation failed only because that environment path was unset.

Final combined workspace formatting, Clippy, build and tests passed on c491be947, after rebasing onto branding PR #379. Dependency hygiene, iOS, Web and Android also passed on that exact head. The final presentation correction keeps known capacity visible even when occupancy has no measured percentage; the accumulation comment now names the timeline owner.

Actual GUI acceptance completed on an isolated app bundle built from c491be947 (distinct bundle ID, explicitly verified TCODE_DATA_DIR, copied binary protected from shared-target replacement). Normal1200px and approximately360px narrow layouts were reviewed in dark/light themes and English/Simplified Chinese. Current context500k/1m remained distinct from4m total traffic; legacy4.1m remained unmeasured Unknown/1m; last-known context showed updating; completed compaction retained known capacity with Unknown and no occupancy progress bar. Manual trigger and pre-compaction count remained readable, wrapping in narrow English. The custom endpoint kept session occupancy while omitting account quota. Settings omitted its row and retained the representative supported native-profile failure with its error message; composer retained localized Usage unavailable. Escape dismissal, focus, navigation and narrow Settings scrolling were exercised. No additional GUI defect was found.

GUI screenshots and the exact-head/binary provenance manifest are retained locally in /tmp/tcode-usage-evidence/GUI.md and its named PNG files for lead review; they are not uploaded as repository assets. Final command logs are in /tmp/tcode-usage-evidence/final-checks/, with workspace build in final-build.log. The isolated GUI process has been stopped and the desktop slot released.

All six hosted checks passed on c491be947e9921b1d39d186de1db9ffc9a5e7e84: scope planning, dependency hygiene, macOS, Linux, Windows, and mobile/Web. Final source, check logs, binary provenance and retained GUI screenshots were independently reviewed. CI run: https://github.com/Tryanks/tcode/actions/runs/34221832016.

The exact reporter's multi-million-token run and automatic compaction were not captured; constructed edge-case fixtures are labeled separately from the live evidence. No user session/profile was opened for the provider captures.

@Tryanks
Tryanks marked this pull request as ready for review September 8, 2026 11:51
@Tryanks
Tryanks merged commit ea2c186 into main Sep 8, 2026
6 checks passed
@Tryanks
Tryanks deleted the fix/usage-occupancy-quota branch September 8, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant