Skip to content

fix(audit): show valid values for rejected filters - #124336

Merged
steipete merged 3 commits into
mainfrom
steipete/audit-filter-validation
Aug 16, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/audit-filter-validation

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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, and AUDIT_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 --kind check 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 resolve uses 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 --direction and --status inputs make no Gateway request, and no audit failure in the repaired paths exposes GatewayClientRequestError, JSON-schema anyOf vocabulary, or the internal audit.activity.list method 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):

Command Before (eb13f5719f0) After (59960136c595)
audit --kind bogus Error: --kind must be agent_run, tool_action, or message. unchanged
audit --limit abc Error: --limit must be between 1 and 500. unchanged
audit --after bogus-timestamp Error: --after must be an ISO timestamp or Unix milliseconds. unchanged
audit --direction sideways GatewayClientRequestError: invalid audit.activity.list params: at /direction: must be equal to constant; at /direction: must match a schema in anyOf Error: --direction must be inbound or outbound.
audit --status bogus GatewayClientRequestError: invalid audit.activity.list params: at /status: must be equal to constant; at /status: must match a schema in anyOf Error: --status must be started, succeeded, failed, cancelled, timed_out, blocked, or unknown.
audit --cursor abc GatewayClientRequestError: invalid audit.activity.list range or cursor Error: --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 used tbx_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 Testbox tbx_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 Testbox tbx_01m042bt4jw3f779787kffn7fn (run 31919263128).
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted --stream-engine-output — clean; no accepted/actionable findings on the final error-rendering change.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes commands Command implementations labels Aug 16, 2026
@steipete
steipete marked this pull request as ready for review August 16, 2026 01:42
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 16, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 15, 2026, 9:48 PM ET / August 16, 2026, 01:48 UTC.

ClawSweeper review

What this changes

The 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 readiness

⚠️ Needs maintainer review before merge - 3 items remain

Keep 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
Reviewed head: 59960136c595214d307871661dcc72e757b3511b

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong primary-path evidence accompanies a focused patch, but a supported fallback path still misses the intended recovery behavior.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body includes an isolated built-product Testbox before/after CLI run showing improved primary-path error output; the remaining gap is legacy compatibility coverage, not absence of real behavior proof.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes an isolated built-product Testbox before/after CLI run showing improved primary-path error output; the remaining gap is legacy compatibility coverage, not absence of real behavior proof.
Evidence reviewed 5 items Legacy fallback remains unnormalized: The changed error branch normalizes only non-legacy failures; the supported unknown-method branch directly awaits the legacy audit.list call, so its rejection bypasses the new formatter.
Current Gateway exposes the legacy cursor error: Current main retains audit.list compatibility and returns an invalid-audit-list range-or-cursor error for a malformed cursor.
Existing tests establish both RPCs reject malformed cursors: Gateway coverage parametrizes malformed-cursor rejection across audit.list and audit.activity.list, while the PR's new CLI recovery test simulates only the activity method failing.
Findings 1 actionable finding [P2] Normalize legacy fallback cursor errors
Security None None.

How this fits together

The 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
Loading

Before merge

  • Normalize legacy fallback cursor errors (P2) - When an older Gateway rejects audit.activity.list, this branch falls back to audit.list at lines 223-226. A malformed cursor then rejects from that second call without formatAuditGatewayError, so the CLI still prints GatewayClientRequestError rather than the recovery text. Wrap or normalize the fallback failure too and cover it with a two-call regression test.
  • Resolve merge risk (P2) - On a supported older Gateway, an invalid cursor reaches the legacy audit.list fallback and still exposes the internal Gateway error instead of a recovery step.
  • Resolve merge risk (P1) - Production code is net +29 lines; the shared enum lists are justified, but the error flow should be consolidated across both RPC paths before accepting that growth.

Findings

  • [P2] Normalize legacy fallback cursor errors — src/commands/audit.ts:215-226
Agent review details

Security

None.

PR surface

Source +29, Tests +59. Total +88 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 62 33 +29
Tests 1 65 6 +59
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 127 39 +88

Review metrics

Metric Value Why it matters
Production versus regression-test delta production +62/-33 (net +29); tests +65/-6 (net +59) The shared protocol constants and CLI error handling add production surface; the added tests should cover both supported Gateway RPC paths.
Supported audit RPC paths 2 paths; 1 newly normalized The CLI supports activity and legacy audit methods, but the new cursor recovery assertion covers only the activity-method rejection.

Stored data model

Persistent data-model change detected: unknown-data-model-change: packages/gateway-protocol/src/schema/audit-activity.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Cover the legacy Gateway fallback (recommended)
    Map the legacy audit.list cursor rejection through the same operator-facing recovery path and add a focused fallback test before merge.
  2. Accept inconsistent upgrade behavior
    Land the primary-path improvement while knowingly leaving CLI-to-older-Gateway cursor failures with internal error text.

Technical review

Best 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:

  • [P2] Normalize legacy fallback cursor errors — src/commands/audit.ts:215-226
    When an older Gateway rejects audit.activity.list, this branch falls back to audit.list at lines 223-226. A malformed cursor then rejects from that second call without formatAuditGatewayError, so the CLI still prints GatewayClientRequestError rather than the recovery text. Wrap or normalize the fallback failure too and cover it with a two-call regression test.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d58e37815778.

Labels

Label changes:

  • add P2: The PR leaves a bounded but user-visible audit CLI recovery failure on the supported older-Gateway compatibility path.
  • add merge-risk: 🚨 compatibility: Existing users can update the CLI while retaining an older Gateway, which activates the unnormalized legacy audit fallback.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes an isolated built-product Testbox before/after CLI run showing improved primary-path error output; the remaining gap is legacy compatibility coverage, not absence of real behavior proof.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes an isolated built-product Testbox before/after CLI run showing improved primary-path error output; the remaining gap is legacy compatibility coverage, not absence of real behavior proof.

Label justifications:

  • P2: The PR leaves a bounded but user-visible audit CLI recovery failure on the supported older-Gateway compatibility path.
  • merge-risk: 🚨 compatibility: Existing users can update the CLI while retaining an older Gateway, which activates the unnormalized legacy audit fallback.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes an isolated built-product Testbox before/after CLI run showing improved primary-path error output; the remaining gap is legacy compatibility coverage, not absence of real behavior proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes an isolated built-product Testbox before/after CLI run showing improved primary-path error output; the remaining gap is legacy compatibility coverage, not absence of real behavior proof.

Evidence

What I checked:

  • Legacy fallback remains unnormalized: The changed error branch normalizes only non-legacy failures; the supported unknown-method branch directly awaits the legacy audit.list call, so its rejection bypasses the new formatter. (src/commands/audit.ts:215, 59960136c595)
  • Current Gateway exposes the legacy cursor error: Current main retains audit.list compatibility and returns an invalid-audit-list range-or-cursor error for a malformed cursor. (src/gateway/server-methods/audit.ts:75, d58e37815778)
  • Existing tests establish both RPCs reject malformed cursors: Gateway coverage parametrizes malformed-cursor rejection across audit.list and audit.activity.list, while the PR's new CLI recovery test simulates only the activity method failing. (src/gateway/server-methods/audit.test.ts:220, d58e37815778)
  • After-fix primary-path proof: The PR body supplies a Testbox built-product before/after comparison for invalid direction, status, and cursor inputs plus focused regression-test results; it does not demonstrate the legacy fallback rejection. (src/commands/audit.test.ts:332, 59960136c595)
  • Area provenance: Audit history shows Josh Avant authored the recent numeric-decision-cursor repair and execution inspection, while Peter Steinberger authored the metadata-only message-audit feature. (src/gateway/server-methods/audit.ts:75, 1b36f4265333)

Likely related people:

  • Josh Avant: Authored the recent numeric decision-cursor repair and the execution-inspection work in the audit Gateway path. (role: recent audit compatibility contributor; confidence: high; commits: 1b36f4265333, 618fba92bf01; files: src/gateway/server-methods/audit.ts, src/commands/audit.ts)
  • steipete: Current history attributes the metadata-only message-audit feature to Peter Steinberger, and this PR continues that audit CLI surface. (role: metadata-only audit feature contributor; confidence: medium; commits: 7a466b33f3ed, 59960136c595; files: packages/gateway-protocol/src/schema/audit-activity.ts, src/commands/audit.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Normalize the audit.list fallback cursor error and add a regression that simulates the old-Gateway two-call path.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 2585edb into main Aug 16, 2026
253 of 254 checks passed
@steipete
steipete deleted the steipete/audit-filter-validation branch August 16, 2026 01:53
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Aug 16, 2026
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.
steipete added a commit that referenced this pull request Aug 16, 2026
* 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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
* fix(audit): validate filter flags before gateway call

* refactor(audit): keep filter constants owner-local

* fix(audit): keep cursor errors operator-facing
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui cli CLI command changes commands Command implementations gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant