Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(agentctl): keep the caller's output from the agentd that agentctl starts on Windows - #573

Draft
olebhansen-agent wants to merge 4 commits into
mainfrom
fix/467-windows-agentd-handle-inheritance
Draft

olebhansen-agent wants to merge 4 commits into
mainfrom
fix/467-windows-agentd-handle-inheritance

Conversation

@olebhansen-agent

@olebhansen-agent olebhansen-agent commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

On Windows, a caller that reads agentctl's output to its end waited until agentd exited whenever that agentctl started agentd. Rust starts a child with every inheritable handle of its parent, and the standard handles agentctl gets from its caller are inheritable, so agentd held them open besides the null and log handles it is given.

agentctl now starts agentd through one agent::local::process::spawn_detached, from both spawn_daemon and the updater's start_daemon. On Windows it first marks agentctl's own standard handles not inheritable. Children started with Stdio::inherit are unaffected, since Rust passes them duplicates it makes inheritable for that one start.

That does not cover a shell that captures agentctl's output into a pipe of its own, such as PowerShell running agentctl get agents | Out-String. agentctl then inherits the shell's output as an extra handle, and agentd still gets it. The last commit adds a test for that case, which fails on Windows. Whether to fix it here, with an explicit handle list, or to merge this for the first case alone waits for a decision on the plan.

windows-sys now names Win32_Foundation, which other dependencies already enable, so the build and Cargo.lock are unchanged.

Closes #467

Evidence

The tests run the test binary as the caller, as agentctl and as a detached agentd, so that pipes reach agentctl as they do from a shell. The detached child runs only while a file in the test's temporary directory exists, so it stops when the test ends. CI runs them in the rust / Portable host (Windows x64 / ARM64) jobs.

  • detached_child_leaves_the_callers_output fails at "test(agentctl): pin that agentd leaves the output of the agentctl that starts it" (run 44630712293, on an earlier main) and passes with the fix (run 44879602845, on current main).
  • detached_child_leaves_the_output_of_the_shell_that_runs_the_caller fails with the fix on both Windows jobs in run 44879602845: the detached child held the caller's output open: Elapsed(()).

On Linux both pass before and after, since Rust closes every other descriptor in a child.

Risk

  • Windows only. After it starts agentd, agentctl's standard handles stay not inheritable for the rest of its run. A child started through Rust with inherited output still gets it, as above.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6e05c740-939a-4bca-9bed-6e3ebd9fb628

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@olebhansen-agent

olebhansen-agent commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

Superseded by the current report.

@olebhansen-agent

olebhansen-agent commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

@olebhansen, this applies to 3060469 ("test(agentctl): pin that agentd leaves the output of a shell that captures agentctl").

Waits for you: which option on the plan to build. The fix here covers a caller that reads agentctl's own output, such as the steps in #467 and the installer. It does not cover a shell that captures agentctl's output, such as PowerShell running agentctl get agents | Out-String. The last commit's test shows that on both Windows CI jobs, so the head fails CI on purpose. I would replace the fix with an explicit handle list (option 1). It is about 100 to 150 lines of unsafe Win32 code that only CI can test here, and whether that is acceptable is your call.

Decided on your behalf: the branch is rebased on current main (only agentctl/CHANGELOG.md conflicted, and both entries are kept), and the pull request is back to draft until the scope is settled.

Small, open: the challenger found the name keep_standard_handles reads as the opposite of what it does. It would become stop_inheriting_standard_handles under option 2, and goes away under option 1.

Checks: the challenger ran on the analysis and the build. The red team and QA have not run, since the solution they would check isn't settled. CodeRabbit has not reviewed the pull request. Nobody has run the steps in #467 by hand on Windows.

@olebhansen-agent
olebhansen-agent marked this pull request as draft November 19, 2026 22:14
@olebhansen-agent
olebhansen-agent force-pushed the fix/467-windows-agentd-handle-inheritance branch from d5efc6e to ff518c0 Compare November 19, 2026 22:39
@olebhansen-agent
olebhansen-agent marked this pull request as ready for review November 19, 2026 23:02
@olebhansen-agent
olebhansen-agent force-pushed the fix/467-windows-agentd-handle-inheritance branch from da3f0f1 to 7c01a68 Compare November 20, 2026 19:54
@olebhansen-agent

Copy link
Copy Markdown
Collaborator Author

Rebased on main after today's merges. The only conflicts were in agentctl/CHANGELOG.md, where both sides added an entry, so both are kept. The code is unchanged.

olebhansen-agent and others added 3 commits November 21, 2026 07:05
…t starts it

A script or coding agent that captures agentctl's output reads it to its end. On Windows, the agentd that agentctl
starts holds that output open, so the reader waits until agentd exits. The test plays agentctl and agentd with the
test binary, and fails on Windows now.

The new spawn_detached is the start agentctl uses for agentd, which the next commit moves both of its callers to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… starts on Windows

Windows starts a child with every inheritable handle of its parent, and the standard handles agentctl gets from its
caller are inheritable. agentd then held agentctl's output open, so a caller reading it to its end waited until agentd
exited. agentctl now marks its standard handles not inheritable before it starts agentd. Children started with
Stdio::inherit are unaffected, since Rust passes them duplicates it makes inheritable.

Win32_Foundation was already enabled for windows-sys by other dependencies; agent now names it, since it uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@olebhansen-agent olebhansen-agent added the platform/win tag for issues/code (only) affecting Windows label Nov 21, 2026
@olebhansen-agent
olebhansen-agent force-pushed the fix/467-windows-agentd-handle-inheritance branch from 7c01a68 to 3060469 Compare November 21, 2026 07:18
…tures agentctl

A shell that captures agentctl's output, such as PowerShell running `agentctl get agents | Out-String`, gives
agentctl a pipe of its own. On Windows, agentctl also inherits the shell's own output, which whatever runs the
shell reads to its end, and the agentd it starts gets that too. The test plays the shell, agentctl and agentd with
the test binary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@olebhansen-agent
olebhansen-agent marked this pull request as draft November 21, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Let CI run, even for draft platform/win tag for issues/code (only) affecting Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agentctl: an agentd that agentctl starts on Windows keeps the caller's output open, so capturing agentctl never ends

1 participant