Repository navigation
Description
Xum created this issue on behalf of @ibetitsmike.
Part of #4.
Workspace brief from the pstack parity plan (local plan page "Running pstack on the Coder Agents Fork"; the PRD is local to Mike's Mac and not reproduced here). Claim numbers such as 1.3 or shared.2 refer to the plan page.
W5 · Loops and wake-ups · mike/chat-wakeups
Task. PRD 6.4 and R11.1 notify_user.
Background. coder#30412 removed chat automations with destructive migrations 000615 and 000616, a credential scope revocation and message provenance columns. No source states the reason. The upstream queue stack (plan shared.5) changes queue delivery: coder#30073 adds busy_behavior, coder#31153 adds one delivery helper and coder#31156 replaces PromoteQueuedMessage with SteerQueuedMessage. W0 merges it before W5 starts. Child turns end at chatd.go:2179; PR and CI status come from the gitsync worker (coderd/x/gitsync/worker.go:181) through PublishDiffStatusChange (chatd.go:1582).
Scope.
0. Before the schema PR, read coder#30412, its commits and linked issues for why automations went away, without contacting upstream (Mike, 2026-11-09: upstream is only a sync source). Put what you found, or "reason not stated", in the PR description.
chatd.chat_wakeupsandchat_wakeup_runs(plan 3.1); a worker that claims due rows withFOR UPDATE SKIP LOCKEDon any replica and sends throughchatstateSendMessage(transitions.go:491) as the owner withbusy_behaviorqueue, so the end of a busy turn (FinishTurn,:1830) delivers it and it never steers into a running turn. Line numbers move after the queue-stack merge.schedule_wakeuptool and/loopslash command (delay, interval, cron, expiry, max runs).wait_for_events: child terminal, PR review, comment or merge, CI change; polling only.- Caps (R4.6): per-chat and per-organization runs and spend per day, checked before the turn; pause and notify; pause on hook failure.
notify_userthrough Coder notifications, rate limited. - UI: list, pause, delete; archive cancels. Audit entries (R4.7).
Acceptance (PRD 6.4).
- A
/loop 5mchat runs three turns in 15 minutes across a server restart on the dev instance. - A coordinator that ends its turn after three spawns wakes once per child completion, with no user message.
- A loop at its daily cap stops and the user gets a notification.
Constraints. Experiment fork-chat-wakeups. No API key scopes, no columns on upstream tables. Starts after W2 and W0's queue-stack merge.
Rules for every workspace
| Topic | Rule |
|---|---|
| Runner | One Xum workspace per brief (W0 runs as W0a and W0b), started from fork main at its wave start. Every implementation runs implement-flow with the workstream issue as its input and the brief as the plan. |
| Branches | mike/<topic> for the workspace; stacked PR branches mike/<topic>-<n>-<slug>. Local name equals remote name. Never push to main. |
| PR size | 500 changed lines at most per PR, generated code excepted (reviewer-friendly-pr). Stack with gh stack; the extension is not installed on the Mac today (gh extension install github/gh-stack), else use explicit-base PRs. |
| Schema | Fork tables are chatd graph nodes: go run ./coderd/database/migrations/chatdmig/cmd/chatdmig new <name> -requires <node or upstream:name>. Never edit a node that ran. No edits to dump.sql, queries.sql.go, querier.go, dbmock or numbered migrations. |
| Queries | coderd/database/forkdb only (created by W0). Every method goes through the forkdb authz wrapper. A forkdb write that belongs with an upstream write runs in the same transaction, through the W0 accessor (database.Store exposes only InTx, coderd/database/db.go:22-31). |
| Authorization | Chat-owned rows authorize through the owning chat (dbauthz.go:6513-6522 pattern). Agent and plugin rows reuse the skill RBAC objects. No new RBAC resources, no new API key scopes. Tools run as the chatd subject, which can read and update every chat (dbauthz.go:807-817): a tool that touches a chat other than its own runs as the owner (asOwner, chattool/listtemplates.go:437-443). |
| Upstream files | One hook line per hot file (plan shared.2). Logic lives in new fork files. Hot files: turn_environment.go, chatd.go, subagent*.go, codersdk/chats.go, deployment.go, dbauthz.go, chat_routes.go, AgentChatInput, AgentChatPageView. |
| Open upstream PRs | If a workspace needs an open coder/coder PR, W0 or W7 merges its branch into the fork with a merge commit. Its migrations go through chatdmig route into the chatd schema. Sync conflicts are solved later (Mike, 2026-11-08). |
| Flags | Each feature is behind its fork-* experiment in codersdk/fork_experiments.go. With the flag off, tool lists, routes and UI match upstream. |
| API | Swagger annotations on new public endpoints. Audited types update enterprise/audit/table.go. |
| chatd docs | coderd/x/chatd/ARCHITECTURE.md gets TODO lines only. Mike writes the text. |
| Validation | Go suites run in Colima: a postgres:17 container, plus golang:<go.mod version>-bookworm --network container:<pg> with volumes coder-gen-gomod and coder-gen-gocache and postgresql-client-17 from PGDG. chatdmig tests use CHATDMIG_TEST_DATABASE_URL='postgres://[email protected]:5432/postgres?sslmode=disable'. Never create a postgres role on the live Postgres. Frontend: site/AGENTS.md commands plus frontend-deep-review for any site/ diff. |
| Review | implement-flow ends with codex-review-loop; Codex is installed (2026-11-08). If @codex review gets no reply within 30 minutes, tell the lead and run code-quality-review with Opus until Codex answers. Mike (2026-11-09): fix real defects in the PR's own change; drop scope creep and defensive bikeshedding with a one-line reply and a resolved thread, no follow-up issue. Upstream is only a sync source: never report or file anything upstream. |
| UAT | coder-agents-uat through Coder MCP on the local deployment (http://127.0.0.1:3000, templates devcontainer or docker, RUNBOOK "Running a branch in a dev container workspace"). The remote agent runs scripts/develop.sh for the branch inside its workspace (plan decision uat). Never coder-local use a branch build: that replaces Mike's daily server. |
| Ready | When a PR meets the merge bar, send the lead (task_send_message to 8ac7791132) READY #<pr> <head sha> with the CI, Codex, UAT and open-thread evidence, then wait. Never merge yourself. |
| Merge | The lead merges (Mike, 2026-11-08). Merge bar: green fork-ci on the exact head, a clean Codex verdict, or Codex findings that were all fixed or dropped under the scope rule (the lead confirms each drop), no unresolved threads, UAT PASS on the head or on a SHA whose later commits only answer review, and a lead review of the diff against the brief. Squash, except sync and upstream stack PRs, which take a merge commit. A merge to fork main deploys Mike's daily server through autodeploy within about 5 minutes plus a drain of up to 30 minutes, so the lead merges one PR at a time and waits until Fork ops reports the deploy healthy. Experiments stay off on that server until Mike enables them. |
| Follow-ups | A defect in merged code or on the daily server becomes an issue in ibetitsmike/coder with label followup. Fork ops triages it; an accepted one gets its own workspace running implement-flow. |
Activity
ibetitsmike commentedon Nov 9, 2026
W5 PR1 opened: #82 (wake-up tables, queries, experiment
fork-chat-wakeups).ibetitsmike commentedon Nov 10, 2026
W5: sent READY for #82 at f92aa5b (fork-ci green, Codex clean, 0 open threads).
ibetitsmike commentedon Nov 10, 2026
W5 status: #82 (schema) is READY at a5068f2: fork-ci green, Codex clean, 0 open threads, 11-node migration UAT passed. PR2 (wake-up worker) is pushed on
mike/chat-wakeups-2-workerand opens as a PR once #82 merges. PR3 (schedule_wakeuptool and/loop) is in implementation.feat: add chat wake-up tables and queries (#82)
feat(coderd/x/chatd): deliver due chat wake-ups to idle chats (#91)
feat(coderd/x/chatd): add the schedule_wakeup tool and the /loop comm…
ibetitsmike commentedon Nov 10, 2026
W5 status: #82, #91, #93 and #121 are merged. #106 (
wait_for_eventsfor child agents) has a fix for the Codex finding and waits for fork-ci and a new Codex review. #115 (caps andnotify_user), #131 (pull request events), #133 (/loopand archive) and #134 (wake-ups API) follow in that order. #146 (wake-ups pill in the composer) is open on top of #134. Tool cards forschedule_wakeupandwait_for_eventscome after #146.feat(coderd/x/chatd): wake a chat when its child agents finish (#106)
feat(coderd/x/chatd): cap chat wake-ups per day and add notify_user (#…
feat(coderd): wake a chat on pull request activity (#131)
feat(coderd): cancel wake-ups on archive and reject invalid /loop com…
feat: manage a chat's wake-ups through the API (#134)
feat(site/src): list, pause and cancel chat wake-ups in the composer (#…
feat(site/src): show the wake-up tools as chat tool cards (#149)
ibetitsmike commentedon Nov 11, 2026
Acceptance evidence map (PRD 6.4)
This comment lists existing UAT evidence only; I ran nothing new for it. Every run below used a throwaway fork server built from the PR branch head at the listed commit (Colima containers: postgres:17 plus a
go build ./enterprise/cmd/coderbinary withfork-chat-wakeupson) and the oMLX GLM-5.3-Flash model. None of these ran on the daily server or onmain. Each PR's later review commits were accepted against this UAT when it merged. The evidence files are in the W5 workspace under.mux-uat/<round>/.1.
/loop 5mruns three turns in 15 minutes across a server restart: partialThe three turns and the restart were proven separately, in two windows on the same chat. No single 15-minute window had both.
/loopandschedule_wakeup). Commit187991a213(the merged head is54b8b8195f). Evidence:.mux-uat/pr3-round-1/02-check1-loop.txtand03-check2-restart.txt.2653c1d5-dc79-436c-8072-e31883f2441b. The message/loop 5m reply with the word PONG and nothing elsewas sent at 02:38:57Z on 2026-11-10.interval_seconds=300, andnext_run_atfollows the schedule exactly.run_keyequal to the scheduled time.d276e14121(.mux-uat/round-1/07-kill-restart.txt) ran a 60-second interval wake-up inserted with psql. After a ~170 s outage with 3 missed slots, it delivered exactly one run, and the next slot fired on schedule. In09-kill-mid-turn.txt, a replica killed mid-turn re-ran that turn after restart, and the wake-up was then delivered exactly once./loop 5mturns within 15 minutes with a restart between two of them.2. A coordinator that ends its turn after three spawns wakes once per child completion, with no user message: covered
b20e3c2ace(the merged head isffdb8baeb7). Evidence:.mux-uat/pr4-round-1/10-run2-*.txt,11-run2-final.txtand11-run2-messages-api.json.dc732487-046b-4637-802e-7bb1a23adf2c(run 2). It calledspawn_agent3 times andwait_for_eventsonce, then ended its turn at 03:09:06Z with "Spawned all three children and wait_for_events is armed".deliveredruns (child_done:<id>), and the wake-up endedcompleted/done.wait_agentonce per wake and replied "child-one: ONE" (03:12:45), "child-two: TWO" (03:17:56) and "child-three: THREE" (03:21:44Z).wait_for_eventswas called, and the call passed their IDs explicitly. The wakes therefore arrived one per child, each after the coordinator's previous turn, rather than at the moment each child finished. The default child set (no IDs) was not exercised live. Run 1 (coord-run1.id) showed the same 3 wakes, but two of its turns hit an oMLX prefill memory guard, which was an environment issue.3. A loop at its daily cap stops, and the user gets a notification: covered
notify_user). Commit9e5c73949e(the merged head is531fafaecd). Evidence:.mux-uat/pr5-round-1/10-s1-runcap-setup.txt,11-s1-runcap-result.txtand30-timeline-ABC.txt.aec4675e-c3c6-4b23-805d-fc7de6d7c4a3(pr5-runcap), ran/loop 1m reply with the single word PING. 287 delivered runs from the last 24 hours were seeded with psql, plus 50 older runs that must not count.daily_run_capand wrote no run and no message. No further turns ran through 05:53Z.A wake-up of chat "pr5-runcap" is paused: it reached the daily limit of 288 runs.It was visible inGET /api/v2/notifications/inbox.ceb07a38-26cc-419b-83db-9ac63a314f1c), the organization run cap and the organization spend cap (chat30ac339a-4031-435c-825c-3aa21ad46014). Each paused its loop and sent one notification.ibetitsmike commentedon Nov 11, 2026
Acceptance (PRD 6.4) is met. W5's evidence map is in #11 (comment).
/loop 5mruns three turns in 15 minutes across a server restart. This check ran on the daily server, with the 3839333 autodeploy as the restart. Chatba4fccf9-3b8f-496b-9f01-c4263a3b5442(agent-uat) sent/loop 5m reply with the word PONG and nothing elseat 01:10:34Z on 2026-11-11. Wake-upaf8243c8hasinterval_seconds=300. Its wake-up messages arrived at 01:15:47 and 01:20:47Z, and the model replied at 01:15:53 and 01:20:59Z. The server went down at 01:25:31Z, while the 01:25:34Z slot was due, and the slot ran once after startup. Itschat_wakeup_runsrow was delivered at 01:25:38Z, PONG came at 01:25:40Z, andnext_run_atmoved on to 01:30:34Z. There was no burst and no lost slot. That is three turns in under 10 minutes with the restart between the second and third.dc732487: 3 spawns, the turn ended, 3 wakes with no human message). One limit: the children finished beforewait_for_events, and the run passed child IDs explicitly, so the default child set wasn't exercised live.aec4675e:daily_run_cappause plus one inbox notification). The cap was reached by seeding 287 runs rather than running for 24 hours.Shipped: #82, #91, #93, #106, #121, #115, #131, #133, #134, #146, #149, all behind
fork-chat-wakeups. The open owner items are the chatd ARCHITECTURE.md wake-ups TODOs from #133 and #134.