feat(core): persist v2 session context epochs#30789
Draft
kitlangton wants to merge 4 commits into
Draft
Conversation
477bf1d to
4c180e2
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.
Why
V1 persisted the transcript but rebuilt most privileged system context at request time. A restarted Session could therefore see a different date, environment, or instruction text than the original run.
This PR gives the V2 runner a durable, private Context Epoch timeline:
Runtime Flow
The V2 runner samples Location-scoped Context Components immediately before provider dispatch. Exact admitted bytes cross the synchronized Session event boundary before they influence the request.
The ordinary transcript API remains unchanged. Hidden context updates are loaded only by the runner.
Epoch Lifecycle
An epoch has one immutable baseline. Changed components append absolute current-state updates. Model switches and completed compactions request lazy replacement; temporary unavailability defers replacement instead of silently dropping admitted context.
The synchronized event types are:
session.next.context.initialized.1session.next.context.updated.1session.next.context.replaced.1Storage Model
Filesystem and service producers answer what exists now. Session events preserve what the model saw then. Disposable projections keep provider-turn reads cheap.
The initial representation deliberately stores admitted bytes in both canonical events and disposable projections. Checkpoint hashes are change detectors, not lookup keys. A content-addressed blob store remains a measured follow-up optimization if large instruction or skills payloads justify it.
Tool Safety
Chronological system updates must never split unresolved local tool calls from their results. The shared protocol guard tracks all unresolved local call IDs across the message prefix, including multi-tool turns.
Unsupported privileged chronological messages lower to escaped
<system-update>user wrappers. Anthropic Opus 4.8 retains its existing native lowering where placement is legal.Scope
This is wired end-to-end into the V2 Session runner before provider dispatch. V1 is unchanged.
Currently populated Context Components:
Follow-up slices:
The reviewed design for instruction observation, optional watcher-backed caching, URL sources, and later skills reuse lives in
specs/v2/refreshable-context-sources.md.Verification
bun typecheckinpackages/corebun run migration --checkinpackages/core99 pass,0 fail1 pass,0 failbun typecheckinpackages/llm141 pass,0 fail258 pass,28 skip,0 failgit diff --check22tasks,0failures