Skip to content

fix(sandbox): bootstrap device identity before restored clone approval - #7968

Closed
laitingsheng wants to merge 2 commits into
mainfrom
fix/restored-clone-pairing-approval
Closed

fix(sandbox): bootstrap device identity before restored clone approval#7968
laitingsheng wants to merge 2 commits into
mainfrom
fix/restored-clone-pairing-approval

Conversation

@laitingsheng

@laitingsheng laitingsheng commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

A cross-sandbox snapshot restore never carries runtime auth state, so the restored clone reaches its pairing approval with no stored operator device credential. The approval pass then called openclaw devices approve with the gateway token stripped, leaving the call with nothing to authenticate, and the restore ended with gateway pairing could not be verified reporting scope-upgrade-pending; approval=approve-failed. The clone's device list now performs the same pairing bootstrap the in-sandbox watcher already performs, so the credential exists before the stripped approve runs.

Related Issue

Fixes #7431

Changes

  • Add pairing_bootstrap_env to the shared approval policy module, beside the existing gateway_approval_env. It keeps the gateway environment and sets the device-pairing marker, matching the watcher's unbootstrapped first list call.
  • Run the restored clone's devices list through that environment. The current consumer is approveRestoredClonePairing, the only caller that passes localDeviceOnly; connect and doctor keep a byte-identical script because they run after onboard, when the stored credential already exists. buildAutoPairApprovalScript script-shape tests protect that split.
  • Split the clone approval receipt so a timed-out approve reports approve-timeout rather than approve-failed. Both outcomes previously produced one receipt, which is why the reported QA failure could not be attributed to a rejection or a stall.

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Quality Gates

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification:
  • Tests not applicable — justification:
  • Docs updated for user-facing behavior changes
  • Docs not applicable — justification: an internal restore-time recovery path changed. The restore command, its failure message, and every documented configuration and default are unchanged; only the receipt value inside that message gains a new case.
  • Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging)
  • Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification:
  • Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue:

Documentation Writer Review

  • Documentation writer subagent reviewed the completed changes
  • Result: blocked
  • Evidence: no documentation files changed. The four changed files are the shared approval policy module, the approval script builder, and their tests.
  • Agent: none — no documentation writer subagent was run on this host.

DGX Station Hardware Evidence

  • Tested on DGX Station
  • Tested commit:
  • Station profile/scenario:
  • Result:
  • Supporting evidence:

Verification

  • PR description includes a Signed-off-by: line and every commit appears as Verified in GitHub
  • Normal pre-commit, commit-msg, and pre-push hooks passed, or npm run validate:pr passed after refreshing origin/main when hooks were skipped or unavailable
  • Targeted behavior tests pass for the current change set, or tests are marked not applicable above — command/result or justification: vitest --project cli auto-pair-approval restore-gateway-pairing 18/18; vitest --project integration openclaw-device-approval-policy 12/12; vitest --project integration nemoclaw-start 114/114; npm run test:changed 203/203 across 20 files; npm run typecheck:cli clean.
  • Applicable broad gate passed — npm test for broad runtime/test-harness changes; npm run check for repo-wide validation/coverage changes — command/result:
  • Quality Gates section completed with required justifications or waivers
  • No secrets, API keys, or credentials committed
  • npm run docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Signed-off-by: Tinson Lai tinsonl@nvidia.com

Summary by CodeRabbit

  • New Features
    • Improved local device pairing by preserving gateway credentials and consistently enabling required pairing checks.
    • Added clearer approval status reporting, including a distinct timeout result.
  • Bug Fixes
    • Prevented stalled approval attempts from being recorded as successful approvals.
    • Improved handling when approval commands fail or exceed their timeout.
  • Tests
    • Expanded coverage for restored environments, credential propagation, pairing behavior, and timeout scenarios.

A restored clone never carries runtime auth state, so its approval pass
held no stored device credential while the approve call already stripped
the gateway token. The clone device list now runs the same pairing
bootstrap the in-sandbox watcher uses, and a stalled approve reports a
timeout receipt instead of a generic failure.

Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The approval flow now creates a forced-device-pairing environment for local device listing and distinguishes approval subprocess timeouts from other failures. Tests cover environment propagation, timeout receipts, and stalled approvals.

Changes

Pairing and approval flow

Layer / File(s) Summary
Pairing bootstrap integration
scripts/lib/openclaw_device_approval_policy.py, src/lib/actions/sandbox/auto-pair-approval.ts
The policy module adds pairing_bootstrap_env. Local device listing uses the returned environment with NEMOCLAW_OPENCLAW_FORCE_DEVICE_PAIRING=1.
Approval timeout receipts
src/lib/actions/sandbox/auto-pair-approval.ts
Approval subprocess timeouts now emit approve-timeout receipts. Other file or OS failures emit approve-failed.
Bootstrap and timeout validation
test/openclaw-device-approval-policy.test.ts, src/lib/actions/sandbox/auto-pair-approval.test.ts
Tests verify environment retention and override behavior, device-list propagation, stalled approvals, timeout receipts, and the absence of recorded approvals.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GeneratedApprovalScript
  participant PairingPolicyModule
  participant DeviceListSubprocess
  participant ApprovalSubprocess
  GeneratedApprovalScript->>PairingPolicyModule: call pairing_bootstrap_env
  PairingPolicyModule-->>GeneratedApprovalScript: return forced-pairing environment
  GeneratedApprovalScript->>DeviceListSubprocess: run device listing with bootstrap environment
  GeneratedApprovalScript->>ApprovalSubprocess: request device approval
  ApprovalSubprocess-->>GeneratedApprovalScript: timeout or approval result
  GeneratedApprovalScript-->>GeneratedApprovalScript: emit approve-timeout or approval receipt
