🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

feat(coderd/x/chatd): consume the pinned chat context in prompt generation - #26558

Merged
kylecarbs merged 1 commit into
mainfrom
kylecarbs/chatd-prompt-consume-pin
Jun 22, 2026
Merged

feat(coderd/x/chatd): consume the pinned chat context in prompt generation#26558
kylecarbs merged 1 commit into
mainfrom
kylecarbs/chatd-prompt-consume-pin

Conversation

@kylecarbs

Copy link
Copy Markdown
Member

What

prepareGeneration now builds the system-prompt instruction block and workspace skills from a chat's pinned context copy (chat_context_resources, populated in #26438) instead of re-scanning per-turn history, when the chat has a pinned copy. This is the first production reader of the pin.

Selection is presence-based, no experiment: a chat with pinned rows builds its prompt from the pin; a chat without them falls back to the existing per-turn history path. The two paths are mutually exclusive, so older agents that never report context keep their current behavior and the per-turn pull stays as the fallback.

How

  • contextResourcesToPrompt maps the protojson resource bodies (instruction files and skills) into the instruction block and skill metadata, skipping non-OK statuses, non-prompt body kinds, and malformed bodies (the malformed count is logged so a proto/encoding regression cannot silently drop context).
  • pinnedWorkspaceContext reads the pin and reports ok=false (history fallback) when there are no pinned rows; read errors propagate. The bound agent only decorates the instruction header with OS and directory, so the pin still resolves when the workspace is unreachable.
  • resolveTurnWorkspaceContext dispatches between the pinned and history paths; prepareGeneration calls it.

Testing

  • go test ./coderd/x/chatd/ for TestContextResourcesToPrompt, TestPinnedWorkspaceContext (incl. ...FromHydratedPin against real Postgres), and TestResolveTurnWorkspaceContext: pass.
  • make gen (no drift), golangci-lint, gofmt, emdash scan, and go build/go vet on ./coderd/x/chatd/...: all clean.

Scope

This is the foundational backend slice split from #26466 (the full-stack staging PR). It changes no API surface, schema, proto, or generated files. The remaining pieces land as follow-ups in dependency order:

  1. ChatContext drift/diff API (resources + changes, ContextDetail). This also extracts the body decoders inlined here so they are shared with the diff path.
  2. Context-ring drift indicator, changes dialog, and refresh (UI).
  3. In-workspace coder exp chat context source CRUD and refresh (CLI).
Why this is the first split

The coderd hydration, the PUT /chats/{id}/context refresh endpoint (#26389), the chat_context_resources table (#26430), and the copy-into-pin logic (#26438) are already merged, as is the agent-side push (#26526, #26533). Consuming the pin in prompt building is the step #26438 explicitly deferred, and it is the bottom of the remaining dependency stack: the drift/diff API, the UI indicator, and the CLI are only meaningful once the chat actually builds its prompt from the pin. Keeping it presence-based means it is independently revertable and leaves the per-turn pull intact as a fallback, matching the RFC's Release 3 rollout.

The files are taken verbatim from the reviewed #26466 boundary commit (before the diff-API work began), so the deep-review feedback already applied there (CRF-1 through CRF-10) is preserved.


This PR was created by Coder Agents on behalf of @kylecarbs. Split from #26466.

…ation

Build the system-prompt instruction block and workspace skills from a
chat's pinned context copy (chat_context_resources, populated in #26438)
instead of scanning per-turn history, when the chat has a pinned copy.

Selection is presence-based, with no experiment: a chat with pinned rows
builds its prompt from the pin; a chat without them falls back to the
per-turn history path, so older agents that never report context keep
their existing behavior. The two paths are mutually exclusive.

- contextResourcesToPrompt maps the protojson resource bodies (instruction
  files and skills) into the instruction block and skill metadata, skipping
  non-OK statuses, non-prompt body kinds, and malformed bodies (counted so a
  proto or encoding regression cannot silently drop context).
- pinnedWorkspaceContext reads the pin and reports ok=false (history
  fallback) when there are no pinned rows; read errors propagate. The bound
  agent only decorates the instruction header with OS and directory, so the
  pin still resolves when the workspace is unreachable.
- resolveTurnWorkspaceContext dispatches between the pinned and history
  paths; prepareGeneration calls it.

Split from #26466. The body decoders this PR inlines are extracted to be
shared with the drift/diff API in the follow-up.
@kylecarbs
kylecarbs merged commit 46916bf into main Jun 22, 2026
52 checks passed
@kylecarbs
kylecarbs deleted the kylecarbs/chatd-prompt-consume-pin branch June 22, 2026 14:52
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 22, 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