Skip to content

feat(site): fetch and merge diff statuses per ref - #29543

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

DanielleMaywood merged 9 commits into
mainfrom
feat/chat-diff-ref-client

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Part 3 of 6. Depends on #29082. No visible UI change.

The frontend API client and React Query cache now handle per-ref diff statuses. getChatDiffContents takes an optional ref, and the diff-contents query key includes it, so each ref has its own cache entry. Invalidation clears every ref's entry for the chat.

When a diff_status_change event arrives, the cache merges changed_diff_status into diff_statuses by ref. Other refs stay untouched, and an event with only chat_id removes its ref. The primary ref stays first in the list. diff_status is set from that first entry, so older consumers stay consistent with the list. The equality check that skips no-op updates now also compares ref and author fields.

Generated by Coder Agents.

@DanielleMaywood DanielleMaywood added the experimental Changes that might not necessarily be merged, until its approved to proceed with. label Sep 18, 2026
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from f23c58a to e827956 Compare September 21, 2026 08:32
@DanielleMaywood DanielleMaywood removed the experimental Changes that might not necessarily be merged, until its approved to proceed with. label Sep 21, 2026
@DanielleMaywood
DanielleMaywood marked this pull request as ready for review September 21, 2026 10:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 21, 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:33.506360Z 42f4e28 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: 742f398220

ℹ️ 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 on lines 711 to +714
...cachedChat,
status: nextStatus,
title: nextTitle,
diff_status: nextDiffStatus,
diff_statuses: nextDiffStatuses,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep the primary diff status synchronized

On every diff_status_change, this writes only diff_statuses while the spread preserves the old diff_status. Current consumers such as ChatTopBar, AgentChatPageView, and the sidebar status configuration still read chat.diff_status, and this event path invalidates only diff contents rather than the chat entity, so PR state, statistics, and even a deleted primary PR remain stale until an unrelated refetch. Continue updating diff_status from the watched primary or the first merged row until those consumers are migrated.

Useful? React with 👍 / 👎.

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.

Fixed in 42f4e28. On diff_status_change the merge now writes diff_status: nextDiffStatuses?.[0], so the legacy field always matches the merged primary: it follows the fresher-than-snapshot merge decisions, and it clears when a tombstone deletes the primary. The field is also part of the no-op guard now. The source is the merged first row rather than the embedded watchedChat.diff_status, so the two fields can never disagree. Layers 4-6 of this stack migrate every production consumer (AgentChatPageView in the GitPanel PR, ChatTopBar in the top-bar PR, the sidebar config in the sidebar PR); after those merge, no production code reads diff_status and the field can be deleted.

Generated by Coder Agents

@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch 2 times, most recently from 3606027 to 78e23f4 Compare September 21, 2026 12:38
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from 78e23f4 to fa1f49c Compare September 21, 2026 13:17
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from fa1f49c to c0e01e3 Compare September 21, 2026 16:19
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from c0e01e3 to d509327 Compare September 22, 2026 08:22
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from d509327 to 4f81bf1 Compare September 22, 2026 08:54
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 42f4e280d2

ℹ️ 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 site/src/api/queries/chats.test.ts Outdated
git_branch: "feature-a",
},
// The server sends only chat_id when the ref has no row.
status: { chat_id: "chat-1" } as TypesGen.ChatDiffStatus,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Model the tombstone without an unsafe cast

Replace this assertion with a complete generated ChatDiffStatus fixture. The server serializes required zero-valued fields such as pull_request_title, pull_request_draft, and the diff counts, so { chat_id } is not an actual wire payload; the cast both bypasses the generated contract and leaves the tombstone test exercising an inaccurate shape.

AGENTS.md reference: site/AGENTS.md:L8-L8

Useful? React with 👍 / 👎.

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.

Fixed in ba8fd59. The test now builds the tombstone without a cast, with the required fields at their zero values, which is the payload the server serializes.

This reply was generated by Coder Agents.

