Skip to content

fix(agent/agentproc): drop the trailing CR of a CR LF output line - #425

Merged
ibetitsmike merged 4 commits into
mainfrom
mike/issue-419-crlf-process-lines
Nov 23, 2026
Merged

ibetitsmike merged 4 commits into
mainfrom
mike/issue-419-crlf-process-lines

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

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 existing fork-chat-wakeups process-events experiment, so no new experiment is needed for the bug fix.

One line of the fork section of coderd/x/chatd/ARCHITECTURE.md documents the line splitting.

How it was tested

Pre-commit hook (coder.pre-commit disabled 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 new TestForkNewLinesCRLF and TestForkOutputWatchCRLF and the new cases of TestForkNewLines.
  • flock ~/.fork-go.lock go vet ./agent/agentproc/: clean.
  • gofmt -l agent/agentproc/: clean.

Negative control: with only the forkNewLines change reverted (git stash, not --no-verify), go test ./agent/agentproc/ -run 'TestForkNewLinesCRLF|TestForkOutputWatchCRLF|TestForkNewLines$' fails: TestForkNewLinesCRLF expects []string{"READY", "b"} and the old code returns []string{"READY\r", "b\r"} (^READY$ would not match), TestForkNewLines/CRLF, /EmptyCRLF and /MixedLineEnds fail, and TestForkOutputWatchCRLF times 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 (forkRunOutputWatch with a pattern ^READY$), but not by a remote UAT.

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.
@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-23T02:59:24.458509Z d0a3d34 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.

@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: 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".

Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
… 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.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

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

@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: 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.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

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

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: d0a3d34f10

ℹ️ 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 683b9b1 into main Nov 23, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-419-crlf-process-lines branch November 23, 2026 03:21
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged at head d0a3d34f1006548cf8b6e83a5f60f763b1a54255 as 683b9b1, on main 1359b2e903fe18a029519aa8b09b68061a21313b, 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 45103079041 passed on this head.
  3. Codex receipt for this head: fix(agent/agentproc): drop the trailing CR of a CR LF output line #425 (comment) ("Didn't find any major issues", Reviewed commit d0a3d34f10).
  4. No unresolved review thread. Three P2s from earlier rounds (a doc section that disagreed, a duplicate test, a non-append-only poll fixture) were fixed, and I resolved their threads with a reply each.
  5. 0 commits behind main.
  6. Test evidence I ran in the PR worktree at this head:
    • flock ~/.fork-go.lock go test ./agent/agentproc/ -run Fork -count=1: ok.
    • Negative control: with the CR strip disabled, TestForkNewLines, TestForkNewLinesCRLF and TestForkOutputWatchCRLF fail. Reverted, and the worktree was clean afterwards.

What this changes: forkNewLines drops a CR right before the LF from the text a process_output_pattern sees, so CRLF output matches end-anchored patterns such as ^READY$. Byte positions still count raw bytes. ARCHITECTURE.md describes it.

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.

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.

agent: process output patterns never match CRLF lines with an end anchor

1 participant