Skip to content

fix(gateway): trim audit.list exact-match filter ids - #110847

Merged
steipete merged 1 commit into
openclaw:mainfrom
nocodet888-arch:fix/gateway-audit-filter-trim
Aug 1, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
nocodet888-arch:fix/gateway-audit-filter-trim

Conversation

@nocodet888-arch

@nocodet888-arch nocodet888-arch commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

audit.list / audit.activity.list forwarded agentId, sessionKey, and
runId into exact store filters without trimming. A pasted filter like
" main " produced a successful empty page even when matching events existed.

Why This Change Was Made

Normalize those exact-match filters with normalizeOptionalString before
listAuditEvents, matching the same file's existing cursor .trim() behavior
and other gateway list filters.

User Impact

Before: Padded filter ids returned empty success results.

After: Leading/trailing whitespace is stripped so padded filters hit the
same rows as the canonical ids.

Evidence

  • Changed: src/gateway/server-methods/audit.ts,
    src/gateway/server-methods/audit.test.ts,
    src/gateway/server-methods/audit.trim.store.test.ts
  • Production path: gateway audit.list / audit.activity.list handlers →
    normalized filters → listAuditEvents
  • Compatibility: empty/whitespace-only filters still omit the field

Real behavior proof

Behavior or issue addressed

  1. Untrimmed store filters miss a planted row (agentId: " main " → empty).
  2. Production audit.list with the same padded filters returns the planted
    agent.run.finished event after handler-side trim.

Canonical reachability path

Real SQLite audit store (recordAuditEvent) → Gateway handler
auditHandlers["audit.list"] → normalizeOptionalString → listAuditEvents
(default OPENCLAW_STATE_DIR) → respond with matching events

Shared helper / provider constraint check

Reuses @openclaw/normalization-core/string-coerce normalizeOptionalString;
no new config/env.

Real environment tested

Local trusted checkout; temp OPENCLAW_STATE_DIR; real OpenClaw state SQLite
audit table (not a mocked listAuditEvents). Node via scripts/run-vitest.mjs.

Exact steps or command run after this patch

node scripts/run-vitest.mjs src/gateway/server-methods/audit.trim.store.test.ts --reporter=verbose

Evidence after fix

✓ returns the planted run for padded agentId/runId filters 331ms
 Test Files  1 passed (1)
      Tests  1 passed (1)

Negative control: listAuditEvents({ filters: { agentId: " main ", runId: " run-trim-1 " } })
returns []. After-fix handler call with the same padded params returns the
planted agentId: "main" / runId: "run-trim-1" event.

Observed result after fix

Padded audit filter ids resolve through the production gateway handler against
a real stored audit event.

What was not tested

Live multi-operator Gateway WebSocket session against a long-lived production
state DB. Proof uses the production handler + real SQLite store under an
isolated state dir.

Fix classification

bugfix — exact-match filter paste/padding miss

AI Assistance

AI-assisted implementation and proof.

Maintainer validation on current main

The sole original contributor commit was refreshed onto clean upstream main after the canonical PTY progress and legacy gateway-startup CI fixes landed. Refreshed exact head 8dd2e18dc03c23bf0608265cca9371e4e3f69e73 preserves @nocodet888-arch original authorship, authored timestamp, commit subject, and stable patch ID cb4cc62115731047916025980833023929e386c5.

Maintainer proof runs the actual authenticated production handleGatewayRequest dispatcher against a real isolated Kysely/SQLite audit ledger on both unpatched main and the contributor head:

  • audit.list: padded exact-match agent/session/run IDs return 0 before -> 1 after.
  • audit.activity.list: the same padded IDs return 0 before -> 1 after.
  • Main-agent and other-agent exact queries stay isolated; whitespace-only filters equal already-authorized unfiltered visibility.
  • Missing operator.read remains FORBIDDEN; node-role calls remain denied.
  • 17/17 focused handler/SQLite/protocol tests pass; targeted formatting and fresh Sol xhigh autoreview are clean.

Existing detailed proof: #110847 (comment)

Full hosted CI on this exact contributor head is required before landing.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Jul 18, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 10:36 AM ET / 14:36 UTC.

ClawSweeper review

What this changes

The PR trims whitespace from agentId, sessionKey, and runId before audit.list and audit.activity.list query the shared audit ledger.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This PR is still necessary: current main forwards padded identifier filters unchanged into exact SQLite predicates, while the proposed handler-boundary normalization fixes both audit query methods without changing stored data, protocol schemas, authorization, or canonical store semantics. The patch and its focused proof are strong; wait for the remaining hosted checks before merge.

Priority: P2
Reviewed head: 8dd2e18dc03c23bf0608265cca9371e4e3f69e73

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrowly scoped, source-proven repair with real SQLite/production-handler evidence and focused regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body and August 1, 2026 maintainer revalidation describe an after-fix authenticated production dispatch against a real isolated SQLite audit ledger, with both audit methods changing from zero matching rows before to one after.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body and August 1, 2026 maintainer revalidation describe an after-fix authenticated production dispatch against a real isolated SQLite audit ledger, with both audit methods changing from zero matching rows before to one after.
Evidence reviewed 6 items Current-main root cause: Current main copies truthy agentId, sessionKey, and runId values directly into the filter object, and the audit store applies each with an exact SQLite equality predicate; padded input therefore yields a successful empty page rather than the canonical matching event.
Proposed owner-boundary repair: The PR normalizes only the optional gateway request identifiers immediately before the two store calls. The shared helper trims strings and maps empty/whitespace-only input to undefined, preserving the existing omission behavior while leaving direct store callers exact-match.
Protocol compatibility: Both RPC schemas accept non-empty identifier strings but do not trim them. Keeping normalization in the gateway handler avoids a protocol contract change and covers both methods consistently.
Findings None None.
Security None None.

How this fits together

Gateway audit RPC methods validate an operator request, build exact-match filters, and query OpenClaw's shared SQLite audit ledger. The returned page is projected into legacy audit events or versioned activity events and sent back to the authorized gateway caller.

flowchart LR
  A[Operator audit request] --> B[Gateway validation and authorization]
  B --> C[Audit list handler]
  C --> D[Normalize optional identifier filters]
  D --> E[Exact SQLite audit query]
  E --> F[Audit event page]
  F --> G[Gateway response]
Loading

Before merge

  • Resolve merge risk (P1) - Required hosted checks are still in progress for the current contributor head; merge only after the exact-head required checks complete successfully.
  • Complete next step (P2) - No repair lane is needed: this active PR already contains the focused owner-boundary fix and real behavior proof; await the remaining required hosted checks and normal maintainer merge review.
Agent review details

Security

None.

PR surface

Source +7, Tests +107. Total +114 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 13 6 +7
Tests 2 107 0 +107
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 120 6 +114

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Merge the handler-boundary normalization after the remaining required hosted checks pass, retaining the audit store's exact-match contract for non-gateway callers.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Merge the handler-boundary normalization after the remaining required hosted checks pass, retaining the audit store's exact-match contract for non-gateway callers.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current main passes padded identifiers to exact SQLite equality predicates in src/gateway/server-methods/audit.ts:97 and src/audit/audit-event-store.ts:637; the PR also supplies a real isolated-store regression path. This read-only review did not execute the test.

Is this the best way to solve the issue?

Yes. Normalizing at the gateway request boundary is the narrowest maintainable fix: it matches existing cursor behavior, reuses the canonical helper, covers both RPC methods, and avoids weakening direct store exact-match semantics or changing the protocol.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded correctness repair for operator audit queries; affected requests return an empty successful result rather than the intended matching records.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body and August 1, 2026 maintainer revalidation describe an after-fix authenticated production dispatch against a real isolated SQLite audit ledger, with both audit methods changing from zero matching rows before to one after.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body and August 1, 2026 maintainer revalidation describe an after-fix authenticated production dispatch against a real isolated SQLite audit ledger, with both audit methods changing from zero matching rows before to one after.

Evidence

What I checked:

  • Current-main root cause: Current main copies truthy agentId, sessionKey, and runId values directly into the filter object, and the audit store applies each with an exact SQLite equality predicate; padded input therefore yields a successful empty page rather than the canonical matching event. (src/gateway/server-methods/audit.ts:97, 133a8a627429)
  • Proposed owner-boundary repair: The PR normalizes only the optional gateway request identifiers immediately before the two store calls. The shared helper trims strings and maps empty/whitespace-only input to undefined, preserving the existing omission behavior while leaving direct store callers exact-match. (src/gateway/server-methods/audit.ts:94, 8dd2e18dc03c)
  • Protocol compatibility: Both RPC schemas accept non-empty identifier strings but do not trim them. Keeping normalization in the gateway handler avoids a protocol contract change and covers both methods consistently. (packages/gateway-protocol/src/schema/audit-activity.ts:425, 133a8a627429)
  • Regression coverage: The PR adds a unit assertion for both gateway handlers and a real isolated SQLite-store test that first proves padded direct store filters miss the planted row, then verifies the production handler returns it after normalization. (src/gateway/server-methods/audit.trim.store.test.ts:49, 8dd2e18dc03c)
  • History and ownership: Available history identifies Peter Steinberger as the largest contributor to the audit handler/test path, including the message-audit expansion commit; Vincent Koc most recently touched the current handler lines through release-validation repair work. (src/gateway/server-methods/audit.ts:97, f5a8cb02ea0a)
  • Real behavior and release status: The PR body and Peter Steinberger's August 1, 2026 revalidation comment report authenticated production-dispatch testing against a real isolated SQLite ledger, including 0-before-to-1-after results for both methods and preserved authorization denials. The contributor commit is unmerged and current main still contains the defect, so it is not in a release. (src/gateway/server-methods/audit.trim.store.test.ts:27, 8dd2e18dc03c)

Likely related people:

  • steipete: Available history shows Peter Steinberger as the largest contributor to the affected audit handler/test path, including the audit activity expansion, and the PR discussion contains his detailed current-head revalidation. (role: primary area contributor and recent revalidator; confidence: high; commits: 7a466b33f3ed, f53346944db0; files: src/gateway/server-methods/audit.ts, src/gateway/server-methods/audit.test.ts)
  • Vincent Koc: Current handler lines blame to Vincent Koc's recent release-validation repair commit, making him a useful routing contact for the present main-tree state. (role: recent area contributor; confidence: medium; commits: f5a8cb02ea0a; files: src/gateway/server-methods/audit.ts)

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.

History

Review history (5 earlier review cycles)
  • reviewed 2026-07-18T17:19:09.601Z sha 8539ea20b7025f83dc19dba589fd2268da7f8801 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T17:37:00.576Z sha 0e985191ea8fe50186c67a2fdb12ff37adaae567 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T18:18:51.847Z sha 0e985191ea8fe50186c67a2fdb12ff37adaae567 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T08:04:05.187Z sha 0e985191ea8fe50186c67a2fdb12ff37adaae567 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T10:47:36.043Z sha 5000406ec461d5cf9a638131f26b2854a469b65d :: needs maintainer review before merge. :: none

@nocodet888-arch
nocodet888-arch force-pushed the fix/gateway-audit-filter-trim branch from 8539ea2 to 0e98519 Compare July 18, 2026 17:33
@nocodet888-arch

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated head + body with real SQLite audit-store proof (not mocked listAuditEvents):

  • plant an agent.run.finished row under a temp OPENCLAW_STATE_DIR
  • show untrimmed store filters miss (" main " → [])
  • production audit.list with the same padded filters returns the planted event

