Skip to content

Windows: a session can finish — stops that stop, state that survives, a first run that works - #2546

Merged
AbirAbbas merged 30 commits into
app/v3from
windows/stability
Nov 10, 2026
Merged

AbirAbbas merged 30 commits into
app/v3from
windows/stability

Conversation

@AbirAbbas

@AbirAbbas AbirAbbas commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

CodeAF had never completed an end-to-end session on native Windows (not WSL), from the desktop app or the CLI. A native-Windows investigation found no single bug: shared code silently assumed POSIX in several places, and no test ever ran on Windows. This PR fixes the engine side so a Windows session can get from first launch to a stopped dev server and a reviewed change. A companion desk PR fixes the desk's path handling.

The rule throughout is one implementation with thin OS leaves. OS-specific code lives only behind existing function signatures in _windows.go / _unix.go files or one small runtime.GOOS check. macOS and Linux behave as on app/v3, except for the additive changes listed under macOS and Linux.

What changes

Stopping a process stops it (processgroup, jobs, services, checks, delegates)

  • On Windows every launch starts suspended, joins its own Job Object, then resumes, so nothing it spawns can escape. That includes npm's cmd.exe /d /s /c node … chain, which used to detach and keep serving after Stop.
  • Stop is still the soft stop first, then a whole-job hard kill. On Windows it reports stopped only once the job has no live process; an unverified ending stays running and sends no stopped note. macOS and Linux keep their existing signal-and-wait stop and receipts.
  • There's deliberately no kill-on-close: lifetimes match POSIX, and deliberate detaches still outlive the engine.
  • The model's Windows shell facts now say: python/py instead of the python3 Store stub, npm/npx are .cmd shims, and long-running servers should be started and stopped with the jobs tool, because Git Bash's kill can't reach native processes.

State files survive Windows file semantics (fsreplace and its callers)

  • fsreplace.Open/OpenFile open held state files with delete sharing. fsreplace.Remove/RemoveAll retry transient locks.
  • On Windows 10 1709+ (NTFS), fsreplace.Rename replaces a file another handle holds open with a POSIX-semantics rename (FileRenameInfoEx). It falls back to the existing retrying rename elsewhere.
  • Reminders fire on Windows. The automation presence lock file is renamed while it is held, which Windows refused, so the clock never saw a window.
  • Spending is no longer lost from history, and the day cap holds. An append-only handle could not take the ledger lock on Windows. Separately, a spending window now counts calls at the current clock tick (all OSes).
  • Conversations can be permanently deleted. Sync, service, task copy, task storage and task door state now publish through fsreplace.

