Skip to content

fix(context): serve a cached SessionStart body only when it fits the reserve-adjusted room (#5672) - #5686

Merged
thedotmack merged 1 commit into
thedotmack:mainfrom
Varshith-Kali:fix-5672-sessionstart-cache-reserve
Nov 10, 2026
Merged

thedotmack merged 1 commit into
thedotmack:mainfrom
Varshith-Kali:fix-5672-sessionstart-cache-reserve

Conversation

@Varshith-Kali

Copy link
Copy Markdown
Contributor

Fixes #5672.

Since 15.13.0, sessions with enough recent observations start with only "[claude-mem] Recent context omitted because it exceeds the session output limit." The timeline and the "Work state, still open" section never reach the model.

Cause: the context cache holds bodies rendered for the full 10,000 character budget, without the current session's notice reserve. The SessionStart handler read such a body whenever it fit the raw limit, and composeSessionStartContext then dropped the whole body against the reserve-adjusted room (about 7,949 characters with about 2,049 characters of notices in the report).

Fix: the cached read now re-validates the body against the reserve-adjusted room, through one shared definition. A new sessionStartBodyRoom helper computes the room the notices leave, and both the cached read and composeSessionStartContext use it. A body rendered for the full budget that does not fit the current room is a cache miss, and the hook falls through to the live fetch, which re-renders it with the current reserve. Bodies that fit are still served from cache. Nothing is cut to fit.

Tests: handler-level regression tests in tests/cli/handlers/context-session-start.test.ts. A 9,361 character cached body with about 1,268 characters of notices is treated as a miss and fetched live with reserveChars, with no omission notice; a 5,000 character body under the same notices is still served from cache with no worker call. With the room check removed, the over-room test fails with exactly the reported omission output. The affected suites pass (90 tests across the SessionStart handler and context cache files), the root TypeScript check is clean, the hook-IO discipline check passes, and the bundle build passes.

Note: verification here is code-path plus handler-level repro, not a live Claude Code session start, which needs Claude Code plus the worker runtime.

…reserve-adjusted room (thedotmack#5672)

The context cache holds bodies rendered for the full 10,000 character
budget, without the current session's notice reserve. The SessionStart
handler read such a body whenever it fit the raw limit, and
composeSessionStartContext then dropped the whole body against the
reserve-adjusted room, so the session started with only the omission
notice and no timeline or work state.

Share one room definition between the read and the compose step: a new
sessionStartBodyRoom helper computes the room the notices leave, and the
cached read serves a body only when it fits that room. An over-room body
is now a cache miss, and the hook falls through to the live fetch, which
re-renders it with the current reserve. Bodies that fit are still served
from cache. Nothing is cut to fit.

Regression tests at the handler level cover both sides: a 9,361
character cached body with about 1,268 characters of notices is treated
as a miss and fetched live with reserveChars, and a 5,000 character body
under the same notices is still served from cache with no worker call.

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@thedotmack
thedotmack merged commit 534bdf2 into thedotmack:main Nov 10, 2026
10 of 11 checks passed
@thedotmack

Copy link
Copy Markdown
Owner

Merged, thank you @Varshith-Kali! Main already rejected a cached body that doesn't fit next to the notices since v15.14.0 (#5487, context.ts:452), so this doesn't change behavior on its own. What it adds is one shared definition of the body room, sessionStartBodyRoom, used by both the cache read and composeSessionStartContext, so the two checks can't drift apart, plus a regression test for the #5672 scenario. I landed it as a refactor under that title. #5672 stays open while we pin down the path the reporter is actually hitting.

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.

SessionStart serves a cached context body rendered without reserveChars, so the whole body is omitted ("Recent context omitted…")

2 participants