Skip to content

refactor(gateway): centralize device token denial responses - #148644

Merged
vincentkoc merged 2 commits into
mainfrom
refactor/device-token-denial-responses-20260914
Sep 15, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
refactor/device-token-denial-responses-20260914

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

This maintainer-requested refactor is part of the approved duplication and complexity reduction deliverable. Device-token rotation and revocation repeat the same denial response after logging and recording the security event. Each operation's existing denial helper now owns that complete sequence.

User Impact

No intended behavior change. Validation, ownership and role checks, awaited token-service calls, generic INVALID_REQUEST messages, and early returns stay in their original order. Pairing, successful token operations, invalidation, disconnection, and node-surface updates are unchanged.

Why This Change Was Made

Each helper performs the existing synchronous warning → trusted denied event → response sequence. Raw identifiers and optional scope details remain in warnings; events retain normalized roles and hashed identifiers. Existing Gateway response callbacks are arrow functions, so forwarding the same callback preserves their receiver behavior and authority checks.

Production: -33 lines. Tests: +108 lines. No schema, protocol, SDK or authorization-policy change.

Evidence

  • Full owner/lifecycle, authorization/security, token-service, response producer/callback, pairing sibling and real Gateway RPC test contracts were inspected. Six handler cases cover rotate/revoke × ownership, role and service denial, asserting precedence, warning/event/response ordering, service calls or exclusion, generic errors, event privacy and no success effects.
  • The earlier typed-lint fixture issue was corrected with the existing captured mock handle; assertions remain intact. Exact-head P2 review found no actionable issue in the complete corrected branch.
  • Fresh normal CI and Workflow Sanity passed on cfa4705ee203d1c719b68157f04c336d7f22ffe5: 122 successful jobs and 17 planned skips. Selected lint, types, dependencies, guards, build and pinned formatting passed.
  • Actual lifecycle execution passed all 34 cases, including all six denial cases. Tested merge 2077dbe62118c84856c849ccf5935d4626ad3e25 contains the exact reviewed two-file postimages.
  • The original run failed in an inherited Cron test that checked state after invocation count increased but before outcome finalization. That failure remains recorded. The separate test synchronization repair #148749 landed before the fresh tested merge; its Cron shard passed all 27 cases, including the previously failing second-error case. No Cron changes were folded into this branch.
  • The latest exact-head ClawSweeper review has no actionable finding, Before merge item or Rank-up move.

These are handler fixtures with mocked token services and real diagnostic-event dispatch. No live Gateway RPC result is claimed.

@vincentkoc vincentkoc self-assigned this Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@vincentkoc
vincentkoc marked this pull request as ready for review September 15, 2026 00:22
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Sep 15, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 15, 2026, 12:38 AM ET / 04:38 UTC (Revision 3).

ClawSweeper review

What this changes

Centralizes device-token denial logging, security events, and error replies in the existing rotation and revocation helpers, adding coverage for six denial paths.

Merge readiness

✅ Ready for maintainer review

This maintainer-requested cleanup remains useful and is absent from current main. No actionable introduced defect was found; the reported lint correction preserves the assertion.

Priority: P3
Reviewed head: cfa4705ee203d1c719b68157f04c336d7f22ffe5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving cleanup with useful handler coverage and no actionable finding; execution validation remains with normal CI.
Proof confidence 🌊 off-meta tidepool Not applicable: The MEMBER-authored refactor moves synchronous denial presentation without materially changing authority; the external-contributor proof gate does not apply, and no live Gateway execution is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored refactor moves synchronous denial presentation without materially changing authority; the external-contributor proof gate does not apply, and no live Gateway execution is claimed.
Evidence reviewed 9 items Introduced production change: The pinned merge-base-to-head diff moves the same warning, security-event emission, and response into existing operation helpers. All six denial branches retain their original guards, service-call positions, arguments, and early returns.
Current main still contains the duplication: Fetched main retains separate event and response sequences after the logging helpers in rotation and revocation denial branches.
Latest release check: The supplied latest release, v2026.9.4, also retains the old logging helpers; no released implementation of this refactor was established.
Findings None None.
Security None None.

How this fits together

Gateway device-management handlers receive authenticated token rotation and revocation requests. Authorization checks and the token service decide whether an operation proceeds; denied requests produce a warning, a sanitized security event, and a generic error reply.

flowchart TD
  A[Authenticated device request] --> B[Ownership and role checks]
  B -->|Allowed| C[Token service]
  B -->|Denied| D[Operation denial helper]
  C -->|Denied| D
  C -->|Succeeded| E[Existing success handling]
  D --> F[Warning and sanitized event]
  F --> G[Generic error reply]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -33, Tests +108. Total +75 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 53 86 -33
Tests 1 108 0 +108
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 161 86 +75

Review metrics

None.

Technical review

Best possible solution:

Keep denial presentation centralized while leaving authorization, token persistence, and response authority with their existing owners.

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

Not applicable: this is a behavior-preserving refactor, and no introduced failure was identified through source review.

Is this the best way to solve the issue?

Yes. Extending the existing operation helpers removes repetition without adding a parallel authorization or response owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3f10235f1a28.

Labels

Label justifications:

  • P3: This is a bounded internal cleanup that preserves existing device-token behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The MEMBER-authored refactor moves synchronous denial presentation without materially changing authority; the external-contributor proof gate does not apply, and no live Gateway execution is claimed.

Evidence

What I checked:

  • Introduced production change: The pinned merge-base-to-head diff moves the same warning, security-event emission, and response into existing operation helpers. All six denial branches retain their original guards, service-call positions, arguments, and early returns. (src/gateway/server-methods/devices.ts:79, cfa4705ee203)
  • Current main still contains the duplication: Fetched main retains separate event and response sequences after the logging helpers in rotation and revocation denial branches. (src/gateway/server-methods/devices.ts:563, 3f10235f1a28)
  • Latest release check: The supplied latest release, v2026.9.4, also retains the old logging helpers; no released implementation of this refactor was established. (src/gateway/server-methods/devices.ts:79, 3a9d69db306c)
  • Response authority remains with the dispatcher: The dispatcher supplies an arrow-function response closure that retains runtime and client-authority checks. Passing that same closure through a synchronous helper does not introduce stored authority or bypass the final response checks. (src/gateway/server/ws-connection/authenticated-request-dispatch.ts:219, cfa4705ee203)
  • Handler coverage and prior correction: The six added cases exercise registered handlers and check denial precedence, ordering, generic errors, trusted-event privacy, and absence of lifecycle effects. The latest commit captures the node-registry spy before invocation and retains the no-call assertion. The supplied prior completed review had no findings. Tests were inspected, not executed. (src/gateway/server-methods/devices.lifecycle.test.ts:33, cfa4705ee203)
  • Dependency-contract signal: The added test uses vi.spyOn, and the PR explicitly claims it preserves the fixture's existing mock history. The fixture creates updateSurface with vi.fn(), and package.json pins Vitest 5.0.0, establishing the relevant dependency contract. (src/gateway/server-methods/devices.test-support.ts:115, cfa4705ee203)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (2 earlier review cycles)
  • reviewed 2026-09-15T00:29:04.381Z sha 708f1d1 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T03:14:35.640Z sha cfa4705 :: needs maintainer review before merge. :: none

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head cfa4705ee203d1c719b68157f04c336d7f22ffe5; the CI unbound-method finding is corrected without weakening the assertion.

@clawsweeper

clawsweeper Bot commented Sep 15, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc vincentkoc closed this Sep 15, 2026
@vincentkoc vincentkoc reopened this Sep 15, 2026
@vincentkoc
vincentkoc merged commit 011fb77 into main Sep 15, 2026
383 of 385 checks passed
@vincentkoc
vincentkoc deleted the refactor/device-token-denial-responses-20260914 branch September 15, 2026 08:24
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 15, 2026
* commit '0cd944c01416c4f9c1f6dc9d1dea9670c5b99cab':
  improve: speed up session search for restricted operators (#148826)
  fix(update): avoid retry guidance for historical abandoned runs (#146982)
  fix(android): reduce queued-message send overhead (#148899)
  refactor(slack): count table cells only for native output (#148872)
  fix: correct update status and apply saved model keys (#148830)
  refactor(nostr): share doctor state migration flow (#148647)
  refactor(gateway): centralize device token denial responses (#148644)
  test: make kitchen sink assertions runtime portable (#148891)
  refactor(agents): share preferred block chunk boundaries (#148391)
  fix(ui): use the selected timezone for Usage date shortcuts (#148277)
  test: probe active Node in release preflight (#148892)
  fix(test): restore services typecheck shard headroom (#148889)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
…#148644)

* refactor(gateway): centralize device token denial responses

* test(gateway): retain the device registry mock handle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

1 participant