Skip to content

feat(core): API-managed per-session context entries - #34941

Merged
kitlangton merged 2 commits into
v2from
api-context-entries
Jul 2, 2026
Merged

kitlangton merged 2 commits into
v2from
api-context-entries

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Closes #34918. Follow-up to #34917.

Allows API clients to attach durable, per-session context that rides the system context belief model.

What

  • New session_context_entry table (session_id, key, JSON value; composite PK, cascade delete)
  • SessionContextEntry service: list/put/remove plus load(sessionID), which emits one SystemContext source per entry keyed api/<key>
  • loadSystemContext in the runner now takes the session ID and composes entries as the sixth producer
  • New endpoints behind the session location middleware:
    • GET /api/session/:sessionID/context-entry — list
    • PUT /api/session/:sessionID/context-entry/:key — upsert { value: Json }
    • DELETE /api/session/:sessionID/context-entry/:key
  • Client keys are slash-free ([a-z0-9][a-z0-9._-]*); the server derives the api/* SystemContext namespace by construction, keeping core/* reserved for built-ins
  • Regenerated packages/client and plugin effect API surfaces

Rendering

Server-owned phrasing, no client-supplied text. String values render verbatim inside a <context key="..."> block (the common case: prose instructions); other JSON pretty-prints. Because entries flow through the reconcile/checkpoint lifecycle:

  • PUT a changed value → chronological System update at the next turn boundary
  • DELETE → removal announcement via the stored removal text
  • Compaction folds accumulated updates into the rebaselined system prompt
  • Forks inherit applied state via the copied checkpoint

Testing

  • Belief-lifecycle test in session-runner.test.ts: baseline render, update narration, removal announcement, list/remove semantics
  • End-to-end put/list/remove roundtrip plus 404 coverage through the real router in the sdk-next embedded test
  • Full core suite green (watcher flakes aside); repo-wide typecheck clean; migration --check fresh

Add a session_context_entry table and a SessionContextEntry service
whose load(sessionID) produces one SystemContext source per stored
entry, keyed api/<key>. Entries ride the existing belief lifecycle:
changes narrate as chronological System updates, deletions announce
through the stored removal text, and compaction folds accumulated
updates into the rebaselined prompt. String values render verbatim
inside a tagged block; other JSON pretty-prints.
Expose GET/PUT/DELETE /api/session/:sessionID/context-entry[/:key]
behind the session location middleware. Clients supply a slash-free
key; the server derives the api/<key> SystemContext namespace by
construction. Regenerates the client surfaces.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant