GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(process-daemon): pipe mode on Windows by jlongster · Pull Request #63196 · anomalyco/opencode

feat(process-daemon): pipe mode on Windows #63196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
jlongster merged 3 commits into dev from windows-pipe-mode
Nov 11, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat(process-daemon): pipe mode on Windows #63196

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
7e4da4b
feat(process-daemon): pipe mode on Windows
jlongster Nov 10, 2026
099e31e
fix(process-daemon): harden Windows pipe reads, env and handles
jlongster Nov 10, 2026
d37f493
fix(process-daemon): reap the output-pipe connect and harden its test
jlongster Nov 11, 2026
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

2 changes: 2 additions & 0 deletions 2 packages/process-daemon/Cargo.toml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ sha2 = "0.10"
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.61.2", features = [
"Win32_Foundation",
"Win32_Globalization",
"Win32_Security",
"Win32_Security_Authorization",
"Win32_Storage_FileSystem",
"Win32_System_IO",
"Win32_System_JobObjects",
"Win32_System_Pipes",
"Win32_System_Threading",
"Win32_System_WindowsProgramming",
Expand Down
81 changes: 52 additions & 29 deletions 81 packages/process-daemon/SPEC.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,33 @@ unknown id. Both refresh a PTY's foreground process first.
`create_pty { program, args, cwd, env, group_id, title, cols, rows }` starts a
PTY. `create_pipe { program, args, cwd, env, group_id, output_path, metadata }`
starts a pipe process: any command without a terminal. Both return
`Created { process }`. Pipe processes are Unix-only for now; a Windows daemon
answers `create_pipe` with an error.
`Created { process }`. Pipe processes work on Unix and Windows.

- The child gets exactly `env`: the daemon's own environment is not
inherited, and no `TERM` or `COLORTERM` is added. `cwd` must be absolute.
- The child gets its own process group, an empty signal mask with default
actions (the daemon blocks SIGTERM and SIGINT, and std keeps the mask across
exec), stdin on `/dev/null`, and one pipe for both stdout and stderr, so
their bytes stay in order. Nothing parses the output: there is no emulator,
no terminal replies, no OSC title and no foreground process.
- The child gets no terminal: stdin is `/dev/null` on Unix and `NUL` on
Windows, and both stdout and stderr share one pipe, so their bytes stay in
order. Nothing parses the output: there is no emulator, no terminal replies,
no OSC title and no foreground process.
- On Unix the child gets its own process group and an empty signal mask with
default actions (the daemon blocks SIGTERM and SIGINT, and std keeps the
mask across exec). On Windows it is created with `CREATE_NO_WINDOW` (no
console window and no console) and is placed in a kill-on-close job from
creation. The program is resolved the way `CreateProcessW` resolves a bare
executable name (the application directory, the current directory, the
system directories and `PATH`); the daemon does not run a shell unless the
request itself asks for one, and passing `["/c", command]` to `cmd.exe` is
the caller's job.
- `output_path` must be absolute. The daemon opens it before spawning,
truncating an existing file or creating one with mode `0666` minus the
daemon's umask, and refuses a symlink as the final path component. The
request is validated (program, absolute paths, metadata size) before the
file is opened, so such a rejected request never creates or truncates it; a
path that cannot be opened fails the request without starting the process.
A missing program or `cwd` fails at spawn, after the file was opened.
truncating an existing file or creating one (mode `0666` minus the daemon's
umask on Unix), and refuses a symlink or other reparse point as the final
path component. The request is validated (program, absolute paths, metadata
size) before the file is opened, so such a rejected request never creates or
truncates it; a path that cannot be opened fails the request without
starting the process. A missing program or `cwd` fails at spawn, after the
file was opened. The file is opened for reading, writing and deletion by
other handles, so a reader can follow it and the owner can delete it while
the process still runs.
- The reader writes every output byte to the file before handing it to the
actor. The file is the only copy of the output: a pipe process has no replay
buffer, so `replay` and `subscribe` return an empty replay (with correct
Expand All @@ -162,18 +172,22 @@ answers `create_pipe` with an error.
- Exit is published once both the exit status and the end of output are known.
A descendant that keeps the pipe open (`cmd &`, dev servers) delays that by
at most one second after the child exits; the reader then closes the pipe,
so leftover writers get `SIGPIPE`/`EPIPE`. This is deliberate: the process
is reported as finished, and nothing reads what comes later. The file is
closed before the exit is published.
so leftover writers get `SIGPIPE`/`EPIPE` on Unix and a broken pipe on
Windows. This is deliberate: the process is reported as finished, and
nothing reads what comes later. The file is closed before the exit is
published.
- `Exited` and the lifecycle carry `signal`, the signal's name such as
`"SIGTERM"`, when the process was killed by one; `exit_code` is then null.
`signal` is left out when there is none.
- An exited pipe process stays listed, as a zombie, until `terminate`. The
zombie keeps its PID and process group ID reserved, so killing the group can
never reach an unrelated process. `terminate` sends SIGKILL to the group and
to the child, reaps it and removes the process; it never waits on a
descendant that left the group and still holds the pipe. The daemon never
deletes output files.
`"SIGTERM"`, when the daemon terminated the process; `exit_code` is then
null. `signal` is left out when there is none.
- On Unix an exited pipe process stays listed, as a zombie, until `terminate`.
The zombie keeps its PID and process group ID reserved, so killing the group
can never reach an unrelated process. On Windows the process object and job
handle stay open until `terminate`, so the PID is not reused either.
`terminate` kills the whole tree (SIGKILL on Unix; `TerminateJobObject`, or
the main process only when no job could be used, on Windows), reaps it and
removes the process; it never waits on a descendant that left the process
group or job and still holds the pipe. The daemon never deletes output
files.

### Line count

Expand Down Expand Up @@ -205,11 +219,20 @@ only; left out for PTYs), `output_error` (left out when there is none) and
`exited_at`. PTY subscriptions send the same response.

`signal { id, signal }` (pipe only; `"SIGTERM"`, `"SIGINT"` or `"SIGKILL"`)
signals the process group and the child, and returns `Ok`. Unlike
`terminate`, it keeps the process: `wait` then gets a normal `Exited` with
`signal`. Signalling an exited process is allowed and reaches whatever is left
of its group (an empty group is not an error); after `terminate` the process
is gone and `signal` fails.
signals the process tree and returns `Ok`. On Unix the signal goes to the
process group and the child, as a real signal. **On Windows every signal is a
hard kill** of the job (or of the main process when no job could be used) with
`TerminateJobObject`/`TerminateProcess`: there is no console and no console
control event, so SIGTERM and SIGINT cannot be caught or trapped, and the exit
reports the signal that was sent, not a platform exit code. Unlike
`terminate`, `signal` keeps the process: `wait` then gets a normal `Exited`
with `signal`. Signalling an exited process is allowed and reaches whatever is
left of its group or job (an empty group is not an error); after `terminate`
the process is gone and `signal` fails. If an outer job refuses the child
(`ERROR_ACCESS_DENIED`, for example a job with UI restrictions), the daemon
runs the command anyway without a job, logs a warning once, and kills only the
main process with `TerminateProcess`; descendants then survive a signal or
terminate.

