@vellumai/assistant 0.12.4 → 0.12.5-dev.202609251017.e467a6c
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/docs/architecture/memory.md +9 -1
- package/docs/architecture/scheduling.md +13 -5
- package/docs/desktop-browser-cli.md +3 -2
- package/docs/guardian-request-flow.md +1 -1
- package/node_modules/@vellumai/avatar-manifest/src/__tests__/notification-avatar.test.ts +48 -4
- package/node_modules/@vellumai/avatar-manifest/src/notification-avatar.ts +12 -8
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
- package/node_modules/@vellumai/gateway-client/src/outbound-contract.ts +2 -4
- package/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
- package/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
- package/openapi.yaml +152 -3
- package/package.json +1 -1
- package/src/__tests__/agent-loop.test.ts +76 -0
- package/src/__tests__/anthropic-error-formatting.test.ts +9 -0
- package/src/__tests__/background-shell-bash.test.ts +34 -0
- package/src/__tests__/background-shell-host-bash.test.ts +98 -1
- package/src/__tests__/background-tool-registry.test.ts +39 -0
- package/src/__tests__/channel-readiness-discord.test.ts +8 -0
- package/src/__tests__/channel-readiness-slack-remote.test.ts +8 -0
- package/src/__tests__/client-os-metadata-persistence.test.ts +4 -20
- package/src/__tests__/conversation-agent-loop.test.ts +529 -1
- package/src/__tests__/conversation-error.test.ts +18 -0
- package/src/__tests__/conversation-pairing.test.ts +69 -0
- package/src/__tests__/conversation-queue.test.ts +257 -4
- package/src/__tests__/conversation-runtime-assembly.test.ts +27 -0
- package/src/__tests__/emit-signal-routing-intent.test.ts +62 -0
- package/src/__tests__/evict-conversations-for-reload.test.ts +21 -0
- package/src/__tests__/gemini-provider.test.ts +9 -0
- package/src/__tests__/host-cu-proxy.test.ts +79 -0
- package/src/__tests__/host-cu-routes-targeted.test.ts +14 -5
- package/src/__tests__/introduction-card-resolver.test.ts +53 -8
- package/src/__tests__/job-handler-registration-guard.test.ts +1 -0
- package/src/__tests__/non-member-access-request.test.ts +48 -0
- package/src/__tests__/notification-events-source-context-probe.test.ts +48 -1
- package/src/__tests__/notification-platform-adapter.test.ts +97 -0
- package/src/__tests__/notification-vellum-adapter.test.ts +103 -3
- package/src/__tests__/platform-callback-registration.test.ts +46 -1
- package/src/__tests__/plugin-import-boundary-guard.test.ts +3 -0
- package/src/__tests__/scaffold-managed-skill-tool.test.ts +116 -66
- package/src/__tests__/scheduler-disk-pressure.test.ts +1 -0
- package/src/__tests__/scheduler-result-notification.test.ts +521 -7
- package/src/__tests__/scheduler-wake.test.ts +1 -0
- package/src/__tests__/skill-load-inline-command.test.ts +35 -0
- package/src/__tests__/subagent-cron-run-attribution.test.ts +41 -2
- package/src/__tests__/subagent-manager-notify.test.ts +48 -0
- package/src/__tests__/trusted-contact-inline-approval-integration.test.ts +6 -6
- package/src/__tests__/usage-attribution.test.ts +31 -0
- package/src/__tests__/wake-schedule-escalation.test.ts +1 -0
- package/src/agent/loop.ts +23 -0
- package/src/api/ask-question-tool.ts +50 -0
- package/src/api/events/generation-handoff.ts +4 -0
- package/src/api/events/message-complete.ts +4 -0
- package/src/api/events/tool-result.ts +11 -0
- package/src/api/index.ts +11 -0
- package/src/api/requests/guardian-actions.test.ts +45 -0
- package/src/api/requests/guardian-actions.ts +20 -0
- package/src/api/responses/conversation-message.ts +4 -0
- package/src/api/responses/home.ts +27 -0
- package/src/approvals/guardian-decision-primitive.ts +6 -4
- package/src/approvals/guardian-request-resolvers.ts +35 -30
- package/src/avatar/notification-avatar.test.ts +42 -34
- package/src/avatar/notification-avatar.ts +1 -0
- package/src/calls/__tests__/call-controller.test.ts +18 -0
- package/src/calls/__tests__/voice-control-protocol.test.ts +6 -1
- package/src/calls/__tests__/voice-leg-coordinator.test.ts +70 -0
- package/src/calls/__tests__/voice-session-bridge.test.ts +116 -4
- package/src/calls/__tests__/voice-triage-escalate.test.ts +77 -11
- package/src/calls/call-controller.ts +3 -1
- package/src/calls/voice-control-protocol.ts +12 -4
- package/src/calls/voice-escalation-judge.ts +2 -2
- package/src/calls/voice-leg-coordinator.ts +23 -5
- package/src/calls/voice-screen-annotation.ts +44 -0
- package/src/calls/voice-session-bridge.ts +63 -20
- package/src/calls/voice-triage-escalate.ts +82 -27
- package/src/cli/commands/__tests__/conversations-clear.test.ts +156 -0
- package/src/cli/commands/conversations.help.ts +7 -2
- package/src/cli/commands/conversations.ts +36 -30
- package/src/cli/commands/oauth/index.help.ts +8 -2
- package/src/cli/commands/oauth/request.test.ts +32 -0
- package/src/cli/commands/platform/index.help.ts +2 -1
- package/src/cli/commands/platform/index.ts +8 -2
- package/src/cli/lib/__tests__/plugin-catalog-cache.test.ts +60 -0
- package/src/cli/lib/__tests__/plugin-catalog-platform.test.ts +66 -2
- package/src/cli/lib/bundled-marketplace.json +35 -0
- package/src/cli/lib/bundled-plugin-packages.json +21 -0
- package/src/cli/lib/plugin-catalog-cache.ts +17 -2
- package/src/cli/lib/plugin-catalog-platform.ts +48 -9
- package/src/config/__tests__/default-profile-catalog.test.ts +28 -0
- package/src/config/__tests__/platform-identity.test.ts +59 -0
- package/src/config/__tests__/profile-order.test.ts +19 -0
- package/src/config/__tests__/sync-gated-profiles.test.ts +71 -0
- package/src/config/bundled-skills/computer-use/SKILL.md +20 -0
- package/src/config/bundled-skills/computer-use/TOOLS.json +11 -11
- package/src/config/bundled-skills/screen-annotation/SKILL.md +41 -29
- package/src/config/bundled-skills/screen-annotation/TOOLS.json +5 -5
- package/src/config/call-site-defaults.ts +6 -0
- package/src/config/default-profile-catalog.ts +30 -1
- package/src/config/default-profile-names.ts +36 -2
- package/src/config/feature-flag-registry.json +9 -1
- package/src/config/platform-identity.ts +22 -5
- package/src/config/profile-order.ts +7 -1
- package/src/config/schemas/call-site-catalog.ts +7 -0
- package/src/config/schemas/llm.ts +21 -5
- package/src/config/sync-gated-profiles.ts +96 -44
- package/src/daemon/__tests__/abort-null-controller.test.ts +135 -1
- package/src/daemon/__tests__/auto-profile-router.test.ts +380 -0
- package/src/daemon/__tests__/turn-tail-assistant-reply-notify.test.ts +16 -0
- package/src/daemon/activity-trail.test.ts +206 -0
- package/src/daemon/activity-trail.ts +190 -0
- package/src/daemon/auto-profile-router.ts +431 -0
- package/src/daemon/computer-use-observation.test.ts +81 -0
- package/src/daemon/computer-use-observation.ts +23 -0
- package/src/daemon/conversation-agent-loop-handlers.ts +11 -0
- package/src/daemon/conversation-agent-loop.ts +157 -32
- package/src/daemon/conversation-error.ts +19 -0
- package/src/daemon/conversation-lifecycle.ts +70 -7
- package/src/daemon/conversation-media-retry.ts +1 -2
- package/src/daemon/conversation-messaging.ts +31 -2
- package/src/daemon/conversation-process.ts +107 -16
- package/src/daemon/conversation-queue-manager.ts +7 -0
- package/src/daemon/conversation-runtime-assembly.ts +1 -0
- package/src/daemon/conversation-turn-finalize.ts +14 -0
- package/src/daemon/conversation.ts +25 -6
- package/src/daemon/event-loop-watchdog.test.ts +201 -2
- package/src/daemon/event-loop-watchdog.ts +182 -6
- package/src/daemon/host-cu-proxy.ts +34 -3
- package/src/daemon/pkb-reminder-builder.test.ts +10 -3
- package/src/daemon/pkb-reminder-builder.ts +1 -1
- package/src/daemon/wake-conversation-ops.ts +4 -2
- package/src/desktop/desktop-computer-use.test.ts +14 -4
- package/src/home/feed-types.ts +2 -0
- package/src/inbound/platform-callback-registration.ts +19 -6
- package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +27 -0
- package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +83 -0
- package/src/live-voice/__tests__/live-voice-triage-escalate.test.ts +48 -1
- package/src/live-voice/__tests__/live-voice-vad.test.ts +34 -2
- package/src/live-voice/__tests__/protocol.test.ts +22 -0
- package/src/live-voice/continuation-judge.ts +1 -1
- package/src/live-voice/live-voice-session.ts +25 -19
- package/src/live-voice/protocol.ts +16 -5
- package/src/messaging/providers/discord/withdraw.ts +4 -5
- package/src/messaging/providers/gmail/client.ts +4 -0
- package/src/messaging/providers/slack/withdraw.ts +5 -5
- package/src/messaging/providers/telegram-bot/withdraw.ts +4 -5
- package/src/monitoring/__tests__/proc-fixtures.ts +28 -0
- package/src/monitoring/__tests__/proc-wait-state.test.ts +232 -0
- package/src/monitoring/__tests__/process-usage.test.ts +243 -0
- package/src/monitoring/proc-wait-state.ts +366 -0
- package/src/monitoring/process-memory.ts +4 -3
- package/src/monitoring/process-usage.ts +215 -0
- package/src/monitoring/resource-sample-types.ts +8 -0
- package/src/monitoring/resource-sampler.ts +17 -2
- package/src/monitoring/stall-capture.ts +12 -0
- package/src/notifications/README.md +88 -9
- package/src/notifications/__tests__/assistant-reply-producer.test.ts +390 -119
- package/src/notifications/__tests__/background-result-producer.test.ts +1272 -0
- package/src/notifications/__tests__/broadcaster.test.ts +292 -1
- package/src/notifications/__tests__/completion-policy.test.ts +243 -0
- package/src/notifications/__tests__/decision-engine.test.ts +51 -4
- package/src/notifications/__tests__/has-pending-background-work.test.ts +281 -0
- package/src/notifications/__tests__/home-feed-side-effect.test.ts +161 -3
- package/src/notifications/__tests__/resolve-visible-in-source.test.ts +110 -1
- package/src/notifications/__tests__/schedule-result-producer.test.ts +11 -4
- package/src/notifications/adapters/macos.ts +24 -12
- package/src/notifications/adapters/platform.ts +16 -5
- package/src/notifications/assistant-reply-producer.ts +96 -71
- package/src/notifications/background-result-producer.ts +369 -0
- package/src/notifications/broadcaster.ts +28 -8
- package/src/notifications/completion-policy.ts +115 -0
- package/src/notifications/completion-work.ts +46 -0
- package/src/notifications/conversation-pairing.ts +32 -13
- package/src/notifications/decision-engine.ts +18 -24
- package/src/notifications/emit-signal.ts +16 -1
- package/src/notifications/events-store.ts +4 -0
- package/src/notifications/has-pending-background-work.ts +91 -0
- package/src/notifications/home-feed-mirror.ts +44 -0
- package/src/notifications/home-feed-side-effect.ts +54 -28
- package/src/notifications/resolve-visible-in-source.ts +56 -2
- package/src/notifications/result-output.ts +154 -0
- package/src/notifications/schedule-result-producer.ts +6 -187
- package/src/notifications/types.ts +2 -0
- package/src/oauth/AGENTS.md +9 -1
- package/src/oauth/byo-connection.test.ts +28 -0
- package/src/persistence/__tests__/recent-conversation-messages.test.ts +41 -0
- package/src/persistence/conversation-crud.ts +26 -0
- package/src/persistence/conversation-types.ts +15 -37
- package/src/persistence/embeddings/__tests__/embedding-local-lifecycle.test.ts +85 -14
- package/src/persistence/jobs-store.ts +229 -0
- package/src/persistence/migrations/383-normalize-opencode-host-connections.ts +44 -0
- package/src/persistence/migrations/__tests__/383-normalize-opencode-host-connections.test.ts +102 -0
- package/src/persistence/steps.ts +12 -0
- package/src/platform/sync-avatar.test.ts +29 -0
- package/src/plugins/defaults/memory/AGENTS.md +5 -3
- package/src/plugins/defaults/memory/__tests__/skill-update-receipt-boundary-guard.test.ts +45 -0
- package/src/plugins/defaults/memory/__tests__/skill-update-receipt-job.test.ts +580 -0
- package/src/plugins/defaults/memory/__tests__/turn-retrieval.test.ts +21 -0
- package/src/plugins/defaults/memory/graph/tools.ts +9 -5
- package/src/plugins/defaults/memory/hooks/conversation-deleted.ts +4 -0
- package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +7 -3
- package/src/plugins/defaults/memory/job-handlers.ts +8 -2
- package/src/plugins/defaults/memory/skill-update-receipt-job.ts +334 -0
- package/src/plugins/defaults/memory/tools.test.ts +17 -0
- package/src/plugins/defaults/memory/turn-retrieval.ts +8 -0
- package/src/plugins/defaults/memory/v3/__tests__/injection.test.ts +24 -0
- package/src/plugins/defaults/memory/v3/injector.ts +4 -4
- package/src/plugins/types.ts +2 -0
- package/src/providers/__tests__/search-provider-catalog.test.ts +8 -0
- package/src/providers/anthropic/client.ts +4 -0
- package/src/providers/gemini/client.ts +7 -1
- package/src/providers/inference/auth.ts +25 -0
- package/src/providers/inference/profile-probe.ts +1 -0
- package/src/{calls/__tests__/typesafe-noul.test.ts → providers/jev/ask.test.ts} +4 -4
- package/src/{calls/typesafe-noul.ts → providers/jev/ask.ts} +67 -34
- package/src/providers/openai/__tests__/api-error-normalization.test.ts +12 -0
- package/src/providers/openai/api-error-normalization.ts +4 -0
- package/src/providers/retry.ts +2 -0
- package/src/providers/search-provider-catalog.ts +10 -0
- package/src/providers/types.ts +7 -0
- package/src/providers/usage-tracking.ts +5 -3
- package/src/runtime/__tests__/agent-wake.test.ts +308 -0
- package/src/runtime/access-request-helper.ts +16 -9
- package/src/runtime/agent-wake-queue.ts +52 -0
- package/src/runtime/agent-wake.ts +111 -18
- package/src/runtime/channel-approval-types.ts +6 -38
- package/src/runtime/channel-approvals.ts +4 -5
- package/src/runtime/http-server.ts +4 -1
- package/src/runtime/introduction-policy.test.ts +17 -1
- package/src/runtime/introduction-policy.ts +25 -7
- package/src/runtime/migrations/vbundle-builder.ts +9 -0
- package/src/runtime/routes/__tests__/inference-profiles-routes.test.ts +21 -1
- package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +60 -0
- package/src/runtime/routes/__tests__/oauth-proxy-routes.test.ts +61 -3
- package/src/runtime/routes/auto-profile-routes.ts +83 -0
- package/src/runtime/routes/conversation-management-routes.ts +1 -3
- package/src/runtime/routes/conversation-routes.ts +9 -0
- package/src/runtime/routes/guardian-action-routes.ts +8 -23
- package/src/runtime/routes/host-cu-routes.ts +3 -1
- package/src/runtime/routes/index.ts +2 -0
- package/src/runtime/routes/inference-profiles-routes.ts +5 -2
- package/src/runtime/routes/inference-provider-connection-routes.ts +25 -8
- package/src/runtime/routes/migration-routes.ts +8 -2
- package/src/runtime/routes/oauth-proxy-passthrough.test.ts +32 -0
- package/src/runtime/routes/platform-routes.ts +6 -1
- package/src/runtime/routes/user-route-dispatcher.ts +1 -2
- package/src/runtime/web-presence.ts +3 -4
- package/src/schedule/schedule-store.ts +10 -0
- package/src/schedule/scheduler.ts +92 -24
- package/src/subagent/manager.ts +32 -12
- package/src/telegram/__tests__/webhook-health.test.ts +8 -0
- package/src/telemetry/telemetry-wire-source.json +1 -1
- package/src/telemetry/telemetry-wire.generated.ts +1 -0
- package/src/tools/background-tool-registry.ts +30 -3
- package/src/tools/browser/cdp-client/local-cdp-client.ts +1 -2
- package/src/tools/host-terminal/host-shell.ts +7 -0
- package/src/tools/network/__tests__/web-fetch-firecrawl.test.ts +28 -1
- package/src/tools/network/__tests__/web-fetch-metadata.test.ts +34 -0
- package/src/tools/network/__tests__/web-fetch-tinyfish.test.ts +35 -1
- package/src/tools/network/__tests__/web-search.test.ts +96 -0
- package/src/tools/network/web-fetch.ts +30 -9
- package/src/tools/network/web-search.ts +235 -4
- package/src/tools/skills/load.ts +13 -17
- package/src/tools/skills/scaffold-managed.ts +86 -71
- package/src/tools/terminal/shell-launch.test.ts +27 -1
- package/src/tools/terminal/shell.ts +4 -0
- package/src/tools/workspace-tools/loader.ts +1 -2
- package/src/usage/attribution.ts +18 -1
- package/src/util/abort-reasons.ts +2 -0
- package/src/util/errors.ts +1 -0
- package/src/util/oauth-request-body.test.ts +5 -1
- package/src/util/provider-error-patterns.ts +11 -0
- package/src/util/single-flight.test.ts +6 -0
- package/src/util/single-flight.ts +2 -0
- package/src/util/worker-pipe.test.ts +56 -10
- package/src/util/worker-pipe.ts +9 -4
- package/src/workspace/git-service.ts +6 -1
- package/src/workspace/migrations/158-repoint-opencode-host-provider-fragments.ts +163 -0
- package/src/workspace/migrations/__tests__/158-repoint-opencode-host-provider-fragments.test.ts +188 -0
- package/src/workspace/migrations/registry.ts +2 -0
|
@@ -0,0 +1,1272 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import type { AttentionState } from "../../persistence/conversation-attention-store.js";
|
|
4
|
+
import type {
|
|
5
|
+
ConversationRow,
|
|
6
|
+
MessageRow,
|
|
7
|
+
} from "../../persistence/conversation-crud.js";
|
|
8
|
+
import type { SubagentRecord } from "../../persistence/subagent-store.js";
|
|
9
|
+
import type { ContentBlock } from "../../providers/types.js";
|
|
10
|
+
import { getLogger } from "../../util/logger.js";
|
|
11
|
+
import type { EmitSignalParams } from "../emit-signal.js";
|
|
12
|
+
|
|
13
|
+
const conversationId = "conv-parent";
|
|
14
|
+
const startedAt = 1_700_000_000_000;
|
|
15
|
+
const externalChannels = ["slack", "telegram", "discord"] as const;
|
|
16
|
+
const rows = new Map<string, MessageRow>();
|
|
17
|
+
let conversation: ConversationRow;
|
|
18
|
+
let task: SubagentRecord;
|
|
19
|
+
const siblingTasks = new Map<string, SubagentRecord>();
|
|
20
|
+
let attention: AttentionState;
|
|
21
|
+
let pending = false;
|
|
22
|
+
let toolsPending = false;
|
|
23
|
+
let queued = false;
|
|
24
|
+
let notifiedContexts = new Set<string>();
|
|
25
|
+
let recipient: string | undefined = "principal-owner";
|
|
26
|
+
let visible = false;
|
|
27
|
+
let lookupBarrier: (() => Promise<void>) | undefined;
|
|
28
|
+
let deferredLookup: "recipient" | "presence" = "recipient";
|
|
29
|
+
const signals: EmitSignalParams[] = [];
|
|
30
|
+
let resultRows: MessageRow[] = [];
|
|
31
|
+
|
|
32
|
+
mock.module("../../daemon/conversation-registry.js", () => ({
|
|
33
|
+
allSubagentConversations: () => [],
|
|
34
|
+
findConversation: () => ({
|
|
35
|
+
isProcessing: () => false,
|
|
36
|
+
hasQueuedMessages: () => queued,
|
|
37
|
+
}),
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
const crud = await import("../../persistence/conversation-crud.js");
|
|
41
|
+
mock.module("../../persistence/conversation-crud.js", () => ({
|
|
42
|
+
...crud,
|
|
43
|
+
getConversation: () => conversation,
|
|
44
|
+
getMessageById: (id: string) => rows.get(id) ?? null,
|
|
45
|
+
getMessagesAfter: () => resultRows,
|
|
46
|
+
getRecentConversationMessages: (
|
|
47
|
+
_conversationId: string,
|
|
48
|
+
limit: number,
|
|
49
|
+
beforeMessageId?: string,
|
|
50
|
+
) => {
|
|
51
|
+
let history = [...rows.values()];
|
|
52
|
+
if (beforeMessageId) {
|
|
53
|
+
history = history.slice(
|
|
54
|
+
0,
|
|
55
|
+
history.findIndex((row) => row.id === beforeMessageId),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return history.slice(-limit);
|
|
59
|
+
},
|
|
60
|
+
}));
|
|
61
|
+
const attentionStore =
|
|
62
|
+
await import("../../persistence/conversation-attention-store.js");
|
|
63
|
+
mock.module("../../persistence/conversation-attention-store.js", () => ({
|
|
64
|
+
...attentionStore,
|
|
65
|
+
getAttentionStateByConversationIds: (ids: string[]) =>
|
|
66
|
+
new Map(ids[0] === conversationId ? [[conversationId, attention]] : []),
|
|
67
|
+
}));
|
|
68
|
+
mock.module("../../persistence/subagent-store.js", () => ({
|
|
69
|
+
getSubagentRecordById: (id: string) => siblingTasks.get(id) ?? task,
|
|
70
|
+
getSubagentRecordByConversationId: () => task,
|
|
71
|
+
getSubagentRecordsByParent: () =>
|
|
72
|
+
pending ? [{ ...task, status: "running" }] : [],
|
|
73
|
+
}));
|
|
74
|
+
mock.module("../../tools/background-tool-registry.js", () => ({
|
|
75
|
+
hasBackgroundToolWork: () => toolsPending,
|
|
76
|
+
}));
|
|
77
|
+
mock.module("../../runtime/agent-wake-queue.js", () => ({
|
|
78
|
+
hasPendingAgentWake: () => false,
|
|
79
|
+
}));
|
|
80
|
+
mock.module("../events-store.js", () => ({
|
|
81
|
+
hasNotifiedSourceContextSince: (id: string) => notifiedContexts.has(id),
|
|
82
|
+
}));
|
|
83
|
+
mock.module("../emit-signal.js", () => ({
|
|
84
|
+
emitNotificationSignal: async (signal: EmitSignalParams) => {
|
|
85
|
+
signals.push(signal);
|
|
86
|
+
},
|
|
87
|
+
}));
|
|
88
|
+
mock.module("../resolve-visible-in-source.js", () => ({
|
|
89
|
+
resolveCompletionRecipientPrincipalId: async () => {
|
|
90
|
+
if (deferredLookup === "recipient") {
|
|
91
|
+
await lookupBarrier?.();
|
|
92
|
+
}
|
|
93
|
+
return recipient;
|
|
94
|
+
},
|
|
95
|
+
resolveCompletionVisibleInSourceNow: async () => {
|
|
96
|
+
if (deferredLookup === "presence") {
|
|
97
|
+
await lookupBarrier?.();
|
|
98
|
+
}
|
|
99
|
+
return visible;
|
|
100
|
+
},
|
|
101
|
+
}));
|
|
102
|
+
const { emitBackgroundResultNotification } =
|
|
103
|
+
await import("../background-result-producer.js");
|
|
104
|
+
|
|
105
|
+
function row(
|
|
106
|
+
id: string,
|
|
107
|
+
role: "user" | "assistant",
|
|
108
|
+
text: string,
|
|
109
|
+
offset: number,
|
|
110
|
+
metadata?: Record<string, unknown>,
|
|
111
|
+
): MessageRow {
|
|
112
|
+
return {
|
|
113
|
+
id,
|
|
114
|
+
conversationId,
|
|
115
|
+
role,
|
|
116
|
+
content: [{ type: "text", text }],
|
|
117
|
+
createdAt: startedAt + offset,
|
|
118
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
119
|
+
clientMessageId: null,
|
|
120
|
+
finalized: 1,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function triggerMetadata(metadata: Record<string, unknown>): void {
|
|
124
|
+
rows.set("trigger", {
|
|
125
|
+
...rows.get("trigger")!,
|
|
126
|
+
metadata: JSON.stringify(metadata),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function setExternalOrigin(channel: (typeof externalChannels)[number]): void {
|
|
130
|
+
conversation.source = channel;
|
|
131
|
+
triggerMetadata({
|
|
132
|
+
...JSON.parse(rows.get("trigger")!.metadata!),
|
|
133
|
+
userMessageChannel: channel,
|
|
134
|
+
assistantMessageChannel: channel,
|
|
135
|
+
});
|
|
136
|
+
rows.get("result")!.metadata = JSON.stringify({
|
|
137
|
+
assistantMessageChannel: channel,
|
|
138
|
+
providerMeta: JSON.stringify({
|
|
139
|
+
source: channel,
|
|
140
|
+
conversationExternalId: "chat-123",
|
|
141
|
+
eventKind: "message",
|
|
142
|
+
}),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const rlog = getLogger("background-result-producer-test");
|
|
146
|
+
function finishSiblingCommand(
|
|
147
|
+
status: "failed" | "cancelled",
|
|
148
|
+
privateResult = false,
|
|
149
|
+
): void {
|
|
150
|
+
rows.set(
|
|
151
|
+
"later-trigger",
|
|
152
|
+
row("later-trigger", "user", "INTERNAL FAILURE", 300, {
|
|
153
|
+
backgroundEventSource: "background-tool",
|
|
154
|
+
backgroundToolCompletion: {
|
|
155
|
+
id: "tool-sibling",
|
|
156
|
+
toolName: "bash",
|
|
157
|
+
conversationId,
|
|
158
|
+
command: "example-command",
|
|
159
|
+
startedAt,
|
|
160
|
+
completedAt: startedAt + 300,
|
|
161
|
+
status,
|
|
162
|
+
exitCode: 1,
|
|
163
|
+
output: "raw failure",
|
|
164
|
+
},
|
|
165
|
+
}),
|
|
166
|
+
);
|
|
167
|
+
rows.set(
|
|
168
|
+
"later-result",
|
|
169
|
+
row(
|
|
170
|
+
"later-result",
|
|
171
|
+
"assistant",
|
|
172
|
+
"The other command failed.",
|
|
173
|
+
400,
|
|
174
|
+
privateResult ? { assistantTextVisibility: "private" } : undefined,
|
|
175
|
+
),
|
|
176
|
+
);
|
|
177
|
+
attention.latestAssistantMessageId = "later-result";
|
|
178
|
+
attention.latestAssistantMessageAt = startedAt + 400;
|
|
179
|
+
}
|
|
180
|
+
function batchSuccessfulResultWithSibling(
|
|
181
|
+
status: "failed" | "cancelled",
|
|
182
|
+
): void {
|
|
183
|
+
triggerMetadata({
|
|
184
|
+
...JSON.parse(rows.get("trigger")!.metadata!),
|
|
185
|
+
turnOutcome: "batched",
|
|
186
|
+
turnBatchedInto: "batch-final",
|
|
187
|
+
});
|
|
188
|
+
rows.delete("result");
|
|
189
|
+
rows.set(
|
|
190
|
+
"batch-final",
|
|
191
|
+
row("batch-final", "user", "INTERNAL SIBLING FAILURE", 100, {
|
|
192
|
+
backgroundEventSource: "background-tool",
|
|
193
|
+
backgroundToolCompletion: {
|
|
194
|
+
id: "tool-batch-final",
|
|
195
|
+
toolName: "bash",
|
|
196
|
+
conversationId,
|
|
197
|
+
command: "example-command",
|
|
198
|
+
startedAt,
|
|
199
|
+
completedAt: startedAt + 100,
|
|
200
|
+
status,
|
|
201
|
+
exitCode: 1,
|
|
202
|
+
output: "raw failure",
|
|
203
|
+
},
|
|
204
|
+
}),
|
|
205
|
+
);
|
|
206
|
+
rows.set(
|
|
207
|
+
"result",
|
|
208
|
+
row("result", "assistant", "The completed portion is ready.", 100),
|
|
209
|
+
);
|
|
210
|
+
attention.latestAssistantMessageAt = startedAt + 100;
|
|
211
|
+
}
|
|
212
|
+
const internalBatchTriggers = [
|
|
213
|
+
{
|
|
214
|
+
name: "ACP notification",
|
|
215
|
+
metadata: { acpNotification: { acpSessionId: "acp-123" } },
|
|
216
|
+
},
|
|
217
|
+
{ name: "hidden message", metadata: { hidden: true } },
|
|
218
|
+
{ name: "automated message", metadata: { automated: true } },
|
|
219
|
+
{
|
|
220
|
+
name: "background wake",
|
|
221
|
+
metadata: { backgroundEventSource: "agent-wake" },
|
|
222
|
+
},
|
|
223
|
+
] satisfies Array<{ name: string; metadata: Record<string, unknown> }>;
|
|
224
|
+
function batchSuccessfulResultWithInternalTrigger(
|
|
225
|
+
metadata: Record<string, unknown> = internalBatchTriggers[0].metadata,
|
|
226
|
+
): void {
|
|
227
|
+
batchSuccessfulResultWithSibling("failed");
|
|
228
|
+
rows.get("batch-final")!.metadata = JSON.stringify(metadata);
|
|
229
|
+
}
|
|
230
|
+
const emit = (
|
|
231
|
+
overrides: Partial<
|
|
232
|
+
Parameters<typeof emitBackgroundResultNotification>[0]
|
|
233
|
+
> = {},
|
|
234
|
+
) =>
|
|
235
|
+
emitBackgroundResultNotification({
|
|
236
|
+
conversationId,
|
|
237
|
+
assistantMessageId: "result",
|
|
238
|
+
userMessageId: "trigger",
|
|
239
|
+
rlog,
|
|
240
|
+
...overrides,
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
beforeEach(() => {
|
|
244
|
+
rows.clear();
|
|
245
|
+
siblingTasks.clear();
|
|
246
|
+
signals.length = 0;
|
|
247
|
+
pending = false;
|
|
248
|
+
toolsPending = false;
|
|
249
|
+
queued = false;
|
|
250
|
+
notifiedContexts = new Set();
|
|
251
|
+
resultRows = [];
|
|
252
|
+
recipient = "principal-owner";
|
|
253
|
+
visible = false;
|
|
254
|
+
lookupBarrier = undefined;
|
|
255
|
+
deferredLookup = "recipient";
|
|
256
|
+
conversation = {
|
|
257
|
+
id: conversationId,
|
|
258
|
+
source: "web",
|
|
259
|
+
conversationType: "standard",
|
|
260
|
+
title: "Research findings",
|
|
261
|
+
} as ConversationRow;
|
|
262
|
+
task = {
|
|
263
|
+
id: "task-123",
|
|
264
|
+
parentConversationId: conversationId,
|
|
265
|
+
conversationId: "conv-child",
|
|
266
|
+
role: "worker",
|
|
267
|
+
status: "completed",
|
|
268
|
+
isFork: false,
|
|
269
|
+
sendResultToUser: null,
|
|
270
|
+
startedAt,
|
|
271
|
+
createdAt: startedAt,
|
|
272
|
+
} as SubagentRecord;
|
|
273
|
+
attention = {
|
|
274
|
+
conversationId,
|
|
275
|
+
latestAssistantMessageId: "result",
|
|
276
|
+
latestAssistantMessageAt: startedAt + 200,
|
|
277
|
+
lastSeenAssistantMessageAt: null,
|
|
278
|
+
} as AttentionState;
|
|
279
|
+
rows.set(
|
|
280
|
+
"trigger",
|
|
281
|
+
row("trigger", "user", "INTERNAL WAKE TEXT", 100, {
|
|
282
|
+
scripted: true,
|
|
283
|
+
subagentNotification: {
|
|
284
|
+
subagentId: task.id,
|
|
285
|
+
label: "Research",
|
|
286
|
+
status: "completed",
|
|
287
|
+
conversationId: task.conversationId,
|
|
288
|
+
},
|
|
289
|
+
}),
|
|
290
|
+
);
|
|
291
|
+
rows.set(
|
|
292
|
+
"result",
|
|
293
|
+
row("result", "assistant", "Here are the completed findings.", 200),
|
|
294
|
+
);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
describe("background result ownership", () => {
|
|
298
|
+
test.each(internalBatchTriggers)(
|
|
299
|
+
"$name can anchor a completed task's shared result",
|
|
300
|
+
async ({ metadata }) => {
|
|
301
|
+
batchSuccessfulResultWithInternalTrigger(metadata);
|
|
302
|
+
|
|
303
|
+
await emit({ userMessageId: "batch-final" });
|
|
304
|
+
|
|
305
|
+
expect(signals).toHaveLength(1);
|
|
306
|
+
expect(signals[0]).toMatchObject({
|
|
307
|
+
dedupeKey: `activity.complete:${conversationId}:subagent:${task.id}`,
|
|
308
|
+
contextPayload: { requestedMessage: "The completed portion is ready." },
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
test.each(internalBatchTriggers)(
|
|
314
|
+
"$name without an eligible completed batch member stays silent",
|
|
315
|
+
async ({ metadata }) => {
|
|
316
|
+
batchSuccessfulResultWithInternalTrigger(metadata);
|
|
317
|
+
rows.delete("trigger");
|
|
318
|
+
|
|
319
|
+
await emit({ userMessageId: "batch-final" });
|
|
320
|
+
|
|
321
|
+
expect(signals).toHaveLength(0);
|
|
322
|
+
},
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
test.each([
|
|
326
|
+
{ turnOutcome: "failed" },
|
|
327
|
+
{ turnOutcome: "cancelled" },
|
|
328
|
+
{ voiceSessionTurn: true },
|
|
329
|
+
])(
|
|
330
|
+
"a non-completion batch anchor preserves %j suppression",
|
|
331
|
+
async (flags) => {
|
|
332
|
+
batchSuccessfulResultWithInternalTrigger({
|
|
333
|
+
...internalBatchTriggers[0].metadata,
|
|
334
|
+
...flags,
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
await emit({ userMessageId: "batch-final" });
|
|
338
|
+
|
|
339
|
+
expect(signals).toHaveLength(0);
|
|
340
|
+
},
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
test("an internal batch anchor requires the completed member's matching batch link", async () => {
|
|
344
|
+
batchSuccessfulResultWithInternalTrigger();
|
|
345
|
+
for (const turnBatchedInto of [undefined, "missing-target", "trigger"]) {
|
|
346
|
+
triggerMetadata({
|
|
347
|
+
...JSON.parse(rows.get("trigger")!.metadata!),
|
|
348
|
+
turnBatchedInto,
|
|
349
|
+
});
|
|
350
|
+
await emit({ userMessageId: "batch-final" });
|
|
351
|
+
}
|
|
352
|
+
triggerMetadata({
|
|
353
|
+
...JSON.parse(rows.get("trigger")!.metadata!),
|
|
354
|
+
turnOutcome: undefined,
|
|
355
|
+
turnBatchedInto: undefined,
|
|
356
|
+
});
|
|
357
|
+
await emit({ userMessageId: "batch-final" });
|
|
358
|
+
|
|
359
|
+
expect(signals).toHaveLength(0);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
test.each([{}, { userMessageChannel: "slack" }, { voiceSessionTurn: true }])(
|
|
363
|
+
"a person's prompt remains a recovery boundary with metadata %j",
|
|
364
|
+
async (metadata) => {
|
|
365
|
+
batchSuccessfulResultWithInternalTrigger(metadata);
|
|
366
|
+
|
|
367
|
+
await emit({ userMessageId: "batch-final" });
|
|
368
|
+
finishSiblingCommand("failed");
|
|
369
|
+
await emit({
|
|
370
|
+
userMessageId: "later-trigger",
|
|
371
|
+
assistantMessageId: "later-result",
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
expect(signals).toHaveLength(0);
|
|
375
|
+
},
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
test("recovery-only skips the current internal batch and recovers an earlier one", async () => {
|
|
379
|
+
batchSuccessfulResultWithInternalTrigger();
|
|
380
|
+
await emit({
|
|
381
|
+
userMessageId: "batch-final",
|
|
382
|
+
assistantMessageId: undefined,
|
|
383
|
+
recoverOnly: true,
|
|
384
|
+
});
|
|
385
|
+
expect(signals).toHaveLength(0);
|
|
386
|
+
|
|
387
|
+
finishSiblingCommand("failed");
|
|
388
|
+
await emit({
|
|
389
|
+
userMessageId: "later-trigger",
|
|
390
|
+
assistantMessageId: undefined,
|
|
391
|
+
recoverOnly: true,
|
|
392
|
+
});
|
|
393
|
+
expect(signals).toHaveLength(1);
|
|
394
|
+
expect(signals[0].contextPayload?.requestedMessage).toBe(
|
|
395
|
+
"The completed portion is ready.",
|
|
396
|
+
);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
test("internal members preserve their shared batch result across history pages", async () => {
|
|
400
|
+
batchSuccessfulResultWithInternalTrigger();
|
|
401
|
+
const finalTrigger = rows.get("batch-final")!;
|
|
402
|
+
const result = rows.get("result")!;
|
|
403
|
+
rows.delete("batch-final");
|
|
404
|
+
rows.delete("result");
|
|
405
|
+
for (let index = 0; index < 210; index++) {
|
|
406
|
+
rows.set(
|
|
407
|
+
`internal-member-${index}`,
|
|
408
|
+
row(`internal-member-${index}`, "user", "INTERNAL UPDATE", 100, {
|
|
409
|
+
hidden: true,
|
|
410
|
+
turnOutcome: "batched",
|
|
411
|
+
turnBatchedInto: finalTrigger.id,
|
|
412
|
+
}),
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
rows.set(finalTrigger.id, finalTrigger);
|
|
416
|
+
rows.set(result.id, result);
|
|
417
|
+
|
|
418
|
+
await emit({ userMessageId: "batch-final" });
|
|
419
|
+
|
|
420
|
+
expect(signals).toHaveLength(1);
|
|
421
|
+
expect(signals[0].dedupeKey).toBe(
|
|
422
|
+
`activity.complete:${conversationId}:subagent:${task.id}`,
|
|
423
|
+
);
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
test.each(["failed", "cancelled"] as const)(
|
|
427
|
+
"a successful batched child owns the shared result when the final command is %s",
|
|
428
|
+
async (status) => {
|
|
429
|
+
batchSuccessfulResultWithSibling(status);
|
|
430
|
+
queued = true;
|
|
431
|
+
await emit({ userMessageId: "batch-final" });
|
|
432
|
+
expect(signals).toHaveLength(0);
|
|
433
|
+
queued = false;
|
|
434
|
+
await emit({ userMessageId: "batch-final" });
|
|
435
|
+
|
|
436
|
+
expect(signals).toHaveLength(1);
|
|
437
|
+
expect(signals[0]).toMatchObject({
|
|
438
|
+
dedupeKey: `activity.complete:${conversationId}:subagent:${task.id}`,
|
|
439
|
+
contextPayload: {
|
|
440
|
+
requestedMessage: "The completed portion is ready.",
|
|
441
|
+
completion: { workId: `subagent:${task.id}` },
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
},
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
test("a successful batched command owns the shared result when the final child failed", async () => {
|
|
448
|
+
batchSuccessfulResultWithSibling("failed");
|
|
449
|
+
triggerMetadata({
|
|
450
|
+
...JSON.parse(rows.get("batch-final")!.metadata!),
|
|
451
|
+
turnOutcome: "batched",
|
|
452
|
+
turnBatchedInto: "batch-final",
|
|
453
|
+
backgroundToolCompletion: {
|
|
454
|
+
...JSON.parse(rows.get("batch-final")!.metadata!)
|
|
455
|
+
.backgroundToolCompletion,
|
|
456
|
+
id: "tool-success",
|
|
457
|
+
status: "completed",
|
|
458
|
+
exitCode: 0,
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
rows.get("batch-final")!.metadata = JSON.stringify({
|
|
462
|
+
subagentNotification: {
|
|
463
|
+
subagentId: "task-failed",
|
|
464
|
+
conversationId: "conv-failed",
|
|
465
|
+
label: "Sibling",
|
|
466
|
+
status: "failed",
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
await emit({ userMessageId: "batch-final" });
|
|
471
|
+
|
|
472
|
+
expect(signals).toHaveLength(1);
|
|
473
|
+
expect(signals[0].dedupeKey).toBe(
|
|
474
|
+
`activity.complete:${conversationId}:tool:tool-success`,
|
|
475
|
+
);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
test.each(["failed", "cancelled"] as const)(
|
|
479
|
+
"a batched successful task cannot make a %s shared synthesis eligible",
|
|
480
|
+
async (outcome) => {
|
|
481
|
+
batchSuccessfulResultWithSibling("failed");
|
|
482
|
+
rows.get("batch-final")!.metadata = JSON.stringify({
|
|
483
|
+
...JSON.parse(rows.get("batch-final")!.metadata!),
|
|
484
|
+
turnOutcome: outcome,
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
await emit({ userMessageId: "batch-final" });
|
|
488
|
+
finishSiblingCommand("failed");
|
|
489
|
+
await emit({
|
|
490
|
+
userMessageId: "later-trigger",
|
|
491
|
+
assistantMessageId: "later-result",
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
expect(signals).toHaveLength(0);
|
|
495
|
+
},
|
|
496
|
+
);
|
|
497
|
+
|
|
498
|
+
test("recovery-only skips its current batch but can recover an earlier settled batch", async () => {
|
|
499
|
+
batchSuccessfulResultWithSibling("failed");
|
|
500
|
+
await emit({
|
|
501
|
+
userMessageId: "batch-final",
|
|
502
|
+
assistantMessageId: undefined,
|
|
503
|
+
recoverOnly: true,
|
|
504
|
+
});
|
|
505
|
+
expect(signals).toHaveLength(0);
|
|
506
|
+
finishSiblingCommand("cancelled", true);
|
|
507
|
+
await emit({
|
|
508
|
+
userMessageId: "later-trigger",
|
|
509
|
+
assistantMessageId: undefined,
|
|
510
|
+
recoverOnly: true,
|
|
511
|
+
});
|
|
512
|
+
expect(signals).toHaveLength(1);
|
|
513
|
+
expect(signals[0].contextPayload?.requestedMessage).toBe(
|
|
514
|
+
"The completed portion is ready.",
|
|
515
|
+
);
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
test("a successful final batch member keeps sole ownership of the shared result", async () => {
|
|
519
|
+
batchSuccessfulResultWithSibling("failed");
|
|
520
|
+
const metadata = JSON.parse(rows.get("batch-final")!.metadata!);
|
|
521
|
+
rows.get("batch-final")!.metadata = JSON.stringify({
|
|
522
|
+
...metadata,
|
|
523
|
+
backgroundToolCompletion: {
|
|
524
|
+
...metadata.backgroundToolCompletion,
|
|
525
|
+
status: "completed",
|
|
526
|
+
exitCode: 0,
|
|
527
|
+
},
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
await emit({ userMessageId: "batch-final" });
|
|
531
|
+
|
|
532
|
+
expect(signals).toHaveLength(1);
|
|
533
|
+
expect(signals[0].dedupeKey).toBe(
|
|
534
|
+
`activity.complete:${conversationId}:tool:tool-batch-final`,
|
|
535
|
+
);
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
test("an intervening assistant turn invalidates a batch result association", async () => {
|
|
539
|
+
batchSuccessfulResultWithSibling("failed");
|
|
540
|
+
const finalTrigger = rows.get("batch-final")!;
|
|
541
|
+
const result = rows.get("result")!;
|
|
542
|
+
rows.delete("batch-final");
|
|
543
|
+
rows.delete("result");
|
|
544
|
+
rows.set(
|
|
545
|
+
"intervening-result",
|
|
546
|
+
row("intervening-result", "assistant", "Other output", 100),
|
|
547
|
+
);
|
|
548
|
+
rows.set(finalTrigger.id, finalTrigger);
|
|
549
|
+
rows.set(result.id, result);
|
|
550
|
+
|
|
551
|
+
await emit({ userMessageId: "batch-final" });
|
|
552
|
+
|
|
553
|
+
expect(signals).toHaveLength(0);
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
test.each([undefined, "missing-target", "trigger", 123])(
|
|
557
|
+
"a batched result needs its actual final trigger, not %s",
|
|
558
|
+
async (turnBatchedInto) => {
|
|
559
|
+
batchSuccessfulResultWithSibling("failed");
|
|
560
|
+
triggerMetadata({
|
|
561
|
+
...JSON.parse(rows.get("trigger")!.metadata!),
|
|
562
|
+
turnBatchedInto,
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
await emit({ userMessageId: "batch-final" });
|
|
566
|
+
|
|
567
|
+
expect(signals).toHaveLength(0);
|
|
568
|
+
},
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
test.each([
|
|
572
|
+
"quiet child",
|
|
573
|
+
"wrong parent",
|
|
574
|
+
"failed child",
|
|
575
|
+
"seen result",
|
|
576
|
+
"private result",
|
|
577
|
+
"parent delivered",
|
|
578
|
+
"child delivered",
|
|
579
|
+
"scheduled owner",
|
|
580
|
+
])("batch recovery preserves %s suppression", async (reason) => {
|
|
581
|
+
batchSuccessfulResultWithSibling("failed");
|
|
582
|
+
switch (reason) {
|
|
583
|
+
case "quiet child":
|
|
584
|
+
task.sendResultToUser = false;
|
|
585
|
+
break;
|
|
586
|
+
case "wrong parent":
|
|
587
|
+
task.parentConversationId = "conv-other";
|
|
588
|
+
break;
|
|
589
|
+
case "failed child":
|
|
590
|
+
task.status = "failed";
|
|
591
|
+
break;
|
|
592
|
+
case "seen result":
|
|
593
|
+
attention.lastSeenAssistantMessageAt = startedAt + 100;
|
|
594
|
+
break;
|
|
595
|
+
case "private result":
|
|
596
|
+
rows.get("result")!.metadata = JSON.stringify({
|
|
597
|
+
assistantTextVisibility: "private",
|
|
598
|
+
});
|
|
599
|
+
break;
|
|
600
|
+
case "parent delivered":
|
|
601
|
+
notifiedContexts.add(conversationId);
|
|
602
|
+
break;
|
|
603
|
+
case "child delivered":
|
|
604
|
+
notifiedContexts.add(task.conversationId);
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
await emit({
|
|
609
|
+
userMessageId: "batch-final",
|
|
610
|
+
...(reason === "scheduled owner" ? { cronRunId: "run-scheduled" } : {}),
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
expect(signals).toHaveLength(0);
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
test("keeps a batch result association across a history page boundary", async () => {
|
|
617
|
+
batchSuccessfulResultWithSibling("failed");
|
|
618
|
+
const finalTrigger = rows.get("batch-final")!;
|
|
619
|
+
const result = rows.get("result")!;
|
|
620
|
+
rows.delete("batch-final");
|
|
621
|
+
rows.delete("result");
|
|
622
|
+
for (let index = 0; index < 210; index++) {
|
|
623
|
+
rows.set(
|
|
624
|
+
`batch-member-${index}`,
|
|
625
|
+
row(`batch-member-${index}`, "user", "INTERNAL FAILURE", 100, {
|
|
626
|
+
...JSON.parse(finalTrigger.metadata!),
|
|
627
|
+
turnOutcome: "batched",
|
|
628
|
+
turnBatchedInto: finalTrigger.id,
|
|
629
|
+
}),
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
rows.set(finalTrigger.id, finalTrigger);
|
|
633
|
+
rows.set(result.id, result);
|
|
634
|
+
|
|
635
|
+
await emit({ userMessageId: "batch-final" });
|
|
636
|
+
|
|
637
|
+
expect(signals).toHaveLength(1);
|
|
638
|
+
expect(signals[0].dedupeKey).toBe(
|
|
639
|
+
`activity.complete:${conversationId}:subagent:${task.id}`,
|
|
640
|
+
);
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
test.each([...externalChannels])(
|
|
644
|
+
"an undelivered %s-origin delegated result still emits a completion",
|
|
645
|
+
async (channel) => {
|
|
646
|
+
setExternalOrigin(channel);
|
|
647
|
+
await emit();
|
|
648
|
+
expect(signals).toHaveLength(1);
|
|
649
|
+
expect(signals[0]).toMatchObject({
|
|
650
|
+
contextPayload: {
|
|
651
|
+
requestedMessage: "Here are the completed findings.",
|
|
652
|
+
completion: {
|
|
653
|
+
workId: `subagent:${task.id}`,
|
|
654
|
+
conversationId,
|
|
655
|
+
recipientPrincipalId: "principal-owner",
|
|
656
|
+
},
|
|
657
|
+
},
|
|
658
|
+
});
|
|
659
|
+
},
|
|
660
|
+
);
|
|
661
|
+
|
|
662
|
+
test.each([...externalChannels])(
|
|
663
|
+
"an undelivered %s-origin background command result still emits a completion",
|
|
664
|
+
async (channel) => {
|
|
665
|
+
triggerMetadata({
|
|
666
|
+
backgroundEventSource: "background-tool",
|
|
667
|
+
backgroundToolCompletion: {
|
|
668
|
+
id: "tool-123",
|
|
669
|
+
toolName: "bash",
|
|
670
|
+
conversationId,
|
|
671
|
+
command: "example-command",
|
|
672
|
+
startedAt,
|
|
673
|
+
completedAt: startedAt + 100,
|
|
674
|
+
status: "completed",
|
|
675
|
+
exitCode: 0,
|
|
676
|
+
output: "RAW COMMAND OUTPUT",
|
|
677
|
+
},
|
|
678
|
+
});
|
|
679
|
+
setExternalOrigin(channel);
|
|
680
|
+
await emit();
|
|
681
|
+
expect(signals).toHaveLength(1);
|
|
682
|
+
expect(signals[0].dedupeKey).toBe(
|
|
683
|
+
`activity.complete:${conversationId}:tool:tool-123`,
|
|
684
|
+
);
|
|
685
|
+
expect(signals[0].contextPayload?.requestedMessage).toBe(
|
|
686
|
+
"Here are the completed findings.",
|
|
687
|
+
);
|
|
688
|
+
},
|
|
689
|
+
);
|
|
690
|
+
|
|
691
|
+
test("voice continuation results keep their existing delivery owner", async () => {
|
|
692
|
+
triggerMetadata({
|
|
693
|
+
...JSON.parse(rows.get("trigger")!.metadata!),
|
|
694
|
+
voiceSessionTurn: true,
|
|
695
|
+
});
|
|
696
|
+
await emit();
|
|
697
|
+
expect(signals).toHaveLength(0);
|
|
698
|
+
});
|
|
699
|
+
test.each(["failed", "cancelled"] as const)(
|
|
700
|
+
"recovers a deferred successful child result when the last command is %s",
|
|
701
|
+
async (status) => {
|
|
702
|
+
toolsPending = true;
|
|
703
|
+
await emit();
|
|
704
|
+
expect(signals).toHaveLength(0);
|
|
705
|
+
toolsPending = false;
|
|
706
|
+
finishSiblingCommand(status);
|
|
707
|
+
await emit({
|
|
708
|
+
userMessageId: "later-trigger",
|
|
709
|
+
assistantMessageId: "later-result",
|
|
710
|
+
});
|
|
711
|
+
expect(signals).toHaveLength(1);
|
|
712
|
+
expect(signals[0].contextPayload?.requestedMessage).toBe(
|
|
713
|
+
"Here are the completed findings.",
|
|
714
|
+
);
|
|
715
|
+
expect(signals[0].dedupeKey).toBe(
|
|
716
|
+
`activity.complete:${conversationId}:subagent:${task.id}`,
|
|
717
|
+
);
|
|
718
|
+
},
|
|
719
|
+
);
|
|
720
|
+
test.each(["child", "parent"] as const)(
|
|
721
|
+
"a later %s delivery only covers results in its own conversation",
|
|
722
|
+
async (deliveryContext) => {
|
|
723
|
+
pending = true;
|
|
724
|
+
await emit();
|
|
725
|
+
expect(signals).toHaveLength(0);
|
|
726
|
+
pending = false;
|
|
727
|
+
const sibling = {
|
|
728
|
+
...task,
|
|
729
|
+
id: "task-sibling",
|
|
730
|
+
conversationId: "conv-sibling",
|
|
731
|
+
};
|
|
732
|
+
siblingTasks.set(sibling.id, sibling);
|
|
733
|
+
rows.set(
|
|
734
|
+
"later-trigger",
|
|
735
|
+
row("later-trigger", "user", "INTERNAL COMPLETION", 300, {
|
|
736
|
+
subagentNotification: {
|
|
737
|
+
subagentId: sibling.id,
|
|
738
|
+
label: "Other task",
|
|
739
|
+
status: "completed",
|
|
740
|
+
conversationId: sibling.conversationId,
|
|
741
|
+
},
|
|
742
|
+
}),
|
|
743
|
+
);
|
|
744
|
+
rows.set(
|
|
745
|
+
"later-result",
|
|
746
|
+
row("later-result", "assistant", "The other task is ready.", 400),
|
|
747
|
+
);
|
|
748
|
+
attention.latestAssistantMessageId = "later-result";
|
|
749
|
+
attention.latestAssistantMessageAt = startedAt + 400;
|
|
750
|
+
notifiedContexts.add(
|
|
751
|
+
deliveryContext === "child" ? sibling.conversationId : conversationId,
|
|
752
|
+
);
|
|
753
|
+
|
|
754
|
+
await emit({
|
|
755
|
+
userMessageId: "later-trigger",
|
|
756
|
+
assistantMessageId: "later-result",
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
if (deliveryContext === "parent") {
|
|
760
|
+
expect(signals).toHaveLength(0);
|
|
761
|
+
} else {
|
|
762
|
+
expect(signals).toHaveLength(1);
|
|
763
|
+
expect(signals[0]).toMatchObject({
|
|
764
|
+
dedupeKey: `activity.complete:${conversationId}:subagent:${task.id}`,
|
|
765
|
+
contextPayload: {
|
|
766
|
+
requestedMessage: "Here are the completed findings.",
|
|
767
|
+
},
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
},
|
|
771
|
+
);
|
|
772
|
+
test("a private-only or empty final wake can flush the earlier successful result", async () => {
|
|
773
|
+
finishSiblingCommand("failed", true);
|
|
774
|
+
await emit({
|
|
775
|
+
userMessageId: "later-trigger",
|
|
776
|
+
assistantMessageId: "later-result",
|
|
777
|
+
});
|
|
778
|
+
expect(signals[0].contextPayload?.requestedMessage).toBe(
|
|
779
|
+
"Here are the completed findings.",
|
|
780
|
+
);
|
|
781
|
+
signals.length = 0;
|
|
782
|
+
rows.delete("later-result");
|
|
783
|
+
attention.latestAssistantMessageId = "result";
|
|
784
|
+
attention.latestAssistantMessageAt = startedAt + 200;
|
|
785
|
+
await emit({
|
|
786
|
+
userMessageId: "later-trigger",
|
|
787
|
+
assistantMessageId: undefined,
|
|
788
|
+
recoverOnly: true,
|
|
789
|
+
});
|
|
790
|
+
expect(signals).toHaveLength(1);
|
|
791
|
+
});
|
|
792
|
+
test("a successful result viewed before the last failure is not reannounced", async () => {
|
|
793
|
+
finishSiblingCommand("failed");
|
|
794
|
+
attention.lastSeenAssistantMessageAt = startedAt + 200;
|
|
795
|
+
await emit({
|
|
796
|
+
userMessageId: "later-trigger",
|
|
797
|
+
assistantMessageId: "later-result",
|
|
798
|
+
});
|
|
799
|
+
expect(signals).toHaveLength(0);
|
|
800
|
+
});
|
|
801
|
+
test("a later user request ends recovery of earlier completion results", async () => {
|
|
802
|
+
rows.set("new-request", row("new-request", "user", "Another request", 250));
|
|
803
|
+
finishSiblingCommand("failed");
|
|
804
|
+
await emit({
|
|
805
|
+
userMessageId: "later-trigger",
|
|
806
|
+
assistantMessageId: "later-result",
|
|
807
|
+
});
|
|
808
|
+
expect(signals).toHaveLength(0);
|
|
809
|
+
});
|
|
810
|
+
test("recovery preserves explicit delivery and quiet decisions", async () => {
|
|
811
|
+
finishSiblingCommand("failed");
|
|
812
|
+
notifiedContexts.add(conversationId);
|
|
813
|
+
await emit({
|
|
814
|
+
userMessageId: "later-trigger",
|
|
815
|
+
assistantMessageId: "later-result",
|
|
816
|
+
});
|
|
817
|
+
expect(signals).toHaveLength(0);
|
|
818
|
+
});
|
|
819
|
+
test("a failed synthesis of a successful task is not a recoverable result", async () => {
|
|
820
|
+
const metadata = JSON.parse(rows.get("trigger")!.metadata!);
|
|
821
|
+
triggerMetadata({ ...metadata, turnOutcome: "failed" });
|
|
822
|
+
finishSiblingCommand("failed");
|
|
823
|
+
await emit({
|
|
824
|
+
userMessageId: "later-trigger",
|
|
825
|
+
assistantMessageId: "later-result",
|
|
826
|
+
});
|
|
827
|
+
expect(signals).toHaveLength(0);
|
|
828
|
+
});
|
|
829
|
+
test("recovery includes successful output written in the same millisecond as the next trigger", async () => {
|
|
830
|
+
finishSiblingCommand("failed");
|
|
831
|
+
rows.get("result")!.createdAt = rows.get("later-trigger")!.createdAt;
|
|
832
|
+
await emit({
|
|
833
|
+
userMessageId: "later-trigger",
|
|
834
|
+
assistantMessageId: "later-result",
|
|
835
|
+
});
|
|
836
|
+
expect(signals).toHaveLength(1);
|
|
837
|
+
});
|
|
838
|
+
test("recovers a successful result across history pages", async () => {
|
|
839
|
+
for (let index = 0; index < 210; index++) {
|
|
840
|
+
rows.set(`tool-result-${index}`, {
|
|
841
|
+
...row(`tool-result-${index}`, "user", "", 250),
|
|
842
|
+
content: [
|
|
843
|
+
{
|
|
844
|
+
type: "tool_result",
|
|
845
|
+
tool_use_id: `tool-${index}`,
|
|
846
|
+
content: "intermediate output",
|
|
847
|
+
},
|
|
848
|
+
],
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
finishSiblingCommand("failed");
|
|
852
|
+
await emit({
|
|
853
|
+
userMessageId: "later-trigger",
|
|
854
|
+
assistantMessageId: "later-result",
|
|
855
|
+
});
|
|
856
|
+
expect(signals).toHaveLength(1);
|
|
857
|
+
expect(signals[0].contextPayload?.requestedMessage).toBe(
|
|
858
|
+
"Here are the completed findings.",
|
|
859
|
+
);
|
|
860
|
+
});
|
|
861
|
+
test("a final failed child continuation flushes a successful sibling", async () => {
|
|
862
|
+
finishSiblingCommand("failed");
|
|
863
|
+
rows.get("later-trigger")!.metadata = JSON.stringify({
|
|
864
|
+
subagentNotification: {
|
|
865
|
+
subagentId: "task-sibling",
|
|
866
|
+
label: "Sibling",
|
|
867
|
+
status: "failed",
|
|
868
|
+
conversationId: "conv-sibling",
|
|
869
|
+
},
|
|
870
|
+
});
|
|
871
|
+
await emit({
|
|
872
|
+
userMessageId: "later-trigger",
|
|
873
|
+
assistantMessageId: undefined,
|
|
874
|
+
recoverOnly: true,
|
|
875
|
+
});
|
|
876
|
+
expect(signals).toHaveLength(1);
|
|
877
|
+
expect(signals[0].contextPayload?.requestedMessage).toBe(
|
|
878
|
+
"Here are the completed findings.",
|
|
879
|
+
);
|
|
880
|
+
});
|
|
881
|
+
test("a standalone card cannot become an earlier task's recovered result", async () => {
|
|
882
|
+
rows.set(
|
|
883
|
+
"card",
|
|
884
|
+
row("card", "assistant", "System card text", 250, {
|
|
885
|
+
messageKind: "system_card",
|
|
886
|
+
}),
|
|
887
|
+
);
|
|
888
|
+
finishSiblingCommand("failed");
|
|
889
|
+
await emit({
|
|
890
|
+
userMessageId: "later-trigger",
|
|
891
|
+
assistantMessageId: "later-result",
|
|
892
|
+
});
|
|
893
|
+
expect(signals[0].contextPayload?.requestedMessage).toBe(
|
|
894
|
+
"Here are the completed findings.",
|
|
895
|
+
);
|
|
896
|
+
});
|
|
897
|
+
test("seen public output is not reannounced through a later private wrap-up", async () => {
|
|
898
|
+
rows.delete("result");
|
|
899
|
+
rows.set(
|
|
900
|
+
"visible-result",
|
|
901
|
+
row("visible-result", "assistant", "Visible findings", 150),
|
|
902
|
+
);
|
|
903
|
+
rows.set(
|
|
904
|
+
"result",
|
|
905
|
+
row("result", "assistant", "Private wrap-up", 200, {
|
|
906
|
+
assistantTextVisibility: "private",
|
|
907
|
+
}),
|
|
908
|
+
);
|
|
909
|
+
attention.lastSeenAssistantMessageAt = startedAt + 150;
|
|
910
|
+
finishSiblingCommand("failed");
|
|
911
|
+
await emit({
|
|
912
|
+
userMessageId: "later-trigger",
|
|
913
|
+
assistantMessageId: "later-result",
|
|
914
|
+
});
|
|
915
|
+
expect(signals).toHaveLength(0);
|
|
916
|
+
});
|
|
917
|
+
test("a newer human prompt prevents a stale wake from recovering an old result", async () => {
|
|
918
|
+
finishSiblingCommand("failed");
|
|
919
|
+
rows.set("new-request", row("new-request", "user", "Another request", 500));
|
|
920
|
+
await emit({
|
|
921
|
+
userMessageId: "later-trigger",
|
|
922
|
+
assistantMessageId: undefined,
|
|
923
|
+
recoverOnly: true,
|
|
924
|
+
});
|
|
925
|
+
expect(signals).toHaveLength(0);
|
|
926
|
+
});
|
|
927
|
+
test("queued continuations settle before the parent announces completion", async () => {
|
|
928
|
+
queued = true;
|
|
929
|
+
await emit();
|
|
930
|
+
expect(signals).toHaveLength(0);
|
|
931
|
+
queued = false;
|
|
932
|
+
await emit();
|
|
933
|
+
expect(signals).toHaveLength(1);
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
test("a long continuation still recognizes its early successful message delivery", async () => {
|
|
937
|
+
rows.delete("result");
|
|
938
|
+
const delivery = row("early-delivery", "assistant", "", 101);
|
|
939
|
+
delivery.content = [
|
|
940
|
+
{
|
|
941
|
+
type: "tool_use",
|
|
942
|
+
id: "send-result",
|
|
943
|
+
name: "messaging_send",
|
|
944
|
+
input: {},
|
|
945
|
+
},
|
|
946
|
+
];
|
|
947
|
+
rows.set(delivery.id, delivery);
|
|
948
|
+
const receipt = row("delivery-receipt", "user", "", 102);
|
|
949
|
+
receipt.content = [
|
|
950
|
+
{ type: "tool_result", tool_use_id: "send-result", content: "Delivered" },
|
|
951
|
+
];
|
|
952
|
+
rows.set(receipt.id, receipt);
|
|
953
|
+
resultRows.push(receipt);
|
|
954
|
+
for (let index = 0; index < 220; index++) {
|
|
955
|
+
rows.set(
|
|
956
|
+
`long-turn-${index}`,
|
|
957
|
+
row(`long-turn-${index}`, "assistant", "Working", 103 + index),
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
rows.set("result", row("result", "assistant", "Result ready.", 400));
|
|
961
|
+
attention.latestAssistantMessageAt = startedAt + 400;
|
|
962
|
+
|
|
963
|
+
await emit();
|
|
964
|
+
|
|
965
|
+
expect(signals).toHaveLength(0);
|
|
966
|
+
});
|
|
967
|
+
|
|
968
|
+
test("private wrap-up uses the earlier user-facing result", async () => {
|
|
969
|
+
rows.delete("result");
|
|
970
|
+
rows.set(
|
|
971
|
+
"visible-result",
|
|
972
|
+
row("visible-result", "assistant", "The requested findings.", 150),
|
|
973
|
+
);
|
|
974
|
+
rows.set(
|
|
975
|
+
"result",
|
|
976
|
+
row("result", "assistant", "Private reasoning", 200, {
|
|
977
|
+
assistantTextVisibility: "private",
|
|
978
|
+
}),
|
|
979
|
+
);
|
|
980
|
+
await emit();
|
|
981
|
+
expect(signals[0].contextPayload?.requestedMessage).toBe(
|
|
982
|
+
"The requested findings.",
|
|
983
|
+
);
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
test("delegated result uses its parent's persisted copy and stable task identity", async () => {
|
|
987
|
+
await emit();
|
|
988
|
+
await emit();
|
|
989
|
+
expect(signals).toHaveLength(2);
|
|
990
|
+
expect(signals[0]).toMatchObject({
|
|
991
|
+
sourceEventName: "activity.complete",
|
|
992
|
+
sourceContextId: conversationId,
|
|
993
|
+
dedupeKey: `activity.complete:${conversationId}:subagent:${task.id}`,
|
|
994
|
+
contextPayload: {
|
|
995
|
+
requestedMessage: "Here are the completed findings.",
|
|
996
|
+
completion: {
|
|
997
|
+
workId: `subagent:${task.id}`,
|
|
998
|
+
recipientPrincipalId: "principal-owner",
|
|
999
|
+
conversationId,
|
|
1000
|
+
owner: "parent_continuation",
|
|
1001
|
+
},
|
|
1002
|
+
},
|
|
1003
|
+
});
|
|
1004
|
+
expect(signals[1].dedupeKey).toBe(signals[0].dedupeKey);
|
|
1005
|
+
expect(JSON.stringify(signals[0])).not.toContain("INTERNAL WAKE TEXT");
|
|
1006
|
+
});
|
|
1007
|
+
test("presence comes from the shared completion helper", async () => {
|
|
1008
|
+
visible = true;
|
|
1009
|
+
await emit();
|
|
1010
|
+
expect(signals[0].attentionHints.visibleInSourceNow).toBe(true);
|
|
1011
|
+
});
|
|
1012
|
+
test("missing recipient never falls back to public delivery", async () => {
|
|
1013
|
+
recipient = undefined;
|
|
1014
|
+
await emit();
|
|
1015
|
+
expect(signals).toHaveLength(0);
|
|
1016
|
+
});
|
|
1017
|
+
test.each(["scheduled", "background"])(
|
|
1018
|
+
"%s conversations keep their existing owner",
|
|
1019
|
+
async (kind) => {
|
|
1020
|
+
conversation.conversationType = kind as "scheduled" | "background";
|
|
1021
|
+
await emit();
|
|
1022
|
+
expect(signals).toHaveLength(0);
|
|
1023
|
+
},
|
|
1024
|
+
);
|
|
1025
|
+
test("scheduled continuations in a standard conversation keep the scheduler owner", async () => {
|
|
1026
|
+
await emit({ cronRunId: "run-scheduled" });
|
|
1027
|
+
expect(signals).toHaveLength(0);
|
|
1028
|
+
});
|
|
1029
|
+
test.each(["failed", "aborted", "running", "interrupted"])(
|
|
1030
|
+
"a %s task never earns a success notification",
|
|
1031
|
+
async (status) => {
|
|
1032
|
+
task.status = status;
|
|
1033
|
+
await emit();
|
|
1034
|
+
expect(signals).toHaveLength(0);
|
|
1035
|
+
},
|
|
1036
|
+
);
|
|
1037
|
+
test("silent forks, explicit silence and advisor work stay quiet", async () => {
|
|
1038
|
+
task.isFork = true;
|
|
1039
|
+
await emit();
|
|
1040
|
+
task.isFork = false;
|
|
1041
|
+
task.sendResultToUser = false;
|
|
1042
|
+
await emit();
|
|
1043
|
+
task.sendResultToUser = true;
|
|
1044
|
+
task.role = "advisor";
|
|
1045
|
+
await emit();
|
|
1046
|
+
expect(signals).toHaveLength(0);
|
|
1047
|
+
});
|
|
1048
|
+
test("a fork explicitly shared with the user notifies", async () => {
|
|
1049
|
+
task.isFork = true;
|
|
1050
|
+
task.sendResultToUser = true;
|
|
1051
|
+
await emit();
|
|
1052
|
+
expect(signals).toHaveLength(1);
|
|
1053
|
+
});
|
|
1054
|
+
test("mismatched task parent cannot opt another conversation into completion", async () => {
|
|
1055
|
+
task.parentConversationId = "conv-other";
|
|
1056
|
+
await emit();
|
|
1057
|
+
expect(signals).toHaveLength(0);
|
|
1058
|
+
});
|
|
1059
|
+
test("ordinary automation and nonterminal updates do not opt in", async () => {
|
|
1060
|
+
triggerMetadata({ scripted: true, hidden: true });
|
|
1061
|
+
await emit();
|
|
1062
|
+
triggerMetadata({
|
|
1063
|
+
subagentNotification: {
|
|
1064
|
+
subagentId: task.id,
|
|
1065
|
+
label: "Research",
|
|
1066
|
+
status: "running",
|
|
1067
|
+
conversationId: task.conversationId,
|
|
1068
|
+
},
|
|
1069
|
+
});
|
|
1070
|
+
await emit();
|
|
1071
|
+
expect(signals).toHaveLength(0);
|
|
1072
|
+
});
|
|
1073
|
+
test("ongoing delegated or shell work prevents a premature completion", async () => {
|
|
1074
|
+
pending = true;
|
|
1075
|
+
await emit();
|
|
1076
|
+
pending = false;
|
|
1077
|
+
toolsPending = true;
|
|
1078
|
+
await emit();
|
|
1079
|
+
expect(signals).toHaveLength(0);
|
|
1080
|
+
});
|
|
1081
|
+
test("explicit delivery or quiet decision by parent or child suppresses fallback", async () => {
|
|
1082
|
+
notifiedContexts.add(conversationId);
|
|
1083
|
+
await emit();
|
|
1084
|
+
notifiedContexts.clear();
|
|
1085
|
+
notifiedContexts.add(task.conversationId);
|
|
1086
|
+
await emit();
|
|
1087
|
+
expect(signals).toHaveLength(0);
|
|
1088
|
+
});
|
|
1089
|
+
test.each([...externalChannels])(
|
|
1090
|
+
"only an acknowledged messaging send suppresses the %s-origin fallback",
|
|
1091
|
+
async (channel) => {
|
|
1092
|
+
setExternalOrigin(channel);
|
|
1093
|
+
const result = rows.get("result")!;
|
|
1094
|
+
rows.delete("result");
|
|
1095
|
+
rows.set("send", {
|
|
1096
|
+
...row("send", "assistant", "", 150),
|
|
1097
|
+
content: [
|
|
1098
|
+
{ type: "tool_use", name: "messaging_send", id: "send-1", input: {} },
|
|
1099
|
+
] as ContentBlock[],
|
|
1100
|
+
});
|
|
1101
|
+
rows.set(result.id, result);
|
|
1102
|
+
await emit();
|
|
1103
|
+
expect(signals).toHaveLength(1);
|
|
1104
|
+
signals.length = 0;
|
|
1105
|
+
resultRows = [
|
|
1106
|
+
{
|
|
1107
|
+
...row("send-result", "user", "", 160),
|
|
1108
|
+
content: [
|
|
1109
|
+
{
|
|
1110
|
+
type: "tool_result",
|
|
1111
|
+
tool_use_id: "send-1",
|
|
1112
|
+
is_error: true,
|
|
1113
|
+
content: "failed",
|
|
1114
|
+
},
|
|
1115
|
+
] as ContentBlock[],
|
|
1116
|
+
},
|
|
1117
|
+
];
|
|
1118
|
+
await emit();
|
|
1119
|
+
expect(signals).toHaveLength(1);
|
|
1120
|
+
resultRows[0].content = [
|
|
1121
|
+
{ type: "tool_result", tool_use_id: "send-1", content: "sent" },
|
|
1122
|
+
] as ContentBlock[];
|
|
1123
|
+
await emit();
|
|
1124
|
+
expect(signals).toHaveLength(1);
|
|
1125
|
+
},
|
|
1126
|
+
);
|
|
1127
|
+
test("empty, private-only, unfinalized, and seen results stay quiet", async () => {
|
|
1128
|
+
rows.set("result", row("result", "assistant", "", 200));
|
|
1129
|
+
await emit();
|
|
1130
|
+
rows.set(
|
|
1131
|
+
"result",
|
|
1132
|
+
row("result", "assistant", "private notes", 200, {
|
|
1133
|
+
assistantTextVisibility: "private",
|
|
1134
|
+
}),
|
|
1135
|
+
);
|
|
1136
|
+
await emit();
|
|
1137
|
+
rows.set("result", {
|
|
1138
|
+
...row("result", "assistant", "Result", 200),
|
|
1139
|
+
finalized: 0,
|
|
1140
|
+
});
|
|
1141
|
+
await emit();
|
|
1142
|
+
rows.set("result", row("result", "assistant", "Result", 200));
|
|
1143
|
+
attention.lastSeenAssistantMessageAt = attention.latestAssistantMessageAt;
|
|
1144
|
+
await emit();
|
|
1145
|
+
expect(signals).toHaveLength(0);
|
|
1146
|
+
});
|
|
1147
|
+
test("a newer result does not reannounce an older continuation", async () => {
|
|
1148
|
+
attention.latestAssistantMessageId = "newer-result";
|
|
1149
|
+
await emit();
|
|
1150
|
+
expect(signals).toHaveLength(0);
|
|
1151
|
+
});
|
|
1152
|
+
test.each(["completed", "failed", "cancelled"])(
|
|
1153
|
+
"background command %s only notifies after successful synthesis",
|
|
1154
|
+
async (status) => {
|
|
1155
|
+
triggerMetadata({
|
|
1156
|
+
kind: "background-event",
|
|
1157
|
+
backgroundEventSource: "background-tool",
|
|
1158
|
+
automated: true,
|
|
1159
|
+
backgroundToolCompletion: {
|
|
1160
|
+
id: "tool-123",
|
|
1161
|
+
toolName: "bash",
|
|
1162
|
+
conversationId,
|
|
1163
|
+
command: "example-command",
|
|
1164
|
+
startedAt,
|
|
1165
|
+
completedAt: startedAt + 100,
|
|
1166
|
+
status,
|
|
1167
|
+
exitCode: status === "completed" ? 0 : 1,
|
|
1168
|
+
output: "RAW COMMAND OUTPUT",
|
|
1169
|
+
},
|
|
1170
|
+
});
|
|
1171
|
+
await emit();
|
|
1172
|
+
expect(signals).toHaveLength(status === "completed" ? 1 : 0);
|
|
1173
|
+
if (status === "completed") {
|
|
1174
|
+
expect(signals[0].dedupeKey).toBe(
|
|
1175
|
+
`activity.complete:${conversationId}:tool:tool-123`,
|
|
1176
|
+
);
|
|
1177
|
+
expect(JSON.stringify(signals[0])).not.toContain("RAW COMMAND OUTPUT");
|
|
1178
|
+
}
|
|
1179
|
+
},
|
|
1180
|
+
);
|
|
1181
|
+
});
|
|
1182
|
+
|
|
1183
|
+
describe("completion eligibility after asynchronous lookups", () => {
|
|
1184
|
+
for (const lookup of ["recipient", "presence"] as const) {
|
|
1185
|
+
for (const change of [
|
|
1186
|
+
"seen",
|
|
1187
|
+
"archived",
|
|
1188
|
+
"deleted",
|
|
1189
|
+
"queued",
|
|
1190
|
+
"tool",
|
|
1191
|
+
"child",
|
|
1192
|
+
"delivered",
|
|
1193
|
+
"new turn",
|
|
1194
|
+
] as const) {
|
|
1195
|
+
test(`${change} during ${lookup} lookup suppresses the stale alert`, async () => {
|
|
1196
|
+
deferredLookup = lookup;
|
|
1197
|
+
const entered = Promise.withResolvers<void>();
|
|
1198
|
+
const release = Promise.withResolvers<void>();
|
|
1199
|
+
lookupBarrier = () => {
|
|
1200
|
+
entered.resolve();
|
|
1201
|
+
return release.promise;
|
|
1202
|
+
};
|
|
1203
|
+
const notification = emit({ conversation: { ...conversation } });
|
|
1204
|
+
await entered.promise;
|
|
1205
|
+
switch (change) {
|
|
1206
|
+
case "seen":
|
|
1207
|
+
attention.lastSeenAssistantMessageAt =
|
|
1208
|
+
attention.latestAssistantMessageAt;
|
|
1209
|
+
break;
|
|
1210
|
+
case "archived":
|
|
1211
|
+
conversation.archivedAt = startedAt + 500;
|
|
1212
|
+
break;
|
|
1213
|
+
case "deleted":
|
|
1214
|
+
rows.clear();
|
|
1215
|
+
break;
|
|
1216
|
+
case "queued":
|
|
1217
|
+
queued = true;
|
|
1218
|
+
break;
|
|
1219
|
+
case "tool":
|
|
1220
|
+
toolsPending = true;
|
|
1221
|
+
break;
|
|
1222
|
+
case "child":
|
|
1223
|
+
pending = true;
|
|
1224
|
+
break;
|
|
1225
|
+
case "delivered":
|
|
1226
|
+
notifiedContexts.add(conversationId);
|
|
1227
|
+
break;
|
|
1228
|
+
case "new turn":
|
|
1229
|
+
rows.set(
|
|
1230
|
+
"new-user",
|
|
1231
|
+
row("new-user", "user", "Another question", 300),
|
|
1232
|
+
);
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
release.resolve();
|
|
1236
|
+
await notification;
|
|
1237
|
+
expect(signals).toHaveLength(0);
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
test(`a newer completion supersedes the alert waiting on ${lookup}`, async () => {
|
|
1242
|
+
deferredLookup = lookup;
|
|
1243
|
+
const entered = Promise.withResolvers<void>();
|
|
1244
|
+
const release = Promise.withResolvers<void>();
|
|
1245
|
+
lookupBarrier = () => {
|
|
1246
|
+
entered.resolve();
|
|
1247
|
+
return release.promise;
|
|
1248
|
+
};
|
|
1249
|
+
const oldNotification = emit();
|
|
1250
|
+
await entered.promise;
|
|
1251
|
+
finishSiblingCommand("failed");
|
|
1252
|
+
const trigger = rows.get("later-trigger")!;
|
|
1253
|
+
const metadata = JSON.parse(trigger.metadata!);
|
|
1254
|
+
metadata.backgroundToolCompletion.status = "completed";
|
|
1255
|
+
metadata.backgroundToolCompletion.exitCode = 0;
|
|
1256
|
+
trigger.metadata = JSON.stringify(metadata);
|
|
1257
|
+
rows.get("later-result")!.content = [
|
|
1258
|
+
{ type: "text", text: "The newer result is ready." },
|
|
1259
|
+
];
|
|
1260
|
+
lookupBarrier = undefined;
|
|
1261
|
+
await emit({
|
|
1262
|
+
userMessageId: "later-trigger",
|
|
1263
|
+
assistantMessageId: "later-result",
|
|
1264
|
+
});
|
|
1265
|
+
release.resolve();
|
|
1266
|
+
await oldNotification;
|
|
1267
|
+
expect(
|
|
1268
|
+
signals.map((signal) => signal.contextPayload?.requestedMessage),
|
|
1269
|
+
).toEqual(["The newer result is ready."]);
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
});
|