Skip to content

fix(windows): decisions are filed under a project named "unknown", and never sync - #2561

Closed
source-utsho wants to merge 2 commits into
garrytan:mainfrom
source-utsho:fix/windows-decision-store
Closed

source-utsho wants to merge 2 commits into
garrytan:mainfrom
source-utsho:fix/windows-decision-store

Conversation

@source-utsho

Copy link
Copy Markdown
Contributor

On Windows, every decision logged by gstack-decision-log is filed under a project literally named
unknown, and the Context Recovery block that should read it back never fires. Separately — and on
every platform — the decision store is not in the sync allowlist, so it never leaves the machine
even with artifacts_sync_mode on.

Measured on one machine before the fix: 62 decisions accumulated across 10 days and 170 gstack
skill runs, and were surfaced zero times.
Two of them were owner decisions that existed in no
other store, in a directory outside git and outside backup.


1. resolveSlug returns the literal string "unknown" on Windows

bin/gstack-slug is a #!/usr/bin/env bash script with no file extension. Windows honors neither
the shebang nor PATHEXT for an explicit path, so CreateProcess fails ENOENT and r.stdout is
undefined. lib/bin-context.ts:12 never inspected r.error:

const r = spawnSync(slugBinPath, { encoding: "utf-8" });
const m = (r.stdout || "").match(/^SLUG=(.+)$/m);
return m ? m[1].trim() : "unknown";   // ← every Windows call lands here

Reproduced directly:

spawn error : ENOENT / spawnSync C:\...\bin/gstack-slug ENOENT
resolveSlug : unknown

decisionPaths() then writes to ~/.gstack/projects/unknown/ — one bucket shared by every
project on the machine
. Mine mixed three.

Why it is silent

Three things had to line up, and they did:

  1. Both decision bins (gstack-decision-log and gstack-decision-search) call the same
    resolveSlug, so they miss identically. Writes and searches agree with each other and the
    store is internally consistent — just in the wrong place.
  2. The read path is bash (generate-context-recovery.ts → eval "$(gstack-slug)"), which
    resolves the slug correctly to the real project directory.
  3. That block then guards on [ -f "$_PROJ/decisions.active.json" ] with no else. The file
    isn't there, so the whole ACTIVE DECISIONS section is skipped and prints nothing.

A missing file and a working store produce identical output. Nothing logs, nothing exits non-zero.

Why shell: true is not the fix here

Unlike #1731, this is not a PATHEXT/shim-resolution problem — cmd.exe cannot run a bash script
either. And re-spawning through bash is worse than it looks: on Windows bash frequently resolves
to C:\WINDOWS\system32\bash.exe, i.e. WSL, whose $HOME and /mnt/c/... paths produce a
different slug and a different slug-cache directory. That trades one split store for
another, silently.

So this ports gstack-slug's own three steps natively — cache → git remote → basename — keeping its
[a-zA-Z0-9._-] alphabet (tr -cd deletes, it does not substitute) and, critically, its MSYS-form
cache key
(C:\Users\j\foo → /c/Users/j/foo → _c_Users_j_foo). Reproducing that key is what
keeps the native path and the shell path on the same answer; getting it wrong would re-derive instead
of reusing, and could drift.

The fallback is win32-gated, so POSIX behaviour is byte-identical.

2. No allowlist glob matches the decision store

gstack-decision-log:40 enqueues projects/<slug>/decisions.jsonl after every write. None of the
16 managed globs in .brain-allowlist match it, so compute_paths_to_stage rejects every one at its
"must match at least one allowlist glob" check.

The writer and the syncer disagree, silently: enabling artifacts sync backs up learnings, plans,
designs and timelines — everything except the durable decision ledger. A dropped path prints
exactly what a synced one does when the queue is otherwise empty.

Fixed by adding the three decisions.* globs and classing them artifact so they also sync under
artifacts-only.

Tests

test/bin-context-windows-slug.test.ts (9) exercises the fallback on every platform — only the
gating is win32-specific — so POSIX CI catches a regression that would otherwise surface only on a
Windows user's disk. Covers the MSYS cache-key derivation, all three resolution steps, https/ssh
remote forms, tr -cd deletion semantics, cache write-back with no trailing newline, plus a static
gate pinning the platform check in the style of gbrain-spawn-windows-shell.test.ts.

test/artifacts-allowlist-decisions.test.ts (3) reads the heredocs out of gstack-artifacts-init
rather than executing it, because gstack-artifacts-init.test.ts drives the real script through
#!/bin/bash shims and a colon-separated PATH and therefore cannot run on Windows — the platform
where the companion bug bites. (I confirmed that file already fails on Windows unmodified, so I left
it alone.) It applies fnmatch.fnmatchcase semantics, matching what compute_paths_to_stage uses.

