evolcore 0.0.43-test.6 → 0.0.43-test.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +95 -0
- package/bin/ecmsg.js +188 -58
- package/dist/agent-template/jobs.js +62 -0
- package/dist/agent-template/runtime.js +214 -0
- package/dist/agent-template/service.js +465 -0
- package/dist/agent-template/tool-runner.js +45 -0
- package/dist/agent-template/types.js +5 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/claude-runner.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/aid/agentmd.js +56 -1
- package/dist/aun/aid/client.js +3 -1
- package/dist/aun/menu/client.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +277 -49
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +7 -3
- package/dist/cli/agent-template.js +124 -0
- package/dist/cli/aun-commands.js +2 -2
- package/dist/cli/ctl-command.js +2 -1
- package/dist/cli/daemon-commands.js +11 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +109 -0
- package/dist/cli/index.js +60 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/net-check.js +1 -1
- package/dist/cli/restart-monitor.js +160 -83
- package/dist/cli/services-command.js +137 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +103 -13
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +8 -8
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +45 -15
- package/dist/config-store.js +2 -1
- package/dist/core/agent-ipc-registration.js +25 -4
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +106 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-authorizer.js +2 -0
- package/dist/core/auth/operation-catalog.js +29 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +20 -12
- package/dist/core/command/agent-control.js +12 -2
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/agent-template-menu.js +147 -0
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +80 -17
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +468 -0
- package/dist/core/command/menu-catalog.js +15 -0
- package/dist/core/command/menu-handler.js +216 -90
- package/dist/core/command/menu-protocol.js +71 -13
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +22 -5
- package/dist/core/daemon-lifecycle.js +323 -191
- package/dist/core/handoff/runtime.js +45 -13
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +50 -7
- package/dist/core/legacy-rename.js +41 -0
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +252 -17
- package/dist/core/message/im-renderer.js +116 -85
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-queue.js +66 -15
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +29 -5
- package/dist/core/message/response-engine.js +194 -61
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +50 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/pack-auth.js +94 -0
- package/dist/core/pack-install.js +194 -0
- package/dist/core/permission/ec-command-parser.js +51 -17
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/rate-window.js +48 -0
- package/dist/core/relation/peer-identity.js +28 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +67 -28
- package/dist/core/session/session-idle-monitor.js +59 -19
- package/dist/core/session/session-manager.js +13 -4
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/core/thread/thread-service.js +52 -3
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/eck/message-renderer.js +2 -0
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +124 -0
- package/dist/event-center/bus-gate.js +154 -0
- package/dist/event-center/bus-host.js +307 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +127 -0
- package/dist/event-center/daemon.js +44 -0
- package/dist/event-center/directory-source.js +55 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +73 -0
- package/dist/event-center/ipc-operation.js +423 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +207 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +463 -0
- package/dist/event-center/runtime.js +837 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +51 -0
- package/dist/event-center/validation.js +435 -0
- package/dist/index.js +424 -135
- package/dist/ipc.js +106 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/engines/v1/proactive-flow.js +4 -2
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +550 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +215 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +98 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/scheduler.js +38 -0
- package/dist/trigger/script-sandbox.js +170 -24
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +6 -3
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +9 -15
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +3 -1
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/agent.md +22 -1
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +227 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +5 -3
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +28 -1
- package/kits/docs/evolcore/msg.md +21 -9
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +294 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/docs/evolcore/thread-chain.md +15 -3
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +1 -0
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-group/SKILL.md +5 -8
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +1 -5
- package/kits/templates/system-fragments/thread.md +13 -10
- package/package.json +5 -6
- package/scripts/agent-template/index.mjs +40 -0
- package/scripts/agent-template/inspect.mjs +240 -0
- package/scripts/agent-template/overlay.mjs +71 -0
- package/scripts/agent-template/pack.mjs +169 -0
- package/scripts/agent-template/shared/common.mjs +235 -0
- package/scripts/agent-template/shared/evolcore.mjs +75 -0
- package/scripts/agent-template/shared/plan.mjs +129 -0
- package/scripts/agent-template/shared/team-schema.json +70 -0
- package/scripts/agent-template/shared/template-contract.mjs +154 -0
- package/scripts/agent-template/shared/template-package.mjs +265 -0
- package/scripts/agent-template/shared/template-runtime.mjs +80 -0
- package/scripts/agent-template/shared/template.mjs +142 -0
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -7,11 +7,12 @@ import { disposeAgentInstances } from './runner-reload-transaction.js';
|
|
|
7
7
|
import { sessionTopicThreadId } from './thread/topic-id.js';
|
|
8
8
|
import { StartupTracer } from '../utils/startup-trace.js';
|
|
9
9
|
import { OFFLINE_TOTAL_BUDGET_MS } from './lifecycle-notice.js';
|
|
10
|
-
import { monitorEventLoopDelay, performance } from 'node:perf_hooks';
|
|
11
10
|
import { setImmediate as yieldToIo } from 'node:timers/promises';
|
|
11
|
+
import { performance, monitorEventLoopDelay } from 'node:perf_hooks';
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import { agentTriggersDir } from '../paths.js';
|
|
14
14
|
import { readLastJsonlLineAsync, scanAgentChatDirsAsync } from './session/session-fs-store.js';
|
|
15
|
+
import { pendingHintDirectoryVersion } from './message/pending-hints.js';
|
|
15
16
|
import { fileToSession } from './session/session-mapper.js';
|
|
16
17
|
import { HandoffStore } from './handoff/store.js';
|
|
17
18
|
export class StartupGate {
|
|
@@ -60,17 +61,36 @@ async function json(file) {
|
|
|
60
61
|
throw error;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
64
|
+
/** Reuse freed scan capacity, and settle in-flight readers before publishing classification. */
|
|
65
|
+
async function scanStartupItems(items, concurrency, visit) {
|
|
66
|
+
let next = 0;
|
|
67
|
+
const results = await Promise.allSettled(Array.from({ length: Math.min(concurrency, items.length) }, async () => {
|
|
68
|
+
while (next < items.length)
|
|
69
|
+
await visit(items[next++]);
|
|
70
|
+
}));
|
|
71
|
+
for (const result of results)
|
|
72
|
+
if (result.status === 'rejected')
|
|
73
|
+
throw result.reason;
|
|
74
|
+
}
|
|
63
75
|
export async function discoverStartupWork(options) {
|
|
64
76
|
const plan = {
|
|
65
77
|
priorityAids: new Set(), triggerAids: new Set(), requiredChannelKeys: new Set(),
|
|
66
78
|
requiredExternalAids: new Set(), pendingSessions: [], staleSessions: [], sessionScanFailed: false,
|
|
67
|
-
|
|
79
|
+
hintDirectories: new Map(),
|
|
68
80
|
};
|
|
69
81
|
const known = new Set(options.agentAids);
|
|
82
|
+
const prioritized = new Set();
|
|
83
|
+
const prioritize = (aid, reason) => {
|
|
84
|
+
plan.priorityAids.add(aid);
|
|
85
|
+
if (!known.has(aid) || prioritized.has(aid))
|
|
86
|
+
return;
|
|
87
|
+
prioritized.add(aid);
|
|
88
|
+
options.onAgentPrioritized?.(aid, reason);
|
|
89
|
+
};
|
|
70
90
|
const uncertain = (aid, error) => {
|
|
71
91
|
if (known.has(aid)) {
|
|
72
|
-
plan.priorityAids.add(aid);
|
|
73
92
|
plan.requiredExternalAids.add(aid);
|
|
93
|
+
prioritize(aid, 'uncertain');
|
|
74
94
|
}
|
|
75
95
|
logger.warn(`[startup] Work classification uncertain for ${aid}; prioritizing recovery: ${error}`);
|
|
76
96
|
};
|
|
@@ -82,15 +102,19 @@ export async function discoverStartupWork(options) {
|
|
|
82
102
|
uncertain(candidate, 'unresolved persisted input owner');
|
|
83
103
|
return;
|
|
84
104
|
}
|
|
85
|
-
|
|
105
|
+
prioritize(aid, 'queue');
|
|
86
106
|
if (message?.channel)
|
|
87
107
|
plan.requiredChannelKeys.add(message.channel);
|
|
88
108
|
else
|
|
89
109
|
plan.requiredExternalAids.add(aid);
|
|
90
110
|
};
|
|
111
|
+
const queueStarted = Date.now();
|
|
112
|
+
let queueItems = 0;
|
|
113
|
+
let queueFiles = 0;
|
|
91
114
|
try {
|
|
92
115
|
const queue = await json(options.queuePath);
|
|
93
116
|
if (queue !== undefined) {
|
|
117
|
+
queueFiles = 1;
|
|
94
118
|
if (!queue || ![1, 2].includes(queue.version) || !Array.isArray(queue.queues)
|
|
95
119
|
|| (queue.active !== undefined && !Array.isArray(queue.active)))
|
|
96
120
|
throw new Error('invalid queue snapshot');
|
|
@@ -98,6 +122,7 @@ export async function discoverStartupWork(options) {
|
|
|
98
122
|
if (!Array.isArray(bucket.items))
|
|
99
123
|
throw new Error('invalid queue bucket');
|
|
100
124
|
for (const item of bucket.items) {
|
|
125
|
+
queueItems++;
|
|
101
126
|
noteMessage(item.message, bucket.queueKey);
|
|
102
127
|
for (const part of item.parts ?? [])
|
|
103
128
|
noteMessage(part.message, bucket.queueKey);
|
|
@@ -110,101 +135,172 @@ export async function discoverStartupWork(options) {
|
|
|
110
135
|
uncertain(aid, error);
|
|
111
136
|
}
|
|
112
137
|
finally {
|
|
138
|
+
options.onScan?.({ phase: 'queue', durationMs: Date.now() - queueStarted, files: queueFiles, items: queueItems });
|
|
113
139
|
options.onQueueCaptured?.();
|
|
114
140
|
}
|
|
115
141
|
const now = Date.now();
|
|
116
142
|
const triggerDir = options.triggerDir ?? agentTriggersDir;
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
plan.priorityAids.add(aid);
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
uncertain(aid, error);
|
|
143
|
+
const scanTriggers = async (aid) => {
|
|
144
|
+
const started = Date.now();
|
|
145
|
+
let files = 0;
|
|
146
|
+
try {
|
|
147
|
+
for (const id of await directories(triggerDir(aid))) {
|
|
148
|
+
files++;
|
|
149
|
+
const active = await json(path.join(triggerDir(aid), id, 'active.json'));
|
|
150
|
+
if (active === undefined)
|
|
151
|
+
continue;
|
|
152
|
+
if (!active || typeof active.runs !== 'object' || !active.runs || Array.isArray(active.runs)) {
|
|
153
|
+
throw new Error(`invalid Trigger active state: ${id}`);
|
|
132
154
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
if (error.code === 'ENOENT')
|
|
142
|
-
continue;
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
const files = names.filter(name => /^meta_.*\.jsonl$/.test(name));
|
|
146
|
-
for (let offset = 0; offset < files.length; offset += 8) {
|
|
147
|
-
await Promise.all(files.slice(offset, offset + 8).map(async (name) => {
|
|
148
|
-
const data = await readLastJsonlLineAsync(path.join(metaDir, name), path.basename(metaDir) === '_threads');
|
|
149
|
-
if (!data)
|
|
150
|
-
return;
|
|
151
|
-
const session = fileToSession(data);
|
|
152
|
-
if (!session.processingState)
|
|
153
|
-
return;
|
|
154
|
-
const startedAt = Number.parseInt(session.processingState.split(':', 1)[0], 10);
|
|
155
|
-
if (Number.isFinite(startedAt) && now - startedAt < 3_600_000) {
|
|
156
|
-
plan.pendingSessions.push(session);
|
|
157
|
-
plan.priorityAids.add(aid);
|
|
158
|
-
plan.requiredChannelKeys.add(session.channel);
|
|
159
|
-
}
|
|
160
|
-
else
|
|
161
|
-
plan.staleSessions.push(session);
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
}
|
|
155
|
+
if (Object.keys(active.runs).length) {
|
|
156
|
+
plan.triggerAids.add(aid);
|
|
157
|
+
const definition = await json(path.join(triggerDir(aid), id, 'trigger.json'));
|
|
158
|
+
if (!definition) {
|
|
159
|
+
plan.requiredExternalAids.add(aid);
|
|
160
|
+
continue;
|
|
165
161
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
162
|
+
for (const key of [definition.origin?.channelKey, definition.feedback?.target?.channelKey,
|
|
163
|
+
...Object.values(active.runs).map((run) => run?.source?.payload?.channelKey ?? run?.source?.payload?.channel)]) {
|
|
164
|
+
if (typeof key === 'string')
|
|
165
|
+
plan.requiredChannelKeys.add(key);
|
|
166
|
+
}
|
|
167
|
+
if (definition.feedback?.strategy === 'event_session')
|
|
168
|
+
plan.requiredExternalAids.add(aid);
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
plan.triggerAids.add(aid);
|
|
174
|
+
uncertain(aid, error);
|
|
175
|
+
}
|
|
176
|
+
if (plan.triggerAids.has(aid)) {
|
|
177
|
+
const owner = aid === options.daemonTriggerAid ? options.primaryAid : aid;
|
|
178
|
+
if (owner)
|
|
179
|
+
prioritize(owner, 'triggers');
|
|
180
|
+
}
|
|
181
|
+
options.onScan?.({ phase: 'triggers', aid, durationMs: Date.now() - started, files });
|
|
182
|
+
};
|
|
183
|
+
// A daemon-owned run can make the primary Agent busy. Finish that decision
|
|
184
|
+
// before publishing its classification, without delaying other Agents.
|
|
185
|
+
const daemonTriggerScan = scanTriggers(options.daemonTriggerAid);
|
|
186
|
+
const aids = [...known];
|
|
187
|
+
let next = 0;
|
|
188
|
+
const loopDelay = monitorEventLoopDelay({ resolution: 20 });
|
|
189
|
+
const loopStart = performance.eventLoopUtilization();
|
|
190
|
+
loopDelay.enable();
|
|
191
|
+
try {
|
|
192
|
+
await Promise.all([daemonTriggerScan, ...Array.from({ length: Math.min(4, aids.length) }, async () => {
|
|
193
|
+
while (next < aids.length) {
|
|
194
|
+
const aid = aids[next++];
|
|
195
|
+
const started = Date.now();
|
|
196
|
+
let files = 0;
|
|
197
|
+
let chats = 0;
|
|
198
|
+
let directoryMs = 0;
|
|
199
|
+
let threadDirectoryMs = 0;
|
|
200
|
+
let metadataMs = 0;
|
|
201
|
+
let readMaxMs = 0;
|
|
202
|
+
const io = { openMs: 0, statMs: 0, readMs: 0, parseMs: 0, closeMs: 0, bytes: 0 };
|
|
203
|
+
try {
|
|
204
|
+
const hintVersion = pendingHintDirectoryVersion();
|
|
205
|
+
let phaseStarted = performance.now();
|
|
206
|
+
let chatDirs;
|
|
207
|
+
try {
|
|
208
|
+
chatDirs = await scanAgentChatDirsAsync(options.sessionsRoot, aid, undefined, { includeEntries: true });
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
directoryMs = Math.round(performance.now() - phaseStarted);
|
|
212
|
+
}
|
|
213
|
+
chats = chatDirs.length;
|
|
214
|
+
// Keep paths only; retries read current hint events. A new hint chat
|
|
215
|
+
// invalidates this inventory even when created while discovery runs.
|
|
216
|
+
if (hintVersion === pendingHintDirectoryVersion())
|
|
217
|
+
plan.hintDirectories.set(aid, {
|
|
218
|
+
sessionsDir: options.sessionsRoot, selfAID: aid, version: hintVersion,
|
|
219
|
+
chats: chatDirs.map(({ entries: _entries, ...chat }) => chat),
|
|
220
|
+
});
|
|
221
|
+
const metadata = [];
|
|
222
|
+
const collect = (dir, names, strict) => {
|
|
223
|
+
for (const name of names)
|
|
224
|
+
if (/^meta_.*\.jsonl$/.test(name)) {
|
|
225
|
+
metadata.push({ file: path.join(dir, name), strict });
|
|
226
|
+
files++;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
for (const chat of chatDirs)
|
|
230
|
+
collect(chat.dirPath, chat.entries.map(entry => entry.name), false);
|
|
231
|
+
phaseStarted = performance.now();
|
|
232
|
+
try {
|
|
233
|
+
await scanStartupItems(chatDirs.filter(chat => chat.entries.some(entry => entry.name === '_threads')), 8, async (chat) => {
|
|
234
|
+
const dir = path.join(chat.dirPath, '_threads');
|
|
235
|
+
try {
|
|
236
|
+
collect(dir, await fs.promises.readdir(dir), true);
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
if (error.code !== 'ENOENT')
|
|
240
|
+
throw error;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
186
243
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (typeof key === 'string')
|
|
190
|
-
plan.requiredChannelKeys.add(key);
|
|
244
|
+
finally {
|
|
245
|
+
threadDirectoryMs = Math.round(performance.now() - phaseStarted);
|
|
191
246
|
}
|
|
192
|
-
|
|
193
|
-
|
|
247
|
+
// The eight-reader budget spans all chats of this Agent. A slow file
|
|
248
|
+
// must not serialize the next chat or a complete batch of eight files.
|
|
249
|
+
phaseStarted = performance.now();
|
|
250
|
+
try {
|
|
251
|
+
await scanStartupItems(metadata, 8, async ({ file, strict }) => {
|
|
252
|
+
const readStarted = performance.now();
|
|
253
|
+
let record;
|
|
254
|
+
try {
|
|
255
|
+
record = await readLastJsonlLineAsync(file, strict, io);
|
|
256
|
+
}
|
|
257
|
+
finally {
|
|
258
|
+
readMaxMs = Math.max(readMaxMs, Math.round(performance.now() - readStarted));
|
|
259
|
+
}
|
|
260
|
+
if (!record)
|
|
261
|
+
return;
|
|
262
|
+
const session = fileToSession(record);
|
|
263
|
+
if (!session.processingState)
|
|
264
|
+
return;
|
|
265
|
+
const startedAt = Number.parseInt(session.processingState.split(':', 1)[0], 10);
|
|
266
|
+
if (Number.isFinite(startedAt) && now - startedAt < 3_600_000) {
|
|
267
|
+
plan.pendingSessions.push(session);
|
|
268
|
+
prioritize(aid, 'sessions');
|
|
269
|
+
plan.requiredChannelKeys.add(session.channel);
|
|
270
|
+
}
|
|
271
|
+
else
|
|
272
|
+
plan.staleSessions.push(session);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
metadataMs = Math.round(performance.now() - phaseStarted);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
plan.hintDirectories.delete(aid);
|
|
281
|
+
plan.sessionScanFailed = true;
|
|
282
|
+
uncertain(aid, error);
|
|
194
283
|
}
|
|
284
|
+
for (const key of Object.keys(io))
|
|
285
|
+
io[key] = Math.round(io[key]);
|
|
286
|
+
options.onScan?.({ phase: 'sessions', aid, durationMs: Date.now() - started, files, directories: chats,
|
|
287
|
+
directoryMs, threadDirectoryMs, metadataMs, readMaxMs, io });
|
|
288
|
+
if (aid === options.daemonTriggerAid)
|
|
289
|
+
await daemonTriggerScan;
|
|
290
|
+
else
|
|
291
|
+
await scanTriggers(aid);
|
|
292
|
+
if (aid === options.primaryAid)
|
|
293
|
+
await daemonTriggerScan;
|
|
294
|
+
options.onAgentDiscovered?.(aid, plan);
|
|
195
295
|
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
plan.priorityAids.add(owner);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}));
|
|
296
|
+
})]);
|
|
297
|
+
}
|
|
298
|
+
finally {
|
|
299
|
+
loopDelay.disable();
|
|
300
|
+
const loop = performance.eventLoopUtilization(loopStart);
|
|
301
|
+
options.onDiagnostics?.({ loopMaxMs: Math.round(loopDelay.max / 1e6),
|
|
302
|
+
loopActiveMs: Math.round(loop.active), loopIdleMs: Math.round(loop.idle) });
|
|
303
|
+
}
|
|
208
304
|
return plan;
|
|
209
305
|
}
|
|
210
306
|
/** Bounded admission for startup side effects. Dependency waits belong outside this queue. */
|
|
@@ -222,11 +318,11 @@ export class StartupTaskQueue {
|
|
|
222
318
|
throw new Error('Invalid startup task queue limits');
|
|
223
319
|
}
|
|
224
320
|
}
|
|
225
|
-
run(run, valid = () => true) {
|
|
321
|
+
run(run, valid = () => true, priority = 'foreground') {
|
|
226
322
|
if (this.stopped)
|
|
227
323
|
return Promise.resolve(false);
|
|
228
324
|
const result = new Promise((resolve, reject) => {
|
|
229
|
-
this.pending.push({ run, valid, resolve, reject });
|
|
325
|
+
this.pending.push({ run, valid, resolve, reject, priority });
|
|
230
326
|
});
|
|
231
327
|
this.schedule();
|
|
232
328
|
return result;
|
|
@@ -245,7 +341,13 @@ export class StartupTaskQueue {
|
|
|
245
341
|
// Yield between admissions even when tasks finish synchronously.
|
|
246
342
|
this.timer = setTimeout(() => {
|
|
247
343
|
this.timer = undefined;
|
|
248
|
-
|
|
344
|
+
// Choose at admission time, so newly classified priority work can pass
|
|
345
|
+
// queued idle channels. Never hold a free slot for unclassified work;
|
|
346
|
+
// already-running connections finish within the existing concurrency cap.
|
|
347
|
+
let index = this.pending.findIndex(task => task.priority === 'foreground');
|
|
348
|
+
if (index < 0)
|
|
349
|
+
index = 0;
|
|
350
|
+
const task = this.pending.splice(index, 1)[0];
|
|
249
351
|
if (!task)
|
|
250
352
|
return;
|
|
251
353
|
this.active++;
|
|
@@ -304,118 +406,146 @@ export function daemonConversationTotalExecutionMs(settings) {
|
|
|
304
406
|
? seconds * 1000
|
|
305
407
|
: undefined;
|
|
306
408
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
409
|
+
/** Observer hints are foreground registration; Handoff history is independent. */
|
|
410
|
+
export async function recoverStartupObserverHints(options) {
|
|
411
|
+
await Promise.all(options.startupObserverRecoveries);
|
|
412
|
+
await Promise.all(options.recoveryAids.map(async (aid) => {
|
|
413
|
+
await options.beforeAgentRecovery?.(aid);
|
|
414
|
+
while (!options.isCancelled()) {
|
|
415
|
+
const started = Date.now();
|
|
416
|
+
try {
|
|
417
|
+
const results = await Promise.allSettled(options.channelInstances
|
|
418
|
+
.filter(inst => inst.channelType === 'aun'
|
|
419
|
+
&& options.agentRegistry.resolveByChannel(inst.adapter.channelKey)?.aid === aid)
|
|
420
|
+
.map(inst => options.queuePendingObserverHints(aid, inst.adapter.channelKey)));
|
|
421
|
+
const failure = results.find(result => result.status === 'rejected');
|
|
422
|
+
if (failure?.status === 'rejected')
|
|
423
|
+
throw failure.reason;
|
|
424
|
+
if (options.isCancelled())
|
|
425
|
+
return;
|
|
426
|
+
options.trace?.addSpan('daemon.observerHints', started, Date.now(), aid, 'ok');
|
|
427
|
+
options.onAgentHintsRecovered(aid);
|
|
320
428
|
return;
|
|
321
|
-
|
|
322
|
-
|
|
429
|
+
}
|
|
430
|
+
catch (error) {
|
|
431
|
+
options.trace?.addSpan('daemon.observerHints', started, Date.now(), `${aid}; retry pending`);
|
|
432
|
+
logger.warn(`[startup] observer hint registration waits for ${aid}: ${error}`);
|
|
433
|
+
await recoveryRetryDelay();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}));
|
|
437
|
+
if (options.isCancelled())
|
|
438
|
+
return;
|
|
439
|
+
options.setStartupRecoveryPending(false);
|
|
440
|
+
options.startupObserverRecoveries.length = 0;
|
|
441
|
+
}
|
|
442
|
+
function recoveryRetryDelay() {
|
|
443
|
+
return new Promise(resolve => { const timer = setTimeout(resolve, 1_000); timer.unref?.(); });
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Background recovery never gates Ready. Until an Agent's scan completes its
|
|
447
|
+
* inputs stay queued; afterwards only sessions referenced by unfinished
|
|
448
|
+
* Handoffs wait for durable local recovery. No Runner is loaded by scanning.
|
|
449
|
+
*/
|
|
450
|
+
export class StartupHandoffRecovery {
|
|
451
|
+
options;
|
|
452
|
+
states = new Map();
|
|
453
|
+
running;
|
|
454
|
+
constructor(options) {
|
|
455
|
+
this.options = options;
|
|
456
|
+
for (const aid of options.aids)
|
|
457
|
+
this.states.set(aid, { phase: 'waiting' });
|
|
458
|
+
}
|
|
459
|
+
blockedReason(aid, sessionId) {
|
|
460
|
+
const state = this.states.get(aid);
|
|
461
|
+
if (!state || state.phase === 'ready')
|
|
462
|
+
return;
|
|
463
|
+
if (!state.sessions)
|
|
464
|
+
return 'startup Handoff scan';
|
|
465
|
+
if (state.sessions.has(sessionId))
|
|
466
|
+
return 'session Handoff recovery';
|
|
467
|
+
}
|
|
468
|
+
status() {
|
|
469
|
+
const states = [...this.states.values()];
|
|
470
|
+
return { completed: states.filter(state => state.phase === 'ready').length,
|
|
471
|
+
total: states.length, retrying: states.filter(state => state.phase === 'retrying').length };
|
|
472
|
+
}
|
|
473
|
+
run(waitForReady) {
|
|
474
|
+
return this.running ??= this.recover(waitForReady);
|
|
475
|
+
}
|
|
476
|
+
async recover(waitForReady) {
|
|
477
|
+
if (!await waitForReady() || this.options.isCancelled())
|
|
478
|
+
return;
|
|
479
|
+
const { runtime, trace, isCancelled, onProgress } = this.options;
|
|
480
|
+
const store = this.options.store ?? new HandoffStore();
|
|
481
|
+
const audits = new Map();
|
|
482
|
+
await Promise.all([...this.states].map(async ([aid, state]) => {
|
|
483
|
+
while (!isCancelled()) {
|
|
484
|
+
const started = Date.now();
|
|
323
485
|
try {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if (isCancelled
|
|
486
|
+
state.phase = 'recovering';
|
|
487
|
+
let scanDetail = '';
|
|
488
|
+
const snapshots = await store.listAsync(aid, stats => {
|
|
489
|
+
scanDetail = Object.entries(stats).map(([key, value]) => `${key}=${Math.round(value)}`).join('; ');
|
|
490
|
+
});
|
|
491
|
+
if (isCancelled())
|
|
330
492
|
return;
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
if (
|
|
340
|
-
throw failure.reason;
|
|
341
|
-
if (isCancelled?.())
|
|
493
|
+
trace?.addSpan('daemon.handoffRecovery.scan', started, Date.now(), `${aid}; files=${snapshots.length}${scanDetail ? '; ' + scanDetail : ''}`, 'ok');
|
|
494
|
+
const pending = snapshots.filter(needsHandoffRecovery);
|
|
495
|
+
state.sessions = new Set(pending.flatMap(item => [item.origin_session_id, item.target_session_id]));
|
|
496
|
+
onProgress(); // Unrelated sessions need not wait for journal reconciliation.
|
|
497
|
+
const options = { snapshots, isCancelled,
|
|
498
|
+
prioritizeOrigin: true,
|
|
499
|
+
onPhase: (phase, from, to, detail, status) => trace?.addSpan(`daemon.handoffRecovery.${phase}`, from, to, detail ? `${aid}; ${detail}` : aid, status) };
|
|
500
|
+
await runtime.prepareRecovery(aid, options);
|
|
501
|
+
if (isCancelled())
|
|
342
502
|
return;
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
503
|
+
await runtime.recover([aid], { ...options, snapshots: pending, discardExpired: false });
|
|
504
|
+
if (isCancelled())
|
|
505
|
+
return;
|
|
506
|
+
const terminal = snapshots.filter(item => !needsHandoffRecovery(item));
|
|
507
|
+
if (terminal.length)
|
|
508
|
+
audits.set(aid, terminal);
|
|
509
|
+
state.phase = 'ready';
|
|
510
|
+
state.sessions.clear();
|
|
511
|
+
trace?.addSpan('daemon.handoffRecovery.agent', started, Date.now(), aid, 'ok');
|
|
512
|
+
onProgress();
|
|
353
513
|
return;
|
|
354
514
|
}
|
|
355
515
|
catch (error) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
await new Promise(resolve => { const timer = setTimeout(resolve, 1_000); timer.unref?.(); });
|
|
516
|
+
state.phase = 'retrying';
|
|
517
|
+
trace?.addSpan('daemon.handoffRecovery.agent', started, Date.now(), `${aid}; retry pending`);
|
|
518
|
+
logger.warn(`[Handoff] background recovery waits for ${aid}: ${error}`);
|
|
519
|
+
await recoveryRetryDelay();
|
|
361
520
|
}
|
|
362
521
|
}
|
|
363
522
|
}));
|
|
364
|
-
|
|
365
|
-
if (outcome.status === 'rejected') {
|
|
366
|
-
logger.error(`[Handoff] startup recovery failed for ${recoveryAids[index]}:`, outcome.reason);
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
finally {
|
|
371
|
-
loopDelay.disable();
|
|
372
|
-
const utilization = performance.eventLoopUtilization(utilizationStart);
|
|
373
|
-
const diagnostics = { loopMaxMs: Math.round(loopDelay.max / 1e6),
|
|
374
|
-
loopP99Ms: Math.round(loopDelay.percentile(99) / 1e6),
|
|
375
|
-
loopActiveMs: Math.round(utilization.active), loopIdleMs: Math.round(utilization.idle) };
|
|
376
|
-
for (const [key, value] of Object.entries(diagnostics))
|
|
377
|
-
trace?.setMeta?.(`handoffRecovery.${key}`, String(value));
|
|
378
|
-
logger.info(`[Handoff] startup scheduling: ${Object.entries(diagnostics).map(([key, value]) => `${key}=${value}`).join(' ')}`);
|
|
379
|
-
// Individual failed Agents remain blocked; completion does not manufacture readiness.
|
|
380
|
-
setStartupRecoveryPending(false);
|
|
381
|
-
onStartupHintsRecovered?.();
|
|
382
|
-
startupObserverRecoveries.length = 0;
|
|
383
|
-
}
|
|
384
|
-
// Start only after every Agent's foreground registration has settled. Audit
|
|
385
|
-
// failures retry independently and never hold restored input or normal Ready.
|
|
386
|
-
if (!terminalAudits.size || isCancelled?.())
|
|
387
|
-
return;
|
|
388
|
-
const finishAudit = trace?.startTask?.('daemon.handoffTerminalAuditComplete');
|
|
389
|
-
let auditSkipped = false;
|
|
390
|
-
void (async () => {
|
|
391
|
-
if (waitForNormalReady && !await waitForNormalReady()) {
|
|
392
|
-
auditSkipped = true;
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
if (isCancelled?.())
|
|
523
|
+
if (!audits.size || isCancelled())
|
|
396
524
|
return;
|
|
397
|
-
|
|
398
|
-
while (
|
|
399
|
-
for (const [aid, snapshots] of
|
|
400
|
-
if (isCancelled
|
|
525
|
+
const finish = trace?.startTask?.('daemon.handoffTerminalAuditComplete');
|
|
526
|
+
while (audits.size && !isCancelled()) {
|
|
527
|
+
for (const [aid, snapshots] of audits) {
|
|
528
|
+
if (isCancelled())
|
|
529
|
+
break;
|
|
530
|
+
await yieldToIo();
|
|
531
|
+
if (isCancelled())
|
|
401
532
|
break;
|
|
402
533
|
const started = Date.now();
|
|
403
534
|
try {
|
|
404
|
-
await
|
|
405
|
-
onPhase: (phase,
|
|
406
|
-
trace?.addSpan('daemon.handoffTerminalAudit.agent', started, Date.now(), aid, isCancelled
|
|
407
|
-
|
|
535
|
+
await runtime.recover([aid], { snapshots, discardExpired: false, isCancelled,
|
|
536
|
+
onPhase: (phase, from, to, detail, status) => trace?.addSpan(`daemon.handoffTerminalAudit.${phase}`, from, to, detail ? `${aid}; ${detail}` : aid, status) });
|
|
537
|
+
trace?.addSpan('daemon.handoffTerminalAudit.agent', started, Date.now(), aid, isCancelled() ? 'cancelled' : 'ok');
|
|
538
|
+
audits.delete(aid);
|
|
408
539
|
}
|
|
409
540
|
catch (error) {
|
|
410
541
|
logger.warn(`[Handoff] terminal audit retry pending for ${aid}: ${error}`);
|
|
411
542
|
}
|
|
412
543
|
}
|
|
413
|
-
if (
|
|
414
|
-
await
|
|
415
|
-
}
|
|
544
|
+
if (audits.size && !isCancelled())
|
|
545
|
+
await recoveryRetryDelay();
|
|
416
546
|
}
|
|
417
|
-
|
|
418
|
-
|
|
547
|
+
finish?.(isCancelled() ? 'cancelled' : 'ok');
|
|
548
|
+
}
|
|
419
549
|
}
|
|
420
550
|
export function resumePendingSessions({ sessionManager, messageQueue, droppedTriggerSessionIds, agentRegistry, agentMap, pendingSessions = sessionManager.getPendingProcessingSessions(), }) {
|
|
421
551
|
if (pendingSessions.length === 0)
|
|
@@ -484,7 +614,7 @@ export function resumePendingSessions({ sessionManager, messageQueue, droppedTri
|
|
|
484
614
|
});
|
|
485
615
|
}
|
|
486
616
|
}
|
|
487
|
-
export function createDaemonShutdown({ disposePluginResources, lifecycleNotices, stopOwnership, ipcServer, readySignalPath, bindService, ecwebSupervisor, messageQueue, permissionGateway, removePermissionConfigListener, stopStatsPersistence, triggerSchedulers, agentMap, eventBus, removeGroupInviteConfigListener, groupInviteReviewService, channelLoader, channelInstances, startupRunners, cancelStartup, controlChannel, sessionManager, removeAll, exit, }) {
|
|
617
|
+
export function createDaemonShutdown({ disposePluginResources, lifecycleNotices, stopOwnership, ipcServer, readySignalPath, bindService, ecwebSupervisor, messageQueue, permissionGateway, removePermissionConfigListener, stopStatsPersistence, triggerSchedulers, agentMap, eventBus, removeGroupInviteConfigListener, groupInviteReviewService, channelLoader, channelInstances, startupRunners, waitForRunnerLoads, cancelStartup, controlChannel, sessionManager, removeAll, exit, }) {
|
|
488
618
|
let shutdownSignal = 'unknown';
|
|
489
619
|
let shutdownInProgress = false;
|
|
490
620
|
return async (signal, traceId) => {
|
|
@@ -577,19 +707,21 @@ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices,
|
|
|
577
707
|
});
|
|
578
708
|
});
|
|
579
709
|
try {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
//
|
|
583
|
-
|
|
584
|
-
await triggerSchedulers.waitForIdle(5_000);
|
|
585
|
-
});
|
|
586
|
-
await shutdownStep('daemon.triggerSuspend', 'suspend trigger schedulers', async () => {
|
|
710
|
+
// Freeze Trigger admission and mark resumable runs suspended before the
|
|
711
|
+
// queue interrupts their turns. Waiting for idle first adds a full 5s for
|
|
712
|
+
// long-lived runs and still leaves timers free to start more work.
|
|
713
|
+
const triggerShutdown = shutdownStep('daemon.triggerSuspend', 'suspend trigger schedulers', async () => {
|
|
587
714
|
await triggerSchedulers.suspendForDaemonExit();
|
|
588
715
|
});
|
|
589
|
-
|
|
716
|
+
const queueShutdown = shutdownStep('daemon.queueDrain', 'interrupt active message queue tasks', async () => {
|
|
717
|
+
await messageQueue.shutdownGracefully();
|
|
718
|
+
});
|
|
719
|
+
await shutdownStep('daemon.stopPermissions', 'cancel pending permissions', () => permissionGateway.cancelAllPending('daemon_restart'));
|
|
720
|
+
await Promise.all([triggerShutdown, queueShutdown]);
|
|
590
721
|
await shutdownStep('daemon.agentRunners', 'dispose agent runners', async () => {
|
|
591
722
|
if (startupRunners)
|
|
592
723
|
await Promise.allSettled([startupRunners]);
|
|
724
|
+
await waitForRunnerLoads?.();
|
|
593
725
|
const currentInstances = [...agentMap.entries()].map(([key, agent]) => {
|
|
594
726
|
const split = key.lastIndexOf('::');
|
|
595
727
|
return {
|