Repository navigation
refactor(ios): one phase per gateway session with a sticky shared pause - #197212
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR consolidates iOS Gateway connection state into session phases and makes either session’s authentication pause stop automatic reconnects. Example: An iPhone receives password_mismatch from its Gateway.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses a verified iOS reconnect defect, and the current head resolves the previous findings and merge conflict without introducing an actionable defect. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe iOS NodeAppModel coordinates node and operator Gateway sessions, translating connection callbacks and user actions into connection state, retry decisions, and presentation. flowchart TD
A[User actions and lifecycle events] --> B[NodeAppModel]
B --> C[Session phases and shared pause]
C --> D[Node and operator reconnect loops]
D --> E[GatewayNodeSession transports]
E --> F[Gateway]
E --> B
Technical reviewBest possible solution: Keep connection phases and shared retry policy in NodeAppModel, with explicit recovery actions and transport watchdog shutdown governed by that owner. Do we have a high-confidence way to reproduce the issue? The current-main pause gap is source-verifiable, and the contributor supplies controlled simulator and physical-device reproductions against a real Gateway; this read-only review executed no target code. Is this the best way to solve the issue? The phase representation is a justified consolidation inside the existing lifecycle owner, removes competing stored projections, and addresses both application-loop and socket-watchdog retries. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 56eb6f3fe2e6. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +52, Tests +199. Total +251 across 14 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed November 11, 2026, 5:52 PM ET / 22:52 UTC (Revision 5). |
|
Fixed the Talk polling finding: the poll now resumes the operator only while it is paused for pairing approval. New test @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Physical iPhone proof (iPhone 17, iOS 27.2, Wi-Fi, isolated password-auth Gateway)Paired by QR, then removed the device's pairing on the Gateway so its stored credential is rejected ( Bug found on the device with the previous head ( Fix ( Device run with the fix:
The banner stayed visible throughout, and nothing retried until the user acted. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Fixed the mixed-pause finding. The decision is now one property on the connection state, @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
d5a30a2 to
c56edfa
Compare
|
Rebased on main to resolve the conflict. The only conflict was the retired-key deep-link test that #197172 added on main; it now marks the node connected through @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…se (openclaw#197212) * refactor(ios): one phase per gateway session with a sticky shared pause * fix(ios): Talk approval polling resumes only pairing pauses * fix(ios): a pause stops the socket watchdog of every unconnected session * fix(ios): automatic pairing retry waits while a credential pause is live
Problem
The iOS app stored the focused Gateway's connection condition in about ten separately written fields on
NodeAppModel(gatewayConnected,operatorConnected,gatewayServerName,gatewayRemoteAddress, node/operator problems, pairing flags, and the pause meaning ofgatewayAutoReconnectEnabled). Fields that must agree were written one by one at many sites, so some paths recorded a pause without pausing. Still onmain:applyOperatorGatewayConnectionProblem).break,return,continue), and Talk/Watch inferred "paused" fromoperatorGatewayTask == nil.The result: against a locked Gateway the app keeps hitting it, which extends the lockout.
Solution
Stage 1 of a one-owner design for connection state:
GatewaySessionPhase:idle,connecting,connected, orpaused(problem).apply(event, to:route:)is the only live writer. It drops events from a superseded route and ignores live events in fixture mode.pauseReconnector pairing approval) moves that session to.paused. The pause is sticky: socket drops, loop exit and the other session connecting don't lift it. Only an explicit user action, a new connect, or disconnect/forget does.canAutoReconnect(user intent, no paused session, no pausing preconnect problem) gates both loops and every automatic reconnect path (lease, restoration, foreground, push wake, Watch, registration refresh). Both loops wait while paused instead of exiting.credentialHandoffFailureGenerationandsetOperatorConnected.Unchanged and out of scope (later stages): status text and
GatewayStatusBuilderderivation, renaminggatewayAutoReconnectEnabled, the persistedgateway.autoconnectlaunch toggle, Talk's admission edge.Impact
When the Gateway locks the device out, or rejects its credentials, the app stops retrying on both connections and keeps the banner until the user taps Retry. Normal connect, reconnect after a Gateway restart, and pairing behave as before.
Evidence
Lockout on a real Gateway (iOS 27 simulator, throwaway password-auth Gateway with the loopback limiter on)
Recipe: pair by manual host + password, lock the address with 11 wrong-password calls (limit is 10/min, 5 min lock), then change the Gateway password so the app's stored credential is also rejected. Count the app's rejected handshakes in the Gateway log for 3 minutes.
mainmainWith this PR, both connections stop and the app shows "Too many failed attempts" with Wait and retry. Nothing reached the Gateway while the app was paused. After the lock expired, tapping Wait and retry reconnected both node and operator in about 0.3 s (app diagnostics:
gateway connected/operator gateway connected).An earlier build of this branch also showed the onboarding pairing ticker retrying every 6 s on both roles through a rate limit. Fixed: automatic pairing resume now runs only while a session is paused for pairing approval.
Physical iPhone (iPhone 17, iOS 27.2, Wi-Fi, isolated password-auth Gateway)
Paired by QR, then removed the device's pairing on the Gateway so its stored credential is rejected (
password_mismatch).Bug found on the device with the previous head (
b990dd8): the node stopped after one attempt, but the operator kept reconnecting at 1, 2, 4, 8, 16, 30, 30… s. The app's diagnostics showed onlyoperator gateway disconnected … connect failedand never the operator loop's ownconnect errorline. So the retries came fromGatewayChannel's internal reconnect, which judges this rejection recoverable and bypassed the app's pause. That same backoff caused the 10 operator rejections onmainin the onboarding simulator run.Fix (
fix(ios): a pause stops the socket watchdog of every unconnected session):applyis the single writer. While any session is paused, it disconnects every session that is not connected; a connected session keeps its socket. This replaces the two per-loop disconnects. Testa dropped node stays down while the operator is pausedfails without the fix (server.roles == ["node"]: the watchdog reconnected) and passes with it. 456 tests in 5 affected suites pass.Device run with the fix:
password_mismatch)client connected, operatorclient connectedThe banner stayed visible throughout, and nothing retried until the user acted.
Tests
GatewaySessionPauseTests:same config connect restarts a paused route: red on base (the paused loop had exited,Still waiting for node connected after retry).node reconnect does not lift an operator pause,resume restarts reconnect attempts after a pause: red on base.operator-only resume keeps a node pause,stale route events are dropped.credential handoff pause survives node loop exit: passes on base too (base usedcredentialHandoffFailureGeneration, deleted here), so it guards that deletion.✔ Test run with 461 tests in 6 suites passed(GatewaySessionPause, GatewayConnectionController, NodeAppModelInvoke, TalkModeManager, OnboardingStateStore, GatewayConnectionSecurity) on the final head; an earlier 14-suite run (614 tests) before the last review round.swiftformat --lintclean.Not covered
GatewayConnectionControllerTests/TalkModeManagerTests.Size
Production +304/−274 (adds the phase type and its one writer; deletes 9 stored fields,
credentialHandoffFailureGeneration,setOperatorConnected,clearOperatorGatewayConnectionProblemIfCurrentand the pairing flags). Tests +273/−137, including the newGatewaySessionPauseTests.swift.