Skip to content

fix(chatd): fold held-back matching lines into the process exit or loss message - #427

Merged
ibetitsmike merged 3 commits into
mainfrom
mike/issue-420-matched-lines-on-exit
Nov 23, 2026
Merged

ibetitsmike merged 3 commits into
mainfrom
mike/issue-420-matched-lines-on-exit

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

Closes #420

What changed

When matching output lines of a watched process are held back in the watch's fired_payload, by a failed send, the output cool-down or a busy chat, and the process then exits or the watch is lost, the delivery dropped the held-back lines: processFiredText returned only the exit or loss text.

processFiredText in coderd/x/chatd/fork_process_events.go now folds the held-back batch into the exit or loss message through a new processFoldedLinesText, which reads the matched count and lines the payload already holds. The folded batch is not a message of its own: it never appends the last-message text of the lines (processLinesLastText), and the final poll delivers it, since the lines were collected before the event that ends the watch. The watch still ends with that one message, so no line message is sent twice.

Tests

  • TestProcessFiredText grew folded cases: ExitOverLines, ExitOverManyLines, ExitOverLinesOnLastDelivery (a folded batch on the watch's last delivery carries no last-message text), ExitOverLinesOnFinalPoll (the final poll delivers the fold), and LostOverLines.
  • New TestWakeupEventsProcessLinesOnExit walks the wake-up end to end: a first line delivers, a second one is held back by the cool-down and its send fails (runs delivered, failed), the process exits, and the retry delivers one message with the exit tail and the folded line (runs delivered, failed, delivered). The watch ends completed with two deliveries, and a resent exit delivers nothing.
  • Negative control: reverting only fork_process_events.go to 1359b2e903 makes both tests fail (TestWakeupEventsProcessLinesOnExit at line 444, TestProcessFiredText for the three folded cases), so the tests cover the fix. Restoring the fix makes them pass.
  • Commands, all under the workspace Go lock: go test ./coderd/x/chatd/ -run 'TestProcessFiredText|TestWakeupEventsProcessLinesOnExit|TestWakeupEventsProcessOutput|TestWakeupEventsProcessExit|TestWakeupEventsProcessOutcomes' -v (pass), go test ./coderd/database/forkdb/... (pass), go vet on both packages (clean).

Docs

  • coderd/x/chatd/ARCHITECTURE.md: the events wake-up bullet and the fire bullet describe the fold, the skipped last-message text, and the final-poll treatment, including the late-final-poll cutoff.
  • docs/fork/pstack-adapter.md: the fold sentence and the final-check wording.
  • coderd/database/forkdb/chat_process_events.go: the ChatProcessFired comment now says the payload keeps lines beside an exit or loss.

Pre-commit hook

The pre-commit hook of this fork (#407) is disabled for this worktree branch, so it did not run. The targeted checks above stand in for it, and fork-ci runs the full checks on the head.

No em dashes or en dashes in changed prose. Fork logic stays in fork_*.go files.

@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 23, 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-23T03:34:56.725672Z 600bd7f 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

Copy link
Copy Markdown

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

Reviewed commit: f19f0375fe

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

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged main (683b9b1 from #425) into the branch to clear the behind-main gate. The ARCHITECTURE.md conflict was resolved by keeping both changes: the CRLF sentences from #425 and the folded-batch prose from this PR. #420 tests rerun green under the lock. @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 600bd7f98b

ℹ️ 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 ebfcb41 into main Nov 23, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-420-matched-lines-on-exit branch November 23, 2026 04:08
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged at head 600bd7f98b9b3b52a5d79cf9102520f415c5de14 as ebfcb41, on main 683b9b12eeb0e0573d09cf9c3d46b188df63fb54, 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 45106521996 passed on this head.
  3. Codex receipt for this head: fix(chatd): fold held-back matching lines into the process exit or loss message #427 (comment) ("Didn't find any major issues", Reviewed commit 600bd7f98b).
  4. No review threads.
  5. 0 commits behind main. The branch merged main after fix(agent/agentproc): drop the trailing CR of a CR LF output line #425 landed.
  6. Test evidence I ran in the PR worktree at this head:
    • flock ~/.fork-go.lock go test ./coderd/x/chatd -run TestWakeupEventsProcess -count=1: ok.
    • Negative control: with the fold on exit disabled in processFiredText, TestWakeupEventsProcessLinesOnExit fails. Reverted, and the worktree was clean afterwards.

What this changes: when a process exits or its watch is lost while matched output lines are still held back (a failed send, a cool-down or a busy chat), the exit or loss message now carries those lines instead of dropping them. Closes #420.

Not exercised: a live coderd with a real process that exits during a cool-down. The unit test covers the delivery path from a fired payload that holds both lines and an exit.

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: matched output lines are lost when the process exits before the lines message is retried

1 participant