The first session can succeed (setup, doctor, opener, installer)

  • A fresh setup's default model is the engine's one default-model constant (the CLI's), not a ranked pick that had landed on a 1.7B model.
  • The stored provider key is checked once, in the background, when setup.get or health.check is first read or a key is handed over. It is never checked at launch, so a quiet engine stays quiet. The check has a short timeout and a cached result, and reads never wait for it. setup.get / health.check expose it as ok / invalid / unknown. A 401 on a real turn marks it invalid. codeaf doctor checks it directly.
  • codeaf doctor also reports git identity, gh auth status and, on Windows, whether Git Bash was found, each with a timeout and a fix hint (every OS). The desk's health.check carries those readiness checks only on Windows: on macOS gh reads its token from the login Keychain, and probing on every desk read could prompt.
  • On Windows the opener uses the file-protocol handler, so sign-in can open the browser.
  • scripts/install.sh run from Git Bash adds the install folder to the user's PATH, or prints the exact command to do it.

Text and paths (exec tools, folder picker, report references)

  • On Windows, headless codeaf do/exec/run commands run bash -c instead of a login shell (a login shell cost ~300 ms per command there; chat already used bash -c), and health checks use the shared Git Bash resolver with pipefail. macOS and Linux keep bash -lc for headless commands and their original health checks, so a deployment that gets PATH from a login profile is unaffected.
  • UTF-16 files with a BOM (what Windows PowerShell 5.1 writes) are decoded on read, and edits keep their encoding and BOM (every OS). On Windows, edits and appends keep the file's line endings and the model sees command output with CRLF normalised to LF; macOS and Linux keep the original bytes.
  • On Windows the folder picker and report references accept C:\…, C:/… and UNC paths; macOS and Linux path handling is unchanged.

Desk checkout on Windows: the contained open behind diff previews of new files and behind Open/Reveal was Unix-only, so every new file read as "could not be opened safely". It now uses the same os.Root walk on Windows; only the leaf's open flags differ.

CI: a new advisory windows native tests job runs 306 named tests in 29 packages on windows-latest. Every listed test passed natively. It is not part of check yet.

macOS and Linux

Before merging, every non-test change in this PR was audited (121 files) as Windows-only, unchanged on macOS/Linux, or shared, so existing macOS and Linux deployments keep working.

Windows-only, with the macOS/Linux behaviour pinned to app/v3 by TestUnixParity* tests and per-OS contract tests:

  • non-login headless shell (bash -c); unix keeps bash -lc
  • CRLF→LF normalisation of command output
  • line-ending coercion on file-tool rewrites and edits
  • pipefail and the Git Bash resolver in resident health checks
  • stop proof and receipts for jobs that will not die
  • reading the usage ledger through a locked read handle
  • native folder parents in the folder picker, and native report pointers
  • seniordev/patch intercepting bash -c
  • unbounded snapshot diagnostics capture
  • the desk's gh/git readiness probes on setup.get/health.check

Shared on every OS (additive; nothing that worked before changes):

  • the provider key check: never at launch (the C27 "a new chat stays quiet" law), lazily on the first setup/health read, deduplicated per key
  • the default model for a fresh setup; a saved model is kept
  • codeaf doctor's new checks
  • the optional health wire fields, omitted when empty, so older payloads still decode
  • UTF-16 BOM files, durability fixes, and spending at the current clock tick

Proposed follow-ups, each with its own cross-platform hand test:

  1. A non-login headless shell on macOS/Linux for speed, as a deliberate change with its own change note.
  2. The desk's readiness checks on macOS/Linux, once gh can be probed without Keychain prompts.
  3. Line-ending preservation on unix edits.
  4. The pipefail "early reader" mark on stock macOS bash 3.2: yes | head -1 exits 141 there. This is pre-existing and was found on the Mac run.

Validation contract

  1. On Windows, stopping a job, service or process ends its whole tree. That includes children whose parent already exited and children started through .cmd shims. Their ports are free afterwards.
  2. On Windows, "stopped" is reported only after the tree is verified gone. macOS and Linux stop and report as on app/v3.
  3. A writer can replace a state file while a reader holds it open through fsreplace; the reader keeps its old generation. A due reminder fires on Windows.
  4. Spending survives on Windows, and the day cap refuses an over-cap call.
  5. A fresh setup uses the shared default model. A dead key is reported by the first setup/health read, before the first turn; starting the engine makes no key request. A machine missing git identity, gh sign-in or Git Bash is told so, with the fix.
  6. On Windows, headless commands don't start a login shell, line endings are kept and native paths are accepted. UTF-16 files are read and edited in their encoding on every OS.
  7. On macOS and Linux, shells, command output, file-tool bytes, health checks, stop receipts and paths behave as on app/v3 (TestUnixParity*).

New tests are named after their contract item (TestContractWindows*, TestPublishContract*, TestSetupContract*, TestTextContract*, TestIntFixContract*, TestUnixParity*).

Evidence

The same Windows-relevant test selection was run natively on Windows 11 (Go 1.26.5, Git for Windows defaults, Defender on), at the base commit and with this branch:

Area Base This branch
automation (reminders) 20 fail 0 fail
service 58 fail 1 fail
syncsetup 36 fail 1 fail
session (usage, deletion) 15 fail 0 fail
factory/serve sessions 16 fail 1 fail
taskdoor / taskstorage 13 fail 0 fail
new Windows contract tests (processgroup, exec, delegate, fsreplace) — all pass
folder picker / report paths / text (tui3, head, store, exec/bare) — all pass

Headless codeaf exec on Windows: 35–39 ms between model requests for no-op commands, down from 282–320 ms with the login shell.

A scripted model then drove the real engine and the desk on Windows. Edit a CRLF file, write a new file, shell basics, a long command, cancel, quit and relaunch, path variants, UTF-16 read and edit, and a task with landing all behaved as on Linux. In the dev-server scenario (npm start, curl, jobs kill), nothing was left on the port afterwards. Pressing the desk's Stop button on npm start ended node src/server.js and freed its port. Before, the server kept serving under cmd.exe /d /s /c while the desk said "stopped".

Stability check before merge (head e38a7a6, base a687c92)

Windows 11, native (Go 1.26.5, Git for Windows defaults, Defender on):

  • The 306 tests the new windows native tests job lists: 305 pass. The one failure is TestTakeLedgerRemoteIdentityCombinations, which is Windows: taking a chat back to a computer it was on fails with "Access is denied" in the handoff swap #2565 (below) and fails earlier at base.
  • TestUnixParity*: 11 pass; the 3 unix-only cases skip on Windows.
  • The scripted-model scenarios behave as in the earlier run.
  • The desk against this engine: Stop on npm start frees the port, quitting stops running jobs ("stopped by quit"), and the diff preview of a new file opens.

macOS 15.6, Apple silicon (Go 1.26.5):

  • go build ./... and go vet on the 30 touched packages pass.
  • The PR's contract tests at the head, verbose: 40 of 40 pass, none skipped (TestUnixParity* 16, TestTextContract* 13, TestContract1/3 2, TestSetupContract* 8, TestUnixDoorArgv 1). Four more live in _windows_test.go files.
  • Across the touched packages (cmd/codeaf sharded), no failure is new. Every failure reproduces identically at the base:
    • the bash 3.2 pipefail early-reader mark (follow-up 4);
    • fence writes into the macOS /private/tmp scratch;
    • cmd/codeaf factory/memory fixtures that expect bash on PATH;
    • TestRunSurface*;
    • a prompt-prefix budget 5 bytes over.
  • Three syncsetup tests hit wireauth: clock skew while the machine slept. They pass at head and base on a rerun with sleep prevented.
  • codeaf --version and codeaf doctor exit 0 under a throwaway home with no gh on PATH, and the doctor rows are as expected. Nothing touched the login Keychain and no Keychain prompt appeared.

CI: all 10 checks green at e38a7a6, including the advisory windows native tests job.

Not in this PR

  • Re-enabling the specialists on Windows (internal/delegate/builtin/carried_windows.go). They still need the hold/report foundation (handle inheritance, descriptor-relative report reads, boot identity).
  • Cross-machine task copy on Windows: 18 internal/taskcopy tests still fail on POSIX permission bits and portable full history.
  • Short task roots for long-path headroom. Evidence: moving the same task scenario's folder 5 characters deeper made git worktree add fail with "Filename too long" on Windows, at base and with this branch alike.
  • The default work folder. It still falls back to the home folder, a product decision that was parked earlier.
  • TestAServedFactoryStartsAGoAheadsJobWithNoAppAttached can fail with TempDir RemoveAll cleanup … directory not empty, on app/v3 too (about 3 in 20 runs). The cause: the served factory's GitHub poll was cancelled but never joined, so a pass could still write after serveFactory returned. Fixed in the app/v3 → dev landing (land/app-v3 8e3411a).
  • Windows: taking a chat back to a computer it was on fails with "Access is denied" in the handoff swap #2565: on native Windows 11, moving a chat back to a computer it was on before (A→B→A→B) fails with "Access is denied" when the handoff sets the old chat folder aside. TestTakeLedgerRemoteIdentityCombinations reproduces it there; it passes on GitHub's Windows runner. app/v3 fails the same test earlier, so it is tracked separately and does not block this PR.
  • cmd/codeaf tests compiling on Windows. tests: FIFO and Unix-helper cases build for Windows; make vet checks the Windows test build #2192 covers the syscall.Mkfifo/Kill fixtures, plus one newer syscall.Kill in app_one_engine_test.go.

Test plan

  • Focused Linux tests, go vet, GOOS=windows/GOOS=darwin vet and test compilation for every touched package
  • Native Windows run of the selection above (base vs branch)
  • Real engine on Windows: the full scripted scenario set (dev-server stop through jobs kill, cancel, task and landing, quit and relaunch, UTF-16, per-command overhead); desk Stop, diff review and new-file preview against this engine
  • make test-quick, make test-tooling, make changelog-check locally. Touched packages run in CI; locally only the tui3 frame law fails under load, and it fails on base too.
  • CI, including the new Windows job (10/10 at e38a7a6)
  • Windows native rerun after the macOS/Linux scope change (CI test list, TestUnixParity*, scenarios, desk Stop / quit / new-file preview)
  • macOS rerun after the scope change: build, vet, touched packages vs base, every contract test, codeaf doctor with no Keychain use

🤖 Generated with Claude Code

AbirAbbas and others added 20 commits November 9, 2026 16:21
…chine readiness checks

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and line endings; the model sees LF output

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the same contained open

The contained open behind checkout.diff's untracked preview and checkout.locate was Unix-only, so on Windows every new file read as 'could not be opened safely' and no changed file could be opened or revealed. os.Root works on Windows; only the leaf's open flags differ (no O_NOFOLLOW or O_NONBLOCK there), and the same-file check after the open still refuses a leaf swapped for a link.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… POSIX-semantics rename

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ore rebinding its port

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… (advisory)

No engine test ran on Windows before; the engine only cross-built for it. The new job runs 306 named tests in 29 packages on windows-latest: process-tree stops, state replacement while held, reminders, spending, native paths, UTF-16 and line endings. It is not part of check yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er at launch

A launch-time probe made a quiet engine send /key and /auth/key before anyone asked (TestC27NewChatByDefaultStaysQuiet), and the CLI started one on every command. Starting the engine now only enables key health; the first setup.get or health.check (or a key handover) starts one background check per key, and reads never wait for it. doctor still checks directly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AbirAbbas
AbirAbbas marked this pull request as ready for review November 9, 2026 21:53
Conflict in cmd/codeaf/app.go: this branch starts the lazy key health
check where app/v3 added the quit-time receipt hurry; both are kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AbirAbbas and others added 5 commits November 10, 2026 01:38
… bytes and health checks

The non-login foreground shell, CRLF-to-LF output, line-ending coercion on
rewrites and pipefail health checks are Windows-only. On macOS and Linux a
headless command loads the login profile again (bash -lc), captured output
keeps its bytes, ordinary rewrites write what they are given, and a health
check's status is its last command's, as before this PR. The PR's text and
shell contract tests now state each OS's rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…order

Proof that the whole tree is gone before a kill reports stopped, and locking
the usage ledger through its read handle, are Windows-only leaves. Unix keeps
the original signal receipt and writer flock order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AbirAbbas and others added 3 commits November 10, 2026 01:38
…adiness probes on Windows only

The lazy key check, the default model for a fresh setup and codeaf doctor's
new checks run on every OS; their wire fields are optional, so older payloads
still decode. The desk's setup and health reads run gh and git probes only on
Windows: on macOS gh reads its token from the login Keychain.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AbirAbbas
AbirAbbas merged commit 6059677 into app/v3 Nov 10, 2026
10 checks passed
@AbirAbbas
AbirAbbas deleted the windows/stability branch November 10, 2026 08:52
AbirAbbas added a commit that referenced this pull request Nov 10, 2026
AbirAbbas added a commit that referenced this pull request Nov 13, 2026
Crew members with nothing in flight are answered from their files rather
than held open, and a quiet member is let go after the idle time. Their task
lists are remembered in a bounded memory and disk cache. Readers pin a
conversation so that release never tears it down mid-read, and opening a
settled conversation no longer rewrites unchanged files. The engine's GC
percent now follows the live heap.

The port keeps dev's later guarantees (#2313, #2014, #2016, #1971, #1991,
#2041, #2556, #2090, #2546). It reshapes every new gate site for the
lock-defer law, so lockRelease expects its caller to hold the gate already;
close and delete take the gate before calling it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AbirAbbas pushed a commit that referenced this pull request Nov 13, 2026
Crew members with nothing in flight are answered from their files rather
than held open, and a quiet member is let go after the idle time like any
other conversation. Their task lists are remembered while their files are
unchanged, in memory (24 MiB) and in a rebuildable disk cache (96 MiB, 256
files). Readers pin a conversation so that idle release, close and delete
never tear it down mid-read, and explicit close and quit stay bounded.
Opening a settled conversation no longer rewrites unchanged tasks.json or
meta.json, and the engine's GC percent follows the live heap.

Ported from app/v3 onto dev. It keeps dev's later guarantees (#2313, #2014,
#2016, #1971, #1991, #2041, #2556, #2090, #2546), and every new gate site
follows the lock-defer law.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant