Skip to content

fix(cli): refuse sessions admin RPCs on non-OpenClaw agents - #7588

Merged
cv merged 4 commits into
mainfrom
fix/sessions-admin-agent-gate
Jul 27, 2026
Merged

fix(cli): refuse sessions admin RPCs on non-OpenClaw agents#7588
cv merged 4 commits into
mainfrom
fix/sessions-admin-agent-gate

Conversation

@laitingsheng

@laitingsheng laitingsheng commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

sessions reset and sessions delete dispatch an OpenClaw plugin-SDK script into the sandbox, but they never checked which agent the sandbox runs. On a Hermes sandbox the script reached its own OPENCLAW_GATEWAY_TOKEN guard and failed with an in-sandbox stack trace that read as a NemoClaw wiring gap, because Hermes ships neither the OpenClaw binary nor that token. Both commands now resolve the registry agent first and report the agent mismatch instead of running the script.

Related Issue

Fixes #7587

Changes

  • callOpenclawGateway resolves the sandbox agent from the host-side registry and stops before any openshell sandbox exec when that agent is not OpenClaw. This is the single choke point for both sessions.reset and sessions.delete.
  • The refusal states the sandbox, the method, and the agent. Hermes sandboxes also get the session commands they do have: sessions list and sessions export.
  • Only an existing registry entry whose agent field is absent or null keeps the historical OpenClaw default. A missing entry or empty agent is refused before any sandbox call, and registry read errors propagate without dispatch.
  • sessions list was routed by agent already; reset and delete now follow the same rule. The docs already scope both commands to OpenClaw, so no doc change was needed.

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: docs/reference/commands.mdx already presents sessions reset and sessions delete inside <AgentOnly variant="openclaw">, so the documented contract is unchanged; this change makes the CLI match it.
  • 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: Exact-head Codex Desktop nine-category review at PR SHA 7564ba458ef4d9145a9d94f008196e4458168dd7 found no security issues. Registry lookup failures and unknown agent identities stop before auto-pair or sandbox execution.
  • 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: no-docs-needed
  • Evidence: At exact PR head 7564ba458ef4d9145a9d94f008196e4458168dd7, reviewed the three-file diff, accepted issue [CLI] sessions reset always fails: OPENCLAW_GATEWAY_TOKEN is never provided to the in-sandbox script that needs it #7587, and docs/reference/commands.mdx. The docs already scope sessions reset and sessions delete to OpenClaw and identify their OpenClaw gateway RPCs; the code now enforces that documented boundary before auto-pairing or sandbox dispatch while preserving explicit OpenClaw and existing absent/null-agent legacy registry entries. No command, flag, output schema, workflow, or supported surface changed. Changed comments and test titles have no blocking writing findings. The PR files are unchanged since reviewed head 386e89b6a; exact-head 52 checks have no non-pass result, protected E2E and gate checker pass, and prior focused validation passed 143 CLI plus 16 integration tests, CLI typecheck, and npm run check:diff.
  • Agent: Codex Desktop

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 check:diff passed 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: npx vitest run --project cli src/lib/actions/sandbox/sessions/ — 143 passed; npx vitest run --project integration test/sandbox-sessions-export-cli.test.ts test/sandbox-sessions-admin-agent-cli.test.ts — 16 passed; npm run typecheck:cli and npm run check:diff passed at PR SHA 386e89b6a.
  • 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

  • Bug Fixes
    • Prevented session administration commands from invoking gateway admin operations on sandboxes backed by unsupported agents.
    • Added clearer refusal messaging (with guidance) when the sandbox agent is incompatible.
    • Preserved normal behavior for legacy or missing agent metadata, and avoided dispatch when the sandbox agent information can’t be resolved.
  • Tests
    • Added CLI coverage for supported, unsupported, and unknown sandbox agent scenarios.
    • Verified refusal outputs and confirmed gateway calls and credential handling behavior match expectations.

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

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Gateway admin RPC calls now inspect the sandbox registry agent, refuse unsupported agents such as Hermes, preserve legacy dispatch behavior for missing agent fields, and add unit and CLI coverage for these paths.

Changes

Agent-aware gateway RPC dispatch

