Skip to content

gut(session): remove vestigial contextTokens config and display denominator#2277

Merged
alexey-pelykh merged 2 commits intomainfrom
gut/remove-context-tokens-2133
Apr 11, 2026
Merged

gut(session): remove vestigial contextTokens config and display denominator#2277
alexey-pelykh merged 2 commits intomainfrom
gut/remove-context-tokens-2133

Conversation

@alexey-pelykh
Copy link
Copy Markdown

Summary

  • Remove contextTokens field from SessionEntry, AgentDefaultsConfig, Zod schema, and all downstream types (status, gateway, TUI, UI, native apps)
  • Delete DEFAULT_CONTEXT_TOKENS constant, lookupContextTokens stub, resolveContextTokens stub, and the contextTokensUsed resolution chain in agent-runner
  • Remove derived fields remainingTokens and percentUsed from SessionStatus and all consumers
  • Simplify token display from "45k/200k (22%)" to "45k used" across status output, sessions list, TUI, macOS app, and shared kit

Rationale

The contextTokens denominator defaulted to 200k regardless of actual runtime context window (Gemini has 1M, some Claude models have 1M). The lookup stubs were gutted in the RemoteClaw fork, making the resolution chain always fall through to hardcoded values. Removing the misleading percentage is better than displaying an inaccurate one.

Real token counting infrastructure (totalTokens, inputTokens, outputTokens, cacheRead, cacheWrite) is fully preserved.

Closes #2133

Test plan

  • pnpm check passes (format, typecheck, lint)
  • All 12,129 tests pass (1374/1375 test files — 1 pre-existing timeout in server.roles-allowlist-update.test.ts)
  • grep -r contextTokens src/ ui/ apps/ docs/ returns no matches
  • grep -r DEFAULT_CONTEXT_TOKENS returns no matches

🤖 Generated with Claude Code

@alexey-pelykh alexey-pelykh enabled auto-merge (squash) April 11, 2026 08:47
…inator (#2133)

Remove the `contextTokens` field, `DEFAULT_CONTEXT_TOKENS` constant,
`lookupContextTokens` stub, and all derived fields (`remainingTokens`,
`percentUsed`) across the entire codebase — types, schemas, agent runner,
session persistence, directive handling, status display, gateway, TUI, UI,
native apps (macOS/shared kit), agent tools, cron, and documentation.

The contextTokens denominator was a static config value (defaulting to 200k)
used to display misleading context window utilization percentages. The lookup
stubs were gutted, making the resolution chain fall through to hardcoded
values regardless of actual runtime context window size. Token display is
simplified from "45k/200k (22%)" to "45k used".

Real token counting infrastructure (totalTokens, inputTokens, outputTokens,
cacheRead, cacheWrite) is preserved — only the static denominator and
percentage display are removed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alexey-pelykh alexey-pelykh force-pushed the gut/remove-context-tokens-2133 branch from 92ff7a8 to ccf4849 Compare April 11, 2026 08:51
…from rebase

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alexey-pelykh alexey-pelykh merged commit f7e9156 into main Apr 11, 2026
10 checks passed
@alexey-pelykh alexey-pelykh deleted the gut/remove-context-tokens-2133 branch April 11, 2026 09:04
alexey-pelykh added a commit that referenced this pull request Apr 17, 2026
Ports 13 @test functions from upstream commit 061b825 ("macOS: add
chat model selector and persist thinking") that were skipped during
the fork sync in #2379. Issue #2381 states "9 tests" but the actual
v2026.3.8..v2026.3.11 cycle delta is 13 — verified via git log.

Ten model-selection tests cover: bootstrap, default patch, provider-
qualified disambiguation, provider-qualified slash IDs, stale patch
race, send-waits-for-patch, failed-latest replay, failed-latest
restore, session-switch late patch, cross-session replay isolation.

Three thinking-level tests cover: explicit level persistence, server-
provided levels outside menu, stale patch replay.

Decision on contextTokens: adapt tests to omit. Fork gutted the field
in #2277 — extending types would revert that deliberate decision.

Helper infrastructure ported: 14 private helpers (functions, actors,
classes). TestChatTransport extended with modelResponses + optional
hook params (backward-compatible) and new async query methods.
Existing 11 tests preserved verbatim.

Local compile blocked by pre-existing symbol references in
RemoteClawKit/GatewayChannel.swift (see #2388). Fork CI has no Swift
jobs so this state also pre-exists and is orthogonal to this change.

Closes #2381.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
alexey-pelykh added a commit that referenced this pull request Apr 26, 2026
…2583) (#2596)

Process Cat A cluster A2 of the v2026.3.22 upstream sync backlog: 35 fork
files under apps/macos/ requiring per-file disposition.

Disposition outcome:

| Action | Count |
|--------|------:|
| CHERRY-PICK applied (rebrand transform → fork content changes) | 27 |
| EXCLUDE-DIVERGENT (registered in hq/upstream/disposition.tsv) | 4 |
| Total | 31 issue-listed |
| Helper files imported (net-new upstream additions referenced by cluster cherry-picks) | 15 |
| PairingAlertSupport refresh (refactored upstream — fork's older version replaced) | 1 |

Issue body listed 31 CHERRY-PICK + 4 EXCLUDE-DIVERGENT = 35. After per-file
inspection, all 4 of the 4 EXCLUDE-DIVERGENT entries were pre-classified by
triage and were not reclassified (rate: 0% reclassification — within the
5-10% the issue body anticipated). The 27/31 CHERRY-PICK count reflects
upstream content that genuinely diverges; the remaining 4 of 31 were NOOP
(fork already in sync after rebrand transform).

EXCLUDE-DIVERGENT classifications (all 4):

- apps/macos/Sources/OpenClaw/ContextUsageBar.swift
- apps/macos/Sources/OpenClaw/SessionMenuLabelView.swift
- apps/macos/Sources/OpenClaw/SessionsSettings.swift
- apps/macos/Sources/OpenClaw/UsageMenuLabelView.swift

All four trace to fork commit f7e9156 — gut(session): remove vestigial
contextTokens config and display denominator (#2277). Upstream still
references the gutted contextTokens symbols.

Approach:

1. Read upstream@v2026.3.22 content via `git show v2026.3.22:{path}`.
2. Apply token-based rebrand transforms per hq/upstream/rebrand-tokens.tsv —
   `OpenClaw → RemoteClaw`, `openclaw → remoteclaw`, `OPENCLAW → REMOTECLAW`,
   `OPENCLAW_ → REMOTECLAW_`, `ai.openclaw → org.remoteclaw`,
   `com.openclaw → org.remoteclaw`, `~/.openclaw → ~/.remoteclaw`,
   `.openclaw → .remoteclaw`, `openclaw-mac → remoteclaw-mac`,
   `@openclaw/ → @remoteclaw/`, `github.com/openclaw/openclaw → github.com/remoteclaw/remoteclaw`,
   `openclaw/openclaw → remoteclaw/remoteclaw`, `openclaw.io|openclaw.ai → remoteclaw.com`.
3. Cross-class API audit detected upstream extracted helper logic into
   13 net-new Swift files (PlatformLabelFormatter, SettingsRefreshButton,
   GatewayPushSubscription, JSONObjectExtractionSupport, TextSummarySupport,
   SimpleTaskSupport, TrackingAreaSupport, MicRefreshSupport,
   AgentWorkspaceConfig, SystemSettingsURLSupport, PermissionMonitoringSupport,
   VoiceOverlayTextFormatting, VoiceWakeRecognitionDebugSupport) plus
   1 in RemoteClawMacCLI (CLIArgParsingSupport) and 1 in shared kit
   (CaptureRateLimits). All 15 imported with rebrand transforms applied —
   they're net-new upstream additions referenced by cluster cherry-picks
   (not in audit's rebrand-below-threshold cluster lists because audit
   only flagged renames, not additions).
4. PairingAlertSupport.swift was refactored upstream — fork's older
   46-line version is replaced with upstream's 277-line refactor (with
   rebrand transforms applied) so cherry-picked NodePairingApprovalPrompter
   compiles. Fork's prior content (PairingAlertHostWindow, endActiveAlert,
   requireAlertHostWindow) is preserved verbatim by upstream's superset.

Notes:

- PeekabooBridgeHostCoordinator cherry-pick adds compatibility code that
  creates symlinks for upstream's pre-rebrand brand directory names
  (clawdbot, clawdis, moltbot). For fresh fork users these are no-op
  ghost directories. Polish reviewer agreed this is acceptable as
  literal upstream-parity (fork users have no pre-rebrand state per
  CLAUDE.md "User state boundary"). Optional follow-up: gate symlink
  creation behind fileExists check.
- Fork CI does not build macOS (per CLAUDE.md). Local Xcode build and
  swift test NOT verified — same caveat as merged Wave 1 PR #2595.

Closes #2583.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

gut(session): remove vestigial contextTokens config and display denominator

1 participant