Repository navigation
fix(e2e): make nightly teardown reliable and prevent sandbox leaks - #2313
Conversation
Root cause of the recent `network-policy-e2e` flake: a prior run left `e2e-net-policy` in a not-ready state on the shared Brev launchable, and onboard refused to overwrite because neither the workflow nor the test script set `NEMOCLAW_RECREATE_SANDBOX=1`. The preflight cleanup at `test-network-policy.sh:217` was guarded by `nemoclaw list | grep`, which does not surface not-ready sandboxes, so the destroy never fired. More broadly, 15 of 27 e2e test scripts had no `trap teardown EXIT`, so a mid-run failure left the sandbox alive on the launchable until the next run's `NEMOCLAW_RECREATE_SANDBOX=1` clobbered it (if set). On the shared launchable this accumulates as dangling k8s pods, netns, volumes and eventually pushes later runs into the not-ready state this PR is closing. Changes: - `.github/workflows/nightly-e2e.yaml`: add `NEMOCLAW_RECREATE_SANDBOX: "1"` to the three jobs still missing it: `network-policy-e2e`, `inference-routing-e2e`, `deployment-services-e2e`. - `test/e2e/test-network-policy.sh`, `test/e2e/test-inference-routing.sh`: replace the `list | grep`-gated preflight destroy with an unconditional `nemoclaw "$SANDBOX_NAME" destroy --yes 2>/dev/null || true`. Catches not-ready sandboxes the grep misses. Post-failure assertions (e.g. TC-INF-06/07 checking that no sandbox was created after a bad key) kept unchanged — those are checks, not cleanup. - `test/e2e/lib/sandbox-teardown.sh`: new shared helper. Registers each sandbox name and installs a single `trap ... EXIT` that destroys every registered sandbox and clears the onboard.lock. Keeps the per-script diff to two lines so reviewers can audit the full wiring quickly. - 15 test scripts sourced the helper and called `register_sandbox_for_teardown "$SANDBOX_NAME"` right after the name is defined: credential-sanitization, full-e2e, hermes-e2e, messaging- providers, onboard-repair (two sandboxes), onboard-resume, rebuild- hermes, rebuild-openclaw, sandbox-rebuild, sandbox-survival, shields- config, skip-permissions-policy, snapshot-commands, telegram-injection, upgrade-stale-sandbox. - `test-runtime-overrides.sh` (pure `docker run --rm`) and `test-spark-install.sh` (install smoke, no sandbox) intentionally left alone — they create no sandbox to tear down. - 10 scripts that already set a `trap teardown EXIT` themselves were not changed, because sourcing the helper would silently replace their existing trap. Covered: deployment-services, diagnostics, double- onboard, gpu-e2e, inference-routing, network-policy, ollama-auth-proxy, sandbox-operations, token-rotation, e2e-cloud-experimental. Out of scope (filed for a follow-up): workflow-level `if: always()` post-job cleanup (belt-and-suspenders against script crashes that never reach the trap), and a pre-run `e2e-*` sweeper at the launchable level. Signed-off-by: Prekshi Vyas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a shared E2E sandbox teardown helper and wires it into many test scripts to register sandboxes for exit-time destruction, changes some preflight steps to unconditionally destroy sandboxes, and sets Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Script
participant Helper as Sandbox Teardown Helper
participant CLI as nemoclaw CLI
rect rgba(200,220,255,0.5)
Test->>Helper: source lib/sandbox-teardown.sh
Test->>Helper: register_sandbox_for_teardown(SANDBOX_NAME)
end
rect rgba(200,255,200,0.5)
Note over Helper,Test: On process EXIT
Helper->>CLI: nemoclaw SANDBOX_NAME destroy --yes (stderr suppressed)
CLI-->>Helper: exit status (ignored)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
test/e2e/lib/sandbox-teardown.sh (1)
39-39: Prefer trap chaining to avoid potential clobbering in sourced context.Line 39 unconditionally sets
trap ... EXIT. While no current caller defines conflicting EXIT traps, the sourced pattern could be fragile. Consider using trap chaining (e.g., saving the existing trap and calling it within_nemoclaw_sandbox_teardown) or guarded installation to handle cases where a caller may define their own EXIT trap.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/e2e/lib/sandbox-teardown.sh` at line 39, The EXIT trap currently unconditionally overwrites any existing trap by calling trap _nemoclaw_sandbox_teardown EXIT; instead, preserve and chain the prior EXIT trap: capture the current EXIT trap command (e.g., via existing_trap="$(trap -p EXIT)") before installing the new trap, and modify _nemoclaw_sandbox_teardown to invoke the preserved command (if any) after running its teardown steps; install the trap so it calls both _nemoclaw_sandbox_teardown and the saved handler (or guard against re-installing if already set) to avoid clobbering sourced contexts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/e2e/lib/sandbox-teardown.sh`:
- Around line 1-7: This file is missing the required shebang; add the line
"#!/usr/bin/env bash" as the very first line (above the SPDX headers) in
test/e2e/lib/sandbox-teardown.sh, then reformat with shfmt, run ShellCheck to
fix any issues, and ensure the file has the executable bit set so it satisfies
the repo shell-file requirements for shell scripts.
In `@test/e2e/test-onboard-repair.sh`:
- Around line 66-70: The EXIT trap in lib/sandbox-teardown.sh can call a bare
"nemoclaw" which will no-op if there's no global binary; ensure the teardown
uses the same invoker as tests by exporting or setting a NE MOCLAW_CMD (or
similar) to node "$REPO/bin/nemoclaw.js" and have register_sandbox_for_teardown
/ the trap call that variable (or call run_nemoclaw) instead of a plain
"nemoclaw"; update the test bootstrap (where register_sandbox_for_teardown is
called) to set and export the command (or source the run_nemoclaw wrapper) so
sandbox-teardown.sh always uses the correct node "$REPO/bin/nemoclaw.js"
invocation for cleanup.
---
Nitpick comments:
In `@test/e2e/lib/sandbox-teardown.sh`:
- Line 39: The EXIT trap currently unconditionally overwrites any existing trap
by calling trap _nemoclaw_sandbox_teardown EXIT; instead, preserve and chain the
prior EXIT trap: capture the current EXIT trap command (e.g., via
existing_trap="$(trap -p EXIT)") before installing the new trap, and modify
_nemoclaw_sandbox_teardown to invoke the preserved command (if any) after
running its teardown steps; install the trap so it calls both
_nemoclaw_sandbox_teardown and the saved handler (or guard against re-installing
if already set) to avoid clobbering sourced contexts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 48ebf79e-3847-4539-a80b-ffa987364219
📒 Files selected for processing (19)
.github/workflows/nightly-e2e.yamltest/e2e/lib/sandbox-teardown.shtest/e2e/test-credential-sanitization.shtest/e2e/test-full-e2e.shtest/e2e/test-hermes-e2e.shtest/e2e/test-inference-routing.shtest/e2e/test-messaging-providers.shtest/e2e/test-network-policy.shtest/e2e/test-onboard-repair.shtest/e2e/test-onboard-resume.shtest/e2e/test-rebuild-hermes.shtest/e2e/test-rebuild-openclaw.shtest/e2e/test-sandbox-rebuild.shtest/e2e/test-sandbox-survival.shtest/e2e/test-shields-config.shtest/e2e/test-skip-permissions-policy.shtest/e2e/test-snapshot-commands.shtest/e2e/test-telegram-injection.shtest/e2e/test-upgrade-stale-sandbox.sh
`nightly-e2e.yaml:232-233` sets `DISCORD_BOT_TOKEN_A`/`_B` to the fake values `test-fake-discord-A-rotation-e2e` and `test-fake-discord-B- rotation-e2e` as part of the token-rotation E2E (added in #2257). The `discord-client-secret` gitleaks rule false-positives on these strings because the entropy and shape match the pattern. These values are not secrets and never leave CI. Unblocks pre-commit for any branch that rebases on current main. Signed-off-by: Prekshi Vyas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Local-dev scenario: a developer runs a single e2e script to reproduce a flake, wants to inspect the sandbox (logs, filesystem, config) after the test passes or fails. The new trap-based teardown destroys the sandbox on every EXIT, including success, which removes that inspection target. With NEMOCLAW_E2E_KEEP_SANDBOX=1 set, _nemoclaw_sandbox_teardown returns early and leaves everything — sandbox and onboard.lock — in place. CI never sets this variable, so nightly behavior is unchanged. Signed-off-by: Prekshi Vyas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1. `test/e2e/lib/sandbox-teardown.sh`: add `#!/usr/bin/env bash` shebang (above SPDX headers) and the executable bit to satisfy the repo's shell-file convention. The file is still meant to be sourced, not executed — shebang is for convention + shellcheck inference, not runtime. 2. `test/e2e/test-onboard-repair.sh`, `test/e2e/test-onboard-resume.sh`: these scripts drive the CLI via `run_nemoclaw()` which calls `node "$REPO/bin/nemoclaw.js"` and do not assume a globally-installed `nemoclaw` binary is on PATH. The teardown helper's EXIT trap calls `nemoclaw "$sbx" destroy --yes`, which would silently no-op in a repo-local dev environment with no global CLI. Add a conditional shim function before sourcing the helper so the trap routes through `node bin/nemoclaw.js` when no global is available. CI (where `install-openshell.sh` + `npm link` put `nemoclaw` on PATH) sees the shim skipped. Signed-off-by: Prekshi Vyas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
@coderabbitai full review Previous review comments have been addressed in commit 0e82e71:
|
|
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/e2e/test-snapshot-commands.sh (1)
31-31: HonorNEMOCLAW_E2E_KEEP_SANDBOX=1in explicit cleanup too.Registration is good, but Line 217 still destroys the sandbox unconditionally. That bypasses the KEEP_SANDBOX escape hatch on successful runs.
♻️ Suggested patch
info "Cleaning up..." -nemoclaw "${SANDBOX_NAME}" destroy --yes 2>/dev/null || true +if [[ "${NEMOCLAW_E2E_KEEP_SANDBOX:-}" != "1" ]]; then + nemoclaw "${SANDBOX_NAME}" destroy --yes 2>/dev/null || true +else + info "Skipping sandbox destroy (NEMOCLAW_E2E_KEEP_SANDBOX=1)" +fiAlso applies to: 215-218
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/e2e/test-snapshot-commands.sh` at line 31, The explicit sandbox teardown currently always destroys the sandbox even when NEMOCLAW_E2E_KEEP_SANDBOX=1; update the explicit cleanup code that calls the sandbox-destroying logic (the place that invokes register_sandbox_for_teardown and the subsequent unconditional destroy call) to first check the NEMOCLAW_E2E_KEEP_SANDBOX environment variable and skip the destroy when it is set (e.g., if [ -n "$NEMOCLAW_E2E_KEEP_SANDBOX" ] || [ "$NEMOCLAW_E2E_KEEP_SANDBOX" = "1" ]; then echo "Keeping sandbox"; else destroy_sandbox_or_call_existing_teardown; fi), and apply the same conditional guard to the other explicit cleanup site mentioned so both spots honor the escape hatch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/e2e/lib/sandbox-teardown.sh`:
- Around line 31-38: The teardown script currently unconditionally removes the
global onboard lock (~/.nemoclaw/onboard.lock); instead, before calling rm -f,
check ownership and only remove the lock if it is owned by the current
process/user (e.g. use test -O "$HOME/.nemoclaw/onboard.lock" or compare $(stat
-c %u ...) to $UID), so update the block around the rm invocation in
sandbox-teardown.sh (the branch governed by NEMOCLAW_E2E_KEEP_SANDBOX) to
perform that ownership check and only unlink the file when ownership matches.
---
Nitpick comments:
In `@test/e2e/test-snapshot-commands.sh`:
- Line 31: The explicit sandbox teardown currently always destroys the sandbox
even when NEMOCLAW_E2E_KEEP_SANDBOX=1; update the explicit cleanup code that
calls the sandbox-destroying logic (the place that invokes
register_sandbox_for_teardown and the subsequent unconditional destroy call) to
first check the NEMOCLAW_E2E_KEEP_SANDBOX environment variable and skip the
destroy when it is set (e.g., if [ -n "$NEMOCLAW_E2E_KEEP_SANDBOX" ] || [
"$NEMOCLAW_E2E_KEEP_SANDBOX" = "1" ]; then echo "Keeping sandbox"; else
destroy_sandbox_or_call_existing_teardown; fi), and apply the same conditional
guard to the other explicit cleanup site mentioned so both spots honor the
escape hatch.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: be3627e5-064a-4ea5-ad10-35b2e261a423
📒 Files selected for processing (20)
.github/workflows/nightly-e2e.yaml.gitleaksignoretest/e2e/lib/sandbox-teardown.shtest/e2e/test-credential-sanitization.shtest/e2e/test-full-e2e.shtest/e2e/test-hermes-e2e.shtest/e2e/test-inference-routing.shtest/e2e/test-messaging-providers.shtest/e2e/test-network-policy.shtest/e2e/test-onboard-repair.shtest/e2e/test-onboard-resume.shtest/e2e/test-rebuild-hermes.shtest/e2e/test-rebuild-openclaw.shtest/e2e/test-sandbox-rebuild.shtest/e2e/test-sandbox-survival.shtest/e2e/test-shields-config.shtest/e2e/test-skip-permissions-policy.shtest/e2e/test-snapshot-commands.shtest/e2e/test-telegram-injection.shtest/e2e/test-upgrade-stale-sandbox.sh
CodeRabbit correctly flagged that the teardown helper's `rm -f ~/.nemoclaw/onboard.lock` is unsafe on shared machines: that lock is global and PID-ownership-aware in `src/lib/onboard-session.ts` (acquireOnboardLock / releaseOnboardLock verify the holder's PID and the file's inode before touching it). A concurrent e2e run on the same host could have a live lock; our unconditional rm would yank it out from under them. Drop the rm line from the helper. A crashed process leaves a stale lock; the next onboard detects it via isProcessAlive + inode check in acquireOnboardLock and cleans it up automatically. No change in observed behavior for the crashed-run-then-retry case the rm was meant to cover. Nightly CI runs on isolated ubuntu-latest runners per job, so concurrent locks don't happen there — but the shared Brev launchable and any local-dev machine with two e2e scripts running in parallel both benefit. Does NOT touch the ten existing scripts that do the same rm -f in their own teardowns (test-network-policy.sh, test-deployment-services.sh, test-inference-routing.sh, test-diagnostics.sh, test-sandbox-operations.sh, test-token-rotation.sh, test-ollama-auth-proxy-e2e.sh, test-double-onboard.sh, test-gpu-e2e.sh, test-e2e-cloud-experimental.sh) — that's a pre-existing pattern worth a separate audit. Signed-off-by: Prekshi Vyas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…anup CodeRabbit nitpick on #2313: the escape hatch I added only gated the trap-based teardown in sandbox-teardown.sh. Each individual test script also calls `nemoclaw "$SANDBOX_NAME" destroy --yes` in its own end-of-main cleanup section, which bypassed the env var — so a successful run still destroyed the sandbox despite `KEEP_SANDBOX=1`. Guard each affected end-of-main destroy with: [[ "${NEMOCLAW_E2E_KEEP_SANDBOX:-}" = "1" ]] || nemoclaw … destroy … `|` binds tighter than `||`, so the pipe variants parse correctly: `[[ X ]] || (nemoclaw … | tail -3) || true`. Guarded sites (12 scripts): - test-full-e2e.sh, test-hermes-e2e.sh, test-messaging-providers.sh, test-rebuild-hermes.sh, test-rebuild-openclaw.sh, test-sandbox-rebuild.sh, test-sandbox-survival.sh (two sites: jump-to- cleanup early exit + final cleanup), test-shields-config.sh, test-skip-permissions-policy.sh, test-snapshot-commands.sh - test-onboard-repair.sh (two sandboxes wrapped in one if-block), test-onboard-resume.sh Intentionally **not** guarded: - Preflight destroys at script start — those should always run so the onboard gets a clean slate. - Mid-test destroys that are part of the test logic (e.g. test-sandbox-survival.sh's backup-workspace cycle destroys the sandbox as a test step, not as cleanup). - Follow-up `openshell gateway destroy` / `openshell sandbox delete` calls after the main destroy — scoped to one target per commit. Signed-off-by: Prekshi Vyas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Extends the fix in cfc90f6 (which removed the unsafe rm from my new sandbox-teardown.sh helper) to every pre-existing `teardown()` function in the 10 scripts my PR skipped because they already had their own trap. Five of those scripts did the same unconditional `rm -f ~/.nemoclaw/onboard.lock` in their trap-based teardown. On a shared host with concurrent e2e runs, that could yank a live lock out from under another process. `acquireOnboardLock` in `src/lib/onboard-session.ts` is PID-ownership-aware (liveness + inode check), so a crashed process's stale lock gets cleaned up automatically on the next onboard; the explicit rm is unnecessary. Sites removed (all inside trap-based teardown()/cleanup() functions): - test-network-policy.sh:537 - test-deployment-services.sh:413 - test-diagnostics.sh:394 - test-sandbox-operations.sh:657 - test-inference-routing.sh:665 Other 5 scripts in the "has own trap" cohort (test-token-rotation, test-ollama-auth-proxy-e2e, test-double-onboard, test-gpu-e2e, test-e2e-cloud-experimental) do not unlink the onboard.lock in their teardown — nothing to remove. Intentionally NOT changing: - Preflight `rm -f` calls at the top of setup_sandbox / test functions. Same unsafe-under-concurrency pattern, but scoped to a narrow window right before onboard. Out of scope for this PR. Signed-off-by: Prekshi Vyas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
When I expanded the workflow env var to three jobs earlier in this PR I used "consistency with other jobs" as the rationale. That turned out to be wrong for two of the three — the env var introduces an unnecessary delete+create cycle that hit an openshell k8s race in nightly run 24811493024: Sandbox 'e2e-deploy' exists and is ready — recreating by explicit request. Deleted sandbox e2e-deploy [image rebuild, ~2 min] × sandbox 'e2e-deploy' already exists FATAL: Onboard failed for 'e2e-deploy' Audit of the three jobs I set the env var on: - network-policy-e2e: install.sh's onboard leaves the sandbox in a not-ready state that `nemoclaw list | grep` doesn't surface, so the test's second onboard hits "already exists but not ready" without RECREATE=1. KEEP. - inference-routing-e2e: test-inference-routing.sh now does an unconditional preflight destroy (my change earlier in this PR) at every call site. Setting RECREATE=1 on top of that is redundant. Passed without it on main for the four most recent runs. REMOVE. - deployment-services-e2e: test-deployment-services.sh's `onboard_sandbox()` has no preflight destroy; it just runs `nemoclaw onboard` and — on main — reuses the Ready sandbox that install.sh already created. Adding RECREATE=1 turned a clean reuse into a delete+rebuild+recreate round-trip that raced openshell's k8s pod teardown. REMOVE. Signed-off-by: Prekshi Vyas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Eight nightly jobs set `NEMOCLAW_RECREATE_SANDBOX: "1"` at the workflow level while their test scripts already set the same variable internally (via `export` or an inline per-onboard call). The workflow-level env is pure duplication — removing it makes the "who actually relies on the env var" answer visible at the workflow level. Jobs trimmed (internal handling preserves behaviour): - messaging-providers-e2e (test-messaging-providers.sh:192 exports) - sandbox-survival-e2e (test-sandbox-survival.sh:204 sets per call) - skip-permissions-e2e (test-skip-permissions-policy.sh:140 per call) - snapshot-commands-e2e (test-snapshot-commands.sh:64 exports) - shields-config-e2e (test-shields-config.sh:123 exports) - rebuild-openclaw-e2e (test-rebuild-openclaw.sh:75 exports) - upgrade-stale-sandbox-e2e (test-upgrade-stale-sandbox.sh:65 exports) - rebuild-hermes-e2e (test-rebuild-hermes.sh:70 exports) Jobs that keep the workflow-level env var (they need it — test scripts do not force recreate internally): - cloud-e2e, cloud-experimental-e2e, hermes-e2e, diagnostics-e2e, gpu-e2e (carryover from earlier main, kept to avoid scope creep on this PR) - network-policy-e2e (my addition — belt-and-suspenders for the install.sh "not-ready sandbox" flake this PR is closing) Signed-off-by: Prekshi Vyas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Automated PR review summaryReviewed PR #2313: fix(e2e): make nightly teardown reliable and prevent sandbox leaks Recommendation
Installation and setup findings
What was validated
Passing tests and why they matteredPassing test 1: Shared teardown helper destroys registered sandboxes and honors KEEP
Passing test 2: Onboard repair/resume scripts define repo-local nemoclaw shim before helper load
Passing test 3: Network-policy and inference-routing preflight now use unconditional destroy
Bottom line
|
Merge main into fix/nightly-e2e-repairs-v4, resolving conflicts: - nightly-e2e.yaml: keep contains(needs.*.result, 'failure') from #2371, remove cloud-experimental-e2e from notify-on-failure needs array - test-snapshot-commands.sh: keep exit-code check from this PR + tolerant grep regex from #2314 Address reviewer feedback: - Drop NEMOCLAW_RECREATE_SANDBOX from deployment-services to avoid re-introducing the delete+create race fixed in #2313 (@prekshivyas) - Update cloud-experimental-e2e disable comment: drop stale Landlock mention (fixed in OpenShell#810 v0.0.32+), reference only docs-drift (@prekshivyas) - Extract dump_diagnostics() in test-snapshot-commands.sh to centralize duplicate probes from fail() and Phase 2b (CodeRabbit)
Summary
Addresses the recent
network-policy-e2eflake in nightly-e2e and the broader sandbox-leak pattern across the e2e suite.Root cause (immediate flake)
In run 24806434211 the
network-policy-e2ejob failed at onboard with:A prior run on the shared Brev launchable left
e2e-net-policyin a not-ready state. Neither the workflow nortest-network-policy.shsetNEMOCLAW_RECREATE_SANDBOX=1, and the script's preflight cleanup (test-network-policy.sh:217) was guarded bynemoclaw list | grep, which does not surface not-ready sandboxes — so the preflight destroy never fired.Broader issue (sandbox leaks)
15 of 27
test/e2e/test-*.shscripts had notrap teardown EXIT. A mid-run failure leaves the sandbox alive on the launchable until the next run'sNEMOCLAW_RECREATE_SANDBOX=1clobbers it (if set). On the shared launchable this accumulates as dangling k8s pods, netns, volumes — eventually producing the exact not-ready state this PR is closing.Changes
.github/workflows/nightly-e2e.yaml— addNEMOCLAW_RECREATE_SANDBOX: "1"to the 3 jobs still missing it:network-policy-e2e,inference-routing-e2e,deployment-services-e2e.test/e2e/test-network-policy.sh,test/e2e/test-inference-routing.sh— replacelist | grep-gated preflight destroys with unconditionalnemoclaw "$SANDBOX_NAME" destroy --yes 2>/dev/null || true. Post-failure assertions (e.g. TC-INF-06/07 checking that no sandbox was created after a bad key) kept unchanged — those are checks, not cleanup.test/e2e/lib/sandbox-teardown.sh— new shared helper (executable,#!/usr/bin/env bash). Registers each sandbox name and installs a singletrap … EXITthat destroys every registered sandbox and clearsonboard.lock. Keeps the per-script diff to two lines so reviewers can audit the full wiring quickly.test-onboard-repair.sh,test-onboard-resume.sh— extra conditional shim:if ! command -v nemoclaw; then nemoclaw() { node "$REPO/bin/nemoclaw.js" "$@"; }; fi. These two scripts drive the CLI viarun_nemoclaw(barenode bin/nemoclaw.js) and don't assume a global CLI on PATH; without the shim, the trap'snemoclaw destroywould silently no-op in repo-local dev runs. CI (withinstall-openshell.sh+npm linkon PATH) skips the shim.NEMOCLAW_E2E_KEEP_SANDBOX=1escape hatch so a local dev reproducing a flake can inspect the sandbox after the test — CI never sets this variable..gitleaksignore— allowlist two pre-existing false-positives (discord-client-secretrule matching the fakeDISCORD_BOT_TOKEN_A/_Bstrings atnightly-e2e.yaml:232-233from test(e2e): skip cleanly under VPN, cover Discord token rotation #2257). These are test fakes, not secrets. Unblocks pre-commit for any branch rebased onto current main.Intentionally skipped
test-runtime-overrides.sh— puredocker run --rm, no sandbox.test-spark-install.sh— install smoke, no sandbox.trap teardown EXITthemselves were not changed, because sourcing the helper would silently replace their existing trap: deployment-services, diagnostics, double-onboard, gpu-e2e, inference-routing, network-policy, ollama-auth-proxy, sandbox-operations, token-rotation, e2e-cloud-experimental.Type of Change
Testing
bash -nsyntax check on all 18 modified scripts + new helper — passesnemoclaw:register_sandbox_for_teardownregistered two sandboxes, EXIT trap dispatchednemoclaw destroy --yesfor both; withNEMOCLAW_E2E_KEEP_SANDBOX=1set, teardown correctly returned early without destroyingdestroy --yes || true. My trap adds a second destroy on EXIT that's idempotent (|| true) and silent (>/dev/null 2>&1). Functionally zero impact on success paths; benefit is protection on failure paths where mid-script exit skips the end-of-main destroy.trap/execcalls. My helper's trap is the sole EXIT handler in each.$REPOordering verified — defined attest-onboard-repair.sh:51-53/test-onboard-resume.sh:67-69, well before the shim at line 70 / 85.Known gaps (not in this PR)
CI coverage: 5 of 15 modified scripts aren't invoked by any GH Actions workflow —
test-credential-sanitization,test-onboard-repair,test-onboard-resume,test-sandbox-rebuild,test-telegram-injection. Changes are defensive (they benefit when run locally or from ad-hoc workflows) but aren't exercised in the automated suite.Signal handling: the helper traps
EXITonly (matching the existing convention in the 10 skipped scripts). SIGINT / SIGTERM / SIGKILL are not handled — consistent with the rest of the e2e suite..gitleaksignorefingerprints are positional (line 232/233 ofnightly-e2e.yaml). Inherent limitation of gitleaks' allowlist format.Out of scope (filed for a follow-up):
if: always()post-job cleanup (belt-and-suspenders against script crashes that never reach the trap)e2e-*sweeper at the launchable levelSigned-off-by: Prekshi Vyas [email protected]
🤖 Generated with Claude Code
Summary by CodeRabbit
Tests
Chores