Skip to content

fix(gateway): retry restart continuation recovery - #90490

Closed
sahibzada-allahyar wants to merge 6 commits into
openclaw:mainfrom
sahibzada-allahyar:fastino-76087-restart-continuation-retry
Closed

sahibzada-allahyar wants to merge 6 commits into
openclaw:mainfrom
sahibzada-allahyar:fastino-76087-restart-continuation-retry

Conversation

@sahibzada-allahyar

@sahibzada-allahyar sahibzada-allahyar commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

What changed

  • Added periodic restart/session-delivery recovery so entries deferred by retry backoff are retried after startup.
  • Added a focused gateway lifecycle regression test that proves the first startup recovery and later 60s retry both call restart-continuation recovery.

Fixes #76087

Real behavior proof

  • Behavior or issue addressed: Restart/session delivery recovery now runs the startup drain and then continues retrying deferred restart-continuation deliveries while the gateway process is alive. Before this PR, recoverPendingSessionDeliveries() scheduled one startup recovery after 1_250ms; after this PR, it also schedules a 60_000ms periodic retry. This proof seeds a failed queued restart-continuation entry, waits past the first retry backoff, then invokes the registered gateway periodic retry callback and verifies the entry is acknowledged.

  • Real environment tested: Local OpenClaw source checkout on Darwin 25.5.0 arm64, Node v26.0.0, pnpm 11.2.2, branch fastino-76087-restart-continuation-retry.

  • Exact steps or command run after this patch:

    1. Ran an isolated source-checkout behavior probe with a temporary OPENCLAW_STATE_DIR.
    2. The probe enqueued a restart-sentinel session-delivery entry, marked it failed with retry metadata, activated activateGatewayScheduledServices(), confirmed the 60000 ms periodic retry interval was registered, waited past the first 5000 ms backoff, invoked that periodic callback, and checked the queue again.
    3. Ran pnpm test src/gateway/server-runtime-services.test.ts src/infra/session-delivery-queue.recovery.test.ts src/gateway/server-restart-sentinel.test.ts.
    4. Ran git diff --check HEAD~1..HEAD.
  • Evidence after fix: Terminal transcript from the failed-entry periodic retry probe:

    $ tmpdir=$(mktemp -d /tmp/openclaw-90490-periodic-proof-XXXXXX); OPENCLAW_STATE_DIR="$tmpdir" pnpm exec tsx --eval '
    (async () => {
    const realSetTimeout = globalThis.setTimeout.bind(globalThis);
    const intervals = [];
    globalThis.setTimeout = ((fn, delay) => ({ unref() {}, __fn: fn, __delay: delay })) as never;
    globalThis.setInterval = ((fn, delay) => { intervals.push({ fn, delay: Number(delay) }); return { unref() {} }; }) as never;
    globalThis.clearTimeout = (() => undefined) as never;
    globalThis.clearInterval = (() => undefined) as never;
    const { enqueueSessionDelivery, failSessionDelivery, loadPendingSessionDeliveries } = await import("./src/infra/session-delivery-queue.ts");
    const { activateGatewayScheduledServices } = await import("./src/gateway/server-runtime-services.ts");
    const id = await enqueueSessionDelivery({ kind: "systemEvent", sessionKey: "agent:main:main", text: "restart continuation after transient send failure", idempotencyKey: "restart-sentinel:agent:main:main:systemEvent:90490-periodic" });
    await failSessionDelivery(id, "Network request for sendMessage failed!");
    console.log("stateDir", process.env.OPENCLAW_STATE_DIR);
    console.log("failedQueuedEntry", JSON.stringify(await loadPendingSessionDeliveries()));
    activateGatewayScheduledServices({ minimalTestGateway: false, cfgAtStart: { models: { pricing: { enabled: false } } }, deps: {}, sessionDeliveryRecoveryMaxEnqueuedAt: Date.now(), cron: { start: async () => undefined }, logCron: { error: (message) => console.log("cronError", message) }, log: { child: (name) => ({ info: (message) => console.log(name + ":info", message), warn: (message) => console.log(name + ":warn", message), error: (message) => console.log(name + ":error", message) }), error: (message) => console.log("error", message), warn: (message) => console.log("warn", message), info: (message) => console.log("info", message), debug: () => undefined } });
    console.log("registeredIntervals", JSON.stringify(intervals.map(({ delay }) => delay)));
    const periodic = intervals.find((item) => item.delay === 60000);
    if (!periodic) throw new Error("missing 60000ms session-delivery retry interval");
    console.log("beforeBackoffElapsed", JSON.stringify(await loadPendingSessionDeliveries()));
    await new Promise((resolve) => realSetTimeout(resolve, 5100));
    periodic.fn();
    await new Promise((resolve) => realSetTimeout(resolve, 1000));
    console.log("afterPeriodicRetry", JSON.stringify(await loadPendingSessionDeliveries()));
    })().catch((err) => { console.error(err); process.exit(1); });
    '
    stateDir /tmp/openclaw-90490-periodic-proof-mQy1Eo
    failedQueuedEntry [{"kind":"systemEvent","sessionKey":"agent:main:main","text":"restart continuation after transient send failure","idempotencyKey":"restart-sentinel:agent:main:main:systemEvent:90490-periodic","id":"07ab21da0fb6f145c33fb4e60eba23ffb46c99b608381765282d6903a6925379","enqueuedAt":1780655248585,"retryCount":1,"lastAttemptAt":1780655248588,"lastError":"Network request for sendMessage failed!"}]
    [heartbeat] started
    registeredIntervals [1800000,60000]
    beforeBackoffElapsed [{"kind":"systemEvent","sessionKey":"agent:main:main","text":"restart continuation after transient send failure","idempotencyKey":"restart-sentinel:agent:main:main:systemEvent:90490-periodic","id":"07ab21da0fb6f145c33fb4e60eba23ffb46c99b608381765282d6903a6925379","enqueuedAt":1780655248585,"retryCount":1,"lastAttemptAt":1780655248588,"lastError":"Network request for sendMessage failed!"}]
    session-delivery-recovery:info Recovered session delivery 07ab21da0fb6f145c33fb4e60eba23ffb46c99b608381765282d6903a6925379
    afterPeriodicRetry []
    

    Supplemental focused test output:

    Test Files  4 passed (4)
    Tests  74 passed (74)
    
    Test Files  1 passed (1)
    Tests  6 passed (6)
    
    [test] passed 2 Vitest shards in 12.49s
    
  • Observed result after fix: A failed pending restart-continuation session-delivery entry (retryCount: 1, lastError: "Network request for sendMessage failed!") remained queued before the first backoff elapsed. After the branch-registered 60000 ms session-delivery periodic retry callback ran past the 5000 ms backoff, OpenClaw logged Recovered session delivery ... and the pending queue became [].

  • What was not tested: No live Telegram network outage or production gateway credential flow. No permanent Telegram API failure path; this proof exercises the gateway scheduler retry path and the durable session-delivery queue recovery path with an isolated local state directory.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 5, 2026
