mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-21 10:16:03 +00:00
feat(core): persist v2 session context epochs (#30789)
This commit is contained in:
@@ -686,3 +686,85 @@ Compatibility:
|
||||
|
||||
- Foreground V2 bash execution is unchanged.
|
||||
- Reintroduce background bash only with durable status observation, completion delivery, and explicit cancellation semantics.
|
||||
|
||||
## 2026-06-04: Add Durable Session Context Snapshots
|
||||
|
||||
Affected schema:
|
||||
|
||||
- Add `session_context_epoch` for one active immutable baseline string, structured JSON snapshot, and baseline sequence per Session.
|
||||
|
||||
Change:
|
||||
|
||||
- Lazily initialize one durable Context Epoch snapshot at the first safe provider-turn boundary.
|
||||
- Lower its exact baseline string through `LLMRequest.system` for every provider turn in the epoch.
|
||||
- Reuse the stored baseline verbatim after restart or producer changes instead of resampling privileged initial context.
|
||||
- Compare later observations against an overwriteable codec-encoded structured snapshot rather than rendered-text hashes.
|
||||
- Expose admitted chronological context as first-class `system` Session messages while keeping the active baseline in bounded context state.
|
||||
|
||||
Compatibility:
|
||||
|
||||
- The unpublished Context Epoch schema is consolidated into one database migration; baseline and structured snapshots are operational state rather than synchronized event history.
|
||||
- Existing experimental V2 Session databases remain disposable across incompatible pre-launch event-schema changes.
|
||||
- Chronological context updates, replacement epochs after compaction or model switches, project instructions, skills guidance, and plugin transforms remain follow-up slices.
|
||||
|
||||
## 2026-06-04: Admit Chronological Session Context Updates
|
||||
|
||||
Affected schema:
|
||||
|
||||
- Add synchronized `session.next.context.updated.1` Session events containing a durable System-message ID and only exact combined model-visible text.
|
||||
- Add `session_context_epoch.revision` for transactional structured-snapshot advancement.
|
||||
- Add the first-class `system` Session message projection for chronological context updates.
|
||||
|
||||
Change:
|
||||
|
||||
- Reconcile Location-scoped Context Sources at each safe provider-turn boundary using one coherent observation.
|
||||
- Keep the stored baseline immutable while admitting changed source renderings as chronological `Message.system(...)` history.
|
||||
- Advance the overwriteable structured snapshot atomically with the rendered System-message event.
|
||||
- Emit the previously stored model-meaningful removal rendering when a source is removed.
|
||||
- Reject chronological system updates that would split a local tool call from its result across provider protocols; use wrapped user fallback when Anthropic native system-update placement is unsupported.
|
||||
|
||||
Compatibility:
|
||||
|
||||
- The synchronized event log retains only text actually shown to the model, not internal structured snapshots.
|
||||
- Existing experimental V2 Session databases remain disposable across incompatible pre-launch event-schema changes.
|
||||
- Replacement epochs after compaction or model switches, skills guidance, and plugin-defined context remain follow-up slices.
|
||||
|
||||
## 2026-06-04: Replace Session Context Epochs Lazily
|
||||
|
||||
Affected schema:
|
||||
|
||||
- Add nullable `session_context_epoch.replacement_seq` for idempotent lazy replacement requests.
|
||||
|
||||
Change:
|
||||
|
||||
- Mark the active Context Epoch for replacement after a model switch or completed compaction projection.
|
||||
- Persist the triggering aggregate sequence so same-target replay cannot reopen an already-settled replacement.
|
||||
- Render and overwrite the fresh immutable baseline and structured snapshot lazily at the next safe provider-turn boundary.
|
||||
- Exclude chronological System messages from earlier epochs when assembling active provider history.
|
||||
|
||||
Compatibility:
|
||||
|
||||
- Baseline replacement is bounded operational state and does not add permanent synchronized events.
|
||||
- Existing experimental V2 Session databases remain disposable across incompatible pre-launch event-schema changes.
|
||||
- Compaction execution, skills guidance, and plugin-defined context remain follow-up slices.
|
||||
|
||||
## 2026-06-05: Register Ambient System Context Producers
|
||||
|
||||
Affected schema:
|
||||
|
||||
- No database schema changes.
|
||||
|
||||
Change:
|
||||
|
||||
- Replace the Session-specific context loader with a Location-scoped registry of stable-keyed scoped context producers.
|
||||
- Register environment/date and ambient instruction producers independently, then evaluate producers concurrently in stable contribution-key order.
|
||||
- Directly discover and read global plus upward project `AGENTS.md` files at each safe provider-turn boundary.
|
||||
- Preserve admitted instructions across transient scan/read failures and block first-epoch initialization while any context source is unavailable.
|
||||
- Retry Context Epoch preparation until stable after optimistic revision mismatches.
|
||||
- Clear the active Context Epoch when a Session moves so the destination initializes a complete baseline before promoting more input.
|
||||
- Fence Context Epoch initialization against the authoritative Session Location so a concurrent old-Location runner cannot recreate stale privileged context after a move.
|
||||
- Canonicalize ambient instruction traversal boundaries, honor `OPENCODE_DISABLE_PROJECT_CONFIG`, and make non-empty aggregate updates explicitly supersede previously loaded instructions.
|
||||
|
||||
Compatibility:
|
||||
|
||||
- Watcher-backed per-file `Refreshable` instruction observations, configured sources, nested discovery, and plugin-defined context remain follow-up slices.
|
||||
|
||||
@@ -37,6 +37,66 @@ The local runner issues one explicit `llm.stream(request)` per provider turn, pr
|
||||
|
||||
Projected hosted tools preserve call-side and settlement-side provider metadata separately so settlement and interruption recovery cannot erase continuation identifiers. Provider-native reasoning and provider metadata replay only while the historical assistant model matches the selected continuation model; after a model switch, visible reasoning text remains ordinary assistant text and provider-native metadata is omitted.
|
||||
|
||||
## Context Epochs
|
||||
|
||||
V2 Sessions persist the exact privileged System Context shown to the model. A Context Epoch owns one immutable baseline plus a model-hidden structured snapshot used to compare independently observed Context Sources. Environment facts, the host-local date, and ambient global/upward-project `AGENTS.md` files are the initial registered sources.
|
||||
|
||||
The first complete observation initializes the epoch before any pending prompt becomes model-visible. If initial context is temporarily unavailable, execution stops while the prompt remains pending and retryable. On later provider turns, the runner promotes eligible input first, then reconciles current sources at the safe boundary. Changed context becomes one durable chronological System message, and its event commit advances the epoch snapshot atomically.
|
||||
|
||||
```text
|
||||
Client Runner System Context Registry Context Epoch Store Session History LLM
|
||||
│ │ │ │ │ │
|
||||
├─ Admit prompt ─────────────────────────────────────────────────────────────────────────────────────────────▶ │
|
||||
│ │ │ │ │ │
|
||||
│ ├─ Observe initial context ────────────▶ │ │ │
|
||||
│ │ │ │ │ │
|
||||
│ ◀─ Complete baseline or unavailable ───┤ │ │ │
|
||||
│ │ │ │ │ │
|
||||
│ ├─ Initialize missing epoch ───────────────────────────────────────▶ │ │
|
||||
│ │ │ │ │ │
|
||||
│ ├─ Promote eligible input ─────────────────────────────────────────────────────────────────▶ │
|
||||
│ │ │ │ │ │
|
||||
│ ├─ Reconcile at safe boundary ─────────▶ │ │ │
|
||||
│ │ │ │ │ │
|
||||
│ ◀─ Unchanged or chronological update ──┤ │ │ │
|
||||
│ │ │ │ │ │
|
||||
│ ├─ Advance snapshot atomically with update ────────────────────────▶ │ │
|
||||
│ │ │ │ │ │
|
||||
│ ├─ Baseline + chronological history ─────────────────────────────────────────────────────────────────────────▶
|
||||
```
|
||||
|
||||
Model switches and completed compactions request lazy baseline replacement. A Session move clears the epoch so the destination Location must initialize a complete baseline before promoting more input. Epoch creation is fenced against the authoritative Session Location, preventing an old-Location runner from recreating stale privileged context after a concurrent move.
|
||||
|
||||
```text
|
||||
Session Epoch
|
||||
│ │
|
||||
├─ initialize complete baseline ──▶
|
||||
│ │
|
||||
│ ├─────────────────────────────────╮
|
||||
│ │ reconcile chronological update │
|
||||
│ ◀─────────────────────────────────╯
|
||||
│ │
|
||||
├─ request replacement ───────────▶
|
||||
│ │
|
||||
│ ├─────────────────────────────────────╮
|
||||
│ │ replace after complete observation │
|
||||
│ ◀─────────────────────────────────────╯
|
||||
│ │
|
||||
├─ clear after Location move ─────▶
|
||||
```
|
||||
|
||||
Ambient project discovery canonicalizes and contains traversal within the project root and honors `OPENCODE_DISABLE_PROJECT_CONFIG`. An unavailable observation preserves the previously admitted value. A confirmed partial instruction removal emits the complete remaining aggregate with explicit supersession text; removing the final instruction emits a revocation message.
|
||||
|
||||
Current Context Epoch follow-ups:
|
||||
|
||||
- Add configured, remote, and nested instruction sources with explicit precedence and removal semantics.
|
||||
- Add durable post-crash activity recovery for promoted or provider-dispatched work.
|
||||
- Integrate actual automatic/context-pressure compaction with epoch replacement.
|
||||
- Add operational metrics for observation latency, unavailable sources, contention, baseline size, and chronological-update growth.
|
||||
- Consider watcher-backed per-file caching only if measurements show direct safe-boundary observation is too expensive.
|
||||
- Expose plugin-defined Context Sources only after plugin reload and scoped cleanup semantics are designed.
|
||||
- Add clustered Session execution ownership and stale-runtime fencing.
|
||||
|
||||
Provider timeout, retry, and watchdog policy is intentionally deferred. The runner does not impose a universal provider-stream inactivity or absolute timeout. A future slice should design configurable policy around provider behavior, durable failure reporting, and local drain-chain release rather than hardcoding one default for every provider.
|
||||
|
||||
Inbox delivery is explicit:
|
||||
|
||||
Reference in New Issue
Block a user