Skip to content

fix(agent): bound transient command output replay by deadline - #46785

Merged
BeautyyuYanli merged 2 commits into
langgenius:mainfrom
Wang-Zephyr:fix/agent-command-output-deadline
Nov 20, 2026
Merged

BeautyyuYanli merged 2 commits into
langgenius:mainfrom
Wang-Zephyr:fix/agent-command-output-deadline

Conversation

@Wang-Zephyr

Copy link
Copy Markdown
Contributor

Fixes #46784

Summary

Honor the remaining command timeout while replaying truncated output. read_output has no timeout argument, so this branch now checks the shared deadline before starting another read and bounds that await with asyncio.timeout.

An exhausted replay returns the existing incomplete-output result with reason timeout, preserves the captured prefix, and uses the existing interrupt/delete cleanup. Healthy replay and caller cancellation retain their behavior. The change stays in the transient command runner used by complete Shell calls and Binding file operations; no provider interface changes.

Verification

Case Evidence
Already-expired budget, running and completed jobs Both new cases fail on main; no extra output read starts after the fix
Stalled output read Main reaches the outer guard; fixed code returns its own timeout result and cleans up
Healthy paginated output Complete concatenated output and no interrupt
Caller cancellation during replay Cancellation propagates and the job is deleted

The standalone issue reproduction was run against original and fixed sources. Tests use a scripted command-protocol implementation; no live remote sandbox/network coverage is claimed.

  • Command-runner suite: 6 passed. The three regression cases fail against unchanged main.
  • Full Agent package: 1415 passed, 6 skipped, 8 failed, 2 setup errors; unchanged baseline: 1410 passed, 6 skipped, the same 8 failed and 2 setup errors. No new failing test IDs. Existing limitations include POSIX shell/file helpers on Windows, a default-dependency installation check, a docs-snippet check, and an overlong parameter environment variable. This is not a clean full-suite pass.
  • Package Ruff lint/format, Pyrefly, the baseline-aware test-doubles guard, and git diff --check passed.
  • Full Dify API tests and deployed provider checks were not run.

Commands from dify-agent, with locked server/dev dependencies:

uv run --no-sync pytest tests/local/dify_agent/runtime/test_command_runner.py -q
uv run --no-sync pytest tests --basetemp=D:/codex/tmp/dify-sdk-src-1119 -q --tb=short
uv run --no-sync python -m ruff check .
uv run --no-sync python -m ruff format --check .
uv run --no-sync pyrefly check

Checklist

  • Linked a reproducible issue before the PR.
  • Verified the regression against main and added preservation coverage.
  • Updated the runtime-resources documentation.

From Codex

@github-actions github-actions Bot added the size:L This PR changes 100-499 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.)

Reviewed and pushed a small follow-up commit (807905991516) on top of the original fix:

  • Re-raise TimeoutError originating inside commands.read_output(...) when not read_timeout.expired(), so provider-side read timeouts before the command deadline are not misclassified as command budget exhaustion.
  • Unify the completion exit (not result.truncated and result.done) and shared _remaining_time(deadline) <= 0.0 budget gate across read_output and wait.
  • Expand test_command_runner.py to cover multi-page remaining-budget replay, interrupt -> delete(force=True) ordering, terminal exit metadata preservation, internal TimeoutError propagation, and output_limit / final-page precedence.

All CI checks on 807905991516 are green.

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent transient commands ignore timeout while replaying truncated output

2 participants