Skip to content

feat: add pinned skills to chats - #237

Merged
ibetitsmike merged 7 commits into
mainfrom
mike/chat-pinned-skills
Nov 12, 2026
Merged

ibetitsmike merged 7 commits into
mainfrom
mike/chat-pinned-skills

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

This lets a user pin skills to a chat, behind the new fork-pinned-skills experiment. Pinned skills apply on every turn until they are unpinned, without the user invoking them in each message. This PR is the backend only; the composer UI to pin skills comes in a later PR.

Storage (coderd/database/forkdb, chatdmig)

  • A chatdmig migration adds chatd.chat_pinned_skills (chat_id, skill_source, skill_name), keyed on all three columns, and the forkdb queries to read, delete and insert pins. dbauthz and dbmetrics wrap the new queries.

API (coderd, codersdk)

  • GET /api/v2/chats/fork/{chat}/pinned-skills returns the pins of a chat. PUT replaces them all in one transaction; an empty list unpins every skill. PUT needs update permission on the chat, and only the chat owner may call it (403 otherwise, like sending a message), since pins run with the owner's tools and credentials.
  • PUT rejects more than 8 pins, an unknown source, and a name that is not a valid skill name. Both routes return 404 while the experiment is off and have @x-apidocgen skip, like the other fork chat routes.

chatd (coderd/x/chatd)

  • syncForkContext asks pinnedSkillsMessage for a model-only message before each step. It loads each pin with the chat owner's permissions, the same way a skill invocation loads it, and renders the bodies in <pinned-skill> blocks, up to 64 KiB in total. A pin the owner can no longer use (deleted, disabled or unshared) is skipped.
  • The message carries a fingerprint of the rendered list. It is appended only when the prompt does not already show that fingerprint, so the cached prompt prefix stays intact, and a compaction that drops the message brings it back on the next step. When every pin is removed, the message says (none), so the model stops following an earlier list. A compacted prompt with no pins gets (none) once, because the summary may keep unpinned instructions; a chat that never pinned anything therefore gets one (none) row per compaction.
  • ARCHITECTURE.md gets two TODOs for the author.

Known gaps:

  • Pins are stored in name order, not in the order the user pinned them.
  • Duplicating a chat or spawning a subagent does not copy its pins.
  • A workspace skill pinned on an API-created idle chat before its first message is skipped on the first turn, because workspace context is hydrated later in that turn. UI chats are created with their first message, so they are not affected.
  • PUT does not publish a chat event, so other open tabs do not see the change until they refetch.
  • PUT does not check that a pinned skill exists. A missing skill is skipped when the prompt is built.
  • Two concurrent PUTs on one chat can store the union of both lists.
  • One error loading a pinned skill (other than "unavailable") skips the whole message for that step.
  • Turning the experiment off after pins were sent leaves the last list in the prompt history, and the routes that could unpin return 404.
  • The 64 KiB budget is fixed. It does not shrink for a model with a small context window.
  • Pin changes are not audited.
  • The API schema marks source and name as optional, though PUT rejects a pin without them.
  • With the experiment on, every step reads the pins of the chat, and reads the prompt rows when a list may need to change.

Validation on 8858f5e, run in a container:

  • forkdb generate, chatdmig check, apitypings, gofmt, go build ./coderd/... ./enterprise/... ./codersdk/... and go vet on the touched packages pass.
  • TestPinnedSkillsMessage, TestTodoSnapshotMessage, TestForkChatPinnedSkills, TestForkChatRoutes, TestForkExperiments and the swagger/endpoint-documented tests in coderd/coderdtest and enterprise/coderd/coderdenttest pass.
  • Negative control: reverting the unpin-all fix makes TestPinnedSkillsMessage fail at fork_pinned_skills_internal_test.go:141.

Main (00e126098d, #235) was then merged in as 8c5e37faf7; it overlaps this PR only in ARCHITECTURE.md and merged cleanly. fork-ci covers the merged head.

Codex round 3 fixes (ded66cd934): owner-only PUT, tested in TestForkChatPinnedSkills (site owner gets 403, pins unchanged), and (none) after compaction, tested in TestPinnedSkillsMessage. fork-ci runs both (-run '(?i)chat|skill|mcp|plugin' ./coderd and ./coderd/x/...). Negative controls, by construction: without the owner check the site owner's PUT returns 200 and the 403 assertion fails; without the compacted condition the last syncPins after the summary returns no message and require.True(t, ok) fails.

Persist skills pinned to a chat in chatd.chat_pinned_skills behind the
fork-pinned-skills experiment, serve them on GET and PUT
/api/v2/chats/fork/{chat}/pinned-skills, and append their bodies as a
model-only message whenever the prompt does not show the current pins,
so they apply on every turn and return after compaction.
# Conflicts:
#	codersdk/fork_experiments.go
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T09:15:22.052051Z ded66cd Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum requested this review on behalf of @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8858f5e8b5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/fork_pinned_skills.go Resolved
Comment thread coderd/fork_chat_pinned_skills.go Resolved
Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
Comment thread coderd/x/chatd/fork_pinned_skills.go Resolved
Comment thread coderd/fork_chat_pinned_skills.go Resolved
Comment thread codersdk/fork_chat_pinned_skills.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum requested this review on behalf of @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8c5e37faf7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/fork_pinned_skills.go Resolved
Comment thread coderd/x/chatd/fork_pinned_skills.go Resolved
Comment thread coderd/fork_chat_pinned_skills.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum requested this review on behalf of @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ded66cd934

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/fork_pinned_skills.go Resolved
@ibetitsmike
ibetitsmike merged commit 013ef4b into main Nov 12, 2026
11 checks passed
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum merged this PR on behalf of @ibetitsmike.

Merge evidence for head ded66cd934e7f446ab9d2018bd51421f2359254d:

  • fork-ci run 43188866143 passed on this head. All checks on the head pass. Main since the merge base 00e126098d doesn't overlap this PR's files.
  • Codex review 5871910067 is on this head. Earlier rounds fixed:
    • pin writes are owner-only, with a 403 for anyone else, like the send path
    • after compaction, (none) is restored when the chat has no pins
    • the first-message hydration P1 and a P2 were declined as known gaps
  • 11 threads, 0 unresolved.
  • An ops Go run (goval2) passed on 8858f5e with an executed negative control. The fix tests in fork-ci (TestPinnedSkillsMessage, TestForkChatPinnedSkills) would fail without the fixes.
  • No live UAT: the routes sit behind RequireExperiment(fork-pinned-skills), and so does the prompt injection. There's no UI in this PR. The pin UI PR gets the live UI check.
  • Deploy note: this adds one chatdmig node, chat_pinned_skills, an additive table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant