Repository navigation
fix(scripts): rename status var in :agent scripts so they work under zsh - #842
Conversation
The `*:agent` capture scripts used `status=$?`, but `status` is a read-only special variable in zsh (a synonym for $?). Under zsh the assignment fails with "read-only variable: status" and the subsequent `echo $status` / `exit $status` fall back to zsh's builtin $status (the $? of the failed assignment, i.e. 1) — so a passing run records exit code 1 and the wrapper exits 1. A green run looks red. The scripts only worked because pnpm runs package scripts under /bin/sh. They break the moment an agent or human copies the wrapper body into a zsh prompt (as already happened with a hand-written ad-hoc wrapper). Rename `status` to `rc` in every `*:agent` script. Verified under zsh: passing command exits 0 and writes 0 to the .exit file; failing command exits 1 and writes 1. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAll eight ChangesAgent Script Exit Code Variable Rename
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
size-limit report 📦
|
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
|
Superseded by #853, which replaces the inline-shell |
Main moved 2 commits ahead (language-server PSL symbol-table diagnostics #862, a zsh :agent-script fix #842). Neither touches the slice's postgres target/adapter source. Clean auto-merge, no conflicts, no src/ conflicts. Lockfile matches main; pnpm install reconciles. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…te fails loudly The :agent wrappers redirect a slow command to a log file and write the exit code to a sibling .exit marker. When vitest intermittently freezes after printing its summary (an unresolved PGlite/WASM teardown abort on Linux), the inner `pnpm <cmd>` never returns, the .exit marker is never written, and the wrapper blocks forever. Replace the inline-shell wrappers with a portable Node wrapper, scripts/ run-logged.mjs, that runs the command under a hard timeout (default 60 min, override via AGENT_CMD_TIMEOUT_SECONDS). On timeout it kills the child process group, records 124 in the .exit file, and returns — so a hang now fails loudly instead of hanging. `timeout`/`gtimeout` are not portable (absent on macOS), so the bound is enforced in Node. This also removes the `status=$?` shell idiom, which is a read-only variable in zsh and broke the wrappers there (supersedes the standalone rename in #842). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…te fails loudly The :agent wrappers redirect a slow command to a log file and write the exit code to a sibling .exit marker. When vitest intermittently freezes after printing its summary (an unresolved PGlite/WASM teardown abort on Linux), the inner `pnpm <cmd>` never returns, the .exit marker is never written, and the wrapper blocks forever. Replace the inline-shell wrappers with a portable Node wrapper, scripts/ run-logged.mjs, that runs the command under a hard timeout (default 60 min, override via AGENT_CMD_TIMEOUT_SECONDS). On timeout it kills the child process group, records 124 in the .exit file, and returns — so a hang now fails loudly instead of hanging. `timeout`/`gtimeout` are not portable (absent on macOS), so the bound is enforced in Node. This also removes the `status=$?` shell idiom, which is a read-only variable in zsh and broke the wrappers there (supersedes the standalone rename in #842). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…te fails loudly The :agent wrappers redirect a slow command to a log file and write the exit code to a sibling .exit marker. When vitest intermittently freezes after printing its summary (an unresolved PGlite/WASM teardown abort on Linux), the inner `pnpm <cmd>` never returns, the .exit marker is never written, and the wrapper blocks forever. Replace the inline-shell wrappers with a portable Node wrapper, scripts/ run-logged.mjs, that runs the command under a hard timeout (default 60 min, override via AGENT_CMD_TIMEOUT_SECONDS). On timeout it kills the child process group, records 124 in the .exit file, and returns — so a hang now fails loudly instead of hanging. `timeout`/`gtimeout` are not portable (absent on macOS), so the bound is enforced in Node. This also removes the `status=$?` shell idiom, which is a read-only variable in zsh and broke the wrappers there (supersedes the standalone rename in #842). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…te fails loudly (prisma#853) ## Problem The root `:agent` script wrappers (`test:integration:agent`, `test:packages:agent`, …) redirect a slow command to a timestamped log under `wip/` and write its exit code to a sibling `.exit` marker, so an agent can fire-and-check rather than stream output. The inline shell was: ``` ts=…; log=wip/<name>.$ts.log; echo "log: $log"; pnpm <cmd> > "$log" 2>&1; status=$?; echo $status > wip/<name>.$ts.exit; exit $status ``` On an intermittent vitest hang **after** it prints its full passing summary (`Test Files … passed`, `Duration …s`), the inner `pnpm <cmd>` never returns. The `status=$?; echo … > …exit; exit` tail never runs, the `.exit` marker is never written, and the wrapper **blocks forever** until something external kills it. ## Diagnosis I could not reproduce the post-summary hang on macOS in 10 full integration runs — the process always exits after the summary (cleanly, or non-zero on a test failure, in which case the `.exit` is written correctly). The hang is intermittent and matches the documented **Linux-only PGlite (WASM) teardown abort** (`jit_page_->allocations_.erase`) that `test/integration/vitest.config.ts` already tries to mitigate with `--no-memory-protection-keys` and that still "intermittently aborts on Linux" per that config's own comment. It lives in the `@prisma/dev` dependency's WASM teardown, not in this repo's test teardown: I traced every suspected leak (the `pg.Pool`/`pg.Client` in the postgres driver tests and integration runtime helper, every `MongoMemoryReplSet`) and each is closed — `driver.close()` ends the pool/client, and every replset has a matching `stop()`. So there is no missing `afterAll` to fix here. ## Fix Replace the eight inline-shell `:agent` wrappers with one portable Node wrapper, `scripts/run-logged.mjs`, that runs the command under a **hard timeout** (default 60 min, override with `AGENT_CMD_TIMEOUT_SECONDS`). On timeout it kills the child **process group** (so turbo/vitest grandchildren die too), records `124` in the `.exit` file, and returns. A hang now fails loudly with a non-zero `.exit` instead of blocking forever — the reliable backstop the root-cause (a dependency's intermittent WASM teardown) doesn't give us. `timeout`/`gtimeout` are not portable (absent on macOS, where agents run), so the bound is enforced in Node rather than via the `timeout` binary. Bonus: this drops the `status=$?` idiom, which is a **read-only variable in zsh** and broke the wrappers there. That makes it a superset of prisma#842 (the standalone `status`→`rc` rename) — **prisma#842 can be closed in favour of this.** ## Verification - `scripts/run-logged.test.mjs` (wired into `test:scripts`) covers all four exit paths: success → `.exit` 0; failure → `.exit` is the child code; timeout → `.exit` 124 + `TIMEOUT` marker; and idempotency (the SIGKILL-triggered `close` can't overwrite `124`). - End-to-end on the real wrappers: `build:agent` returns rc 0 and writes `.exit` 0; `test:integration:agent` returns rc 1 on a failing run and writes `.exit` 1 (faithful pass-through). Both print the `log:` line and capture full output. ## Out of scope / follow-up The package-level vitest configs (run by `test:packages`) lack the `--no-memory-protection-keys` flag that integration/e2e set, which is the most likely contributor to the Linux `test:packages` hang. Propagating it is a separate, low-risk change tracked as a follow-up; it only *reduces* the abort, so the timeout wrapper here is the actual backstop. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Updated agent command execution to run through a logging wrapper that records stdout/stderr to timestamped logs and prints the log path. * Added hard timeouts for `:agent` runs (default **5 minutes**; configurable); on timeout the process is terminated and the run exits with **124**. * **Documentation** * Refreshed running-tests guidance to clarify timeout and timeout-termination behavior. * **Tests** * Added tests covering successful runs, exit-code propagation, and timeout behavior (including ensuring the `.exit` file isn’t overwritten). <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
The root
package.json*:agentcapture scripts (build:agent,typecheck:agent,test:packages:agent,test:integration:agent,test:e2e:agent,lint:agent,lint:deps:agent,fixtures:check:agent) recorded the exit code with:statusis a read-only special variable in zsh (a synonym for$?). Under zsh the assignment fails withread-only variable: status, and the followingecho $status/exit $statusthen read zshs builtin$status— which is the$?of the failed assignment, i.e.1. So a passing run records exit code1in the.exitfile and the wrapper exits1. A green run looks red.These scripts work today only because pnpm runs package scripts under
/bin/sh(whereZSH_VERSIONis empty). The pattern breaks the moment the wrapper body is copied into a zsh prompt or the Claude Code Bash tool — which is exactly what agents and humans on zsh machines do. A subagent already hit this with a hand-written ad-hoc wrapper.Fix
Rename
status→rcin every*:agentscript. Behavior is otherwise identical.Verification
Wrapper body run directly under
zsh -c:status=)read-only variable: status, exits1, no.exitfilerc=)0,.exit=01,.exit=1Also ran
pnpm lint:deps:agentend-to-end: prints the log path, writes0to the.exitsibling, exits0.No rule/skill/doc shows the raw wrapper body (
running-tests.mdconly documents the:agentscripts and the.exitfile), so this change is confined topackage.json.🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes