Skip to content

feat(gateway): await native upgrade headers before connecting - #147070

Merged
vincentkoc merged 11 commits into
mainfrom
feat/shared-gateway-ingress-20260913
Sep 24, 2026
Merged

vincentkoc merged 11 commits into
mainfrom
feat/shared-gateway-ingress-20260913

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Native Gateway connections need to await authorization before opening a WebSocket. A route retired during that wait must never open a socket with its prepared headers.

User Impact

Shared Apple transport accepts asynchronous, throwing upgrade-header providers and preserves typed authorization failures. Existing synchronous callers remain valid. This prerequisite does not activate Cloudflare Access, change pairing or saved credentials, or change desktop production callers.

Why This Change Was Made

The channel owns socket creation; the native session owns route retirement. Retirement now closes a synchronous admission gate before detaching the channel, and socket creation plus resume occur under that same gate. Queued asynchronous shutdown can finish afterward without leaving a window for a retired route to open a socket. Ordinary reconnects retain admission; a replacement route gets a new channel.

A temporary provider failure before socket creation also retains the existing reconnect retry owner. Once a replacement socket is admitted, its generation owns subsequent retries. This resolves the retirement and reconnect findings without adding another retry policy. The macOS change is test-only. Browser sign-in, reauthentication, and installed-app upgrade proof remain in the downstream iOS app stack.

Evidence

Candidate: e246f5b798f626d35ad233cafd0ff0b6e1d712c0, rebased onto 79cc65fd2ef35e4c391ca7315fed2af21caadb6d. Exact-head ClawSweeper revision 28 is ready with no source or security findings. The native package job passed; remaining required CI is enforced before merge.

  • Added two controlled-order tests: suspend authorization, retire the route by disconnect or replacement, hold queued shutdown, then release authorization. Both require zero socket creations and zero resumes before shutdown is released.
  • The replacement and active-route controls require exactly one created/resumed socket with the expected header. Existing provider-error, direct shutdown, and handshake coverage remains.
  • All newly introduced ordering waits now use awaitable gate-start signals with bounded failure deadlines, resolving the latest polling-test finding. The gate verifies owner-recorded start state after stream completion so cancellation cannot masquerade as admission.
  • Added an automatic-reconnect regression: initial connection succeeds, the second provider call throws, and the third succeeds. It awaits the replacement hello within five seconds and requires three provider reads, two socket creations, two resumes, and generation two. No explicit reconnect call or 30-second watchdog masks the failure.
  • Independent source review and focused autoreview found no actionable P0-P2 issue in the reconnect repair. The earlier retirement and polling findings are addressed. Production net +22 lines; tests net +308.
  • Pinned SwiftFormat 0.63.0 and git diff --check pass. Current-head native package run passed 1,790 shared-kit tests in 141 suites (35.207 seconds); GatewayNodeSessionTests took 22.002 seconds.
  • The throw-once automatic reconnect case passed in 1.538 seconds. Both retired-route cases passed in 0.002 seconds, active admission in 0.001 seconds, direct disconnect during suspended authorization in 0.001 seconds, and all three provider-error entry points in 0.002 seconds. These execute the production channel and route owner with injected WebSocket sessions; no real-network or app-browser proof is claimed.
  • The latest ClawSweeper rank-up is addressed by the current-head execution results and measured retry cost above.

Already-admitted sockets continue through the existing asynchronous shutdown lifecycle; this does not claim instantaneous transport quiescence or withdrawal of bytes already sent.

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

clawsweeper Bot commented Sep 13, 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.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Sep 13, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review September 13, 2026 14:03
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 24, 2026, 2:14 PM ET / 18:14 UTC (Revision 29).

ClawSweeper review

What this changes

The shared Apple Gateway transport awaits a throwing upgrade-header provider, prevents retired routes from opening sockets, preserves retries after temporary provider errors, and adds native regression tests.

Merge readiness

✅ Ready for maintainer review

Current main lacks this native authorization boundary. The member-owned PR remains the implementation candidate, and the exact-head review found no blocking patch defect.

Priority: P2
Reviewed head: e246f5b798f626d35ad233cafd0ff0b6e1d712c0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused owner-level patch and exact-head native validation support normal merge review, with live app activation scoped to downstream work.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The production native session retires the route before detachment, and the channel gates socket creation after awaiting headers. The exact-head native package job passed; the PR reports injected-session tests observing zero creates or resumes for retired routes, one for an active route, and recovery after a provider failure. These are native boundary tests rather than a live app run; the member-authored PR has no unresolved authority-proof gap, and no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The production native session retires the route before detachment, and the channel gates socket creation after awaiting headers. The exact-head native package job passed; the PR reports injected-session tests observing zero creates or resumes for retired routes, one for an active route, and recovery after a provider failure. These are native boundary tests rather than a live app run; the member-authored PR has no unresolved authority-proof gap, and no stored-data contract changes.
Evidence reviewed 8 items Current main: Fetched main still declares a synchronous header provider and creates and resumes the WebSocket without the proposed route-retirement gate.
Socket admission: The introduced path awaits headers, checks cancellation, and serializes socket creation and resume with the retirement gate.
Route retirement: The native session closes socket admission before detaching a route on replacement or disconnect.
Findings None None.
Security None None.

How this fits together

Apple apps use OpenClawKit to connect to a Gateway. A native session owns the route, while its channel prepares upgrade headers, opens the WebSocket, and handles reconnects.

flowchart LR
A[Apple app route] --> B[Native session]
B --> C[Upgrade header provider]
C --> D{Route still active?}
D -->|Yes| E[WebSocket connection]
D -->|No| F[No socket]
E --> G[Callbacks and reconnects]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Other +330. Total +330 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 4 365 35 +330
Total 4 365 35 +330

Review metrics

Metric Value Why it matters
Production and test growth production +22 net lines; tests +308 net lines The production gate has a stated race and retry purpose, with most growth in boundary coverage.
Header-provider contracts 3 entry-point signatures accept async throwing providers The shared channel initializer and two native-session connect overloads can now await authorization.

Technical review

Best possible solution:

Keep route retirement with the native session and socket admission with the shared channel; complete browser sign-in and installed-app upgrade validation in the downstream iOS work.

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

Not applicable: this adds a transport capability. Current-head native boundary tests exercise the route-retirement and retry scenarios.

Is this the best way to solve the issue?

