From dc5b070709b67697808a9e20dc96c16fd6606473 Mon Sep 17 00:00:00 2001 From: scotttong Date: Fri, 21 Aug 2026 17:26:51 -0700 Subject: [PATCH] fix(runtime): guard empty Bash 3.2 array expansion (#11891) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Agents can run in isolated worktrees with a separate Paperclip runtime. > - Runtime provisioning uses a Bash script on macOS hosts. > - macOS ships Bash 3.2, where an empty array expansion fails under `set -u`. > - The source-config argument array is empty when the base workspace already has a config. > - This pull request guards that expansion and tests the normal base-config path on Bash 3.2. > - The benefit is that managed worktree provisioning no longer fails before database seeding. ## Linked Issues or Issue Description No public GitHub issue exists for this problem. PR #11752 added the conditional source-config argument that exposed the failure. **What happened?** `scripts/provision-worktree-runtime.sh` expands an empty `source_config_args` array while `set -u` is active. Bash 3.2 reports `source_config_args[@]: unbound variable` and stops provisioning when the registered base workspace already has `.paperclip/config.json`. **Expected behavior** Runtime provisioning must call `worktree ensure-seeded` without a source override when the base workspace config exists. It must work with the Bash 3.2 version that macOS supplies. **Steps to reproduce** 1. Use macOS system Bash 3.2. 2. Create a base workspace with `.paperclip/config.json`. 3. Run `scripts/provision-worktree-runtime.sh` with `set -u` active in the script. 4. Observe the unbound-variable error before `worktree ensure-seeded` runs. **Paperclip version or commit** Reproduced on `origin/master` before this change. **Deployment mode** Local managed worktree runtime on macOS. ## What Changed - Guard all three optional source-config array expansions with Bash 3.2-compatible parameter expansion. - Add a regression test that uses the base-config path and verifies that no `--from-config` argument is sent. - Document the Bash 3.2 compatibility requirement in the runtime script. ## Verification - `/bin/bash -n scripts/provision-worktree-runtime.sh` - `node --test --test-name-pattern='runtime provisioning invokes ensure-seeded once|runtime provisioning omits the source override|runtime provisioning guards every optional source-config expansion' scripts/__tests__/provision-worktree-self-heal.test.mjs` - `git diff --check` ## Risks Low risk. The change only affects expansion of an optional two-element CLI argument array. The regression tests cover both the empty and non-empty paths. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used OpenAI Codex with model ID `gpt-5`. The runtime did not expose the context-window size. Reasoning, tool use, and code execution were enabled. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip --- .../provision-worktree-self-heal.test.mjs | 33 +++++++++++++++++++ scripts/provision-worktree-runtime.sh | 7 ++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/scripts/__tests__/provision-worktree-self-heal.test.mjs b/scripts/__tests__/provision-worktree-self-heal.test.mjs index 34d64167fb..bbe44698d1 100644 --- a/scripts/__tests__/provision-worktree-self-heal.test.mjs +++ b/scripts/__tests__/provision-worktree-self-heal.test.mjs @@ -381,6 +381,39 @@ test("runtime provisioning invokes ensure-seeded once and fast-exits after succe assert.equal(ensureCallsAfterSecond.length, 1); }); +test("runtime provisioning omits the source override when the base config exists", () => { + const baseCwd = makeBaseWorkspace({ helpExit: 0, initExit: 0 }); + fs.mkdirSync(path.join(baseCwd, ".paperclip"), { recursive: true }); + fs.writeFileSync(path.join(baseCwd, ".paperclip", "config.json"), "{}\n"); + const worktreeCwd = makeTempDir("paperclip-provision-runtime-base-config-"); + fs.mkdirSync(path.join(worktreeCwd, ".paperclip"), { recursive: true }); + fs.writeFileSync(path.join(worktreeCwd, ".paperclip", "config.json"), "{}\n"); + + const result = runRuntimeProvision(baseCwd, worktreeCwd); + + assert.equal(result.status, 0, result.stderr); + const ensureCall = readCliInvocations(baseCwd).find( + (args) => args[0] === "worktree" && args[1] === "ensure-seeded", + ); + assert.ok(ensureCall, "expected the runtime provisioner to invoke ensure-seeded"); + assert.ok(!ensureCall.includes("--from-config")); +}); + +test("runtime provisioning guards every optional source-config expansion for Bash 3.2", () => { + const source = fs.readFileSync(runtimeScript, "utf8"); + const ensureSeededLines = source + .split("\n") + .filter((line) => line.includes("worktree ensure-seeded --config")); + + assert.equal(ensureSeededLines.length, 3); + for (const line of ensureSeededLines) { + assert.ok( + line.includes('${source_config_args[@]+"${source_config_args[@]}"}'), + `expected Bash 3.2-compatible optional array expansion in: ${line}`, + ); + } +}); + test("runtime provisioning seeds a worktree config that has no seed markers", () => { const baseCwd = makeBaseWorkspace({ helpExit: 0, initExit: 0 }); const worktreeCwd = makeTempDir("paperclip-provision-runtime-unmarked-config-"); diff --git a/scripts/provision-worktree-runtime.sh b/scripts/provision-worktree-runtime.sh index 99a56fe1e4..a6d925918a 100755 --- a/scripts/provision-worktree-runtime.sh +++ b/scripts/provision-worktree-runtime.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# Keep this script compatible with macOS's system Bash 3.2. set -euo pipefail base_cwd="${PAPERCLIP_WORKSPACE_BASE_CWD:?PAPERCLIP_WORKSPACE_BASE_CWD is required}" @@ -139,7 +140,7 @@ run_ensure_seeded() { if ensure_base_cli_healthy; then ( cd "$worktree_cwd" && - node "$base_cli_runner_path" "$base_cli_entry_path" worktree ensure-seeded --config "$worktree_config_path" "${source_config_args[@]}" + node "$base_cli_runner_path" "$base_cli_entry_path" worktree ensure-seeded --config "$worktree_config_path" ${source_config_args[@]+"${source_config_args[@]}"} ) return fi @@ -147,7 +148,7 @@ run_ensure_seeded() { if command -v pnpm >/dev/null 2>&1 && pnpm paperclipai --help >/dev/null 2>&1; then ( cd "$worktree_cwd" && - pnpm paperclipai worktree ensure-seeded --config "$worktree_config_path" "${source_config_args[@]}" + pnpm paperclipai worktree ensure-seeded --config "$worktree_config_path" ${source_config_args[@]+"${source_config_args[@]}"} ) return fi @@ -155,7 +156,7 @@ run_ensure_seeded() { if command -v paperclipai >/dev/null 2>&1; then ( cd "$worktree_cwd" && - paperclipai worktree ensure-seeded --config "$worktree_config_path" "${source_config_args[@]}" + paperclipai worktree ensure-seeded --config "$worktree_config_path" ${source_config_args[@]+"${source_config_args[@]}"} ) return fi