Repository navigation
fix(audit): show valid values for rejected filters - #124336
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: found issues before merge. Reviewed August 15, 2026, 9:48 PM ET / August 16, 2026, 01:48 UTC. ClawSweeper reviewWhat this changesThe PR centralizes audit filter values in the Gateway protocol, validates status and direction locally in the CLI, and makes rejected audit requests more operator-facing. Merge readinessKeep open: the new cursor recovery text does not cover the supported legacy Gateway fallback, so some operators still receive the internal error the PR intends to replace. Priority: P2 Review scores
Verification
How this fits togetherThe audit CLI sends bounded activity queries to the Gateway and falls back to the older audit RPC when a connected Gateway lacks the newer activity method. It turns Gateway responses into terminal output for operators. flowchart LR
A[Operator audit command] --> B[CLI filter validation]
B --> C[Current activity Gateway method]
C --> D[Operator-facing result or error]
C --> E[Older Gateway detected]
E --> F[Legacy audit method]
F --> D
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +29, Tests +59. Total +88 across 4 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Normalize invalid-cursor failures from both activity and legacy audit RPCs into one recovery message, with a focused fallback regression test. Do we have a high-confidence way to reproduce the issue? Yes—source establishes the path: an old Gateway rejects audit.activity.list, the CLI falls back to audit.list, and a malformed cursor is rejected there without the new formatter. It was not executed because this was a read-only review. Is this the best way to solve the issue? No—the shared filter values and local validation are sound, but the same cursor recovery must apply after the legacy fallback call to complete the existing compatibility contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d58e37815778. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
PR #124336 landed audit's gateway-error rendering while this branch was in flight, so its two new assertions were written against the prefixed output. The canonical formatter no longer emits the generic Error: prefix, so the expected strings are updated to match.
* fix(gateway): drop internal error class names from operator output * test(cli): drop stale Error: prefixes from capability expectations * test(cli): align invalid-port output with canonical formatting * fix(errors): preserve primary structured codes * style(cli): format invalid-port expectation * test(cli): align shared error rendering expectations * fix(gateway): scope error code rendering to agent failures * test(errors): redact opt-in structured codes * refactor(errors): keep canonical formatter callback-safe * test(audit): drop stale Error: prefixes after formatter cleanup PR #124336 landed audit's gateway-error rendering while this branch was in flight, so its two new assertions were written against the prefixed output. The canonical formatter no longer emits the generic Error: prefix, so the expected strings are updated to match.
* fix(audit): validate filter flags before gateway call * refactor(audit): keep filter constants owner-local * fix(audit): keep cursor errors operator-facing
…24329) * fix(gateway): drop internal error class names from operator output * test(cli): drop stale Error: prefixes from capability expectations * test(cli): align invalid-port output with canonical formatting * fix(errors): preserve primary structured codes * style(cli): format invalid-port expectation * test(cli): align shared error rendering expectations * fix(gateway): scope error code rendering to agent failures * test(errors): redact opt-in structured codes * refactor(errors): keep canonical formatter callback-safe * test(audit): drop stale Error: prefixes after formatter cleanup PR openclaw#124336 landed audit's gateway-error rendering while this branch was in flight, so its two new assertions were written against the prefixed output. The canonical formatter no longer emits the generic Error: prefix, so the expected strings are updated to match.
What Problem This Solves
Fixes an issue where operators using
openclaw audit --direction,--status, or an invalid continuation cursor received Gateway class names and JSON-schema/protocol vocabulary instead of an explanation of their input mistake and what to try next.AI-assisted; the implementation and proof were reviewed by the author.
Why This Change Was Made
The filter values now have one runtime source of truth in
packages/gateway-protocol/src/schema/audit-activity.ts:AUDIT_ACTIVITY_KINDS,AUDIT_ACTIVITY_STATUSES, andAUDIT_ACTIVITY_DIRECTIONS. The protocol schemas and TypeScript filter types derive from those arrays, while the CLI derives its validation, error text, and help text from the same values. This also replaces the old hard-coded--kindcheck with the shared path.Invalid closed-enum values are rejected before any RPC, so an older Gateway cannot obscure a bad local value with a capability error. Gateway-originated audit failures are normalized through
formatErrorMessage, removing JavaScript class-name prefixes.The activity cursor remains opaque to the client. Although the current Gateway issues numeric sequence cursors, locally enforcing that implementation detail would reject future valid tokens. The CLI therefore forwards cursors unchanged and translates the Gateway's exact invalid-cursor response into:
--cursor must be a continuation token returned by a previous audit result.Sibling sweep:
channels resolveuses Commander choices, fleet enum flags use argument parsers, and cron failure-alert mode validates locally. Task/task-flow status, runtime, severity, and code filters are local-store filters rather than Gateway RPC schema surfaces. No other bounded enum-shaped Gateway leak in this CLI neighborhood needed the same repair.User Impact
Operators now get actionable, consistent errors naming every valid filter value. Invalid
--directionand--statusinputs make no Gateway request, and no audit failure in the repaired paths exposesGatewayClientRequestError, JSON-schemaanyOfvocabulary, or the internalaudit.activity.listmethod name.Production LOC: +61/-32 (net +29) | Tests: +65/-6 (net +59). The production growth is the canonical protocol value lists plus the CLI owner-boundary validation/error normalization; duplicated filter literals were removed from schemas, types, validation, and help.
Evidence
Built-product comparison using profile
r13,OPENCLAW_STATE_DIR=$(mktemp -d),OPENCLAW_SKIP_CHANNELS=1, and an isolated loopback Gateway (ports 19438/19440; never 18789):eb13f5719f0)59960136c595)audit --kind bogusError: --kind must be agent_run, tool_action, or message.audit --limit abcError: --limit must be between 1 and 500.audit --after bogus-timestampError: --after must be an ISO timestamp or Unix milliseconds.audit --direction sidewaysGatewayClientRequestError: invalid audit.activity.list params: at /direction: must be equal to constant; at /direction: must match a schema in anyOfError: --direction must be inbound or outbound.audit --status bogusGatewayClientRequestError: invalid audit.activity.list params: at /status: must be equal to constant; at /status: must match a schema in anyOfError: --status must be started, succeeded, failed, cancelled, timed_out, blocked, or unknown.audit --cursor abcGatewayClientRequestError: invalid audit.activity.list range or cursorError: --cursor must be a continuation token returned by a previous audit result.All six commands exited 1. The before proof used Testbox
tbx_01m0416hr1799nx8d3q98rsdtf(run 31918470632); the final build and after proof usedtbx_01m043emf6wwev4rdxk8zkd2hz(run 31919987512). Both scratch directories and Gateway processes were removed by the proof command.Regression provenance was demonstrated by running the new audit suite with only pre-fix
src/commands/audit.ts: 4 expected failures (invalid direction/status reached the Gateway mock, the class prefix remained, and cursor recovery text was absent). After the repair:node scripts/run-vitest.mjs src/commands/audit.test.ts packages/gateway-protocol/src/schema/audit.test.ts— 35 tests passed on Testboxtbx_01m0428p7dfe0avh8kr1ab119a(run 31919199242).node scripts/check-changed.mjs— all core production/test typechecks, lint, format, dead-export, dependency, boundary, cycle, and repository guards passed on Testboxtbx_01m042bt4jw3f779787kffn7fn(run 31919263128)..agents/skills/autoreview/scripts/autoreview --mode uncommitted --stream-engine-output— clean; no accepted/actionable findings on the final error-rendering change.