GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(coderd): key chat diff statuses by ref by DanielleMaywood · Pull Request #29081 · coder/coder Conversation
|
|
@codex review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Codex Review SummaryThis 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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a7076c4bd
Your 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".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
e370f06 to
caa4caa
Compare
|
@codex review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: caa4caa84c
Your 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".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
caa4caa to
c6eef7d
Compare
|
@codex review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Codex Review: Didn't find any major issues. Bravo. 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". |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
c6eef7d to
12de2af
Compare
12de2af to
50c7b30
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: 50c7b30cd0
Your 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".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| ADD COLUMN reported_at timestamp with time zone DEFAULT now() NOT NULL; | ||
|
|
||
| UPDATE chat_diff_statuses | ||
| SET reported_at = updated_at; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
maybe it will be apparent once I scroll some more, but what is going to be the diff between those columns?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
So the chat_diff_statuses column can be updated separately from a PR being reported as existing. Name is maybe a bit shit. updated_at is our generic update thing. Happy to change this if too odd
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am using the Linear agent to discuss because I did find it odd and this is what tells me:
updated_at used to advance during background PR refreshes, so it could not safely order the primary ref. The change removes that update. After that, both timestamps advance only in UpsertChatDiffStatusReference, and both are initialized from the same value for existing rows.
So reported_at only makes sense if we want to preserve updated_at as a generic “last changed” timestamp and later allow non-report mutations to advance it again. As written, it’s redundant; ordering by updated_at would produce the same result.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Not sure what model is running underneath, but maybe it's made use of further in the stack and it just lacks the context
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Your Linear agent's summary is right about the history but misses the second half of the design. Here is the full reasoning (LLM-generated, Coder Agents):
reported_at exists so the primary ref (row 0 of the chat's diff statuses) changes only when the agent reports a ref. Ordering by updated_at breaks in two ways:
UpdateChatDiffStatusReferenceURL touches only the URL, and DiscoveryWriteDoesNotReorderPrimary covers this case.The result is that only the agent-report upsert sets reported_at. Refreshes, claims, backoffs and URL writes cannot reorder the primary. You are right that today both columns advance together in practice, and that updated_at ordering would give the same result right now. The separation is the invariant: updated_at stays free to advance on any future non-report mutation without silently changing which PR the chat displays.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
the migration to modify the keys looks safe, it's not a big table on df
| Rows | 6,942 live, 515 dead; about 75–140 new rows a day |
|---|---|
| Table data | 15.2 MB, but only about 1.7 MB is live data (242 B per row on average) |
| Indexes | 12.8 MB, of which 9.7 MB is the stale_at index |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We agree with the analysis and removed reported_at in 53bc0cd. The migration no longer adds the column, and the ordering now reads updated_at.
What carries the invariant instead: this PR also removes the updated_at = NOW() that main's worker refresh set, so updated_at now advances only when the agent reports a ref. Refreshes, claims, backoffs, PR clears and URL writes cannot reorder the primary. The rule to keep for future queries on this table: do not add updated_at to a write that must not change the primary ref.
This reply was generated by Coder Agents.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Authorize read on the parent chat. | ||
| _, err := q.GetChatByID(ctx, chatID) | ||
| if err != nil { | ||
| return nil, err |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
previously we were returning an empty object, but now it's nil, I guess it makes some difference for consumers, and ChatStusesByChatIDs still returns an empty array instead of nil
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Returning nil here does not change behavior. Only the error path returns nil, and callers do not read the result when err is not nil. GetChatDiffStatusesByChatIDs also returns nil on its error path. Its []database.ChatDiffStatus{} is the success result for an empty ID list, which main already had. When there are no rows, both queries return nil, because sqlc does not emit empty slices. All callers check len(), and diff_statuses is omitempty, so nil and empty give the same JSON. return nil, err is also the usual form in dbauthz.go.
This reply was generated by Coder Agents.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| case err == nil: | ||
| diffStatus = &status | ||
| case !xerrors.Is(err, sql.ErrNoRows): | ||
| diffStatuses, err := api.Database.GetChatDiffStatusesByChatID(ctx, chat.ID) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
doesn't this break current fe?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
ok, nvm 1562 handles it
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
probably should remove 1562-1564 if frontend handles arrays going forward
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We need to keep these lines. In this PR, diff_status is the only diff field in the API. If we remove them, the chat page does not show the PR, and TestGetChatDiffStatus fails. #29082 adds diff_statuses and marks diff_status as deprecated, but still fills it. The chat list, child chats, and watch events also fill it, and at the top of the stack the frontend still reads it from watch events. Removing the field is a breaking change to /api/v2, and multiple-PR support does not need it.
This reply was generated by Coder Agents.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
53bc0cd to
745eca7
Compare
2668b37 to
8ccd48b
Compare
9f3ded7 to
082e0ac
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Approved after schema simplification but imho the regex in the migration needs a test.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| -- Strip it with the same pattern as originCredentials in coderd/x/gitsync. | ||
| -- Each chat still has one row here, so this cannot create duplicate keys. | ||
| UPDATE chat_diff_statuses | ||
| SET git_remote_origin = regexp_replace(git_remote_origin, '^(https?://)[^/]*@', '\1') |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Imho this type of migration with regex needs a migration test to make sure we're handling edge cases correctly. The repo has prior art so should be doable for a bot.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added in ffb7a98. testMigration000606ChatDiffStatusOriginCredentials is a table test and a step in TestMigrationChain. It adds one chat for each case at 605, applies 606, and checks each origin.
@, http://, a port, no path, and an @ in the path after the credentials.@ only in the path, scp-style SSH, ssh://git@..., and an empty origin.When I changed the regex to [^/@]*@, the test failed on the case with @ in the password.
This reply was generated by Coder Agents.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
chat_diff_statuses held one row per chat, so a chat could only track one pull request at a time and a branch switch carried the previous PR's URL onto the new branch's data. Re-key the table to (chat_id, git_remote_origin, git_branch) so every ref the agent reports keeps its own row. Existing rows satisfy the new key without a rewrite: both columns are NOT NULL with '' defaults and the old key capped rows at one per chat. The worker claims stale rows by the full key. Retained refs keep polling on their own schedule, so no pause state or resume protocol is needed. Telemetry reports one diff row per chat via DISTINCT ON. The diff GET's discovery write now keys its upsert to the stored ref. Under the old single-row key an empty ref key was safe; under the composite key it would create a stray row the worker ignores. Old coderd instances must finish before this migration runs: their ON CONFLICT (chat_id) writes have no arbiter under the new key.
The primary ref is the most recently reported one, but its ordering column was updated_at, the generic mutation time. A discovery GET that resolves a changed PR URL late could bump the old ref's updated_at past a newer report and steal the primary back. The table now tracks reported_at, set only by reports. Primary ordering, the chat-list tiebreak, and telemetry dedup read it. Refreshes, claims, backoffs, and URL writes cannot reorder the primary anymore. The discovery write uses a dedicated query that never touches ordering columns.
A remote URL can contain a token, such as https://<token>@github.com/o/r.git. coder gitaskpass sends that URL as it is, and the server stored it in chat_diff_statuses.git_remote_origin. MarkStale now removes the user and password from HTTP(S) remotes before it stores them. Migration 000600 removes them from existing rows before it changes the primary key. SSH remotes do not change.
… in migration 000606
082e0ac to
ffb7a98
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.