Loading

Suggested reviewers: brandonpelfrey

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: bootstrapping device identity before restored clone approval.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/restored-clone-pairing-approval

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/lib/actions/sandbox/auto-pair-approval.test.ts (1)

44-52: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace source-text assertions with execution checks.

Lines 44-52 and Line 77 lock the test to generated Python text and policy source layout. Extend the execution fixture to verify that ordinary device listing has no pairing marker and restored-clone listing has the marker. Remove these containment assertions.

As per path instructions, prefer observable public-boundary outcomes and flag source-text assertions.

Also applies to: 77-77

🤖 Prompt for 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.

In `@src/lib/actions/sandbox/auto-pair-approval.test.ts` around lines 44 - 52,
Update the test around the execution fixture in the auto-pair approval flow to
validate behavior through public-boundary results: ordinary device listing must
have no pairing marker, while restored-clone listing must include one. Remove
the generated Python source containment assertions, including the assertion at
line 77, and preserve the existing execution setup and other observable checks.

Source: Path instructions

🤖 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.

Nitpick comments:
In `@src/lib/actions/sandbox/auto-pair-approval.test.ts`:
- Around line 44-52: Update the test around the execution fixture in the
auto-pair approval flow to validate behavior through public-boundary results:
ordinary device listing must have no pairing marker, while restored-clone
listing must include one. Remove the generated Python source containment
assertions, including the assertion at line 77, and preserve the existing
execution setup and other observable checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2208d3b7-9952-48a5-be97-4ba632bb3e64

📥 Commits

Reviewing files that changed from the base of the PR and between 91fc63e and ffd2a7f.

📒 Files selected for processing (4)
  • scripts/lib/openclaw_device_approval_policy.py
  • src/lib/actions/sandbox/auto-pair-approval.test.ts
  • src/lib/actions/sandbox/auto-pair-approval.ts
  • test/openclaw-device-approval-policy.test.ts

@github-code-quality

github-code-quality Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall coverage in commit 88a9b4d in the fix/restored-clone-p... branch remains at 96%, unchanged from commit 387cb08 in the main branch.

TypeScript / code-coverage/cli

The overall coverage in commit 88a9b4d in the fix/restored-clone-p... branch remains at 81%, unchanged from commit 387cb08 in the main branch.

Show a code coverage summary of the most impacted files.
File main 387cb08 fix/restored-clone-p... 88a9b4d +/-
src/lib/onboard...flight-ports.ts 67% 33% -34%
src/lib/onboard...box-prebuild.ts 92% 74% -18%
src/lib/actions...ocker-health.ts 82% 65% -17%
src/lib/actions...confirmation.ts 79% 69% -10%
src/lib/onboard...box-gpu-mode.ts 97% 92% -5%
src/lib/actions...orchestrator.ts 87% 83% -4%
src/lib/onboard...al-inference.ts 93% 91% -2%
src/lib/onboard/preflight.ts 80% 80% 0%
src/lib/onboard...host-anchors.ts 90% 94% +4%
src/lib/onboard/docker-cdi.ts 70% 80% +10%

Updated July 31, 2026 08:22 UTC

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor — No blocking findings reported

Advisor assessment: No blocking advisor findings reported
Next action: No advisor follow-up needed.
Findings: 0 blockers · 0 warnings · 0 suggestions

Model lanes

  • GPT-5.6 Terra (primary): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Nemotron 3 Ultra (second opinion): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Model comparison: normalized findings match; normalized E2E selections differ; severity counts match.

Nemotron output stays in workflow artifacts and does not change the assessment above.

E2E guidance

Advisory only. E2E / PR Gate selects and runs jobs independently.

Recommended E2E: onboard-repair, onboard-resume, snapshot-commands

1 optional E2E recommendation
  • issue-4462-scope-upgrade-approval

Workflow run details

This automated review informs maintainers. Warnings and suggestions do not require a response. A maintainer decides whether to merge.

@laitingsheng laitingsheng added NV QA Bugs found by the NVIDIA QA Team area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery bug-fix PR fixes a bug or regression v0.0.99 labels Jul 31, 2026
@copy-pr-bot

copy-pr-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@apurvvkumaria apurvvkumaria left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment — reviewed exact head 88a9b4d. I found no blocking correctness or security regression in the current two-file diff. Non-blocking: after the merge from main, the comparison now only adds pairing_bootstrap_env plus direct unit coverage; no production consumer calls that helper, and the restore-time approval logic described in the PR body is no longer part of this diff. Please consider closing this as superseded by the intervening restored-pairing work, or use a narrowly scoped follow-up PR if a current-main reproduction shows a remaining gap. This does not need to block the current branch on safety grounds.

@cv cv closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery bug-fix PR fixes a bug or regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Linux][Sandbox] snapshot restore does not preserve gateway websocket credentials causing agent invocations to fail

5 participants