Skip to content

feat: add chat context pinning storage and push trigger#26385

Merged
kylecarbs merged 1 commit into
mainfrom
chat-context-hydration
Jun 15, 2026
Merged

feat: add chat context pinning storage and push trigger#26385
kylecarbs merged 1 commit into
mainfrom
chat-context-hydration

Conversation

@kylecarbs

@kylecarbs kylecarbs commented Jun 15, 2026

Copy link
Copy Markdown
Member

Foundation for the Workspace Context Sources RFC (phase 3). The agent push (#25983) and coderd snapshot storage (#26145) already persist per-agent context snapshots; this PR lands the chat-side storage plus the agentapi push trigger that a follow-up will use to read them. It does not touch chatd and changes no behavior — nothing wires an implementation yet.

What changed

  • Adds four nullable columns to chatscontext_aggregate_hash, context_dirty_since, context_dirty_resources, and context_error — and rebuilds the chats_expanded view.
  • Adds three queries — SetChatContextSnapshot, HydrateAgentChatsContext, MarkChatsContextDirtyByAgent — with dbauthz wrappers and audit entries. They are store-interface methods covered by a Postgres test (TestChatContextHydration).
  • Adds the agentapi.ContextDirtyMarker interface and invokes it inside the PushContextState transaction, publishing collected events only after commit.

Intentionally inert

There are no production callers of the three queries and no implementation wired for ContextDirtyMarker, so the push trigger is dormant. This is deliberate: the PR is the durable storage/query foundation only.

The actual integration — the chatd implementation that hydrates/dirties chats and backs a refresh endpoint, consuming the pinned context in prompt building, the rich SDK types + UI, and retiring the live per-turn pull — lands as a single follow-up PR. Splitting this way keeps the schema/query layer reviewable on its own and keeps the integration whole in one place.

Refs #25983, #26145.

Decision log
  • Columns over a side table. The four chats columns are the durable model (accepting the one-time chats_expanded view/CTE churn). last_injected_context is deliberately left untouched — it is load-bearing for the live per-turn context pull.
  • Keep agentapi, drop chatd. The earlier revision wired the hydrate/dirty implementation through chatd and added a PUT /chats/{chat}/context refresh endpoint. Those were removed so this PR is pure foundation; agentapi defines the trigger + interface (it does not import chatd), and the chatd implementation arrives with the full integration.
  • No new experiment flag. The columns are dark and unread by prompt building.
  • Authz. The new query wrappers authorize chat updates under the chat RBAC object / ResourceChat, consistent with the existing system chat mutators.

🤖 Generated by Coder Agents on behalf of @kylecarbs.

@github-actions

Copy link
Copy Markdown

Docs preview

📖 View docs preview for docs/admin/security/audit-logs.md

@kylecarbs kylecarbs marked this pull request as ready for review June 15, 2026 20:23
Foundation for the Workspace Context Sources RFC phase 3. Agent push
(#25983) and coderd snapshot storage (#26145) persist per-agent context
snapshots; this lands the chat-side storage plus the agentapi trigger
that a follow-up will use to read them. It is inert: nothing wires an
implementation yet, so behavior is unchanged and chatd is untouched.

Add four nullable columns to chats (context_aggregate_hash,
context_dirty_since, context_dirty_resources, context_error) and rebuild
the chats_expanded view. Add three queries -- SetChatContextSnapshot,
HydrateAgentChatsContext, MarkChatsContextDirtyByAgent -- with dbauthz
wrappers and audit entries. The queries have no production callers yet;
they are store-interface methods covered by a Postgres test.

Add the agentapi ContextDirtyMarker interface and invoke it inside the
PushContextState transaction, publishing collected events only after
commit. No implementation is wired in this PR, so the trigger is dormant.
The full context integration (the chatd implementation, prompt
consumption, SDK/UI, and retiring the per-turn pull) lands separately.

Refs #25983, #26145.
@kylecarbs kylecarbs force-pushed the chat-context-hydration branch from 4d6ec76 to 832dc67 Compare June 15, 2026 20:52
@kylecarbs kylecarbs changed the title feat: hydrate and refresh chat context from agent snapshots feat: add chat context pinning storage and push trigger Jun 15, 2026
@kylecarbs kylecarbs marked this pull request as draft June 15, 2026 20:53
@kylecarbs kylecarbs marked this pull request as ready for review June 15, 2026 21:36
@kylecarbs

Copy link
Copy Markdown
Member Author

@hugodutka since you're offline right now, I avoided doing the chatd component as part of this. I'm going to do that in a separate PR that also integrates the UX.

I just got @sreya to approve the DB changes, which are in the RFC.

@kylecarbs kylecarbs merged commit 210261b into main Jun 15, 2026
40 checks passed
@kylecarbs kylecarbs deleted the chat-context-hydration branch June 15, 2026 21:41
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants