Skip to content

Commit ef22410

Browse files
authored
refactor(protocol): remove beta-only expectedRunId from chat.send (#125921)
The Gateway owns start-or-steer at admission (6515f6a) and no client produces expectedRunId anymore (d84a910). The field shipped only in v2026.8.1-beta.2 - never a stable tag - so it is removed rather than deprecated. Steer sends resolve the selected session's current operation; the exact-match branch, the operation|run target identity discriminator, run_mismatch rejection, and the suggestion producers' active-run-id selection (with its ambiguity failure) are deleted. Provider-native turn fencing (Codex expectedTurnId) is unchanged: the backend-captured runId on the injection target remains.
1 parent 91cc7d5 commit ef22410

18 files changed

Lines changed: 52 additions & 574 deletions

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19853,7 +19853,6 @@ public struct ChatSendParams: Codable, Sendable {
1985319853
public let systemprovenancereceipt: String?
1985419854
public let suppresscommandinterpretation: Bool?
1985519855
public let expectedleafentryid: AnyCodable?
19856-
public let expectedrunid: String?
1985719856
public let expectedsessionroutingcontract: String?
1985819857
public let idempotencykey: String
1985919858

@@ -19879,7 +19878,6 @@ public struct ChatSendParams: Codable, Sendable {
1987919878
systemprovenancereceipt: String? = nil,
1988019879
suppresscommandinterpretation: Bool? = nil,
1988119880
expectedleafentryid: AnyCodable? = nil,
19882-
expectedrunid: String? = nil,
1988319881
expectedsessionroutingcontract: String? = nil,
1988419882
idempotencykey: String)
1988519883
{
@@ -19904,7 +19902,6 @@ public struct ChatSendParams: Codable, Sendable {
1990419902
self.systemprovenancereceipt = systemprovenancereceipt
1990519903
self.suppresscommandinterpretation = suppresscommandinterpretation
1990619904
self.expectedleafentryid = expectedleafentryid
19907-
self.expectedrunid = expectedrunid
1990819905
self.expectedsessionroutingcontract = expectedsessionroutingcontract
1990919906
self.idempotencykey = idempotencykey
1991019907
}
@@ -19930,7 +19927,6 @@ public struct ChatSendParams: Codable, Sendable {
1993019927
systemprovenancereceipt: String? = nil,
1993119928
suppresscommandinterpretation: Bool? = nil,
1993219929
expectedleafentryid: AnyCodable? = nil,
19933-
expectedrunid: String? = nil,
1993419930
expectedsessionroutingcontract: String? = nil,
1993519931
idempotencykey: String)
1993619932
{
@@ -19956,7 +19952,6 @@ public struct ChatSendParams: Codable, Sendable {
1995619952
systemprovenancereceipt: systemprovenancereceipt,
1995719953
suppresscommandinterpretation: suppresscommandinterpretation,
1995819954
expectedleafentryid: expectedleafentryid,
19959-
expectedrunid: expectedrunid,
1996019955
expectedsessionroutingcontract: expectedsessionroutingcontract,
1996119956
idempotencykey: idempotencykey)
1996219957
}
@@ -19983,7 +19978,6 @@ public struct ChatSendParams: Codable, Sendable {
1998319978
case systemprovenancereceipt = "systemProvenanceReceipt"
1998419979
case suppresscommandinterpretation = "suppressCommandInterpretation"
1998519980
case expectedleafentryid = "expectedLeafEntryId"
19986-
case expectedrunid = "expectedRunId"
1998719981
case expectedsessionroutingcontract = "expectedSessionRoutingContract"
1998819982
case idempotencykey = "idempotencyKey"
1998919983
}

‎docs/gateway/protocol.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ methods. Treat this as feature discovery, not a full enumeration of
663663
Tail responses can include an opaque `deltaCursor`. Pass it back as `cursor` to `chat.history` or `chat.startup` instead of `offset` or `messageId`. A successful catch-up returns `{ kind: "delta", messages, deltaCursor, sessionInfo }`; replay each `messages` entry through the same reducer as a live `session.message` payload. `{ kind: "reset" }` means the cursor is invalid, stale, belongs to another session, crossed a reset or compaction, or is too far behind; fetch a normal tail page. Catch-up never returns a partial page or continuation: more than 200 raw events or the 1 MB payload budget resets to a tail fetch.
664664
- `chat.message.get` is the additive bounded full-message reader for a single visible transcript entry. Pass `sessionKey`, optional `agentId` when session selection is agent-scoped, and a transcript `messageId` previously surfaced through `chat.history`; the gateway returns the same display-normalized projection without the lightweight history truncation cap when the stored entry is still available and not oversized.
665665
- `chat.toolTitles` returns short purpose titles for tool calls rendered in the Control UI (batched, max 24 items with bounded inputs). The feature is opt-in via `gateway.controlUi.toolTitles` (default off); disabled gateways answer `{ titles: {}, disabled: true }` with no model call so clients stop asking. When enabled, titles use standard utility-model routing: an explicitly configured `utilityModel` (an operator decision that, like all utility tasks, may send bounded task content to the chosen provider), else the session provider's declared small-model default so no new egress destination appears implicitly; an empty `utilityModel` disables them entirely. Titles never fall back to the primary model. Results cache in the per-agent state database keyed by tool name + input, so repeated views never re-bill the same calls.
666-
- `chat.send` accepts one-turn `fastMode: "auto"` to use fast mode for model calls started before the auto cutoff, then start later retry, fallback, tool-result, or continuation calls without fast mode. The cutoff defaults to 60 seconds (`DEFAULT_FAST_MODE_AUTO_ON_SECONDS`) and can be configured per model with `agents.defaults.models["<provider>/<model>"].params.fastAutoOnSeconds`. A `chat.send` caller can pass one-turn `fastAutoOnSeconds` to override the cutoff for that request. Pass `queueMode` (`steer`, `followup`, `collect`, or `interrupt`) to override the stored queue mode for this request only; explicit Control UI steer actions use `queueMode: "steer"`. A steer send targets the selected session's current state: the Gateway atomically injects the message into that session's direct active run, or starts a new turn when the session is idle. Activity in descendant subagent sessions never makes the selected session busy for this decision. A client that captured an exact run id may additionally pass `expectedRunId` as a fence; the Gateway binds the injection to that exact run and rejects on mismatch instead of redirecting to a successor. `expectedLeafEntryId` is an independent transcript-branch compare-and-swap for non-steer interactive sends: pass the displayed branch leaf (or deliberate `null` for an authoritative empty transcript) and the send rejects with `details.reason: "active-leaf-changed"` if another client switched transcript branches first; steer sends ignore it.
666+
- `chat.send` accepts one-turn `fastMode: "auto"` to use fast mode for model calls started before the auto cutoff, then start later retry, fallback, tool-result, or continuation calls without fast mode. The cutoff defaults to 60 seconds (`DEFAULT_FAST_MODE_AUTO_ON_SECONDS`) and can be configured per model with `agents.defaults.models["<provider>/<model>"].params.fastAutoOnSeconds`. A `chat.send` caller can pass one-turn `fastAutoOnSeconds` to override the cutoff for that request. Pass `queueMode` (`steer`, `followup`, `collect`, or `interrupt`) to override the stored queue mode for this request only; explicit Control UI steer actions use `queueMode: "steer"`. A steer send targets the selected session's current state: the Gateway atomically injects the message into that session's direct active run, or starts a new turn when the session is idle. Activity in descendant subagent sessions never makes the selected session busy for this decision. `expectedLeafEntryId` is an independent transcript-branch compare-and-swap for non-steer interactive sends: pass the displayed branch leaf (or deliberate `null` for an authoritative empty transcript) and the send rejects with `details.reason: "active-leaf-changed"` if another client switched transcript branches first; steer sends ignore it.
667667

668668
</Accordion>
669669

‎packages/gateway-protocol/src/schema/logs-chat.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ describe("ChatSendParamsSchema", () => {
7575
expectedLeafEntryId: "leaf-1",
7676
}),
7777
).toBe(true);
78-
expect(Value.Check(ChatSendParamsSchema, { ...send, expectedRunId: "run-1" })).toBe(true);
7978
expect(Value.Check(ChatSendParamsSchema, { ...send, unknown: true })).toBe(false);
8079
});
8180
});