@clawsweeper

clawsweeper Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 2, 2026, 1:51 PM ET / 17:51 UTC.

Summary
This PR adds a 60-second gateway restart-continuation session-delivery retry loop, shutdown stop wiring, late sidecar stop tracking, delayed restart-sentinel removal, and focused gateway/session-delivery tests.

PR surface: Source +74, Tests +113. Total +187 across 10 files.

Reproducibility: yes. Current main source shows only a one-shot 1,250 ms restart-continuation recovery while failed session-delivery entries persist retry/backoff metadata; I did not run a live Telegram outage scenario.

Review metrics: 1 noteworthy metric.

  • Background recovery lifecycle: 1 interval added, 1 stop handle added. The new recurring recovery path runs during gateway lifetime and shutdown, so maintainers need lifecycle ownership proof beyond ordinary unit coverage.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #76087
Summary: This PR is the candidate fix for the canonical restart-continuation periodic retry issue; adjacent session-delivery work covers duplicate replay, retry persistence, and broader restart-recovery concerns.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🦪 silver shellfish
Patch quality: 🧂 unranked krab
Result: blocked until stronger real behavior proof is added.

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

Rank-up moves:

  • Track and await or suppress in-flight periodic recovery during gateway shutdown.
  • [P1] Add after-fix terminal, log, or live proof for the latest shutdown-sidecar and sentinel-handoff behavior with private details redacted.
  • Rebase against current main to resolve the dirty gateway lifecycle branch.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The terminal proof covers the original 60-second retry path, but not the latest shutdown-sidecar and delayed-sentinel behavior; add redacted terminal/log/live output in the PR body and request re-review if needed. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

