Skip to content

gbrain-refresh no longer deletes a healthy brain-aware render when python3 is the Windows Store alias (#1967) - #4752

Closed
Barack-zero-to-one wants to merge 2 commits into
garrytan:mainfrom
Barack-zero-to-one:fix/windows-python3-stub-gbrain-refresh
Closed

Barack-zero-to-one wants to merge 2 commits into
garrytan:mainfrom
Barack-zero-to-one:fix/windows-python3-stub-gbrain-refresh

Conversation

@Barack-zero-to-one

Copy link
Copy Markdown
Contributor

gstack-config gbrain-refresh now reads the gbrain detection file with the first of python3 and python that runs, then grep, so a healthy gbrain is no longer reported as not detected and its brain-aware render is no longer deleted.
Why: on Windows python3 is often the Microsoft Store alias, which exits 49 and stays on PATH next to a python.org install, including during the refresh run after each auto-update.
Nothing to do; where python3 works, nothing changes.

Root cause

In bin/gstack-config, gbrain-refresh chose its interpreter with command -v python3 || command -v python and never checked that it runs. The Store alias prints its hint on stderr and exits 49, so both parses fell to || echo unknown, and the grep fallback stayed unreachable because PYTHON_CMD was set. The *) branch then printed "gbrain not detected (local-status: unknown)" and, with a global install present, removed $RENDER_DIR through gstack_claude_render_action "$RENDER_DIR" absent, although gbrain-detection.json said ok. bin/gstack-session-update runs this refresh silently after every pull, so a Windows team-mode install loses its brain-aware skills on each update. #3025 fixed the MSYS path half of #1967 by passing the file on stdin. The reporter of #1967 also had python3 under WindowsApps, and this cause survives that fix.

Fix

The parse now tries python3, then python, keeps a result only when both reads exit 0, and otherwise uses the existing grep fallback. Before this change that fallback ran only on a machine with no Python at all, and under set -euo pipefail a field grep could not find ended the run with exit 1 and no output. The no-cli record written when detection fails has no gbrain_version, so that case is common once the fallback is reachable; both greps now end with || true. Production change: 29 lines in bin/gstack-config.

Tests

test/gstack-config-gbrain-refresh.test.ts gains a stub that behaves like the Store alias (hint on stderr, exit 49) and four cases. With the alias under both names, the grep fallback reports Detected gbrain v0.35.8.0 (local-status: ok). With the alias only as python3, python parses the file, and the stub records that it ran twice before grep. With a fake global install and an existing render, a failed render step leaves the render file intact instead of printing "Removed the brain-aware render". A failed detection is reported as local-status: no-cli with exit 0. All four fail on main; the existing two cases still pass unchanged.

Run on Windows 11 with Git Bash and bun 1.4.5: the file passes 6 of 6, and test/gbrain-refresh-install-render.test.ts and test/plan-mode-preamble-render.test.ts pass. test/claude-overlay-setup-lifecycle.test.ts and test/claude-overlay-setup-recovery.test.ts skip on win32, so these integration tests rely on the Linux free-tests.yml run of this PR.

Reproduction

On a Windows machine where command -v python3 prints .../Microsoft/WindowsApps/python3, copy bin/ to a temp root, stub gstack-gbrain-detect to print {"gbrain_on_path":true,"gbrain_version":"0.9.1","gbrain_local_status":"ok"}, create $HOME/.claude/skills/gstack with VERSION and package.json and a file under $GSTACK_STATE_ROOT/render/claude, then run gstack-config gbrain-refresh. main prints "gbrain not detected (local-status: unknown)" and deletes the render. This branch prints "Detected gbrain v0.9.1 (local-status: ok)" and keeps it.

… Windows Store alias

gstack-config gbrain-refresh took the first python3 or python on PATH without
checking that it runs. On Windows python3 is often the Microsoft Store alias,
which exits 49, so every parse read as unknown, the grep fallback stayed
unreachable, and the not detected branch removed the brain-aware render,
including in the refresh gstack-session-update runs after each pull.

The parse now uses the first of python3 and python whose two reads succeed,
then grep. Both greps end with || true: under set -euo pipefail a field missing
from the detection file, such as the version in the no-cli record, ended the
run with exit 1 and no output.
@trunk-io

trunk-io Bot commented Nov 23, 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

@capy-ai

capy-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, and for the four failing-first tests and the Windows run. The bug is real and worth fixing: bin/gstack-config on main picks python3 with command -v and never checks that it runs, so the Store alias turns a healthy detection into "unknown" and the refresh after an auto-update removes the brain-aware render.

We're picking it up. Because bin/gstack-config runs during every auto-update, we don't merge outside branches that change it; a fix thread rebuilds the change on our own branch from current main, keeps your tests, and credits you with a Co-authored-by trailer. Our tracking thread GSTA-36 is assigning it, and we'll close this PR with a link once the rebuild lands.

@capy-ai

capy-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Thanks for the careful root cause and the failing tests. Because this runs on every update, we've rebuilt the fix on current main in #4793, with your commit credited as co-author and your tests adapted. It also keeps the existing render whenever gbrain's state can't be read at all. The owner thread is GSTA-842; we'll post here when it lands.

capy-ai Bot added a commit that referenced this pull request Nov 24, 2026
… and long test commands fail clearly (#4793)

On Windows, an update no longer deletes your brain-aware skills when
`python3` is the Microsoft Store alias, and a pre-ship test command too
long for Git Bash is split to fit or refused clearly instead of running
cut off.

Why: keeps install and upgrade working on Windows, where gstack promises
minimal support (#4752 by @Barack-zero-to-one, #4773 by @targetpark).

Nothing to do.

Co-authored-by: Barack-zero-to-one <121355791+Barack-zero-to-one@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: bin/gstack-config:1335:completeness reader=core
Review-Finding: lib/pregate/checks/lanes.ts:457:completeness reader=core
Review-Finding: lib/pregate/checks/lanes.ts:442:completeness reader=core
Review-Finding: lib/pregate/checks/lanes.ts:456:completeness reader=core
@capy-ai

capy-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This fix landed in #4793, which rebuilt your change on main with you credited as co-author. Thanks again for the diagnosis and the tests. Closing this PR in favor of #4793.

@capy-ai capy-ai Bot closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S3 Severity 3: everything else

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant