Repository navigation
fix(cli): reject an unconfigured --agent across every operator selector - #126983
Merged
Merged
Conversation
`skills` (#126954) turned out to be one instance of a class. Two more surfaces accepted an agent id that names nothing, and one of them wrote it to disk: - `sandbox explain --agent nope-agent` exited 0 and printed a complete policy report, including `Elevated: enabled: true` and a workspace root that does not exist, for an agent `openclaw agents list` does not know. - `approvals allowlist add "<pattern>" --agent nope-agent` exited 0, printed `Writing local approvals.`, and persisted the entry under a key nothing will ever read. The operator believes they approved an exec pattern; nothing was approved. This is the severe one: a false record of an approval. Sweeping `option("--agent"` across the CLI found the rest. Each hit was classified as a selector (names the thing operated on, must validate) or a filter (narrows a list, may legitimately return empty). Selectors now route the explicit value through `resolveConfiguredAgentId`, the helper that already backs `models`, `memory`, `sessions list`, `hooks`, and every capability surface: `channels resolve`, `sessions export-trajectory`, `sessions archive/delete`, `backup enable`, `backup git create`, `backup sqlite create`. Blank-only guards close the empty-shell-variable hole in `hooks`, `sessions` list/cleanup/tail/ compact, `migrate`, and agent turns. Filters are deliberately unchanged: `audit`, `usage-cost`, agent bindings, `backup verify/restore`, and `sandbox recreate` all match existing records and correctly report no matches. Cron is gateway-owned and already rejects an unavailable agent server-side; it is untouched. `sessions archive/delete` was not silent -- it failed with `Session not found. Run openclaw sessions list --agent ghost --json to choose a valid key.` But that suggested command itself exits 1 with `Unknown agent id "ghost"`, so the remediation handed to the operator could not run. Validating locally, exactly as `sessions list` already does, keeps the hint runnable without adding a roster round-trip to the gateway. Production +140/-38.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
steipete
marked this pull request as ready for review
August 21, 2026 03:56
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 21, 2026
…or (openclaw#126983) `skills` (openclaw#126954) turned out to be one instance of a class. Two more surfaces accepted an agent id that names nothing, and one of them wrote it to disk: - `sandbox explain --agent nope-agent` exited 0 and printed a complete policy report, including `Elevated: enabled: true` and a workspace root that does not exist, for an agent `openclaw agents list` does not know. - `approvals allowlist add "<pattern>" --agent nope-agent` exited 0, printed `Writing local approvals.`, and persisted the entry under a key nothing will ever read. The operator believes they approved an exec pattern; nothing was approved. This is the severe one: a false record of an approval. Sweeping `option("--agent"` across the CLI found the rest. Each hit was classified as a selector (names the thing operated on, must validate) or a filter (narrows a list, may legitimately return empty). Selectors now route the explicit value through `resolveConfiguredAgentId`, the helper that already backs `models`, `memory`, `sessions list`, `hooks`, and every capability surface: `channels resolve`, `sessions export-trajectory`, `sessions archive/delete`, `backup enable`, `backup git create`, `backup sqlite create`. Blank-only guards close the empty-shell-variable hole in `hooks`, `sessions` list/cleanup/tail/ compact, `migrate`, and agent turns. Filters are deliberately unchanged: `audit`, `usage-cost`, agent bindings, `backup verify/restore`, and `sandbox recreate` all match existing records and correctly report no matches. Cron is gateway-owned and already rejects an unavailable agent server-side; it is untouched. `sessions archive/delete` was not silent -- it failed with `Session not found. Run openclaw sessions list --agent ghost --json to choose a valid key.` But that suggested command itself exits 1 with `Unknown agent id "ghost"`, so the remediation handed to the operator could not run. Validating locally, exactly as `sessions list` already does, keeps the hint runnable without adding a roster round-trip to the gateway. Production +140/-38.
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
#126954 fixed
skills --agent. It turned out to be one instance of a class. Two more surfaces accepted an agent id naming nothing, and one of them wrote it to disk.sandbox explain— exit 0, full confident report for an agent that does not exist:approvals allowlist add— exit 0, and it persists:The operator believes they approved an exec pattern. Nothing was approved, nothing will ever read that key, and nothing told them.
Why This Change Was Made
Sweeping
option("--agent"acrosssrc/cliandsrc/commands, each hit was classified as a selector (names the thing being operated on — must validate) or a filter (narrows a list — may legitimately return empty).Selectors now route the explicit value through
resolveConfiguredAgentId, the helper that already backsmodels,memory,sessions list,hooks, and everycapability-clisurface:sandbox explainUnknown agent idapprovals allowlist add/removechannels resolvesessions export-trajectorysessions archive/deletebackup enable/git create/sqlite createBlank-only guards close the empty-shell-variable hole in
hooks,sessionslist/cleanup/tail/compact,migrate, and agent turns.Filters are deliberately unchanged and were checked individually:
audit,usage-cost, agent bindings,backup verify/restore, andsandbox recreateall match existing records and correctly report no matches without mutating anything. Cron is gateway-owned and already rejects an unavailable agent server-side (cron job agent is unavailable: nope-agent), so it is untouched.The
sessions archive/deletecase is a dead-end, not a silent failureIt already failed visibly, but handed back a remediation that cannot run:
Validating locally — exactly as
sessions listalready does in the same command family — makes that suggestion runnable. A gateway roster fetch was considered and rejected: it adds anagents.listround-trip to every archive/delete, duplicates policy the server owns, and would make the localagents listhint wrong against a remote gateway.approvalsvalidates against the config for its actual target:loadConfigForApprovalsTargetalready fetches remote config viaconfig.getfor--gateway/--node, so a remote node is checked against its own roster, and an unavailable config fails closed before any write.User Impact
Every operator-supplied
--agentnow behaves the same way across the CLI. No filter semantics change; no valid invocation changes.Production LOC: +140/-35, net +105 across thirteen command boundaries.
Evidence
Both headline defects were reproduced against a real
pnpm builddist ofmainin an isolatedOPENCLAW_STATE_DIR+HOMEbefore any code was written, and the persisted approvals row was read back out of SQLite to confirm the write.Tests — all 11 touched suites, 256 passed + 1 pre-existing skip,
rc=0:exec-approvals-cli,hooks-cli.toggle,agent-via-gateway,backup-schedule,backup-sqlite,channels.resolve,export-trajectory,migrate/context,sandbox-explain,sessions-compact,sessions-lifecycle.New coverage asserts, per surface: unknown id exits nonzero; blank id exits nonzero; for
approvals, thatupdateExecApprovalsis never called, the snapshot'sagentsmap is unchanged, and noWriting local approvals.line is emitted; and that default, explicit*, and configured ids still work. Pre-fix, the newsandbox-explain(2) andexec-approvals(4) regressions failed as intended.node scripts/check-changed.mjs: all gates pass.$autoreview: clean, no accepted or actionable findings, correctness 0.98.