Skip to content

feat: the workspace agent reports chat process events - #376

Merged
ibetitsmike merged 11 commits into
mainfrom
mike/issue-295-process-events
Nov 17, 2026
Merged

ibetitsmike merged 11 commits into
mainfrom
mike/issue-295-process-events

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

Closes #295

Part of #347: removing the process read from deliverEventsWakeup, with wakeupReadFits and withWakeupDeadline, also resolves item 1 (a read that did not fit the time left returned nil and re-ran at once) and the quartz nit of item 5 (the delivery deadline used time.Now). #347 has its own PR for the rest.

The workspace agent now reports when chat background processes exit and when their output matches a pattern. chatd no longer dials the agent every 15 seconds. An agent that is offline can no longer delay the wake-ups of other chats.

What changed

  • Agent API RPC. ReportChatProcessEvents is added to agent/proto/agent.proto. It is served as its own fork DRPC service (agent/proto/fork_agent_drpc.go), so the numbered Agent API version stays at 2.16. Bumping the version would put a fork number into a sequence upstream owns and make every sync conflict. A coderd without the RPC answers with an unknown RPC error. The agent then logs at debug level and backs off.
  • Agent. agent/agentproc/fork_process_events.go queues one exit event for each process started with a chat ID. The event carries the code (-1 for a signal), the last 8 KiB of output and the exit time. agent/fork_process_events.go sends the queue over the Agent API connection in batches of up to 100. An event is removed only after coderd acks it, and failed calls retry with backoff from 1 s to 1 min. Whatever a lost connection left unacked goes out on the next connection. While a chat process runs and nothing waits for an ack, the agent sends two empty reports every 30 s. Each one sends back the acked_at of the response before it as last_acked_at, and coderd records that time, so an empty report tells coderd that every exit queued before that time of coderd was acked. Output-pattern watches are registered over the existing agent connection (POST /api/v0/processes/{id}/watch). The agent reads the output every second and reports new matching lines, subject to the cooldown. It does not count its reports: coderd merges several into one message, so the response names the output events that no open watch takes lines for (closed_output_events), and the agent stops those watches.
  • coderd. coderd/agentapi/fork_process_events.go fires the open watches that match the chat, process and reporting agent (FireChatProcessWatches), then pokes the waker for each chat. Events that match no watch change nothing. A delivery uses the fired payload it read as a guard (MarkChatWakeupWatchDelivered), so a report that lands during a delivery is not lost.
  • chatd. coderd/x/chatd/fork_process_events.go no longer reads processes on a tick or during a delivery. The tool first commits the watch rows, then registers them with the agent and reads the process state once in that same request. The exit fires its watch from whichever path comes first. Both paths write the same payload and fired_at keeps the first write, so the chat gets one message whichever order they run in. Every 5 minutes, a set-based sweep (MarkLostChatProcessWatches) fires as lost the watches whose workspace stopped or was rebuilt, or whose agent restarted after the watch began.
  • Storage. There is one new chatdmig node, 01a1e710-..._chat_wakeup_watches_open_process_idx (a partial index on open process watches). No existing node is edited.
  • Docs. I rewrote the fork sections of coderd/x/chatd/ARCHITECTURE.md and added ### Background process events. I also updated docs/fork/pstack-adapter.md.

Old agents (criterion 5)

An agent too old to report process events either has no ForkProcessEventsConn or answers the watch route with 404. In that case the tool fails the call with an error, and the tool description states the limit. I picked this over a capability flag because it is the honest and simple choice:

  • The chat learns at once that it must poll the process with schedule_wakeup or restart the workspace.
  • The alternative is a wake-up that silently waits until it expires.
  • It needs no new handshake field in the Agent API.

Experiment gating

The feature stays behind fork-chat-wakeups. The agent always reports, and coderd decides what to do with the report. With the experiment off, coderd/fork_process_events.go passes no options, and the handler acks every report without writing anything. Nothing creates or reads process watches when the experiment is off, so the old 15-second path did not need to survive.