Yes. The existing route owner retires admission, and the channel that creates sockets enforces that decision at creation and resume.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded native transport prerequisite with limited immediate user-facing impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 production native session retires the route before detachment, and the channel gates socket creation after awaiting headers. The exact-head native package job passed; the PR reports injected-session tests observing zero creates or resumes for retired routes, one for an active route, and recovery after a provider failure. These are native boundary tests rather than a live app run; the member-authored PR has no unresolved authority-proof gap, and no stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Gio Della-Libera: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: 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 (28 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-21T07:53:07.951Z sha 3d56e824b1b13ed3b80de235ce6f82a45dfb9731 :: needs changes before merge. :: none
  • reviewed 2026-09-21T08:21:22.329Z sha f2eacdb :: needs changes before merge. :: none
  • reviewed 2026-09-21T15:59:25.416Z sha 89f0869 :: needs changes before merge. :: none
  • reviewed 2026-09-24T11:34:20.762Z sha 89f0869 :: blocked before merge. :: none
  • reviewed 2026-09-24T16:31:18.682Z sha 89f0869 :: needs real behavior proof before merge. :: [P1] Fence route retirement before opening the socket
  • reviewed 2026-09-24T17:33:42.963Z sha 59e7ed8 :: blocked before merge. :: [P3] Replace polling in the new route-retirement tests
  • reviewed 2026-09-24T17:47:56.804Z sha 35b3446 :: blocked before merge. :: [P2] Preserve reconnect ownership when header authorization throws
  • reviewed 2026-09-24T18:01:07.903Z sha e246f5b :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc force-pushed the feat/mobile-cloudflare-access-20260913 branch from f4962a5 to f744a90 Compare September 13, 2026 14:19
@vincentkoc
vincentkoc force-pushed the feat/shared-gateway-ingress-20260913 branch from 13f11fa to fade3cc Compare September 13, 2026 14:19
@vincentkoc
vincentkoc force-pushed the feat/mobile-cloudflare-access-20260913 branch from f744a90 to e978a5c Compare September 13, 2026 15:27
@vincentkoc
vincentkoc force-pushed the feat/shared-gateway-ingress-20260913 branch from fade3cc to e6b51ee Compare September 13, 2026 15:27
@clawsweeper clawsweeper Bot added 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: 🦐 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 Sep 13, 2026
@vincentkoc
vincentkoc force-pushed the feat/mobile-cloudflare-access-20260913 branch from e978a5c to 33b2459 Compare September 13, 2026 19:19
@vincentkoc
vincentkoc force-pushed the feat/shared-gateway-ingress-20260913 branch from e6b51ee to 2735a7f Compare September 13, 2026 19:19
@vincentkoc
vincentkoc force-pushed the feat/mobile-cloudflare-access-20260913 branch from 33b2459 to 252d1ea Compare September 14, 2026 02:30
@vincentkoc
vincentkoc force-pushed the feat/shared-gateway-ingress-20260913 branch from 2735a7f to b35fa0f Compare September 14, 2026 02:30
@vincentkoc vincentkoc changed the title feat: authorize native ingress before Gateway connections feat(gateway): await native upgrade headers before connecting Sep 14, 2026
@vincentkoc
vincentkoc force-pushed the feat/mobile-cloudflare-access-20260913 branch from 252d1ea to 961b0be Compare September 14, 2026 03:34
@vincentkoc
vincentkoc force-pushed the feat/shared-gateway-ingress-20260913 branch from b35fa0f to c96e046 Compare September 14, 2026 03:34
@vincentkoc
vincentkoc force-pushed the feat/mobile-cloudflare-access-20260913 branch from 961b0be to c472838 Compare September 14, 2026 07:33
@vincentkoc
vincentkoc force-pushed the feat/shared-gateway-ingress-20260913 branch from c96e046 to 7c0e423 Compare September 14, 2026 07:33
@clawsweeper

clawsweeper Bot commented Sep 16, 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 marked this pull request as draft September 18, 2026 16:11
@vincentkoc
vincentkoc force-pushed the feat/mobile-cloudflare-access-20260913 branch from 970c028 to 4efcf25 Compare September 21, 2026 04:26
@vincentkoc
vincentkoc force-pushed the feat/shared-gateway-ingress-20260913 branch 2 times, most recently from 679f3ae to 355778a Compare September 21, 2026 06:00
@vincentkoc
vincentkoc force-pushed the feat/mobile-cloudflare-access-20260913 branch from 4efcf25 to 0a50cea Compare September 21, 2026 06:00
@vincentkoc
vincentkoc marked this pull request as ready for review September 21, 2026 06:08
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 59e7ed8bb0714f4ddebfe50fbf018a8ade91ea9c against main. The route-retirement finding is fixed at the session/channel ownership boundary: retirement synchronously closes socket admission before detachment, and creation plus resume share that gate. Two new controlled-order tests hold queued shutdown while the retired authorization completes and require zero created/resumed sockets; replacement and active-route controls require one with the expected header. Pinned formatting and independent source review pass. Fresh native CI is pending and the PR body does not claim an older run covers this repair.

@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 35b34467c9153a069e2045e496d36457151f0058. The only new commit replaces all ordering polls introduced by this PR with bounded awaitable gate-start signals; stream cancellation cannot stand in for the owner recording a start. This addresses the remaining P3. The PR body also records the preceding identical production repair's native package results: 1,789 shared-kit tests, including both retirement orders, active admission, direct shutdown and typed provider errors, with measured durations. Fresh current-head CI is still required.

@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head e246f5b798f626d35ad233cafd0ff0b6e1d712c0. The existing retry owner now retains pre-socket provider failures; a throw-once test requires automatic recovery before the watchdog. The earlier retirement and polling findings remain addressed. Current-head CI is running; the PR body distinguishes prior native evidence from pending proof.

@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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