@bastani/atomic 0.9.78 → 0.9.79-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/dist/builtin/intercom/CHANGELOG.md +12 -0
- package/dist/builtin/intercom/broker/broker.ts +198 -72
- package/dist/builtin/intercom/broker/client-message-validation.ts +38 -0
- package/dist/builtin/intercom/broker/client.ts +150 -11
- package/dist/builtin/intercom/broker/delivery-failure-reason.ts +1 -0
- package/dist/builtin/intercom/broker/departed-children.ts +23 -0
- package/dist/builtin/intercom/broker/hosted-session-errors.ts +188 -0
- package/dist/builtin/intercom/broker/hosted-sessions.ts +113 -0
- package/dist/builtin/intercom/broker/multinode-router.ts +7 -2
- package/dist/builtin/intercom/broker/presence-handler.ts +2 -1
- package/dist/builtin/intercom/broker/protocol-version.ts +6 -1
- package/dist/builtin/intercom/broker/recipient-gone-errors.ts +46 -5
- package/dist/builtin/intercom/broker/released-reply-errors.ts +1 -1
- package/dist/builtin/intercom/broker/send-handler.ts +19 -3
- package/dist/builtin/intercom/broker/socket-writes.ts +20 -1
- package/dist/builtin/intercom/hosted-session-timeout-error.ts +59 -0
- package/dist/builtin/intercom/index.bundle.mjs +634 -125
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/intercom/types.ts +41 -3
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +8 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +90 -34
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +9 -0
- package/dist/builtin/workflows/builtin/{chunk-89we7r4p.js → chunk-5hrzxynt.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-8yfssw01.js → chunk-m56qhe4b.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-wh2p4qjg.js → chunk-x8m4t2jy.js} +182 -33
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +1243 -230
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +854 -170
- package/dist/builtin/workflows/src/index.js +854 -170
- package/dist/builtin/workflows/src/local-worker-entry.mjs +854 -170
- package/dist/cli/startup-progress.d.ts +30 -0
- package/dist/cli/startup-progress.d.ts.map +1 -0
- package/dist/cli/startup-progress.js +78 -0
- package/dist/cli/startup-progress.js.map +1 -0
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +3 -0
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +2 -0
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +2 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-state.d.ts +12 -4
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +82 -15
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +3 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/builtin-resource-loader.d.ts.map +1 -1
- package/dist/core/builtin-resource-loader.js +3 -0
- package/dist/core/builtin-resource-loader.js.map +1 -1
- package/dist/core/debug.d.ts +2 -0
- package/dist/core/debug.d.ts.map +1 -1
- package/dist/core/debug.js +13 -0
- package/dist/core/debug.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts +5 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js +57 -20
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/template.js +1 -1
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +2 -3
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/workflow-activity-hub.d.ts +7 -0
- package/dist/core/extensions/workflow-activity-hub.d.ts.map +1 -1
- package/dist/core/extensions/workflow-activity-hub.js +104 -6
- package/dist/core/extensions/workflow-activity-hub.js.map +1 -1
- package/dist/core/keybindings.d.ts +0 -8
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +0 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/mandatory-resource-loader.d.ts.map +1 -1
- package/dist/core/mandatory-resource-loader.js +3 -0
- package/dist/core/mandatory-resource-loader.js.map +1 -1
- package/dist/core/resume/session-resume.d.ts +7 -1
- package/dist/core/resume/session-resume.d.ts.map +1 -1
- package/dist/core/resume/session-resume.js +136 -16
- package/dist/core/resume/session-resume.js.map +1 -1
- package/dist/core/session-history-index.d.ts +31 -0
- package/dist/core/session-history-index.d.ts.map +1 -0
- package/dist/core/session-history-index.js +82 -0
- package/dist/core/session-history-index.js.map +1 -0
- package/dist/core/session-manager-core.d.ts +3 -0
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +22 -17
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-history.d.ts +3 -3
- package/dist/core/session-manager-history.d.ts.map +1 -1
- package/dist/core/session-manager-history.js +6 -5
- package/dist/core/session-manager-history.js.map +1 -1
- package/dist/core/storage/session/history-load-observer.d.ts +11 -0
- package/dist/core/storage/session/history-load-observer.d.ts.map +1 -0
- package/dist/core/storage/session/history-load-observer.js +25 -0
- package/dist/core/storage/session/history-load-observer.js.map +1 -0
- package/dist/core/storage/session/sql-session-store.d.ts.map +1 -1
- package/dist/core/storage/session/sql-session-store.js +6 -0
- package/dist/core/storage/session/sql-session-store.js.map +1 -1
- package/dist/core/tool-deactivation.d.ts +11 -0
- package/dist/core/tool-deactivation.d.ts.map +1 -0
- package/dist/core/tool-deactivation.js +13 -0
- package/dist/core/tool-deactivation.js.map +1 -0
- package/dist/core/tool-status.d.ts +6 -1
- package/dist/core/tool-status.d.ts.map +1 -1
- package/dist/core/tool-status.js +11 -3
- package/dist/core/tool-status.js.map +1 -1
- package/dist/extensions/llama/errors.js +1 -1
- package/dist/extensions/llama/errors.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts +1 -1
- package/dist/extensions/llama/provider.js +1 -1
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/main-session.d.ts +14 -2
- package/dist/main-session.d.ts.map +1 -1
- package/dist/main-session.js +42 -9
- package/dist/main-session.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -2
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +6 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +13 -4
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/task-detail.d.ts +1 -1
- package/dist/modes/interactive/components/task-detail.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-detail.js +1 -3
- package/dist/modes/interactive/components/task-detail.js.map +1 -1
- package/dist/modes/interactive/components/task-inspector.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-inspector.js +1 -7
- package/dist/modes/interactive/components/task-inspector.js.map +1 -1
- package/dist/modes/interactive/components/task-navigation.d.ts +0 -1
- package/dist/modes/interactive/components/task-navigation.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-navigation.js +1 -3
- package/dist/modes/interactive/components/task-navigation.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +5 -9
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.js +8 -5
- package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js +16 -10
- package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +2 -0
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-unavailable-tools.d.ts +20 -0
- package/dist/modes/interactive/interactive-unavailable-tools.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-unavailable-tools.js +40 -0
- package/dist/modes/interactive/interactive-unavailable-tools.js.map +1 -0
- package/dist/modes/interactive-engine/remote-component.js +1 -1
- package/dist/modes/interactive-engine/remote-component.js.map +1 -1
- package/docs/background-tasks.md +1 -1
- package/docs/extensions/api-reference.md +1 -1
- package/docs/extensions/events.md +2 -0
- package/docs/intercom/operations.md +2 -2
- package/docs/intercom/reference.md +12 -1
- package/docs/keybindings.md +2 -3
- package/docs/llama-cpp.md +9 -10
- package/docs/models/reference.md +1 -1
- package/docs/models-configuration.md +1 -1
- package/docs/sessions.md +6 -2
- package/docs/subagents.md +3 -1
- package/docs/usage.md +1 -1
- package/docs/workflows/operations.md +2 -2
- package/docs/worktree-snapshots.md +3 -1
- package/npm-shrinkwrap.json +32 -32
- package/package.json +4 -4
- package/schemas/keybindings.schema.json +0 -4
- package/schemas/models.schema.json +1 -1
|
@@ -9,8 +9,10 @@ export interface BrokerProtocolRange {
|
|
|
9
9
|
/**
|
|
10
10
|
* Protocol 1 is the wire of Atomic 0.9.71 and earlier: plain `register`, no released-children frames. Protocol 2 adds
|
|
11
11
|
* `register_verified`, the released-children frames and the broker frames that answer them, and `peer_rebound`.
|
|
12
|
+
* Protocol 3 adds hosted sessions (#4642): `host_sessions`, `unhost_sessions`, `hosted_sessions_ack`, a send's
|
|
13
|
+
* `hostedSender` and a message's `hostedRecipient`.
|
|
12
14
|
*/
|
|
13
|
-
export const BROKER_PROTOCOL: BrokerProtocolRange = { min: 1, max:
|
|
15
|
+
export const BROKER_PROTOCOL: BrokerProtocolRange = { min: 1, max: 3 };
|
|
14
16
|
|
|
15
17
|
/** The range of a broker that answers `broker_status` without advertising one, or a client that registers without one. */
|
|
16
18
|
export const LEGACY_BROKER_PROTOCOL: BrokerProtocolRange = { min: 1, max: 1 };
|
|
@@ -18,6 +20,9 @@ export const LEGACY_BROKER_PROTOCOL: BrokerProtocolRange = { min: 1, max: 1 };
|
|
|
18
20
|
/** The first protocol with `register_verified`, the released-children frames and `peer_rebound`. */
|
|
19
21
|
export const VERIFIED_REGISTRATION_PROTOCOL = 2;
|
|
20
22
|
|
|
23
|
+
/** #4642: the first protocol with hosted sessions. */
|
|
24
|
+
export const HOSTED_SESSIONS_PROTOCOL = 3;
|
|
25
|
+
|
|
21
26
|
/**
|
|
22
27
|
* How a session of `own` treats a running broker of `running`:
|
|
23
28
|
* - `upgrade`: the running broker is older and everything it accepts this version's broker accepts too, so a successor
|
|
@@ -19,11 +19,15 @@ export type SubagentRecipientDisconnectedCode = "recipient_disconnected";
|
|
|
19
19
|
/** The subagent is released and the session that would wake it is suspended or disconnected. */
|
|
20
20
|
export type SubagentRecipientOwnerSuspendedCode = "recipient_owner_suspended";
|
|
21
21
|
|
|
22
|
-
/**
|
|
22
|
+
/** The released workflow stage's peer is no longer hosted: its host connection closed or removed it (#4642). */
|
|
23
|
+
export type StageRecipientReleasedCode = "recipient_stage_released";
|
|
24
|
+
|
|
25
|
+
/** Why a send or ask to a subagent or released stage with no live session was refused (#4639, #4642). Codes are public API. */
|
|
23
26
|
export type IntercomRecipientGoneErrorCode =
|
|
24
27
|
| SubagentRecipientEndedCode
|
|
25
28
|
| SubagentRecipientDisconnectedCode
|
|
26
|
-
| SubagentRecipientOwnerSuspendedCode
|
|
29
|
+
| SubagentRecipientOwnerSuspendedCode
|
|
30
|
+
| StageRecipientReleasedCode;
|
|
27
31
|
|
|
28
32
|
export const INTERCOM_RECIPIENT_GONE_ERROR_CODES: readonly IntercomRecipientGoneErrorCode[] = [
|
|
29
33
|
"recipient_completed",
|
|
@@ -32,6 +36,7 @@ export const INTERCOM_RECIPIENT_GONE_ERROR_CODES: readonly IntercomRecipientGone
|
|
|
32
36
|
"recipient_cancelled",
|
|
33
37
|
"recipient_disconnected",
|
|
34
38
|
"recipient_owner_suspended",
|
|
39
|
+
"recipient_stage_released",
|
|
35
40
|
];
|
|
36
41
|
|
|
37
42
|
const CODES: ReadonlySet<unknown> = new Set(INTERCOM_RECIPIENT_GONE_ERROR_CODES);
|
|
@@ -67,9 +72,12 @@ const WHAT: Readonly<Record<IntercomRecipientGoneErrorCode, string>> = {
|
|
|
67
72
|
recipient_cancelled: "was cancelled for good and has no live session",
|
|
68
73
|
recipient_disconnected: "disconnected and has not reconnected",
|
|
69
74
|
recipient_owner_suspended: "is released and the session that launched it is suspended or disconnected, so nothing can wake it now",
|
|
75
|
+
recipient_stage_released: "was released and the session that answered for it has gone away",
|
|
70
76
|
};
|
|
71
77
|
|
|
72
78
|
function hintFor(code: IntercomRecipientGoneErrorCode, childId: string | undefined): string {
|
|
79
|
+
if (code === "recipient_stage_released")
|
|
80
|
+
return "Send to its workflow stage target (workflow:<rootRunId>/<stage>), which reaches the stage's current session or queues until it reopens, or resume the run.";
|
|
73
81
|
if (code === "recipient_cancelled")
|
|
74
82
|
return "It cannot be resumed; launch a fresh subagent if its work is still needed.";
|
|
75
83
|
if (code === "recipient_disconnected")
|
|
@@ -83,6 +91,7 @@ const BASE_NAME = "IntercomRecipientGoneError";
|
|
|
83
91
|
const ENDED_NAME = "SubagentRecipientEndedError";
|
|
84
92
|
const DISCONNECTED_NAME = "SubagentRecipientDisconnectedError";
|
|
85
93
|
const OWNER_SUSPENDED_NAME = "SubagentRecipientOwnerSuspendedError";
|
|
94
|
+
const STAGE_RELEASED_NAME = "StageRecipientReleasedError";
|
|
86
95
|
|
|
87
96
|
/**
|
|
88
97
|
* #4639: base of the refusals of a send or ask to a subagent that has no live session, decided by the broker
|
|
@@ -103,7 +112,8 @@ export class IntercomRecipientGoneError extends Error {
|
|
|
103
112
|
options?: { readonly cause?: Error },
|
|
104
113
|
) {
|
|
105
114
|
const hint = hintFor(code, fields.childId);
|
|
106
|
-
|
|
115
|
+
const subject = code === "recipient_stage_released" ? "Workflow stage" : "Subagent";
|
|
116
|
+
super(`${subject} ${JSON.stringify(fields.childName)} ${WHAT[code]} (${code}). ${hint}`, options);
|
|
107
117
|
this.code = code;
|
|
108
118
|
this.hint = hint;
|
|
109
119
|
this.retryable = code === "recipient_disconnected" || code === "recipient_owner_suspended";
|
|
@@ -155,7 +165,27 @@ export class SubagentRecipientOwnerSuspendedError extends IntercomRecipientGoneE
|
|
|
155
165
|
}
|
|
156
166
|
}
|
|
157
167
|
|
|
158
|
-
|
|
168
|
+
/**
|
|
169
|
+
* #4642: a released workflow stage answered through a hosted peer, and that peer is gone: its host connection closed or
|
|
170
|
+
* removed it. Names the stage and where to send instead. Not retryable: the same name stays unreachable until the stage
|
|
171
|
+
* is hosted again.
|
|
172
|
+
*/
|
|
173
|
+
export class StageRecipientReleasedError extends IntercomRecipientGoneError {
|
|
174
|
+
override readonly name = STAGE_RELEASED_NAME;
|
|
175
|
+
declare readonly code: StageRecipientReleasedCode;
|
|
176
|
+
constructor(fields: IntercomRecipientGoneErrorFields, options?: { readonly cause?: Error }) {
|
|
177
|
+
super("recipient_stage_released", fields, options);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const NAMES: ReadonlySet<string> = new Set([
|
|
182
|
+
BASE_NAME,
|
|
183
|
+
ENDED_NAME,
|
|
184
|
+
DISCONNECTED_NAME,
|
|
185
|
+
OWNER_SUSPENDED_NAME,
|
|
186
|
+
STAGE_RELEASED_NAME,
|
|
187
|
+
]);
|
|
188
|
+
const STAGE_RELEASED_NAMES: ReadonlySet<string> = new Set([STAGE_RELEASED_NAME]);
|
|
159
189
|
const ENDED_NAMES: ReadonlySet<string> = new Set([ENDED_NAME]);
|
|
160
190
|
const DISCONNECTED_NAMES: ReadonlySet<string> = new Set([DISCONNECTED_NAME]);
|
|
161
191
|
const OWNER_SUSPENDED_NAMES: ReadonlySet<string> = new Set([OWNER_SUSPENDED_NAME]);
|
|
@@ -180,6 +210,10 @@ export function isSubagentRecipientOwnerSuspendedError(error: Error): error is S
|
|
|
180
210
|
return error instanceof SubagentRecipientOwnerSuspendedError || hasStructure(error, OWNER_SUSPENDED_NAMES);
|
|
181
211
|
}
|
|
182
212
|
|
|
213
|
+
export function isStageRecipientReleasedError(error: Error): error is StageRecipientReleasedError {
|
|
214
|
+
return error instanceof StageRecipientReleasedError || hasStructure(error, STAGE_RELEASED_NAMES);
|
|
215
|
+
}
|
|
216
|
+
|
|
183
217
|
const MAX_CAUSE_DEPTH = 4;
|
|
184
218
|
|
|
185
219
|
/** Whether the error, or one of its first causes, is a gone-recipient refusal that may be retried. */
|
|
@@ -230,7 +264,14 @@ export function rehydrateIntercomRecipientGoneError(
|
|
|
230
264
|
): IntercomRecipientGoneError {
|
|
231
265
|
const options = serialized.cause === undefined ? undefined : { cause: rehydrateErrorCause(serialized.cause, 1) };
|
|
232
266
|
const { code, fields } = serialized;
|
|
233
|
-
if (serialized.name ===
|
|
267
|
+
if (serialized.name === STAGE_RELEASED_NAME && code === "recipient_stage_released")
|
|
268
|
+
return new StageRecipientReleasedError(fields, options);
|
|
269
|
+
if (
|
|
270
|
+
serialized.name === ENDED_NAME &&
|
|
271
|
+
code !== "recipient_disconnected" &&
|
|
272
|
+
code !== "recipient_owner_suspended" &&
|
|
273
|
+
code !== "recipient_stage_released"
|
|
274
|
+
)
|
|
234
275
|
return new SubagentRecipientEndedError(code, fields, options);
|
|
235
276
|
if (serialized.name === DISCONNECTED_NAME && code === "recipient_disconnected")
|
|
236
277
|
return new SubagentRecipientDisconnectedError(fields, options);
|
|
@@ -158,7 +158,7 @@ type WireObject = { readonly [key: string]: JsonWireValue };
|
|
|
158
158
|
const isWireObject = (value: JsonWireValue | undefined): value is WireObject =>
|
|
159
159
|
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
160
160
|
|
|
161
|
-
function readCause(value: JsonWireValue | undefined, depth: number): SerializedErrorCause | undefined | false {
|
|
161
|
+
export function readCause(value: JsonWireValue | undefined, depth: number): SerializedErrorCause | undefined | false {
|
|
162
162
|
if (value === undefined) return undefined;
|
|
163
163
|
if (!isWireObject(value) || typeof value.name !== "string" || typeof value.message !== "string") return false;
|
|
164
164
|
const next = depth < MAX_CAUSE_DEPTH ? readCause(value.cause, depth + 1) : undefined;
|
|
@@ -43,6 +43,24 @@ export interface BrokerConnectedSession {
|
|
|
43
43
|
supervisorOwnerToken?: string;
|
|
44
44
|
/** #3761: the recipient confirms each message once it has saved it; `delivered` waits for that confirmation. */
|
|
45
45
|
readonly acknowledgesReceipt?: true;
|
|
46
|
+
/** #4642: the session id of the connection hosting this session, whose `socket` it shares. */
|
|
47
|
+
readonly hostedBy?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A message frame for `recipient`; the connection hosting a hosted recipient learns which of its sessions it is for. */
|
|
51
|
+
export function messageFrameFor(
|
|
52
|
+
recipient: BrokerConnectedSession,
|
|
53
|
+
from: SessionInfo,
|
|
54
|
+
message: Message,
|
|
55
|
+
channel?: "supervisor",
|
|
56
|
+
): Extract<BrokerMessage, { type: "message" }> {
|
|
57
|
+
return {
|
|
58
|
+
type: "message",
|
|
59
|
+
from,
|
|
60
|
+
message,
|
|
61
|
+
...(channel === undefined ? {} : { channel }),
|
|
62
|
+
...(recipient.hostedBy === undefined ? {} : { hostedRecipient: recipient.info.id }),
|
|
63
|
+
};
|
|
46
64
|
}
|
|
47
65
|
|
|
48
66
|
/** Immutable registration authority plus normalized memberships used when an accepted ask is rebound. */
|
|
@@ -696,9 +714,7 @@ export function handleBrokerSend(
|
|
|
696
714
|
) {
|
|
697
715
|
return;
|
|
698
716
|
}
|
|
699
|
-
const outbound = supervisorSend
|
|
700
|
-
? ({ type: "message", from: fromSession.info, message, channel: "supervisor" } as const)
|
|
701
|
-
: ({ type: "message", from: fromSession.info, message } as const);
|
|
717
|
+
const outbound = messageFrameFor(target, fromSession.info, message, supervisorSend ? "supervisor" : undefined);
|
|
702
718
|
const failDelivery = (): void => {
|
|
703
719
|
if (reservation === "recorded") deliveredMessages.forget(message.id, signature);
|
|
704
720
|
write(socket, {
|
|
@@ -2,7 +2,11 @@ import type net from "node:net";
|
|
|
2
2
|
import type { BrokerMessage } from "../types.js";
|
|
3
3
|
import type { WorkflowSendPredictionFields } from "../workflow-prediction-fields.js";
|
|
4
4
|
import { writeMessage } from "./framing.js";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
type BrokerProtocolRange,
|
|
7
|
+
HOSTED_SESSIONS_PROTOCOL,
|
|
8
|
+
VERIFIED_REGISTRATION_PROTOCOL,
|
|
9
|
+
} from "./protocol-version.js";
|
|
6
10
|
|
|
7
11
|
/**
|
|
8
12
|
* Broker-side socket writes.
|
|
@@ -78,17 +82,32 @@ export const PROTOCOL_2_FRAME_TYPES: ReadonlySet<BrokerOutboundFrame["type"]> =
|
|
|
78
82
|
"restoring_recipient_wake",
|
|
79
83
|
]);
|
|
80
84
|
|
|
85
|
+
/** #4642: frames of protocol 3, written only to a client that registered speaking it. */
|
|
86
|
+
export const PROTOCOL_3_FRAME_TYPES: ReadonlySet<BrokerOutboundFrame["type"]> = new Set<BrokerOutboundFrame["type"]>([
|
|
87
|
+
"hosted_sessions_ack",
|
|
88
|
+
]);
|
|
89
|
+
|
|
81
90
|
/** Sockets whose client registered speaking protocol 1 only. */
|
|
82
91
|
const protocol1Clients = new WeakSet<net.Socket>();
|
|
92
|
+
/** #4642: sockets whose client registered speaking protocol 3 or later. */
|
|
93
|
+
const hostingClients = new WeakSet<net.Socket>();
|
|
83
94
|
|
|
84
95
|
/** Record the protocol range the client on `socket` registered with, before anything is written to it. */
|
|
85
96
|
export function recordClientProtocol(socket: net.Socket, protocol: BrokerProtocolRange): void {
|
|
86
97
|
if (protocol.max < VERIFIED_REGISTRATION_PROTOCOL) protocol1Clients.add(socket);
|
|
87
98
|
else protocol1Clients.delete(socket);
|
|
99
|
+
if (protocol.max >= HOSTED_SESSIONS_PROTOCOL) hostingClients.add(socket);
|
|
100
|
+
else hostingClients.delete(socket);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** #4642: whether the client on `socket` registered speaking protocol 3, so it may host sessions. */
|
|
104
|
+
export function clientHostsSessions(socket: net.Socket): boolean {
|
|
105
|
+
return hostingClients.has(socket);
|
|
88
106
|
}
|
|
89
107
|
|
|
90
108
|
/** Whether the client on `socket` knows the type of `message`. */
|
|
91
109
|
function clientKnows(socket: net.Socket, message: BrokerOutboundFrame): boolean {
|
|
110
|
+
if (PROTOCOL_3_FRAME_TYPES.has(message.type)) return hostingClients.has(socket);
|
|
92
111
|
return !(protocol1Clients.has(socket) && PROTOCOL_2_FRAME_TYPES.has(message.type));
|
|
93
112
|
}
|
|
94
113
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { IntercomBrokerTimeoutError } from "./recoverable-disconnect.js";
|
|
2
|
+
|
|
3
|
+
export type IntercomHostedSessionTimeoutCode = "hosted_session_timeout";
|
|
4
|
+
|
|
5
|
+
/** The step that was waiting: the broker's answer to a request to host or remove sessions on a connection. */
|
|
6
|
+
export type IntercomHostedSessionTimeoutPhase = "hosted-session-request";
|
|
7
|
+
|
|
8
|
+
/** The request that went unanswered. */
|
|
9
|
+
export type IntercomHostedSessionRequestType = "host_sessions" | "unhost_sessions";
|
|
10
|
+
|
|
11
|
+
const HOSTED_SESSION_TIMEOUT_HINT =
|
|
12
|
+
"Hosting is tried again on the next connection; run `atomic intercom restart` if the broker keeps timing out.";
|
|
13
|
+
|
|
14
|
+
export interface IntercomHostedSessionTimeoutFields {
|
|
15
|
+
readonly requestType: IntercomHostedSessionRequestType;
|
|
16
|
+
/** Sessions the request carried; never the sessions themselves. */
|
|
17
|
+
readonly sessionCount: number;
|
|
18
|
+
readonly timeoutMs: number;
|
|
19
|
+
/**
|
|
20
|
+
* Whole milliseconds from writing the request to the bound expiring, on the monotonic clock; past `timeoutMs` when
|
|
21
|
+
* the event loop was late.
|
|
22
|
+
*/
|
|
23
|
+
readonly elapsedMs: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The broker was asked to host or remove sessions on a connection and did not answer within its bound. It is an
|
|
28
|
+
* {@link IntercomBrokerTimeoutError}, so every recoverable-disconnect check still recognizes it; `cause` is the failed
|
|
29
|
+
* broker health check when the connection was given up as well.
|
|
30
|
+
*/
|
|
31
|
+
export class IntercomHostedSessionTimeoutError extends IntercomBrokerTimeoutError {
|
|
32
|
+
override readonly name = "IntercomHostedSessionTimeoutError" as const;
|
|
33
|
+
readonly code: IntercomHostedSessionTimeoutCode = "hosted_session_timeout";
|
|
34
|
+
readonly phase: IntercomHostedSessionTimeoutPhase = "hosted-session-request";
|
|
35
|
+
readonly retryable = true as const;
|
|
36
|
+
readonly hint = HOSTED_SESSION_TIMEOUT_HINT;
|
|
37
|
+
readonly requestType: IntercomHostedSessionRequestType;
|
|
38
|
+
readonly sessionCount: number;
|
|
39
|
+
readonly timeoutMs: number;
|
|
40
|
+
readonly elapsedMs: number;
|
|
41
|
+
|
|
42
|
+
constructor(fields: IntercomHostedSessionTimeoutFields, options?: ErrorOptions) {
|
|
43
|
+
super(
|
|
44
|
+
`Hosted-session request timed out: ${fields.requestType} for ${fields.sessionCount} sessions, unanswered after ${fields.elapsedMs} ms of ${fields.timeoutMs} ms (hosted_session_timeout). ${HOSTED_SESSION_TIMEOUT_HINT}`,
|
|
45
|
+
options,
|
|
46
|
+
);
|
|
47
|
+
this.requestType = fields.requestType;
|
|
48
|
+
this.sessionCount = fields.sessionCount;
|
|
49
|
+
this.timeoutMs = fields.timeoutMs;
|
|
50
|
+
this.elapsedMs = fields.elapsedMs;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** True for an {@link IntercomHostedSessionTimeoutError}, or an error of another realm shaped like one, by `name` and `code`. */
|
|
55
|
+
export function isIntercomHostedSessionTimeoutError(value: unknown): value is IntercomHostedSessionTimeoutError {
|
|
56
|
+
if (typeof value !== "object" || value === null) return false;
|
|
57
|
+
const { name, code } = value as { readonly name?: unknown; readonly code?: unknown };
|
|
58
|
+
return name === "IntercomHostedSessionTimeoutError" && code === "hosted_session_timeout";
|
|
59
|
+
}
|