Skip to content

feat: expose per-ref diff statuses - #29082

Merged
DanielleMaywood merged 4 commits into
mainfrom
feat/chat-diff-ref-api
Oct 6, 2026
Merged

DanielleMaywood merged 4 commits into
mainfrom
feat/chat-diff-ref-api

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

Part 2 of 6. Depends on #29081.

The API now exposes every ref a chat tracks. All API changes are additive.

  • Chat.diff_statuses lists every ref on the chat GET and in chat lists (including child chats). The order is stable: refs are listed by first report, so the list does not change order when a ref gets a new git report.
  • Chat.diff_status is the primary: the ref with the most recent git report. It is the same rule as before. Use it to find the primary, not the list position.
  • ChatDiffStatus gains remote_origin and git_branch.
  • diff_status_change watch events carry changed_diff_status ({ref, status}) naming the ref that changed. If that ref's row is gone, status contains only chat_id.
  • GET /chats/{chat}/diff accepts optional origin and branch query parameters. Set both or omit both (otherwise 400). A selector that matches no stored ref returns 404. Without a selector the endpoint returns the primary, as before. The Go SDK adds WithChatDiffStatusRef for this.
  • A git report without a chat ID (for example, from a terminal or an agent older than v2.32) now refreshes only the chats that already track that ref. It does not add the ref to other chats. Such a report can no longer give a chat its first ref.

Generated by Coder Agents.

@DanielleMaywood DanielleMaywood added the experimental Changes that might not necessarily be merged, until its approved to proceed with. label Sep 8, 2026
@DanielleMaywood DanielleMaywood changed the title feat(coderd): expose per-ref diff statuses feat: expose per-ref diff statuses Sep 8, 2026
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-api branch 2 times, most recently from e55688b to eae5fbe Compare September 10, 2026 09:14
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T08:59:19.721047Z b3168bd 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.

@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: 10e9ca4d69

ℹ️ 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/database/db2sdk/db2sdk.go Resolved
Comment thread coderd/exp_chats.go Resolved
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-api branch 2 times, most recently from 4c58154 to e81202d Compare September 15, 2026 11:12
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-api branch 2 times, most recently from 5344c6c to fdbbdf2 Compare September 15, 2026 14:01
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

Re the documentation check: we will not add @Failure annotations here. Other chats endpoints that return 400 for bad query parameters do not annotate it, and this endpoint's existing 404 and 500 responses are not annotated either. Nothing in the repo requires them.

This reply was generated by Coder Agents.

@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-api branch 2 times, most recently from 2ae28cc to e50e145 Compare September 25, 2026 08:59
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-api branch 2 times, most recently from 7c4c61b to 8795d37 Compare September 30, 2026 14:37
Base automatically changed from feat/chat-diff-ref-key to main October 1, 2026 09:59
Comment thread coderd/x/chatd/chatd.go Outdated

var sdkStatus *codersdk.ChatDiffStatus
var changed *codersdk.ChatDiffStatus
var primarySDK *codersdk.ChatDiffStatus

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we could drop "SDK" here? It's a bit confusing, considering changed doesn't have it, etc.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Dropped it

Comment thread coderd/exp_chats.go Outdated
}
if (selector.RemoteOrigin == "") != (selector.GitBranch == "") {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "The origin and branch query parameters must be set together.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Set together, or omitted.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated it

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One design question here and two points inline, all about how diff_statuses is ordered. I only looked at ordering; didn't review tests or the rest of the diff.

The primary is the last ref the git credential helper reported, so it moves on every authenticated git operation in a different branch. An agent pushing a stack (push A, push B, push A) flips diff_status and reorders diff_statuses three times. A git fetch on main, or from a detached HEAD (branch "HEAD"), becomes the primary. Is "last git operation wins" the intended policy?

🤖 This review was automatically generated with Coder Agents.

Comment thread codersdk/chats.go
// Deprecated: use DiffStatuses, which lists every pull request
// the chat tracks.
DiffStatus *ChatDiffStatus `json:"diff_status,omitempty"`
DiffStatuses []ChatDiffStatus `json:"diff_statuses,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggestion: the stack's frontend treats this order as contract ("the first row is the primary" in site/src/api/queries/chats.ts, #29543), but the field has no doc comment, so Swagger and typesGenerated.ts don't say so. ChatDiffStatus also lacks the sort key, so clients can't sort the list or tell which of two events is newer.

Could we document the order here and expose the report time on ChatDiffStatus? Alternatively: a stable list order (e.g. created_at) with an explicit primary marker would also stop the top bar and sidebar PR menus from reshuffling on every report.

PS. DiffStatusRef and ChangedDiffStatus need doc comments too.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Made the order stable

// branch info even before the worker refreshes PR data.
if w.publishDiffStatusChangeFn != nil {
if pubErr := w.publishDiffStatusChangeFn(ctx, chatID); pubErr != nil {
if pubErr := w.publishDiffStatusChangeFn(ctx, chatID, codersdk.DiffStatusRef{RemoteOrigin: origin, GitBranch: branch}); pubErr != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Check: the broadcast path in MarkStale also reaches this. Git run outside a chat process (terminal, IDE, startup script) has no CODER_CHAT_ID, so the ref is upserted into every non-archived chat on the workspace. Before #29081 that overwrote one row; now it adds a row and makes it primary, and rows are never pruned. A terminal git pull on main over HTTPS makes main the primary of every chat on the workspace, and this PR returns it in diff_statuses. Should the broadcast path still write refs now that chats keep several?

🤖

The primary status in PublishDiffStatusChange is now named primary,
the same as the changed status next to it. The 400 error for an
incomplete ref selector now tells the user to set both query
parameters or omit both.
diff_statuses now lists refs by first report, so the list does not
change order when a ref gets a new git report. diff_status is still
the ref with the most recent git report. One helper picks it, with
the same tie order as before. diff_status is the primary marker and
is no longer deprecated.

The SDK types for the ref list, the ref selector, and the changed
ref event now have doc comments.
A git report without a chat ID comes from outside a chat process,
for example a terminal. MarkStale added the ref to every chat on
the workspace, and the ref became the primary of each chat. Rows are
not pruned, so the chats collected refs they never used.

MarkStale now refreshes only the chats that already track the
reported ref, and adds no rows. Reports with a chat ID do not change.
@DanielleMaywood
DanielleMaywood merged commit 49b1a2c into main Oct 6, 2026
36 checks passed
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