Repository navigation
Conversation
… on Windows Terminate killed only a terminal's root process, then waited without limit for the ConPTY output to end. A program that cannot leave the console (a suspended one, as when Git Bash's prompt starts git while its MSYS parent is killed) kept that output open, so the delete never answered and the console host leaked. The root shell now runs in a job; when teardown has not finished after a grace period, terminate ends what is left of the job, and it stops waiting after another one.
A request whose reply goes missing never reset the registration, so a daemon that still accepted connections but answered nothing failed every later shell and terminal request until the server restarted. When a ping on a fresh connection gets no reply either, give the daemon up so the next request starts a fresh one. Also keep the daemon's stderr in a capped log beside its runtime directories, and name Smart App Control and application control policies when Windows refuses to start the binary.
Session terminals ignored the shell config and fell back to \, which is usually unset on Windows, so they always opened PowerShell while the shell tool used the configured shell. Resolve the configured shell in the session's location, with the config loaded now, when the client sends no command.
…Shift+PageUp A Windows clipboard ends lines with CR LF, which PowerShell read as Enter plus a stray line feed; pasted line breaks now go to the PTY as one CR. Shift+PageUp, PageDown, Home and End move through the scrollback on the normal screen, as in other terminals, and still reach programs on the alternate screen.
The persistent terminal smoke test expected the PTY root to hold only the daemon's runtime directory; it now also holds opencode-pty.log.
There was a problem hiding this comment.
The configured-shell fix and the unresponsive-daemon replacement work as described. I checked both by running the new server and core tests on the base, where they fail, and on this branch, where they pass. I couldn't run the Windows job-object teardown (no Rust toolchain, and it's Windows-only) or the desktop terminal's paste and scroll-key changes here.
Public API: no HTTP, SDK, config or CLI changes. Session terminals created without command now open the configured shell instead of $SHELL, and the daemon now writes <state>/pty/opencode-pty.log.
Concerns, in order:
- The new log file breaks the existing server test
creates two persistent terminals for one session through the client API. It passes on the base and fails here. - The configured shell isn't loaded yet when a terminal opens on a cold location.
- Taking over Shift+Home and Shift+End also takes them from PowerShell's line editor (PSReadLine), which uses them to select text.
- The new server test is heavy for what it checks.
|
|
||
| // One log for every daemon of this root, beside their runtime directories, which their sweep leaves alone. It starts | ||
| // over once it passes 1 MB. | ||
| async function openLog(root: string) { |
There was a problem hiding this comment.
The log goes in root, next to the daemon's runtime directories. That breaks creates two persistent terminals for one session through the client API in packages/server/test/persistent-pty.test.ts: it reads fs.readdir(fixture.directory) and expects exactly one entry, the daemon directory, and now gets opencode-pty.log as well. It passes on the base and fails with this PR. Either update that test or move the log somewhere the runtime-root listing doesn't see. Separately, the 1 MB check only runs when a daemon is spawned, so a long-lived daemon can still grow the file without limit.
| // Terminals are process-global and the configured shell belongs to a location, so read it in the session's | ||
| // location, with whatever config is loaded now, to open the shell the shell tool runs. Without the session or its | ||
| // location the terminal keeps the default shell. | ||
| const configuredShell = (sessionID: string) => |
There was a problem hiding this comment.
Because this reads whatever config is loaded at that moment, a terminal opened before the location's plugins have loaded still gets the default shell. That includes the first terminal after a cold start, which is exactly the Windows case #51051 is about. The new test has to poll /api/shell until the shell shows up before it opens a terminal. Users who open a terminal right after launch will still sometimes get PowerShell. Could this wait for the location's config to be ready, even if not for all plugins?
|
|
||
| // Programs on the alternate screen (vim, less) keep these keys; on the normal screen they move through the | ||
| // scrollback, as in other terminals. | ||
| const scroll = terminalScrollKey(event) |
There was a problem hiding this comment.
On the normal screen this always takes Shift+Home and Shift+End. PowerShell's line editor (PSReadLine), the main Windows shell, binds them by default to select to the start and end of the line, and fish and zsh users sometimes bind them too. Windows Terminal leaves Shift+Home and Shift+End to the shell and only scrolls with Ctrl+Shift+Home and Ctrl+Shift+End. Shift+PageUp and Shift+PageDown look safe; Home and End could be limited to Ctrl+Shift, or not taken at all.
| const base = HttpServer.formatAddress(server.address) | ||
| const session = yield* request(base, "POST", "/api/session", { location: { directory: fixture.root } }) | ||
| const sessionID = Schema.decodeUnknownSync(Schema.Struct({ id: Session.ID }))(session.data).id | ||
| // The configured shell arrives with the location's plugins, and the server answers with what is loaded, so wait |
There was a problem hiding this comment.
This test is heavy for what it checks: a 30 s timeout, a real-time loop that polls /api/shell with 20 ms sleeps until the config loads, and a full server boot. Its timing depends on how fast the location boots, which makes it likely to be flaky on slow CI. If the handler waited for config (see the comment in the handler), this could shrink to one request and one assertion. Otherwise, a smaller check of the shell-resolution step would cover the fix.
PowerShell's PSReadLine selects to the start and end of the line with Shift+Home and Shift+End. Go to the top and bottom of the scrollback with Ctrl+Shift+Home and Ctrl+Shift+End instead, as Windows Terminal does, and also page with its Ctrl+Shift+PageUp and Ctrl+Shift+PageDown.
There was a problem hiding this comment.
The new commits fix two earlier points. The runtime-directory test now accounts for the log file and passes. Shift+Home and Shift+End now go to the shell; Ctrl+Shift+Home and Ctrl+Shift+End go to the top and bottom. The rest of the log thread is still open: the 1 MB limit is only checked when a daemon starts, so a long-running daemon can still grow the log without limit. The points on reading the configured shell before config loads, and on the size of the server test, are also unchanged. Checked by running the server persistent-pty tests (8 pass) and the gui-plugins key tests (8 pass), plus a gui-plugins type check. Public API is unchanged.
Issue for this PR
Closes #61644
Closes #51051
Closes #65655
Closes #65666
Refs #65175, #63241
Type of change
What does this PR do?
A batch of Windows terminal fixes, one commit each:
git rev-parseis left suspended with its MSYS parent gone. The DELETE then times out with a 503, and the conhost and git leak for good. The root shell now runs in a job object. It is not kill-on-close, so programs started from a terminal still outlive it as before. If teardown has not finished after 1.5 s, terminate ends what is left of the job; after another 1.5 s it stops waiting rather than hang.<state>/pty/opencode-pty.loginstead of nowhere; the file starts over past 1 MB. When Windows refuses to start the binary (EUNKNOWN … uv_spawn), the error now names Smart App Control and application control policies (terminal: opencode-pty.exe blocked by Windows Smart App Control -> couldn't create a terminal #63241; the binary still needs signing, see below).shell(session terminal ignores the "shell" config option (always PowerShell on Windows) #51051). They fell back to$SHELL, usually unset on Windows, so they always opened PowerShell while the shell tool used the configured shell. The handler now resolves the configured shell in the session's location with the config loaded now; it does not wait for plugins. This replaces fix(server): resolve the configured shell for session terminals #61353, which no longer applies to dev and waited for plugins in the handler.>>prompt. On the normal screen, Shift+PageUp and Shift+PageDown (and Windows Terminal's Ctrl+Shift+PageUp/PageDown) page through the scrollback, and Ctrl+Shift+Home and Ctrl+Shift+End go to the top and bottom. Shift+Home and Shift+End stay with the shell, because PowerShell's line editor uses them to select text. On the alternate screen, all of these still go to programs such as vim and less.No feature flag: these are fixes. The daemon change reaches users with the next
@opencode/ptyrelease.Not in this PR: signing
opencode-pty.exeinrelease-process-daemon.yml. That needs the Windows job to log in to Azure under the release environment, which I can't set up or test from here.How did you verify your code works?
On Windows 11 (26H2), with pwsh 7, PowerShell 5.1, cmd and Git Bash:
terminating_a_terminal_ends_a_descendant_that_cannot_leave_its_console(tests/runtime.rs). It hangs on dev until the 45 s watchdog and passes in about 1.5 s with the fix. The full daemon suite,cargo fmt --checkandcargo clippy --all-targets --all-features -D warningspass.replaces a daemon that takes requests but no longer answers them, on TestClock,--rerun-each 10. The existing "does not replay a dispatched mutating request" test still passes. Also new: a Windows test for the refused-spawn message.opens a session terminal in the configured shell. It fails on dev withpwsh.EXEinstead of the configured shell.terminalScrollKeyunit tests, including that Shift+Home and Shift+End are left to the shell; all 135 terminal tests in gui-plugins pass. I checked the paste bytes against pwsh, PowerShell and cmd PTYs.bun run typecheckpasses (36 tasks) andlint:changedis clean.bun run lintfails only oncheck-greysinservices/site, which this PR doesn't touch. In core,rejects incompatible daemons…fails on Windows before and after this change because it spawnssleep.Screenshots / recordings
No UI change beyond key handling and paste.
Checklist
Added by the opencode bot (AI-generated).
Related: #65175, #63241