Skip to content

Commit 8286e25

Browse files
authored
fix(matrix): revert multi-agent turn-taking (#132977)
This reverts commit 5d7bd83. Roll back PR #113115 at maintainer request, restoring the previous Matrix and runtime behavior while preserving subsequent main changes. Retain only the publication-safe synthetic model name in an existing test fixture.
1 parent 9d8bf35 commit 8286e25

224 files changed

Lines changed: 3532 additions & 23966 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.

‎config/knip.config.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,6 @@ const config = {
443443
// Focused tests consume these diagnostic/test seams; production code uses
444444
// the surrounding runtime helpers rather than importing the exports.
445445
"extensions/signal/src/setup-core.ts": ["exports"],
446-
// Focused Matrix tests instantiate isolated coordinators and inspect the reserved wire marker;
447-
// production uses the singleton coordinator and protocol helpers within their owning modules.
448-
"extensions/matrix/src/matrix/monitor/turn-taking-coordinator.ts": ["exports"],
449-
"extensions/matrix/src/matrix/preview-protocol.ts": ["exports"],
450-
// Focused retry tests exercise this parameter-resolution seam; production calls it in-module.
451-
"src/agents/embedded-agent-runner/run/attempt-dispatch-preparation.ts": ["exports"],
452446
// Focused CLI tests exercise plan construction through this explicit test seam.
453447
"extensions/onepassword/src/secret-ref-cli.ts": ["exports"],
454448
// Mirror config parsing, redaction mapping, cap fitting, and the runner are

‎docs/channels/matrix.md‎

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -312,87 +312,6 @@ By default, Matrix messages from other configured OpenClaw Matrix accounts are i
312312

313313
Use strict room allowlists and mention requirements when enabling bot-to-bot traffic in shared rooms.
314314

315-
## Intelligent multi-agent turn-taking
316-
317-
Matrix can coordinate multiple OpenClaw agent accounts in the same room without requiring every message to mention an agent and without forcing every agent to answer. This feature is channel-wide and off by default:
318-
319-
```json5
320-
{
321-
channels: {
322-
matrix: {
323-
turnTaking: {
324-
enabled: true,
325-
redraftDepth: 1,
326-
nextStep: { decider: "ai" },
327-
// Fixed-policy alternative:
328-
// nextStep: { decider: "user", action: "redraft" },
329-
},
330-
groups: {
331-
// Disable the channel-wide feature in one room.
332-
"!quiet-room:example.org": { turnTaking: false },
333-
},
334-
},
335-
},
336-
}
337-
```
338-
339-
Configure `turnTaking` only at the top-level `channels.matrix` object. It is one policy shared by every local Matrix account; account-level `turnTaking` values and account-level room opt-outs are rejected. A room is eligible when all of the following are true:
340-
341-
- `turnTaking.enabled` is `true`, and the room does not set `groups.<room>.turnTaking: false` (legacy `rooms` also works).
342-
- The current joined-room membership contains at least two distinct, enabled, configured Matrix account identities from this Gateway. Configuration alone is not enough; membership is rechecked and cached briefly.
343-
- The room is unencrypted. Enhanced turn-taking currently fails closed in E2EE rooms; ordinary Matrix E2EE behavior continues without this feature.
344-
345-
A normal one-human/one-agent DM has only one eligible local agent and remains unchanged. A room still marked as a Matrix direct room is eligible if its live membership contains at least two eligible local agent accounts.
346-
347-
### Participation decision
348-
349-
For each native message event, one deterministic local owner makes one shared, low-reasoning utility-model call for accounts allowed by their room and sender access policies. Each account's own routing determines which agent identity is used. The model receives bounded recent room context, the current message, routed agent identities, and bounded active sibling-preview progress. Shared context includes only content permitted by every participant's context visibility policy. It returns exactly one disposition per candidate:
350-
351-
- `strongly-speak`: context strongly indicates that this agent should answer.
352-
- `strongly-silent`: context strongly indicates that this agent should not answer. This is the only disposition that suppresses a turn.
353-
- `neutral`: neither conclusion is strong. The agent remains eligible to answer.
354-
355-
The decision is shared across account monitors, so one Matrix event does not create competing classifier calls. Invalid output, model failure, or timeout fails open to `neutral`. A classifier request exceeding the total context budget is logged and also uses `neutral`; OpenClaw does not truncate the candidate roster. Commands, including `/steer`, bypass participation classification and continue through the normal command path.
356-
357-
Participation classification is independent of the replying agent's full runtime. Set `redraftDepth: 0` for participation-only mode with any otherwise supported runtime. At depth `1` or `2`, the built-in OpenClaw embedded path and prepared CLI runner retain their source-finalization support. For plugin agent harnesses, the private finalization handoff is supported only by the exact bundled, registry-attested Codex runtime; Copilot and other plugin harnesses do not receive that private capability.
358-
359-
Explicit channel enablement authorizes authenticated protocol finals from a currently joined, configured sibling account to bypass the legacy `allowBots` and mention-only gates. It does not bypass `groupPolicy`, `dm.policy`, `groupAllowFrom`, `dm.allowFrom`, per-room `users`, room enablement, room opt-out, self-message rejection, replay protection, or bot-pair loop protection. Arbitrary bot traffic and unmarked configured-bot messages still follow [`allowBots`](#bot-to-bot-rooms). Matrix room turn-taking is separate from the local `tools.agentToAgent` and `sessions_send` controls.
360-
361-
### Fresh-message action and redraft depth
362-
363-
After the replying agent has produced a complete candidate but before terminal delivery, OpenClaw checks for newer room activity. `nextStep` distinguishes who decides from the three possible actions:
364-
365-
- `{ decider: "ai" }`: the fast utility model dynamically chooses `redraft`, `discard`, or `send-as-is` from bounded newer activity.
366-
- `{ decider: "user", action: "redraft" | "discard" | "send-as-is" }`: configuration fixes the action. The three action names are values, not separate feature toggles.
367-
368-
`redraftDepth` is exactly `0`, `1`, or `2`:
369-
370-
- `0`: no pre-send freshness check.
371-
- `1` (default): check once. If the action is `redraft`, perform at most one rewrite.
372-
- `2`: check once and, only after an actual rewrite, check once more for activity that arrived after the first check. At most two rewrites occur; there is no third check.
373-
374-
When a freshness-enabled turn selects an unsupported plugin harness, OpenClaw rejects that harness before provider or model work. When a later model candidate resolves to a supported source-finalization path, normal model fallback can continue through that candidate; if none is available, the user sees an error that identifies OpenClaw's registry-attested bundled Codex harness as the supported plugin runtime, also notes the embedded/CLI alternatives, and names `redraftDepth: 0` as participation-only mode. "Registry-attested" identifies the harness registration and provenance; it is not a Codex app-server version pin or ceiling, and OpenClaw's normal minimum-version compatibility continues to apply. OpenClaw does not silently deliver a plugin-harness candidate without the configured freshness gate.
375-
376-
Before each freshness snapshot, OpenClaw waits up to five seconds for Matrix ingress that has already been announced to a local handler, then proceeds with the activity observed by that point. This barrier is intentionally bounded: an event not yet delivered to any local handler, or still unresolved after the five-second wait, can be absent from that snapshot.
377-
378-
Freshness checks apply the replying account's own room access and `contextVisibility` policy to both messages and preview revisions. Another account receiving a message does not grant this account access to it. Existing `contextVisibility: "all"` behavior still permits supplemental context from otherwise blocked senders; in group rooms, `allowlist` and `allowlist_quote` filter history and previews by the receiver's sender allowlist. Accounts with different reply-thread settings share the native source event's decision; sibling answers in another thread are included only when their protocol marker names that exact trigger event.
379-
380-
The utility model only selects an action. A `redraft` is a hidden retry through the replying agent's already-selected normal/full runtime: the same embedded model/provider/auth/persona/session path, or the same prepared CLI backend/model/auth/runtime binding. The retry retains committed tool results but disables model access to external tools, so it cannot repeat those tool actions. Native Codex models that require Code Mode may retain isolated JavaScript computation with an empty tool registry. Normal lifecycle hooks, including the final-message gate, still run. A `discard` is deterministic host behavior: OpenClaw closes any visible preview, removes the rejected assistant candidate and pending client action, and finishes silently without asking a model to emit `NO_REPLY`.
381-
382-
Utility-model failure, timeout, or invalid output selects `send-as-is`, preserving the completed draft. Once an embedded redraft has been accepted, the rejected assistant leaf is rewound before the normal-model retry; if that retry ultimately fails, OpenClaw fails the turn rather than resurrecting a draft that freshness review rejected. A CLI redraft preparation or execution failure before a successor is accepted keeps the current pre-rewrite draft. Both supported runtime paths run the freshness gate before assistant transcript persistence and terminal delivery.
383-
384-
### Preview streaming behavior
385-
386-
Enhanced rooms support Matrix `partial`, `quiet`, and `progress` preview streaming. OpenClaw correlates an initial preview, its edits, and its final state so sibling agents can observe bounded progress without treating every edit as a new message. Only one authenticated logical final is promoted into sibling ingress; partial, ancillary media, tool progress, and abandoned previews never trigger a normal sibling turn. Media-bearing replacements close and redact the old preview before publishing the replacement final.
387-
388-
The embedded runtime streams source-owned provisional previews during generation while holding assistant events and final replies for freshness review. If a plugin also registers a global `before_agent_finalize` hook, Matrix disables preview streaming and holds the final reply until finalization is accepted.
389-
390-
`streaming.block.enabled` is effectively forced off for each eligible enhanced turn without rewriting stored config. Block streaming is not supported by intelligent turn-taking. Ineligible and opted-out rooms keep their configured streaming behavior.
391-
392-
Preview awareness is transient and bounded. In-progress previews older than two minutes are ignored after reconnect, and terminal protocol events older than 30 minutes cannot start a fresh turn. Normal persistent Matrix replay claims still protect promoted finals. Because Matrix clients may already have rendered partial text, a later redraft or discard is a live correction: OpenClaw edits or redacts the preview, but cannot make text that a human already saw retroactively invisible.
393-
394-
Enhanced turn-taking is deliberately disabled in encrypted rooms for now. Decrypted Matrix messages still use the ordinary Matrix pipeline, but OpenClaw does not emit or consume enhanced turn-taking protocol as conversational input there. This avoids treating an incompletely decrypted replacement edit as a final sibling answer.
395-
396315
## Encryption and verification
397316

398317
In encrypted (E2EE) rooms, outbound image events use `thumbnail_file` so image previews are encrypted alongside the full attachment; unencrypted rooms use plain `thumbnail_url`. No configuration is needed - the plugin detects E2EE state automatically.
@@ -858,7 +777,7 @@ Authorization rules still apply: command senders must satisfy the same DM or roo
858777

859778
**Inheritance:**
860779

861-
- Top-level `channels.matrix` values act as defaults for named accounts unless an account overrides them. `turnTaking` is the exception: it is channel-wide and cannot be overridden per account.
780+
- Top-level `channels.matrix` values act as defaults for named accounts unless an account overrides them.
862781
- Scope an inherited room entry to a specific account with `groups.<room>.account`. Entries without `account` are shared across accounts; `account: "default"` still works when the default account is configured at the top level.
863782

864783
**Default account selection:**
@@ -986,13 +905,6 @@ Room allowlist keys (`groups`, legacy `rooms`) should be room IDs or aliases. Pl
986905
- `autoJoinAllowlist`: rooms/aliases allowed when `autoJoin` is `"allowlist"`. Alias entries resolve against the homeserver, not against state claimed by the invited room.
987906
- `contextVisibility`: supplemental context visibility (`"all"` default, `"allowlist"`, `"allowlist_quote"`).
988907

989-
### Intelligent turn-taking
990-
991-
- `turnTaking.enabled`: enable shared intelligent multi-agent participation for eligible unencrypted Matrix rooms. Default: `false`.
992-
- `turnTaking.redraftDepth`: `0`, `1` (default), or `2`; `0` is participation-only and works with any otherwise supported runtime. Depth `1` and `2` use a supported embedded or CLI finalizer; among plugin harnesses, OpenClaw's registry-attested bundled Codex harness is required. This is an identity/provenance check, not an exact-version pin.
993-
- `turnTaking.nextStep`: `{ decider: "ai" }` (default), or `{ decider: "user", action: "redraft" | "discard" | "send-as-is" }`.
994-
- `groups.<room>.turnTaking`: only `false` is accepted; opts one room out of the channel-wide feature. This key is top-level only and cannot appear under `accounts.<id>.groups` or `accounts.<id>.rooms`.
995-
996908
### Reply behavior
997909

998910
- `joinIntro`: introduce when the bot joins an allowed group room. Default: `true`. Per-account override: `accounts.<accountId>.joinIntro`.
@@ -1028,7 +940,6 @@ Room allowlist keys (`groups`, legacy `rooms`) should be room IDs or aliases. Pl
1028940
- `groups.<room>.autoReply`: per-room mention-gating override. `true` disables mention requirements for that room; `false` forces them back on.
1029941
- `groups.<room>.skills`: per-room skill filter.
1030942
- `groups.<room>.systemPrompt`: per-room system prompt snippet.
1031-
- `groups.<room>.turnTaking`: set `false` to opt this room out of channel-wide intelligent turn-taking.
1032943

1033944
### Exec approval settings
1034945

‎docs/plugins/sdk-subpaths.md‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ subpaths.
6969
OpenClaw's Vitest-backed test-helper subpaths are repo-local only and are no
7070
longer package exports: `agent-runtime-test-contracts`,
7171
`channel-contract-testing`, `channel-target-testing`, `channel-test-helpers`,
72-
`matrix-source-finalization-test-fixtures`, `plugin-state-test-runtime`,
73-
`plugin-test-api`, `plugin-test-contracts`, `plugin-test-runtime`,
74-
`provider-http-test-mocks`, `provider-test-contracts`, `reply-payload-testing`,
75-
`sqlite-runtime-testing`, `test-env`, `test-fixtures`, `test-live`,
76-
`test-live-auth`, `test-media-generation`,
72+
`plugin-state-test-runtime`, `plugin-test-api`, `plugin-test-contracts`,
73+
`plugin-test-runtime`, `provider-http-test-mocks`, `provider-test-contracts`,
74+
`reply-payload-testing`, `sqlite-runtime-testing`, `test-env`, `test-fixtures`,
75+
`test-live`, `test-live-auth`, `test-media-generation`,
7776
`test-media-understanding`, `test-node-mocks`, and `testing`.
7877
`ssrf-runtime-internal` is a JavaScript-only host runtime reserved for exact
7978
trusted local-service plugins; it is not a public plugin authoring API.
@@ -402,7 +401,6 @@ Use `isLoopbackHost(host)` when a plugin must accept only the local machine. It
402401
| `plugin-sdk/channel-test-helpers` | Repo-local channel-oriented test helpers for generic actions/setup/status contracts, directory assertions, account startup lifecycle, send-config threading, runtime mocks, status issues, outbound delivery, and hook registration |
403402
| `plugin-sdk/channel-target-testing` | Repo-local shared target-resolution error-case suite for channel tests |
404403
| `plugin-sdk/channel-contract-testing` | Repo-local narrow channel contract test helpers without the broad testing barrel |
405-
| `plugin-sdk/matrix-source-finalization-test-fixtures` | Private-local, unexported Matrix source-finalization fixtures for repository tests only |
406404
| `plugin-sdk/plugin-test-contracts` | Repo-local plugin package, registration, public artifact, runtime API, and import side-effect contract helpers |
407405
| `plugin-sdk/plugin-state-test-runtime` | Repo-local plugin state store, ingress queue, and state DB test helpers |
408406
| `plugin-sdk/provider-test-contracts` | Repo-local provider runtime, auth, discovery, onboard, catalog, wizard, media capability, replay policy, realtime STT live-audio, web-search/fetch, and stream contract helpers |

‎extensions/codex/harness.ts‎

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type { PluginRuntime } from "openclaw/plugin-sdk/plugin-runtime";
1212
import { runHostPreparedIsolatedCompletion } from "openclaw/plugin-sdk/simple-completion-runtime";
1313
import { readCodexRuntimeModelId } from "./src/app-server/model-runtime.js";
1414
import type { CodexAppServerBindingStore } from "./src/app-server/session-binding.js";
15-
import type { CodexTurnLocalBeforeAgentFinalize } from "./src/app-server/turn-local-finalization-types.js";
1615
import type { CodexSessionCatalogControlFactory } from "./src/session-catalog-types.js";
1716

1817
// `codex` is legacy input only until Part 2 doctor migration rewrites stored refs.
@@ -62,10 +61,6 @@ type CodexAppServerAgentHarnessOptions = {
6261
sessionCatalogControlFactory?: CodexSessionCatalogControlFactory;
6362
};
6463

65-
type CodexPrivateRunAttempt = (
66-
params: Parameters<AgentHarnessV2["runAttempt"]>[0],
67-
onBeforeAgentFinalize?: CodexTurnLocalBeforeAgentFinalize,
68-
) => ReturnType<AgentHarnessV2["runAttempt"]>;
6964
async function disposeSharedCodexAppServerClients(): Promise<void> {
7065
const dispose = (
7166
globalThis as typeof globalThis & {
@@ -101,19 +96,6 @@ export function createCodexAppServerAgentHarness(
10196
resolvePluginConfigObject(config, "codex") ??
10297
options.resolvePluginConfig?.() ??
10398
options.pluginConfig;
104-
const runAttempt: CodexPrivateRunAttempt = async (params, onBeforeAgentFinalize) => {
105-
// The optional second argument is an unexported host-to-attested-Codex
106-
// handoff. It never appears on the public harness attempt object.
107-
const codexParams = onBeforeAgentFinalize ? { ...params, onBeforeAgentFinalize } : params;
108-
const { runCodexAppServerAttempt } = await import("./src/app-server/run-attempt.js");
109-
return runCodexAppServerAttempt(codexParams, {
110-
bindingStore: options.bindingStore,
111-
pluginConfig: resolveAttemptPluginConfig(params.config),
112-
runtime: sessionRuntime,
113-
runtimeModelId: readCodexRuntimeModelId(params.model, params.modelId),
114-
nativeHookRelay: { enabled: true },
115-
});
116-
};
11799
const harness: AgentHarnessV2 = {
118100
id: harnessRuntimeId,
119101
label: options?.label ?? "Codex agent harness",
@@ -257,7 +239,18 @@ export function createCodexAppServerAgentHarness(
257239
}
258240
return { supported: true, priority: 100 };
259241
},
260-
runAttempt,
242+
runAttempt: async (params) => {
243+
// Keep app-server runtime code behind lazy imports so plugin discovery and
244+
// cold provider catalog reads do not pull in the whole Codex runtime.
245+
const { runCodexAppServerAttempt } = await import("./src/app-server/run-attempt.js");
246+
return runCodexAppServerAttempt(params, {
247+
bindingStore: options.bindingStore,
248+
pluginConfig: resolveAttemptPluginConfig(params.config),
249+
runtime: sessionRuntime,
250+
runtimeModelId: readCodexRuntimeModelId(params.model, params.modelId),
251+
nativeHookRelay: { enabled: true },
252+
});
253+
},
261254
runIsolatedCompletionV2: async (params) => {
262255
if (params.authorization.owner === "host") {
263256
return runHostPreparedIsolatedCompletion(params);

0 commit comments

Comments
 (0)