Skip to content

fix(tool): reject workspace named pipes before opening - #1979

Merged
lizhengfeng101 merged 2 commits into
alibaba:mainfrom
Afloat16:fix/workspace-nonregular-reads
Nov 22, 2026
Merged

lizhengfeng101 merged 2 commits into
alibaba:mainfrom
Afloat16:fix/workspace-nonregular-reads

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

A workspace path can resolve to a FIFO inside the repository. Both full-file reads and the line-window reader open that path before their read loop can observe cancellation. A review tool call therefore hangs on a named pipe even after its context deadline expires.

Check the resolved workspace entry for os.ModeNamedPipe before opening it. The check runs after the existing symlink and canonical repository-containment checks, so it also covers an in-repository symlink to a FIFO. Other mode flags, including os.ModeIrregular alone, are not rejected by this guard.

Type of Change

  • Bug fix (workspace file reads)

How Has This Been Tested?

The Linux regression creates a real named pipe and a symlink to it, then invokes FileReader.Read, ReadLines and the public file_read tool in isolated child processes. Each read has a 50 ms context deadline, and the parent terminates a regression after 2 seconds so the test does not leave a blocked goroutine behind. All six cases remain in the test and return a named-pipe error with the fix. Positive controls read a regular file and an in-repository symlink through both the full-file and tool paths.

The mode-classification regression accepts a regular mode and ModeIrregular alone, and rejects ModeNamedPipe both alone and combined with ModeIrregular. The ModeIrregular case failed with the previous !IsRegular() guard and passes with the narrowed guard. This is a mode-classification test; no live OneDrive checkout was used.

Validation of rebased commit 2071cccf6dd3a4b3e31bb689dddac922104abc5b (tree 353323fa1a7037e7b0d53566d8ead4dcf355ce2a), using Go 1.26.10 on Linux. The two original commits were replayed unchanged onto main at 39515dca6161fb7fd176d87704b2b10e5f7a0c36; git range-diff marks both patches equal.

  • make check — passed.
  • make test PACKAGES="./internal/tool ./internal/diff" — passed, including the race detector, all six FIFO cases, mode classifications and regular-file controls.
  • make coverage — the complete unit-test suite passed, with 91.5% overall coverage (90% required).
  • make build — passed.
  • git diff --check — passed.

The inherited telemetry sampler was explicitly set to always_on for the test suite. The required ocr review --audience agent --background "..." command was attempted, but could not start because no LLM endpoint is configured in the environment.

This handles named pipes present at resolution time. It does not claim to eliminate concurrent path-replacement races or provide cancellation for every filesystem operation.

Checklist

  • The change follows the project's coding style.
  • The failure and the production read paths were checked independently.
  • New and existing unit tests pass locally.
  • The CLA check passes.

Primary contributor and submitting author: Afloat16.

AI/LLM disclosure required by this repository: OpenAI ChatGPT (GPT-6 Astra Pro).

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

@chaojixinren chaojixinren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Defensive fix for a rare but real hang on FIFOs. Only adds an early file-type check before opening — no impact on normal file reads. Tests cover FIFO paths and regular symlinks. Safe to merge. LGTM.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

@Afloat16 Thanks for covering both FIFO paths and symlinks to them. Could we narrow the guard in resolveWorkspacePath to info.Mode()&os.ModeNamedPipe != 0 instead of !info.Mode().IsRegular()?

The distinction matters on Windows: Go 1.26.10 marks unrecognized reparse tags as ModeIrregular, including cloud-file tags. A source file in a OneDrive Files On-Demand checkout can therefore be readable through os.Open but fail the new guard before Windows gets a chance to serve its contents. This is based on the code path; I haven't tested it on a live OneDrive checkout.

Checking specifically for os.ModeNamedPipe after the existing symlink and containment checks would still reject both FIFO cases before opening, without changing how other file types are handled. The six Linux FIFO cases are worth keeping. A small classification test that rejects os.ModeNamedPipe but does not reject os.ModeIrregular alone would also pin down that distinction without requiring OneDrive in CI.

@Afloat16 Afloat16 changed the title fix(tool): reject non-regular workspace files before opening fix(tool): reject workspace named pipes before opening Nov 20, 2026
@Afloat16

Copy link
Copy Markdown
Contributor Author

Implemented in 49d1e70. The guard now checks mode & os.ModeNamedPipe != 0 after the existing symlink/containment checks.

All six real Linux FIFO cases are retained. A small classification table accepts ModeIrregular alone and rejects ModeNamedPipe, including the combined flags. The irregular-only case fails with the previous guard and passes with this change. The regular-file and symlink controls also pass.

make check, the tool/diff tests with -race, make build, and the full coverage suite pass on Go 1.26.10; coverage is 91.7%. The description now reflects the narrower named-pipe scope and these results. No live OneDrive result is claimed.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

@Afloat16 Thanks for updating the FIFO check. I’m planning to run the benchmark for this PR tonight and would like to test it against the latest main. The branch is currently four commits behind. Could you rebase it onto main before then?

If you don’t have time, just let me know here. Allow edits from maintainers is already enabled, so there’s no setting to change; I can take care of the rebase before the benchmark.

@Afloat16
Afloat16 force-pushed the fix/workspace-nonregular-reads branch from 49d1e70 to 2071ccc Compare November 21, 2026 16:52
@Afloat16

Copy link
Copy Markdown
Contributor Author

Rebased onto the current main at 39515dca6161fb7fd176d87704b2b10e5f7a0c36. The branch now ends at 2071ccc.

Both original commits replayed without conflict; git range-diff marks both patches equal. The named-pipe guard and all six FIFO regressions are unchanged.

Validation on the rebased tree with Go 1.26.10 on Linux: make check, the tool/diff tests with the race detector, make build, full make coverage (91.5%, above the 90% gate), and git diff --check pass. The repository's ocr review command was attempted but could not start because no LLM endpoint is configured.

The new-head hosted checks have now passed: Linux tests, Windows tests, all five cross-compilation targets, and all CodeQL analyses/results. CI run.

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit fa315a0 into alibaba:main Nov 22, 2026
12 checks passed
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.

3 participants