fix(shields): clean up permissive runtime temp dir on failed shields down (#7964) - #7966
Conversation
…down (#7964) shieldsDown builds the merged permissive policy into a 0700 mkdtemp directory, but only the policy-apply try/finally removed it. The two early exits between the build and that apply — the auto-restore timer failure and the saveShieldsState failure — skipped cleanup, so each failed transition leaked one nemoclaw-permissive-runtime-* directory into the system temp directory. Route all three exits through a single cleanupRuntimePolicyFile() closure so a failed shields down leaves nothing behind. Add a flow test that drives the real shieldsDown timer-failure path with a live policy carrying filesystem_policy paths (so the merge writes a temp file) and asserts no permissive-runtime temp directory remains. Signed-off-by: Jason Ma <jama@nvidia.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe shields-down flow now shares cleanup for temporary permissive-policy directories across timer startup failure, state persistence failure, and policy application. Tests can provide live policy YAML and verify cleanup after timer startup failure. ChangesShields runtime policy cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Code Coverage OverviewLanguages: TypeScript TypeScript / code-coverage/pluginThe overall coverage in commit 172f40d in the TypeScript / code-coverage/cliThe overall coverage in commit 172f40d in the Show a code coverage summary of the most impacted files.
Updated |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib/shields/flow.test.ts`:
- Around line 880-908: Update the test around shieldsDown and the mocked fork to
capture the newly created nemoclaw-permissive-runtime directory during policy
application. Assert that a runtime-policy directory was observed before the
expected auto-restore timer error, then assert that no such directory remains
afterward, ensuring the test exercises temporary-policy creation and cleanup
rather than only the failure path.
🪄 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: Enterprise
Run ID: 6da5fdc2-8154-4858-ae30-7cc8ad8c2bb5
📒 Files selected for processing (2)
src/lib/shields/flow.test.tssrc/lib/shields/index.ts
PR Review Advisor — No blocking findings reportedAdvisor assessment: No blocking advisor findings reported Model lanes
Nemotron output stays in workflow artifacts and does not change the assessment above. E2E guidanceAdvisory only. E2E / PR Gate selects and runs jobs independently. Recommended E2E: 1 optional E2E recommendation
1 warning · 0 suggestionsWarningsWarnings do not block.
|
…sition (#7964) Address CodeRabbit review on #7966: the regression test asserted only that no runtime-policy directory remained after a failed shields down, which a vacuous run (no temp file ever created) would also satisfy. Capture the temp directory set inside the fork mock, which shieldsDown invokes after building the permissive policy, and assert exactly one runtime-policy directory exists during the transition. The test now proves it exercises temp-policy creation and cleanup, not just absence. Signed-off-by: Jason Ma <jama@nvidia.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Addressed the CodeRabbit review in 172f40d: the regression test now captures the temp-directory set inside the Re-verified on the Ubuntu host (clean clone +
|
apurvvkumaria
left a comment
There was a problem hiding this comment.
Reviewed exact head 172f40d. The change routes every post-merge failure exit through the existing scoped temporary-policy cleanup while retaining the normal apply-path cleanup, and the regression test proves the directory exists at the failure point and is removed afterward. I found no blocking correctness, security, compatibility, or regression issue; current CI is green.
Summary
nemoclaw <sandbox> shields downleaked a0700temporary directory into thesystem temp directory whenever the transition failed partway through.
shieldsDownbuilds the merged permissive policy into amkdtempdirectory, butonly the policy-apply
try/finallyremoved it. Two early exits sit between thebuild and that apply, and both skipped cleanup:
Cannot start auto-restore timer: …), andsaveShieldsStatefailure (rethrow).Each failed transition therefore leaked one
nemoclaw-permissive-runtime-*directory holding the merged permissive policy YAML. The merge runs on
effectively every real
shields down, because a liveopenshell policy get --basealways carriesfilesystem_policy.read_only/read_writeentries.Fixes #7964.
Changes
src/lib/shields/index.ts: route all three exits (timer failure,saveShieldsStatefailure, and the existing applyfinally) through a singlecleanupRuntimePolicyFile()closure, so a failedshields downleaves nothingbehind.
src/lib/shields/flow.test.ts: add a regression test that drives the realshieldsDowntimer-failure path with a live policy carryingfilesystem_policypaths (so the permissive merge writes a temp file, matchingproduction) and asserts no
nemoclaw-permissive-runtime-*directory remains.A new
livePolicyYamlharness option supplies that live policy.Verification
Run on the Ubuntu host (
npm ci+ plugin build, Node 22), against a clean cloneof this branch:
npx vitest run --project cli src/lib/shields/flow.test.ts -t "removes the permissive runtime temp directory"→ 1 passed.1 failed with
AssertionError: expected [ Array(1) ] to deeply equal []and a leftover
nemoclaw-permissive-runtime-*directory.The second run confirms the test exercises the real
shieldsDowncode path (nothand-built internal state) and reproduces the reported leak; the first confirms
the fix removes it.
Documentation
No user-visible surface changes (no CLI, config, output, or documented behavior
change). Behavior is corrected to match the already-documented contract that a
failed
shields downleaves nothing behind. No docs update required.Signed-off-by: Jason Ma jama@nvidia.com
Summary by CodeRabbit