Skip to content

fix(agent): reject FIFO file previews without blocking - #46787

Merged
BeautyyuYanli merged 1 commit into
langgenius:mainfrom
Wang-Zephyr:fix/binding-preview-fifo
Nov 26, 2026
Merged

BeautyyuYanli merged 1 commit into
langgenius:mainfrom
Wang-Zephyr:fix/binding-preview-fifo

Conversation

@Wang-Zephyr

Copy link
Copy Markdown
Contributor

Fixes #46786

Summary

Reject a FIFO preview without waiting for a writer. The Binding read script opens a path before checking fstat, so blocking O_RDONLY could stall on a named pipe and never reach its existing regular-file check.

Add O_NONBLOCK alongside O_NOFOLLOW, allowing the existing rejection to produce 400 invalid_binding_path. The regular-file check and descriptor cleanup remain in the same place. The production diff is one open flag plus a comment, with a real-FIFO regression and a short Binding file documentation update.

Precondition: the inspection script runs in the existing POSIX Binding runtime. Postcondition: a writerless FIFO is rejected before reading, its descriptor is closed, and regular-file preview output retains its existing contract.

Verification

Linux / Python 3.13.17, with test dependencies aligned to the locked Agent environment:

  • Unchanged main plus the new regression: 36 passed, 1 failed in the Binding file suite. The new test fails with subprocess.TimeoutExpired; its child is automatically killed and reaped.
  • Fixed Binding file suite: 37 passed.
  • Binding files, execution-binding service, RuntimeLease, and command-runner suites together: 42 passed.
  • Package Ruff lint/format and Pyrefly: passed. Baseline-aware no-new-test-doubles guard and git diff --check: passed.

An isolated check also sent real requests through create_binding_files_router and BindingFileService, using ASGI transport and a local subprocess command adapter:

Preview Unchanged main Fixed source
FIFO without a writer Reaches the adapter's 2-second guard; 502 400 invalid_binding_path before the guard
UTF-8 regular file 200, full text Same
UTF-8 byte-limit split 200, complete prefix, truncated Same
Binary file 200, binary flag, no text Same
Symlink Existing rejection Same

All five operations released their leases in both runs. No remote sandbox/provider deployment, full Agent package suite, or full Dify API suite was exercised for this change. The FIFO regression skips platforms without os.mkfifo.

From dify-agent on Linux:

uv run --extra server pytest tests/local/dify_agent/server/test_binding_files.py tests/local/dify_agent/server/test_execution_bindings.py tests/local/dify_agent/runtime_backend/test_leases.py tests/local/dify_agent/runtime/test_command_runner.py -q
uv run python -m ruff check .
uv run python -m ruff format --check .
uv run --group dev --extra server pyrefly check

Checklist

  • Linked the reproducible issue before opening this PR.
  • Added a regression that fails against unchanged main.
  • Updated the Binding file boundary documentation.

From Codex

@github-actions github-actions Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Nov 19, 2026

@BeautyyuYanli BeautyyuYanli 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.

(This message is automated while I'm responsible for it.)

LGTM. Opening the target path with os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK in _READ_BINDING_FILE_SCRIPT keeps the TOCTOU-safe fstat / stat.S_ISREG check intact while preventing writerless FIFOs from blocking open(2) until the browse timeout, ensuring immediate 400 invalid_binding_path rejection and prompt descriptor/lease cleanup.

Verified locally (pytest tests/local/dify_agent/server/test_binding_files.py, make check, make typecheck, and real FIFO verification against both the inspection script and FastAPI read route) with all remote CI checks green on e5a2e0b09f04.

@BeautyyuYanli
BeautyyuYanli added this pull request to the merge queue Nov 26, 2026
Merged via the queue into langgenius:main with commit fe7901e Nov 26, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Binding file preview blocks while opening a FIFO without a writer

2 participants