Both files added to windows-free-tests.yml.

Verified by planted negative, not just by passing:

Change reverted Result
resolveSlug body only (exports kept) 2 fail, incl. "a spawn that cannot run resolves to a real slug, not 'unknown'"
gstack-artifacts-init allowlist 2 fail, marker test correctly still passes
Nothing 12 pass

Windows CI subset, run locally on Windows 11 / bun 1.3.14: 39 pass, 6 skip, 0 fail.

Not changed here

docs/gbrain-sync.md:34 still says gstack-brain-init, renamed to gstack-artifacts-init in
v1.27.0.0 — test/no-stale-gstack-brain-refs.test.ts exists but doesn't catch this one. Left out to
keep the diff focused; happy to send it separately.

Also worth a look, though out of scope: gstack-artifacts-init creates the repo with gh/glab
and then verifies it via git ls-remote over SSH. On a machine where the CLI and the SSH key
authenticate as different accounts, that aborts at line 188 before writing anything, even though
gstack-brain-sync only ever does git push origin HEAD and works fine over HTTPS. And git init
there could use core.autocrlf=false — it stores JSONL that must round-trip byte-exactly.

🤖 Generated with Claude Code

…ot spawn

bin/gstack-slug is a `#!/usr/bin/env bash` script with no file extension. Windows
honors neither the shebang nor PATHEXT for an explicit path, so spawnSync fails
ENOENT and resolveSlug returned its literal fallback, "unknown".

Every decision on the machine was therefore filed under
~/.gstack/projects/unknown/ -- one bucket shared by every project -- while the
bash-side Context Recovery preamble resolved the real slug, found no
decisions.active.json there, and skipped through a bare `if [ -f ... ]` with no
else.

Nothing failed. Both decision bins (log and search) missed identically, so writes
and searches stayed consistent with each other, and the only component that
resolved correctly was silent by design. Measured on one machine: 62 decisions
accumulated over 10 days and 170 skill runs, surfaced zero times.

shell:true is not the fix here, unlike garrytan#1731 -- cmd.exe cannot run a bash script
either. Nor is re-spawning through `bash`: on Windows that frequently resolves to
WSL, whose $HOME and /mnt/c paths yield a different slug AND a different cache
directory, trading one split store for another.

Instead, port gstack-slug's own three steps (cache -> git remote -> basename),
keeping its alphabet and its MSYS-form cache key so both paths agree. The
fallback is win32-gated, so POSIX behaviour is byte-identical.

Tests exercise the fallback on every platform (only the gating is win32-specific),
so POSIX CI catches a regression that would otherwise surface only on a Windows
user's disk, plus a static gate pinning the platform check.
gstack-decision-log enqueues projects/<slug>/decisions.jsonl after every write,
but none of the 16 managed globs matched it, so compute_paths_to_stage rejected
every one at its "must match at least one allowlist glob" check.

The writer and the syncer disagreed silently: enabling artifacts sync backed up
learnings, plans, designs and timelines -- everything except the durable decision
ledger -- and nothing reported a miss, because a dropped path prints exactly what
a synced one does when the queue is otherwise empty.

Add the three decisions.* globs and class them artifact so they also sync in
artifacts-only mode.

The test reads the heredocs out of the script rather than executing it:
gstack-artifacts-init.test.ts drives the real script through #!/bin/bash shims and
a colon-separated PATH, so it cannot run on Windows -- the platform where the
companion slug bug bit.
@trunk-io

trunk-io Bot commented Aug 14, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

garrytan added a commit that referenced this pull request Aug 16, 2026
… GSTACK_HOME-aware

Found while closing the wave's eval gate: a test exporting
GSTACK_PROJECT_SLUG from the repo root persisted the override into the cwd
slug cache, silently rebinding the ENTIRE repo's session state (evals,
decisions, timelines) to the test's slug for every later env-less run. The
escape hatch is per-invocation by contract — it no longer writes the cache.
The cache dir also hardcoded $HOME while lib/bin-context.ts's native port
(#2561) reads it GSTACK_HOME-aware, so temp-home test runs littered the real
~/.gstack (observed: 2,528 stale temp-cwd entries, swept). Writer and reader
now key the same GSTACK_HOME-aware cache; regression tests pin both
behaviors.

Also raises the cso --diff eval budget (240s/25t → 360s/40t):
transcript-verified, the wave's legitimately-grown audit session completes
the report and dies in closing telemetry at ~215s under the old budget; the
full-audit sibling already runs at 300s.

Co-Authored-By: Claude Fable 5 <[email protected]>
@garrytan

Copy link
Copy Markdown
Owner

Thank you — this landed in v1.67.0.0 (credited in the CHANGELOG). Closing since the fix is on main. 🙏

@garrytan garrytan closed this Aug 17, 2026
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.

2 participants