Repository navigation
fix(agent/agentproc): drop the trailing CR of a CR LF output line - #425
Conversation
The output watch of wait_for_events split lines at LF but kept the CR that a CR LF line carries, so a pattern with an end anchor such as ^READY$ never matched the output of a Windows or a TTY process. The report now drops that CR, and byte positions still count raw bytes, so a poll neither reports nor skips a line twice. Closes #419
The CRLF and MixedLineEnds cases of TestForkNewLines set total one byte below the length of the head, which production cannot reach, so their wantEnd checked a shifted position.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f765463886
ℹ️ 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".
… CRLF helper test The detailed output section of the architecture document still said that the pattern matches the raw bytes, which the CR drop of forkNewLines no longer does for a CR LF line. It now documents the normalization, as the wake-ups section already does. TestForkNewLinesCRLF keeps only the poll sequence over CR LF output, which no other case covers: a line that one poll saw is not reported again, lines that arrive later come alone, and a line that is still open holds for the next poll. The line text and the end anchor are the job of the CRLF table case and of TestForkOutputWatchCRLF.
Both findings are fixed on head 8e9cd29: the detailed output section of the architecture document now describes the CR normalization as well, and TestForkNewLinesCRLF keeps only the poll sequence over CR LF output, which no other case covers, with the line text and the end anchor owned by the CRLF table case and by TestForkOutputWatchCRLF. @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8e9cd2982e
ℹ️ 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".
The last poll of TestForkNewLinesCRLF replaced the output and put the cursor past the new total, a state an append-only HeadTailBuffer cannot produce, so the empty result proved nothing. The sequence now only grows the output: the same output is polled twice, then an open line is appended and polled, then completed and polled.
Fixed on head d0a3d34: the last poll of TestForkNewLinesCRLF no longer shrinks the output below the cursor. The sequence is append only: the same output is polled twice, then an open line is appended and polled, then completed and polled. @codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Merged at head Gates on this exact head:
What this changes: Not exercised: a live coderd with a real CRLF-writing process. TestForkOutputWatchCRLF covers the agent matching path end to end in a unit test. Pre-commit hook: the workstream used the worktree-only opt-out (#407, Mike 2026-11-22) and ran go test, go vet and gofmt on the package. |
Closes #419
What changed and why
forkNewLines(agent/agentproc/fork_process_events.go) split the output lines of a watched process at LF but kept the CR that a CR LF line carries, so a pattern with an end anchor such as^READY$never matched the output of a Windows or a TTY process. The report now drops a CR immediately before the LF. Byte positions still count raw bytes: the returned end and the cursor move past LF, so a poll neither reports nor skips a line twice. The change sits in fork code behind the existingfork-chat-wakeupsprocess-events experiment, so no new experiment is needed for the bug fix.One line of the fork section of
coderd/x/chatd/ARCHITECTURE.mddocuments the line splitting.How it was tested
Pre-commit hook (
coder.pre-commitdisabled in this worktree only, per #407), with the checks it would have run:flock ~/.fork-go.lock go test ./agent/agentproc/ -run 'Fork' -v: all 16 Fork tests pass, including the newTestForkNewLinesCRLFandTestForkOutputWatchCRLFand the new cases ofTestForkNewLines.flock ~/.fork-go.lock go vet ./agent/agentproc/: clean.gofmt -l agent/agentproc/: clean.Negative control: with only the
forkNewLineschange reverted (git stash, not--no-verify),go test ./agent/agentproc/ -run 'TestForkNewLinesCRLF|TestForkOutputWatchCRLF|TestForkNewLines$'fails:TestForkNewLinesCRLFexpects[]string{"READY", "b"}and the old code returns[]string{"READY\r", "b\r"}(^READY$would not match),TestForkNewLines/CRLF,/EmptyCRLFand/MixedLineEndsfail, andTestForkOutputWatchCRLFtimes out with no matching line. The fix restored afterwards. A read-only review subagent on the diff confirmed which assertions fail without the fix.What was not verified
No runtime check against a live coderd or a real CRLF-producing process: the CRLF path is covered by unit tests, including one through the matching path (
forkRunOutputWatchwith a pattern^READY$), but not by a remote UAT.