Skip to content

Windows: run commands in Git Bash, and open SQLite stores on Windows paths - #1882

Merged
AbirAbbas merged 7 commits into
app/v3from
fix/windows-real-bash
Oct 19, 2026
Merged

AbirAbbas merged 7 commits into
app/v3from
fix/windows-real-bash

Conversation

@AbirAbbas

Copy link
Copy Markdown
Collaborator

What was broken

On the native Windows desktop app, a conversation that started tasks lost every one of them. Each worker command, even true, failed with:

/bin/bash: -c: line 1: syntax error near unexpected token `('
/bin/bash: -c: line 1: `export PATH='C:\Users\…\bin':/usr/local/sbin:…:/mnt/c/Program Files (x86)/…

The engine starts every shell as exec.Command("bash", …), and on Windows bash resolves to C:\Windows\System32\bash.exe. That is WSL's launcher, not a bash. It passes the command line to a Linux shell, which parses it once more before /bin/bash -lc sees it. So commands ran in a different OS from the engine's file tools, and every line was evaluated twice:

  • A task worker's PlanDB prefix (export PATH='<shim dir>':$PATH …) had $PATH expanded early to WSL's PATH. WSL's PATH contains /mnt/c/Program Files (x86)/…, so every worker command failed with the syntax error above. One session lost nine tasks and its whole $5 task budget to retries.
  • Chat commands silently misbehaved. In for n in 1 2 3; do gh pr view $n; done, $n was empty, so gh pr view ran three times with no number.

Running the engine's own test binaries natively on Windows also turned up two more Windows-only defects, fixed here:

  • Background jobs and services: Git Bash exits 1 without writing anything when its stdout is an O_APPEND file from Go, so every background job and detached service would have died silently.
  • SQLite stores: url.URL{Scheme: "file", Path: path} renders C:\Users\… as file:C:%5CUsers…, which SQLite rejects ("SQL logic error: out of memory (1)"). The graph store had never opened on Windows.

What changed

  1. app: a Windows sidecar…. This commit was already written but never pushed: make app-sidecar APP_GOOS=windows APP_GOARCH=amd64, and the factory check stage moves onto internal/processgroup.

  2. Run commands in Git Bash, never in WSL's launcher. The new internal/shell package chooses the bash for every engine shell door. On Windows the order is:

    • CODEAF_BASH,
    • Git for Windows found beside git.exe,
    • the standard install folders,
    • a bash.exe on PATH that is not WSL's launcher.

    With none, nothing runs and the door names the fix. On Windows, shell.OpenLog opens job and service logs writable and seeks to the end. The skills and rtk shelves are written into PATH in bash's /c/… form. Unix argv, environment, log flags and prompt bytes are unchanged, and tests pin them.

  3. Task workers reach their plandb shim. The shim directory and both shims' exec targets are written in /c/… form. PLANDB_DB and PLANDB_RUN are read by codeaf.exe, so they keep their Windows spelling. On Windows, the worker and chat project facts name the shell, the drive form, and Git Bash's habit of rewriting a /route argument for a Windows program (gh api /repos/…). A new manual page answers "which bash does codeaf use on Windows", "can it use WSL", and what each refusal means.

  4. SQLite stores open on a Windows path. internal/sqlitefile spells the URI SQLite accepts on Windows. Its output is byte-identical to the old expression on Unix. The graph, workspace and automation stores use it.

  5. Plan-store readers name the file the writer wrote. plandb.StoreURI is the one spelling for every plan-store open. On Unix it is the writer's existing bytes exactly, so existing stores stay where they are. On Windows it is the escaped URI: the raw spelling never opened a path containing %XX or # there.

  6. Three resolver edges from review:

    • Git behind a package-manager shim is found through git --exec-path.
    • A relative CODEAF_BASH is cached per working directory.
    • Drive-relative paths are made absolute before conversion.

