Skip to content

Commit 0a86817

Browse files
zhangguiping-xydthxy91819steipete
authored
fix(session): stop repeated restart recovery after retry budget (#96230)
* fix(session): bound restart recovery across gateway restarts Co-authored-by: Mason Huang <[email protected]> * style(session): format restart recovery changes * fix(session): fence recovery notice state * test(session): align internal recovery types * test(session): type recovery completion fixture * style(session): satisfy recovery lint rules * test(plugin-sdk): split recovery boundary coverage * test(plugin-sdk): use tracked recovery temp dirs * fix(session): preserve stale admission errors * fix(session): close recovery lifecycle races * fix(session): rotate rejected recovery dispatch ids * fix(session): enforce recovery quarantine boundaries * fix(session): close restart recovery exhaustion gaps * fix(session): preserve recovery command narrowing * test(session): type restart recovery fixtures * fix(session): enforce restart recovery quarantine * fix(session): close restart recovery races * fix(session): type recovery lifecycle state * fix(session): enforce recovery ownership fences * fix(session): fence recovery lifecycle completion * fix(session): quarantine cross-process recovery * fix(session): retire stale recovery ownership * fix(session): restore rejected recovery admission * fix(session): preserve restored recovery target * fix(session): retry pending recovery races * fix(session): preserve concurrent recovery aborts * fix(session): quarantine recovery lifecycle state * fix(session): settle exact recovery delivery fences * fix(session): keep recovery restoration internal * fix(session): close recovery admission races * fix(session): retry durable recovery rollback * fix(session): guard cached recovery settlement * fix(session): close recovery ownership gaps * fix(session): resume after delayed recovery rollback * fix(session): finalize unrecoverable restart state * fix(session): retry admitted recovery restoration * fix(session): preserve recovery cleanup guarantees * fix(session): restore failed terminal settlement * chore(plugin-sdk): refresh API baseline * fix(session): close recovery owner retry races * test(session): type recovery owner fixture * refactor(session): remove obsolete owner validator * fix(session): preserve explicit abort recovery --------- Co-authored-by: Mason Huang <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent 90ab572 commit 0a86817

89 files changed

Lines changed: 8840 additions & 639 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
dc2bf410e15972389b8e60d772f92731130148845dff24294fae4786d3b9f41a plugin-sdk-api-baseline.json
2-
ce076f7e71bb1ffbd0eead42a178dd069e15693348c4fd69b2ed291d51a8fcd7 plugin-sdk-api-baseline.jsonl
1+
16f7664192e83f3e689685ecc917fa0578db5686646d3e7277ba866f07e1002d plugin-sdk-api-baseline.json
2+
f8c7d2a77b258f347bd6b741461990c57c4f70d85d91d05b2526829e2980df60 plugin-sdk-api-baseline.jsonl

‎docs/cli/agent.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ openclaw agent --agent ops --message "Run locally" --local
5353
- Pass exactly one of `--message` or `--message-file`. `--message-file` strips a leading UTF-8 BOM and preserves multiline content; it rejects files that are not valid UTF-8.
5454
- Slash commands (for example `/compact`) cannot run through `--message`. The CLI rejects them and points you at the first-class command instead (`openclaw sessions compact <key>` for compaction).
5555
- `--local` and embedded fallback runs are one-shot: bundled MCP loopback resources and warm Claude stdio sessions opened for the run are retired after the reply, so scripted invocations do not leave local child processes running. Gateway-backed runs keep Gateway-owned MCP loopback resources under the running Gateway process instead.
56+
- Standalone embedded execution (`--local` and transport fallback) refuses to reuse an existing main session while restart recovery is pending. Run the turn through a healthy Gateway, or reset it there with `/new` or `/reset`; an independent embedded process cannot safely coordinate that recovery owner with the Gateway scanner.
5657
- With `--agent`, `--channel` and `--to` together, session routing follows the channel's canonical recipient and `session.dmScope`. Channels with a stable outbound-only recipient identity use a provider-owned session isolated from the agent's main session. `--reply-channel` and `--reply-account` affect delivery only.
5758
- `--session-key` selects an explicit session key. Agent-prefixed keys must use `agent:<agent-id>:<session-key>`, and `--agent` must match the key's agent id when both are given. Bare non-sentinel keys scope to `--agent` when supplied, or to the configured default agent otherwise; for example `--agent ops --session-key incident-42` routes to `agent:ops:incident-42`. The literal keys `global` and `unknown` stay unscoped only when no `--agent` is supplied.
5859
- `--json` reserves stdout for the JSON response; Gateway, plugin, and embedded-fallback diagnostics go to stderr so scripts can parse stdout directly.

‎docs/gateway/doctor.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Flags:
170170
<Accordion title="State and integrity">
171171
- Session lock file inspection and stale lock cleanup.
172172
- Session transcript repair for duplicated prompt-rewrite branches created by affected 2026.4.24 builds.
173-
- Wedged subagent restart-recovery tombstone detection, with `--fix` support for clearing stale aborted recovery flags so startup does not keep treating the child as restart-aborted.
173+
- Wedged main-session and subagent restart-recovery tombstone detection. Doctor reports the blocked sessions and only repairs stale aborted flags that conflict with an existing tombstone; it does not re-enable automatic recovery.
174174
- State integrity and permissions checks (sessions, transcripts, state dir).
175175
- Config file permission checks (chmod 600) when running locally.
176176
- Model auth health: checks OAuth expiry, can refresh expiring tokens, and reports auth-profile cooldown/disabled states.

‎docs/gateway/restart-recovery.md‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ title: "Restart recovery"
1010
Restarting the gateway does not lose agent state. Conversations, transcripts,
1111
scheduled jobs, background task records, and queued outbound messages all live
1212
on disk, and work that was interrupted mid-turn is detected and resumed
13-
automatically after the gateway comes back up. No manual intervention is
14-
required, and there is nothing to configure: recovery is always on.
13+
automatically after the gateway comes back up. Recovery is always on and
14+
normally needs no manual intervention. Repeatedly failing recovery is bounded
15+
and may quarantine one session until you inspect or replace it.
1516

1617
This page describes what survives a restart, how interrupted work is detected,
1718
and what the automatic resume looks like.
@@ -75,12 +76,26 @@ A few seconds after startup, the gateway re-dispatches each marked session
7576
with a synthetic system message telling the agent its previous turn was
7677
interrupted by a restart and to continue from the existing transcript. If a
7778
final reply had already been produced but not delivered, its text is included
78-
so the agent can deliver it instead of redoing the work. Recovery retries up
79-
to 3 times with exponential backoff. Every retry reuses one durable dispatch
80-
identifier, so an ambiguous connection failure cannot start the same recovery
81-
twice. Completed and unresumable Control UI turns also retain bounded durable
82-
idempotency tombstones, allowing a reconnecting outbox to retire them without
83-
re-executing the request.
79+
so the agent can deliver it instead of redoing the work.
80+
81+
Startup reconciliation retries transient failures up to three times with
82+
exponential backoff. Separately, each interrupted main-session cycle has a
83+
durable budget of three charged automatic dispatch attempts, retained across
84+
gateway restarts. OpenClaw charges an attempt before dispatch, refunds it when
85+
the gateway explicitly rejects the request before acceptance, and retains the
86+
charge when a post-dispatch result is uncertain to avoid replaying work.
87+
Foreground work that already owns the session keeps automatic recovery out
88+
until that work settles.
89+
90+
After the durable budget is exhausted, the session is tombstoned instead of
91+
looping forever. Inspect the failed session and use `/new` or `/reset` to start a
92+
replacement. `openclaw doctor --fix` can repair a stale aborted flag that
93+
conflicts with a tombstone, but it does not re-enable that recovery cycle.
94+
95+
Every retry reuses one durable dispatch identifier, so an ambiguous connection
96+
failure cannot start the same recovery twice. Completed and unresumable Control
97+
UI turns also retain bounded durable idempotency tombstones, allowing a
98+
reconnecting outbox to retire them without re-executing the request.
8499

85100
Message-tool-only replies use a second durable correlation. Before a terminal
86101
same-conversation send reaches the channel, the gateway records an unresolved
@@ -149,6 +164,9 @@ agent picks up exactly where it left off, on the same channel and thread.
149164
- **Crash-loop breaker:** 3 unclean boots within 5 minutes trip a breaker that
150165
suppresses auto-start side services on the next boot, so a crashing gateway
151166
does not amplify itself. It recovers once the unclean-boot window drains.
167+
- **Main-session attempt budget:** three charged automatic dispatch attempts
168+
per interrupted cycle; exhaustion tombstones that session until it is
169+
inspected and replaced.
152170
- **Metrics:** recovery activity is exported via
153171
[Prometheus](/gateway/prometheus) as `openclaw_session_recovery_total` and
154172
`openclaw_session_recovery_age_seconds`.
@@ -167,3 +185,6 @@ agent picks up exactly where it left off, on the same channel and thread.
167185
- Work that was never admitted: messages arriving during the drain window are
168186
rejected with an explicit restart error rather than silently queued into a
169187
dying process.
188+
- Standalone embedded turns cannot take over a main session with pending
189+
restart recovery because they do not share the gateway's lifecycle owner.
190+
Run the turn through the gateway or reset it there with `/new` or `/reset`.

0 commit comments

Comments
 (0)