Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions bin/gstack-config
Original file line number Diff line number Diff line change
Expand Up @@ -1225,25 +1225,33 @@ $_gstack_legacy_root"
echo "gstack-gbrain-detect not found at $DETECT_BIN" >&2
exit 1
fi
_GBRAIN_PROBE=absent
if ! "$DETECT_BIN" > "$DETECTION_FILE.tmp.$$" 2>/dev/null; then
printf '{"gbrain_on_path":false,"gbrain_local_status":"no-cli"}\n' > "$DETECTION_FILE.tmp.$$"
_GBRAIN_PROBE=unknown
fi
mv "$DETECTION_FILE.tmp.$$" "$DETECTION_FILE"

# Summarize for the user. Use python (already required elsewhere) to
# parse the JSON portably; fall back to grep if python is unavailable.
# Summarize for the user with the first Python that runs, else grep. A
# python3 on PATH may not run: on Windows it is often the Microsoft Store
# alias, which exits 49 (#4752), so it counts as absent.
# The file goes in on stdin (E6, #1967): bash opens the path, so a native
# Windows Python under Git Bash never has to resolve an MSYS /c/... path.
PYTHON_CMD=$(command -v python3 || command -v python || true)
if [ -n "$PYTHON_CMD" ]; then
STATUS=$("$PYTHON_CMD" -c "import json,sys; d=json.load(sys.stdin); print(d.get('gbrain_local_status','unknown'))" < "$DETECTION_FILE" 2>/dev/null || echo unknown)
VERSION=$("$PYTHON_CMD" -c "import json,sys; d=json.load(sys.stdin); print(d.get('gbrain_version') or 'unknown')" < "$DETECTION_FILE" 2>/dev/null || echo unknown)
else
STATUS=$(grep -o '"gbrain_local_status":[[:space:]]*"[^"]*"' "$DETECTION_FILE" | sed 's/.*"\([^"]*\)"$/\1/')
VERSION=$(grep -o '"gbrain_version":[[:space:]]*"[^"]*"' "$DETECTION_FILE" | sed 's/.*"\([^"]*\)"$/\1/')
[ -z "$STATUS" ] && STATUS=unknown
[ -z "$VERSION" ] && VERSION=unknown
STATUS=""; VERSION=""
for _py in python3 python; do
command -v "$_py" >/dev/null 2>&1 || continue
STATUS=$("$_py" -c "import json,sys; d=json.load(sys.stdin); print(d.get('gbrain_local_status','unknown'))" < "$DETECTION_FILE" 2>/dev/null) \
&& VERSION=$("$_py" -c "import json,sys; d=json.load(sys.stdin); print(d.get('gbrain_version') or 'unknown')" < "$DETECTION_FILE" 2>/dev/null) \
&& break
STATUS=""; VERSION=""
done
if [ -z "$STATUS" ]; then
STATUS=$(grep -o '"gbrain_local_status":[[:space:]]*"[^"]*"' "$DETECTION_FILE" | sed 's/.*"\([^"]*\)"$/\1/' || true)
VERSION=$(grep -o '"gbrain_version":[[:space:]]*"[^"]*"' "$DETECTION_FILE" | sed 's/.*"\([^"]*\)"$/\1/' || true)
fi
[ -n "$STATUS" ] || STATUS=unknown
[ -n "$VERSION" ] || VERSION=unknown
[ "$STATUS" != unknown ] || _GBRAIN_PROBE=unknown

