Skip to content

Commit 7026cf2

Browse files
authored
fix(delivery): bound failed-row retention lifecycle (#123410)
1 parent 9122db3 commit 7026cf2

82 files changed

Lines changed: 7229 additions & 416 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.

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ enum class GatewayMethod(
581581
PortalList("portal.list"),
582582
PortalOpen("portal.open"),
583583
PortalClose("portal.close"),
584+
DeliveryFailuresResubmit("delivery.failures.resubmit"),
584585
}
585586

586587
enum class GatewayEvent(

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,22 @@ public enum TaskSuggestionResolution: String, Codable, Sendable {
194194
case expired = "expired"
195195
}
196196

197+
public enum DeliveryFailureResubmitReason: String, Codable, Sendable {
198+
case notFound = "not_found"
199+
case notFailed = "not_failed"
200+
case legacyUnknown = "legacy_unknown"
201+
case compacted = "compacted"
202+
case ownerManaged = "owner_managed"
203+
case ambiguous = "ambiguous"
204+
case fenced = "fenced"
205+
case missingPayload = "missing_payload"
206+
case missingMedia = "missing_media"
207+
case ownershipChanged = "ownership_changed"
208+
case migrationNamespace = "migration_namespace"
209+
case unsupportedQueue = "unsupported_queue"
210+
case ambiguousQueue = "ambiguous_queue"
211+
}
212+
197213
public enum SystemChangeKind: String, Codable, Sendable {
198214
case operation = "operation"
199215
case configWrite = "config-write"
@@ -10943,6 +10959,68 @@ public struct ConfigSchemaLookupResult: Codable, Sendable {
1094310959
}
1094410960
}
1094510961

10962+
public struct DeliveryFailureResubmitParams: Codable, Sendable {
10963+
public let id: String
10964+
public let queuename: String?
10965+
10966+
public init(
10967+
id: String,
10968+
queuename: String? = nil)
10969+
{
10970+
self.id = id
10971+
self.queuename = queuename
10972+
}
10973+
10974+
private enum CodingKeys: String, CodingKey {
10975+
case id
10976+
case queuename = "queueName"
10977+
}
10978+
}
10979+
10980+
public struct DeliveryFailureResubmitSuccessResult: Codable, Sendable {
10981+
public let ok: Bool
10982+
public let queuename: String
10983+
public let disposition: AnyCodable
10984+
10985+
public init(
10986+
ok: Bool,
10987+
queuename: String,
10988+
disposition: AnyCodable)
10989+
{
10990+
self.ok = ok
10991+
self.queuename = queuename
10992+
self.disposition = disposition
10993+
}
10994+
10995+
private enum CodingKeys: String, CodingKey {
10996+
case ok
10997+
case queuename = "queueName"
10998+
case disposition
10999+
}
11000+
}
11001+
11002+
public struct DeliveryFailureResubmitRefusedResult: Codable, Sendable {
11003+
public let ok: Bool
11004+
public let queuename: String?
11005+
public let reason: DeliveryFailureResubmitReason
11006+
11007+
public init(
11008+
ok: Bool,
11009+
queuename: String? = nil,
11010+
reason: DeliveryFailureResubmitReason)
11011+
{
11012+
self.ok = ok
11013+
self.queuename = queuename
11014+
self.reason = reason
11015+
}
11016+
11017+
private enum CodingKeys: String, CodingKey {
11018+
case ok
11019+
case queuename = "queueName"
11020+
case reason
11021+
}
11022+
}
11023+
1094611024
public struct SystemAgentChatParams: Codable, Sendable {
1094711025
public let sessionid: String
1094811026
public let message: String?
@@ -20122,6 +20200,31 @@ public enum AuditRunIdentityV1: Codable, Sendable {
2012220200
}
2012320201
}
2012420202

20203+
public enum DeliveryFailureResubmitResult: Codable, Sendable {
20204+
case success(DeliveryFailureResubmitSuccessResult)
20205+
case failure(DeliveryFailureResubmitRefusedResult)
20206+
20207+
private enum CodingKeys: String, CodingKey {
20208+
case discriminator = "ok"
20209+
}
20210+
20211+
public init(from decoder: Decoder) throws {
20212+
let container = try decoder.container(keyedBy: CodingKeys.self)
20213+
let discriminator = try container.decode(Bool.self, forKey: .discriminator)
20214+
switch discriminator {
20215+
case true: self = try .success(DeliveryFailureResubmitSuccessResult(from: decoder))
20216+
case false: self = try .failure(DeliveryFailureResubmitRefusedResult(from: decoder))
20217+
}
20218+
}
20219+
20220+
public func encode(to encoder: Encoder) throws {
20221+
switch self {
20222+
case .success(let value): try value.encode(to: encoder)
20223+
case .failure(let value): try value.encode(to: encoder)
20224+
}
20225+
}
20226+
}
20227+
2012520228
public enum ApprovalPresentation: Codable, Sendable {
2012620229
case exec(ExecApprovalPresentation)
2012720230
case plugin(PluginApprovalPresentation)

‎docs/cli/backup.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ The repository contains one directory per committed snapshot. Each snapshot dire
9696
- `manifest.json`
9797
- `database.sqlite`
9898

99-
Snapshot creation verifies the live database before reading it, uses SQLite's online backup API to capture committed WAL state without holding one long read transaction, closes the live database, compacts the private copy with `VACUUM`, verifies the generated database again, and publishes the completed directory without overwriting existing paths. Global snapshots remove transient delivery queue rows before compaction so deleted queue payloads are not retained in free pages.
99+
Snapshot creation verifies the live database before reading it, uses SQLite's online backup API to capture committed WAL state without holding one long read transaction, closes the live database, compacts the private copy with `VACUUM`, verifies the generated database again, and publishes the completed directory without overwriting existing paths. Global snapshots remove every delivery queue row before compaction, including pending work, failed ownership fences, and completion or idempotency receipts, so neither payload detail nor ownership tombstones are published or retained in free pages. Restoring this sanitized, portable snapshot is therefore not an exactly-once delivery continuation boundary. This is an intentional privacy and no-replay portability tradeoff.
100100

101101
Do not copy live `.sqlite`, `-wal`, `-shm`, or `-journal` files as a portability artifact. Copy only completed snapshot directories.
102102

‎docs/cli/delivery.md‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
summary: "Inspect, compact, purge, and safely resubmit retained delivery failures"
3+
read_when:
4+
- A session or outbound delivery is dead-lettered
5+
- You need to remove sensitive failed-delivery detail without breaking idempotency
6+
title: "Delivery failures"
7+
---
8+
9+
# `openclaw delivery failures`
10+
11+
OpenClaw keeps failed outbound and session deliveries separate from the live
12+
retry queue. The failure record can retain diagnostic or recovery detail for a
13+
bounded time while its compact tombstone continues to own a stable delivery ID.
14+
15+
## List failure metadata
16+
17+
```bash
18+
openclaw delivery failures list
19+
openclaw delivery failures list --queue outbound-prepared-v1 --limit 50
20+
openclaw delivery failures list --json
21+
openclaw delivery failures list --exact-ids
22+
```
23+
24+
The default limit is 100 and the hard maximum is 500. Output includes queue,
25+
age, detail state, replay classification, fence policy, reason code, and retry
26+
count. It never includes the message or payload, route, target, account,
27+
session key, media path, or raw provider error.
28+
29+
Stable identifiers can contain routing identity, so human and JSON output use
30+
a repeatable SHA-256 fingerprint by default. Pass `--exact-ids` only when an
31+
exact identifier is needed for a follow-up command. Producer-bounded fences
32+
similarly show an `idPrefixFingerprint` by default; `--exact-ids` also reveals
33+
their exact producer prefix.
34+
35+
## Preview or apply retention cleanup
36+
37+
```bash
38+
openclaw delivery failures purge
39+
openclaw delivery failures purge --queue session
40+
openclaw delivery failures purge --apply --yes
41+
```
42+
43+
`purge` is a dry run by default. Apply mode deletes only expired diagnostic
44+
rows whose policy has no fence, plus producer-bounded fences after their
45+
authored age or producer-local count limit expires. Unexpired producer-bounded,
46+
permanent, and owner-managed records keep their ownership tombstone while
47+
sensitive detail is compacted. Dry-run and apply use the same bounded row set;
48+
`--queue` and `--limit` scope both modes identically.
49+
50+
There is no option to force-break a fence. Without `--yes`, apply mode prompts
51+
in an interactive terminal and refuses in JSON or other non-interactive use.
52+
53+
Logical compaction clears payload-bearing JSON, raw errors, and denormalized
54+
session/channel/target/account metadata. SQLite can continue to reserve the
55+
freed pages inside the database file. To return free pages to the filesystem,
56+
stop the Gateway and run [`openclaw doctor --state-sqlite compact`](/cli/doctor#shared-state-sqlite-compaction).
57+
58+
## Safely resubmit one failure
59+
60+
```bash
61+
openclaw delivery failures resubmit <id>
62+
openclaw delivery failures resubmit <id> --queue session
63+
openclaw delivery failures resubmit <id> --queue outbound-prepared-v1
64+
openclaw delivery failures resubmit <id> --url ws://127.0.0.1:18789 --token <token>
65+
```
66+
67+
`resubmit` requires a running, reachable Gateway and accepts the standard
68+
Gateway client options: `--url`, `--token`, `--password`, and `--timeout`. The
69+
Gateway performs the failed-to-pending transition and immediately schedules an
70+
eligible session row in its live delivery runtime. If the runtime is still
71+
starting or immediate scheduling fails after that durable transition, the
72+
command reports that the row remains queued for startup recovery. A connection
73+
or authentication failure occurs before the row changes.
74+
75+
Session and outbound queues have independent ID namespaces. If both own the
76+
same ID, an unqualified resubmit is refused; rerun with the exact `--queue`
77+
namespace shown by `openclaw delivery failures list --exact-ids`.
78+
79+
Success means **queued for recovery**, not delivered. Outbound rows are picked
80+
up by the Gateway's bounded outbound recovery interval; the command does not
81+
claim recipient delivery or start a second recovery loop.
82+
83+
Generic resubmit is intentionally narrow. Outbound rows require an explicit
84+
pre-side-effect classification, a full canonical prepared payload, no durable
85+
owner or stable fence, and every queue-owned media file. Session rows require
86+
full detail, no owner, no delivery-start or settlement marker, and no ambiguity.
87+
The Gateway's failed-to-pending transition is atomic, so a second invocation
88+
does not submit the same row again.
89+
90+
Stable outbound IDs and claimed session producers retain failed ownership even
91+
when successful sends would not keep a completion receipt.
92+
93+
OpenClaw refuses cross-queue ambiguity, compacted, ambiguous, owner-managed,
94+
legacy-unknown, migration-namespace, missing-media, and stale-owner rows.
95+
Subagent completion failures remain under their owner commands:
96+
97+
```bash
98+
openclaw tasks retry <task-id>
99+
openclaw tasks dismiss <task-id>
100+
```
101+
102+
## Backups and retained bytes
103+
104+
Global SQLite snapshots remove every delivery queue row before publishing the
105+
snapshot, including pending work, failed fences, and completion or idempotency
106+
receipts. Restoring one is not an exactly-once delivery continuation; the
107+
sanitized artifact deliberately chooses privacy and no-replay portability over
108+
queue continuity. A normal state backup can contain the live database, so
109+
protect it like other sensitive OpenClaw state. Logical retention and SQLite
110+
file-size reclamation are separate operations; use the explicit doctor
111+
compaction flow when physical reclamation is required.
112+
113+
## Related
114+
115+
- [`openclaw health`](/cli/health)
116+
- [`openclaw doctor`](/cli/doctor)
117+
- [Restart recovery](/gateway/restart-recovery)

‎docs/cli/doctor.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ When Gateway status reports degraded SecretRef owners, doctor prints a **Secret
1414

1515
When channel ingress events are dead-lettered, doctor names each affected channel account and points to [`openclaw channels dead-letters list`](/cli/channels#inbound-dead-letters) for inspection and recovery.
1616

17+
When outbound or session failures are retained, doctor reports queue counts,
18+
payload-bearing and legacy-unknown rows, owner cleanup still pending in either
19+
the provider or exact-media phase, and retention-maintenance failures.
20+
Inspect them with [`openclaw delivery failures list`](/cli/delivery); subagent
21+
completion recovery remains under `openclaw tasks retry` and `tasks dismiss`.
22+
1723
When the Gateway has exporter health facts, doctor reports the latest trusted
1824
per-signal state and transport under **Telemetry exporters**. The summary is
1925
redacted and does not include endpoint values, headers, certificates, payloads,
@@ -262,6 +268,10 @@ JSON output reports the database and WAL sizes, freelist pages, page size, and
262268
fail-closed and has no separate success field. SQLite reports `auto_vacuum` as
263269
`0` for none, `1` for full, and `2` for incremental.
264270

271+
Delivery failure cleanup first removes sensitive logical content while keeping
272+
any required ownership tombstone. This command performs the separate physical
273+
SQLite reclamation step; it does not resubmit deliveries or break fences.
274+
265275
Compaction fails without mutation when the schema is old, newer than the
266276
running OpenClaw build, or belongs to an agent database. Run
267277
`openclaw doctor --fix` first for an older shared-state schema. Restore a

‎docs/cli/health.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ openclaw health --debug
3434
- `--verbose` forces a live probe (per-channel account probes), prints Gateway connection details, and expands human-readable output across all configured accounts and agents instead of just the default agent.
3535
- `--json` always returns the full snapshot: channels, per-account probes, plugin load state, context-engine quarantine state, model-pricing cache state, event-loop health, delivery-queue warnings, and per-agent session stores.
3636
- Top-level `ok: true` means the health RPC succeeded and the Gateway produced a snapshot. Queue warnings do not change it to `false`.
37-
- When outbound deliveries or inbound channel events are dead-lettered, text output reports their counts and oldest failure age. Inbound counts are grouped by channel account; inspect or recover individual events with [`openclaw channels dead-letters`](/cli/channels#inbound-dead-letters).
37+
- When outbound or session deliveries are dead-lettered, text output reports classification counts, the oldest payload-bearing failure, and retention-maintenance errors without exposing content. The owner-cleanup-pending count includes both provider cleanup still owed and exact media removal awaiting retry. Inspect failures with [`openclaw delivery failures list`](/cli/delivery). Inbound counts are grouped by channel account; inspect or recover individual events with [`openclaw channels dead-letters`](/cli/channels#inbound-dead-letters).
3838
- Optional `deliveryQueues.ingressPressure` summarizes durable inbound lanes that may be blocking later events. It is grouped by channel account and never exposes event, lane, payload, error, owner, token, session, or target identifiers. See [Gateway health](/gateway/health#queue-warnings) for the exact qualification and counting semantics.
3939

4040
## Related

‎docs/cli/index.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Setup commands by intent:
2424
| Setup and onboarding | [`openclaw`](/cli/openclaw) · [`setup`](/cli/setup) · [`onboard`](/cli/onboard) · [`configure`](/cli/configure) · [`config`](/cli/config) · [`completion`](/cli/completion) · [`doctor`](/cli/doctor) · [`dashboard`](/cli/dashboard) |
2525
| Reset, backup, and migration | [`backup`](/cli/backup) · [`migrate`](/cli/migrate) · [`reset`](/cli/reset) · [`uninstall`](/cli/uninstall) · [`update`](/cli/update) |
2626
| Messaging and agents | [`message`](/cli/message) · [`agent`](/cli/agent) · [`agents`](/cli/agents) · [`attach`](/cli/attach) · [`acp`](/cli/acp) · [`mcp`](/cli/mcp) |
27-
| Health and sessions | [`status`](/cli/status) · [`health`](/cli/health) · [`sessions`](/cli/sessions) · [`resume`](/cli/resume) · [`audit`](/cli/audit) |
27+
| Health and sessions | [`status`](/cli/status) · [`health`](/cli/health) · [`delivery`](/cli/delivery) · [`sessions`](/cli/sessions) · [`resume`](/cli/resume) · [`audit`](/cli/audit) |
2828
| Gateway and logs | [`gateway`](/cli/gateway) · [`logs`](/cli/logs) · [`system`](/cli/system) |
2929
| Models and inference | [`models`](/cli/models) · [`promos`](/cli/promos) · [`infer`](/cli/infer) · `capability` (alias for [`infer`](/cli/infer)) · [`memory`](/cli/memory) · [`wiki`](/cli/wiki) |
3030
| Network and nodes | [`directory`](/cli/directory) · [`nodes`](/cli/nodes) · [`devices`](/cli/devices) · [`node`](/cli/node) · [`worker`](/cli/worker) |
@@ -242,6 +242,11 @@ openclaw [--dev] [--profile <name>] <command>
242242
unset
243243
status
244244
health
245+
delivery
246+
failures
247+
list
248+
purge
249+
resubmit <id>
245250
sessions
246251
cleanup
247252
audit

‎docs/docs.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,7 @@
18071807
"cli/backup",
18081808
"cli/openclaw",
18091809
"cli/daemon",
1810+
"cli/delivery",
18101811
"cli/doctor",
18111812
"cli/fleet",
18121813
"cli/gateway",

0 commit comments

Comments
 (0)