Skip to content

fix(app): scale MAX_CONTEXT_SIZE for 1M models + render alwaysShow before usage streams in#1271

Open
g0rdonL wants to merge 2 commits into
slopus:mainfrom
g0rdonL:fix/dynamic-max-context-size
Open

fix(app): scale MAX_CONTEXT_SIZE for 1M models + render alwaysShow before usage streams in#1271
g0rdonL wants to merge 2 commits into
slopus:mainfrom
g0rdonL:fix/dynamic-max-context-size

Conversation

@g0rdonL
Copy link
Copy Markdown

@g0rdonL g0rdonL commented May 14, 2026

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)

  • 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 latestUsageSession.latestUsageAgentInput.usageData.
  • AgentInput now picks the limit dynamically via getMaxContextSize(model): 950K for model ids matching [1m], 190K otherwise.

Commit 2 — Closes #1274 (render alwaysShow before usage streams in)

  • The outer gate at the call site short-circuited to null whenever usageData.contextSize was 0 or undefined:
    const contextWarning = props.usageData?.contextSize
        ? getContextWarning(...)
        : null;
    …which swallowed the alwaysShow signal that getContextWarning itself honors (line 311). Two failure modes this addresses on Android (and silently on iOS/web — same render path):
    1. Fresh session with no agent reply yet — latestUsage is undefined, indicator never showed.
    2. Sessions where the reducer resets contextSize to 0 on session events (reducer.ts:324, 338) with no subsequent assistant message carrying usage.
  • Gate is now alwaysShow || contextSize, and getContextWarning receives contextSize ?? 0. On fresh always-show sessions the indicator renders "100% remaining" until real usage arrives.

Files changed

  • sources/sync/typesRaw.ts — capture message.model when normalizing assistant messages; add model?: string to NormalizedMessage.
  • sources/sync/reducer/reducer.ts — thread model through processUsageData / ReducerState.latestUsage / ReducerResult.usage.
  • sources/sync/storageTypes.ts — add model?: string to persisted Session.latestUsage.
  • sources/-session/SessionView.tsx — thread model into the memoized usageData source mapping.
  • sources/components/AgentInput.tsxgetMaxContextSize(model) helper + rewrite the contextWarning gate to honor alwaysShow when usage is missing.

Test plan

  • pnpm typecheck in packages/happy-app passes.
  • pnpm test --run in packages/happy-appidentical failure baseline to main (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).
  • Manual: open a session on claude-opus-4-7[1m] with Always Show Context Size enabled; the percentage should reflect 1M-token usage rather than sticking at 0%.
  • Manual: open a 200K-context session (Sonnet/Haiku); behavior unchanged.
  • Manual: enable Always Show Context Size on a fresh session (no agent reply yet) — the indicator should render "100% remaining" immediately rather than waiting for usage.

Notes

  • [1m] detection is /\[1m\]/i against the model id returned by the Claude API stream. Happy to switch to an explicit lookup table if you'd prefer.
  • model is optional throughout — pre-existing sessions and non-Claude flavors keep working with the 190K default.
  • Rebased onto main (270+ commits since the original PR); SessionView.tsx was reconciled with the new memoized usageData introduced in main.

Closes #910
Closes #1274

@g0rdonL g0rdonL force-pushed the fix/dynamic-max-context-size branch from 6d66056 to f3e3862 Compare May 14, 2026 19:26
g0rdonL added 2 commits May 17, 2026 23:24
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
@g0rdonL g0rdonL force-pushed the fix/dynamic-max-context-size branch from f3e3862 to 266731c Compare May 17, 2026 16:27
@g0rdonL g0rdonL changed the title fix(app): scale MAX_CONTEXT_SIZE for 1M-context models fix(app): scale MAX_CONTEXT_SIZE for 1M models + render alwaysShow before usage streams in May 17, 2026
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.

alwaysShowContextSize toggle has no visible effect on Android Context remaining shows 0% on 1M context models (hardcoded MAX_CONTEXT_SIZE = 190000)

1 participant