case "$STATUS" in
ok|timeout|db-unreachable|thin-client|engine-locked)
Expand Down Expand Up @@ -1308,8 +1316,12 @@ $_gstack_legacy_root"
fi
;;
*)
echo "gbrain not detected (local-status: $STATUS) → brain-aware blocks will be suppressed in planning-skill SKILL.md files."
echo "Install gbrain (see /setup-gbrain) and re-run 'gstack-config gbrain-refresh' once it's configured."
if [ "$_GBRAIN_PROBE" = unknown ]; then
echo "Could not read gbrain's state (local-status: $STATUS); an existing Claude render is left in place. Re-run 'gstack-config gbrain-refresh' to retry."
else
echo "gbrain not detected (local-status: $STATUS) → brain-aware blocks will be suppressed in planning-skill SKILL.md files."
echo "Install gbrain (see /setup-gbrain) and re-run 'gstack-config gbrain-refresh' once it's configured."
fi
# Drop a brain-aware render, or re-render a pinned overlay without
# brain blocks, so removing gbrain keeps the chosen overlay.
INSTALL_DIR="$HOME/.claude/skills/gstack"
Expand All @@ -1320,19 +1332,25 @@ $_gstack_legacy_root"
echo "Skip: bun not on PATH — the Claude render at $RENDER_DIR was not refreshed. Install bun, then re-run 'gstack-config gbrain-refresh'."
else
gstack_claude_overlay "$INSTALL_DIR" "$0"
gstack_claude_render_action "$RENDER_DIR" absent
if [ "$_GSTACK_RENDER_ACTION" = plain ]; then
if [ "$_GBRAIN_PROBE" = unknown ] && [ -d "$RENDER_DIR" ]; then
_GSTACK_RENDER_ACTION=keep
else
gstack_claude_render_action "$RENDER_DIR" "$_GBRAIN_PROBE"
fi
if [ "$_GSTACK_RENDER_ACTION" = keep ]; then
:
elif [ "$_GSTACK_RENDER_ACTION" = plain ]; then
if gstack_claude_render_plain "$INSTALL_DIR" "$RENDER_DIR"; then
gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" absent rendered
gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" "$_GBRAIN_PROBE" rendered
else
gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" absent failed
gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" "$_GBRAIN_PROBE" failed
fi
else
if [ -d "$RENDER_DIR" ]; then
rm -rf "$RENDER_DIR"
echo "Removed the brain-aware render at $RENDER_DIR; Claude skills serve the committed files."
fi
gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" absent removed
gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" "$_GBRAIN_PROBE" removed
fi
"$INSTALL_DIR/bin/gstack-relink" >/dev/null 2>&1 || true
fi
Expand Down
4 changes: 4 additions & 0 deletions changelog.d/windows-python3-stub-and-long-test-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
important: data-loss
---
**On Windows, an update no longer deletes your brain-aware skills when `python3` is the Microsoft Store alias.** That alias stays on PATH next to a real Python and exits 49 without running anything, so `gstack-config gbrain-refresh`, which runs after every team-mode update, read a healthy gbrain as "not detected" and removed the brain-aware render. A Python that does not run now counts as absent (the next Python, then a plain-text read, is used instead), and when gbrain's state cannot be read at all the existing render is left in place. Thanks to @Barack-zero-to-one for the diagnosis and tests (#4752). A pre-ship test command longer than the 8,186 characters Git Bash keeps is now split to fit, or refused with a clear "argument list too long" message, instead of starting cut off and failing with an empty log (#4773).
3 changes: 2 additions & 1 deletion docs/pregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ Two stages with separate clocks, both printed:
`**/*.serial.test.*`) run one process per file after the unit files. A unit
group whose quoted file list would pass the system's argument limits (Linux
caps one argument at 128 KiB) runs as several runner processes in sequence,
each under about 96 KB of file arguments (24 KB on Windows), read back as one run: counts add up,
each under about 96 KB of file arguments (on Windows, under the 8,186 characters
Git Bash keeps of one argument, #4773), read back as one run: counts add up,
any failing chunk fails the lane, and they share the group's one `--timeout`. The
runner and every guard run with the verified launch Bun first on PATH: the
first of `$BUN_INSTALL/bin` and `~/.bun/bin` whose Bun satisfies gstack's and
Expand Down
7 changes: 5 additions & 2 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -4894,11 +4894,14 @@ line really pins the old value, so update the golden.
the system's limit, so it never ran and no test was counted. Linux caps one
argument at 128 KiB and a whole command line plus environment at about 2 MiB,
macOS caps the total at 1 MiB, and Windows caps a command line at 32,767
characters. The usual trigger is a long file list: thousands of selected test
characters. Git Bash on Windows keeps only the first 8,186 characters of a
`bash -c` command, so gstack refuses a longer one with `argument list too long
for Git Bash` instead of running it cut off (#4773). The usual trigger is a long file list: thousands of selected test
files put into one argument.

**Fix.** gstack keeps file lists out of single arguments: a local lane splits
its files into runner processes of about 96 KB each (24 KB on Windows), and
its files into runner processes of about 96 KB each (under 8,186 characters on
Windows), and
the `test_backend` command for the remote gate passes them in a setup script
(docs/pregate.md#remote-gate). So this cause is a gstack bug: report it with
the `environment:` line and the lane or command it names. Until it is fixed,
Expand Down
18 changes: 9 additions & 9 deletions lib/pregate/checks/lanes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ import { docsOnlyLane } from '../docs-only-lane';
import { selectLanes, type Selection } from '../lane-selection';
import { launchRuntime } from '../runtime';
import { cargoModel, type CargoModel } from '../rust';
import { adapterFor, readRange, STALL_IDLE, supervise, type Counter, type Supervised } from '../supervise';
import { adapterFor, PIPEFAIL, readRange, STALL_IDLE, supervise, type Counter, type Supervised } from '../supervise';
import { ranFiles, runChanged, runReceiptFields, verifyFromRun, type RunProfile } from '../../run-evidence';
import { WINDOWS_BASH_ARG_MAX } from '../../script-invocation';
import { matchesAny } from '../../ship-policy';
import { testFileArgs } from '../../test-paths';
import type { CheckDef, CheckResult, PregateContext, RemoteObligation } from '../types';
Expand Down Expand Up @@ -406,15 +407,14 @@ interface LocalRun { exit: number | null; outcome: Supervised['outcome']; signal
const quote = (f: string) => `'${f.replace(/'/g, `'\\''`)}'`;

/**
* Bytes of quoted file arguments one runner process may take. supervise passes the whole command as one `bash -c`
* argument: Linux caps a single execve argument at 128 KiB (MAX_ARG_STRLEN), every POSIX system caps argv plus the
* environment (ARG_MAX: 1 MiB on macOS, 2 MiB by default on Linux), and Windows caps a whole command line at 32,767
* characters. The runner text itself and a margin come off the top.
* Bytes of quoted file arguments one runner process may take (unlimited without a {files} placeholder: `cargo test -p`).
* supervise passes PIPEFAIL plus the command as one `bash -c` argument: Linux caps one execve argument at 128 KiB, POSIX
* caps argv plus environment (ARG_MAX), and Git Bash on Windows keeps its first 8,186 characters only (#4773).
*/
export function argBudget(runner: string, env: NodeJS.ProcessEnv, platform = process.platform): number {
const envBytes = Object.entries(env).reduce((n, [k, v]) => n + Buffer.byteLength(`${k}=${v ?? ''}`) + 9, 0);
const cap = platform === 'win32' ? 24 * 1024 : Math.min(96 * 1024, 1024 * 1024 - 64 * 1024 - envBytes);
return cap - Buffer.byteLength(runner) - 512;
const cap = platform === 'win32' ? WINDOWS_BASH_ARG_MAX : Math.min(96 * 1024, 1024 * 1024 - 64 * 1024 - envBytes);
return runner.includes('{files}') ? cap - Buffer.byteLength(PIPEFAIL) - Buffer.byteLength(runner) - 512 : Infinity;
}

/** `args` split in order into chunks whose quoted, space-joined text fits `budget` bytes; an argument over it runs alone. */
Expand Down Expand Up @@ -452,8 +452,8 @@ async function runOnce(ctx: PregateContext, env: NodeJS.ProcessEnv, g: RunGroup,
if (r.exit === null) break;
}
if (parts.length === 1) return parts[0]!;
const bad = parts.find(p => p.exit === null) ?? parts.find(p => p.exit !== 0) ?? parts.at(-1)!;
const sum = (k: 'ran' | 'failed') => (parts.some(p => p[k] === null) ? null : parts.reduce((n, p) => n + (p[k] as number), 0));
const bad = parts.find(p => p.exit === null) ?? parts.find(p => p.exit !== 0) ?? parts.find(p => p.ran === 0) ?? parts.at(-1)!;
const sum = (k: 'ran' | 'failed') => (k === 'ran' && parts.some(p => p.ran === 0) ? 0 : parts.some(p => p[k] === null) ? null : parts.reduce((n, p) => n + (p[k] as number), 0));
return { ...(parts.every(p => p.noBrowsers) ? { noBrowsers: parts[0]!.noBrowsers } : {}), exit: bad.exit, outcome: bad.outcome, signal: bad.signal, observedStart: parts.some(p => p.observedStart), ran: sum('ran'), failed: sum('failed'), tail: bad.tail, runner: g.runner, command: parts.map(p => p.command).join(' && '), files: parts.flatMap(p => p.files), lastFile: bad.lastFile, ms: parts.reduce((n, p) => n + p.ms, 0), ...(bad.error ? { error: bad.error } : {}) };
}

Expand Down
4 changes: 3 additions & 1 deletion lib/pregate/supervise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { BUN_TEST } from '../test-paths';

export type ProgressAdapter = 'bun';
export const PROGRESS_ADAPTERS: Record<ProgressAdapter, RegExp> = { bun: BUN_TEST };
/** Prefixed to every supervised command, so it counts against the argument limits too. */
export const PIPEFAIL = 'set -o pipefail; ';

export interface Counter { done: number; total: number }

Expand Down Expand Up @@ -216,7 +218,7 @@ export function supervise(o: SuperviseOptions): Promise<Supervised> {
let fd: number;
try { fd = fs.openSync(o.log, 'a'); }
catch (e: any) { resolve({ outcome: 'spawn-failed', exit: null, signal: null, start, end: start, lastFile: null, observedStart: false, error: e.message, ms: 0 }); return; }
const inv = bashCommandInvocation(`set -o pipefail; ${o.command}`);
const inv = bashCommandInvocation(`${PIPEFAIL}${o.command}`);
if (!inv.ok) {
fs.closeSync(fd);
resolve({ outcome: 'spawn-failed', exit: null, signal: null, start, end: start, lastFile: null, observedStart: false, error: inv.error, ms: Date.now() - started });
Expand Down
11 changes: 10 additions & 1 deletion lib/script-invocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,18 @@ export function scriptInvocation(script: string, args: readonly string[], o: Inv
return bash.ok ? { ok: true, cmd: bash.bash, argv: [slash(script), ...args] } : bash;
}

/** How to run `bash -c <command>` on this platform. */
/**
* Characters of one argument that Git Bash keeps when a Windows program starts it: the Cygwin/MSYS runtime silently drops
* the rest of an argument with spaces (#4773; reported on Git for Windows 2.53, bash 5.2.37).
*/
export const WINDOWS_BASH_ARG_MAX = 8186;

/** How to run `bash -c <command>` on this platform. On Windows a command Git Bash would cut off is refused, never run. */
export function bashCommandInvocation(command: string, o: InvocationOptions = {}): Invocation {
if ((o.platform ?? process.platform) !== 'win32') return { ok: true, cmd: 'bash', argv: ['-c', command] };
if (command.length > WINDOWS_BASH_ARG_MAX) {
return { ok: false, error: `argument list too long for Git Bash: the bash -c command is ${command.length.toLocaleString('en-US')} characters and Git Bash on Windows keeps only the first ${WINDOWS_BASH_ARG_MAX.toLocaleString('en-US')}, so it was not started rather than run cut off (#4773)` };
}
const bash = windowsBash(o);
return bash.ok ? { ok: true, cmd: bash.bash, argv: ['-c', command] } : bash;
}
Expand Down
Loading
Loading