fix(app): scale MAX_CONTEXT_SIZE for 1M models + render alwaysShow before usage streams in#1271
Open
g0rdonL wants to merge 2 commits into
Open
fix(app): scale MAX_CONTEXT_SIZE for 1M models + render alwaysShow before usage streams in#1271g0rdonL wants to merge 2 commits into
g0rdonL wants to merge 2 commits into
Conversation
6d66056 to
f3e3862
Compare
Context-remaining indicator was hardcoded to 190K, so any session on a 1M-context Anthropic model (e.g. claude-opus-4-7[1m]) clamped to 0% within minutes and the toggle appeared broken. Plumb the assistant `model` field from the raw Claude API event through NormalizedMessage → reducer latestUsage → Session.latestUsage → AgentInput.usageData, then pick the limit dynamically: 950K for model ids matching `[1m]`, 190K otherwise. Closes slopus#910
The Always Show Context Size toggle wired through SessionView and AgentInput, but the indicator never appeared on Android sessions until the first assistant turn delivered a non-zero `contextSize`. The outer gate at the call site (`props.usageData?.contextSize ? ... : null`) short-circuited to null whenever `contextSize` was 0 or undefined, swallowing the alwaysShow signal that `getContextWarning` itself honors. Two failure modes this resolves: 1. Fresh session with no agent reply yet — `latestUsage` is undefined so the indicator never showed despite the toggle being on. 2. Sessions where the reducer reset `contextSize` to 0 on a session event (reducer.ts lines 324, 338) and no subsequent assistant message with usage arrived to repopulate it. Now the gate is `alwaysShow || contextSize`, and `getContextWarning` is called with `contextSize ?? 0`. On fresh always-show sessions the indicator renders as "100% remaining" until real usage arrives. Closes slopus#1274
f3e3862 to
266731c
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Two related fixes to the Always Show Context Size indicator in
AgentInput. Originally only #910; on rebase I traced #1274 to the same render path and added a one-line gate fix that pairs naturally with the model plumbing.Commit 1 — Closes #910 (scale MAX_CONTEXT_SIZE for 1M-context models)
claude-opus-4-7[1m]) clamped to 0% within minutes and the toggle appeared broken.modelfield from the raw Claude API event throughNormalizedMessage→ reducerlatestUsage→Session.latestUsage→AgentInput.usageData.AgentInputnow picks the limit dynamically viagetMaxContextSize(model): 950K for model ids matching[1m], 190K otherwise.Commit 2 — Closes #1274 (render alwaysShow before usage streams in)
nullwheneverusageData.contextSizewas0orundefined:getContextWarningitself honors (line 311). Two failure modes this addresses on Android (and silently on iOS/web — same render path):latestUsageis undefined, indicator never showed.contextSizeto 0 on session events (reducer.ts:324, 338) with no subsequent assistant message carrying usage.alwaysShow || contextSize, andgetContextWarningreceivescontextSize ?? 0. On fresh always-show sessions the indicator renders "100% remaining" until real usage arrives.Files changed
sources/sync/typesRaw.ts— capturemessage.modelwhen normalizing assistant messages; addmodel?: stringtoNormalizedMessage.sources/sync/reducer/reducer.ts— threadmodelthroughprocessUsageData/ReducerState.latestUsage/ReducerResult.usage.sources/sync/storageTypes.ts— addmodel?: stringto persistedSession.latestUsage.sources/-session/SessionView.tsx— threadmodelinto the memoizedusageDatasource mapping.sources/components/AgentInput.tsx—getMaxContextSize(model)helper + rewrite thecontextWarninggate to honoralwaysShowwhen usage is missing.Test plan
pnpm typecheckinpackages/happy-apppasses.pnpm test --runinpackages/happy-app— identical failure baseline tomain(11 failed / 466 passed / 57 skipped on both branches; failures are pre-existing markdown, GitHub API, settings-defaults, and model-mode tests untouched by this PR).claude-opus-4-7[1m]with Always Show Context Size enabled; the percentage should reflect 1M-token usage rather than sticking at 0%.Notes
[1m]detection is/\[1m\]/iagainst the model id returned by the Claude API stream. Happy to switch to an explicit lookup table if you'd prefer.modelis optional throughout — pre-existing sessions and non-Claude flavors keep working with the 190K default.main(270+ commits since the original PR);SessionView.tsxwas reconciled with the new memoizedusageDataintroduced in main.Closes #910
Closes #1274