feat: add chat context pinning storage and push trigger#26385
Merged
Conversation
Docs preview📖 View docs preview for |
sreya
approved these changes
Jun 15, 2026
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.
4d6ec76 to
832dc67
Compare
Member
Author
|
@hugodutka since you're offline right now, I avoided doing the I just got @sreya to approve the DB changes, which are in the RFC. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
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
agentapipush trigger that a follow-up will use to read them. It does not touchchatdand changes no behavior — nothing wires an implementation yet.What changed
chats—context_aggregate_hash,context_dirty_since,context_dirty_resources, andcontext_error— and rebuilds thechats_expandedview.SetChatContextSnapshot,HydrateAgentChatsContext,MarkChatsContextDirtyByAgent— withdbauthzwrappers andauditentries. They are store-interface methods covered by a Postgres test (TestChatContextHydration).agentapi.ContextDirtyMarkerinterface and invokes it inside thePushContextStatetransaction, 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
chatdimplementation 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
chatscolumns are the durable model (accepting the one-timechats_expandedview/CTE churn).last_injected_contextis deliberately left untouched — it is load-bearing for the live per-turn context pull.agentapi, dropchatd. The earlier revision wired the hydrate/dirty implementation throughchatdand added aPUT /chats/{chat}/contextrefresh endpoint. Those were removed so this PR is pure foundation;agentapidefines the trigger + interface (it does not importchatd), and thechatdimplementation arrives with the full integration.ResourceChat, consistent with the existing system chat mutators.🤖 Generated by Coder Agents on behalf of @kylecarbs.