Repository navigation
fix(audit): blank --agent silently returns every agent's audit records - #193704
wangmiao0668000666 wants to merge 1 commit into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesReject explicitly blank audit selectors and cursors before they can silently become omitted query filters. Example: Run
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR: it fixes a current audit-query bug with a focused change, and no actionable correctness or security findings remain. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe audit CLI maps operator flags into bounded Gateway queries, which read retained audit metadata and return text or JSON pages. flowchart LR
A[Operator flags] --> B[Audit CLI registration]
B --> C[Audit command validation]
C --> D[Gateway audit RPC]
D --> E[Audit ledger]
E --> F[Text or JSON page]
Technical reviewBest possible solution: Retain this focused validation at the existing audit command owner and proceed through the normal landing workflow. Do we have a high-confidence way to reproduce the issue? The current-main truthy parameter construction establishes the failure directly, and the contributor supplies a pinned built-CLI reproduction with a real Gateway record; this review executed no target code. Is this the best way to solve the issue? Yes: explicit blank input must fail before normalization can erase it, and the smallest complete fix is the proposed loop at auditListCommand with regression coverage in its existing suite. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3543fda490ec. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +13, Tests +6, Other +2. Total +21 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 5, 2026, 3:04 PM ET / 20:04 UTC. |
daba319 to
6dbf612
Compare
|
Closing to free PR quota; audit blank-filter fix is superseded in priority by the same-blank-input family already landed (#198965). Branch + commits retained for revival when maintainer picks up the audit blank-input area. |
What Problem This Solves
openclaw audit --agent ""(or--agent "$AGENT"where the variable is empty) exits 0 and returns every agent's audit records — byte-identical to runningopenclaw auditwith no filter at all. The same command with--agent nonexistentcorrectly returns an empty page, so an explicitly passed empty value is silently treated as "flag not provided" while any non-empty value is honored.--session,--run,--execution,--channel, and--cursorbehave the same way: the blank filter is dropped before the query is built.The
--executioncase is the sharpest:openclaw audit --execution xyzfails with--execution requires --explain., butopenclaw audit --execution ""succeeds and lists activity — a blank value silently bypasses a validation that a non-blank value triggers.Root cause:
auditListCommandbuildsAuditActivityListParamswith truthy spreads (...(options.agentId ? { agentId: options.agentId } : {})and the same forsessionKey,runId,executionId,channel,cursor), so""never reaches the Gateway as a filter. The same function already rejects blank--after/--before/--kind/--status/--direction(bounds added in #137335), so the free-string filters are the inconsistent half.User Impact
User impact: an operator who scopes an audit query with an empty variable now gets
--agent must not be blankand exit 1 instead of a successful report that silently widens the query to all agents, sessions, runs, and channels — before any Gateway call is made. Non-empty values, omitted flags, and every otherauditpath behave exactly as before.Why This Change Was Made
Adds a 13-line guard at the top of
auditListCommandthat mirrors the repository's existingagentCliCommandloop insrc/commands/agent-via-gateway.ts(["--agent", opts.agent], … → ${flag} must not be blank), covering the six free-string list filters. It runs before the--explainbranch and beforeparamsis constructed, so a present blank filter can never be normalized away.Not introducing: no new error type, no config validation, no Gateway/protocol change, no new owner or export, no schema/API change. The
--limitblank path keeps its existing1 and 500rejection, and--kind/--status/--direction/--after/--beforekeep their existing validators — this change only closes the free-string half of the same contract.Evidence
Base
37706a74a81129f8ec85289399a2703abf98c2b4(branch base =origin/mainat branch creation) → Candidatedaba319ff1d884e144c71126b57548e85023e341(branchfix/audit-blank-filters).Environment: Linux x64, Node v24.22.1, normally built
openclaw.mjs(OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build:docker), isolatedOPENCLAW_HOME+OPENCLAW_STATE_DIR+ isolatedHOME, and a dedicated isolated Gateway started by this proof (openclaw gateway run --port 18999 --allow-unconfigured) soaudithas something to query. The isolated ledger contains exactly one real record, written by the Gateway itself:That record makes the byte-identity comparisons non-trivial: a dropped filter has to return it, and an honored filter has to hide it. Every case below was run twice and compared with
cmp(exit code + stdout + stderr), not by eye.Shipped CLI (each leg run at least twice)
audit(no filter) ×2audit --agent ""×2audit— the blank filter is dropped andmain's record is returned although a specific agent was requested--agent must not be blankaudit --agent nonexistent×2audit --execution ""×2--explainrule)--execution must not be blankaudit --execution xyz×2--execution requires --explain.audit --cursor ""×2audit(blank cursor dropped)--cursor must not be blankaudit --session ""(candidate spot check) ×2--session must not be blankThe decisive pair: on base,
audit --agent ""returns the record andaudit --agent nonexistentdoes not — the same query with an empty value is wider than the query with an explicit non-existent value.Regression RED → GREEN (remote, real vitest)
Remote proof host (Docker
lexiflow-all:latest, Nodev24.22.1,OPENCLAW_VITEST_RUNTIME=node);src/commands/audit.tsandsrc/commands/audit.test.tsverified md5-identical togit show origin/main:<path>before the RED run:6 failed | 25 passed (31). The six failures are exactly the new cases —rejects invalid --agent / --session / --run / --execution / --channel / --cursor before calling the Gateway— each withAssertionError: promise resolved "undefined" instead of rejectingatsrc/commands/audit.test.ts:76.31 passed (31).src/gateway/server-methods/audit.test.ts(root matrix) →1 passed (1)file,17 passed (17).auditListCommand's only production caller issrc/cli/program/register.audit.ts, which has no dedicated test file, and no other test file importsauditListCommand(grep overorigin/main).Local gates
Line counts
Whole-PR delta: production +13/-0 (1 file), tests +6/-0 (1 file),
config/test-lines-allocations/audit-blank-filters.txt= 6 for exactly this PR's net test growth. Shared scalarconfig/test-lines-baseline.txtuntouched. On a clean37706a74a81the ratchet reportsTest lines OK: 6496704; ceiling: 6496746; slack: 42, so this branch stays inside the ceiling with the allocation applied.Negative claims
--limit ""(already rejected by the existing1 and 500bound),--kind/--status/--direction/--after/--before(already validated by fix(cli): reject blank audit bounds #137335 and untouched here).agent_runformain, so the widening is proven against that single record, not against multi-tenant data.audit --explainbehavior for blank selectors beyond the guard itself; the guard runs before that branch, but the proof exercises the activity-list path.Focused Checks and Simplification
agentCliCommandprecedent — no helper, no wrapper, no new export.audit.test.ts) by extending the existingrejects invalid $flag before calling the Gatewayit.each, so the new cases reuse the existingcallGateway-not-called assertion instead of adding a new harness.Compatibility and Merge Risk
Two-way door: reverting restores the previous silent fallback without migrations or persisted state changes. Blast radius is
auditListCommand's validation of six free-string filters; the guard runs before any option is consumed and beforecallGateway, so no Gateway request,--explainbranch, or output path changes for non-blank input. Unchanged adjacent behavior: omitted flags, non-empty valid values, non-empty unknown values (still an empty page),--limit, all enum/timestamp filters,--json, and every non-auditcommand.Collision check (run against
origin/mainminutes before opening): the only open PR that touches these two files is #141004 (feat(audit): record observed runtime skill usage, different purpose). Itssrc/commands/audit.tshunks sit at lines 63–234 (record type, row rendering, filter helpers, legacy-param mapping) and never reachauditListCommandat line 506, so this PR's guard does not overlap them. Insrc/commands/audit.test.tsboth PRs append cases to the samerejects invalid $flag before calling the Gatewayit.eacharray — adjacent-line additions that resolve trivially on rebase, with no shared semantic change. Every other candidate from the per-filegh api pulls/<n>/filessweep (#181303, #193525, #191070, #184328) is unrelated to blank filters, and merged #137335 covered only the timestamp/enum bounds.