Skip to content

fix(clickclack): prevent reconnect from skipping in-flight events - #108577

Merged
steipete merged 2 commits into
openclaw:mainfrom
zhanxingxin1998:fix/clickclack-commit-cursor-after-processing
Jul 16, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
zhanxingxin1998:fix/clickclack-commit-cursor-after-processing

Conversation

@zhanxingxin1998

Copy link
Copy Markdown
Contributor

Closes #108570

Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers can help update the branch when needed.

What Problem This Solves

Fixes an issue where ClickClack users could lose an inbound event when a websocket disconnect overlapped slow event processing. The gateway advanced its reconnect cursor before the event handler completed and started each message handler independently, so a reconnect could skip an in-flight or failed event.

Why This Change Was Made

The websocket cycle is the ownership boundary for event order and cursor commitment. It now serializes message processing, commits each cursor only after that event succeeds, waits for queued handlers before a normal reconnect, and terminates the queue on the first processing failure so backlog recovery can retry from the last successful cursor.

User Impact

ClickClack reconnects no longer acknowledge work that has not completed. Normal ordered delivery, malformed-frame skipping, shutdown aborts, and empty-queue reconnects retain their existing behavior.

Evidence

Real behavior proof

  • Behavior addressed: A websocket reconnect no longer skips an event whose inbound handler is still running or has failed.

  • Real environment tested: Linux x86_64, Node 24.15.0, commit ac8bb62b702d92f7535068b872abc72bd10a9873 on branch fix/clickclack-commit-cursor-after-processing.

  • Exact steps or command run after this patch: node --import tsx .artifacts/verify-clickclack-cursor.ts - started a real local HTTP/WebSocket server, delayed the first inbound handler, closed the first socket, and inspected the reconnect cursor and timing.

  • Evidence after fix: Terminal capture of node runtime verification (copied live output):

    {"result":"PASS","reconnectCursor":"cursor-1","processingAndBackoffMs":355,"websocketConnections":2}
    
  • Observed result after fix: The second websocket connection opened only after the delayed handler and reconnect backoff completed, and it resumed from the successfully processed cursor-1.

  • What was not tested: A production ClickClack tenant was not used; the proof used the actual gateway against a local protocol-compatible HTTP/WebSocket server. Cross-platform execution is left to CI.

Tests and validation

$ node scripts/run-vitest.mjs extensions/clickclack/src/gateway.test.ts
Test Files  1 passed (1)
Tests       19 passed (19)

$ oxfmt --check extensions/clickclack/src/gateway.ts extensions/clickclack/src/gateway.test.ts
All matched files use the correct format.

$ oxlint extensions/clickclack/src/gateway.ts extensions/clickclack/src/gateway.test.ts
EXIT=0

$ git diff --check origin/main...HEAD
EXIT=0

The regressions defer the first event to prove strict ordering and reconnect waiting, then reject an event to prove later queued events are neither processed nor committed.

Risk checklist

  • User-visible behavior: Yes - reconnect waits for in-flight processing and failed events remain eligible for backlog recovery.
  • Config/env/migration behavior: No - no configuration, persisted schema, or migration changes.
  • Security/auth/secrets/network/tool execution: No - the existing ClickClack connection and inbound authorization paths are unchanged.
  • Plugins/providers/channels/SDK: Yes - this is isolated to the bundled ClickClack plugin; no SDK or cross-plugin contract changes.
  • Highest-risk area: Socket close/error/abort ordering could otherwise leave a cycle unsettled or process later events after a failure.
  • Mitigation: Focused tests cover delayed processing, failure, close, error, abort, malformed frames, reconnect, and backlog cursor behavior; the real server proof covers reconnect timing and cursor selection.

AI assistance

This PR is AI-assisted. OpenAI Codex helped investigate, implement, test, and review the change. I reviewed the resulting code and understand its behavior. Automated structured review was attempted, but the local review engine failed before producing a clean/finding result; GitHub review and CI remain authoritative.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 16, 2026, 12:12 AM ET / 04:12 UTC.

Summary
The PR serializes ClickClack websocket event handling, advances the reconnect cursor only after successful processing, waits for queued work before normal reconnect, and adds ordering and failure regressions.

PR surface: Source +20, Tests +86. Total +106 across 2 files.

Reproducibility: yes. at source level with high confidence: delay the first websocket handler, deliver another event, and close the socket before the first handler completes; the pre-patch listener can reconnect using the prematurely advanced cursor. The supplied report and harness describe this current-main path, though this review did not independently execute it.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: extensions/clickclack/src/gateway.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #108570
Summary: This PR is the direct candidate fix for the linked ClickClack reconnect-cursor issue; both should remain open until the patch lands or is rejected.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Risk before merge

  • [P1] The PR head is behind current main; maintainers should refresh or rebase and verify the exact merge result before landing, particularly around socket close, error, and abort lifecycle changes.

Maintainer options:

  1. Decide the mitigation before merge
    Land the per-socket ordered queue and post-success cursor commitment after refreshing the branch against current main and confirming the focused gateway tests and real reconnect proof still pass unchanged.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] This PR does not need an automated repair; it needs ordinary maintainer review and an exact-main refresh before landing alongside the linked issue.

Security
Cleared: The two-file runtime and test patch adds no dependencies, workflow execution, permissions, secret handling, authentication changes, or new external code source.

Review details

Best possible solution:

Land the per-socket ordered queue and post-success cursor commitment after refreshing the branch against current main and confirming the focused gateway tests and real reconnect proof still pass unchanged.

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

Yes at source level with high confidence: delay the first websocket handler, deliver another event, and close the socket before the first handler completes; the pre-patch listener can reconnect using the prematurely advanced cursor. The supplied report and harness describe this current-main path, though this review did not independently execute it.

Is this the best way to solve the issue?

Yes. Serializing work at the websocket-cycle boundary and committing only the successful contiguous cursor is the narrowest maintainable fix and matches the upstream sequential-processing contract; the branch only needs an exact-main refresh before landing.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P1: The existing ClickClack reconnect race can suppress an inbound channel event during a real disconnect and slow-processing overlap, making this an urgent message-delivery regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR provides after-fix live output from the actual ClickClack gateway against a protocol-compatible local HTTP/WebSocket server, demonstrating that delayed processing finishes before reconnect and that reconnect uses the last successfully processed cursor.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR provides after-fix live output from the actual ClickClack gateway against a protocol-compatible local HTTP/WebSocket server, demonstrating that delayed processing finishes before reconnect and that reconnect uses the last successfully processed cursor.

Label justifications:

  • P1: The existing ClickClack reconnect race can suppress an inbound channel event during a real disconnect and slow-processing overlap, making this an urgent message-delivery regression.
  • 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. Sufficient (live_output): The PR provides after-fix live output from the actual ClickClack gateway against a protocol-compatible local HTTP/WebSocket server, demonstrating that delayed processing finishes before reconnect and that reconnect uses the last successfully processed cursor.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides after-fix live output from the actual ClickClack gateway against a protocol-compatible local HTTP/WebSocket server, demonstrating that delayed processing finishes before reconnect and that reconnect uses the last successfully processed cursor.
Evidence reviewed

PR surface:

Source +20, Tests +86. Total +106 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 33 13 +20
Tests 1 86 0 +86
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 119 13 +106

What I checked:

  • Current behavior permits skipped work: The pre-patch websocket listener starts independent asynchronous handlers and assigns afterCursor before awaiting processIncomingEvent, allowing reconnect to use a cursor for unfinished or failed work. (extensions/clickclack/src/gateway.ts:272, 957cc81175a3)
  • Patch moves commitment behind successful processing: The PR head chains messages through one promise queue, awaits processIncomingEvent, and only then assigns the event cursor, so a rejected handler leaves the last successful cursor available for backlog recovery. (extensions/clickclack/src/gateway.ts:278, ac8bb62b702d)
  • Regression coverage exercises the race: The added tests delay the first event, close the socket, verify ordered processing before reconnect, and reject an event to ensure later queued events are neither processed nor committed. (extensions/clickclack/src/gateway.test.ts:338, ac8bb62b702d)
  • Real behavior proof: The PR body records an after-fix Node 24 run using the actual gateway with a local protocol-compatible HTTP/WebSocket server; reconnect occurred after delayed processing and resumed from cursor-1, with a reported PASS result. (extensions/clickclack/src/gateway.ts:239, ac8bb62b702d)
  • Dependency contract supports the ordering model: ClickClack's bot protocol documentation describes receiving events sequentially and persisting the latest cursor after each processed event, which matches the patch's ownership and commitment boundary. citeturn7search4.
  • Linked canonical report remains open: The linked issue describes the same concurrent-handler and premature-cursor defect and supplies a deterministic current-main reproduction path; this PR is its candidate fix, not a reason to close either item before merge. (extensions/clickclack/src/gateway.ts:272, 7f9d519fcb0d)

Likely related people:

  • steipete: The ClickClack project and its bot protocol are closely associated with Peter Steinberger, making this the strongest available routing candidate for the cross-repository event-order and cursor contract; local file-history inspection was unavailable, so confidence is limited. citeturn15search1turn7search4. (role: adjacent product owner; confidence: medium; files: extensions/clickclack/src/gateway.ts, extensions/clickclack/src/gateway.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@steipete steipete self-assigned this Jul 16, 2026
zhanxingxin1998 and others added 2 commits July 16, 2026 11:50
Serialize realtime events and wait for queued handlers before reconnecting so only successfully processed cursors advance.

Co-Authored-By: OpenAI Codex <[email protected]>
Keep the last successful cursor when realtime handling fails, then reconnect through durable backlog recovery before reopening the stream.

Co-authored-by: 詹幸心0668001037 <[email protected]>
@steipete
steipete force-pushed the fix/clickclack-commit-cursor-after-processing branch from ac8bb62 to faa987d Compare July 16, 2026 11:02
@steipete

Copy link
Copy Markdown
Contributor

Maintainer repair complete on exact head faa987deeb9ef67d05fcaf57bd7fcb358c9c45cb.

The original queue fix still rejected the entire gateway on a handler failure. A supervisor restart then reset ClickClack startup-tail state, so the failed durable event could still disappear. I changed failure handling to close only that websocket cycle, retain the last successfully processed cursor, and replay the failed event plus later queued events through the HTTP backlog before reopening realtime. A repeated failure during canonical backlog replay remains surfaced to the gateway supervisor.

The queue stays lexical to each account/gateway invocation; a slow stream does not block unrelated streams.

Proof:

Upstream contract checked against live openclaw/clickclack main: durable events replay after after_cursor; clients commit cursors only after handling. No security, docs, migration, or changelog blocker.

@steipete
steipete merged commit 5810de2 into openclaw:main Jul 16, 2026
92 of 94 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
…enclaw#108577)

* fix(clickclack): commit websocket cursors after processing

Serialize realtime events and wait for queued handlers before reconnecting so only successfully processed cursors advance.

Co-Authored-By: OpenAI Codex <[email protected]>

* fix(clickclack): replay failed websocket events

Keep the last successful cursor when realtime handling fails, then reconnect through durable backlog recovery before reopening the stream.

Co-authored-by: 詹幸心0668001037 <[email protected]>

---------

Co-authored-by: OpenAI Codex <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…enclaw#108577)

* fix(clickclack): commit websocket cursors after processing

Serialize realtime events and wait for queued handlers before reconnecting so only successfully processed cursors advance.

Co-Authored-By: OpenAI Codex <[email protected]>

* fix(clickclack): replay failed websocket events

Keep the last successful cursor when realtime handling fails, then reconnect through durable backlog recovery before reopening the stream.

Co-authored-by: 詹幸心0668001037 <[email protected]>

---------

Co-authored-by: OpenAI Codex <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

[Bug]: ClickClack reconnect can skip in-flight websocket events

2 participants