Skip to content

refactor(process-daemon): route stop and ownership through Control - #59700

Merged
jlongster merged 1 commit into
devfrom
daemon-control
Oct 28, 2026
Merged

jlongster merged 1 commit into
devfrom
daemon-control

Conversation

@jlongster

@jlongster jlongster commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Ported from anomalyco/opencode-pty#30. Part of the stack for anomalyco/opencode-pty#25. Builds directly on dev; no prerequisite.

Issue for this PR

Related to anomalyco/opencode-pty#25

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

  • Behaviour-preserving refactor: the 10 ms accept loop is unchanged. This PR prepares the loop to become readiness-driven in the next PR.
  • New daemon::Control (packages/process-daemon/src/daemon/control.rs) holds a private stop flag and the ownership mutex, and is now the only way to stop the daemon or mutate ownership.
    • request_stop takes the ownership lock, so the next PR can wake the accept loop under that same lock.
  • run is split into bind → Control → serve. Ownership is still created after bind, as before.
  • Handler completion is tracked with a done flag set by a drop guard in the handler thread (the reap check still also accepts is_finished()). The next PR adds a wake there.
  • Ownership::with_timeouts lets tests use short starting/handoff deadlines.
  • New in-process unix tests in packages/process-daemon/src/daemon/server.rs, using a TestDaemon fixture that runs serve on a temp socket:
    • shutdown_request_stops_immediately
    • owner_shutdown_stops_immediately
    • owner_disconnect_without_handoff_stops_immediately
    • starting_deadline_fires_on_time
    • waiting_deadline_fires_on_time
    • handoff_claim_transfers_without_spurious_stop

Ported from the opencode-pty commit; the only difference is that connection handlers are spawned with plain thread::spawn, as on dev.

How did you verify your code works?

  • Port validation (macOS arm64, Rust 1.90.0, in packages/process-daemon): cargo fmt --check, cargo clippy --locked --all-targets --all-features -- -D warnings, and cargo test --locked --lib (53 passed) pass.
  • On the stack tip (daemon-windows-poll) the full macOS CI test selection and Windows/Linux cross clippy also pass.
  • Original PR: the macOS CI test selection passed: cargo test --locked --lib --test service --test runtime --test ownership --test rows --test ghostty-effects (lib 47, ghostty-effects 5, ownership 8, rows 1, runtime 8 + 1 ignored, service 9), and cross clippy with -D warnings passed for x86_64-pc-windows-msvc and x86_64-unknown-linux-gnu (--all-targets --all-features, ghostty-vt link libs stubbed). Windows and Linux tests rely on CI.

Screenshots / recordings

N/A, internal daemon change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@jlongster
jlongster changed the base branch from daemon-handler-spawn to dev October 27, 2026 22:33
@jlongster jlongster closed this Oct 28, 2026
@jlongster jlongster reopened this Oct 28, 2026
@jlongster
jlongster merged commit f0160a1 into dev Oct 28, 2026
24 checks passed
@jlongster
jlongster deleted the daemon-control branch October 28, 2026 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant