


























@@ -12,7 +12,7 @@ import { requestHeartbeat } from "../infra/heartbeat-wake.js";
1212import { isDangerousHostInheritedEnvVarName } from "../infra/host-env-security.js";
1313import { findPathKey, mergePathPrepend } from "../infra/path-prepend.js";
1414import { enqueueSystemEvent } from "../infra/system-events.js";
15-import { scopedHeartbeatWakeOptions } from "../routing/session-key.js";
15+import { resolveEventSessionKey, scopedHeartbeatWakeOptions } from "../routing/session-key.js";
1616import type { ProcessSession } from "./bash-process-registry.js";
1717import type { ExecToolDetails } from "./bash-tools.exec-types.js";
1818import type { BashSandboxConfig } from "./bash-tools.shared.js";
@@ -340,17 +340,22 @@ function maybeNotifyOnExit(session: ProcessSession, status: "completed" | "faile
340340 ? `Exec ${status} (${session.id.slice(0, 8)}, ${exitLabel}) :: ${output}`
341341 : `Exec ${status} (${session.id.slice(0, 8)}, ${exitLabel})`;
342342enqueueSystemEvent(summary, {
343- sessionKey,
343+sessionKey: resolveEventSessionKey(sessionKey, session.mainKey, session.sessionScope),
344344deliveryContext: session.notifyDeliveryContext,
345345trusted: false,
346346});
347347requestHeartbeat(
348-scopedHeartbeatWakeOptions(sessionKey, {
349-source: "exec-event",
350-intent: "event",
351-reason: "exec-event",
352-coalesceMs: 0,
353-}),
348+scopedHeartbeatWakeOptions(
349+sessionKey,
350+{
351+source: "exec-event",
352+intent: "event",
353+reason: "exec-event",
354+coalesceMs: 0,
355+},
356+session.mainKey,
357+session.sessionScope,
358+),
354359);
355360}
356361@@ -416,25 +421,40 @@ export function resolveApprovalRunningNoticeMs(value?: number) {
416421417422export function emitExecSystemEvent(
418423text: string,
419-opts: { sessionKey?: string; contextKey?: string; deliveryContext?: DeliveryContext },
424+opts: {
425+sessionKey?: string;
426+contextKey?: string;
427+deliveryContext?: DeliveryContext;
428+/** `session.mainKey` from the runtime config; pass-through of `undefined`
429+ * falls back to the literal "main" default in `resolveEventSessionKey`. */
430+mainKey?: string;
431+/** `session.scope` from the runtime config; needed so global-scope
432+ * agents route cron-run events to the "global" queue. */
433+sessionScope?: "per-sender" | "global";
434+},
420435) {
421436const sessionKey = opts.sessionKey?.trim();
422437if (!sessionKey) {
423438return;
424439}
425440enqueueSystemEvent(text, {
426- sessionKey,
441+sessionKey: resolveEventSessionKey(sessionKey, opts.mainKey, opts.sessionScope),
427442contextKey: opts.contextKey,
428443deliveryContext: opts.deliveryContext,
429444trusted: false,
430445});
431446requestHeartbeat(
432-scopedHeartbeatWakeOptions(sessionKey, {
433-source: "exec-event",
434-intent: "event",
435-reason: "exec-event",
436-coalesceMs: 0,
437-}),
447+scopedHeartbeatWakeOptions(
448+sessionKey,
449+{
450+source: "exec-event",
451+intent: "event",
452+reason: "exec-event",
453+coalesceMs: 0,
454+},
455+opts.mainKey,
456+opts.sessionScope,
457+),
438458);
439459}
440460@@ -568,6 +588,15 @@ export async function runExecProcess(opts: {
568588notifyOnExitEmptySuccess?: boolean;
569589scopeKey?: string;
570590sessionKey?: string;
591+/** `session.mainKey` from the runtime config; snapshotted onto the
592+ * ProcessSession so background-exit notifications can remap cron-run
593+ * keys without an ambient config load. Long-running background exits use
594+ * this start-time value even if config changes while the process runs. */
595+mainKey?: string;
596+/** `session.scope` from the runtime config; snapshotted alongside
597+ * `mainKey` so the cron-run remap can route global-scope agents to
598+ * the "global" queue instead of agent-main. */
599+sessionScope?: "per-sender" | "global";
571600notifyDeliveryContext?: DeliveryContext;
572601timeoutSec: number | null;
573602onUpdate?: (partialResult: AgentToolResult<ExecToolDetails>) => void;
@@ -587,6 +616,8 @@ export async function runExecProcess(opts: {
587616command: opts.command,
588617scopeKey: opts.scopeKey,
589618sessionKey: opts.sessionKey,
619+mainKey: opts.mainKey,
620+sessionScope: opts.sessionScope,
590621notifyDeliveryContext: normalizeDeliveryContext(opts.notifyDeliveryContext),
591622notifyOnExit: opts.notifyOnExit,
592623notifyOnExitEmptySuccess: opts.notifyOnExitEmptySuccess === true,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。