Known limits

  • Restart detection compares the agent's started_at with the creation time of the watch. If the agent's clock runs far ahead of coderd's, a watch created right after the agent started can be marked lost.
  • At the expiry, the final poll of a process watch that no exit fired waits for the agent to say, at least 5 s after the expiry, that it holds no unacked event. A healthy agent says so every 30 s while a chat process runs, with two reports, so the wait can take one heartbeat more when the first report after the expiry carries an acked_at from before it. The poll waits at most 10 minutes; an agent that stays away or keeps failing its reports longer loses an exit it queued before the expiry.
  • The 5 s margin now covers only the time between a process exit and its queueing on the agent, since the recorded time is coderd's own ack time and not the time of receipt or an agent clock.
  • An exit time is whole seconds, from the upstream process info. A late final poll counts an exit by the end of its second, so an exit in the same second as the expiry is left out. Main did the same (processExitedBy compared ExitedAt+1).
  • Output reports are deduplicated by the agent's match time. The agent keeps that time increasing per watch, a microsecond past the last one when its clock goes back.
  • Watches created before this deploy have no output watch on the agent. They report exits only.
  • The agent queue holds at most 1000 events. Past the cap it drops the oldest output match first. If the queue holds only exits, a new exit is still queued but without its output tail, and a new output match is dropped. Exits are bounded at 10000: past that, the oldest exit is dropped, and its watch ends at the expiry without the exit. Reaching that needs 10000 chat processes to exit while coderd does not ack.
  • An agent keeps at most 4 output watches per process, one per wake-up. A fifth wake-up on the same process stops the oldest watch.
  • The output cool-down runs from the last message of the wake-up, as on main. The agent also waits the cool-down between its own reports of one watch.
  • Exits and output matches for a paused wake-up fire its watch and stay fired until it resumes. A canceled or delivered wake-up ignores them, and the agent still gets its ack.

Tests

