Skip to content

fix(gateway): avoid repeated channel restarts after deferred thaw recovery - #186077

Merged
vincentkoc merged 10 commits into
mainfrom
fix/gateway-thaw-captured-lifetimes-20261027
Oct 28, 2026
Merged

vincentkoc merged 10 commits into
mainfrom
fix/gateway-thaw-captured-lifetimes-20261027

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes channels being restarted twice when host-thaw recovery waits for active work and health monitoring recovers them first.

User Impact

Accounts recovered by another owner stay online. Accounts still affected by the original timing gap continue through the existing bounded recovery window. No configuration or operator action changes.

Why This Change Was Made

Capture each affected account lifetime when the timing gap is detected, before active-work deferral. The account lifecycle owner conditionally stops and replaces only that captured lifetime, checking ownership again after awaited teardown. Maintenance owns the pending targets and deadline; the separate core-runtime target list and retry-selection mode are removed.

Manual stops, account removal, incomplete cleanup retries, and account-specific failure diagnostics remain intact. Shared lifecycle contracts stay separate from the manager's private runtime store, avoiding an import cycle.

Production delta: +240/-165 (net +75). The growth supplies the conditional lifetime-replacement boundary and its connected contracts; tests add 292 net lines.

Evidence

  • Independent source review covered the lifecycle owner, scheduler ordering, health monitoring, callers, and sibling recovery paths.
  • Targeted formatting, git diff --check, and the native line-cap ratchet passed for the authored fix.
  • Regressions exercise the reported deferral order, identical start timestamps, health-first scheduler wake, failed-stop recovery by another owner, later timing gaps, interrupted admission, late timeout cleanup, and retry diagnostics.
  • 150 changed-suite tests passed at current head 8793a69450f42e58b04440fe31004d9e506a473d. The runtime shard passed channel-manager 93, account-lifetime 11, work-scope 1, maintenance 36, and telemetry 9. Ordinary CI completed successfully: 42 checks passed, 27 skipped, none failed. The exact-head hosted review at 02:22 UTC on October 28 found no actionable finding or remaining rank-up move.
  • The current candidate integrates pinned main 2262f3d2d82c8743dcda1087032e57e60db890a2. Only the test-budget conflict was resolved, retaining the same ceiling; all 15 authored Gateway blobs and the production/test diff remain identical to the prior tested candidate. Current-head CI covers the integrated candidate; this does not claim unchanged dependency context.

Local dependency qualification refused reuse. Focused remote thaw attempts queued and were stopped before payload execution. Baseline-red/head-green, isolated full-Gateway, and live Telegram recovery proof remain unverified; the regressions use real maintenance, scheduler and account-lifecycle owners. No live-channel success is claimed.

Test-Budget Justification

Pinned main 2262f3d2d82c8743dcda1087032e57e60db890a2 contains 6,293,974 counted test lines, independently verified from the ratchet's exact filename patterns and literal newline counts: 58 changed matching blobs add 737 lines to the previously verified 6,293,237. Its existing ceiling is 6,293,776.

The reviewed recovery fixes add this PR's 292 lines, the separate Telegram disconnect-episode fix's 241, and the separate health-admission fix's 235: 6,294,742 combined. The ceiling is 6,295,000, with 258 disclosed lines of slack. This follows the documented ratchet policy and merged rounded-allowance precedent. Both follow-ups reuse this allowance.

The separate test-budget allocation PR is pending landing. It sets this same ceiling on main to resolve the shared-file conflict while preserving this PR's reviewed head.

Separate Follow-ups

Telegram transport retry status owns its disconnect episode. Health monitoring must refresh each account's status after awaiting an earlier account. Those are separate narrow fixes; this PR repairs deferred outer account replacement.

@vincentkoc vincentkoc self-assigned this Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@vincentkoc
vincentkoc marked this pull request as ready for review October 27, 2026 15:21
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L labels Oct 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review current head 8f34cb2e6a864a2c9b2af43d40787c9d8c22c696. The previous review started on bcc9efa66a2d706866eb3c4e43ec97e89b84e290; this update fixes the type-import cycles and two test-contract failures reported by its CI. Fresh CI is pending, as recorded in the PR body.

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR captures channel account lifetimes before thaw recovery is deferred and skips replacements recovered by another owner.

Example: Health monitoring replaces discord/first while thaw recovery waits for active work to finish.

  • Before: The deferred thaw pass stops and restarts the recovered replacement again.
  • After: The deferred pass preserves that replacement and recovers only accounts still owned by its captured targets.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused owner-level repair appears correct, with useful integration coverage; shipped-entry-point proof remains unverified.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; supplied tests exercise real maintenance, scheduler, and lifecycle owners with synthetic transports, while the body explicitly leaves full-Gateway and live Telegram recovery unverified.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A channel that already recovered can disconnect again when deferred thaw recovery resumes.
Reason: This maintainer-authored repair restores the intended targeted-recovery behavior without adding configuration, public APIs, or operator steps.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a duplicate-restart path still present on main, and inspection found no actionable code defect.

Priority: P2
Reviewed head: 8793a69450f42e58b04440fe31004d9e506a473d

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not establish base-red/head-green behavior or an isolated shipped-Gateway recovery where health replaces an account during thaw deferral.
Agent review details

How this fits together

Gateway maintenance detects host timing gaps and waits for idle work; the channel manager owns account lifetimes, transport teardown, and replacement startup.

flowchart TD
  A[Host timing gap] --> B[Capture account lifetimes]
  B --> C[Pending maintenance targets]
  C --> D[Idle admission check]
  D --> E[Conditional account restart]
  E --> F[Channel transport]
  G[Health monitor recovery] --> F
  G --> E
Loading

Technical review

Best possible solution:

Keep thaw targets in maintenance and let the existing account-lifecycle owner conditionally replace only the captured lifetime.

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

Current-main source shows that recovery deferred behind active work later selects or restarts accounts without lifetime identity, allowing a health-recovered replacement to be restarted again; no product reproduction was run during this read-only review.

Is this the best way to solve the issue?

The change repairs selection timing and conditional replacement at the existing owners, removes the competing core-runtime target list, and preserves the established cleanup and admission contracts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f76e79be6a8f.

Provenance checked

  • Thaw deferral and target selection keeps the original intent (7e2111e: Defer disruptive reconnects while tracked work is active and retry only unfinished accounts.)
  • Account lifetime and cleanup ownership keeps the original intent (7f0410c: Bind account scheduling and cleanup to their lifetime so retired work cannot outlive its owner.)
  • Timed-out task replacement keeps the original intent (d57a382: Let the channel manager recover with one ordinary start request after cleanup joins, preserving manual stops and failed-cleanup custody.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main retains the reported path: Current main selects thaw targets by channel/account identifiers and later stops the current account without comparing its captured lifetime; the central production files are unchanged from the pinned base. (src/gateway/channel-thaw-restart.ts:62, f76e79be6a8f)
  • Capture precedes deferral: Maintenance captures running account lifetimes when detecting the gap, before admission checks and awaited recovery steps, and owns both pending targets and their deadline. (src/gateway/server-maintenance.ts:304, 8793a69450f4)
  • Lifecycle owner preserves replacements: The restart operation checks lifetime identity before stopping and after awaited teardown, preserves manual stops and account removal, and retains unfinished recovery for retry. (src/gateway/server-channel-account-lifetime.ts:49, 8793a69450f4)
  • Prior-head CI and unchanged Gateway blobs: The linked prior-head workflow and both runtime jobs completed successfully at 9916b48; all 15 authored Gateway blobs match this head. The body reports 150 affected tests, but raw job logs redirect to a blocked artifact host, so that count was not independently read. (9916b48411a6)
  • Current-head gates: The current head is mergeable, its CI gate remains pending, and the paginated check census showed no failed check; prior-head success is not current-head acceptance. (8793a69450f4)
  • Test-budget policy: The ratchet explicitly permits a justified ceiling increase, and this maintainer-authored PR records the measured allowance and separate recovery follow-ups. (scripts/check-test-lines-ratchet.mts:113, 8793a69450f4)

PR surface

Source +80, Tests +287, Other 0. Total +367 across 16 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 8 246 166 +80
Tests 7 370 83 +287
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 16 617 250 +367

Review metrics

Metric Value Why it matters
Production versus test growth Production +240/-165; tests and support +376/-84 The lifetime check requires modest production growth while removing duplicate target ownership; added tests cover distinct deferral, replacement, interrupted-admission, and timeout-cleanup failures.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: Avoids unnecessary channel disconnections after deferred host-thaw recovery, with a bounded lifecycle scope.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (5 earlier review cycles)
  • reviewed 2026-10-27T15:43:56.068Z sha 8f34cb2 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-27T16:01:29.717Z sha edf2471 :: needs changes before merge. :: none
  • reviewed 2026-10-27T16:12:14.779Z sha 3aa3546 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-27T18:52:27.971Z sha bb4092a :: needs maintainer review before merge. :: none
  • reviewed 2026-10-28T01:51:47.229Z sha 9916b48 :: needs maintainer review before merge. :: none

Reviewed October 27, 2026, 10:22 PM ET / October 28, 2026, 02:22 UTC (Revision 6).

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review current head edf24713b6b030a799752b47586abcff730fb6fa. The private manager store no longer introduces the transitive runtime-types/HTTP-registry cycle. The test-line ceiling now follows the documented measured-baseline allowance, without deleting regression coverage. The PR body records exact attribution, prior-head CI results, and the unverified base/red and isolated-Gateway proof after queued remote attempts. Current-head CI is pending.

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
Baseline-Refresh: 89870580a45169933124aca3d7164370d5578833
@clawsweeper clawsweeper Bot removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper clawsweeper Bot removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
Baseline-Refresh: 043cb915c08ebf34eae45ac6d5afca3c72607be1
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review current head 9916b48411a6f53a93c1c3166ee1f010105ad11b. The native integration preserves all 15 authored Gateway source and test blobs. The updated PR body distinguishes the prior bb4092a5 150-test proof from pending current-head CI and records the measured test allowance.

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
Baseline-Refresh: c46cbc1ca7b96fb2c69eca170804909b64d480b5
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review current head 8793a69450f42e58b04440fe31004d9e506a473d. The native successor resolves only the new main test-ceiling conflict, retaining the reviewed allowance and all 15 authored Gateway blobs. The PR body links the green prior-head 9916b484 CI and 150 affected tests, records the new pinned counts, and explicitly marks current-head proof pending.

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@vincentkoc
vincentkoc merged commit b61ab6d into main Oct 28, 2026
151 checks passed
@vincentkoc
vincentkoc deleted the fix/gateway-thaw-captured-lifetimes-20261027 branch October 28, 2026 03:01
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…overy (openclaw#186077)

* fix(gateway): preserve recovered channels during deferred thaw recovery

* fix(gateway): isolate account lifetime contracts and align regressions

* fix(gateway): isolate private channel runtime store contracts

* test(gateway): budget distinct thaw lifecycle regressions

* test(gateway): align thaw regression budget with pinned main

* test(gateway): reserve the reviewed recovery regression budget
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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