Comment on lines +545 to +547
return cached.every((status, index) =>
diffStatusEqual(status, incoming[index]),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve author-only diff status updates

When a non-primary ref changes only author_login or author_avatar_url, mergeDiffStatuses installs the new row but this equality check calls diffStatusEqual, which omits both author fields. With the primary and other chat fields unchanged, the no-op guard returns the old cached chat, so the newly supported diff_statuses cache retains stale author data until an unrelated refetch. Include both author fields in the equality comparison.

Useful? React with 👍 / 👎.

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.

Fixed in ba8fd59. diffStatusEqual now compares author_login and author_avatar_url, so the no-op guard no longer keeps stale author data. Covered by new rows in the existing adopts diff status when only $field changes table test.

This reply was generated by Coder Agents.

@linear-code

linear-code Bot commented Sep 23, 2026

Copy link
Copy Markdown

CODAGT-990

@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from e619485 to 92da57a Compare September 23, 2026 17:52
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from 92da57a to 3bcd5ba Compare September 24, 2026 08:32
Comment thread site/src/api/queries/chats.ts Outdated
removedRef?: TypesGen.DiffStatusRef,
): TypesGen.ChatDiffStatus[] | undefined => {
const merged = new Map(
(cached ?? []).map((status) => [diffStatusRefKey(status), status]),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: I HATE this pattern of ?? []

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.

Fixed in 76d7c04. mergeDiffStatuses has no ?? [] now. cached defaults to [], and incoming is a required array that its caller starts as []. The behavior is the same, because diff_statuses is never null.

This reply was generated by Coder Agents.

@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from 56cafce to b985b69 Compare September 28, 2026 12:11
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch 2 times, most recently from 76d7c04 to c0ef5fc Compare September 30, 2026 14:37
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from c0ef5fc to a7b5e0f Compare October 1, 2026 09:10
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from a7b5e0f to c29d3eb Compare October 1, 2026 09:59
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from c29d3eb to cdc7d3d Compare October 5, 2026 09:06

@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 minor point inline about event ordering. It follows from the ordering review on #29082. I only looked at mergeDiffStatuses.

🤖 This review was automatically generated with Coder Agents.

Comment thread site/src/api/queries/chats.ts Outdated
);
if (primaryIndex > 0) {
const [primaryRow] = statuses.splice(primaryIndex, 1);
statuses.unshift(primaryRow);

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.

Minor: this moves the event's embedded primary to the front unconditionally. The comment above says the embedded primary can be stale by delivery delay, but that only guards adding the row. If events for A then B arrive as B then A, the cache shows A as primary until the next event or refetch. Not reproduced. Exposing the report time (see #29082) would let this drop stale events.

🤖

@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from cdc7d3d to 8ecc197 Compare October 5, 2026 14:38
Base automatically changed from feat/chat-diff-ref-api to main October 6, 2026 08:32
The chat diff client and query cache now track every ref the chat
follows, not only the primary. The GET diff client accepts a ref
selector. The diff-contents query key includes the ref, so each ref
keeps its own cache entry. The watch merge keys rows by ref, so a
changed row for one ref leaves the other refs' rows intact, and a
tombstone row removes its ref. The diff-contents invalidation
prefix-matches every ref.
The factory took positional git_branch and additions arguments.
A const base with object spread states every field at each call
site, matching the mock fixture convention.
Single-letter loop variables now name their rows. The tombstone
and changed-row arguments are built before the merge call instead
of nested ternaries inside it. The diff-contents key prefix gets
a named family key that the invalidation reuses.
The merge phases and the event derivation groups ran together
without separation. Each phase and group now has its own comment
with a blank line between them.
The server now keeps diff_statuses in a stable order and marks the
primary with diff_status. The watch merge no longer moves the
primary to the front. It replaces each row in place, adds new refs
at the end, and takes diff_status from the merged row of the
primary ref.
@DanielleMaywood
DanielleMaywood force-pushed the feat/chat-diff-ref-client branch from 8ecc197 to bea1de5 Compare October 6, 2026 08:32
@DanielleMaywood
DanielleMaywood merged commit 8f1fc53 into main Oct 6, 2026
27 checks passed
@DanielleMaywood
DanielleMaywood deleted the feat/chat-diff-ref-client branch October 6, 2026 09:19
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 6, 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.

3 participants