Validation contract

  • On Windows, every shell door parses a command exactly once: x=inner; echo "x=[$x]" prints x=[inner]. Multi-line text, quotes, %PATH%, $(…) and non-ASCII arrive byte for byte, and a PATH with Program Files (x86) never breaks a command.
  • WSL's launcher (System32/SysWOW64/Sysnative bash.exe, WindowsApps) is never chosen.
  • With no usable bash, no process starts and every door gives the same sentence. A CODEAF_BASH that is missing or names WSL's launcher gets its own refusal.
  • With an armed plan on Windows, a worker's bare plandb and codeaf reach the run's own shims from any working directory.
  • Background jobs and detached services on Windows write their output to their logs.
  • The graph, workspace, automation and plan stores open, write and read at a Windows path containing spaces, non-ASCII, %20 and #, and every plan reader reaches the file the writer wrote.
  • Linux and macOS behave exactly as before.

How it was checked

  • Native Windows (Windows 11, Git for Windows): test binaries cross-compiled from this branch and run on the host. Everything named TestWindows… passes in internal/shell, exec, session, store, workspace, automation, plandb, manual and sqlitefile. That includes the real worker belt with both shims, the background job and service doors, and every store.
  • Local gates (this box, Linux), since app/v3 pull requests get no CI run:
    • Builds: Linux, GOOS=windows, and GOOS=darwin.
    • Checks: go vet for both OSes on the touched packages, gofmt, the packed manual, the manual gates, carried help, belt pages and tooling.
    • Each intermediate commit builds and vets on its own for Linux and Windows.
    • Touched-package suites: see the gate result below.
  • Already red on app/v3, not touched here:
    • make test-laws: TestNoRoadInTheMemoryEngineHasMoreEndingsThanTheCeiling (automation.Store.MadeInTeam, 30 decisions against a ceiling of 15). It reproduces on 0bf1f2fd8.
    • changelog-check: 144 problems in existing docs/changes/unreleased/ entries.
    • The touched-package classifier attributes TestPlandbCliConcurrentWritersLandEveryTask and TestEightyConcurrentAddsFromSeparateHandlesAllLand as already failing on the base under load, and TestUntrustedWorkAsksAndTheLadderClimbs as flaky.
  • An adversarial review pass found the plan-reader regression (commit 5) and the three resolver edges (commit 6). All are fixed and re-run natively on Windows.

Not in this PR

  • internal/store's full suite run natively on Windows still has 9 failures out of 327 tests. None involve the shell or opening a store. One is a real product gap: a worker report that names a file as C:\… does not get that file carried as a deliverable. The others are Unix-shaped test assumptions (chmod, ~/ display, timing).
  • internal/seniordev's $VIRTUAL_ENV/bin PATH prefix (a Windows venv uses Scripts), and the v1 resident's sh -c, are left as they were.
  • Cygwin's /cygdrive/ prefix is not supported, and the manual says so.

🤖 Generated with Claude Code

AbirAbbas and others added 7 commits October 19, 2026 16:39
The factory check stage put its shell in a process group with Setpgid and
killed it with syscall.Kill(-pid), neither of which exists on Windows, so
app/v3 stopped compiling for GOOS=windows. It now uses internal/processgroup,
which is the same Setpgid/SIGKILL on Unix and taskkill /T on Windows.

make app-sidecar APP_GOOS=windows APP_GOARCH=amd64 now builds
dist/app/codeaf-x86_64-pc-windows-msvc.exe. Windows has no pinned furrow, so,
as release.yml does, it skips the fetch and builds without one. It also skips
garble: Microsoft Defender quarantined the garbled binary on first run as a
virus or potentially unwanted software. app-sidecars still builds the four
macOS and Linux triples only.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
On the native Windows desktop every shell door ran exec.Command("bash", ...),
and Windows resolves "bash" to C:\Windows\System32\bash.exe: WSL's launcher,
not a bash. It hands the command line to a Linux shell that parses it once
more before /bin/bash sees it, so the commands ran in another OS and were
evaluated twice. A chat's `for n in 1 2 3; do gh pr view $n; done` ran with
an empty $n, and (next commit) every task command failed outright.

internal/shell now chooses the bash for every engine door. On Windows it is
CODEAF_BASH, else Git for Windows found beside git.exe, else the standard
install folders, else a bash.exe on PATH that is not WSL's launcher; with
none, nothing runs and the door says how to fix it. Unix argv is unchanged.

