Skip to content

refactor(gateway): consolidate pairing approval ownership - #129744

Merged
steipete merged 1 commit into
mainfrom
steipete/pairing-approval-consolidation
Aug 26, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/pairing-approval-consolidation

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Follow-up cleanup to #129563. The pairing authorization surface carried three coherence debts:

  1. Split ownership of the trusted-proxy grant decision: resolvePairingApprovalPlan decided auto-approval eligibility while requirePairing separately re-read the trustedProxy config, re-trimmed the verified user, and computed the capped grant — two readers of one config, and the decision "may we auto-approve, and for what" lived in two files.
  2. Three hand-rolled copies of the same handshake-failure shape (setHandshakeState("failed") → optional setCloseCause → send NOT_PAIRED → close(1008, …)) inside authorizeGatewayConnectDevice.
  3. A dead pre-computation and a condition pyramid in connect-existing-device's bootstrap-retry block (operator scopes computed before the handoff-client check that gates their only use).

Why This Change Was Made

Behavior-neutral consolidation, one owner per decision:

  • The approval plan now returns trustedProxyAutoApproveScopes (the capped grant, null when ineligible) and trustedProxyUser; requirePairing's fast path and inline-approval lane consume them. The allowTrustedProxyDeviceAutoApproval flag and the resolveTrustedProxyDeviceAutoApproveScopes export are gone — eligibility without an amount no longer exists as a concept. The connection scope cap is injected as a closure so the plan module stays free of HTTP types.
  • One failPairingHandshake helper replaces the three failure blocks, preserving exact operation order and per-site behavior (the two simple sites still record no close cause).
  • The bootstrap-retry block merges its nested guards into the flat gather→decide shape and computes scopes only where used.

No behavior change: identical grants, store writes, broadcast ordering, audit/log lines, close codes/reasons, and error details. The #129563 invariant (live paired-row reread as the last await before the fast-path decision) is preserved verbatim.

User Impact

None — internal refactor. Production LOC −20 (+100/−120), tests unchanged.

Evidence

  • pnpm test src/gateway/server.auth.trusted-proxy-device-autoapprove.test.ts (13 passed, incl. the fix(gateway): stop fabricating scope-upgrade requests on trusted-proxy reconnects #129563 regression), server.auth.control-ui.test.ts (40), server-methods/device-scope-upgrade.test.ts (4), server.device-pair-approve-authz.test.ts (8).
  • node scripts/check-changed.mjs clean (typecheck/lint/guards).
  • Fresh Codex autoreview clean.
  • Behavior-neutral bounded refactor: focused suites + changed gates per validation policy; no issue/live proof required.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 26, 2026 01:35
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 26, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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 Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 10:22 PM ET / August 26, 2026, 02:22 UTC.

ClawSweeper review

What this changes

The PR centralizes trusted-proxy auto-approval scope calculation in the pairing approval plan, shares pairing-failure handling, and flattens bootstrap retry logic.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No concrete patch defect found. Keep this protected maintainer-authored gateway authorization refactor open until exact-head checks complete.

Priority: P3
Reviewed head: fa0f7dc46f5c618df4a4151b98d9031ec476fbbf

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative refactor with no source-level defect found, pending exact-head validation of its security-sensitive boundary.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor proof gate; its cited Gateway harness tests remain the relevant merge validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor proof gate; its cited Gateway harness tests remain the relevant merge validation.
Evidence reviewed 6 items Approval-owner consolidation: The approval plan now derives the verified proxy user and capped auto-approval scopes from the trusted-proxy configuration; the caller consumes that single result.
Live authorization fence retained: The fast path still rereads the paired device as its last await and validates key, role, and capped scopes before returning a narrowed session.
Approval callee enforces the grant: The pairing approval owner reloads state under its lock and rejects caller scopes that do not cover the resulting operator token scopes.
Findings None None.
Security None None.

Live Verification

Command: pnpm test src/gateway/server.auth.trusted-proxy-device-autoapprove.test.ts

Result: FAIL (failed) — step 1 run pnpm test src/gateway/server.auth.trusted-proxy-device-autoapprove.test.ts: previous terminal command was still running after 30 seconds: "pnpm test src/gateway/server.auth.trusted-proxy-device-autoapprove.test.ts"

$ node --import tsx scripts/test-projects.mts src/gateway/server.auth.trusted-proxy-device-autoapprove.test.ts
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129744-pBCIOI/target

Assertions:

  • FAIL expect_output: passed

How this fits together

Gateway device connections enter pairing authorization before a session is granted or a pairing request is created. Trusted-proxy identity, configured scopes, and the live paired-device row determine whether a reconnect is narrowed or requires approval.

flowchart LR
  A[Device connection] --> B[Gateway pairing authorization]
  B --> C[Pairing approval plan]
  C --> D{Trusted proxy and paired row}
  D -->|Eligible| E[Narrowed session grant]
  D -->|Not eligible| F[Pairing request]
  F --> G[Handshake response]
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head CI is still incomplete; merging before it finishes would leave a security-sensitive authorization refactor without its required focused gateway validation.
  • Complete next step (P2) - No mechanical repair is indicated; wait for exact-head CI on the protected pairing authorization boundary.
Agent review details

Security

None.

PR surface

Source -20. Total -20 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 3 100 120 -20
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 100 120 -20

Review metrics

Metric Value Why it matters
Production versus test LOC production −20; tests unchanged The three-file refactor removes duplicated authorization and failure-path logic without growing production or test surface.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/gateway/server/ws-connection/connect-existing-device.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete exact-head authorization validation (recommended)
    Wait for the focused Gateway checks to validate the preserved live-row authorization fence before merge.

Technical review

Best possible solution:

Retain the single approval-plan owner and land only after exact-head Gateway checks confirm same-key narrowing, foreign-key rejection, and the live paired-row fence.

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

Not applicable: this PR is a behavior-neutral refactor rather than a report of a new defect; existing Gateway tests exercise the preserved authorization behavior.

Is this the best way to solve the issue?

Yes. Moving the complete trusted-proxy grant result into the approval-plan owner removes duplicate policy reads while retaining the consumer’s live paired-row check before a session is granted.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This is a focused internal cleanup with no claimed user-visible behavior change.
  • merge-risk: 🚨 security-boundary: The diff relocates trusted-proxy scope grants and verified-user data within Gateway pairing authorization.
  • 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: This maintainer-authored internal refactor is exempt from the external-contributor proof gate; its cited Gateway harness tests remain the relevant merge validation.

Evidence

What I checked:

Likely related people:

  • steipete: Current and preceding merged pairing authorization work, including the live-row fence, are authored by Peter Steinberger under this GitHub handle. (role: feature owner and recent area contributor; confidence: high; commits: fa0f7dc46f5c, 91cc37b788cd, 551c65e49010; files: src/gateway/server/ws-connection/connect-device-pairing.ts, src/gateway/server/ws-connection/connect-pairing-approval-plan.ts, src/gateway/server/ws-connection/connect-existing-device.ts)

Rank-up moves

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

  • Let the exact-head focused Gateway checks complete before merge.

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 (1 earlier review cycle)
  • reviewed 2026-08-26T01:41:06.691Z sha e63917e :: needs maintainer review before merge. :: none

The approval plan now owns the whole trusted-proxy auto-approval
decision — eligibility and the capped grant — returning
trustedProxyAutoApproveScopes/trustedProxyUser instead of a bare flag
that requirePairing re-derived from config. One failPairingHandshake
helper replaces three hand-rolled failure blocks, and the bootstrap
retry block in connect-existing-device flattens its guard pyramid and
computes scopes only where used. Behavior-neutral; net -20 production
LOC.
@steipete
steipete force-pushed the steipete/pairing-approval-consolidation branch from e63917e to fa0f7dc Compare August 26, 2026 02:16
@steipete
steipete merged commit 3caf21b into main Aug 26, 2026
196 checks passed
@steipete
steipete deleted the steipete/pairing-approval-consolidation branch August 26, 2026 02:39
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
…29744)

The approval plan now owns the whole trusted-proxy auto-approval
decision — eligibility and the capped grant — returning
trustedProxyAutoApproveScopes/trustedProxyUser instead of a bare flag
that requirePairing re-derived from config. One failPairingHandshake
helper replaces three hand-rolled failure blocks, and the bootstrap
retry block in connect-existing-device flattens its guard pyramid and
computes scopes only where used. Behavior-neutral; net -20 production
LOC.
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 merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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