Skip to content

Commit 8afc9ef

Browse files
[plugin sdk] Harden finalize retry and run context cleanup (#75600)
Merged via squash. Prepared head SHA: ec58a62 Co-authored-by: 100yenadmin <[email protected]> Co-authored-by: jalehman <[email protected]> Reviewed-by: @jalehman
1 parent 042d7b8 commit 8afc9ef

22 files changed

Lines changed: 2105 additions & 121 deletions

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Docs: https://docs.openclaw.ai
3737
- Plugins/update: clean stale bundled load paths for already-externalized pinned npm and ClawHub plugin installs, so release-channel sync does not leave removed bundled paths ahead of the installed external package. Thanks @vincentkoc.
3838
- Telegram: accept plugin-owned numeric forum-topic targets in the agent message tool and keep reply-dispatch provider chunks behind a real stable runtime alias during in-place package updates. Fixes #77137. Thanks @richardmqq.
3939
- Google Meet: preserve `realtime.introMessage: ""` so realtime Chrome joins can stay silent instead of restoring the default spoken intro. Thanks @vincentkoc.
40+
- Plugins/SDK: add bounded `before_agent_finalize` retry instructions so workflow plugins can request one more model pass. Thanks @100yenadmin.
41+
- Discord/status: add degraded Discord transport and gateway event-loop starvation signals to `openclaw channels status`, `openclaw status --deep`, and fetch-timeout logs so intermittent socket resets do not look like a healthy running channel. (#76327) Thanks @joshavant.
4042
- Providers/OpenRouter: add opt-in response caching params that send OpenRouter's `X-OpenRouter-Cache`, `X-OpenRouter-Cache-TTL`, and cache-clear headers only on verified OpenRouter routes. Thanks @vincentkoc.
4143
- Providers/OpenRouter: expand app-attribution categories so OpenClaw advertises coding, programming, writing, chat, and personal-agent usage on verified OpenRouter routes. Thanks @vincentkoc.
4244
- Plugins/runtime state: add `registerIfAbsent` for atomic keyed-store dedupe claims that return whether a plugin successfully claimed a key without overwriting an existing live value. Thanks @amknight.
@@ -465,6 +467,9 @@ Docs: https://docs.openclaw.ai
465467
- Gateway/CLI: make `openclaw gateway start` repair stale managed service definitions that point at old OpenClaw versions, missing binaries, or temporary installer paths before starting.
466468
- Heartbeat/scheduler: make heartbeat phase scheduling active-hours-aware so the scheduler seeks forward to the first in-window phase slot instead of arming timers for quiet-hours slots and relying solely on the runtime guard. Non-UTC `activeHours.timezone` values (e.g. `Asia/Shanghai`) now correctly influence when the next heartbeat timer fires, avoiding wasted quiet-hours ticks and long dormant gaps after gateway restarts. Fixes #75487. Thanks @amknight.
467469
- Providers/Arcee AI: mark Trinity Large Thinking as tool-incompatible so main-session runs use the same text-only request shape that made subagent runs recover, avoiding the remaining main-session response-shape mismatch after the #62848 transport failover fix. Fixes #62851 and #62847; carries forward #62848. Thanks @Adam-Researchh.
470+
- Plugins/SDK: harden run-scoped plugin context cleanup so finalized workflow runs do not leak per-run state. Thanks @100yenadmin.
471+
- Plugins/SDK: keep stale async registry cleanup from clearing restored plugin run context and scheduler state after a plugin registry is reactivated. (#75600) Thanks @100yenadmin.
472+
- Plugins/SDK: preserve restored plugin scheduler state when earlier delayed replacement cleanup finishes after reactivation. Thanks @100yenadmin.
468473
- Status: show the `openai-codex` OAuth profile for `openai/gpt-*` sessions running through the native Codex runtime instead of reporting auth as unknown. (#76197) Thanks @mbelinky.
469474
- Gateway: avoid repeated plugin tool descriptor config hashing so large runtime configs do not block reply startup and trigger reconnect/timeouts. (#75944) Thanks @joshavant.
470475
- Plugins/externalization: keep diagnostics ClawHub packages and persisted bundled-plugin relocation on npm-first install metadata for launch, and omit Discord from the core package now that its external package is published. Thanks @vincentkoc.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
c38441e2e18aa519c5dc22c2b593694444869673447740327c87f16f3d4a0f8d plugin-sdk-api-baseline.json
2-
5711948923b5a4f89ac04a182266ee0fb57275369a3a8112433f3758a7d38c86 plugin-sdk-api-baseline.jsonl
1+
3c0423e26e758e7a5f5febcbaacd6a7ceb8584a8eecd0224f7ce98e6bcb9e9c0 plugin-sdk-api-baseline.json
2+
952ba44c63a9f2107fc10aead1d0cc77ef06ac9a9befcac3ca9e4b0f4427cdfc plugin-sdk-api-baseline.jsonl

‎docs/plugins/hooks.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,22 @@ the harness for one more model pass before finalization, `{ action:
264264
Codex native `Stop` hooks are relayed into this hook as OpenClaw
265265
`before_agent_finalize` decisions.
266266

267+
When returning `action: "revise"`, plugins can include `retry` metadata to make
268+
the extra model pass bounded and replay-safe:
269+
270+
```typescript
271+
type BeforeAgentFinalizeRetry = {
272+
instruction: string;
273+
idempotencyKey?: string;
274+
maxAttempts?: number;
275+
};
276+
```
277+
278+
`instruction` is appended to the revision reason sent to the harness.
279+
`idempotencyKey` lets the host count retries for the same plugin request across
280+
equivalent finalize decisions, and `maxAttempts` caps how many extra passes the
281+
host will allow before continuing with the natural final answer.
282+
267283
Non-bundled plugins that need `llm_input`, `llm_output`,
268284
`before_agent_finalize`, or `agent_end` must set:
269285

‎extensions/matrix/src/matrix/monitor/handler.test-helpers.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type MatrixHandlerTestHarnessOptions = {
2323
accountId?: string;
2424
accountConfig?: MatrixConfig;
2525
cfg?: unknown;
26+
liveCfg?: unknown;
2627
client?: Partial<MatrixClient>;
2728
runtime?: RuntimeEnv;
2829
logger?: RuntimeLogger;
@@ -192,7 +193,7 @@ export function createMatrixHandlerTestHarness(
192193
} as never,
193194
core: {
194195
config: {
195-
current: () => cfgForHandler,
196+
current: () => options.liveCfg ?? cfgForHandler,
196197
},
197198
channel: {
198199
pairing: {

‎extensions/matrix/src/matrix/monitor/handler.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,50 @@ describe("matrix monitor handler pairing account scope", () => {
228228
);
229229
});
230230

231+
it("uses live dmScope when deciding whether to pin main DM route updates", async () => {
232+
const startupCfg = {
233+
session: { dmScope: "main" },
234+
channels: {
235+
matrix: {
236+
dm: { allowFrom: ["@owner:example.org"] },
237+
},
238+
},
239+
};
240+
const liveCfg = {
241+
session: { dmScope: "per-channel-peer" },
242+
channels: {
243+
matrix: {
244+
dm: { allowFrom: ["@owner:example.org"] },
245+
},
246+
},
247+
};
248+
const { handler, recordInboundSession } = createMatrixHandlerTestHarness({
249+
cfg: startupCfg,
250+
liveCfg,
251+
dmPolicy: "allowlist",
252+
allowFrom: ["@owner:example.org"],
253+
allowFromResolvedEntries: [{ input: "@owner:example.org", id: "@owner:example.org" }],
254+
isDirectMessage: true,
255+
});
256+
257+
await handler(
258+
"!dm:example.org",
259+
createMatrixTextMessageEvent({
260+
eventId: "$owner-dm-live-scope",
261+
sender: "@owner:example.org",
262+
body: "hello",
263+
}),
264+
);
265+
266+
expect(recordInboundSession).toHaveBeenCalledWith(
267+
expect.objectContaining({
268+
updateLastRoute: expect.objectContaining({
269+
mainDmOwnerPin: undefined,
270+
}),
271+
}),
272+
);
273+
});
274+
231275
it("sends pairing reminders for pending requests with cooldown", async () => {
232276
vi.useFakeTimers();
233277
vi.setSystemTime(new Date("2026-03-01T10:00:00.000Z"));

‎extensions/matrix/src/matrix/monitor/handler.ts‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,6 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
11981198
triggerSnapshot,
11991199
threadRootId: _threadRootId,
12001200
thread,
1201-
effectiveAllowFrom,
12021201
effectiveGroupAllowFrom,
12031202
effectiveRoomUsers,
12041203
} = resolvedIngressResult;
@@ -1940,11 +1939,27 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
19401939
onIdle: typingCallbacks.onIdle,
19411940
});
19421941
const pinnedMainDmOwner = isDirectMessage
1943-
? resolvePinnedMainDmOwnerFromAllowlist({
1944-
dmScope: cfg.session?.dmScope,
1945-
allowFrom: effectiveAllowFrom,
1946-
normalizeEntry: normalizeMatrixUserId,
1947-
})
1942+
? await (async () => {
1943+
const livePinnedCfg = core.config.current() as CoreConfig;
1944+
const livePinnedAllowlists = resolveMatrixAccountAllowlistConfig({
1945+
cfg: livePinnedCfg,
1946+
accountId,
1947+
});
1948+
const livePinnedDmAllowFrom = await resolveCachedLiveAllowlist({
1949+
cfg: livePinnedCfg,
1950+
entries: livePinnedAllowlists.dmAllowFrom,
1951+
startupResolvedEntries: allowFromResolvedEntries,
1952+
cache: liveDmAllowlistCache,
1953+
updateCache: (next) => {
1954+
liveDmAllowlistCache = next;
1955+
},
1956+
});
1957+
return resolvePinnedMainDmOwnerFromAllowlist({
1958+
dmScope: livePinnedCfg.session?.dmScope,
1959+
allowFrom: livePinnedDmAllowFrom,
1960+
normalizeEntry: normalizeMatrixUserId,
1961+
});
1962+
})()
19481963
: null;
19491964

19501965
const turnResult = await core.channel.turn.run({

0 commit comments

Comments
 (0)