Layer / File(s) Summary
Gateway agent resolution and refusal
src/lib/actions/sandbox/sessions/gateway-rpc.ts
Resolves the registered sandbox agent, allows OpenClaw and legacy entries, and refuses unsupported or missing agents with agent-specific diagnostics before auto-pair or capture.
Agent-aware dispatch validation
src/lib/actions/sandbox/sessions/gateway-rpc-call.test.ts, test/sandbox-sessions-admin-agent-cli.test.ts
Tests refusal, successful dispatch, legacy-entry handling, registry lookup failures, and CLI behavior for Hermes-backed and unassigned sandboxes.

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

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant callOpenclawGateway
  participant Registry
  participant OpenShell

  CLI->>callOpenclawGateway: request sessions admin RPC
  callOpenclawGateway->>Registry: getSandbox
  alt unsupported or missing registry agent
    callOpenclawGateway-->>CLI: print refusal and exit 1
  else OpenClaw or legacy agent field
    callOpenclawGateway->>OpenShell: dispatch gateway RPC
    OpenShell-->>CLI: return RPC result
  end
Loading

Suggested labels: integration: hermes, area: sandbox, area: security

Suggested reviewers: cv, prekshivyas

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds agent-based refusal, but it does not address the issue's token-forwarding fix for sessions reset/delete on OpenClaw sandboxes. Forward OPENCLAW_GATEWAY_TOKEN into the in-sandbox admin script or otherwise make sessions reset/delete work as described in the issue.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The changes stay focused on sessions admin RPC gating and tests, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: refusing sessions admin RPCs when the sandbox agent is not OpenClaw.
✨ 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/sessions-admin-agent-gate

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

@laitingsheng laitingsheng added integration: openclaw OpenClaw integration behavior area: cli Command line interface, flags, terminal UX, or output bug-fix PR fixes a bug or regression labels Jul 26, 2026
@github-code-quality

github-code-quality Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall coverage in commit 7564ba4 in the fix/sessions-admin-a... branch remains at 96%, unchanged from commit fdf14f5 in the main branch.

TypeScript / code-coverage/cli

The overall coverage in commit 7564ba4 in the fix/sessions-admin-a... branch is 80%. The coverage in commit a02a3b9 in the main branch is 81%.

Show a code coverage summary of the most impacted files.
File main a02a3b9 fix/sessions-admin-a... 7564ba4 +/-
src/lib/onboard...ndbox-create.ts 83% 33% -50%
src/lib/actions...-add-restart.ts 19% 10% -9%
src/lib/actions...x/mcp-bridge.ts 43% 35% -8%
src/lib/onboard...ndbox-create.ts 91% 83% -8%
src/lib/actions...lution-probe.ts 93% 88% -5%
src/lib/actions...e-validation.ts 84% 81% -3%
src/lib/actions...dbox/destroy.ts 95% 93% -2%
src/lib/onboard...eway-service.ts 82% 81% -1%
src/lib/actions...ol-discovery.ts 0% 82% +82%
src/lib/actions...time-command.ts 0% 82% +82%

Updated July 27, 2026 03:09 UTC

@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)
test/sandbox-sessions-admin-agent-cli.test.ts (1)

41-43: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Suffix the suite title with the linked issue.

This suite covers Issue #7587, but its describe title lacks the required final (#7587) suffix. Add it on Line 41; nested tests need not repeat it.

Proposed fix
-describe("sandbox sessions admin RPCs on a non-OpenClaw agent", () => {
+describe("sandbox sessions admin RPCs on a non-OpenClaw agent (`#7587`)", () => {

As per coding guidelines, “Use behavior-oriented test titles and place local issue references in a final (#1234) suffix.”

🤖 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 `@test/sandbox-sessions-admin-agent-cli.test.ts` around lines 41 - 43, Update
the describe suite title surrounding the sandbox sessions admin RPC tests to
append the issue reference as the final “(`#7587`)” suffix, preserving the
existing behavior-oriented wording and leaving nested test titles unchanged.

Sources: Coding guidelines, Learnings

🤖 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 `@test/sandbox-sessions-admin-agent-cli.test.ts`:
- Around line 41-43: Update the describe suite title surrounding the sandbox
sessions admin RPC tests to append the issue reference as the final “(`#7587`)”
suffix, preserving the existing behavior-oriented wording and leaving nested
test titles unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: aecc3060-0f41-4cb1-b454-72df0790082c

📥 Commits

Reviewing files that changed from the base of the PR and between d4a859a and 8492e01.

📒 Files selected for processing (3)
  • src/lib/actions/sandbox/sessions/gateway-rpc-call.test.ts
  • src/lib/actions/sandbox/sessions/gateway-rpc.ts
  • test/sandbox-sessions-admin-agent-cli.test.ts

@github-actions

github-actions Bot commented Jul 26, 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 · 1 blocker · 1 warning · 0 suggestions
  • Model comparison: normalized findings differ; normalized E2E selections differ; Nemotron reported 1 more blocker, 1 more warning, the same number of suggestions.

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

1 optional E2E recommendation
  • sessions-agents-cli

Workflow run details

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

@cv cv 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.

Security blocker at exact head 8492e01: resolveSandboxAgent catches every registry.getSandbox error and assumes OpenClaw. getSandbox can throw ConfigPermissionError for host permission or path-security failures; this turns an unreadable authoritative agent identity into permission to enter auto-pair and destructive sessions.reset or sessions.delete dispatch. Adjacent sessions list and export paths fail closed. Please: (1) fail closed with no auto-pair or sandbox exec when lookup throws or the registry entry is missing; (2) default to OpenClaw only when an existing legacy entry has an absent or null agent; (3) replace the throw-fallback test with no-dispatch negatives while retaining legacy-null and explicit-OpenClaw positives; and (4) refresh the documentation-writer receipt and required CI. Refusing Hermes for both commands matches the current OpenClaw-only contract; Hermes delete parity needs a separately accepted product scope.

@apurvvkumaria apurvvkumaria self-assigned this Jul 26, 2026
prekshivyas and others added 3 commits July 26, 2026 17:00
Signed-off-by: Prekshi Vyas <prekshiv@nvidia.com>
Signed-off-by: Prekshi Vyas <prekshiv@nvidia.com>
Signed-off-by: Apurv Kumaria <akumaria@nvidia.com>

@prekshivyas prekshivyas 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.

Security review — exact head 7564ba458ef4d9145a9d94f008196e4458168dd7: PASS, no findings across all nine categories.

  1. Secrets and credentials: PASS. No credential value, forwarding path, persistence, or log surface changes. Unsupported and unknown agents are rejected before the token-bearing OpenClaw script runs.
  2. Input validation and sanitization: PASS. The gateway method remains exact-allowlisted; registry identity is checked before auto-pair or sandbox execution. Non-OpenClaw and empty identities fail closed.
  3. Authentication and authorization: PASS. Only explicit OpenClaw and an existing legacy registry record with an absent or null agent retain the historical admin-RPC path. Missing entries are refused, and registry lookup errors propagate without dispatch.
  4. Dependencies: PASS. No dependency, lockfile, image, or external-source change.
  5. Error handling and logging: PASS. The refusal names the sandbox, method, and agent without exposing credentials. Existing gateway-output redaction remains intact.
  6. Cryptography and data protection: PASS / not applicable. No cryptographic or storage behavior changes.
  7. Configuration and infrastructure: PASS. No network policy, port, container privilege, workflow, or runtime configuration change.
  8. Security testing: PASS. Unit and CLI tests cover explicit OpenClaw, legacy absent/null agent fields, Hermes refusal for reset/delete, missing entry, empty identity, and thrown registry reads; every forbidden path asserts no auto-pair and/or no sandbox execution. Exact-head CI has all 52 checks green, including protected E2E.
  9. System security: PASS. The authoritative host registry check occurs before side effects, preserves least privilege, and closes the prior fail-open permission/error path identified by cv. No TOCTOU or client-only bypass is introduced by this local synchronous dispatch boundary.

The later signed merge commit changed none of the three PR files relative to previously reviewed head 386e89b6a. Files reviewed: src/lib/actions/sandbox/sessions/gateway-rpc.ts, src/lib/actions/sandbox/sessions/gateway-rpc-call.test.ts, and test/sandbox-sessions-admin-agent-cli.test.ts.

@prekshivyas prekshivyas 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.

Maintainer review complete at exact head 7564ba4. The prior fail-open registry lookup issue is fixed: missing/empty identities and lookup errors now refuse dispatch, while only explicit OpenClaw and existing legacy absent/null agent entries retain the historical path. Targeted unit/CLI coverage, exact-head protected E2E, security review, documentation receipt, DCO, signatures, and all 54 current checks pass. check-gates reports allPass=true. This approval does not dismiss or supersede another reviewer’s recorded decision.

@cv cv 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.

Exact-head approval at 7564ba4. Product scope is established by #7587; all nine security categories pass; missing, empty, unknown, or unreadable agent identity fails closed before auto-pair or sandbox execution; exact protected E2E and all 54 current checks pass; all threads are resolved; DCO and GitHub verification pass. The low-value test-title wording nit is nonblocking under the changed-text pilot and does not affect behavior, security, test meaning, or release meaning.

@cv
cv merged commit c02f01e into main Jul 27, 2026
77 checks passed
@cv
cv deleted the fix/sessions-admin-agent-gate branch July 27, 2026 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli Command line interface, flags, terminal UX, or output bug-fix PR fixes a bug or regression integration: openclaw OpenClaw integration behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CLI] sessions reset always fails: OPENCLAW_GATEWAY_TOKEN is never provided to the in-sandbox script that needs it

4 participants