‎packages/gateway-protocol/src/schema/logs-chat.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,6 @@ export const ChatSendParamsSchema = closedObject({
168168
// branch leaf (null = authoritative empty transcript). Steer sends ignore it;
169169
// the Gateway steers the session's direct run or starts a turn when idle.
170170
expectedLeafEntryId: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
171-
// Optional exact-run fence for steer sends; on mismatch the send rejects
172-
// instead of reaching a same-key successor run.
173-
expectedRunId: Type.Optional(NonEmptyString),
174171
expectedSessionRoutingContract: Type.Optional(NonEmptyString),
175172
idempotencyKey: NonEmptyString,
176173
});

‎src/auto-reply/reply/reply-run-registry.contracts.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,13 @@ export type ReplyBackendHandle = {
145145
export const replyMessageInjectionTargetOperation = Symbol("replyMessageInjectionTargetOperation");
146146
export type ReplyMessageInjectionTarget = {
147147
readonly [replyMessageInjectionTargetOperation]: ReplyOperation;
148-
readonly identity: "operation" | "run";
149148
readonly runId?: string;
150149
};
151150

152151
type ReplyMessageInjectionRejectionReason =
153152
| "no_active_run"
154153
| "not_running"
155154
| "stale_run"
156-
| "run_mismatch"
157155
| "injection_unavailable"
158156
| ReplyBackendQueueMessageMismatch
159157
| "runtime_rejected";
@@ -323,12 +321,6 @@ export type ReplyRunRegistry = {
323321
}): ReplyOperation;
324322
get(sessionKey: string): ReplyOperation | undefined;
325323
isActive(sessionKey: string): boolean;
326-
resolveMessageInjectionTarget(params: {
327-
sessionKey: string;
328-
/** Retained in the internal call shape until expected-leaf removal; injection ignores it. */
329-
originatingLeafEntryId: string | null | undefined;
330-
expectedRunId?: string;
331-
}): ReplyMessageInjectionTarget | undefined;
332324
/** Captures the current direct owner without requiring client-supplied run identity. */
333325
resolveCurrentMessageInjectionTarget(sessionKey: string): ReplyMessageInjectionTarget | undefined;
334326
abort(sessionKey: string): boolean;

