@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
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
|
|
4
|
+
import { v4 as uuid } from "uuid";
|
|
5
|
+
|
|
4
6
|
import type { SkillSource } from "../../config/skills.js";
|
|
5
7
|
import { loadSkillCatalog } from "../../config/skills.js";
|
|
6
8
|
import { refreshSkillCapabilityMemories } from "../../daemon/skill-memory-refresh.js";
|
|
7
|
-
import { emitNotificationSignal } from "../../notifications/emit-signal.js";
|
|
8
9
|
import { sanitizeMultilineMessagePreview } from "../../notifications/notification-utils.js";
|
|
9
10
|
import { getConversation } from "../../persistence/conversation-crud.js";
|
|
10
11
|
import { upsertSkillCardInsertJob } from "../../persistence/jobs-store.js";
|
|
11
12
|
import { MEMORY_RETROSPECTIVE_ORIGIN } from "../../plugins/defaults/memory/memory-retrospective-constants.js";
|
|
13
|
+
import { recordSkillUpdate } from "../../plugins/defaults/memory/skill-update-receipt-job.js";
|
|
12
14
|
import { readInstallMeta } from "../../skills/install-meta.js";
|
|
13
15
|
import {
|
|
14
16
|
createManagedSkill,
|
|
@@ -90,78 +92,90 @@ function normalizeOptionalStringArray(
|
|
|
90
92
|
return { value: normalized };
|
|
91
93
|
}
|
|
92
94
|
|
|
95
|
+
/** Watchdog check_name counted when a receipt entry could not be recorded. */
|
|
96
|
+
const SKILL_UPDATE_RECEIPT_RECORD_FAILED_CHECK_NAME =
|
|
97
|
+
"skill_update_receipt_record_failed";
|
|
98
|
+
|
|
93
99
|
/**
|
|
94
|
-
*
|
|
100
|
+
* Record that a background pass changed a skill the user already has.
|
|
95
101
|
*
|
|
96
102
|
* A newly authored skill announces itself in the conversation through the
|
|
97
|
-
* `skill_card` surface; an update
|
|
98
|
-
* runs in a background fork and rewrites the body
|
|
99
|
-
* relying on, and `createManagedSkill` writes
|
|
100
|
-
* keeping no prior version, so the
|
|
101
|
-
* change in the background feed alongside the other unattended
|
|
102
|
-
* scheduled jobs, heartbeat), where a user already looks to
|
|
103
|
-
* assistant did on its own.
|
|
103
|
+
* `skill_card` surface; an update is announced through a skill-update
|
|
104
|
+
* receipt instead. The pass runs in a background fork and rewrites the body
|
|
105
|
+
* of a skill the user may be relying on, and `createManagedSkill` writes
|
|
106
|
+
* through an atomic rename keeping no prior version, so the receipt is what
|
|
107
|
+
* puts the change in the background feed alongside the other unattended
|
|
108
|
+
* work (sweeps, scheduled jobs, heartbeat), where a user already looks to
|
|
109
|
+
* see what the assistant did on its own. One pass can rewrite several skills
|
|
110
|
+
* within minutes, so the rewrites accumulate on one pending receipt job
|
|
111
|
+
* (`plugins/defaults/memory/skill-update-receipt-job.ts`), which announces
|
|
112
|
+
* the whole burst once it has settled rather than one notification per
|
|
113
|
+
* rewrite.
|
|
104
114
|
*
|
|
105
115
|
* `changeSummary` is the pass's own account of what it changed and is the
|
|
106
|
-
*
|
|
107
|
-
* reader triaging it there has no diff to look at, so
|
|
116
|
+
* entry's body: the receipt is the only place the change surfaces, and a
|
|
117
|
+
* reader triaging it there has no diff to look at, so an entry that only
|
|
108
118
|
* names the skill sends them into the skill to find out what happened. The
|
|
109
119
|
* executor refuses the overwrite without one, so this never runs without it.
|
|
110
120
|
*
|
|
111
|
-
* `
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* the
|
|
116
|
-
*
|
|
117
|
-
*
|
|
121
|
+
* `sourceConversationId` is the conversation the receipt's link resolves to
|
|
122
|
+
* for this entry (see `home-updates-list.tsx`): the source conversation when
|
|
123
|
+
* lineage resolved, else none. The run's own conversation is never used in
|
|
124
|
+
* its place: it is an ephemeral fork the next successful retrospective
|
|
125
|
+
* garbage-collects, and the receipt job leaves out any entry whose source
|
|
126
|
+
* is gone by the time it announces, so naming the fork would drop the
|
|
127
|
+
* entry rather than link it. `entryId` is the producing tool call's id, so a
|
|
128
|
+
* re-executed call records nothing new. A context with no tool call id (a
|
|
129
|
+
* direct caller) has no re-execution to guard against, so it gets a fresh
|
|
130
|
+
* id: a stable key on the run and skill would drop a second rewrite of the
|
|
131
|
+
* same skill in the same run.
|
|
132
|
+
*
|
|
133
|
+
* Best-effort and non-blocking: the skill is already written, and a receipt
|
|
134
|
+
* that cannot be recorded is a receipt the user will not get, not a reason
|
|
135
|
+
* to fail or retry a write that already landed. The failure is logged with
|
|
136
|
+
* the ids and counted, and the tool-invocation history keeps the summary as
|
|
137
|
+
* audit evidence.
|
|
118
138
|
*/
|
|
119
|
-
function
|
|
139
|
+
function recordBackgroundSkillUpdate(args: {
|
|
120
140
|
skillId: string;
|
|
121
141
|
name: string;
|
|
122
|
-
conversationId: string;
|
|
123
142
|
changeSummary: string;
|
|
143
|
+
runConversationId: string;
|
|
144
|
+
sourceConversationId: string | undefined;
|
|
145
|
+
toolUseId: string | undefined;
|
|
124
146
|
}): void {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// `fromAssistant` from it, so labelling this "scheduler" would drop the
|
|
130
|
-
// item from the feed's assistant-initiated filter despite being exactly
|
|
131
|
-
// that.
|
|
132
|
-
sourceChannel: "assistant_tool",
|
|
133
|
-
sourceContextId: args.conversationId,
|
|
134
|
-
sourceEventName: "activity.complete",
|
|
135
|
-
dedupeKey: `skill-updated:${args.skillId}:${day}`,
|
|
136
|
-
contextPayload: {
|
|
137
|
-
// `summary` feeds the copy composer and `title` is the headline both
|
|
138
|
-
// it and the home feed keep; `title`/`body` are also the feed's
|
|
139
|
-
// fallback when no channel copy was rendered. Without them a fully
|
|
140
|
-
// suppressed delivery (the intended shape for this signal: low urgency,
|
|
141
|
-
// background, no interruption) leaves the feed writer with no summary
|
|
142
|
-
// and it skips the item entirely, so the quiet case would surface
|
|
143
|
-
// nothing at all.
|
|
144
|
-
summary: args.changeSummary,
|
|
145
|
-
// Named, not just "Skill updated": the feed sits several rows deep and
|
|
146
|
-
// a generic title is unscannable next to entries that name their
|
|
147
|
-
// subject (`Background job failed: memory.v2.sweep`). The word "Skill"
|
|
148
|
-
// stays because a bare skill name does not always read as one.
|
|
149
|
-
title: `Skill updated: ${args.name}`,
|
|
150
|
-
body: args.changeSummary,
|
|
147
|
+
const entryId = `${args.runConversationId}:${args.toolUseId ?? uuid()}`;
|
|
148
|
+
try {
|
|
149
|
+
recordSkillUpdate({
|
|
150
|
+
entryId,
|
|
151
151
|
skillId: args.skillId,
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
}
|
|
152
|
+
name: args.name,
|
|
153
|
+
changeSummary: args.changeSummary,
|
|
154
|
+
runConversationId: args.runConversationId,
|
|
155
|
+
...(args.sourceConversationId
|
|
156
|
+
? { sourceConversationId: args.sourceConversationId }
|
|
157
|
+
: {}),
|
|
158
|
+
});
|
|
159
|
+
} catch (err) {
|
|
160
160
|
log.warn(
|
|
161
|
-
{
|
|
162
|
-
|
|
161
|
+
{
|
|
162
|
+
err,
|
|
163
|
+
skillId: args.skillId,
|
|
164
|
+
runConversationId: args.runConversationId,
|
|
165
|
+
entryId,
|
|
166
|
+
},
|
|
167
|
+
"skill update receipt recording failed; the skill write stands and no receipt will name this update",
|
|
163
168
|
);
|
|
164
|
-
|
|
169
|
+
try {
|
|
170
|
+
recordWatchdogEvent({
|
|
171
|
+
checkName: SKILL_UPDATE_RECEIPT_RECORD_FAILED_CHECK_NAME,
|
|
172
|
+
value: 1,
|
|
173
|
+
});
|
|
174
|
+
} catch {
|
|
175
|
+
// recordWatchdogEvent already no-ops on opt-out and a missing
|
|
176
|
+
// telemetry DB; anything past that is not worth surfacing here.
|
|
177
|
+
}
|
|
178
|
+
}
|
|
165
179
|
}
|
|
166
180
|
|
|
167
181
|
/**
|
|
@@ -333,10 +347,11 @@ export async function executeScaffoldManagedSkill(
|
|
|
333
347
|
category = input.category.trim().toLowerCase();
|
|
334
348
|
}
|
|
335
349
|
|
|
336
|
-
// The
|
|
350
|
+
// The receipt entry's body. Model-authored text bound for a notification
|
|
337
351
|
// surface, so it gets the same control-character strip and preview clamp as
|
|
338
352
|
// any other producer-supplied body; blank collapses to absent so the
|
|
339
|
-
// requirement below treats it as missing rather than
|
|
353
|
+
// requirement below treats it as missing rather than recording an empty
|
|
354
|
+
// entry.
|
|
340
355
|
let changeSummary: string | undefined;
|
|
341
356
|
if (input.change_summary !== undefined) {
|
|
342
357
|
if (typeof input.change_summary !== "string") {
|
|
@@ -404,9 +419,9 @@ export async function executeScaffoldManagedSkill(
|
|
|
404
419
|
}
|
|
405
420
|
}
|
|
406
421
|
|
|
407
|
-
// A background overwrite announces itself through the
|
|
408
|
-
//
|
|
409
|
-
// refused without one. The error returns to the pass in the same turn and
|
|
422
|
+
// A background overwrite announces itself through the receipt entry
|
|
423
|
+
// recorded in recordBackgroundSkillUpdate, whose body is this summary, so
|
|
424
|
+
// the write is refused without one. The error returns to the pass in the same turn and
|
|
410
425
|
// it retries with the field, the way a missing activation_hints does.
|
|
411
426
|
// Checked after the ownership backstop so a pass that may not touch the
|
|
412
427
|
// skill hears that first, and only for a call that asked to overwrite: a
|
|
@@ -500,23 +515,23 @@ export async function executeScaffoldManagedSkill(
|
|
|
500
515
|
}
|
|
501
516
|
|
|
502
517
|
// A background pass changed a skill that already existed. Creates announce
|
|
503
|
-
// themselves through the skill card below; updates
|
|
504
|
-
// the
|
|
505
|
-
// refinement as well as any other background write onto
|
|
506
|
-
// skill.
|
|
507
|
-
const notifyConversationId =
|
|
508
|
-
sourceConversationId ?? retrospectiveConversationId;
|
|
518
|
+
// themselves through the skill card below; updates land on the skill-update
|
|
519
|
+
// receipt that announces the whole burst. Covers an explicit
|
|
520
|
+
// `overwrite: true` refinement as well as any other background write onto
|
|
521
|
+
// a pre-existing skill.
|
|
509
522
|
if (
|
|
510
523
|
fromRetrospective &&
|
|
511
524
|
managedSkillExistedBefore &&
|
|
512
|
-
|
|
525
|
+
retrospectiveConversationId &&
|
|
513
526
|
changeSummary
|
|
514
527
|
) {
|
|
515
|
-
|
|
528
|
+
recordBackgroundSkillUpdate({
|
|
516
529
|
skillId: id,
|
|
517
530
|
name: normalizedName,
|
|
518
|
-
conversationId: notifyConversationId,
|
|
519
531
|
changeSummary,
|
|
532
|
+
runConversationId: retrospectiveConversationId,
|
|
533
|
+
sourceConversationId,
|
|
534
|
+
toolUseId: context.toolUseId,
|
|
520
535
|
});
|
|
521
536
|
}
|
|
522
537
|
|
|
@@ -6,6 +6,7 @@ import { join } from "node:path";
|
|
|
6
6
|
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
7
7
|
|
|
8
8
|
import { setConfig } from "../../__tests__/helpers/set-config.js";
|
|
9
|
+
import type { WakeOptions } from "../../runtime/agent-wake.js";
|
|
9
10
|
import { SHELL_DID_NOT_START_MESSAGE } from "../shared/shell-output.js";
|
|
10
11
|
import type { ToolContext } from "../types.js";
|
|
11
12
|
|
|
@@ -62,9 +63,13 @@ mock.module("../../runtime/assistant-event-hub.js", () => ({
|
|
|
62
63
|
}));
|
|
63
64
|
|
|
64
65
|
const realWake = await import("../../runtime/agent-wake.js");
|
|
66
|
+
const wakeCalls: WakeOptions[] = [];
|
|
65
67
|
mock.module("../../runtime/agent-wake.js", () => ({
|
|
66
68
|
...realWake,
|
|
67
|
-
wakeAgentForOpportunity: async () =>
|
|
69
|
+
wakeAgentForOpportunity: async (opts: WakeOptions) => {
|
|
70
|
+
wakeCalls.push(opts);
|
|
71
|
+
return {};
|
|
72
|
+
},
|
|
68
73
|
}));
|
|
69
74
|
|
|
70
75
|
const { shellTool } = await import("./shell.js");
|
|
@@ -108,6 +113,7 @@ describe("bash launch failures are not success", () => {
|
|
|
108
113
|
|
|
109
114
|
beforeEach(() => {
|
|
110
115
|
spawnCalls.length = 0;
|
|
116
|
+
wakeCalls.length = 0;
|
|
111
117
|
spawnImpl = originalSpawn as SpawnImpl;
|
|
112
118
|
workingDir = mkdtempSync(join(tmpdir(), "bash-launch-"));
|
|
113
119
|
});
|
|
@@ -159,4 +165,24 @@ describe("bash launch failures are not success", () => {
|
|
|
159
165
|
expect(result.content).not.toContain("<command_completed />");
|
|
160
166
|
expect(existsSync(join(workingDir, "help.txt"))).toBe(false);
|
|
161
167
|
});
|
|
168
|
+
|
|
169
|
+
for (const cronRunId of [undefined, null, "cron-run-123"]) {
|
|
170
|
+
test(`preserves originating schedule ${String(cronRunId)} on background spawn error`, async () => {
|
|
171
|
+
const child = fakeChild();
|
|
172
|
+
spawnImpl = () =>
|
|
173
|
+
child as unknown as ReturnType<typeof realChildProcess.spawn>;
|
|
174
|
+
const context = { ...makeContext(workingDir), cronRunId };
|
|
175
|
+
await shellTool.execute(
|
|
176
|
+
{ command: "echo hello", activity: "test", background: true },
|
|
177
|
+
context,
|
|
178
|
+
);
|
|
179
|
+
context.cronRunId = "cron-run-later";
|
|
180
|
+
child.emit("error", new Error("spawn ENOENT"));
|
|
181
|
+
child.emit("close", null, null);
|
|
182
|
+
|
|
183
|
+
expect(wakeCalls).toHaveLength(1);
|
|
184
|
+
expect(wakeCalls[0]!.cronRunId).toBe(cronRunId ?? undefined);
|
|
185
|
+
expect(wakeCalls[0]!.backgroundToolCompletion?.status).toBe("failed");
|
|
186
|
+
});
|
|
187
|
+
}
|
|
162
188
|
});
|
|
@@ -125,6 +125,7 @@ export const shellTool = {
|
|
|
125
125
|
input: Record<string, unknown>,
|
|
126
126
|
context: ToolContext,
|
|
127
127
|
): Promise<ToolExecutionResult> {
|
|
128
|
+
const cronRunId = context.cronRunId ?? undefined;
|
|
128
129
|
const parsed = shellInputSchema.safeParse(input);
|
|
129
130
|
if (!parsed.success) {
|
|
130
131
|
return invalidToolInputResult("bash", parsed.error);
|
|
@@ -410,6 +411,7 @@ export const shellTool = {
|
|
|
410
411
|
: `Background command completed (id=${bgId}, exit=${code ?? "unknown"}):`;
|
|
411
412
|
void wakeAgentForOpportunity({
|
|
412
413
|
conversationId: context.conversationId,
|
|
414
|
+
cronRunId,
|
|
413
415
|
hint: framing,
|
|
414
416
|
source: "background-tool",
|
|
415
417
|
persistTriggerAsEvent: true,
|
|
@@ -473,6 +475,7 @@ export const shellTool = {
|
|
|
473
475
|
};
|
|
474
476
|
void wakeAgentForOpportunity({
|
|
475
477
|
conversationId: context.conversationId,
|
|
478
|
+
cronRunId,
|
|
476
479
|
hint: framing,
|
|
477
480
|
source: "background-tool",
|
|
478
481
|
persistTriggerAsEvent: true,
|
|
@@ -496,6 +499,7 @@ export const shellTool = {
|
|
|
496
499
|
|
|
497
500
|
registerBackgroundTool({
|
|
498
501
|
id: bgId,
|
|
502
|
+
cronRunId,
|
|
499
503
|
toolName: "bash",
|
|
500
504
|
conversationId: context.conversationId,
|
|
501
505
|
command,
|
|
@@ -236,7 +236,7 @@ function selectLiveExtension(
|
|
|
236
236
|
* delete of the file unregisters the right tool.
|
|
237
237
|
*/
|
|
238
238
|
function applyWorkspaceToolDefaults(tool: ToolDefinition, name: string): Tool {
|
|
239
|
-
|
|
239
|
+
return finalizeTool(
|
|
240
240
|
{
|
|
241
241
|
...tool,
|
|
242
242
|
name,
|
|
@@ -253,7 +253,6 @@ function applyWorkspaceToolDefaults(tool: ToolDefinition, name: string): Tool {
|
|
|
253
253
|
},
|
|
254
254
|
name,
|
|
255
255
|
);
|
|
256
|
-
return finalized;
|
|
257
256
|
}
|
|
258
257
|
|
|
259
258
|
/**
|
package/src/usage/attribution.ts
CHANGED
|
@@ -10,11 +10,15 @@ import { safeStringSlice } from "../util/unicode.js";
|
|
|
10
10
|
|
|
11
11
|
const MAX_METADATA_VALUE_LENGTH = 128;
|
|
12
12
|
|
|
13
|
+
/** `profileSource` reported for a turn whose profile the Auto router chose. */
|
|
14
|
+
export const AUTO_PROFILE_SOURCE = "auto";
|
|
15
|
+
|
|
13
16
|
export type UsageAttributionProfileSource =
|
|
14
17
|
| "call_site"
|
|
15
18
|
| "conversation"
|
|
16
19
|
| "active"
|
|
17
20
|
| "default"
|
|
21
|
+
| typeof AUTO_PROFILE_SOURCE
|
|
18
22
|
| "unknown";
|
|
19
23
|
|
|
20
24
|
export interface UsageAttributionInput {
|
|
@@ -27,6 +31,12 @@ export interface UsageAttributionInput {
|
|
|
27
31
|
*/
|
|
28
32
|
profileResolutionCallSite?: LLMCallSite | null;
|
|
29
33
|
overrideProfile?: string | null;
|
|
34
|
+
/**
|
|
35
|
+
* Who chose `overrideProfile`. `"auto"` marks a profile the Auto profile's
|
|
36
|
+
* router picked for the turn, so usage rows can tell an Auto pick from a
|
|
37
|
+
* user pin that landed on the same profile. Absent for a user pin.
|
|
38
|
+
*/
|
|
39
|
+
overrideProfileOrigin?: "auto" | null;
|
|
30
40
|
/**
|
|
31
41
|
* Mirrors `ResolveCallSiteOpts.forceOverrideProfile`: the override profile
|
|
32
42
|
* was floated above the call-site layers for this request, so attribution
|
|
@@ -227,9 +237,16 @@ function appliedProfileFromWinnerSelection(
|
|
|
227
237
|
call_site: "call_site",
|
|
228
238
|
default: "default",
|
|
229
239
|
} as const;
|
|
240
|
+
// An override the Auto router chose is reported as its own source: the
|
|
241
|
+
// applied profile is the routed arm, so without this a routed turn would
|
|
242
|
+
// be indistinguishable from a user who pinned that arm.
|
|
243
|
+
const profileSource =
|
|
244
|
+
selection.source === "override" && input.overrideProfileOrigin === "auto"
|
|
245
|
+
? AUTO_PROFILE_SOURCE
|
|
246
|
+
: sourceBySelection[selection.source];
|
|
230
247
|
return {
|
|
231
248
|
appliedProfile: selection.profileName,
|
|
232
|
-
profileSource
|
|
249
|
+
profileSource,
|
|
233
250
|
};
|
|
234
251
|
}
|
|
235
252
|
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
export type AbortReasonKind =
|
|
13
|
+
/** A scheduled run exhausted its execution budget. */
|
|
14
|
+
| "schedule_timeout"
|
|
13
15
|
/** User explicitly hit Stop / Esc on the active conversation. */
|
|
14
16
|
| "user_cancel"
|
|
15
17
|
/** A new user message arrived for the same conversation, preempting the in-flight turn. */
|
package/src/util/errors.ts
CHANGED
|
@@ -53,6 +53,9 @@ describe("parseRequestBodyData", () => {
|
|
|
53
53
|
expect(parseRequestBodyData('{"a":1}', "multipart/related")).toBe(
|
|
54
54
|
'{"a":1}',
|
|
55
55
|
);
|
|
56
|
+
expect(
|
|
57
|
+
parseRequestBodyData("From: user@example.com\r\n\r\nHi", "message/rfc822"),
|
|
58
|
+
).toBe("From: user@example.com\r\n\r\nHi");
|
|
56
59
|
});
|
|
57
60
|
|
|
58
61
|
test("parses under a JSON Content-Type", () => {
|
|
@@ -82,7 +85,7 @@ describe("isBinaryOAuthContentType", () => {
|
|
|
82
85
|
expect(isBinaryOAuthContentType("image/png; charset=binary")).toBe(true);
|
|
83
86
|
});
|
|
84
87
|
|
|
85
|
-
test("rejects JSON, multipart, and
|
|
88
|
+
test("rejects JSON, multipart, form, and rfc822 types", () => {
|
|
86
89
|
expect(isBinaryOAuthContentType("application/json")).toBe(false);
|
|
87
90
|
expect(isBinaryOAuthContentType("multipart/related; boundary=b")).toBe(
|
|
88
91
|
false,
|
|
@@ -90,6 +93,7 @@ describe("isBinaryOAuthContentType", () => {
|
|
|
90
93
|
expect(isBinaryOAuthContentType("application/x-www-form-urlencoded")).toBe(
|
|
91
94
|
false,
|
|
92
95
|
);
|
|
96
|
+
expect(isBinaryOAuthContentType("message/rfc822")).toBe(false);
|
|
93
97
|
expect(isBinaryOAuthContentType(undefined)).toBe(false);
|
|
94
98
|
});
|
|
95
99
|
});
|
|
@@ -99,3 +99,14 @@ export const INSUFFICIENT_CREDITS_PATTERNS = [
|
|
|
99
99
|
// credit-exhaustion prose above — both are 402s from the same proxy — so
|
|
100
100
|
// classification sites must test this before INSUFFICIENT_CREDITS_PATTERNS.
|
|
101
101
|
export const DAILY_LIMIT_PATTERNS = [/"code"\s*:\s*"daily_limit_reached"/i];
|
|
102
|
+
|
|
103
|
+
// Managed-proxy free-tier daily usage-credit cap: a 402 whose body carries
|
|
104
|
+
// `"code": "free_tier_daily_limit_reached"`. The platform imposes it on a
|
|
105
|
+
// cohort of free-tier orgs (it is not the user-configured daily limit above,
|
|
106
|
+
// which caps purchased spend), so it gets its own reason and copy: there is
|
|
107
|
+
// no limit for the user to raise, only the UTC reset, an upgrade, or extra
|
|
108
|
+
// credits. Anchored on the opening quote so DAILY_LIMIT_PATTERNS, which is
|
|
109
|
+
// anchored the same way, never matches this code as its suffix.
|
|
110
|
+
export const FREE_TIER_DAILY_LIMIT_PATTERNS = [
|
|
111
|
+
/"code"\s*:\s*"free_tier_daily_limit_reached"/i,
|
|
112
|
+
];
|
|
@@ -31,6 +31,9 @@ describe("createKeyedSingleFlight", () => {
|
|
|
31
31
|
return "b";
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
+
expect(run.isPending("k")).toBe(true);
|
|
35
|
+
expect(run.isPending("other")).toBe(false);
|
|
36
|
+
|
|
34
37
|
// B must not start until A finishes.
|
|
35
38
|
await tick();
|
|
36
39
|
expect(order).toEqual(["a:start"]);
|
|
@@ -39,6 +42,7 @@ describe("createKeyedSingleFlight", () => {
|
|
|
39
42
|
await expect(a).resolves.toBe("a");
|
|
40
43
|
await expect(b).resolves.toBe("b");
|
|
41
44
|
expect(order).toEqual(["a:start", "a:end", "b:start"]);
|
|
45
|
+
expect(run.isPending("k")).toBe(false);
|
|
42
46
|
});
|
|
43
47
|
|
|
44
48
|
test("does not serialize across different keys", async () => {
|
|
@@ -69,6 +73,7 @@ describe("createKeyedSingleFlight", () => {
|
|
|
69
73
|
throw new Error("boom");
|
|
70
74
|
}),
|
|
71
75
|
).rejects.toThrow("boom");
|
|
76
|
+
expect(run.isPending("k")).toBe(false);
|
|
72
77
|
await expect(run("k", async () => "ok")).resolves.toBe("ok");
|
|
73
78
|
});
|
|
74
79
|
|
|
@@ -80,6 +85,7 @@ describe("createKeyedSingleFlight", () => {
|
|
|
80
85
|
await tick();
|
|
81
86
|
|
|
82
87
|
run.reset();
|
|
88
|
+
expect(run.isPending("k")).toBe(false);
|
|
83
89
|
|
|
84
90
|
// After reset, a fresh call for the same key does not wait on the
|
|
85
91
|
// abandoned one.
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export interface KeyedSingleFlight {
|
|
15
15
|
<T>(key: string, fn: () => Promise<T>): Promise<T>;
|
|
16
|
+
isPending(key: string): boolean;
|
|
16
17
|
/**
|
|
17
18
|
* Drop all chain entries. Test-only escape hatch for a clean slate between
|
|
18
19
|
* cases; production code never needs it because entries self-clear once
|
|
@@ -52,6 +53,7 @@ export function createKeyedSingleFlight(): KeyedSingleFlight {
|
|
|
52
53
|
run.reset = (): void => {
|
|
53
54
|
chain.clear();
|
|
54
55
|
};
|
|
56
|
+
run.isPending = (key: string): boolean => chain.has(key);
|
|
55
57
|
|
|
56
58
|
return run;
|
|
57
59
|
}
|
|
@@ -32,21 +32,67 @@ function spawnBusyWorker() {
|
|
|
32
32
|
|
|
33
33
|
describe("writeWorkerLine", () => {
|
|
34
34
|
/**
|
|
35
|
-
* The
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
35
|
+
* The contract this module rests on, against the real Bun API: a payload
|
|
36
|
+
* that outruns the pipe buffer comes back as a `Promise`, and killing the
|
|
37
|
+
* worker settles it. Which way it settles is Bun's to choose. It rejects
|
|
38
|
+
* with EPIPE on nearly every kill and, rarely on Linux, resolves with a
|
|
39
|
+
* short count instead, so this asserts only that nothing escapes either
|
|
40
|
+
* way. Demanding the rejection is what made this case flaky on CI.
|
|
39
41
|
*/
|
|
40
|
-
test("
|
|
42
|
+
test("observes a real pending write however Bun settles it", async () => {
|
|
41
43
|
const proc = spawnBusyWorker();
|
|
42
|
-
const
|
|
44
|
+
const failures: unknown[] = [];
|
|
45
|
+
const settling: Promise<number>[] = [];
|
|
46
|
+
const record = (result: number | Promise<number>) => {
|
|
47
|
+
if (result instanceof Promise) {
|
|
48
|
+
settling.push(result);
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
43
52
|
|
|
44
|
-
writeWorkerLine(
|
|
53
|
+
writeWorkerLine(
|
|
54
|
+
{
|
|
55
|
+
write: (chunk) => record(proc.stdin.write(chunk)),
|
|
56
|
+
flush: () => record(proc.stdin.flush()),
|
|
57
|
+
},
|
|
58
|
+
OVERSIZED_LINE,
|
|
59
|
+
(err) => failures.push(err),
|
|
60
|
+
);
|
|
45
61
|
proc.kill("SIGKILL");
|
|
62
|
+
const outcomes = await Promise.race([
|
|
63
|
+
Promise.allSettled(settling),
|
|
64
|
+
Bun.sleep(10_000).then(() => null),
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
expect(settling.length).toBeGreaterThan(0);
|
|
68
|
+
expect(outcomes).not.toBeNull();
|
|
69
|
+
expect(failures).toHaveLength(
|
|
70
|
+
outcomes!.some((o) => o.status === "rejected") ? 1 : 0,
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The production failure: the payload outruns the pipe buffer, Bun hands
|
|
76
|
+
* `write` and `flush` one pending promise, and the worker dies before
|
|
77
|
+
* draining it. Bun rejects that promise from its own event loop, after this
|
|
78
|
+
* call has returned. Unobserved, the rejection is an `unhandledRejection`,
|
|
79
|
+
* which `bun test` reports as a failure of this test.
|
|
80
|
+
*/
|
|
81
|
+
test("reports a write still pending when the worker dies", async () => {
|
|
82
|
+
const failure = Promise.withResolvers<unknown>();
|
|
83
|
+
const epipe = Object.assign(new Error("EPIPE: broken pipe, write"), {
|
|
84
|
+
code: "EPIPE",
|
|
85
|
+
});
|
|
86
|
+
const pending = Promise.withResolvers<number>();
|
|
87
|
+
const stdin = {
|
|
88
|
+
write: () => pending.promise,
|
|
89
|
+
flush: () => pending.promise,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
writeWorkerLine(stdin, "line", failure.resolve);
|
|
93
|
+
pending.reject(epipe);
|
|
46
94
|
|
|
47
|
-
|
|
48
|
-
expect(err).toBeInstanceOf(Error);
|
|
49
|
-
expect((err as NodeJS.ErrnoException).code).toBe("EPIPE");
|
|
95
|
+
expect(await failure.promise).toBe(epipe);
|
|
50
96
|
});
|
|
51
97
|
|
|
52
98
|
test("reports a synchronous throw", () => {
|
package/src/util/worker-pipe.ts
CHANGED
|
@@ -8,10 +8,15 @@ import type { FileSink } from "bun";
|
|
|
8
8
|
* While the pipe has room they complete synchronously. Once a payload outruns
|
|
9
9
|
* the pipe buffer, which is what happens when the worker is busy and not
|
|
10
10
|
* draining stdin, they return a pending promise instead, and that promise
|
|
11
|
-
* rejects with EPIPE
|
|
12
|
-
* `try/catch` sees only the synchronous half: the
|
|
13
|
-
* the process's `unhandledRejection` handler,
|
|
14
|
-
* shuts the whole process down.
|
|
11
|
+
* rejects with EPIPE once the worker dies, from Bun's event loop, after this
|
|
12
|
+
* call has returned. A `try/catch` sees only the synchronous half: the
|
|
13
|
+
* rejection escapes it, reaches the process's `unhandledRejection` handler,
|
|
14
|
+
* and in the daemon that handler shuts the whole process down.
|
|
15
|
+
*
|
|
16
|
+
* On Linux, Bun occasionally treats a zero-byte write to the dead worker's
|
|
17
|
+
* pipe as end-of-file and resolves that promise with the bytes written so
|
|
18
|
+
* far instead. `onFailure` then never runs, and the caller learns of the
|
|
19
|
+
* death only when the worker's stdout ends.
|
|
15
20
|
*
|
|
16
21
|
* `onFailure` runs at most once per call, even though `write` and `flush` can
|
|
17
22
|
* each report the same broken pipe.
|
|
@@ -12,6 +12,7 @@ import { join } from "node:path";
|
|
|
12
12
|
import { promisify } from "node:util";
|
|
13
13
|
|
|
14
14
|
import { getConfig } from "../config/loader.js";
|
|
15
|
+
import { trackDaemonActivity } from "../daemon/activity-trail.js";
|
|
15
16
|
import { isFileUnheld } from "../util/file-use.js";
|
|
16
17
|
import { getLogger } from "../util/logger.js";
|
|
17
18
|
import { Mutex } from "../util/mutex.js";
|
|
@@ -1049,7 +1050,11 @@ export class WorkspaceGitService {
|
|
|
1049
1050
|
retryAfterMs?: number;
|
|
1050
1051
|
}> {
|
|
1051
1052
|
await this.ensureInitialized();
|
|
1052
|
-
return this.mutex.withLock(() =>
|
|
1053
|
+
return this.mutex.withLock(() =>
|
|
1054
|
+
trackDaemonActivity({ kind: "git_compaction" }, () =>
|
|
1055
|
+
this.compactHistoryLocked(options),
|
|
1056
|
+
),
|
|
1057
|
+
);
|
|
1053
1058
|
}
|
|
1054
1059
|
|
|
1055
1060
|
/**
|