Skip to content

fix(android): recover dropped gateway events - #129723

Merged
steipete merged 1 commit into
mainfrom
codex/android-gateway-seq-gap
Aug 26, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/android-gateway-seq-gap

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Android silently kept stale assistant replies, run state, usage, and subagent progress after the gateway dropped a slow-client event. The existing ChatController recovery path already refreshes authoritative history on a sequence gap, but Android GatewaySession never emitted that signal.

Why This Change Was Made

Gateway broadcast sequences are per connection, advance only after scope and subscription filters, and intentionally skip a number when a slow client drops an eligible event. Track that sequence in the existing Connection owner and mirror the Apple client: emit seqGap before the next normal event or node invocation, reset naturally on reconnect, and recheck the current connection plus READY state after the recovery callback. Challenge frames, first events, missing sequences, duplicates, and older events retain their existing semantics. The production change adds ten lines and does not change protocol, configuration, authentication, or gateway permissions.

User Impact

A missed gateway event now refreshes Android chat history and clears stale live-run, usage, and subagent presentation before the next event is delivered. Existing connections and device commands remain unchanged when their event sequences are contiguous.

Evidence

  • Unchanged real WebSocket regression baseline: 28 owner tests, exactly four new failures proving absent recovery before normal events and node invocation, stale-event admission after callback disconnect, and missing recovery after reconnect; all 24 existing controls passed.
  • Final focused validation: 90 passing tests covering GatewaySession (28), ChatController history/run recovery (44), subagent state (9), and usage streaming (9).
  • All four Android lint modules pass: app, benchmark, wear, and wear-shared.
  • Independent P1 code review reports no actionable findings.
  • Real Android API 36 uses an in-process loopback WebSocket that validates a synthetic token, operator role, challenge nonce, and the production Ed25519 device identity before connecting the actual GatewaySession and ChatController.
  • Unchanged Android runner passes while proving one chat.history request, legal node.presence and update.available events with sequence numbers 1 and 3, and a visible production ChatBubble showing STALE CHAT MESSAGE.
  • Fixed Android runner passes with the same device, app signer, and scenario: two chat.history requests, seqGap delivered before update.available, and the production ChatBubble visibly showing RECOVERED GATEWAY MESSAGE. Screenshot glyph pixels are validated before capture.

Before:

Actual Android production chat before dropped-event recovery: STALE CHAT MESSAGE

After:

Actual Android production chat after dropped-event recovery: RECOVERED GATEWAY MESSAGE

@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.

@openclaw-barnacle openclaw-barnacle Bot added app: android App: android size: S maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete marked this pull request as ready for review August 26, 2026 00:57
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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:15 PM ET / August 26, 2026, 02:15 UTC.

ClawSweeper review

What this changes

The PR detects skipped gateway event sequence numbers in Android’s WebSocket session, triggers existing recovery before forwarding the next event or node command, and adds reconnection regressions.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for maintainer merge handling: this is a focused Android session-state repair with no actionable patch finding, and it is protected by maintainer ownership context.

Priority: P1
Reviewed head: 54ba7576ea97c9d34821388391a53d7984dc701a

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary repair with strong stated Android evidence and targeted lifecycle regressions.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR; its body nevertheless provides Android loopback and before/after UI evidence.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR; its body nevertheless provides Android loopback and before/after UI evidence.
Evidence reviewed 4 items Gateway sequence contract: Eligible clients receive per-client sequence numbers; slow-client drops consume a number so the next delivered frame exposes the loss.
Current-main gap: Current Android decodes event sequences but forwards current-connection events without detecting discontinuities.
Existing recovery owner: ChatController already clears incomplete run/subagent presentation and refreshes authoritative history on seqGap.
Findings None None.
Security None None.

Live Verification

Command: cd apps/android && ./gradlew :app:testPlayDebugUnitTest --tests ai.openclaw.app.gateway.GatewaySessionReconnectTest

Result: FAIL (failed) — step 1 run cd apps/android && ./gradlew :app:testPlayDebugUnitTest --tests ai.openclaw.app.gateway.GatewaySessionReconnectTest: previous terminal command was still running after 30 seconds: "cd apps/android && ./gradlew :app:testPlayDebugUnitTest --tests ai.openclaw.app.gateway.GatewaySessionReconnectTest"

Fetching distribution.
Downloading https://services.gradle.org/distributions/gradle-9.7.0-bin.zip
..............10%..............20%..............30%...............40%..............50%...............60%..............70%..............80%...............90%....
..........100%

Welcome to Gradle 9.7.0!

Here are the highlights of this release:
 - Isolated Projects graduates to incubating
 - Broader Configuration Cache compatibility
 - More source locations in problem reports

For more details see https://docs.gradle.org/9.7.0/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)
│···············│ 0% CONFIGURING [26s]
› IDLE
› IDLE
› IDLE
› IDLE
› IDLE
› IDLE
› IDLE
› IDLE
› IDLE
› IDLE
› IDLE
› root project › Resolve files of configuration 'classpath' › ExternalDependencyInstrumentingArtifactTransform instrumentation-dependencies.bin
› IDLE
› IDLE
› IDLE
› IDLE
› IDLE
› IDLE

Assertions:

  • FAIL expect_output: BUILD SUCCESSFUL

How this fits together

The gateway assigns event sequences per WebSocket connection and deliberately leaves gaps when slow-client events are dropped. Android GatewaySession receives those frames and ChatController refreshes authoritative chat and run state when it receives a recovery signal.

flowchart LR
A[Gateway broadcaster] --> B[Per-connection sequence]
B --> C[Android Gateway Session]
C --> D{Sequence gap?}
D -->|yes| E[Chat recovery signal]
E --> F[History and run refresh]
D -->|no| G[Normal event or node command]
F --> G
G --> H[Android chat UI]
Loading

Before merge

  • Resolve merge risk (P1) - The PR changes recovery of displayed chat and run state after a delivery loss; preserve the exact-head Android checks if the branch is refreshed against main.
  • Complete next step (P2) - This active maintainer-authored PR has no mechanical repair finding and should continue through normal exact-head merge validation.
Agent review details

Security

None.

PR surface

Other +196. Total +196 across 2 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 2 196 0 +196
Total 2 196 0 +196

Review metrics

Metric Value Why it matters
Production vs test delta production +10, tests +186 The production growth is the connection-owned sequence cursor and lifecycle fence; tests cover four asynchronous boundary cases.

Merge-risk options

Maintainer options:

  1. Refresh exact-head validation (recommended)
    If the branch is rebased or otherwise refreshed, rerun the Android build, lint, and gateway-session checks on that exact head.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Require exact-head Android build, lint, and gateway-session test checks after any branch refresh.

Technical review

Best possible solution:

Retain the connection-local detector and existing ChatController recovery path, then merge after exact-head Android validation remains green.

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

Yes: a focused loopback-WebSocket scenario can create a skipped sequence, and current source shows Android lacks the producer for its existing seqGap recovery path.

Is this the best way to solve the issue?

Yes: tracking at the per-connection receiver matches the broadcaster contract and reuses the existing ChatController recovery owner rather than adding a parallel refresh path.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The patch changes when Android clears and refreshes live chat/run presentation after a gateway delivery discontinuity.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: Dropped gateway events can silently leave Android chat, run, usage, and subagent presentation stale.
  • merge-risk: 🚨 session-state: The patch changes when Android clears and refreshes live chat/run presentation after a gateway delivery discontinuity.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR; its body nevertheless provides Android loopback and before/after UI evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the existing Android seqGap consumer and prior merged GatewaySession work in this area. (role: recent Android gateway and recovery contributor; confidence: high; commits: 85611e061265, 54ba7576ea97; files: apps/android/app/src/main/java/ai/openclaw/app/chat/ChatController.kt, apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewaySession.kt)

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:05:21.145Z sha 54ba757 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 26, 2026
@steipete
steipete merged commit 4048b57 into main Aug 26, 2026
127 checks passed
@steipete
steipete deleted the codex/android-gateway-seq-gap branch August 26, 2026 02:30
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

app: android App: android maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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