@bastani/atomic 0.9.76 → 0.9.77-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 +23 -0
- package/dist/builtin/intercom/CHANGELOG.md +13 -0
- package/dist/builtin/intercom/broker/broker.ts +153 -6
- package/dist/builtin/intercom/broker/client.ts +85 -3
- package/dist/builtin/intercom/broker/departed-children.ts +471 -0
- package/dist/builtin/intercom/broker/recipient-gone-errors.ts +280 -0
- package/dist/builtin/intercom/broker/restoring-recipients.ts +108 -7
- package/dist/builtin/intercom/broker/send-handler.ts +42 -0
- package/dist/builtin/intercom/broker/workflow-stage-aliases.ts +69 -0
- package/dist/builtin/intercom/index.bundle.mjs +374 -129
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/intercom/types.ts +30 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +15 -0
- package/dist/builtin/subagents/README.md +1 -1
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/subagents/skills/agent-browser/SKILL.md +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +64 -4
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +14 -0
- package/dist/builtin/workflows/README.md +1 -1
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/SKILL.md +3 -3
- package/dist/builtin/workflows/skills/impeccable/scripts/VERSION +1 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/engine-checksums.txt +5 -5
- package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +71 -56
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +315 -112
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +168 -9
- package/dist/builtin/workflows/src/index.js +168 -9
- package/dist/builtin/workflows/src/local-worker-entry.mjs +168 -9
- package/dist/core/agent-session-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-compaction.js +2 -1
- package/dist/core/agent-session-compaction.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 +1 -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.map +1 -1
- package/dist/core/agent-session-state.js +7 -2
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session-tasks.d.ts +6 -0
- package/dist/core/agent-session-tasks.d.ts.map +1 -1
- package/dist/core/agent-session-tasks.js +13 -25
- package/dist/core/agent-session-tasks.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +2 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +2 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/loader-rollback.d.ts.map +1 -1
- package/dist/core/extensions/loader-rollback.js +1 -0
- package/dist/core/extensions/loader-rollback.js.map +1 -1
- package/dist/core/extensions/runner-context.d.ts +3 -3
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.js +2 -1
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +9 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +16 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/sdk-types.d.ts +5 -0
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +8 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/system-prompt.d.ts +6 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +26 -18
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/agent-adapter.js +2 -2
- package/dist/core/tasks/agent-adapter.js.map +1 -1
- package/dist/core/tasks/cancel-reason.d.ts +20 -0
- package/dist/core/tasks/cancel-reason.d.ts.map +1 -0
- package/dist/core/tasks/cancel-reason.js +47 -0
- package/dist/core/tasks/cancel-reason.js.map +1 -0
- package/dist/core/tasks/child-command-owner.d.ts +1 -1
- package/dist/core/tasks/child-command-owner.d.ts.map +1 -1
- package/dist/core/tasks/child-command-owner.js +22 -0
- package/dist/core/tasks/child-command-owner.js.map +1 -1
- package/dist/core/tasks/completion-message.d.ts +11 -0
- package/dist/core/tasks/completion-message.d.ts.map +1 -0
- package/dist/core/tasks/completion-message.js +30 -0
- package/dist/core/tasks/completion-message.js.map +1 -0
- package/dist/core/tasks/completion.d.ts +2 -0
- package/dist/core/tasks/completion.d.ts.map +1 -1
- package/dist/core/tasks/completion.js +30 -14
- package/dist/core/tasks/completion.js.map +1 -1
- package/dist/core/tasks/contracts.d.ts +4 -0
- package/dist/core/tasks/contracts.d.ts.map +1 -1
- package/dist/core/tasks/contracts.js.map +1 -1
- package/dist/core/tasks/supervisor.d.ts +29 -3
- package/dist/core/tasks/supervisor.d.ts.map +1 -1
- package/dist/core/tasks/supervisor.js +48 -25
- package/dist/core/tasks/supervisor.js.map +1 -1
- package/dist/core/tasks/task-view-source.d.ts +6 -0
- package/dist/core/tasks/task-view-source.d.ts.map +1 -1
- package/dist/core/tasks/task-view-source.js +49 -0
- package/dist/core/tasks/task-view-source.js.map +1 -1
- package/dist/core/tools/bash-pty-native.d.ts +6 -1
- package/dist/core/tools/bash-pty-native.d.ts.map +1 -1
- package/dist/core/tools/bash-pty-native.js +5 -1
- package/dist/core/tools/bash-pty-native.js.map +1 -1
- package/dist/core/tools/bash.d.ts +5 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +14 -5
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/history-protocol.d.ts +15 -1
- package/dist/core/tools/history-protocol.d.ts.map +1 -1
- package/dist/core/tools/history-protocol.js +9 -7
- package/dist/core/tools/history-protocol.js.map +1 -1
- package/dist/core/tools/shell-task-status.d.ts.map +1 -1
- package/dist/core/tools/shell-task-status.js +3 -13
- package/dist/core/tools/shell-task-status.js.map +1 -1
- package/dist/core/workflow-stage-admission.d.ts +2 -0
- package/dist/core/workflow-stage-admission.d.ts.map +1 -1
- package/dist/core/workflow-stage-admission.js +36 -6
- package/dist/core/workflow-stage-admission.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.js +12 -8
- package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.d.ts +2 -0
- package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.js +2 -0
- package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-types.d.ts +6 -0
- package/dist/modes/interactive/components/chat-session-host-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-types.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +5 -2
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +8 -5
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +5 -2
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/input-label.d.ts +29 -0
- package/dist/modes/interactive/components/input-label.d.ts.map +1 -0
- package/dist/modes/interactive/components/input-label.js +75 -0
- package/dist/modes/interactive/components/input-label.js.map +1 -0
- package/dist/modes/interactive/components/task-inspector.d.ts +4 -1
- package/dist/modes/interactive/components/task-inspector.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-inspector.js +6 -2
- package/dist/modes/interactive/components/task-inspector.js.map +1 -1
- package/dist/modes/interactive/components/task-transcript-page.d.ts +12 -1
- package/dist/modes/interactive/components/task-transcript-page.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-transcript-page.js +63 -6
- package/dist/modes/interactive/components/task-transcript-page.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +1 -0
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +1 -0
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive-engine/engine-session-stats.d.ts +1 -1
- package/dist/modes/interactive-engine/engine-session-stats.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-session-stats.js.map +1 -1
- package/dist/modes/rpc/task-ui-bridge.d.ts +2 -2
- package/dist/modes/rpc/task-ui-bridge.d.ts.map +1 -1
- package/dist/modes/rpc/task-ui-bridge.js +2 -0
- package/dist/modes/rpc/task-ui-bridge.js.map +1 -1
- package/docs/background-tasks.md +14 -1
- package/docs/getting-started/first-session.md +1 -1
- package/docs/intercom/operations.md +4 -2
- package/docs/intercom/reference.md +18 -1
- package/docs/llama-cpp.md +1 -1
- package/docs/sessions.md +1 -1
- package/docs/subagents.md +5 -1
- package/docs/tools.md +1 -1
- package/docs/usage.md +1 -12
- package/docs/workflows/operations.md +3 -1
- package/docs/workflows/verification.md +1 -8
- package/npm-shrinkwrap.json +83 -98
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.9.77-alpha.1] - 2026-11-11
|
|
6
|
+
|
|
7
|
+
Subagent chats look and scope like stage chats, agents recall project history, and background shells explain why they stopped.
|
|
8
|
+
|
|
9
|
+
- **Subagent chat box.** A subagent's transcript in `/tasks` gets a workflow stage's chat box, with its own usage, model, footer and `/tasks` list, so you can follow and manage one subagent without the parent's tasks in the way ([#4640](https://github.com/bastani-inc/atomic/issues/4640), [#4646](https://github.com/bastani-inc/atomic/pull/4646)).
|
|
10
|
+
- **Project memory by default.** Workflow stages and subagents read and search the project's sessions and workflow runs through `history://`, and agents consult earlier runs and your stated preferences before choosing workflow versus inline, verification and estimates ([#4648](https://github.com/bastani-inc/atomic/issues/4648), [#4649](https://github.com/bastani-inc/atomic/pull/4649)).
|
|
11
|
+
- **Reliable background shells.** Subagents keep their shells when their workflow stage is released or replaced, and a shell that ends now says why, including the execution timeout that stopped it ([#4639](https://github.com/bastani-inc/atomic/issues/4639), [#4650](https://github.com/bastani-inc/atomic/pull/4650)).
|
|
12
|
+
- **Upstream fixes.** `/share` reports a failed `gh` start instead of crashing, the llama.cpp guide uses `llama --version`, and the pi packages move to 1.5.2 ([#4638](https://github.com/bastani-inc/atomic/pull/4638), [#4647](https://github.com/bastani-inc/atomic/pull/4647)).
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- A subagent's transcript in `/tasks` now has the chat box of a workflow stage chat: its prompt's top rule names the subagent, as `[subagent: <name>]`, and while it runs its usage meter, model line, working line and queued messages sit around the prompt in the same order, with a footer counting its own running tasks. `/tasks` typed there lists that subagent's own shells and the subagents it launched instead of the parent's, also for nested subagents, and Escape or Left returns to its chat ([#4640](https://github.com/bastani-inc/atomic/issues/4640))
|
|
17
|
+
- Updated `@earendil-works/pi-tui`, `@earendil-works/pi-agent-core`, `@earendil-works/pi-codemode`, `@earendil-works/pi-schema` and `@earendil-works/pi-telemetry` to 1.5.2; the intercom, subagents, web-access and workflows packages now require `@earendil-works/pi-tui` and `@earendil-works/pi-agent-core` `^1.5.2`
|
|
18
|
+
- Workflow stages and subagents now recall the project's history by default: `read` and `search` on `history://workflows` and `history://` reach the project's workflow runs, and a subagent's `history://sessions` lists the project's sessions rather than only its own. A subagent whose own prompt replaces the default prompt also gets the Session memory guidance ([#4648](https://github.com/bastani-inc/atomic/issues/4648))
|
|
19
|
+
- The default prompt's Session memory guidance now has the agent recall comparable earlier sessions and workflow runs, and the preferences you stated in them, before it chooses between a workflow and inline work, how to verify a change, or how long a task will take. With a shell tool it also suggests searching commits, issues, PRs and their comments for relevant prior work ([#4648](https://github.com/bastani-inc/atomic/issues/4648))
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- Fixed the llama.cpp setup guide telling you to verify the installation with `llama cli --version`; it now uses the unified `llama --version` entry point (upstream [#11958](https://github.com/earendil-works/pi/pull/11958))
|
|
24
|
+
- Fixed `/share` crashing Atomic when the `gh` command fails to start while creating the gist; it now shows the error (upstream [#12025](https://github.com/earendil-works/pi/pull/12025))
|
|
25
|
+
- Fixed subagents of a workflow stage losing their background shells when the stage is released while it waits or its session is replaced: the subagent can still wait on, stop and start shells instead of failing with `Task owner is closed` or `stage-parked`, and its shells' completion notices still reach it ([#4639](https://github.com/bastani-inc/atomic/issues/4639)).
|
|
26
|
+
- Fixed a background shell's end being unexplained: its wait result and completion notice now name an execution timeout with its length (`timed out after 300 seconds`), a workflow stage that closed, a session that closed or Atomic shutting down, instead of the same `session closed` for every close. A command that continues in the background now names the timeout that will stop it, and a `wait` that sees the timeout stop it returns an error. A cancelled SDK `TaskResult` carries the same facts as `ownerClose` and `executionTimeoutMs` ([#4639](https://github.com/bastani-inc/atomic/issues/4639)).
|
|
27
|
+
|
|
5
28
|
## [0.9.76] - 2026-11-10
|
|
6
29
|
|
|
7
30
|
Claude Fable 5.2 works with an Anthropic subscription login.
|
|
@@ -4,6 +4,19 @@ All notable changes to the `pi-intercom` extension will be documented in this fi
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.9.77-alpha.1] - 2026-11-11
|
|
8
|
+
|
|
9
|
+
Messages to ended, released or replaced sessions arrive or fail with a reason.
|
|
10
|
+
|
|
11
|
+
- **Explained recipient errors.** Sends to a subagent that ended or disconnected are held briefly and delivered if it returns, otherwise refused with a typed error that says how it ended and how to resume it ([#4639](https://github.com/bastani-inc/atomic/issues/4639), [#4650](https://github.com/bastani-inc/atomic/pull/4650)).
|
|
12
|
+
- **Suspended and replaced stages.** Sends to a workflow stage, or to subagents of a stage that is suspended, reach its current session or queue until it reopens instead of answering `Session not found` ([#4639](https://github.com/bastani-inc/atomic/issues/4639), [#4650](https://github.com/bastani-inc/atomic/pull/4650)).
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- Fixed sends and asks to a subagent that just ended or dropped its connection failing with a bare `Session not found`: the broker now holds them for up to 20 seconds, delivers them once if the subagent reconnects, and otherwise refuses them with a typed `IntercomRecipientGoneError` that names how the subagent ended (`recipient_completed`, `recipient_failed`, `recipient_stopped`, `recipient_cancelled`, or the retryable `recipient_disconnected`) and the `subagent({ action: "resume" })` call to make. What the launching session reported survives the closing of its connection, as a suspended workflow stage's does, until the session is back ([#4639](https://github.com/bastani-inc/atomic/issues/4639))
|
|
17
|
+
- Fixed sends and asks to a released subagent answering `Session not found` once the session that launched it lost its connection, as a workflow stage's does while it is suspended: the broker keeps the subagent's hold for that session, holds each send up to 20 seconds and then refuses it with the retryable `recipient_owner_suspended` error, and the session, once back, takes the subagent over and wakes it for the sends waiting then ([#4639](https://github.com/bastani-inc/atomic/issues/4639))
|
|
18
|
+
- Fixed sends to a workflow stage's session name or session ID returning `Session not found` once the stage's session was replaced or released while it waits: they now reach the stage's current session, or queue for the stage until it reopens, for senders in the stage's group and for the session that launched the run. `contact_supervisor` from a subagent of such a stage is queued for the stage the same way instead of failing ([#4639](https://github.com/bastani-inc/atomic/issues/4639))
|
|
19
|
+
|
|
7
20
|
## [0.9.73] - 2026-11-08
|
|
8
21
|
|
|
9
22
|
Intercom connects in every session of a multi-directory process.
|
|
@@ -97,6 +97,9 @@ import {
|
|
|
97
97
|
validateReleasedChildFrame,
|
|
98
98
|
} from "./released-children.js";
|
|
99
99
|
import { type HeldSend, RestoringRecipients, type RestoringRecipientWake } from "./restoring-recipients.js";
|
|
100
|
+
import { DepartedChildren, type HeldSendRefusal, validateEndedChildrenFrame } from "./departed-children.js";
|
|
101
|
+
import { WorkflowStageAliases } from "./workflow-stage-aliases.js";
|
|
102
|
+
import { type IntercomRecipientGoneError, serializeIntercomRecipientGoneError } from "./recipient-gone-errors.js";
|
|
100
103
|
import { ReleasedAskerReplies, type ReleasedAskerReplyRoute } from "./released-asker-replies.js";
|
|
101
104
|
import { releasedAskerReplyRefusal } from "./released-asker-remote-replies.js";
|
|
102
105
|
import { hasGroup, normalizeGroup, normalizeGroups, workflowInvocationRefusalFor } from "../group.js";
|
|
@@ -397,13 +400,17 @@ class IntercomBroker {
|
|
|
397
400
|
console.error("Intercom broker released-asker reply route capacity reached; dropped routes are counted in broker_status");
|
|
398
401
|
});
|
|
399
402
|
private releasedReplyAcks = new Map<string, PendingReleasedReplyAck>();
|
|
400
|
-
private restoringRecipients = new RestoringRecipients((held, reason, reasonCode) =>
|
|
401
|
-
this.failHeldSend(held, reason, reasonCode),
|
|
403
|
+
private restoringRecipients = new RestoringRecipients((held, reason, reasonCode, error) =>
|
|
404
|
+
error === undefined ? this.failHeldSend(held, reason, reasonCode) : this.failHeldSendWith(held, error),
|
|
402
405
|
);
|
|
406
|
+
/** #4639: subagents whose session is gone, held for until they return or their owner says why they ended. */
|
|
407
|
+
private departedChildren = new DepartedChildren((refusals) => this.refuseHeldSends(refusals));
|
|
403
408
|
private pendingStageRoutes = new Map<string, PendingStageRouteRegistration>();
|
|
404
409
|
private pendingStageAcknowledgments = new Map<string, PendingStageAcknowledgment>();
|
|
405
410
|
private pendingStageNotificationAcknowledgments = new Map<string, PendingStageNotificationAcknowledgment>();
|
|
406
411
|
private liveWorkflowStageRoutes = new Map<string, LiveWorkflowStageRouteRegistration>();
|
|
412
|
+
/** #4639: the names and ids each stage's sessions registered under, so they keep reaching the stage. */
|
|
413
|
+
private workflowStageAliases = new WorkflowStageAliases();
|
|
407
414
|
private workflowRosters = new Map<string, WorkflowRosterRegistration>();
|
|
408
415
|
private liveWorkflowStageRouteActivations = new Map<string, LiveWorkflowStageRouteActivation>();
|
|
409
416
|
/**
|
|
@@ -981,6 +988,7 @@ class IntercomBroker {
|
|
|
981
988
|
for (const target of targets) {
|
|
982
989
|
this.liveWorkflowStageRoutes.set(target, { sessionId: currentId, capability, runId });
|
|
983
990
|
}
|
|
991
|
+
this.recordWorkflowStageAliases(currentId, runId, registrant?.target ?? targets[0]);
|
|
984
992
|
const pendingRequestIds = new Set(
|
|
985
993
|
[...this.pendingStageAcknowledgments]
|
|
986
994
|
.filter(([, pending]) => {
|
|
@@ -1012,6 +1020,31 @@ class IntercomBroker {
|
|
|
1012
1020
|
return undefined;
|
|
1013
1021
|
}
|
|
1014
1022
|
|
|
1023
|
+
/** #4639: the stage session's names and ids reach its stage at `target` for as long as the run's route lives. */
|
|
1024
|
+
private recordWorkflowStageAliases(sessionId: string, runId: string, target: string | undefined): void {
|
|
1025
|
+
const session = this.sessions.get(sessionId);
|
|
1026
|
+
if (session === undefined || target === undefined) return;
|
|
1027
|
+
const group = normalizeGroup(session.registrationGroup ?? session.info.group);
|
|
1028
|
+
const aliases = [session.info.name, session.registrationName, session.info.id, session.registrationReturnAddress];
|
|
1029
|
+
this.workflowStageAliases.record({ runId, target, group }, aliases.filter((alias): alias is string => alias !== undefined));
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* #4639: the `workflow:` target a stage session's name or id stands for, to a sender that may reach the stage: one
|
|
1034
|
+
* in the stage's group, or one that controls its run. Anyone else finds nothing, as before.
|
|
1035
|
+
*/
|
|
1036
|
+
private resolveWorkflowStageAlias = (sender: ConnectedSession, alias: string): string | undefined => {
|
|
1037
|
+
const stage = this.workflowStageAliases.resolve(alias);
|
|
1038
|
+
if (stage === undefined) return undefined;
|
|
1039
|
+
const route = this.pendingStageRoutes.get(stage.runId);
|
|
1040
|
+
if (route === undefined) {
|
|
1041
|
+
this.workflowStageAliases.forgetRun(stage.runId);
|
|
1042
|
+
return undefined;
|
|
1043
|
+
}
|
|
1044
|
+
const reachable = hasGroup(sessionGroups(sender.info), stage.group) || this.canControlWorkflowInvocation(sender, route.group);
|
|
1045
|
+
return reachable ? stage.target : undefined;
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1015
1048
|
private routePendingStage = (route: PendingStageRoute): boolean => {
|
|
1016
1049
|
const ownerMatch = this.pendingStageOwnerForTarget(route.target);
|
|
1017
1050
|
if (ownerMatch === undefined) return false;
|
|
@@ -1019,6 +1052,7 @@ class IntercomBroker {
|
|
|
1019
1052
|
const owner = this.sessions.get(ownerRegistration.sessionId);
|
|
1020
1053
|
if (owner === undefined) {
|
|
1021
1054
|
this.pendingStageRoutes.delete(runId);
|
|
1055
|
+
this.workflowStageAliases.forgetRun(runId);
|
|
1022
1056
|
return false;
|
|
1023
1057
|
}
|
|
1024
1058
|
if (route.liveTargetId === undefined && !this.canControlWorkflowInvocation(route.from, ownerRegistration.group)) {
|
|
@@ -1793,6 +1827,9 @@ class IntercomBroker {
|
|
|
1793
1827
|
? { registrationReturnAddress: clientMessage.returnAddress }
|
|
1794
1828
|
: {}),
|
|
1795
1829
|
...(supervisorId ? { supervisorId } : {}),
|
|
1830
|
+
...(supervisorId && this.sessions.get(supervisorId)?.registrationReturnAddress !== undefined
|
|
1831
|
+
? { supervisorReturnAddress: this.sessions.get(supervisorId)?.registrationReturnAddress }
|
|
1832
|
+
: {}),
|
|
1796
1833
|
...(typeof clientMessage.supervisorOwnerToken === "string"
|
|
1797
1834
|
? { supervisorOwnerToken: clientMessage.supervisorOwnerToken }
|
|
1798
1835
|
: {}),
|
|
@@ -1819,6 +1856,7 @@ class IntercomBroker {
|
|
|
1819
1856
|
brokerStatus: true as const,
|
|
1820
1857
|
claimsWorkflowInvocations: true as const,
|
|
1821
1858
|
extendsSaves: true as const,
|
|
1859
|
+
marksEndedChildren: true as const,
|
|
1822
1860
|
multiNodeRouting: this.multiNodeStatus,
|
|
1823
1861
|
protocol: { ...BROKER_PROTOCOL },
|
|
1824
1862
|
});
|
|
@@ -1851,6 +1889,10 @@ class IntercomBroker {
|
|
|
1851
1889
|
: undefined,
|
|
1852
1890
|
))
|
|
1853
1891
|
this.dispatchSend(send.socket, send.clientMessage, send.senderId);
|
|
1892
|
+
// #4639: a subagent whose session dropped is back under its owner's authorization; its held sends follow.
|
|
1893
|
+
if (registered !== undefined && supervisorId !== undefined)
|
|
1894
|
+
for (const send of this.departedChildren.registered(registered, sessionGroups(info), supervisorId))
|
|
1895
|
+
this.dispatchSend(send.socket, send.clientMessage, send.senderId);
|
|
1854
1896
|
};
|
|
1855
1897
|
// Multi-node S5: brokers on other hosts find this session through its presence lease, so registration
|
|
1856
1898
|
// completes once the lease is written (or bounded attempts found it still held elsewhere). The session is
|
|
@@ -1985,6 +2027,7 @@ class IntercomBroker {
|
|
|
1985
2027
|
aliases,
|
|
1986
2028
|
{ dormant: clientMessage.dormant === true },
|
|
1987
2029
|
);
|
|
2030
|
+
this.dispatchHeldSends(this.departedChildren.supersede(currentId, childName));
|
|
1988
2031
|
writeMessageIfOpen(socket, { type: "restoring_recipient_ack", requestId: clientMessage.requestId });
|
|
1989
2032
|
break;
|
|
1990
2033
|
}
|
|
@@ -1994,6 +2037,8 @@ class IntercomBroker {
|
|
|
1994
2037
|
if (owner === undefined || typeof clientMessage.requestId !== "string") {
|
|
1995
2038
|
throw new Error("Invalid reserve_released_children message");
|
|
1996
2039
|
}
|
|
2040
|
+
// #4639: a host session back after its connection closed takes over the released children it kept.
|
|
2041
|
+
this.adoptOrphans(currentId, owner);
|
|
1997
2042
|
const validation = validateReleasedChildFrame(clientMessage.children);
|
|
1998
2043
|
const refusal = validation.ok ? this.releasedChildrenRefusal(owner, validation.children) : validation.refusal;
|
|
1999
2044
|
if (!validation.ok || refusal !== undefined) {
|
|
@@ -2003,7 +2048,29 @@ class IntercomBroker {
|
|
|
2003
2048
|
for (const child of validation.children) {
|
|
2004
2049
|
this.reserveReleasedChild(currentId, owner.registrationGroup, child);
|
|
2005
2050
|
this.releasedAskerReplies.attach(child.childName, currentId);
|
|
2051
|
+
this.dispatchHeldSends(this.departedChildren.supersede(currentId, child.childName));
|
|
2052
|
+
}
|
|
2053
|
+
writeMessageIfOpen(socket, { type: "released_children_ack", requestId: clientMessage.requestId });
|
|
2054
|
+
break;
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
case "mark_ended_children": {
|
|
2058
|
+
const owner = this.sessions.get(currentId);
|
|
2059
|
+
if (owner === undefined || typeof clientMessage.requestId !== "string") {
|
|
2060
|
+
throw new Error("Invalid mark_ended_children message");
|
|
2006
2061
|
}
|
|
2062
|
+
this.adoptOrphans(currentId, owner);
|
|
2063
|
+
const validation = validateEndedChildrenFrame(clientMessage.children, owner.registrationGroup);
|
|
2064
|
+
const refusal = validation.ok
|
|
2065
|
+
? this.releasedChildrenRefusal(owner, validation.children.map((child) => ({ ...child, wake: false })))
|
|
2066
|
+
: validation.refusal;
|
|
2067
|
+
if (!validation.ok || refusal !== undefined) {
|
|
2068
|
+
writeMessageIfOpen(socket, { type: "released_children_ack", requestId: clientMessage.requestId, refusal });
|
|
2069
|
+
break;
|
|
2070
|
+
}
|
|
2071
|
+
const marked = this.departedChildren.mark(currentId, validation.children);
|
|
2072
|
+
this.refuseHeldSends(marked.refused);
|
|
2073
|
+
this.dispatchHeldSends(marked.evicted);
|
|
2007
2074
|
writeMessageIfOpen(socket, { type: "released_children_ack", requestId: clientMessage.requestId });
|
|
2008
2075
|
break;
|
|
2009
2076
|
}
|
|
@@ -2021,6 +2088,7 @@ class IntercomBroker {
|
|
|
2021
2088
|
) {
|
|
2022
2089
|
throw new Error("Invalid drop_released_children message");
|
|
2023
2090
|
}
|
|
2091
|
+
this.adoptOrphans(currentId, owner);
|
|
2024
2092
|
const childNames = clientMessage.childNames as string[];
|
|
2025
2093
|
const refusal = childNames
|
|
2026
2094
|
.map((childName) => this.releasedChildOwnerRefusal(owner, childName))
|
|
@@ -2043,6 +2111,7 @@ class IntercomBroker {
|
|
|
2043
2111
|
if (owner === undefined || typeof clientMessage.requestId !== "string" || typeof clientMessage.childName !== "string") {
|
|
2044
2112
|
throw new Error("Invalid acknowledge_released_child_wake message");
|
|
2045
2113
|
}
|
|
2114
|
+
this.adoptOrphans(currentId, owner);
|
|
2046
2115
|
const childName = clientMessage.childName;
|
|
2047
2116
|
const valid = isValidChildName(childName);
|
|
2048
2117
|
const refusal: ReleasedChildRefusal | undefined = valid ? this.releasedChildOwnerRefusal(owner, childName) : undefined;
|
|
@@ -2446,6 +2515,7 @@ class IntercomBroker {
|
|
|
2446
2515
|
this.routeRemote,
|
|
2447
2516
|
(sender, group) => this.canInspectSelectedGroup(sender, group),
|
|
2448
2517
|
this.routeReleasedAskerReply,
|
|
2518
|
+
this.resolveWorkflowStageAlias,
|
|
2449
2519
|
);
|
|
2450
2520
|
}
|
|
2451
2521
|
|
|
@@ -2573,7 +2643,7 @@ class IntercomBroker {
|
|
|
2573
2643
|
pid: process.pid,
|
|
2574
2644
|
sessions: this.sessions.size,
|
|
2575
2645
|
reservations: this.restoringRecipients.size,
|
|
2576
|
-
heldSends: this.restoringRecipients.heldSendCount,
|
|
2646
|
+
heldSends: this.restoringRecipients.heldSendCount + this.departedChildren.heldSendCount,
|
|
2577
2647
|
droppedReleasedReplyRoutes: this.releasedAskerReplies.droppedRoutes,
|
|
2578
2648
|
...(setting === undefined
|
|
2579
2649
|
? {}
|
|
@@ -2695,13 +2765,49 @@ class IntercomBroker {
|
|
|
2695
2765
|
held,
|
|
2696
2766
|
clientMessage.awaitRestoringRecipient === true,
|
|
2697
2767
|
);
|
|
2698
|
-
if (admission.kind === "none")
|
|
2699
|
-
|
|
2768
|
+
if (admission.kind === "none")
|
|
2769
|
+
return this.holdForDepartedChild(held, target, from, clientMessage.awaitRestoringRecipient === true);
|
|
2770
|
+
if (admission.kind === "refused" && admission.error !== undefined) this.failHeldSendWith(held, admission.error);
|
|
2771
|
+
else if (admission.kind === "refused") this.failHeldSend(held, admission.reason, admission.reasonCode);
|
|
2700
2772
|
else writeMessageIfOpen(socket, { type: "send_held", messageId, ...(attemptId === undefined ? {} : { attemptId }), timeoutMs: admission.timeoutMs });
|
|
2701
2773
|
if (admission.kind === "held" && admission.wake !== undefined) this.wakeRestoringRecipientOwner(admission.wake);
|
|
2702
2774
|
return true;
|
|
2703
2775
|
};
|
|
2704
2776
|
|
|
2777
|
+
/** #4639: a subagent whose session is gone: hold the send for its return or its owner's verdict, or refuse it with why. */
|
|
2778
|
+
private holdForDepartedChild(held: HeldSend, target: string, from: ConnectedSession, canHold: boolean): boolean {
|
|
2779
|
+
const admission = this.departedChildren.admit(target, { id: from.info.id, info: from.info }, held, canHold);
|
|
2780
|
+
if (admission.kind === "none") return false;
|
|
2781
|
+
if (admission.kind === "refused") this.refuseHeldSends([{ held, error: admission.error }]);
|
|
2782
|
+
else
|
|
2783
|
+
writeMessageIfOpen(held.socket, {
|
|
2784
|
+
type: "send_held",
|
|
2785
|
+
messageId: held.messageId,
|
|
2786
|
+
...(held.attemptId === undefined ? {} : { attemptId: held.attemptId }),
|
|
2787
|
+
timeoutMs: admission.timeoutMs,
|
|
2788
|
+
});
|
|
2789
|
+
return true;
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
private dispatchHeldSends(sends: readonly HeldSend[]): void {
|
|
2793
|
+
for (const send of sends) this.dispatchSend(send.socket, send.clientMessage, send.senderId);
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
/** #4639: refuse held sends with the typed error naming why their subagent is gone; its message is the reason. */
|
|
2797
|
+
private refuseHeldSends(refusals: readonly HeldSendRefusal[]): void {
|
|
2798
|
+
for (const { held, error } of refusals) this.failHeldSendWith(held, error);
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
private failHeldSendWith(held: HeldSend, error: IntercomRecipientGoneError): void {
|
|
2802
|
+
writeMessageIfOpen(held.socket, {
|
|
2803
|
+
type: "delivery_failed",
|
|
2804
|
+
messageId: held.messageId,
|
|
2805
|
+
...(held.attemptId === undefined ? {} : { attemptId: held.attemptId }),
|
|
2806
|
+
reason: error.message,
|
|
2807
|
+
recipientError: serializeIntercomRecipientGoneError(error),
|
|
2808
|
+
});
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2705
2811
|
/** #4326: the child is released; its owner rehydrates it, and it takes the held sends in order when it registers. */
|
|
2706
2812
|
private wakeRestoringRecipientOwner(wake: RestoringRecipientWake): void {
|
|
2707
2813
|
const owner = this.sessions.get(wake.ownerSessionId);
|
|
@@ -2815,13 +2921,25 @@ class IntercomBroker {
|
|
|
2815
2921
|
}
|
|
2816
2922
|
}
|
|
2817
2923
|
|
|
2924
|
+
/** #4639: a session back after its connection closed takes over what its host session kept: released children and answers. */
|
|
2925
|
+
private adoptOrphans(ownerSessionId: string, owner: ConnectedSession): void {
|
|
2926
|
+
this.restoringRecipients.adoptOrphans(ownerSessionId, owner.registrationReturnAddress);
|
|
2927
|
+
this.dispatchHeldSends(this.departedChildren.adoptOrphans(ownerSessionId, owner.registrationReturnAddress));
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2818
2930
|
private disconnectSession(sessionId: string): void {
|
|
2819
2931
|
const departed = this.sessions.get(sessionId);
|
|
2820
2932
|
if (!departed) return;
|
|
2821
2933
|
|
|
2822
2934
|
this.restoringRecipients.dropSender(sessionId);
|
|
2935
|
+
this.departedChildren.dropSender(sessionId);
|
|
2823
2936
|
// #3760: a departed owner restores nothing more; what it held goes through ordinary routing once it is gone.
|
|
2824
|
-
|
|
2937
|
+
// #4639: a session whose connection closes while it keeps released children, as a suspended stage's does, keeps
|
|
2938
|
+
// them: sends to them are held until its host session connects again and reserves them.
|
|
2939
|
+
const unreserved = [
|
|
2940
|
+
...this.restoringRecipients.dropOwner(sessionId, departed.registrationReturnAddress),
|
|
2941
|
+
...this.departedChildren.dropOwner(sessionId, departed.registrationReturnAddress),
|
|
2942
|
+
];
|
|
2825
2943
|
this.failParkedQuestions(this.pendingQuestions.takeParkedForOwner(sessionId));
|
|
2826
2944
|
|
|
2827
2945
|
const unanswered = this.pendingQuestions.takeForSender(sessionId);
|
|
@@ -2846,11 +2964,40 @@ class IntercomBroker {
|
|
|
2846
2964
|
} else {
|
|
2847
2965
|
this.failParkedQuestions(this.pendingQuestions.takeForTarget(sessionId), departed.info.name);
|
|
2848
2966
|
}
|
|
2967
|
+
// #4639: a subagent that left without being released: hold sends to it until it is back or its owner says why. An
|
|
2968
|
+
// owner already away, as a suspended workflow stage's session is, says so through its host session when it is back.
|
|
2969
|
+
const ownerAway = departed.supervisorId !== undefined && !this.sessions.has(departed.supervisorId);
|
|
2970
|
+
if (
|
|
2971
|
+
!parked &&
|
|
2972
|
+
childName !== undefined &&
|
|
2973
|
+
departed.supervisorId !== undefined &&
|
|
2974
|
+
(!ownerAway || departed.supervisorReturnAddress !== undefined)
|
|
2975
|
+
) {
|
|
2976
|
+
const aliases = [sessionId, departed.registrationReturnAddress].filter((alias): alias is string => alias !== undefined);
|
|
2977
|
+
unreserved.push(...this.departedChildren.depart({
|
|
2978
|
+
ownerSessionId: departed.supervisorId,
|
|
2979
|
+
childName,
|
|
2980
|
+
group: normalizeGroup(departed.registrationGroup),
|
|
2981
|
+
aliases,
|
|
2982
|
+
...(ownerAway && departed.supervisorReturnAddress !== undefined
|
|
2983
|
+
? { ownerHostSession: departed.supervisorReturnAddress }
|
|
2984
|
+
: {}),
|
|
2985
|
+
}));
|
|
2986
|
+
}
|
|
2849
2987
|
|
|
2988
|
+
const endedInvocations = new Set<string>();
|
|
2850
2989
|
for (const [runId, owner] of this.pendingStageRoutes) {
|
|
2851
2990
|
if (owner.sessionId !== sessionId) continue;
|
|
2852
2991
|
this.pendingStageRoutes.delete(runId);
|
|
2853
2992
|
this.workflowRosters.delete(runId);
|
|
2993
|
+
this.workflowStageAliases.forgetRun(runId);
|
|
2994
|
+
endedInvocations.add(normalizeGroup(owner.group));
|
|
2995
|
+
}
|
|
2996
|
+
// #4639: once no route of a run is left, the released children its stages kept while away go with it.
|
|
2997
|
+
for (const invocation of endedInvocations) {
|
|
2998
|
+
if ([...this.pendingStageRoutes.values()].some((route) => normalizeGroup(route.group) === invocation)) continue;
|
|
2999
|
+
unreserved.push(...this.restoringRecipients.dropOrphans((group) => invocationOwnsGroup(invocation, group)));
|
|
3000
|
+
unreserved.push(...this.departedChildren.dropOrphans((group) => invocationOwnsGroup(invocation, group)));
|
|
2854
3001
|
}
|
|
2855
3002
|
for (const [requestId, pending] of this.pendingStageAcknowledgments) {
|
|
2856
3003
|
if (pending.ownerSessionId !== sessionId) continue;
|
|
@@ -35,6 +35,12 @@ import {
|
|
|
35
35
|
rehydrateIntercomReleasedReplyError,
|
|
36
36
|
} from "./released-reply-errors.js";
|
|
37
37
|
import { RELEASED_CHILD_FRAME_MAX, validateReleasedChildFrame } from "./released-children.js";
|
|
38
|
+
import {
|
|
39
|
+
type IntercomRecipientGoneError,
|
|
40
|
+
readSerializedIntercomRecipientGoneError,
|
|
41
|
+
rehydrateIntercomRecipientGoneError,
|
|
42
|
+
type SubagentEndedOutcome,
|
|
43
|
+
} from "./recipient-gone-errors.js";
|
|
38
44
|
import { normalizeGroups } from "../group.js";
|
|
39
45
|
import {
|
|
40
46
|
BROKER_RETIRING_CODE,
|
|
@@ -188,6 +194,17 @@ export interface ReleasedChildReply {
|
|
|
188
194
|
readonly message: Message;
|
|
189
195
|
}
|
|
190
196
|
|
|
197
|
+
/** A subagent this session launched whose last run ended, and how (#4639). */
|
|
198
|
+
export interface EndedChildReport {
|
|
199
|
+
readonly childName: string;
|
|
200
|
+
readonly group?: string;
|
|
201
|
+
/** Its Atomic session id and last Intercom id, when known. */
|
|
202
|
+
readonly aliases?: readonly string[];
|
|
203
|
+
readonly outcome: SubagentEndedOutcome;
|
|
204
|
+
/** The `<runId>:<index>` id `subagent({ action: "resume" })` takes. */
|
|
205
|
+
readonly childId?: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
191
208
|
/** A released subagent to keep addressable through its owner, by name (#4326). */
|
|
192
209
|
export interface ReleasedChildReservation {
|
|
193
210
|
readonly childName: string;
|
|
@@ -208,6 +225,32 @@ export {
|
|
|
208
225
|
UnknownReleasedChildError,
|
|
209
226
|
} from "./released-child-errors.js";
|
|
210
227
|
export type { IntercomReleasedChildErrorCode, SerializedIntercomReleasedChildError } from "./released-child-errors.js";
|
|
228
|
+
export {
|
|
229
|
+
INTERCOM_RECIPIENT_GONE_ERROR_CODES,
|
|
230
|
+
IntercomRecipientGoneError,
|
|
231
|
+
isIntercomRecipientGoneError,
|
|
232
|
+
isIntercomRecipientGoneErrorCode,
|
|
233
|
+
isRetryableIntercomRecipientGoneError,
|
|
234
|
+
isSubagentRecipientDisconnectedError,
|
|
235
|
+
isSubagentRecipientEndedError,
|
|
236
|
+
isSubagentRecipientOwnerSuspendedError,
|
|
237
|
+
readSerializedIntercomRecipientGoneError,
|
|
238
|
+
rehydrateIntercomRecipientGoneError,
|
|
239
|
+
SUBAGENT_ENDED_OUTCOMES,
|
|
240
|
+
SubagentRecipientDisconnectedError,
|
|
241
|
+
SubagentRecipientEndedError,
|
|
242
|
+
SubagentRecipientOwnerSuspendedError,
|
|
243
|
+
serializeIntercomRecipientGoneError,
|
|
244
|
+
} from "./recipient-gone-errors.js";
|
|
245
|
+
export type {
|
|
246
|
+
IntercomRecipientGoneErrorCode,
|
|
247
|
+
IntercomRecipientGoneErrorFields,
|
|
248
|
+
SerializedIntercomRecipientGoneError,
|
|
249
|
+
SubagentEndedOutcome,
|
|
250
|
+
SubagentRecipientDisconnectedCode,
|
|
251
|
+
SubagentRecipientEndedCode,
|
|
252
|
+
SubagentRecipientOwnerSuspendedCode,
|
|
253
|
+
} from "./recipient-gone-errors.js";
|
|
211
254
|
export {
|
|
212
255
|
IntercomReleasedReplyError,
|
|
213
256
|
isIntercomReleasedReplyError,
|
|
@@ -239,8 +282,11 @@ export interface SendResult {
|
|
|
239
282
|
queued?: boolean;
|
|
240
283
|
reason?: string;
|
|
241
284
|
reasonCode?: DeliveryFailureReasonCode;
|
|
242
|
-
/**
|
|
243
|
-
|
|
285
|
+
/**
|
|
286
|
+
* #4386: the typed refusal of a reply to a released subagent. #4639: why a subagent with no live session is gone.
|
|
287
|
+
* Its `code` is `reasonCode`.
|
|
288
|
+
*/
|
|
289
|
+
error?: IntercomReleasedReplyError | IntercomRecipientGoneError;
|
|
244
290
|
target?: string;
|
|
245
291
|
position?: number;
|
|
246
292
|
/** How a queued workflow target relates to the run's stages (#4359). */
|
|
@@ -391,6 +437,7 @@ export class IntercomClient extends EventEmitter {
|
|
|
391
437
|
private connectAttempt: AbortController | undefined;
|
|
392
438
|
/** #3983: the broker of the current registration accepts `saving`. */
|
|
393
439
|
private brokerExtendsSaves = false;
|
|
440
|
+
private brokerMarksEndedChildren = false;
|
|
394
441
|
private socket: net.Socket | null = null;
|
|
395
442
|
private _sessionId: string | null = null;
|
|
396
443
|
private _supervisorSessionId: string | null = null;
|
|
@@ -657,6 +704,7 @@ export class IntercomClient extends EventEmitter {
|
|
|
657
704
|
this._brokerProtocol = LEGACY_BROKER_PROTOCOL;
|
|
658
705
|
this.brokerClaimsWorkflowInvocations = false;
|
|
659
706
|
this.brokerExtendsSaves = false;
|
|
707
|
+
this.brokerMarksEndedChildren = false;
|
|
660
708
|
this._messageSource = undefined;
|
|
661
709
|
this.disconnectError = null;
|
|
662
710
|
if (connectionEstablished && !wasDisconnecting) {
|
|
@@ -790,6 +838,7 @@ export class IntercomClient extends EventEmitter {
|
|
|
790
838
|
&& brokerMessage.multiNodeRouting !== "starting" && brokerMessage.multiNodeRouting !== "on"
|
|
791
839
|
&& brokerMessage.multiNodeRouting !== "unavailable")
|
|
792
840
|
|| (brokerMessage.extendsSaves !== undefined && brokerMessage.extendsSaves !== true)
|
|
841
|
+
|| (brokerMessage.marksEndedChildren !== undefined && brokerMessage.marksEndedChildren !== true)
|
|
793
842
|
|| (brokerMessage.protocol !== undefined && !isBrokerProtocolRange(brokerMessage.protocol as JsonWireValue))) {
|
|
794
843
|
throw new Error("Invalid registered message");
|
|
795
844
|
}
|
|
@@ -819,6 +868,7 @@ export class IntercomClient extends EventEmitter {
|
|
|
819
868
|
this._multiNodeRouting = brokerMessage.multiNodeRouting as BrokerMultiNodeStatus["status"] | undefined;
|
|
820
869
|
this.brokerClaimsWorkflowInvocations = brokerMessage.claimsWorkflowInvocations === true;
|
|
821
870
|
this.brokerExtendsSaves = this.brokerAcknowledgesReceipt && brokerMessage.extendsSaves === true;
|
|
871
|
+
this.brokerMarksEndedChildren = brokerMessage.marksEndedChildren === true;
|
|
822
872
|
this._brokerProtocol = protocolRangeOf(brokerMessage.protocol as BrokerProtocolRange | undefined);
|
|
823
873
|
this.emit("_registered", { type: "registered", sessionId: brokerMessage.sessionId });
|
|
824
874
|
break;
|
|
@@ -1162,12 +1212,16 @@ export class IntercomClient extends EventEmitter {
|
|
|
1162
1212
|
const { messageId, attemptId, reason, reasonCode } = brokerMessage;
|
|
1163
1213
|
const wireError = brokerMessage.error as JsonWireValue | undefined;
|
|
1164
1214
|
const error = readSerializedIntercomReleasedReplyError(wireError);
|
|
1215
|
+
const wireRecipientError = brokerMessage.recipientError as JsonWireValue | undefined;
|
|
1216
|
+
const recipientError = readSerializedIntercomRecipientGoneError(wireRecipientError);
|
|
1165
1217
|
if (
|
|
1166
1218
|
typeof messageId !== "string" ||
|
|
1167
1219
|
(attemptId !== undefined && typeof attemptId !== "string") ||
|
|
1168
1220
|
typeof reason !== "string" ||
|
|
1169
1221
|
(reasonCode !== undefined && (typeof reasonCode !== "string" || !isDeliveryFailureReasonCode(reasonCode))) ||
|
|
1170
|
-
(wireError !== undefined && (error === undefined || error.code !== reasonCode))
|
|
1222
|
+
(wireError !== undefined && (error === undefined || error.code !== reasonCode)) ||
|
|
1223
|
+
// A valid released-reply `error` always comes with its `reasonCode`, so this also refuses carrying both errors.
|
|
1224
|
+
(wireRecipientError !== undefined && (recipientError === undefined || reasonCode !== undefined))
|
|
1171
1225
|
) {
|
|
1172
1226
|
throw new Error("Invalid delivery_failed message");
|
|
1173
1227
|
}
|
|
@@ -1177,6 +1231,9 @@ export class IntercomClient extends EventEmitter {
|
|
|
1177
1231
|
reason,
|
|
1178
1232
|
...(reasonCode === undefined ? {} : { reasonCode }),
|
|
1179
1233
|
...(error === undefined ? {} : { error: rehydrateIntercomReleasedReplyError(error) }),
|
|
1234
|
+
...(recipientError === undefined
|
|
1235
|
+
? {}
|
|
1236
|
+
: { reasonCode: recipientError.code, error: rehydrateIntercomRecipientGoneError(recipientError) }),
|
|
1180
1237
|
};
|
|
1181
1238
|
if (attemptId === undefined) this.pendingSends.resolveLegacy(messageId, result);
|
|
1182
1239
|
else this.pendingSends.resolve(messageId, attemptId, result);
|
|
@@ -1559,6 +1616,31 @@ export class IntercomClient extends EventEmitter {
|
|
|
1559
1616
|
}
|
|
1560
1617
|
}
|
|
1561
1618
|
|
|
1619
|
+
/**
|
|
1620
|
+
* #4639: report how subagents this session launched ended, in frames of at most 500, so a send to one that has no
|
|
1621
|
+
* live session is refused with why and the next step instead of `Session not found`. The broker keeps each report on
|
|
1622
|
+
* this connection until the subagent registers again or this session disconnects; report again after a reconnect.
|
|
1623
|
+
* Resolves without sending anything to a broker that does not advertise `marksEndedChildren`. Fails with a
|
|
1624
|
+
* `ReleasedChildReservationError` naming the first invalid child, or `not_owner` when another session owns one.
|
|
1625
|
+
*/
|
|
1626
|
+
async markEndedChildren(children: readonly EndedChildReport[]): Promise<void> {
|
|
1627
|
+
if (!this.brokerMarksEndedChildren) return;
|
|
1628
|
+
// Fields left undefined are not written: the frame carries what each report names, nothing else.
|
|
1629
|
+
const wireChildren = children.map((child) => ({
|
|
1630
|
+
childName: child.childName,
|
|
1631
|
+
group: child.group,
|
|
1632
|
+
aliases: child.aliases,
|
|
1633
|
+
outcome: child.outcome,
|
|
1634
|
+
childId: child.childId,
|
|
1635
|
+
}));
|
|
1636
|
+
for (let start = 0; start < wireChildren.length; start += RELEASED_CHILD_FRAME_MAX) {
|
|
1637
|
+
await this.restoringRecipientRequest({
|
|
1638
|
+
type: "mark_ended_children",
|
|
1639
|
+
children: wireChildren.slice(start, start + RELEASED_CHILD_FRAME_MAX),
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1562
1644
|
/**
|
|
1563
1645
|
* #4326: confirm this session is waking `childName`: the broker lengthens the hold of every send waiting for it,
|
|
1564
1646
|
* once per wake, up to 120 seconds from each send's admission. Fails with `UnknownReleasedChildError` when no
|