All Go runs were done under flock ~/.fork-go.lock, on the tree rebased onto main 99d1b24aed, unless noted. After merging main 76b39d63c8 (#369) the chatd, forkdb, agentapi, agentproc and dbpurge packages and the dbauthz suite were run again at count=1 and passed, with no generate drift.

  • Acceptance criterion 1, agent: TestForkReportProcessExit checks that the exit is reported exactly once with its code. After a simulated failed ack, it checks that the exit is reported a second time. TestForkReportProcessEventsReconnect checks that the unacked events are resent on a new connection.
  • Acceptance criterion 2, agentapi: TestReportChatProcessEvents checks that an exit for a watched process sets fired_at and pokes the waker, and that an unwatched exit changes nothing.
  • Acceptance criterion 3, chatd: in TestWakeupProcessAgentUnreachable, every agent dial fails, yet an interval wake-up of another chat is delivered on the first pass. The poke delivers the exit with zero dials.
  • Acceptance criterion 4: TestWaitForEventsProcessExitOrder runs "watch row committed, process exits, state read" in both orders and asserts one message.
  • TestWakeupEventsProcessOutcomes adds the AgentRestarted and AgentStartedBefore cases to the lost-watch sweep tests.
  • Codex P1, an exit reported after the expiry: TestWakeupFinalPollProcesses checks that the final poll waits while the agent never said, or said only before expiry plus the margin, that it holds no unacked event. It completes once the agent said so after the margin, or once the 10-minute window has passed. In ReportAfterRetry, an exit from before the expiry that is reported after the first final poll is delivered once.
  • Codex P1 (second round), a report that keeps failing while heartbeats stay connected: the final poll no longer looks at connection timestamps. An empty report is the agent's heartbeat. The agent sends one every 30 s while a chat process runs and nothing waits for an ack, and coderd records it per watch (MarkChatProcessWatchesReported). TestForkReportProcessEventsHeartbeat checks that no empty report goes out while no chat process runs, that a pending exit whose ack was lost goes out before the empty report, and that the next tick sends another. TestReportChatProcessEvents checks that an empty report writes reported_at and pokes nobody. TestMarkChatProcessWatchesReported checks that only open, unended watches of active wake-ups on that agent are marked.
  • Codex P2, a resent output report counted against process_output_max_events: FireChatProcessWatches keeps the agent's match time in spec.output_at and ignores a report that is not newer. TestFireChatProcessWatches and TestReportChatProcessEventsOutputResent check that a resent report changes nothing, before and after a delivery, and that a later one still fires.
  • Codex third round (on e37ef8a451):
    • P1, an exit while the wake-up is paused was acked and lost: FireChatProcessWatches, MarkChatProcessWatchesReported and MarkLostChatProcessWatches now accept paused as well as active. TestWakeupEventsProcessExitWhilePaused reports an exit while paused, resumes, and checks one delivered message. TestFireChatProcessWatches and TestMarkChatProcessWatchesReported check that paused counts and canceled does not.
    • P2, a full queue dropped exits: TestForkEnqueueCap checks that an exit is never dropped, that the oldest output match goes first, and that an exit past the cap with only exits queued keeps its code but not its tail.
    • P2, a zero-omission separator was read as a line end: the output watch now reads the raw head and tail bytes (forkRaw) instead of the formatted output. TestForkNewLines, TestForkRaw and TestForkOutputWatchOpenLineAcrossHead check an open line that spans the head buffer.
    • P1, invalid UTF-8 broke the protobuf marshal and blocked the queue: output tails and matched lines go through strings.ToValidUTF8. TestForkInvalidUTF8 marshals a report built from invalid bytes.

Commands and results:

  • go test -count=20 -race -run TestFork ./agent/agentproc/: PASS
  • go test -count=20 -race -run TestReportChatProcessEvents ./coderd/agentapi/: PASS
  • go test -count=20 -race -run TestFireChatProcessWatches ./coderd/database/forkdb/: PASS
  • go test -count=20 -race -run 'TestWakeupProcess|TestWaitForEventsProcess|TestWakeupEventsProcess|TestProcess' ./coderd/x/chatd/: PASS
  • go test -count=1 ./coderd/x/chatd/: PASS
  • go test -count=1 ./coderd/database/forkdb/... ./coderd/agentapi/ ./agent/agentproc/: PASS
  • go test -count=1 -run TestMethodTestSuite ./coderd/database/dbauthz/: PASS
  • go test -count=1 -race -run 'TestWaitForEvents|TestWakeup|TestProcess' ./coderd/x/chatd/ (after the last edit): PASS
  • After the P1 fix, on head c97c875907: go test -count=1 ./coderd/x/chatd/ PASS. go test -count=20 -race -run 'TestWakeupFinalPollProcesses|TestWakeupEventsProcess|TestWakeupProcess|TestWaitForEventsProcess' ./coderd/x/chatd/ PASS.
  • After the second-round P1 and P2 fix, on the tree of the new head:
    • go test -count=1 ./coderd/x/chatd/: PASS
    • go test -count=1 -run TestMethodTestSuite ./coderd/database/dbauthz/: PASS
    • go test -count=20 -race -run TestFork ./agent/agentproc/: PASS
    • go test -count=20 -race -run TestReportChatProcessEvents ./coderd/agentapi/: PASS
    • go test -count=20 -race -run 'TestFireChatProcessWatches|TestMarkChatProcessWatchesReported' ./coderd/database/forkdb/: PASS
    • go test -count=20 -race -run 'TestWakeupFinalPollProcesses|TestWakeupEventsProcess|TestWakeupProcess|TestWaitForEventsProcess|TestProcess' ./coderd/x/chatd/: PASS
  • After the third-round fixes, on the tree of the new head:
    • go test -count=1 ./coderd/x/chatd/ ./coderd/database/forkdb/... ./coderd/agentapi/ ./agent/agentproc/ ./coderd/database/dbpurge/: PASS
    • go test -count=1 -run TestMethodTestSuite ./coderd/database/dbauthz/: PASS
    • go test -count=20 -race -run TestFork ./agent/agentproc/: PASS
    • go test -count=20 -race -run 'TestFireChatProcessWatches|TestMarkChatProcessWatchesReported' ./coderd/database/forkdb/: PASS
    • go test -count=20 -race -run 'TestWakeupEventsProcess|TestWakeupFinalPollProcesses|TestWaitForEventsProcess|TestWakeupProcess|TestProcess' ./coderd/x/chatd/: PASS
    • After merging main d310975509 (perf(coderd/x/chatd): pack path cache, one linkable plugins query, subscribe before a step wait #370): the chatd, forkdb, agentapi and agentproc packages at count=1 and the dbauthz suite again: PASS, with no generate drift.
  • After the fourth-round fixes and the merge of main 497bbb6a70 (perf: purge old fork rows and bound wake-up and report reads #368, perf(coderd/x/chatd): count notify_user sends in a fork table #369), on head 95b794c5a3, cold build cache: generate.sh no drift, chatdmig check ok, go build ./enterprise/cmd/coder ok, go vet ok, go test -count=1 ./coderd/x/chatd/ ./coderd/database/forkdb/... ./coderd/agentapi/ ./agent/agentproc/ ./coderd/database/dbpurge/ ./coderd/database/migrations/chatdmig/ PASS, dbauthz TestMethodTestSuite PASS, -count=20 -race on agentproc TestFork, forkdb TestFireChatProcessWatches|TestMarkChatProcessWatchesReported, chatd TestWakeupEventsProcess|TestWakeupFinalPollProcesses|TestWaitForEventsProcess|TestWakeupProcess|TestProcess and agentapi ReportChatProcessEvents PASS, new-code golangci 0 issues, make lint/markdown lint/emdash lint/style-claims lint/architecture pass. The merge kept both new chatdmig nodes of main and this PR side by side in sqlc.yaml; neither edits an existing node.
  • Codex fourth round (on eba9c4fdf3), three P2 findings, all regressions of this PR, fixed in f92b24b196:
    • The exit queue was unbounded. forkEnqueue now drops the oldest exit past 10000 exits. TestForkEnqueueCap fills the queue with 10000 exits, adds one more and checks that the oldest is gone and the new one is last.
    • A second wake-up on the same process replaced the agent output watch of a paused one. The agent now keeps one watch per wake-up, up to 4 per process. TestForkHandleWatchProcess/SameWakeupWatchesOnce checks that a repeat of one wake-up adds nothing, that other wake-ups each get a watch, and that a fifth stops the oldest.
    • The cool-down ran from the agent's report, not from the last message of the wake-up as on main. ListDueChatWakeups and the process case of the wake-up now skip fired output lines while last_run_at + output_cooldown_seconds is after now, and the run time is set to the end of the cool-down. TestWakeupEventsProcessOutputCooldown checks that lines fired during the cool-down are not due, that the run time is the cool-down end, and that they are delivered then in one message.
  • Codex fifth round (on 95b794c5a3), fixed in 0f7d6c5584 and 76108de735 (the limit case of TestFireChatProcessWatches). The proto messages changed again (OutputMatch.last removed, last_acked_at, acked_at and closed_output_events added); no agent with the earlier shape shipped.
    • P1, a heartbeat certified an exit that was in flight: coderd recorded the time of receipt, after the agent read its queue. Now every response carries acked_at, the next report sends it back, and coderd records min(last_acked_at, now); a report without it, the first of a connection, records nothing. TestForkReportProcessEventsHeartbeat checks two empty reports per tick, each with the acked_at of the response before it, and no last_acked_at before any ack. TestReportChatProcessEvents checks that a report without last_acked_at changes nothing, that one with it records that time and not the time of receipt, that a future one is cut to now, and that the response carries acked_at, with the experiment off too.
    • P1, the agent stopped an output watch after process_output_max_events reports, while coderd merges reports into fewer messages. The agent no longer counts; coderd answers with closed_output_events from ChatProcessWatchTakesLines. TestForkOutputWatch checks that the watch goes on after reports coderd does not close and ends when coderd closes it. TestReportChatProcessEventsOutputResent checks that a resent report is not closed, that a report for an unknown wake-up is closed by its index in a batch, and that a report after the exit is closed. TestFireChatProcessWatches checks ChatProcessWatchTakesLines for another wake-up, a watch at its limit and an ended watch.
    • P2, output report times went back with the clock: forkReportTime keeps them increasing. TestForkReportTime checks it.
    • P2, a stale queued exit could fire the watch of a new process with the same ID after the one-hour reap: a start drops the queued events of its chat and process ID. TestForkProcessIDReuse checks that the stale event of that chat goes and the one of another chat stays.
    • P2, the docs claimed a 2 KiB cut with a ... [truncated] marker: fixed to the 4 KiB cut after the match, with no marker.
    • P2, an exit in the second of the expiry is left out by a late final poll: not fixed, see Known limits. Main did the same.
    • On the new head, cold run of the suite below: generate.sh no drift, chatdmig check ok, build ok, vet ok, the five packages at count=1 PASS, dbauthz TestMethodTestSuite PASS, the four -count=20 -race runs PASS, new-code golangci 0 issues, the markdown lints pass.
  • go run ./coderd/database/migrations/chatdmig/cmd/chatdmig check: ok
  • go build ./enterprise/cmd/coder: ok
  • ./coderd/database/forkdb/generate.sh: no drift
  • golangci-lint --config=.golangci.new-code.yaml --new-from-merge-base=origin/main on the changed packages: 0 issues
  • make lint/markdown lint/emdash lint/style-claims lint/architecture lint/check-experiment-keys lint/migrations: pass (the last round reran lint/markdown lint/emdash lint/style-claims lint/architecture)

Negative controls (patched, saw FAIL, restored and checked with cmp):

  • If the agent drops unacked events after a failed report, TestForkReportProcessExit fails because the second report never comes.
  • If the agentapi handler stops poking, TestReportChatProcessEvents fails because the poke never arrives.
  • If the final poll stops waiting for the agent, 5 of the TestWakeupFinalPollProcesses cases fail, among them ReportAfterRetry. (Rerun on the new head with processReported always true: OnTimeLines, LateNotFiredNeverReported, LateNotFiredReportedBeforeExpiry, LateNotFiredReportedInMargin and ReportAfterRetry fail.)
  • If FireChatProcessWatches drops the output_at condition, TestFireChatProcessWatches and TestReportChatProcessEventsOutputResent fail.
  • If the fire query accepts only active wake-ups, TestWakeupEventsProcessExitWhilePaused fails because the fire returns no row.
  • If the queue drops the oldest event at the cap, TestForkEnqueueCap fails. If the output watch reads the formatted output, TestForkOutputWatchOpenLineAcrossHead fails with an unexpected report of an open line. Without ToValidUTF8, TestForkInvalidUTF8 fails on marshal.
  • Fourth round: without the cool-down check in ListDueChatWakeups and the wake-up, TestWakeupEventsProcessOutputCooldown fails with two messages instead of one. If a new wake-up replaces the output watches of a process, SameWakeupWatchesOnce fails (1 watch, want 4). Without the 10000 exit bound, TestForkEnqueueCap fails because the oldest exit stays.
  • If the agent never sends the empty report, TestForkReportProcessEventsHeartbeat fails waiting for it. If it sends one while no chat process runs, the test fails with an unexpected report.
  • Fifth round: if coderd records the time of receipt instead of last_acked_at, TestReportChatProcessEvents fails (10 s off). If the agent sends one empty report per tick, or never sends back acked_at, TestForkReportProcessEventsHeartbeat fails. If the agent ignores closed_output_events, TestForkOutputWatch fails because the watch never ends. If forkReportTime returns now, TestForkReportTime fails. Without the drop on start, TestForkProcessIDReuse fails. If ChatProcessWatchTakesLines and the fire query allow one delivery past output_max_events, TestFireChatProcessWatches fails at the limit case.

Not exercised

  • A real agent binary against a real coderd end to end. The tests use the agentproc API with a fake DRPC client, the agentapi handler with a real database, and chatd with a fake agent connection.
  • A poke across replicas, which is covered only by the sweep that runs every minute.
  • An actual old agent binary. The too-old path is tested with a connection that lacks the fork interface and with a 404 from the watch route.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T07:30:29.851944Z 270fc47 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1020fd84c

ℹ️ 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".

Comment thread coderd/x/chatd/fork_wait_for_events.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c97c875907

ℹ️ 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".

Comment thread coderd/x/chatd/fork_process_events.go Resolved
…rop resent output reports

The final poll of a process watch now waits until the agent says, after the
expiry plus a margin, that it holds no unacked event. The agent says so with
an empty ReportChatProcessEvents every 30 s while a chat process runs, and
coderd records it per watch. A connected agent whose reports keep failing no
longer passes for one that reported.

A report of matching lines carries the agent's match time, kept in
spec.output_at, so a resent report fires nothing and does not count against
output_max_events.
…ocess-events-825b2d7c

# Conflicts:
#	coderd/database/forkdb/sqlc.yaml
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e37ef8a451

ℹ️ 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".

Comment thread agent/agentproc/fork_process_events.go Resolved
Comment thread agent/agentproc/fork_process_events.go Resolved
Comment thread agent/agentproc/fork_process_events.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eba9c4fdf3

ℹ️ 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".

Comment thread agent/agentproc/fork_process_events.go Resolved
Comment thread agent/agentproc/fork_process_events.go Resolved
Comment thread agent/agentproc/fork_process_events.go Resolved
…ocess-events-825b2d7c

# Conflicts:
#	coderd/database/forkdb/sqlc.yaml
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 95b794c5a3

ℹ️ 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".

Comment thread agent/agentproc/fork_process_events.go Resolved
Comment thread agent/agentproc/fork_process_events.go Resolved
Comment thread coderd/x/chatd/fork_process_events.go Resolved
Comment thread agent/agentproc/fork_process_events.go Resolved
Comment thread agent/agentproc/fork_process_events.go Resolved
Comment thread docs/fork/pstack-adapter.md Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 76108de735

ℹ️ 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".

…ocess-events-825b2d7c

# Conflicts:
#	agent/proto/agent.pb.go
#	coderd/agentapi/api.go
#	coderd/workspaceagentsrpc.go
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 270fc4782c

ℹ️ 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".

@ibetitsmike
ibetitsmike merged commit ada0207 into main Nov 17, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-295-process-events branch November 17, 2026 08:02
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged at head 270fc4782ca00f7d5281a3028fcca0fd2375c7c7 as ada0207, on main cc3ed79df09581324bbe6db9b29b58c9f55f09c5, with the server running that main.

Gates on this exact head:

  1. The head matched the SHA I verified (--match-head-commit).
  2. Every check run passed. fork-ci run 44038729640 passed on this head.
  3. Codex receipt for this head: feat: the workspace agent reports chat process events #376 (comment) ("Didn't find any major issues").
  4. No unresolved review thread.
  5. 0 commits behind main.
  6. I ran the tests below on this exact head.

Tests I ran on 270fc4782c (detached worktree, under flock ~/.fork-go.lock):

  • go test -count=1 -race -v -run TestFork ./agent/agentproc/: 28 PASS, 0 FAIL.
  • go test -count=1 -race -v -run TestReportChatProcessEvents ./coderd/agentapi/: 2 PASS, 0 FAIL.
  • go test -count=1 -v ./coderd/database/forkdb/...: 73 PASS, 0 FAIL.
  • go test -count=1 -race -v -run 'TestWaitForEvents|TestWakeup|TestProcess' ./coderd/x/chatd/: 160 PASS, 0 FAIL.
  • go test -count=1 ./coderd/x/chatd/: ok.
  • go test -count=1 -run TestMethodTestSuite ./coderd/database/dbauthz/: ok.
  • Negative control: with the agentapi handler treating the experiment as always off, TestReportChatProcessEvents and TestReportChatProcessEventsOutputResent fail. The source was restored after the control.

Review notes:

  • The feature stays behind fork-chat-wakeups. With the experiment off, coderd/fork_process_events.go passes no options and the handler acks every report without a write.
  • The agent always reports chat process exits, plus two empty reports every 30 s while a chat process runs. With the experiment off this is extra Agent API traffic only, and it is bounded.
  • The RPC is its own fork DRPC service, so the Agent API version stays at 2.16.
  • One new chatdmig node (01a1e710-..._chat_wakeup_watches_open_process_idx, a partial index). No existing node is edited.
  • Old agents: a workspace agent built before this deploy cannot report process events. wait_for_events with process IDs then fails with an error that says to poll or restart the workspace. Watches created before the deploy on such agents end at their expiry. A workspace restart picks up the new agent.

Not exercised:

  • a real workspace agent against a live coderd, and the old-agent error path on a real workspace;
  • multi-replica delivery (the poke goes only to the local replica; the 5-minute sweep and the wake-up sweep cover others, which is tested only in unit tests);
  • the darwin and Windows agent runtimes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chatd, agent: the agent reports process exits and matching output instead of chatd dialing it every 15 s

1 participant