Repository navigation
perf(chatd): refetch fork panels on fork_change watch events - #386
Conversation
Questions, wake-ups, workflow runs and workflow logs now publish a fork_change event on the owner's chat watch channel at the commit points chatd owns. The site can refetch a panel on the event instead of polling it every few seconds. Refs #304.
The agents layout routes fork_change events from the chat watch socket to the panel queries they name, throttled per query, and refetches every panel when the socket opens. The panel polls become a 60 s resync, and the family capacity poll a 30 s one. Closes #304.
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0e7f10175
ℹ️ 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".
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0e7f10175
ℹ️ 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".
The embed route renders outside AgentsPageLayout, so it now opens its own chat watch socket for fork_change events. The wake-ups query polls at 30 s while an events wake-up is active, since its empty polls move next_run_at without an event. Addresses the Codex review of #386.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7439fadec
ℹ️ 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".
@codex review |
|
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 at head Gates on this exact head:
Tests I ran on
Review notes:
Not exercised: the network view of an idle chat page on a running server over several minutes, and the statement-per-minute effect, which the PR body estimates against the #304 numbers. |
Closes #304
What changed
chatd now publishes a
fork_changeevent on the chat watch stream when state behind a fork panel changes, and the agents page refetches the panel the event names instead of polling it every few seconds.Server (
coderd/x/chatd/fork_panel_events.go,codersdk/fork_chat_watch.go)fork_change. It reusesChatWatchEventand the existing pubsub path:pubsub.ChatWatchEventChannel(ownerID), i.e.chat:owner:{owner_id}.Chatis left empty; the payload isfork_change: {chat_id, root_chat_id, facets, workflow_run_id?}.questions:recordDescendantQuestion.wakeups: wake-up created (schedule_wakeup,wait_for_events,/loop), paused, resumed or canceled through the API, delivery sent, failed or finished. An events poll that finds nothing publishes nothing.workflows: every journal write infork_workflow_journal.gothat changed a row (run insert, status, phases, claim, step insert, update, report, reuse, close of open steps). A write that matched no row publishes nothing.workflow_logs: the journal's log write, at most every 2 s per run.coderd/x/plugins/delivery.goignores the new kind, so plugin event delivery is unchanged.chat_mutations.go. Prose incoderd/x/chatd/ARCHITECTURE.mdunder "Fork panel events".Site (
site/src/api/queries/forkChatWatch.ts,AgentsPageLayout.tsx)createForkChatWatch. Afork_changeevent invalidates only the keys its facets name, and returns early so it never reaches the chat list merge or cancels a list refetch.status_change,createdanddeletedof a descendant invalidate the family capacity and questions of its root (the issue's "treat it as family").deletedalso invalidates the chat's wake-ups.invalidateQueriesrefetches only mounted queries.forkPanelResyncInterval= 60 s. Family capacity stays at 30 s (see below). Wake-ups poll at 30 s, as on main, while an active events wake-up is listed: its empty polls movenext_run_atand publish nothing./agents/:agentId/embed) renders outsideAgentsPageLayout, so it mountsuseForkChatWatch, which opens its own watch socket for the fork events once signed in.Statements per minute
Per-call costs from #304: questions 3, runs list 6, run detail 6, family up to 6, wake-ups 3.
With an active events wake-up, wake-ups stay at their main cost (6 per minute instead of 3). Between changes an open page now costs 12 to 30 statements per minute instead of 54 to 190, per tab. The one case that does not shrink is the run detail while a step streams logs: it refetches at the 3 s throttle, about the old 3 s poll, but only while logs actually change. Moving logs onto a stream is out of scope here.
Choices
chat. The existing handler merges nothing for it. Theawait_chattoolsdk path matches events by chat ID, which an empty chat never matches.questionsevent. The client refetches the root's questions on every descendant status event, which covers the answer moving the child out of waiting.chatWorkflowRunsKey(chatId)key. This PR changes only the intervals and key construction inforkWorkflows.ts; whichever lands second merges main.Size
Outside generated files the diff is about 1,245 changed lines: about 520 of code and docs, 725 of tests (
forkChatWatch.test.tsalone is 362). It is not stacked: fork-ci runs only for PRs based onmain, and the server half alone would publish events nothing reads.Out of scope
Tests
flock ~/.fork-go.lock go test ./coderd/x/chatd/... ./codersdk/ -count=1: pass.TestForkChangeEventssubscribes to the owner's watch channel and asserts onefork_changeper write, with the right facet, chat, root and run, for a descendant question, a scheduled wake-up and its pause, and workflow journal writes (run insert, step insert, step update, logs, run status). A step update that matches no row publishes nothing. It fails with the publish calls removed.flock ~/.fork-go.lock go test ./coderd/x/plugins/ -count=1: pass (delivery ignoresfork_change).pnpm exec vitest run --project unitsrc/pages/AgentsPage src/api/queries: 197 files, 3443 passed, 2 skipped.forkChatWatch.test.ts: aquestionsevent invalidates that root's questions query and no other fork query; each facet maps to its keys; throttle, dispose and open behavior; each panel query does not poll at the old interval and refetches at the resync (fails with a 5 s interval), including the 30 s wake-ups poll with an active events wake-up.hooks/useForkChatWatch.test.tsx: the embed hook routes a fork_change event and the socket open to the panel queries, closes the socket on unmount, and opens none while disabled.AgentEmbedPage/AgentEmbedPage.test.tsx: the embed route publishes aworkflow_logsfork_change on the mocked socket and the run query is invalidated (fails without theuseForkChatWatchline).AgentsPageLayout.test.tsx: afork_changeevent during an in-flight chat list refetch invalidates the wake-ups query and does not cancel the refetch (fails without the early return); socket open invalidates the panels (fails withoutonOpen).pnpm check,pnpm lint:check,pnpm lint:oxlint,pnpm lint:types,pnpm lint:circular-deps: pass.pnpm lint:compilerfails onForkHtmlAttachmentViewer.tsx: onFrameLoadandknipreportschatPinnedSkillsKeyandexcludedPluginPacksKey; both are on main and outside this diff.make genoutput is committed (apidoc,docs/reference/api,typesGenerated.ts).Not verified