@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
|
@@ -24,6 +24,7 @@ import { extractPreferences } from "../notifications/preference-extractor.js";
|
|
|
24
24
|
import { createPreference } from "../notifications/preferences-store.js";
|
|
25
25
|
import {
|
|
26
26
|
addMessage,
|
|
27
|
+
getMessageById,
|
|
27
28
|
isEchoSuppressedUserMessage,
|
|
28
29
|
isHiddenMessageMetadata,
|
|
29
30
|
isSuppressedQueuedMessage,
|
|
@@ -44,12 +45,14 @@ import { stampTurnOutcome } from "../telemetry/turn-outcome.js";
|
|
|
44
45
|
import { getLogger } from "../util/logger.js";
|
|
45
46
|
import type { CleanResult, Conversation } from "./conversation.js";
|
|
46
47
|
import { repairInterruptedToolUseBlocks } from "./conversation-interrupt-repair.js";
|
|
48
|
+
import { discardQueueOnAbort } from "./conversation-lifecycle.js";
|
|
47
49
|
import {
|
|
48
50
|
CONVERSATION_BUSY_MESSAGE,
|
|
49
51
|
persistQueuedMessageBody,
|
|
50
52
|
serializePersistedUserMessageContent,
|
|
51
53
|
} from "./conversation-messaging.js";
|
|
52
54
|
import type {
|
|
55
|
+
QueuedDispatch,
|
|
53
56
|
QueuedMessage,
|
|
54
57
|
QueueDrainReason,
|
|
55
58
|
} from "./conversation-queue-manager.js";
|
|
@@ -506,8 +509,8 @@ export async function drainQueue(
|
|
|
506
509
|
if (!next) {
|
|
507
510
|
return;
|
|
508
511
|
}
|
|
509
|
-
return dispatchDrainWithRestore(conversation, [next], true, () =>
|
|
510
|
-
drainSingleMessage(conversation, next, reason, true),
|
|
512
|
+
return dispatchDrainWithRestore(conversation, [next], true, (signal) =>
|
|
513
|
+
drainSingleMessage(conversation, next, reason, true, signal),
|
|
511
514
|
);
|
|
512
515
|
}
|
|
513
516
|
|
|
@@ -520,17 +523,17 @@ export async function drainQueue(
|
|
|
520
523
|
if (!next) {
|
|
521
524
|
return;
|
|
522
525
|
}
|
|
523
|
-
return dispatchDrainWithRestore(conversation, [next], false, () =>
|
|
524
|
-
drainSingleMessage(conversation, next, reason),
|
|
526
|
+
return dispatchDrainWithRestore(conversation, [next], false, (signal) =>
|
|
527
|
+
drainSingleMessage(conversation, next, reason, false, signal),
|
|
525
528
|
);
|
|
526
529
|
}
|
|
527
530
|
if (batch.length === 1) {
|
|
528
|
-
return dispatchDrainWithRestore(conversation, batch, false, () =>
|
|
529
|
-
drainSingleMessage(conversation, batch[0], reason),
|
|
531
|
+
return dispatchDrainWithRestore(conversation, batch, false, (signal) =>
|
|
532
|
+
drainSingleMessage(conversation, batch[0], reason, false, signal),
|
|
530
533
|
);
|
|
531
534
|
}
|
|
532
|
-
return dispatchDrainWithRestore(conversation, batch, false, () =>
|
|
533
|
-
drainBatch(conversation, batch, reason),
|
|
535
|
+
return dispatchDrainWithRestore(conversation, batch, false, (signal) =>
|
|
536
|
+
drainBatch(conversation, batch, reason, signal),
|
|
534
537
|
);
|
|
535
538
|
}
|
|
536
539
|
|
|
@@ -555,11 +558,46 @@ async function dispatchDrainWithRestore(
|
|
|
555
558
|
conversation: Conversation,
|
|
556
559
|
messages: QueuedMessage[],
|
|
557
560
|
steered: boolean,
|
|
558
|
-
dispatch: () => Promise<void>,
|
|
561
|
+
dispatch: (signal?: AbortSignal) => Promise<void>,
|
|
559
562
|
): Promise<void> {
|
|
563
|
+
const runId = messages[0]?.cronRunId ?? null;
|
|
564
|
+
const controller = new AbortController();
|
|
565
|
+
const pending =
|
|
566
|
+
(conversation.pendingQueuedDispatches ??= new Map()).get(runId) ??
|
|
567
|
+
new Set<QueuedDispatch>();
|
|
568
|
+
const queuedDispatch = { controller, messages };
|
|
569
|
+
pending.add(queuedDispatch);
|
|
570
|
+
conversation.pendingQueuedDispatches.set(runId, pending);
|
|
571
|
+
const cancelDispatch = () => {
|
|
572
|
+
const unpersisted: QueuedMessage[] = [];
|
|
573
|
+
for (const message of messages) {
|
|
574
|
+
if (getMessageById(message.requestId, conversation.conversationId)) {
|
|
575
|
+
message.onEvent({
|
|
576
|
+
type: "generation_cancelled",
|
|
577
|
+
conversationId: conversation.conversationId,
|
|
578
|
+
});
|
|
579
|
+
} else {
|
|
580
|
+
unpersisted.push(message);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
if (unpersisted.length === 0) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
requeueDrainedMessages(
|
|
587
|
+
conversation,
|
|
588
|
+
unpersisted,
|
|
589
|
+
steered,
|
|
590
|
+
"Restoring cancelled dispatch for queue teardown",
|
|
591
|
+
);
|
|
592
|
+
discardQueueOnAbort(conversation, (queued) => unpersisted.includes(queued));
|
|
593
|
+
};
|
|
594
|
+
controller.signal.addEventListener("abort", cancelDispatch, { once: true });
|
|
560
595
|
try {
|
|
561
|
-
return await dispatch();
|
|
596
|
+
return await dispatch(controller.signal);
|
|
562
597
|
} catch (err) {
|
|
598
|
+
if (controller.signal.aborted) {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
563
601
|
const alreadyRestored =
|
|
564
602
|
typeof err === "object" && err !== null && restoredDrainErrors.has(err);
|
|
565
603
|
if (!alreadyRestored) {
|
|
@@ -574,6 +612,12 @@ async function dispatchDrainWithRestore(
|
|
|
574
612
|
);
|
|
575
613
|
}
|
|
576
614
|
throw err;
|
|
615
|
+
} finally {
|
|
616
|
+
controller.signal.removeEventListener("abort", cancelDispatch);
|
|
617
|
+
pending.delete(queuedDispatch);
|
|
618
|
+
if (pending.size === 0) {
|
|
619
|
+
conversation.pendingQueuedDispatches.delete(runId);
|
|
620
|
+
}
|
|
577
621
|
}
|
|
578
622
|
}
|
|
579
623
|
|
|
@@ -651,6 +695,7 @@ async function drainSingleMessage(
|
|
|
651
695
|
next: QueuedMessage,
|
|
652
696
|
reason: QueueDrainReason,
|
|
653
697
|
steered = false,
|
|
698
|
+
signal?: AbortSignal,
|
|
654
699
|
): Promise<void> {
|
|
655
700
|
// Another turn already owns the processing lock: requeue before touching
|
|
656
701
|
// ANY conversation state. The lock holder installed its own per-turn
|
|
@@ -762,6 +807,11 @@ async function drainSingleMessage(
|
|
|
762
807
|
buildSlashContext(next.content, conversation),
|
|
763
808
|
);
|
|
764
809
|
|
|
810
|
+
if (signal?.aborted) {
|
|
811
|
+
await drainQueue(conversation);
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
|
|
765
815
|
// Unknown slash — persist the exchange and continue draining.
|
|
766
816
|
// Persist each message before pushing to conversation.messages so that a
|
|
767
817
|
// failed write never leaves an unpersisted message in memory.
|
|
@@ -1087,6 +1137,9 @@ async function drainSingleMessage(
|
|
|
1087
1137
|
try {
|
|
1088
1138
|
persistResult = await conversation.persistUserMessage({
|
|
1089
1139
|
content: resolvedContent,
|
|
1140
|
+
cronRunId: next.cronRunId,
|
|
1141
|
+
signal,
|
|
1142
|
+
insertPrecondition: () => !signal?.aborted,
|
|
1090
1143
|
attachments: next.attachments,
|
|
1091
1144
|
requestId: next.requestId,
|
|
1092
1145
|
activeSurfaceId: next.activeSurfaceId,
|
|
@@ -1101,6 +1154,10 @@ async function drainSingleMessage(
|
|
|
1101
1154
|
: {}),
|
|
1102
1155
|
});
|
|
1103
1156
|
} catch (err) {
|
|
1157
|
+
if (signal?.aborted) {
|
|
1158
|
+
await drainQueue(conversation);
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1104
1161
|
const message = err instanceof Error ? err.message : String(err);
|
|
1105
1162
|
// runAgentLoop never ran, so its finally block won't clear this
|
|
1106
1163
|
conversation.preactivatedSkillIds = undefined;
|
|
@@ -1275,6 +1332,7 @@ async function drainBatch(
|
|
|
1275
1332
|
conversation: Conversation,
|
|
1276
1333
|
batch: QueuedMessage[],
|
|
1277
1334
|
reason: QueueDrainReason,
|
|
1335
|
+
signal?: AbortSignal,
|
|
1278
1336
|
): Promise<void> {
|
|
1279
1337
|
// Another turn already owns the processing lock: requeue the whole batch
|
|
1280
1338
|
// before touching ANY conversation state, mirroring `drainSingleMessage`.
|
|
@@ -1409,6 +1467,9 @@ async function drainBatch(
|
|
|
1409
1467
|
qm.content,
|
|
1410
1468
|
buildSlashContext(qm.content, conversation),
|
|
1411
1469
|
);
|
|
1470
|
+
if (signal?.aborted) {
|
|
1471
|
+
break;
|
|
1472
|
+
}
|
|
1412
1473
|
if (qmSlash.kind !== "passthrough") {
|
|
1413
1474
|
// Defensive recovery. `buildPassthroughBatch` should make this
|
|
1414
1475
|
// unreachable, but if it ever fires we must avoid stranding
|
|
@@ -1446,9 +1507,15 @@ async function drainBatch(
|
|
|
1446
1507
|
conversation.preactivatedSkillIds = undefined;
|
|
1447
1508
|
const remaining = batch.slice(1);
|
|
1448
1509
|
if (remaining.length >= 2) {
|
|
1449
|
-
await drainBatch(conversation, remaining, reason);
|
|
1510
|
+
await drainBatch(conversation, remaining, reason, signal);
|
|
1450
1511
|
} else if (remaining.length === 1) {
|
|
1451
|
-
await drainSingleMessage(
|
|
1512
|
+
await drainSingleMessage(
|
|
1513
|
+
conversation,
|
|
1514
|
+
remaining[0],
|
|
1515
|
+
reason,
|
|
1516
|
+
false,
|
|
1517
|
+
signal,
|
|
1518
|
+
);
|
|
1452
1519
|
} else {
|
|
1453
1520
|
await drainQueue(conversation);
|
|
1454
1521
|
}
|
|
@@ -1464,6 +1531,9 @@ async function drainBatch(
|
|
|
1464
1531
|
let batchPersistResult: { id: string; deduplicated: boolean };
|
|
1465
1532
|
const persistOptions = {
|
|
1466
1533
|
content: qmContent,
|
|
1534
|
+
cronRunId: qm.cronRunId,
|
|
1535
|
+
signal,
|
|
1536
|
+
insertPrecondition: () => !signal?.aborted,
|
|
1467
1537
|
attachments: qm.attachments,
|
|
1468
1538
|
requestId: qm.requestId,
|
|
1469
1539
|
activeSurfaceId: qm.activeSurfaceId,
|
|
@@ -1494,9 +1564,15 @@ async function drainBatch(
|
|
|
1494
1564
|
// processing via persistUserMessage.
|
|
1495
1565
|
const remaining = batch.slice(1);
|
|
1496
1566
|
if (remaining.length >= 2) {
|
|
1497
|
-
await drainBatch(conversation, remaining, reason);
|
|
1567
|
+
await drainBatch(conversation, remaining, reason, signal);
|
|
1498
1568
|
} else if (remaining.length === 1) {
|
|
1499
|
-
await drainSingleMessage(
|
|
1569
|
+
await drainSingleMessage(
|
|
1570
|
+
conversation,
|
|
1571
|
+
remaining[0],
|
|
1572
|
+
reason,
|
|
1573
|
+
false,
|
|
1574
|
+
signal,
|
|
1575
|
+
);
|
|
1500
1576
|
} else {
|
|
1501
1577
|
await drainQueue(conversation);
|
|
1502
1578
|
}
|
|
@@ -1507,6 +1583,9 @@ async function drainBatch(
|
|
|
1507
1583
|
lastUserMessageId = batchPersistResult.id;
|
|
1508
1584
|
persistedMessageIds.push(batchPersistResult.id);
|
|
1509
1585
|
} catch (err) {
|
|
1586
|
+
if (signal?.aborted) {
|
|
1587
|
+
break;
|
|
1588
|
+
}
|
|
1510
1589
|
const message = err instanceof Error ? err.message : String(err);
|
|
1511
1590
|
if (i === 0 && message === CONVERSATION_BUSY_MESSAGE) {
|
|
1512
1591
|
// The head hit lock contention before any batch state was set:
|
|
@@ -1546,9 +1625,15 @@ async function drainBatch(
|
|
|
1546
1625
|
conversation.preactivatedSkillIds = undefined;
|
|
1547
1626
|
const remaining = batch.slice(1);
|
|
1548
1627
|
if (remaining.length >= 2) {
|
|
1549
|
-
await drainBatch(conversation, remaining, reason);
|
|
1628
|
+
await drainBatch(conversation, remaining, reason, signal);
|
|
1550
1629
|
} else if (remaining.length === 1) {
|
|
1551
|
-
await drainSingleMessage(
|
|
1630
|
+
await drainSingleMessage(
|
|
1631
|
+
conversation,
|
|
1632
|
+
remaining[0],
|
|
1633
|
+
reason,
|
|
1634
|
+
false,
|
|
1635
|
+
signal,
|
|
1636
|
+
);
|
|
1552
1637
|
} else {
|
|
1553
1638
|
await drainQueue(conversation);
|
|
1554
1639
|
}
|
|
@@ -1660,6 +1745,9 @@ async function drainBatch(
|
|
|
1660
1745
|
"drainBatch: no messages persisted successfully; skipping runAgentLoop",
|
|
1661
1746
|
);
|
|
1662
1747
|
conversation.preactivatedSkillIds = undefined;
|
|
1748
|
+
if (signal?.aborted) {
|
|
1749
|
+
await drainQueue(conversation);
|
|
1750
|
+
}
|
|
1663
1751
|
return;
|
|
1664
1752
|
}
|
|
1665
1753
|
|
|
@@ -1679,6 +1767,9 @@ async function drainBatch(
|
|
|
1679
1767
|
// side correlation (message_complete / generation_cancelled /
|
|
1680
1768
|
// generation_handoff) surfaces a requestId that actually has a DB row.
|
|
1681
1769
|
conversation.currentRequestId = lastSuccessfulRequestId;
|
|
1770
|
+
conversation.currentTurnWorkOrigins = successfulBatch.map(
|
|
1771
|
+
({ sentAt, metadata }) => ({ sentAt, metadata }),
|
|
1772
|
+
);
|
|
1682
1773
|
conversation.currentActiveSurfaceId = lastSuccessfulActiveSurfaceId;
|
|
1683
1774
|
conversation.currentPage = lastSuccessfulCurrentPage;
|
|
1684
1775
|
|
|
@@ -70,6 +70,13 @@ export interface QueuedMessage {
|
|
|
70
70
|
dequeueAnnounced?: boolean;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
export type TurnWorkOrigin = Pick<QueuedMessage, "sentAt" | "metadata">;
|
|
74
|
+
|
|
75
|
+
export interface QueuedDispatch {
|
|
76
|
+
readonly controller: AbortController;
|
|
77
|
+
readonly messages: readonly QueuedMessage[];
|
|
78
|
+
}
|
|
79
|
+
|
|
73
80
|
/**
|
|
74
81
|
* Maximum total estimated bytes across all queued messages per conversation.
|
|
75
82
|
* Limits memory consumption when a sender floods messages while the
|
|
@@ -2529,6 +2529,7 @@ export async function applyRuntimeInjections(
|
|
|
2529
2529
|
liveConversation?.getTurnOrRestingTrust() ??
|
|
2530
2530
|
fallbackTurnTrust(channelCapabilities),
|
|
2531
2531
|
callSite: options.callSite ?? liveConversation?.currentCallSite,
|
|
2532
|
+
skipMemoryRetrieval: liveConversation?.currentTurnSkipMemoryRetrieval,
|
|
2532
2533
|
...injectionInputs,
|
|
2533
2534
|
};
|
|
2534
2535
|
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
postTurnTruncateToolResults,
|
|
35
35
|
} from "../context/post-turn-tool-result-truncation.js";
|
|
36
36
|
import { emitAssistantReplyNotification } from "../notifications/assistant-reply-producer.js";
|
|
37
|
+
import { emitBackgroundResultNotification } from "../notifications/background-result-producer.js";
|
|
37
38
|
import { projectAssistantMessage } from "../persistence/conversation-attention-store.js";
|
|
38
39
|
import {
|
|
39
40
|
type ConversationRow,
|
|
@@ -299,6 +300,8 @@ export async function runDeferredTurnTail(params: {
|
|
|
299
300
|
* notification producer's delivery-surface gates.
|
|
300
301
|
*/
|
|
301
302
|
replyDeliveredInAppOnly?: boolean;
|
|
303
|
+
/** Scheduled continuations keep their existing result-delivery owner. */
|
|
304
|
+
cronRunId?: string | null;
|
|
302
305
|
}): Promise<void> {
|
|
303
306
|
const {
|
|
304
307
|
conversationId,
|
|
@@ -364,6 +367,17 @@ export async function runDeferredTurnTail(params: {
|
|
|
364
367
|
conversation,
|
|
365
368
|
});
|
|
366
369
|
}
|
|
370
|
+
void emitBackgroundResultNotification({
|
|
371
|
+
conversationId,
|
|
372
|
+
assistantMessageId: turnCompleted
|
|
373
|
+
? (state.lastAssistantMessageId ?? undefined)
|
|
374
|
+
: undefined,
|
|
375
|
+
userMessageId,
|
|
376
|
+
recoverOnly: !turnCompleted,
|
|
377
|
+
cronRunId: params.cronRunId,
|
|
378
|
+
conversation,
|
|
379
|
+
rlog,
|
|
380
|
+
});
|
|
367
381
|
|
|
368
382
|
rlog.info(
|
|
369
383
|
{
|
|
@@ -118,6 +118,7 @@ import { getLogger } from "../util/logger.js";
|
|
|
118
118
|
import { withSqliteRetry } from "../util/sqlite-retry.js";
|
|
119
119
|
import type { WorkspaceGitService } from "../workspace/git-service.js";
|
|
120
120
|
import type { commitTurnChanges } from "../workspace/turn-commit.js";
|
|
121
|
+
import { trackDaemonActivity, turnActivityLabel } from "./activity-trail.js";
|
|
121
122
|
import type { AssistantAttachmentDraft } from "./assistant-attachments.js";
|
|
122
123
|
import { BrowserModeSessionProducer } from "./browser-mode-session.js";
|
|
123
124
|
import { ComputerUseModeSessionProducer } from "./computer-use-mode-session.js";
|
|
@@ -130,6 +131,7 @@ import type { HistoryConversationContext } from "./conversation-history.js";
|
|
|
130
131
|
import { undo as undoImpl } from "./conversation-history.js";
|
|
131
132
|
import {
|
|
132
133
|
abortConversation,
|
|
134
|
+
abortScheduledRun,
|
|
133
135
|
disposeConversation,
|
|
134
136
|
reinjectAttachmentPathAnnotations,
|
|
135
137
|
reinjectInterruptTurnNote,
|
|
@@ -154,8 +156,10 @@ import {
|
|
|
154
156
|
processMessage as processMessageImpl,
|
|
155
157
|
} from "./conversation-process.js";
|
|
156
158
|
import type {
|
|
159
|
+
QueuedDispatch,
|
|
157
160
|
QueuedMessage,
|
|
158
161
|
QueueDrainReason,
|
|
162
|
+
TurnWorkOrigin,
|
|
159
163
|
} from "./conversation-queue-manager.js";
|
|
160
164
|
import { MessageQueue } from "./conversation-queue-manager.js";
|
|
161
165
|
import {
|
|
@@ -576,6 +580,8 @@ export class Conversation {
|
|
|
576
580
|
* @internal
|
|
577
581
|
*/
|
|
578
582
|
currentCallSite?: LLMCallSite;
|
|
583
|
+
/** Skip fresh memory retrieval for this turn, retaining context already in history. */
|
|
584
|
+
currentTurnSkipMemoryRetrieval?: boolean;
|
|
579
585
|
/**
|
|
580
586
|
* Whether no human is present to see UI or answer prompts. Derived from the
|
|
581
587
|
* in-flight turn's interactivity ({@link currentTurnIsNonInteractive}); a
|
|
@@ -656,6 +662,8 @@ export class Conversation {
|
|
|
656
662
|
* @internal
|
|
657
663
|
*/
|
|
658
664
|
currentTurnCronRunId?: string | null;
|
|
665
|
+
currentTurnWorkOrigins?: readonly TurnWorkOrigin[];
|
|
666
|
+
pendingQueuedDispatches = new Map<string | null, Set<QueuedDispatch>>();
|
|
659
667
|
/** @internal */ currentTurnIsNonInteractive?: boolean;
|
|
660
668
|
/** @internal */ currentTurnModelProfileNoticeKey?: string;
|
|
661
669
|
/** @internal */ currentTurnRequestOrigin?: string;
|
|
@@ -2502,6 +2510,10 @@ export class Conversation {
|
|
|
2502
2510
|
abortConversation(this, reason);
|
|
2503
2511
|
}
|
|
2504
2512
|
|
|
2513
|
+
abortScheduledRun(runId: string): void {
|
|
2514
|
+
abortScheduledRun(this, runId);
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2505
2517
|
dispose(): void {
|
|
2506
2518
|
// Cancel all pending standalone surfaces so callers get a clean
|
|
2507
2519
|
// cancellation instead of hanging forever. Emit dismiss notifications
|
|
@@ -2603,6 +2615,7 @@ export class Conversation {
|
|
|
2603
2615
|
return (
|
|
2604
2616
|
this.isProcessing() ||
|
|
2605
2617
|
this.hasQueuedMessages() ||
|
|
2618
|
+
this.pendingQueuedDispatches.size > 0 ||
|
|
2606
2619
|
this.liveVoiceResidencyLeases > 0 ||
|
|
2607
2620
|
this.modeSessions.hasResidentWork() ||
|
|
2608
2621
|
getSubagentManager().hasActiveChildren(this.conversationId)
|
|
@@ -3515,6 +3528,8 @@ export class Conversation {
|
|
|
3515
3528
|
*/
|
|
3516
3529
|
replyDeliveredInAppOnly?: boolean;
|
|
3517
3530
|
callSite?: LLMCallSite;
|
|
3531
|
+
/** Skip fresh retrieval while keeping resident memory and static context. */
|
|
3532
|
+
skipMemoryRetrieval?: boolean;
|
|
3518
3533
|
/** Provider configuration source when distinct from turn semantics. */
|
|
3519
3534
|
inferenceCallSite?: LLMCallSite;
|
|
3520
3535
|
/**
|
|
@@ -3544,12 +3559,16 @@ export class Conversation {
|
|
|
3544
3559
|
},
|
|
3545
3560
|
): Promise<void> {
|
|
3546
3561
|
const { onEvent, ...rest } = options ?? {};
|
|
3547
|
-
return
|
|
3548
|
-
this,
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3562
|
+
return trackDaemonActivity(
|
|
3563
|
+
turnActivityLabel(this, options?.callSite, options?.isInteractive),
|
|
3564
|
+
() =>
|
|
3565
|
+
runAgentLoopImpl(
|
|
3566
|
+
this,
|
|
3567
|
+
content,
|
|
3568
|
+
userMessageId,
|
|
3569
|
+
onEvent ?? this.emit,
|
|
3570
|
+
rest,
|
|
3571
|
+
),
|
|
3553
3572
|
);
|
|
3554
3573
|
}
|
|
3555
3574
|
|
|
@@ -6,11 +6,112 @@
|
|
|
6
6
|
* a healthy loop never reports.
|
|
7
7
|
* - `start`/`stop` must be idempotent and safe to call in any order so daemon
|
|
8
8
|
* startup and the two shutdown paths can call them unconditionally.
|
|
9
|
+
* - `buildBlockTelemetryDetail` must never send conversation titles and must
|
|
10
|
+
* always fit the server's detail byte cap, since an oversize bag drops the
|
|
11
|
+
* whole report.
|
|
9
12
|
*/
|
|
10
13
|
import { describe, expect, test } from "bun:test";
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
import type { StallCapture } from "../monitoring/stall-capture.js";
|
|
16
|
+
import type { SectionTrailEntry } from "../persistence/slow-sync-log.js";
|
|
17
|
+
import type { DaemonActivityGroup } from "./activity-trail.js";
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
buildBlockTelemetryDetail,
|
|
21
|
+
detailFitsServerCap,
|
|
22
|
+
evaluateTick,
|
|
23
|
+
startEventLoopWatchdog,
|
|
24
|
+
stopEventLoopWatchdog,
|
|
25
|
+
} = await import("./event-loop-watchdog.js");
|
|
26
|
+
|
|
27
|
+
function captureWith(conversationCount: number): StallCapture {
|
|
28
|
+
return {
|
|
29
|
+
ts: 1,
|
|
30
|
+
daemonPid: 1,
|
|
31
|
+
heartbeatAgeMs: 21_000,
|
|
32
|
+
kernelStack: "[<0>] do_epoll_wait+0x4a0/0x4e0\n".repeat(12),
|
|
33
|
+
processState: "S",
|
|
34
|
+
waitState: {
|
|
35
|
+
syscall: 232,
|
|
36
|
+
epoll: {
|
|
37
|
+
fd: 7,
|
|
38
|
+
watched: 1,
|
|
39
|
+
listeningSockets: 0,
|
|
40
|
+
sockets: 0,
|
|
41
|
+
pipes: 1,
|
|
42
|
+
eventfds: 0,
|
|
43
|
+
timerfds: 0,
|
|
44
|
+
other: 0,
|
|
45
|
+
},
|
|
46
|
+
children: [{ pid: 200, comm: "git", state: "R", ageMs: 20_000 }],
|
|
47
|
+
threads: Array.from({ length: 8 }, (_, i) => ({
|
|
48
|
+
comm: `Bun Pool ${i}`,
|
|
49
|
+
state: "S",
|
|
50
|
+
wchan: "futex_wait_queue",
|
|
51
|
+
count: 1,
|
|
52
|
+
})),
|
|
53
|
+
},
|
|
54
|
+
sample: {
|
|
55
|
+
ts: 1,
|
|
56
|
+
memory: null,
|
|
57
|
+
memoryStat: null,
|
|
58
|
+
reclaim: null,
|
|
59
|
+
cpu: null,
|
|
60
|
+
events: null,
|
|
61
|
+
deltas: null,
|
|
62
|
+
disk: null,
|
|
63
|
+
processes: [
|
|
64
|
+
...Array.from({ length: 6 }, (_, i) => ({
|
|
65
|
+
pid: 100 + i,
|
|
66
|
+
name: i === 0 ? "memory-worker" : `chrome-${i}`,
|
|
67
|
+
cpuPct: 150 - i * 10,
|
|
68
|
+
rssMb: 800,
|
|
69
|
+
})),
|
|
70
|
+
{ pid: 1, name: "daemon", cpuPct: 4, rssMb: 900 },
|
|
71
|
+
],
|
|
72
|
+
activeConversations: Array.from(
|
|
73
|
+
{ length: conversationCount },
|
|
74
|
+
(_, i) => ({
|
|
75
|
+
conversationId: `01a0c9a0-0000-7000-8000-00000000000${i % 10}`,
|
|
76
|
+
title:
|
|
77
|
+
"A long title drawn from the user's own first message x".repeat(2),
|
|
78
|
+
originChannel: "vellum",
|
|
79
|
+
originInterface: "web",
|
|
80
|
+
processingStartedAt: 1,
|
|
81
|
+
}),
|
|
82
|
+
),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The report's maximum of 10 activity groups, longest (a user turn) first. */
|
|
88
|
+
const fullActivity: DaemonActivityGroup[] = [
|
|
89
|
+
{
|
|
90
|
+
kind: "turn",
|
|
91
|
+
conversationType: "standard",
|
|
92
|
+
callSite: "mainAgent",
|
|
93
|
+
turnInterface: "web",
|
|
94
|
+
interactive: true,
|
|
95
|
+
count: 1,
|
|
96
|
+
running: 1,
|
|
97
|
+
longestMs: 90_000,
|
|
98
|
+
},
|
|
99
|
+
...Array.from({ length: 9 }, (_, i) => ({
|
|
100
|
+
kind: "turn" as const,
|
|
101
|
+
conversationType: "background" as const,
|
|
102
|
+
callSite: "heartbeatAgent" as const,
|
|
103
|
+
interactive: false,
|
|
104
|
+
count: i + 1,
|
|
105
|
+
running: 0,
|
|
106
|
+
longestMs: 60_000 - i,
|
|
107
|
+
})),
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
const trail: SectionTrailEntry[] = Array.from({ length: 16 }, (_, i) => ({
|
|
111
|
+
label: "conversation-crud:get-messages",
|
|
112
|
+
startedAgoMs: 100_000 + i * 1_000,
|
|
113
|
+
endedAgoMs: 99_000 + i * 1_000,
|
|
114
|
+
}));
|
|
14
115
|
|
|
15
116
|
describe("evaluateTick", () => {
|
|
16
117
|
const INTERVAL = 1_000;
|
|
@@ -78,3 +179,101 @@ describe("start/stop lifecycle", () => {
|
|
|
78
179
|
expect(() => stopEventLoopWatchdog()).not.toThrow();
|
|
79
180
|
});
|
|
80
181
|
});
|
|
182
|
+
|
|
183
|
+
describe("buildBlockTelemetryDetail", () => {
|
|
184
|
+
test("never sends conversation titles", () => {
|
|
185
|
+
// GIVEN a capture whose active conversations carry titles
|
|
186
|
+
// WHEN the telemetry detail is built
|
|
187
|
+
const detail = buildBlockTelemetryDetail({
|
|
188
|
+
thresholdMs: 5_000,
|
|
189
|
+
daemonUptimeMs: 60_000,
|
|
190
|
+
activity: [],
|
|
191
|
+
sectionTrail: [],
|
|
192
|
+
stallCapture: captureWith(2),
|
|
193
|
+
});
|
|
194
|
+
// THEN every title is nulled but the rest of the entry is kept
|
|
195
|
+
const conversations = detail.stall_capture!.sample.activeConversations!;
|
|
196
|
+
expect(conversations).toHaveLength(2);
|
|
197
|
+
expect(conversations.every((c) => c.title === null)).toBe(true);
|
|
198
|
+
expect(conversations[0]!.originInterface).toBe("web");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("does not mutate the caller's capture", () => {
|
|
202
|
+
// GIVEN a capture the caller also logs locally
|
|
203
|
+
const capture = captureWith(2);
|
|
204
|
+
// WHEN the telemetry detail is built
|
|
205
|
+
buildBlockTelemetryDetail({
|
|
206
|
+
thresholdMs: 5_000,
|
|
207
|
+
daemonUptimeMs: 60_000,
|
|
208
|
+
activity: [],
|
|
209
|
+
sectionTrail: trail,
|
|
210
|
+
stallCapture: capture,
|
|
211
|
+
});
|
|
212
|
+
// THEN the local copy still has its titles
|
|
213
|
+
expect(capture.sample.activeConversations![0]!.title).not.toBeNull();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("a small report is sent untrimmed", () => {
|
|
217
|
+
// GIVEN a report well under the byte cap
|
|
218
|
+
// WHEN the telemetry detail is built
|
|
219
|
+
const detail = buildBlockTelemetryDetail({
|
|
220
|
+
thresholdMs: 5_000,
|
|
221
|
+
daemonUptimeMs: 60_000,
|
|
222
|
+
activity: [],
|
|
223
|
+
sectionTrail: trail.slice(0, 2),
|
|
224
|
+
stallCapture: captureWith(1),
|
|
225
|
+
});
|
|
226
|
+
// THEN nothing is trimmed and the wait state survives intact
|
|
227
|
+
expect(detail.trimmed).toBeUndefined();
|
|
228
|
+
expect(detail.stall_capture!.waitState!.threads).toHaveLength(8);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test("an oversize report is trimmed to fit, keeping the wait state", () => {
|
|
232
|
+
// GIVEN a full trail and many active conversations (the heavy-user case)
|
|
233
|
+
// WHEN the telemetry detail is built
|
|
234
|
+
const detail = buildBlockTelemetryDetail({
|
|
235
|
+
thresholdMs: 5_000,
|
|
236
|
+
daemonUptimeMs: 60_000,
|
|
237
|
+
activity: fullActivity,
|
|
238
|
+
sectionTrail: trail,
|
|
239
|
+
stallCapture: captureWith(20),
|
|
240
|
+
});
|
|
241
|
+
// THEN it fits the server cap, records what was trimmed, and still
|
|
242
|
+
// carries the attribution the report exists for
|
|
243
|
+
expect(detailFitsServerCap(detail)).toBe(true);
|
|
244
|
+
expect(detail.trimmed!.length).toBeGreaterThan(0);
|
|
245
|
+
expect(detail.stall_capture!.waitState!.epoll!.pipes).toBe(1);
|
|
246
|
+
expect(detail.stall_capture!.waitState!.children).toHaveLength(1);
|
|
247
|
+
expect(detail.activity.length).toBeGreaterThanOrEqual(4);
|
|
248
|
+
expect(
|
|
249
|
+
detail.stall_capture!.sample.processes!.length,
|
|
250
|
+
).toBeGreaterThanOrEqual(3);
|
|
251
|
+
expect(detail.stall_capture!.sample.processes![0]!.name).toBe(
|
|
252
|
+
"memory-worker",
|
|
253
|
+
);
|
|
254
|
+
// Trimming keeps the daemon for comparison.
|
|
255
|
+
expect(
|
|
256
|
+
detail.stall_capture!.sample.processes!.some((p) => p.name === "daemon"),
|
|
257
|
+
).toBe(true);
|
|
258
|
+
expect(detail.activity[0]).toMatchObject({
|
|
259
|
+
kind: "turn",
|
|
260
|
+
conversationType: "standard",
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe("detailFitsServerCap", () => {
|
|
266
|
+
test("ignores undefined keys, which serialization drops", () => {
|
|
267
|
+
// GIVEN a small detail with an undefined field
|
|
268
|
+
// WHEN it is checked against the server cap
|
|
269
|
+
// THEN the undefined key does not count as an invalid payload
|
|
270
|
+
expect(detailFitsServerCap({ a: 1, b: undefined })).toBe(true);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test("rejects a detail over the server cap", () => {
|
|
274
|
+
// GIVEN a detail larger than 4096 serialized bytes
|
|
275
|
+
// WHEN it is checked against the server cap
|
|
276
|
+
// THEN it does not fit
|
|
277
|
+
expect(detailFitsServerCap({ blob: "x".repeat(5_000) })).toBe(false);
|
|
278
|
+
});
|
|
279
|
+
});
|