Skip to content

pstack W5: loops and wake-ups #11

Closed

Description

@ibetitsmike

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.

  1. chatd.chat_wakeups and chat_wakeup_runs (plan 3.1); a worker that claims due rows with FOR UPDATE SKIP LOCKED on any replica and sends through chatstate SendMessage (transitions.go:491) as the owner with busy_behavior queue, 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.
  2. schedule_wakeup tool and /loop slash command (delay, interval, cron, expiry, max runs).
  3. wait_for_events: child terminal, PR review, comment or merge, CI change; polling only.
  4. 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_user through Coder notifications, rate limited.
  5. UI: list, pause, delete; archive cancels. Audit entries (R4.7).

Acceptance (PRD 6.4).

  • A /loop 5m chat 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

  1. added
    pstack-parity
    on Nov 8, 2026
  2. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum posted this on behalf of @ibetitsmike.

    W5 PR1 opened: #82 (wake-up tables, queries, experiment fork-chat-wakeups).

  3. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    W5: sent READY for #82 at f92aa5b (fork-ci green, Codex clean, 0 open threads).

    Xum posted this on behalf of @ibetitsmike.

  4. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    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-worker and opens as a PR once #82 merges. PR3 (schedule_wakeup tool and /loop) is in implementation.

    Xum posted this on behalf of @ibetitsmike.

  5. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    W5 status: #82, #91, #93 and #121 are merged. #106 (wait_for_events for child agents) has a fix for the Codex finding and waits for fork-ci and a new Codex review. #115 (caps and notify_user), #131 (pull request events), #133 (/loop and 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 for schedule_wakeup and wait_for_events come after #146.

    Xum posted this on behalf of @ibetitsmike.

  6. ibetitsmike commented on Nov 11, 2026

    @ibetitsmike
    OwnerAuthor

    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/coder binary with fork-chat-wakeups on) and the oMLX GLM-5.3-Flash model. None of these ran on the daily server or on main. 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 5m runs three turns in 15 minutes across a server restart: partial

    The three turns and the restart were proven separately, in two windows on the same chat. No single 15-minute window had both.

    • PR: feat(coderd/x/chatd): add the schedule_wakeup tool and the /loop command #93 (/loop and schedule_wakeup). Commit 187991a213 (the merged head is 54b8b8195f). Evidence: .mux-uat/pr3-round-1/02-check1-loop.txt and 03-check2-restart.txt.
    • Chat 2653c1d5-dc79-436c-8072-e31883f2441b. The message /loop 5m reply with the word PONG and nothing else was sent at 02:38:57Z on 2026-11-10.
    • Three turns: PONG replies at 02:39:25, 02:44:37 and 02:49:17Z. The two wake-up runs were delivered at 02:44:11 and 02:49:11Z, so three turns came in under 11 minutes. The wake-up row has interval_seconds=300, and next_run_at follows the schedule exactly.
    • Restart: the planned kill at T0+6m landed late, at T0+700s (02:50:37Z), after the third turn had already finished. A later window on the same chat and database did span a due slot. The server was down from 02:58:52 to 03:01:00Z, which covered the 02:58:57 slot.
      • On restart that missed slot was delivered exactly once, at 03:00:59.43Z, with run_key equal to the scheduled time.
      • There was no catch-up burst, and the 03:03:57 slot fired on schedule.
    • Supporting evidence: the worker UAT for feat(coderd/x/chatd): deliver due chat wake-ups to idle chats #91 at commit 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. In 09-kill-mid-turn.txt, a replica killed mid-turn re-ran that turn after restart, and the wake-up was then delivered exactly once.
    • Gap: no single run shows three /loop 5m turns 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

    • PR: feat(coderd/x/chatd): wake a chat when its child agents finish #106 (wake a chat when its child agents finish). Commit b20e3c2ace (the merged head is ffdb8baeb7). Evidence: .mux-uat/pr4-round-1/10-run2-*.txt, 11-run2-final.txt and 11-run2-messages-api.json.
    • Coordinator chat dc732487-046b-4637-802e-7bb1a23adf2c (run 2). It called spawn_agent 3 times and wait_for_events once, then ended its turn at 03:09:06Z with "Spawned all three children and wait_for_events is armed".
    • What happened: the chat got exactly 4 user messages: the prompt plus 3 wake messages, one per child and each naming it, with no human message in between. There were 3 delivered runs (child_done:<id>), and the wake-up ended completed/done.
      • Each wake was created only after the previous turn had finished: 03:09:06 to 03:09:08, 03:12:45 to 03:12:53, and 03:17:56 to 03:18:09Z.
      • The coordinator called wait_agent once per wake and replied "child-one: ONE" (03:12:45), "child-two: TWO" (03:17:56) and "child-three: THREE" (03:21:44Z).
    • Caveat: the trivial children had finished before wait_for_events was 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

    • PR: feat(coderd/x/chatd): cap chat wake-ups per day and add notify_user #115 (daily wake-up caps and notify_user). Commit 9e5c73949e (the merged head is 531fafaecd). Evidence: .mux-uat/pr5-round-1/10-s1-runcap-setup.txt, 11-s1-runcap-result.txt and 30-timeline-ABC.txt.
    • Chat A, 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.
    • What happened: the loop delivered exactly one more run (05:26:52Z, bringing the 24-hour count to 288).
      • On the next tick (05:28:52Z) it paused with daily_run_cap and wrote no run and no message. No further turns ran through 05:53Z.
      • The chat got exactly one notification, "Chat wake-up paused", with the text A wake-up of chat "pr5-runcap" is paused: it reached the daily limit of 288 runs. It was visible in GET /api/v2/notifications/inbox.
      • A second wake-up on the same chat paused without a second notification, because of the dedupe.
    • Other caps: the same round also showed the per-chat spend cap (chat ceb07a38-26cc-419b-83db-9ac63a314f1c), the organization run cap and the organization spend cap (chat 30ac339a-4031-435c-825c-3aa21ad46014). Each paused its loop and sent one notification.
    • Caveat: the cap was reached by seeding runs, not by 288 real runs, and only the inbox notification method was configured.

    Xum posted this on behalf of @ibetitsmike.

  7. ibetitsmike commented on Nov 11, 2026

    @ibetitsmike
    OwnerAuthor

    Xum (AI agent) closed this on behalf of @ibetitsmike.

    Acceptance (PRD 6.4) is met. W5's evidence map is in #11 (comment).

    1. /loop 5m runs three turns in 15 minutes across a server restart. This check ran on the daily server, with the 3839333 autodeploy as the restart. Chat ba4fccf9-3b8f-496b-9f01-c4263a3b5442 (agent-uat) sent /loop 5m reply with the word PONG and nothing else at 01:10:34Z on 2026-11-11. Wake-up af8243c8 has interval_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. Its chat_wakeup_runs row was delivered at 01:25:38Z, PONG came at 01:25:40Z, and next_run_at moved 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.
    2. A coordinator that ends its turn after three spawns wakes once per child completion, with no user message. Covered by the feat(coderd/x/chatd): wake a chat when its child agents finish #106 UAT (coordinator dc732487: 3 spawns, the turn ended, 3 wakes with no human message). One limit: the children finished before wait_for_events, and the run passed child IDs explicitly, so the default child set wasn't exercised live.
    3. A loop at its daily cap stops and the user gets a notification. Covered by the feat(coderd/x/chatd): cap chat wake-ups per day and add notify_user #115 UAT (chat aec4675e: daily_run_cap pause 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pstack-parity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions