Repository navigation
refactor(gateway): consolidate pairing approval ownership - #129744
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 10:22 PM ET / August 26, 2026, 02:22 UTC. ClawSweeper reviewWhat this changesThe PR centralizes trusted-proxy auto-approval scope calculation in the pairing approval plan, shares pairing-failure handling, and flattens bootstrap retry logic. Merge readinessNo concrete patch defect found. Keep this protected maintainer-authored gateway authorization refactor open until exact-head checks complete. Priority: P3 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — step 1 Assertions:
How this fits togetherGateway 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -20. Total -20 across 3 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel 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
HistoryReview history (1 earlier review cycle)
|
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.
e63917e to
fa0f7dc
Compare
|
Merged via squash.
|
…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.
What Problem This Solves
Follow-up cleanup to #129563. The pairing authorization surface carried three coherence debts:
resolvePairingApprovalPlandecided auto-approval eligibility whilerequirePairingseparately 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.setHandshakeState("failed")→ optionalsetCloseCause→ send NOT_PAIRED →close(1008, …)) insideauthorizeGatewayConnectDevice.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:
trustedProxyAutoApproveScopes(the capped grant,nullwhen ineligible) andtrustedProxyUser;requirePairing's fast path and inline-approval lane consume them. TheallowTrustedProxyDeviceAutoApprovalflag and theresolveTrustedProxyDeviceAutoApproveScopesexport 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.failPairingHandshakehelper replaces the three failure blocks, preserving exact operation order and per-site behavior (the two simple sites still record no close cause).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.mjsclean (typecheck/lint/guards).