Skip to content

Commit f2112c7

Browse files
Merge current main into PR #131750 preparation
2 parents aa9e3d8 + a6ccf6a commit f2112c7

26 files changed

Lines changed: 999 additions & 345 deletions

‎docs/channels/line.md‎

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ openclaw plugins install ./path/to/local/line-plugin
4242
https://gateway-host/line/webhook
4343
```
4444

45-
The Gateway answers LINE's webhook verification (GET). For signed inbound events
46-
(POST), it writes each event to the durable ingress queue before returning `200`;
47-
agent processing continues asynchronously. Failed delivery is retried from the
48-
queue, including after a Gateway restart, and poison events become failed queue
49-
records after bounded retries. If durable persistence fails, the request returns
45+
The Gateway answers LINE's signed webhook verification request: a `POST` with an
46+
empty `events` list. For signed inbound events, it writes each event to the durable
47+
ingress queue before returning `200`; agent processing continues asynchronously.
48+
Failed delivery is retried from the queue, including after a Gateway restart, and
49+
poison events become failed queue records after bounded retries. If durable
50+
persistence fails, the request returns
5051
`500` instead of acknowledging an event that could be lost.
5152
Delivery is at least once across the queue-to-agent boundary: a Gateway shutdown or
5253
crash during an active delivery can replay the turn. Message events deduplicate by
@@ -61,6 +62,77 @@ Security notes:
6162
- LINE signature verification is body-dependent (HMAC over the raw body), so OpenClaw applies a strict pre-auth body limit (64 KB) and read timeout before verification.
6263
- OpenClaw processes webhook events from the verified raw request bytes. Upstream middleware-transformed `req.body` values are ignored for signature-integrity safety.
6364

65+
## Inbound durability
66+
67+
The [Setup](#setup) webhook contract acknowledges an event only after it is durably
68+
queued. The durable `200` carries `x-openclaw-delivery-accepted: durable`; signed
69+
verification pings (empty event lists) and error responses omit the marker, so
70+
reverse proxies can require it to distinguish durable acceptance from a generic
71+
`200`. From there, delivery runs through the core channel-ingress drain with
72+
LINE-specific settings:
73+
74+
- **Per-conversation ordering.** Events are serialized by source lane —
75+
`group:<groupId>`, `room:<roomId>`, or `user:<userId>`; events without a
76+
conversation source use their own event-scoped lane. Within a lane, events
77+
dispatch in received order, so a retrying event delays later events in the same
78+
chat. One chat's backlog never blocks another chat's lane, but all lanes share
79+
a cap of 8 concurrent deliveries: other chats progress independently while a
80+
slot is free, and a 9th lane waits for one to open.
81+
- **Retries.** A failed delivery retries with exponential backoff starting at
82+
1 second and doubling per attempt, roughly two minutes of cumulative backoff
83+
across the window. After the 8th failed attempt the event dead-letters
84+
(`retry-limit-exceeded`) immediately: LINE opts out of the generic 24-hour
85+
dead-letter age floor so a poison event cannot block its conversation lane for
86+
a day.
87+
- **Non-retryable failures.** These dead-letter immediately, with no further
88+
retries regardless of the attempt count: stored payloads that no longer parse
89+
(`invalid-event`), deliveries that already committed side effects
90+
(`delivery-side-effects-committed`), and LINE API authentication failures
91+
(`authentication-failed`, HTTP 401/403).
92+
- **Stall watchdog.** A claimed delivery that neither reaches agent-turn adoption
93+
nor reports continued deferred progress for 5 minutes is aborted and released
94+
back to its lane through the same retry policy as any other failure: the event
95+
returns to pending with its attempt count incremented and `handler-timeout`
96+
recorded as its last error, and it keeps its place at the head of its lane. A
97+
stall is not itself a dead letter — only the retry limit above ends the event,
98+
as `retry-limit-exceeded`. The watchdog only covers the window between claim
99+
and adoption: deferred progress re-arms it and adoption clears it, so a long
100+
agent turn is never interrupted by it. Adoption that arrives after the
101+
watchdog fires is fenced off, so a late turn cannot claim an event that has
102+
already been handed back.
103+
- **Crash recovery.** Every drain pass opens with a recovery sweep that reclaims
104+
any claim whose owning Gateway process is no longer running, so a delivery lost
105+
to a hard crash is retried on the next sweep rather than after a timeout. The
106+
30-minute claim lease is the fallback bound for the opposite case: without a
107+
successful lease refresh, it caps how long a claim stays protected solely
108+
because its owner PID still looks alive — including a reused PID whose process
109+
identity cannot be verified. Events accepted while the Gateway is stopping are
110+
still persisted and drain after the next start.
111+
- **Duplicate suppression window.** On every admission, LINE removes completed
112+
and failed queue records older than 30 days, then keeps the most recently
113+
updated 4096 records of each kind per account. Because pruning runs before the
114+
new event is queued rather than on a timer, records can remain past 30 days on
115+
an idle account, and a newly completed record can put the count above 4096 until
116+
the next admission. While a record exists, a redelivered webhook for the same
117+
event is acknowledged without a second dispatch; once it is gone — by age or by
118+
cap — a redelivery is admitted and dispatched again, so handlers with external
119+
side effects should not treat this window as a substitute for their own
120+
idempotency.
121+
122+
The `500`-on-persistence-failure contract only helps if LINE re-sends the event.
123+
LINE redelivers a webhook when **Webhook redelivery** is enabled for the channel in
124+
the LINE Developers Console (Messaging API settings, alongside **Use webhook**) and
125+
the bot server did not answer `2xx`. Without that setting, an event refused with
126+
`500` is not re-sent. Even enabled, redelivery is best effort rather than a
127+
guarantee: LINE documents that it is not reliable, that the retry count and
128+
interval are undisclosed, and that redelivered events may arrive out of order or
129+
more than once (the duplicate suppression window above absorbs the repeats). See
130+
[Redeliver a webhook that failed to be received](https://developers.line.biz/en/docs/messaging-api/receiving-messages/#webhook-redelivery).
131+
132+
Dead-lettered events stay inspectable and, depending on the failure reason,
133+
recoverable; see [Inbound dead letters](/cli/channels#inbound-dead-letters) and
134+
[Troubleshooting](#troubleshooting) below.
135+
64136
## Configure
65137

66138
Minimal config:
@@ -306,6 +378,32 @@ Generic media sends without LINE-specific options use the image route.
306378
and that the gateway is reachable from LINE.
307379
- **Media download errors:** raise `channels.line.mediaMaxMb` if media exceeds the
308380
default limit.
381+
- **Bot silently skips messages (events dead-lettered):** `openclaw logs` shows
382+
`line: spooled update <id> ... dead-lettered` lines with the failure reason.
383+
Inspect with `openclaw channels dead-letters list --channel line --account default`
384+
and check the failure reason before recovering: `resubmit` re-enqueues by event
385+
id without checking why the event failed. After fixing the cause of a failure
386+
with no committed side effects (for example `retry-limit-exceeded` after a
387+
provider outage), re-enqueue one event with
388+
`openclaw channels dead-letters resubmit <event-id> --channel line --account default`.
389+
Never resubmit a `delivery-side-effects-committed` event: that reason means the
390+
delivery already adopted an agent turn or consumed its reply token, so
391+
re-enqueuing repeats the committed work — for example a second visible reply.
392+
`openclaw health` reports dead-letter counts and `openclaw doctor` names
393+
affected accounts.
394+
- **`handler-timeout` retries:** the delivery was claimed but neither reached
395+
agent-turn adoption nor reported deferred progress for 5 minutes. This is a
396+
stall _before_ the turn starts —
397+
adoption clears the watchdog, so a turn that is already running is never the
398+
cause and is never cut off by it. Look at the dispatch path instead: the
399+
delivery preparation that runs between claim and adoption, such as inbound
400+
media download or a Gateway that is not accepting new work. This does not
401+
dead-letter the event; `openclaw logs` shows
402+
`applying retry policy (handler-timeout)` and the event waits out its backoff
403+
with `handler-timeout` as its last error. A stall that keeps repeating is what
404+
eventually exhausts the retry limit, so an event that stalls its way to a dead
405+
letter lands under `retry-limit-exceeded`, not under a timeout reason. Check
406+
`openclaw logs --follow` around the affected event id.
309407

310408
## Related
311409

‎src/agents/embedded-agent-runner/model.forward-compat.errors-and-overrides.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ vi.mock("../prepared-model-runtime.js", async () => {
9393
}) => {
9494
const config = input.config ?? {};
9595
return {
96+
catalogOwner: undefined,
9697
agentDir: input.agentDir,
9798
...(input.workspaceDir ? { workspaceDir: input.workspaceDir } : {}),
9899
activeProjectKeys: [],

‎src/agents/embedded-agent-runner/model.generation-scope.test-support.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export function createModelGenerationFixture(params: {
107107
return { authStorage, modelRegistry: ModelRegistry.inMemory(authStorage) };
108108
});
109109
const preparedModelRuntime = {
110+
catalogOwner: undefined,
110111
agentDir: "/tmp/openclaw-model-generation-agent",
111112
workspaceDir: GENERATION_WORKSPACE_DIR,
112113
activeProjectKeys: [],

‎src/agents/embedded-agent-runner/model.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ vi.mock("../prepared-model-runtime.js", async () => {
194194
Object.assign(modelRegistry, { fork: () => modelRegistry });
195195
}
196196
const snapshot = {
197+
catalogOwner: undefined,
197198
agentDir: input.agentDir,
198199
...(workspaceDir ? { workspaceDir } : {}),
199200
activeProjectKeys: [],
@@ -1077,6 +1078,7 @@ describe("resolveModel", () => {
10771078
models: [{ id: "deepseek-v4-pro", name: "Configured DeepSeek" }],
10781079
});
10791080
const preparedModelRuntime = {
1081+
catalogOwner: undefined,
10801082
agentDir: "/tmp/agent",
10811083
activeProjectKeys: [],
10821084
allowGatewaySubagentBinding: false,
@@ -1118,6 +1120,7 @@ describe("resolveModel", () => {
11181120
);
11191121

11201122
const preparedModelRuntime = {
1123+
catalogOwner: undefined,
11211124
agentDir: "/tmp/agent",
11221125
activeProjectKeys: [],
11231126
allowGatewaySubagentBinding: false,
@@ -1155,6 +1158,7 @@ describe("resolveModel", () => {
11551158
it("resolves opt-in provider static catalog rows while skipping agent discovery", async () => {
11561159
const metadataSnapshot = createPluginMetadataSnapshotFixture();
11571160
const preparedModelRuntime = {
1161+
catalogOwner: undefined,
11581162
agentDir: "/tmp/agent",
11591163
activeProjectKeys: [],
11601164
allowGatewaySubagentBinding: false,

‎src/agents/openclaw-tools.browser-plugin.integration.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ describe("createOpenClawTools browser plugin integration", () => {
499499
config,
500500
workspaceDir: "/tmp",
501501
preparedModelRuntime: {
502+
catalogOwner: undefined,
502503
agentDir: "/tmp/agent",
503504
workspaceDir: "/tmp",
504505
activeProjectKeys: [],

‎src/agents/prepared-model-catalog-owner.ts‎

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { normalizeAgentId } from "../routing/session-key.js";
2-
import { listAgentIds, resolveAgentDir, resolveAgentWorkspaceDir } from "./agent-scope.js";
2+
import { listAgentIds, resolveAgentDir, resolveAgentWorkspaceDir } from "./agent-scope-config.js";
33
import type {
44
PublishedModelCatalogOwnerCandidate,
55
ResolvedPublishedModelCatalogOwner,
66
} from "./prepared-model-catalog.types.js";
77
import { getPreparedModelRuntimeAuthStore } from "./prepared-model-runtime-auth.js";
8+
import type { PreparedModelRuntimeInput } from "./prepared-model-runtime.types.js";
89

910
class PublishedModelCatalogOwnerResolutionError extends Error {
1011
constructor(message: string) {
@@ -13,38 +14,48 @@ class PublishedModelCatalogOwnerResolutionError extends Error {
1314
}
1415
}
1516

16-
export function resolvePublishedModelCatalogOwner(
17-
snapshot: PublishedModelCatalogOwnerCandidate,
18-
): ResolvedPublishedModelCatalogOwner {
19-
const configuredAgentIds = listAgentIds(snapshot.config);
20-
const directoryAgentIds = configuredAgentIds.filter(
21-
(candidate) => resolveAgentDir(snapshot.config, candidate) === snapshot.agentDir,
22-
);
23-
const agentId = snapshot.agentId
17+
export function preparePublishedModelCatalogOwnerIdentity(
18+
input: PreparedModelRuntimeInput,
19+
): PublishedModelCatalogOwnerCandidate["catalogOwner"] {
20+
const env = input.env ?? process.env;
21+
const configuredAgentIds = listAgentIds(input.config);
22+
const directoryAgentIds = input.agentId
23+
? []
24+
: configuredAgentIds.filter(
25+
(candidate) => resolveAgentDir(input.config, candidate, env) === input.agentDir,
26+
);
27+
const agentId = input.agentId
2428
? configuredAgentIds.find(
25-
(candidate) => normalizeAgentId(candidate) === normalizeAgentId(snapshot.agentId),
29+
(candidate) => normalizeAgentId(candidate) === normalizeAgentId(input.agentId),
2630
)
2731
: directoryAgentIds.length === 1
2832
? directoryAgentIds[0]
2933
: undefined;
30-
if (!agentId || resolveAgentDir(snapshot.config, agentId) !== snapshot.agentDir) {
31-
throw new PublishedModelCatalogOwnerResolutionError(
32-
`published model catalog owner did not identify one configured agent (${snapshot.agentDir})`,
33-
);
34+
if (!agentId || resolveAgentDir(input.config, agentId, env) !== input.agentDir) {
35+
return undefined;
3436
}
35-
const workspaceDir = snapshot.workspaceDir ?? resolveAgentWorkspaceDir(snapshot.config, agentId);
36-
if (!workspaceDir) {
37+
const workspaceDir = input.workspaceDir ?? resolveAgentWorkspaceDir(input.config, agentId, env);
38+
return workspaceDir ? Object.freeze({ agentId, workspaceDir }) : undefined;
39+
}
40+
41+
export function resolvePublishedModelCatalogOwner(
42+
snapshot: PublishedModelCatalogOwnerCandidate,
43+
): ResolvedPublishedModelCatalogOwner {
44+
const { catalogOwner } = snapshot;
45+
if (!catalogOwner) {
3746
throw new PublishedModelCatalogOwnerResolutionError(
38-
`published model catalog owner did not identify a workspace (${agentId})`,
47+
`published model catalog owner did not identify one configured agent (${snapshot.agentDir})`,
3948
);
4049
}
50+
const { agentId, workspaceDir } = catalogOwner;
4151
const authStore = snapshot.authStore ?? getPreparedModelRuntimeAuthStore(snapshot);
4252
if (!authStore) {
4353
throw new PublishedModelCatalogOwnerResolutionError(
4454
`published model catalog owner is missing prepared auth state (${agentId})`,
4555
);
4656
}
4757
return Object.freeze({
58+
catalogOwner,
4859
agentId,
4960
agentDir: snapshot.agentDir,
5061
workspaceDir,

0 commit comments

Comments
 (0)