Maintainer options:

  1. Make periodic recovery shutdown-owned (recommended)
    Track a stopped flag and active recovery promise, and have close prelude or close handling await or suppress the in-flight recovery before channels and sidecars are torn down.
  2. Accept the lifecycle risk explicitly
    Maintainers could choose to land with a known shutdown race, but that would deliberately allow restart-continuation replay to overlap gateway teardown.
  3. Replace after rebase if needed
    If resolving the dirty branch through current gateway shutdown changes is too invasive, keep the canonical issue open and use a narrower replacement PR for the same retry wake.

Next step before merge

  • [P1] Human follow-up is needed because the branch is conflicting, has a blocking shutdown lifecycle defect, and needs contributor real behavior proof for the latest changes.

Security
Cleared: No dependency, workflow, secret-handling, package, or supply-chain surface changed; the concern is functional delivery lifecycle risk.

Review findings

  • [P1] Drain in-flight recovery before shutdown — src/gateway/server-runtime-services.ts:181-194
Review details

Best possible solution:

Make the retry loop shutdown-owned: stop scheduling after close starts, track and await or suppress any active recovery before channel teardown, keep the sentinel handoff ordering, then refresh real behavior proof for the latest lifecycle change.

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

Yes. Current main source shows only a one-shot 1,250 ms restart-continuation recovery while failed session-delivery entries persist retry/backoff metadata; I did not run a live Telegram outage scenario.

Is this the best way to solve the issue?

No. The periodic retry direction is plausible for the missing wake, but the callback is fire-and-forget and not drained by the close path, so this is not yet the best lifecycle-safe fix.

Full review comments:

  • [P1] Drain in-flight recovery before shutdown — src/gateway/server-runtime-services.ts:181-194
    The interval callback starts an async recovery task with void, but the returned stop handle only clears the timeout and interval. If the callback has already fired before close prelude calls stopSessionDeliveryRecovery, recovery can still deliver queued restart-continuation messages while channels and sidecars are shutting down. Track a stopped signal plus the active promise and await or suppress it from the close path.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: The PR targets a real restart-continuation message-loss bug with limited blast radius, but it is not a whole-runtime emergency.
  • merge-risk: 🚨 message-delivery: The new periodic recovery can deliver queued restart-continuation messages while shutdown is already underway if its callback fired before the stop handle ran.
  • merge-risk: 🚨 session-state: The PR changes restart/session-delivery recovery timing and interacts with adjacent duplicate-replay and restart lifecycle state.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The terminal proof covers the original 60-second retry path, but not the latest shutdown-sidecar and delayed-sentinel behavior; add redacted terminal/log/live output in the PR body and request re-review if needed. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +74, Tests +113. Total +187 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 7 95 21 +74
Tests 3 117 4 +113
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 212 25 +187

What I checked:

  • Current main still has startup-only recovery: Current main schedules restart-continuation session-delivery recovery through one 1,250 ms timeout and does not install a periodic retry loop, so the PR is not obsolete on main. (src/gateway/server-runtime-services.ts:155, 55ed57a4e39b)
  • PR head starts fire-and-forget periodic recovery: The PR head adds a 60-second interval whose callback starts an async recovery task with void; the returned stop handle clears future timers but does not track or await an already-fired callback. (src/gateway/server-runtime-services.ts:181, d45584459116)
  • Close prelude calls a synchronous stop hook: The PR wires stopSessionDeliveryRecovery into close prelude as a synchronous callback, which cannot await a periodic recovery promise that is already running. (src/gateway/server.impl.ts:992, d45584459116)
  • Latest sentinel handoff change is test/comment-backed only: The PR head delays sentinel removal until after notice delivery and continuation drain, but the PR body's real behavior proof still demonstrates only the periodic retry probe, not this latest shutdown/sentinel handoff behavior. (src/gateway/server-restart-sentinel.ts:620, d45584459116)
  • Maintainer review already requested lifecycle serialization: A live changes-requested review from vincentkoc said the retry direction is useful but must serialize restart-sentinel producer work with gateway shutdown before landing. (d45584459116)
  • Canonical linked issue remains open: The PR uses closing syntax for [Bug] Restart-sentinel continuation can get stuck after transient Telegram sendMessage failure #76087, which remains open and should stay open until this or a replacement fix lands.

Likely related people:

  • vincentkoc: Submitted the live changes-requested review on this PR and has recent history touching the gateway runtime/restart-sentinel/session-delivery files in this area. (role: reviewer and recent gateway lifecycle contributor; confidence: high; commits: e085fa1a3ffd, 9c32c2bf2613, 74e7b8d47b18; files: src/gateway/server-runtime-services.ts, src/gateway/server-restart-sentinel.ts, src/infra/session-delivery-queue-recovery.ts)
  • steipete: Merged and co-authored the gateway scheduled-services deferral work that owns when recovery starts after sidecars are ready. (role: scheduled-services merger and adjacent owner; confidence: medium; commits: 6a7961736a83, 4fec8073b12b, 63965dc70ba0; files: src/gateway/server-runtime-services.ts, src/gateway/server.impl.ts, src/gateway/server-close.ts)
  • lml2468: Authored the PR that deferred cron, heartbeat, and recovery activation until gateway sidecars are ready, which is the startup seam this PR extends. (role: scheduled-services behavior author; confidence: medium; commits: c7f6a670c36e; files: src/gateway/server-runtime-services.ts)
  • gumadeiras: Introduced the split gateway startup/runtime/close seams that this PR now threads through for sidecar and shutdown lifecycle handling. (role: gateway seam refactor author; confidence: medium; commits: 8de63ca26825, 9c44f100266e; files: src/gateway/server-runtime-services.ts, src/gateway/server-startup-post-attach.ts, src/gateway/server-close.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.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 5, 2026
@sahibzada-allahyar

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 5, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 5, 2026
@sahibzada-allahyar

Copy link
Copy Markdown
Contributor Author

Pushed the lifecycle-owned retry repair in a5a31a0.

Exact verification run after the patch:

node scripts/run-vitest.mjs src/gateway/server-runtime-services.test.ts src/gateway/server-close.test.ts src/gateway/server-restart-sentinel.test.ts src/infra/session-delivery-queue.recovery.test.ts

[test] starting test/vitest/vitest.gateway.config.ts
Test Files  6 passed (6)
Tests  140 passed (140)

[test] starting test/vitest/vitest.infra.config.ts
Test Files  1 passed (1)
Tests  6 passed (6)

[test] passed 2 Vitest shards in 14.37s

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 5, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 Jun 5, 2026
@sahibzada-allahyar

Copy link
Copy Markdown
Contributor Author

Pushed follow-up commit 6f2323e to address the periodic retry cutoff review. The periodic retry now uses a fresh cutoff instead of the startup maxEnqueuedAt, while the initial startup recovery remains guarded.

Exact verification after the patch:

node scripts/run-vitest.mjs src/gateway/server-runtime-services.test.ts src/gateway/server-close.test.ts src/gateway/server-restart-sentinel.test.ts src/infra/session-delivery-queue.recovery.test.ts

[test] starting test/vitest/vitest.gateway.config.ts
Test Files  6 passed (6)
Tests  142 passed (142)

[test] starting test/vitest/vitest.infra.config.ts
Test Files  1 passed (1)
Tests  6 passed (6)

[test] passed 2 Vitest shards in 13.74s

git diff --check -- src/gateway/server-runtime-services.ts src/gateway/server-runtime-services.test.ts produced no output.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 5, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jun 5, 2026
@sahibzada-allahyar

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 5, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@sahibzada-allahyar

Copy link
Copy Markdown
Contributor Author

Follow-up lint cleanup pushed in commit b5a8a7a.\n\nWhat changed:\n- Removed the now-unnecessary non-null assertions in src/gateway/server-runtime-services.test.ts after the mock call type was made explicit.\n- Test-only change; no production behavior changed.\n\nVerification run locally:\n\ntext\npnpm lint --threads=8\n# passed\n\npnpm check:test-types\n# passed\n\npnpm oxfmt --check src/gateway/server-runtime-services.test.ts\n# passed during commit hook\n\n\n@clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026

@vincentkoc vincentkoc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This retry direction is useful, but the current lifecycle is not safe enough to land. The fix needs to serialize restart-sentinel producer work with gateway shutdown; otherwise it can still deliver after close or lose restart state.

Findings:

  • P1: late-registered restart sidecar shutdown is not awaited. The new restart-sentinel sidecar can be created while close has already drained runtimeState.postReadySidecars. stopPostReadySidecarsAfterCloseStarted() currently calls void postReadySidecar.stop() for late registration, so the async stop promise that waits for restartSentinelWakePromise can be dropped. That reopens the race where sentinel/queue work continues after shutdown proceeds. The sidecar needs to be registered before it can start, or late-stop promises need to be tracked and awaited by the close path.

  • P1: the sentinel is removed before the restart notice has a durable handoff. removeRestartSentinelFile() runs before deliverRestartSentinelNotice(). If shutdown aborts after removal and before the notice is enqueued/sent, deliverRestartSentinelNotice() exits on the aborted signal and there is no sentinel file or outbound queue row left. For notice-only sentinels, the in-memory wake dies with the closing process, so the restart/update result can be lost. Keep/restore the sentinel on abort or durably enqueue the notice before deleting the sentinel.

Best-fix verdict: not landable as a small PR. This should either narrow to retrying only pre-startup abandoned rows, or grow into an explicit lifecycle/ownership fix with shutdown-aware producer tracking and durable handoff ordering.

@clawsweeper clawsweeper Bot added 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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jun 14, 2026
Address review findings on restart-continuation retry lifecycle:

- P1: track and await stop() promises for sidecars registered after close
  started, instead of dropping them via void stop(). The restart-sentinel
  sidecar's stop() awaits the sentinel wake, so dropping it let producer
  work continue past shutdown. stopPostReadySidecarsAfterCloseStarted now
  returns the stop promises; the close path awaits them.

- P1: remove the restart sentinel file only after the notice has a durable
  handoff (continuation enqueued/drained and notice delivered). Previously
  removal ran before delivery, so an abort in between lost the notice.
  Delivery is now at-least-once (replayed on next boot) rather than lost.
@sahibzada-allahyar

Copy link
Copy Markdown
Contributor Author

Thanks @vincentkoc — both P1s addressed in d455844:

P1 — late-registered sidecar stop not awaited. stopPostReadySidecarsAfterCloseStarted() no longer fires void postReadySidecar.stop(); it now returns the stop promises. The two post-attach callbacks push them into a new runtimeState.lateSidecarStopPromises tracker, and the close path awaits that list (Promise.allSettled) in the post-ready-sidecars step alongside the drained snapshot. A sidecar that registers after the snapshot is taken — including the restart-sentinel sidecar whose stop() waits on the sentinel wake — is now drained before shutdown proceeds instead of being dropped.

P1 — sentinel removed before durable handoff. removeRestartSentinelFile() now runs after the continuation is enqueued/drained and the notice is delivered, rather than before. If shutdown aborts mid-delivery the sentinel survives and is replayed on the next boot, so the restart/update notice is at-least-once instead of silently lost.

Added regression coverage: post-attach test asserts the stop promises are returned and stay pending until the sidecar's stop() resolves; restart-sentinel test asserts removeRestartSentinelFile is invoked strictly after deliverOutboundPayloads (invocation-order check). Full gateway suite green locally (105/105), oxlint + tsc clean.

Re-requesting review when you have a moment.

@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 2, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(gateway): retry restart continuation recovery This is item 1/1 in the current shard. Shard 3/4.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

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

Labels

gateway Gateway runtime merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Restart-sentinel continuation can get stuck after transient Telegram sendMessage failure

2 participants