Repository navigation
fix(coderd/x/chatd): make replayed notes calls change a note once - #315
Conversation
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Merged as 6ae5568 (squash) at 08:08Z. Before the merge, the server was confirmed on the previous deploy, 9c4c333. Gates on head ac06a9c:
Not exercised: a real server crash between the note change and the saved tool result. The test replays the call directly. Records expire after 1 day, so a replay later than that would apply again. That is accepted as out of scope. |
Part of #283
Problem
Codex raised this as a P2 on #285. Tool calls run at least once. If the server restarts after a
notesappend committed but before the tool result was saved, the call runs again on resume and the note gets the same text twice. A replayedwriteordeleteis harmless on its own, but it can undo a later change in the same batch.Change
01a1d903-ff52-75e8-91c2-e50d900ac0b7_chat_note_callsadds the tablechat_note_calls. It requires thechat_notesnode. It records each notes call that changed a note, keyed by the tool call ID, with the result the call returned.WriteChatNoteandDeleteChatNoteare now one statement each. The change runs only when the call ID is not recorded yet, and the record is written in the same statement. Records older than one day are dropped in the same statement, so the table stays small.GetChatNoteCallreads a record. dbauthz authorizes it as a read of the chat.fork_chat_notes.gotakes the call ID fromworkspacesdk.ToolCallIDFromContext. A recorded call returns its recorded result and changes nothing. Two runs of the same call can race, so after a write error or a delete that removed nothing, the tool reads the record again and returns it if the other run won. This follows the fix(coderd/x/chatd): deliver a replayed message_agent message once #282 re-read pattern.coderd/x/chatd/ARCHITECTURE.mdlists the table and the at-least-once exception.docs/fork/pstack-adapter.mdhas a user sentence and evidence lines.Tests
TestChatNotesToolReplayincoderd/x/chatd/fork_chat_notes_internal_test.go:log.mdhas 11 bytes, want 7).Commands I ran, all under
flock ~/.fork-go.lock:go build ./coderd/...andgo vet: passedgo run ./coderd/database/migrations/chatdmig/cmd/chatdmig check: passedgo test ./coderd/database/migrations/chatdmig/... ./coderd/database/forkdb/... ./coderd/database/dbauthz/ ./coderd/database/dbmetrics/withCHATDMIG_TEST_DATABASE_URLset: passedgo test -count=5 -race -run 'TestChatNotesTool' ./coderd/x/chatd/: passedgo test -count=1 ./coderd/x/chatd/... ./coderd/database/dbauthz/ ./coderd/database/forkdb/...: passedgolangci-lint run --config=.golangci.new-code.yaml --new-from-merge-base=origin/mainon the touched packages: 0 issuesmake lint/emdash lint/markdown lint/architecture lint/agents: passedNot verified