`metadata` on `create_pipe` is an opaque JSON object the daemon stores and
returns as `pipe.metadata` without interpreting it. `set_metadata { id,
Expand Down
3 changes: 1 addition & 2 deletions 3 packages/process-daemon/src/protocol.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ pub enum Request {
cols: u16,
rows: u16,
},
/// Unix only. The child gets exactly `env`; `cwd` and `output_path` must
/// be absolute.
/// The child gets exactly `env`; `cwd` and `output_path` must be absolute.
CreatePipe {
program: String,
args: Vec<String>,
Expand Down
70 changes: 31 additions & 39 deletions 70 packages/process-daemon/src/service.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use serde::{Deserialize, Serialize};
use crate::ghostty::{Format, Terminal, TerminalOptions};
use crate::protocol::AttachmentRole;

#[cfg(unix)]
mod pipe;
#[cfg(windows)]
mod windows;
Expand Down Expand Up @@ -311,7 +310,7 @@ impl TerminalService {
self.insert(|id, order| TerminalHandle::spawn_pty(id, order, request, replay_capacity))
}

/// Starts a pipe process. Unix only.
/// Starts a pipe process.
pub fn create_pipe(&self, request: CreatePipe) -> Result<ProcessInfo> {
// Everything is checked before the output file is opened, so a
// rejected request never creates or truncates it.
Expand All @@ -323,10 +322,7 @@ impl TerminalService {
bail!("output_path must be absolute");
}
validate_metadata(&request.metadata)?;
#[cfg(unix)]
return self.insert(|id, order| TerminalHandle::spawn_pipe(id, order, request));
#[cfg(not(unix))]
bail!("pipe processes are not supported on this platform");
self.insert(|id, order| TerminalHandle::spawn_pipe(id, order, request))
}

fn insert(
Expand Down Expand Up @@ -399,18 +395,11 @@ impl TerminalService {
/// Signals a pipe process and its process group. The process stays
/// listed; signalling one that already exited is allowed.
pub fn signal(&self, id: TerminalId, signal: ProcessSignal) -> Result<()> {
let process = self.pipe(id)?;
#[cfg(unix)]
return process
self.pipe(id)?
.process
.as_ref()
.ok_or_else(|| anyhow!("process {id} cannot be signalled"))?
.signal(signal);
#[cfg(not(unix))]
{
let _ = (process, signal);
bail!("pipe processes are not supported on this platform");
}
.signal(signal)
}

/// Replaces a pipe process's metadata.
Expand Down Expand Up @@ -644,7 +633,6 @@ struct TerminalHandle {
/// Runs after the joins; reaps a pipe process kept as a zombie until now.
reap: Mutex<Option<Box<dyn FnOnce() + Send>>>,
/// Pipe only: the child, for `signal`.
#[cfg(unix)]
process: Option<Arc<pipe::Process>>,
info: Arc<RwLock<ProcessInfo>>,
joins: Mutex<Option<Vec<JoinHandle<()>>>>,
Expand Down Expand Up @@ -789,7 +777,7 @@ impl TerminalHandle {
ActorMaster {
pty: Some(pair.master),
#[cfg(windows)]
close_tx,
close_tx: Some(close_tx),
},
writer_tx,
&info,
Expand Down Expand Up @@ -880,7 +868,6 @@ impl TerminalHandle {
killer: Mutex::new(killer),
cancel: Mutex::new(None),
reap: Mutex::new(None),
#[cfg(unix)]
process: None,
info,
joins: Mutex::new(Some(vec![
Expand Down Expand Up @@ -1017,10 +1004,8 @@ enum ActorMessage {
WriterFailed(String),
ChildExited(Result<Option<u32>, String>),
/// A pipe process ended by a signal; the value is the signal's name.
#[cfg(unix)]
ChildKilled(String),
/// Writing the `output_path` file failed; it stops at this point.
#[cfg(unix)]
OutputFileFailed(String),
#[cfg(not(windows))]
RefreshForegroundProcess {
Expand Down Expand Up @@ -1111,10 +1096,19 @@ enum WriterMessage {
struct ActorMaster {
pty: Option<Box<dyn MasterPty + Send>>,
#[cfg(windows)]
close_tx: Sender<Box<dyn MasterPty + Send>>,
close_tx: Option<Sender<Box<dyn MasterPty + Send>>>,
}

impl ActorMaster {
/// A master for a process with no terminal.
fn pipe() -> Self {
Self {
pty: None,
#[cfg(windows)]
close_tx: None,
}
}

fn get(&self) -> Result<&(dyn MasterPty + Send)> {
self.pty
.as_deref()
Expand All @@ -1123,15 +1117,20 @@ impl ActorMaster {

#[cfg(windows)]
fn close(&mut self) -> Result<()> {
if let Some(master) = self.pty.take() {
// A capacity-one channel receives this unique master exactly once;
// handoff cannot wait on ClosePseudoConsole or PTY output drainage.
if let Err(error) = self.close_tx.send(master) {
// Keep ownership on failure. The actor stops receiving before
// dropping this fallback master, so its reader can still drain.
self.pty = Some(error.0);
bail!("terminal close worker stopped");
}
let Some(master) = self.pty.take() else {
return Ok(());
};
let Some(close_tx) = &self.close_tx else {
// Only PTYs have a close worker; a pipe process has no master.
return Ok(());
};
// A capacity-one channel receives this unique master exactly once;
// handoff cannot wait on ClosePseudoConsole or PTY output drainage.
if let Err(error) = close_tx.send(master) {
// Keep ownership on failure. The actor stops receiving before
// dropping this fallback master, so its reader can still drain.
self.pty = Some(error.0);
bail!("terminal close worker stopped");
}
Ok(())
}
Expand Down Expand Up @@ -1544,15 +1543,13 @@ fn run_actor(config: ActorConfig) -> Result<()> {
}
None => waiters.push(reply),
},
#[cfg(unix)]
Ok(ActorMessage::OutputFileFailed(message)) => {
if let Ok(mut value) = info.write()
&& let Some(pipe) = value.pipe.as_mut()
{
pipe.output_error = Some(message);
}
}
#[cfg(unix)]
Ok(ActorMessage::ChildKilled(signal)) => {
child_exit = Some(Ok((None, Some(signal))));
}
Expand Down Expand Up @@ -2250,7 +2247,7 @@ mod tests {
.is_pty()
.then(|| Box::new(TestMaster) as Box<dyn MasterPty + Send>),
#[cfg(windows)]
close_tx,
close_tx: mode.is_pty().then_some(close_tx),
},
messages,
writes,
Expand All @@ -2274,7 +2271,6 @@ mod tests {
killer: Mutex::new(Box::new(TestKiller)),
cancel: Mutex::new(None),
reap: Mutex::new(None),
#[cfg(unix)]
process: None,
info,
joins: Mutex::new(Some(vec![
Expand Down Expand Up @@ -2428,17 +2424,13 @@ mod tests {
for message in [
ActorMessage::Wait { reply },
ActorMessage::ChildExited(Ok(Some(0))),
#[cfg(unix)]
ActorMessage::OutputFileFailed("disk full".into()),
ActorMessage::ReaderFailed("boom".into()),
] {
actor.actor_tx.send(message).unwrap();
}
let exit = wait.recv_timeout(Duration::from_secs(5)).unwrap();
#[cfg(unix)]
assert_eq!(exit.output_error.as_deref(), Some("disk full"));
#[cfg(not(unix))]
assert!(exit.output_error.is_some());
actor.shutdown().unwrap();
}

Expand Down Expand Up @@ -2507,7 +2499,7 @@ mod tests {
drop(close_rx);
let mut master = ActorMaster {
pty: Some(Box::new(TestMaster)),
close_tx,
close_tx: Some(close_tx),
};
assert!(master.close().is_err());
assert!(master.get().is_ok());
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.