‎src/auto-reply/reply/reply-run-registry.message-injection.ts‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ type ReplyMessageInjectionRejectionReason =
2828
| "no_active_run"
2929
| "not_running"
3030
| "stale_run"
31-
| "run_mismatch"
3231
| "injection_unavailable"
3332
| ReplyBackendQueueMessageMismatch
3433
| "runtime_rejected";
@@ -100,7 +99,6 @@ function resolveReplyBackendMessageInjection(
10099

101100
export function resolveReplyMessageInjectionRejection(params: {
102101
operation: ReplyOperation | undefined;
103-
expectedRunId?: string;
104102
options?: ReplyBackendQueueMessageOptions;
105103
}):
106104
| {
@@ -116,9 +114,6 @@ export function resolveReplyMessageInjectionRejection(params: {
116114
if (operation.result || operation.phase !== "running") {
117115
return { reason: "not_running" };
118116
}
119-
const expectedRunId = normalizeOptionalString(params.expectedRunId);
120-
// Exact run identity supersedes the operation's immutable origin leaf. The
121-
// same run advances its transcript leaf during ordinary tool/output progress.
122117
if (isReplyRunEvidenceStale(operation)) {
123118
return { reason: "stale_run" };
124119
}
@@ -127,9 +122,6 @@ export function resolveReplyMessageInjectionRejection(params: {
127122
if (!backend || !injection) {
128123
return { reason: "injection_unavailable" };
129124
}
130-
if (expectedRunId && normalizeOptionalString(backend.runId) !== expectedRunId) {
131-
return { reason: "run_mismatch" };
132-
}
133125
try {
134126
if (!injection.isAvailable()) {
135127
return { reason: "injection_unavailable" };
@@ -185,7 +177,6 @@ export function beginReplyMessageInjectionTarget(
185177
: undefined;
186178
const resolved = resolveReplyMessageInjectionRejection({
187179
operation,
188-
expectedRunId: target.identity === "run" ? target.runId : undefined,
189180
options: queueOptions,
190181
});
191182
if (!("injection" in resolved)) {

‎src/auto-reply/reply/reply-run-registry.registry.ts‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
import * as replyRunSettle from "./reply-run-finalization-lease.js";
99
import {
1010
replyMessageInjectionTargetOperation,
11-
type ReplyMessageInjectionTarget,
1211
type ReplyOperation,
1312
type ReplyOperationPhase,
1413
type ReplyRunRegistry,
@@ -108,22 +107,6 @@ export const replyRunRegistry: ReplyRunRegistry = {
108107
}
109108
return replyRunState.activeRunsByKey.has(normalizedSessionKey);
110109
},
111-
resolveMessageInjectionTarget({ sessionKey, expectedRunId }) {
112-
const operation = this.get(sessionKey);
113-
const resolved = resolveReplyMessageInjectionRejection({
114-
operation,
115-
expectedRunId,
116-
});
117-
if (!("injection" in resolved)) {
118-
return undefined;
119-
}
120-
const target: ReplyMessageInjectionTarget = {
121-
[replyMessageInjectionTargetOperation]: operation!,
122-
identity: normalizeOptionalString(expectedRunId) ? "run" : "operation",
123-
...(resolved.backend.runId ? { runId: resolved.backend.runId } : {}),
124-
};
125-
return target;
126-
},
127110
resolveCurrentMessageInjectionTarget(sessionKey) {
128111
const operation = this.get(sessionKey);
129112
const resolved = resolveReplyMessageInjectionRejection({
@@ -134,7 +117,6 @@ export const replyRunRegistry: ReplyRunRegistry = {
134117
}
135118
return {
136119
[replyMessageInjectionTargetOperation]: operation,
137-
identity: "operation",
138120
...(resolved.backend.runId ? { runId: resolved.backend.runId } : {}),
139121
};
140122
},

‎src/auto-reply/reply/reply-run-registry.test.ts‎

Lines changed: 12 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ async function queueCurrentReplyRunMessage(
104104
) {
105105
const operation = resolveActiveReplyOperationForSessionId(sessionId);
106106
const target = operation
107-
? replyRunRegistry.resolveMessageInjectionTarget({
108-
sessionKey: operation.key,
109-
originatingLeafEntryId: operation.originatingLeafEntryId,
110-
})
107+
? replyRunRegistry.resolveCurrentMessageInjectionTarget(operation.key)
111108
: undefined;
112109
return target
113110
? await queueReplyMessageInjectionTarget(target, text, options)
@@ -1917,19 +1914,13 @@ describe("reply run registry", () => {
19171914
});
19181915
operation.setPhase("running");
19191916

1920-
const target = replyRunRegistry.resolveMessageInjectionTarget({
1921-
sessionKey: "agent:main:main",
1922-
originatingLeafEntryId: "leaf-a",
1923-
});
1917+
const target = replyRunRegistry.resolveCurrentMessageInjectionTarget("agent:main:main");
19241918
expect(target).toBeDefined();
19251919

19261920
vi.advanceTimersByTime(RUN_STALE_TAKEOVER_MS + 1);
19271921

19281922
expect(
1929-
replyRunRegistry.resolveMessageInjectionTarget({
1930-
sessionKey: "agent:main:main",
1931-
originatingLeafEntryId: "leaf-a",
1932-
}),
1923+
replyRunRegistry.resolveCurrentMessageInjectionTarget("agent:main:main"),
19331924
).toBeUndefined();
19341925
await expect(queueReplyMessageInjectionTarget(target!, "stale")).resolves.toMatchObject({
19351926
status: "rejected",
@@ -1940,10 +1931,7 @@ describe("reply run registry", () => {
19401931
operation.recordActivity();
19411932

19421933
expect(
1943-
replyRunRegistry.resolveMessageInjectionTarget({
1944-
sessionKey: "agent:main:main",
1945-
originatingLeafEntryId: "leaf-a",
1946-
}),
1934+
replyRunRegistry.resolveCurrentMessageInjectionTarget("agent:main:main"),
19471935
).toBeDefined();
19481936
await expect(queueReplyMessageInjectionTarget(target!, "fresh")).resolves.toEqual({
19491937
status: "accepted",
@@ -2008,32 +1996,7 @@ describe("reply run registry", () => {
20081996
operation.setPhase("running");
20091997
operation.attachBackend({ kind: "cli", runId: "run-a", cancel: vi.fn() });
20101998

2011-
expect(
2012-
replyRunRegistry.resolveMessageInjectionTarget({
2013-
sessionKey: operation.key,
2014-
originatingLeafEntryId: "leaf-a",
2015-
expectedRunId: "run-a",
2016-
}),
2017-
).toBeUndefined();
2018-
});
2019-
2020-
it("rejects a different expected run id", () => {
2021-
const operation = createTestReplyOperation({ originatingLeafEntryId: "leaf-a" });
2022-
operation.setPhase("running");
2023-
operation.attachBackend({
2024-
kind: "embedded",
2025-
runId: "run-a",
2026-
cancel: vi.fn(),
2027-
messageInjection: { isAvailable: () => true, queueMessage: vi.fn(async () => {}) },
2028-
});
2029-
2030-
expect(
2031-
replyRunRegistry.resolveMessageInjectionTarget({
2032-
sessionKey: operation.key,
2033-
originatingLeafEntryId: "leaf-a",
2034-
expectedRunId: "run-b",
2035-
}),
2036-
).toBeUndefined();
1999+
expect(replyRunRegistry.resolveCurrentMessageInjectionTarget(operation.key)).toBeUndefined();
20372000
});
20382001

20392002
it("returns synchronous and asynchronous queue failures as typed rejections", async () => {
@@ -2048,11 +2011,7 @@ describe("reply run registry", () => {
20482011
cancel: vi.fn(),
20492012
messageInjection: { isAvailable: () => true, queueMessage: synchronous },
20502013
});
2051-
const target = replyRunRegistry.resolveMessageInjectionTarget({
2052-
sessionKey: operation.key,
2053-
originatingLeafEntryId: "leaf-a",
2054-
expectedRunId: "run-a",
2055-
})!;
2014+
const target = replyRunRegistry.resolveCurrentMessageInjectionTarget(operation.key)!;
20562015

20572016
const synchronousAttempt = beginReplyMessageInjectionTarget(target, "first");
20582017
expect(synchronous).toHaveBeenCalledOnce();
@@ -2101,11 +2060,7 @@ describe("reply run registry", () => {
21012060
}),
21022061
},
21032062
});
2104-
const target = replyRunRegistry.resolveMessageInjectionTarget({
2105-
sessionKey: operation.key,
2106-
originatingLeafEntryId: "leaf-a",
2107-
expectedRunId: "run-a",
2108-
})!;
2063+
const target = replyRunRegistry.resolveCurrentMessageInjectionTarget(operation.key)!;
21092064
const attempt = beginReplyMessageInjectionTarget(target, "accepted", {
21102065
onQueueAccepted: callerOnQueueAccepted,
21112066
});
@@ -2132,11 +2087,7 @@ describe("reply run registry", () => {
21322087
cancel: vi.fn(),
21332088
messageInjection: { isAvailable: () => true, queueMessage: vi.fn(async () => {}) },
21342089
});
2135-
const target = replyRunRegistry.resolveMessageInjectionTarget({
2136-
sessionKey: operation.key,
2137-
originatingLeafEntryId: "leaf-a",
2138-
expectedRunId: "run-a",
2139-
})!;
2090+
const target = replyRunRegistry.resolveCurrentMessageInjectionTarget(operation.key)!;
21402091
const accepted = beginReplyMessageInjectionTarget(target, "accepted");
21412092
await expect(accepted.acceptance).resolves.toBe(true);
21422093

@@ -2172,11 +2123,7 @@ describe("reply run registry", () => {
21722123
}),
21732124
},
21742125
});
2175-
const target = replyRunRegistry.resolveMessageInjectionTarget({
2176-
sessionKey: operation.key,
2177-
originatingLeafEntryId: "leaf-a",
2178-
expectedRunId: "run-a",
2179-
})!;
2126+
const target = replyRunRegistry.resolveCurrentMessageInjectionTarget(operation.key)!;
21802127
const attempt = beginReplyMessageInjectionTarget(target, "uncertain");
21812128

21822129
queueOptions?.onQueueAccepted?.(true);
@@ -2195,11 +2142,7 @@ describe("reply run registry", () => {
21952142
cancel: vi.fn(),
21962143
messageInjection: { isAvailable: () => true, queueMessage: vi.fn(async () => {}) },
21972144
});
2198-
const target = replyRunRegistry.resolveMessageInjectionTarget({
2199-
sessionKey: first.key,
2200-
originatingLeafEntryId: "leaf-a",
2201-
expectedRunId: "run-a",
2202-
})!;
2145+
const target = replyRunRegistry.resolveCurrentMessageInjectionTarget(first.key)!;
22032146
first.complete();
22042147
const successorQueue = vi.fn(async () => {});
22052148
const successor = createTestReplyOperation({ originatingLeafEntryId: "leaf-a" });
@@ -2229,11 +2172,7 @@ describe("reply run registry", () => {
22292172
messageInjection: { isAvailable: () => true, queueMessage: firstQueue },
22302173
};
22312174
operation.attachBackend(first);
2232-
const target = replyRunRegistry.resolveMessageInjectionTarget({
2233-
sessionKey: operation.key,
2234-
originatingLeafEntryId: "leaf-a",
2235-
expectedRunId: "run-a",
2236-
})!;
2175+
const target = replyRunRegistry.resolveCurrentMessageInjectionTarget(operation.key)!;
22372176
const replacementQueue = vi.fn(async () => {});
22382177
operation.attachBackend({
22392178
kind: "embedded",
@@ -2264,11 +2203,7 @@ describe("reply run registry", () => {
22642203
cancel: vi.fn(),
22652204
messageInjection: { isAvailable: () => true, queueMessage },
22662205
});
2267-
const target = replyRunRegistry.resolveMessageInjectionTarget({
2268-
sessionKey: operation.key,
2269-
originatingLeafEntryId: "leaf-a",
2270-
expectedRunId: "run-a",
2271-
})!;
2206+
const target = replyRunRegistry.resolveCurrentMessageInjectionTarget(operation.key)!;
22722207

22732208
await expect(queueReplyMessageInjectionTarget(target, "last input")).resolves.toEqual({
22742209
status: "accepted",

0 commit comments

Comments
 (0)