Git Bash also exits 1 without writing anything when its stdout is Go's
append-only Windows handle, which killed every background job and detached
service, so shell.OpenLog opens their logs writable and seeks to the end
on Windows. The skills and rtk shelves go on PATH in bash's /c/... form.

A few exec, factory and session tests used syscall.Kill and Unix-only
fixtures, so their test binaries could not be built for Windows; those
helpers are split by platform with the Unix bytes unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…s shell

A task worker's commands carry `export PATH='<shim dir>':$PATH PLANDB_DB=...`.
Through WSL's launcher the $PATH in it was expanded early to WSL's PATH,
whose /mnt/c/Program Files (x86)/... entries ended every worker command,
even `true`, with "syntax error near unexpected token `('". On 2026-10-19 a
desktop session lost nine tasks and its $5 task budget to it.

With a real bash that line parses, but a C:\ entry in a PATH list splits at
the colon, so the shim directory and both shims' exec targets are now
written in bash's /c/... form. PLANDB_DB and PLANDB_RUN are read by
codeaf.exe and keep their Windows spelling. A bash or sh check script's
file argument is converted the same way.

On Windows the worker and chat project facts name the shell, its /c/...
drive form, and Git Bash's habit of rewriting a /route argument for a
Windows program (gh api /repos/...). The manual gains a page that answers
which bash codeaf uses on Windows, why not WSL, and what each refusal means.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Every store built its SQLite name as url.URL{Scheme: "file", Path: path},
which renders C:\Users\... as file:C:%5CUsers%5C..., and SQLite refused it
with "SQL logic error: out of memory (1)". The graph store had never opened
on the Windows desktop: its home held automations.db and no graph.db.

internal/sqlitefile spells the URI SQLite accepts on Windows
(file:///C:/Users/..., and file:////server/share/... for a share), and is
byte-identical to the old expression on Unix. The graph, workspace,
automation and plan-reader stores and the session's read-only spend opens
use it. plandb's own store already spelled file:C:/... and opened, so it is
left alone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The previous commit moved the plan-store readers to the escaped SQLite URI
while plandb's writer kept its raw "file:" + path spelling. SQLite decodes
%XX in a raw filename and stops it at #, so for a store path holding either
the readers and the writer addressed different files and every spend, usage
and task read came back empty, on Linux as well.

plandb.StoreURI is now the one spelling every plan-store open uses, and on
Unix it is the writer's bytes exactly, so existing stores stay where they
are and the session readers return to their old bytes. On Windows the raw
spelling never opened such a path at all, so there it is the escaped URI,
which names the same file for every ordinary path.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…e paths

Three edges of the Git Bash resolver:

- A git.exe outside Git's own layouts (a package manager's shim) is asked
  `git --exec-path` once, under a three-second limit, and Git Bash is found
  up to four folders above the answer. A failure falls through.
- A relative CODEAF_BASH is bound to the working directory, so the cached
  answer now includes that directory.
- C:skills\bin and \tools\bin are made absolute by Windows' own rules
  before conversion; replacing separators alone kept the C: (which bash
  splits as a PATH separator) or sent bash under its own install root.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@AbirAbbas
AbirAbbas merged commit 9200731 into app/v3 Oct 19, 2026
1 check passed
@AbirAbbas
AbirAbbas deleted the fix/windows-real-bash branch October 19, 2026 22:32
santoshkumarradha pushed a commit that referenced this pull request Oct 24, 2026
On native Windows codeaf's bash resolved to System32\bash.exe, the WSL
launcher, which parsed every line a second time inside Linux: a PATH holding
Program Files (x86) broke every command and $vars came back empty. The
shell now resolves CODEAF_BASH, then Git for Windows, then other standard
roots, then a non-WSL bash on PATH, and every door that starts a shell uses
it. Background job and service logs open writable at their end, because Git
Bash exits silently on an append-only handle. With no usable bash the shell
tool is absent and the manual says to install Git for Windows.

This ports the Windows fixes of #1882, which landed on app/v3, to dev.

Co-Authored-By: Claude Opus 5.5 (1M context) <[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