@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 18, 2026
@steipete
steipete force-pushed the fix/gateway-audit-filter-trim branch from 0e98519 to 5000406 Compare August 1, 2026 10:42
@steipete

steipete commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer end-to-end revalidation on the exact refreshed original contributor head 8dd2e18dc03c23bf0608265cca9371e4e3f69e73.

  • Original author @nocodet888-arch, authored timestamp, commit subject, sole contributor commit, and stable patch ID cb4cc62115731047916025980833023929e386c5 are preserved.
  • Verified the root cause on current main in both canonical Gateway handlers: padded agentId, sessionKey, and runId are forwarded unchanged into exact Kysely/SQLite filters, silently returning an empty successful result.
  • Executed the actual production handleGatewayRequest authorization/dispatch path against a real isolated SQLite audit ledger on both main and the exact contributor head:
    • audit.list: padded matching event 0 before -> 1 after.
    • audit.activity.list: padded matching event 0 before -> 1 after.
    • Canonical main-agent and other-agent filters each returned only their own exact event; no cross-agent result leakage.
    • Blank filters matched the same two events already visible to the authorized unfiltered request.
    • Missing operator.read remained FORBIDDEN and the node role remained denied for both RPC methods.
  • 17/17 focused Gateway handler, real SQLite store, and protocol-schema tests pass; targeted formatting and git diff --check pass; fresh gpt-5.6-sol xhigh structured review reports no findings.
  • This rebase inherits the canonical upstream built-CLI/verbose-reporter PTY and legacy gateway-sidecar CI repairs; no CI workaround or unrelated code was added to the contributor patch. Full exact-head hosted CI must pass before native landing.

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 1, 2026
@steipete
steipete force-pushed the fix/gateway-audit-filter-trim branch from 5000406 to 8dd2e18 Compare August 1, 2026 14:25
@steipete
steipete merged commit 5ad7c96 into openclaw:main Aug 1, 2026
125 checks passed
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

wingwkyuen pushed a commit to tcgoidc/openclaw that referenced this pull request Aug 1, 2026
…up-ownership-20260801

* origin/main:
  fix(gateway): trim audit.list exact-match filter ids (openclaw#110847)
  fix: harden plugin import-boundary guards and remove dead scanner (openclaw#117386)
  fix(ci): keep PTY tests observable and wait for completed turns (openclaw#117405)
  fix(plugins): resolve marketplace aliases without recursive cycles (openclaw#117440)
  fix: break command recovery import cycle (openclaw#116947)
  fix: clear offscreen command recovery
  fix: fence command recovery ownership
  fix: scope failed command recovery
  fix(plugins): fail closed on ambiguous uninstall targets (openclaw#117406)
pull Bot pushed a commit to mcx/moltbot that referenced this pull request Aug 1, 2026
* origin/main:
  fix(gateway): trim audit.list exact-match filter ids (openclaw#110847)
  fix: harden plugin import-boundary guards and remove dead scanner (openclaw#117386)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
…up-ownership-20260801

* origin/main:
  fix(gateway): trim audit.list exact-match filter ids (openclaw#110847)
  fix: harden plugin import-boundary guards and remove dead scanner (openclaw#117386)
  fix(ci): keep PTY tests observable and wait for completed turns (openclaw#117405)
  fix(plugins): resolve marketplace aliases without recursive cycles (openclaw#117440)
  fix: break command recovery import cycle (openclaw#116947)
  fix: clear offscreen command recovery
  fix: fence command recovery ownership
  fix: scope failed command recovery
  fix(plugins): fail closed on ambiguous uninstall targets (openclaw#117406)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* origin/main:
  fix(gateway): trim audit.list exact-match filter ids (openclaw#110847)
  fix: harden plugin import-boundary guards and remove dead scanner (openclaw#117386)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants