You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
chatd: wake a chat when a background process exits or prints a matching line #248
Part of moving the pstack lead ("Pstack General", Xum workspace 8ac7791132) to a Coder Agents chat on this fork.
Gap
execute can run a command in the background and process_output reads it, but nothing wakes the chat when that process exits or prints a line. wait_for_events watches only direct children and one GitHub pull request (waitForEventsArgs, coderd/x/chatd/fork_wait_for_events.go:37).
The lead and ops end their turns on background watchers and get woken by them:
Workspace
Background bash with a monitor
Monitor wakes
Lead
358
250
Fork ops
not counted
903
The watchers are not all pull requests: "Deploy watcher" (152 runs, autodeploy log and buildinfo), fork-ci on main, slot guards, Codex verdict watchers and long validation runs. schedule_wakeup polling is the only substitute, at one model turn per poll and against the limit of 288 wake-up runs per chat each 24 hours.
Wanted
wait_for_events takes background process IDs from execute.
The chat wakes when a watched process exits, with its exit code and the tail of its output.
Optional: a line pattern that wakes the chat on a matching output line, with a cool-down and a maximum number of events.
The wake-up never interrupts a turn, as today.
Acceptance
A chat starts sleep 90; echo DONE in the background, calls wait_for_events and ends its turn. It gets one message after the exit, with exit code 0 and DONE.
A watch on a process that already exited wakes the chat at once.
The watch survives a coderd restart, or the chat gets a message that the watch was lost.
Status: #263 (PR1, wake on background process exit) is READY on head 63e228f: fork-ci green, Codex clean, 0 open threads, dev-build UAT PASS 5/5 (including the coderd restart case). Output-pattern wakes and the site status pill follow in later PRs.
#269 merged as 72d8af0. Follow-ups from its Codex review, kept out of that PR:
Line positions after the agent shortens output. When the agent's head/tail buffer drops bytes or shortens long lines, processNewLines maps the shown output back to original byte positions with a fixed offset. The cursor can then land past a matching line, so later matches are skipped, and a line crossing the head boundary can count as complete. A fix needs the agent to return raw byte offsets in ProcessOutputResponse (coderd/x/chatd/fork_process_events.go, processNewLines).
A failed match message is dropped when the process ends. If sending a match message fails and the process exits (or the watch is lost) before the next poll, the next poll sends only the exit message and completes the entry, so the matched batch never arrives as its own message. The exit tail still shows it unless the output is long (processWakeupText, the output.Running branch).
Windows line endings. A line read from \r\n output keeps its trailing \r, so end-anchored patterns such as ^READY$ never match. Strip one trailing \r before matching and display (processNewLines).
Starting PR3: the site UI for process wake-ups, including the status pill deferred from #263.
W15 status: PR3 is open as #270 (site UI for process wake-ups, which includes the pill P2 deferred from #263). Head is f62e780da9. Host pnpm check, tsc and the targeted Vitest run (309 tests) passed, and frontend-deep-review has no blocking or should-fix findings left. Next: fork-ci, Codex review and :3100 UAT through Fork ops.
W15 status: #270 is READY at f62e780da9. fork-ci passed, Codex found no major issues, and Fork ops' :3100 UAT passed 4/4 (process card with a pattern, status pill text, two processes, child-agent regression). It's waiting for the lead to merge.
The three open PR2 follow-ups (raw byte offsets, replaying a failed match message, CRLF) are in this comment. I'm leaving the issue open for Mike to close.
Done. #263, #269 and #270 are merged, and main 0d8bea4783 is deployed to the daily server, where it passed the post-deploy checks. The three PR2 follow-ups are listed in this comment. The ARCHITECTURE.md TODOs from #263 and #269 are being filled in by a separate docs PR.
Activity
ibetitsmike commentedon Nov 12, 2026
Tracked in #255.
ibetitsmike commentedon Nov 13, 2026
W15: opened #263 (PR 1 of 3: process exit wake-ups for
wait_for_events). Output-pattern wake-ups and the UI follow.ibetitsmike commentedon Nov 13, 2026
Status: #263 (PR1, wake on background process exit) is READY on head 63e228f: fork-ci green, Codex clean, 0 open threads, dev-build UAT PASS 5/5 (including the coderd restart case). Output-pattern wakes and the site status pill follow in later PRs.
ibetitsmike commentedon Nov 13, 2026
Status: #263 (PR1, wake on process exit) merged as addead5. Starting PR2: output-pattern wake-ups.
ibetitsmike commentedon Nov 13, 2026
Status: opened #269 (PR2, wake on matching output lines of a watched process).
ibetitsmike commentedon Nov 13, 2026
W15: sent READY for #269 (output-pattern wake-ups) at 413c4bb: fork-ci green, Codex clean, 0 open threads, container UAT PASS.
ibetitsmike commentedon Nov 13, 2026
#269 merged as 72d8af0. Follow-ups from its Codex review, kept out of that PR:
processNewLinesmaps the shown output back to original byte positions with a fixed offset. The cursor can then land past a matching line, so later matches are skipped, and a line crossing the head boundary can count as complete. A fix needs the agent to return raw byte offsets inProcessOutputResponse(coderd/x/chatd/fork_process_events.go,processNewLines).processWakeupText, theoutput.Runningbranch).\r\noutput keeps its trailing\r, so end-anchored patterns such as^READY$never match. Strip one trailing\rbefore matching and display (processNewLines).Starting PR3: the site UI for process wake-ups, including the status pill deferred from #263.
ibetitsmike commentedon Nov 13, 2026
W15 status: PR3 is open as #270 (site UI for process wake-ups, which includes the pill P2 deferred from #263). Head is
f62e780da9. Hostpnpm check,tscand the targeted Vitest run (309 tests) passed, and frontend-deep-review has no blocking or should-fix findings left. Next: fork-ci, Codex review and :3100 UAT through Fork ops.ibetitsmike commentedon Nov 13, 2026
W15 status: #270 is READY at
f62e780da9. fork-ci passed, Codex found no major issues, and Fork ops' :3100 UAT passed 4/4 (process card with a pattern, status pill text, two processes, child-agent regression). It's waiting for the lead to merge.ibetitsmike commentedon Nov 13, 2026
W15 closing status: all three PRs for process wake-ups are merged.
0d8bea4783)The three open PR2 follow-ups (raw byte offsets, replaying a failed match message, CRLF) are in this comment. I'm leaving the issue open for Mike to close.
ibetitsmike commentedon Nov 13, 2026
Done. #263, #269 and #270 are merged, and main
0d8bea4783is deployed to the daily server, where it passed the post-deploy checks. The three PR2 follow-ups are listed in this comment. The ARCHITECTURE.md TODOs from #263 and #269 are being filled in by a separate docs PR.