gentle-pi 4.6.0 → 4.7.0
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/README.md +10 -11
- package/assets/agents/gentle-ai-explore.md +1 -0
- package/assets/agents/gentle-ai-verify.md +5 -2
- package/assets/agents/gentle-ai-worker.md +3 -0
- package/assets/agents/jd-fix-agent.md +1 -0
- package/assets/agents/jd-judge-a.md +1 -0
- package/assets/agents/jd-judge-b.md +1 -0
- package/assets/design-canvas/canvas.css +13 -1
- package/assets/design-canvas/canvas.js +11 -2
- package/assets/install-wizard/wizard.js +1 -0
- package/assets/migrations/agent-body-history.json +16 -1
- package/assets/orchestrator-delegation-reference.md +4 -4
- package/assets/orchestrator-delegation.md +1 -1
- package/assets/orchestrator-full-delegation-card.md +65 -0
- package/assets/orchestrator-full-delegation.md +34 -0
- package/assets/orchestrator-memory.md +3 -3
- package/assets/orchestrator-prompts.md +1 -1
- package/assets/orchestrator-skills.md +1 -1
- package/assets/orchestrator-verification.md +7 -5
- package/assets/orchestrator.md +3 -3
- package/bin/gentle-shell.mjs +164 -56
- package/docs/agent-status.md +61 -0
- package/docs/bundled-install.md +7 -5
- package/docs/delegated-verification.md +29 -7
- package/docs/gentle-agents-activity.md +14 -0
- package/docs/gentle-shell.md +54 -16
- package/docs/install-wizard.md +1 -1
- package/docs/permission-modes.md +9 -4
- package/docs/readme-reference.md +75 -30
- package/docs/render-cache-performance.md +11 -1
- package/docs/review-coordinator.md +33 -0
- package/docs/review-request-context.md +19 -0
- package/docs/review-windows-acl.md +18 -0
- package/docs/voice.md +6 -3
- package/docs/yolo-mode.md +5 -5
- package/extensions/ask-user-choice.ts +1 -0
- package/extensions/ask-user-question.ts +1 -0
- package/extensions/child-safety.ts +3 -0
- package/extensions/gentle-agent-status.ts +99 -0
- package/extensions/gentle-agents.ts +326 -34
- package/extensions/gentle-ai.ts +1496 -454
- package/extensions/gentle-shell.ts +293 -63
- package/extensions/gentle-todo.ts +18 -2
- package/extensions/gentle-tps.ts +48 -0
- package/extensions/quiet-tools.ts +38 -8
- package/extensions/skill-registry.ts +175 -18
- package/extensions/startup-banner.ts +30 -3
- package/lib/agent-profile-pin.ts +3 -3
- package/lib/agent-profiles.ts +160 -2
- package/lib/agent-status.ts +105 -0
- package/lib/agents-config.ts +46 -0
- package/lib/agents-history.ts +24 -5
- package/lib/agents-messaging.ts +47 -5
- package/lib/agents-runner.ts +183 -12
- package/lib/auto-permission-runtime.ts +1 -1
- package/lib/bounded-writer-admission.ts +13 -1
- package/lib/card-content-policy.ts +8 -6
- package/lib/command-palette.ts +133 -17
- package/lib/context-backstop.ts +14 -5
- package/lib/destructive-command-guard.ts +48 -4
- package/lib/execution-surface-guard.ts +20 -0
- package/lib/exploration-budget.ts +4 -2
- package/lib/gentle-ai-binary.ts +1 -1
- package/lib/gentle-design.ts +3 -0
- package/lib/gentle-shell-bundled.ts +6 -19
- package/lib/gentle-shell-launcher.ts +43 -8
- package/lib/herdr-activity.ts +14 -2
- package/lib/herdr-busy.ts +45 -0
- package/lib/image-attachments.ts +33 -0
- package/lib/image-disk-cache.ts +137 -0
- package/lib/inprocess-reviewer.ts +270 -140
- package/lib/jobs-view.ts +198 -11
- package/lib/model-routing-authority.ts +22 -4
- package/lib/native-choice-list.ts +20 -2
- package/lib/native-review-cli.ts +96 -19
- package/lib/orchestrator-mode-policy.ts +105 -0
- package/lib/questionnaire/questionnaire-view.ts +105 -12
- package/lib/rdd-mode-control.ts +32 -0
- package/lib/reply-language-anchor.ts +104 -0
- package/lib/review-blocker.ts +92 -0
- package/lib/review-candidate-symlink-scan.ts +136 -0
- package/lib/review-candidate-view-owner.ts +81 -44
- package/lib/review-continuation-registry.ts +99 -0
- package/lib/review-coordinator.ts +163 -0
- package/lib/review-failure-facts.ts +49 -0
- package/lib/review-host-relay.ts +46 -10
- package/lib/review-integration-v2.ts +7 -1
- package/lib/review-relay-phase-timing.ts +45 -0
- package/lib/review-start-context.ts +17 -0
- package/lib/session-profile-freeze.ts +4 -2
- package/lib/shell-bar.ts +140 -58
- package/lib/shell-changes.ts +2 -0
- package/lib/shell-panel.ts +17 -3
- package/lib/shell-sidebar-layout.ts +112 -40
- package/lib/shell-sidebar.ts +7 -0
- package/lib/shell-todo.ts +10 -3
- package/lib/verifier-admission.ts +1 -1
- package/lib/visual-customization-policy.ts +36 -16
- package/lib/visual-customize-view.ts +216 -21
- package/lib/visual-layout-preview.ts +9 -5
- package/lib/visual-profiles.ts +2 -2
- package/lib/windows-session-transport.ts +53 -2
- package/lib/yolo-session-policy.ts +40 -15
- package/package.json +2 -1
- package/runtime/gentle-ai-binary.mjs +1 -1
- package/runtime/gentle-shell-bundled.mjs +6 -19
- package/runtime/gentle-shell-launcher.mjs +42 -7
- package/runtime/native-review-cli.mjs +93 -16
- package/runtime/review-integration-v2.mjs +7 -1
- package/scripts/build-full-delegation-card.mjs +175 -0
- package/scripts/bundled-install.mjs +38 -8
- package/scripts/download-progress.mjs +68 -0
- package/scripts/gentle-ai-installer.mjs +41 -18
- package/scripts/gentle-ai-proxy.mjs +294 -0
- package/scripts/install-gentle-ai.mjs +14 -1
- package/scripts/installer-preflight.mjs +5 -5
- package/scripts/installer-runner.mjs +27 -12
- package/scripts/installer-server.mjs +8 -7
- package/scripts/render-cache-host.mjs +72 -0
- package/scripts/render-cache-performance-worker.mjs +5 -4
- package/scripts/render-cache-performance.mjs +6 -1
- package/scripts/run-test-suite.mjs +40 -28
- package/scripts/verify-package-files.mjs +12 -2
- package/scripts/voice-worker.cjs +32 -6
- package/skills/design/SKILL.md +11 -8
- package/skills/gentle-ai/SKILL.md +2 -2
- package/skills/gentle-ui-design/SKILL.md +46 -0
- package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
- package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
- package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
- package/skills/gentle-ui-design/references/task-and-content.md +60 -0
- package/skills/skill-registry/SKILL.md +4 -2
- package/skills/work-unit-commits/SKILL.md +6 -7
- package/tests/agent-home.test.ts +28 -9
- package/tests/agent-profiles-workflow.test.ts +163 -0
- package/tests/agent-risk-escalation.test.ts +1 -1
- package/tests/agent-status.test.ts +143 -0
- package/tests/agents-config.test.ts +96 -0
- package/tests/agents-history.test.ts +31 -0
- package/tests/agents-jobs-frames.test.ts +93 -0
- package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
- package/tests/agents-runner-drain.test.ts +193 -0
- package/tests/agents-runner.test.ts +178 -2
- package/tests/append-system-prompt-route.test.ts +4 -1
- package/tests/ask-user-choice.test.ts +4 -3
- package/tests/ask-user-question.test.ts +97 -0
- package/tests/auto-permission-runtime.test.ts +1 -1
- package/tests/autonomous-guard.test.ts +346 -10
- package/tests/bounded-stop-contract.test.ts +43 -3
- package/tests/bridge-cost.test.ts +19 -4
- package/tests/bundled-install.test.ts +30 -5
- package/tests/card-content-policy.test.ts +3 -3
- package/tests/chained-pr-skill.test.ts +8 -6
- package/tests/child-safety.test.ts +11 -0
- package/tests/codegraph-tools.test.ts +11 -5
- package/tests/command-palette.test.ts +284 -1
- package/tests/delegate-for-reason-contract.test.ts +3 -3
- package/tests/design-canvas-assets.test.ts +185 -2
- package/tests/destructive-command-guard.test.ts +52 -0
- package/tests/download-progress.test.ts +71 -0
- package/tests/execution-surface-guard.test.ts +55 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +9 -5
- package/tests/fixtures/proxy-tls/proxy.crt +19 -0
- package/tests/fixtures/proxy-tls/proxy.key +28 -0
- package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
- package/tests/fixtures/session-profile-v1/replay.ts +53 -6
- package/tests/full-delegation-closure.test.ts +131 -0
- package/tests/full-delegation-notices.test.ts +76 -0
- package/tests/generic-agent-tools.test.ts +3 -3
- package/tests/gentle-agent-status.test.ts +74 -0
- package/tests/gentle-agents-child-jobs.test.ts +237 -0
- package/tests/gentle-agents.test.ts +1070 -12
- package/tests/gentle-ai-binary.test.ts +3 -1
- package/tests/gentle-ai-elapsed-store.test.ts +19 -0
- package/tests/gentle-ai-exploration-budget.test.ts +18 -2
- package/tests/gentle-ai-installer.test.ts +134 -51
- package/tests/gentle-ai-proxy.test.ts +434 -0
- package/tests/gentle-ai.test.ts +113 -38
- package/tests/gentle-design.test.ts +21 -0
- package/tests/gentle-herdr-activity.test.ts +9 -6
- package/tests/gentle-shell-bin.test.ts +123 -0
- package/tests/gentle-shell-bundled.test.ts +207 -31
- package/tests/gentle-shell-launcher.test.ts +77 -10
- package/tests/gentle-shell.test.ts +899 -59
- package/tests/gentle-todo.test.ts +19 -2
- package/tests/gentle-tps.test.ts +123 -0
- package/tests/gentle-ui-design-skill.test.ts +59 -0
- package/tests/herdr-busy.test.ts +59 -0
- package/tests/herdr-task-summary-policy.test.ts +8 -4
- package/tests/image-disk-cache.test.ts +163 -0
- package/tests/independent-recovery-delivery.test.ts +83 -0
- package/tests/inprocess-reviewer.test.ts +176 -4
- package/tests/installer-posix-bootstrap.test.ts +1 -1
- package/tests/installer-preflight.test.ts +5 -4
- package/tests/installer-runner.test.ts +79 -44
- package/tests/installer-server.test.ts +14 -11
- package/tests/jobs-view.test.ts +260 -6
- package/tests/modal-mouse-boundaries.test.ts +136 -0
- package/tests/model-routing-authority.test.ts +178 -2
- package/tests/native-choice-list.test.ts +77 -2
- package/tests/native-review-capability-contract.test.ts +7 -1
- package/tests/native-review-cli.test.ts +269 -1
- package/tests/no-self-pause-contract.test.ts +4 -1
- package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
- package/tests/orchestrator-budget.test.ts +7 -2
- package/tests/orchestrator-delegation-mode.test.ts +153 -0
- package/tests/orchestrator-mode-policy.test.ts +175 -0
- package/tests/orchestrator-prompt-budget.test.ts +3 -1
- package/tests/orchestrator-rdd-ownership.test.ts +2 -2
- package/tests/package-manifest.test.ts +11 -9
- package/tests/permission-allowlist.test.ts +202 -0
- package/tests/pi-update-launcher.test.ts +8 -0
- package/tests/pnpm-workspace-config.test.ts +58 -0
- package/tests/primary-session-prompt.test.ts +13 -0
- package/tests/profile-pin.test.ts +29 -2
- package/tests/profile-tier-footer.test.ts +5 -0
- package/tests/profiles-panel-delegation-mode.test.ts +422 -0
- package/tests/questionnaire-view.test.ts +115 -0
- package/tests/quiet-bash-runtime.test.ts +1 -1
- package/tests/quiet-tool-rendering.test.ts +48 -0
- package/tests/rdd-aware-verification-contract.test.ts +16 -11
- package/tests/rdd-customize.test.ts +287 -0
- package/tests/rdd-mode-cache.test.ts +450 -0
- package/tests/rdd-mode-control.test.ts +407 -0
- package/tests/rdd-mode-scope-regression.test.ts +137 -0
- package/tests/rdd-off-independent-regression.test.ts +69 -0
- package/tests/rdd-status-line.test.ts +18 -0
- package/tests/render-cache-performance.test.ts +171 -2
- package/tests/reply-language-anchor.test.ts +173 -0
- package/tests/review-agent-end-preflight.test.ts +1 -1
- package/tests/review-blocker.test.ts +193 -0
- package/tests/review-candidate-owner-retry.test.ts +1 -1
- package/tests/review-candidate-symlink-scan.test.ts +157 -0
- package/tests/review-candidate-view.test.ts +1 -1
- package/tests/review-candidate-windows-boundary.test.ts +131 -0
- package/tests/review-candidate-windows-probe.test.ts +63 -0
- package/tests/review-committed-restart-ack.test.ts +129 -0
- package/tests/review-continuation-registry.test.ts +76 -0
- package/tests/review-controller-native-routing.test.ts +261 -5
- package/tests/review-controller-workspace-root.test.ts +230 -3
- package/tests/review-controller.test.ts +96 -11
- package/tests/review-coordinator-runtime.test.ts +117 -0
- package/tests/review-coordinator.test.ts +195 -0
- package/tests/review-failure-facts.test.ts +87 -0
- package/tests/review-host-relay-routing.test.ts +258 -4
- package/tests/review-host-relay.test.ts +39 -0
- package/tests/review-integration-v2.test.ts +46 -3
- package/tests/review-json-arguments.test.ts +65 -10
- package/tests/review-last-event-closure.test.ts +68 -0
- package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
- package/tests/review-owner-identity.test.ts +60 -24
- package/tests/review-relay-phase-timing.test.ts +128 -0
- package/tests/review-relay-transport-agent.test.ts +12 -2
- package/tests/review-reviewer-evidence.test.ts +183 -0
- package/tests/review-risk-assessment.test.ts +74 -3
- package/tests/review-session-standing-permission-controller.test.ts +21 -1
- package/tests/review-start-context.test.ts +19 -0
- package/tests/review-tool-prose-budget.test.ts +121 -0
- package/tests/run-test-suite.test.ts +122 -1
- package/tests/runtime-harness.mjs +4 -1
- package/tests/sensitive-path-tools.test.ts +181 -5
- package/tests/session-profile-append-controller-pi.test.ts +60 -31
- package/tests/session-profile-binding.test.ts +19 -1
- package/tests/session-profile-disk-reader-pi.test.ts +58 -16
- package/tests/session-profile-v1-compat.test.ts +35 -1
- package/tests/shell-bar.test.ts +186 -42
- package/tests/shell-panel.test.ts +50 -22
- package/tests/shell-sidebar-fullscreen.test.ts +5 -5
- package/tests/shell-sidebar-layout.test.ts +294 -23
- package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
- package/tests/shell-surface-transparent.test.ts +89 -0
- package/tests/shell-todo.test.ts +12 -0
- package/tests/skill-registry.test.ts +838 -5
- package/tests/startup-banner.test.ts +152 -1
- package/tests/startup-home-repo.test.ts +2 -0
- package/tests/support/review-coordinator-runtime.ts +69 -0
- package/tests/task-size-routing-contract.test.ts +5 -3
- package/tests/verifier-admission.test.ts +49 -0
- package/tests/verify-first-launch-contract.test.ts +78 -3
- package/tests/visual-customization-policy.test.ts +39 -6
- package/tests/visual-customize-view.test.ts +573 -9
- package/tests/visual-layout-preview.test.ts +15 -1
- package/tests/visual-profiles.test.ts +11 -0
- package/tests/voice-worker.test.ts +73 -2
- package/tests/windows-session-transport.test.ts +126 -0
- package/tests/work-continuity-contract.test.ts +28 -0
- package/tests/writer-feature-document-admission.test.ts +92 -0
- package/tests/yolo-customize.test.ts +27 -4
- package/tests/yolo-mode.test.ts +23 -18
- package/tests/yolo-session-policy.test.ts +270 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import { appendFileSync, chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { appendFileSync, chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { execFileSync } from "node:child_process";
|
|
4
4
|
import { homedir, tmpdir } from "node:os";
|
|
5
5
|
import { createRequire, syncBuiltinESMExports } from "node:module";
|
|
@@ -16,10 +16,10 @@ import { createAssistantMessageEventStream, type AssistantMessage } from "@earen
|
|
|
16
16
|
import { visibleWidth, type Component, type TUI, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
17
17
|
import { sidebarState } from "../lib/shell-sidebar.ts";
|
|
18
18
|
import { CHILD_PACKAGE_INJECTION_ENV, encodeChildPackageInjection } from "../lib/child-package-injection.ts";
|
|
19
|
-
import installGentleAgents, { agentRuntimePaths, agentsCollapseKey, agentsEnabled, agentsStopKey, agentsViewKey, agentResultPreview, answerThroughUi, childContextExtensionPaths, completionText, createDefaultSessionTransport, legacySubagentsInstalled, PARENT_WAKE_GRACE_MS, type AgentsDeps, type SessionTransportFactory } from "../extensions/gentle-agents.ts";
|
|
19
|
+
import installGentleAgents, { agentRuntimePaths, agentsCollapseKey, agentsEnabled, agentsStopKey, agentsViewKey, agentResultPreview, answerThroughUi, childContextExtensionPaths, completionText, createDefaultSessionTransport, legacySubagentsInstalled, HOLD_RECHECK_MS, INPUT_PROMPT_GRACE_MS, PARENT_WAKE_GRACE_MS, type AgentsDeps, type SessionTransportFactory } from "../extensions/gentle-agents.ts";
|
|
20
20
|
import { ActiveSessionClient, ActiveSessionListener, SessionPresenceError, SessionPresenceRegistry, type PresenceRecord } from "../lib/agents-session-transport.ts";
|
|
21
21
|
import { WindowsActiveSessionClient, WindowsActiveSessionListener } from "../lib/windows-session-transport.ts";
|
|
22
|
-
import { historyDir, loadHistory, saveTask } from "../lib/agents-history.ts";
|
|
22
|
+
import { historyDir, loadHistory, loadStoredTask, saveTask } from "../lib/agents-history.ts";
|
|
23
23
|
import { STALE_COMPLETION_MS } from "../lib/agents-completion-delivery.ts";
|
|
24
24
|
import { applyTaskEvent, emptyThread, MISSING_TOOLS_NOTE_PREFIX, TASK_EVENT, TASK_STATUS, TaskStore, type TaskRecord } from "../lib/agents-protocol.ts";
|
|
25
25
|
import { NativePointerScope } from "../lib/native-pointer-region.ts";
|
|
@@ -134,7 +134,7 @@ function fakePi(initialProvider: string = "claude-bridge") {
|
|
|
134
134
|
const handlers = new Map<string, Handler[]>();
|
|
135
135
|
const tools = new Map<string, Registered>();
|
|
136
136
|
const shortcuts = new Map<string, { description: string; handler(ctx: ExtensionContext): Promise<void> }>();
|
|
137
|
-
const commands = new Map<string, { handler(args: string, ctx: ExtensionContext): Promise<void> }>();
|
|
137
|
+
const commands = new Map<string, { description?: string; handler(args: string, ctx: ExtensionContext): Promise<void> }>();
|
|
138
138
|
const sent: Array<{ message: Record<string, unknown>; options: Record<string, unknown> }> = [];
|
|
139
139
|
// `delivery` records custom messages and user wakes in dispatch order.
|
|
140
140
|
const userMessages: Array<{ content: unknown; options: Record<string, unknown> | undefined }> = [];
|
|
@@ -168,7 +168,7 @@ function fakePi(initialProvider: string = "claude-bridge") {
|
|
|
168
168
|
on: (event: string, handler: Handler) => handlers.set(event, [...(handlers.get(event) ?? []), handler]),
|
|
169
169
|
registerTool: (tool: Registered) => tools.set(tool.name, tool),
|
|
170
170
|
registerShortcut: (key: string, registration: { description: string; handler(ctx: ExtensionContext): Promise<void> }) => shortcuts.set(key, registration),
|
|
171
|
-
registerCommand: (name: string, registration: { handler(args: string, ctx: ExtensionContext): Promise<void> }) => commands.set(name, registration),
|
|
171
|
+
registerCommand: (name: string, registration: { description?: string; handler(args: string, ctx: ExtensionContext): Promise<void> }) => commands.set(name, registration),
|
|
172
172
|
} as unknown as ExtensionAPI;
|
|
173
173
|
let activeSession: ExtensionContext | undefined;
|
|
174
174
|
const teardown = async () => {
|
|
@@ -1204,6 +1204,65 @@ test("child parent-message tooling admits notifications and the active parent pr
|
|
|
1204
1204
|
assert.deepEqual(runtime.children[0].sent, [{ id: "n1", kind: "ack", accepted: true }, { id: "n2", kind: "ack", accepted: false, error: "task parent is not the active host session" }]);
|
|
1205
1205
|
await parent.fire("session_shutdown", ctx);
|
|
1206
1206
|
});
|
|
1207
|
+
|
|
1208
|
+
// #2266: a child with the forwarded job capability and owned IPC registers the
|
|
1209
|
+
// background job tools for its own session; the monitor stays parent-only.
|
|
1210
|
+
function childJobsChild(env: NodeJS.ProcessEnv, overrides: Partial<AgentsDeps> = {}) {
|
|
1211
|
+
const child = fakePi();
|
|
1212
|
+
const listeners = new Map<string, Array<(value: Record<string, unknown>) => void>>();
|
|
1213
|
+
const frames: Array<Record<string, unknown>> = [];
|
|
1214
|
+
gentleAgents(child.pi, { GENTLE_PI_AGENTS_CHILD: "1", GENTLE_PI_AGENTS_OWNED_IPC: "fixture", ...env }, {
|
|
1215
|
+
childIpc: {
|
|
1216
|
+
send: (frame: Record<string, unknown>) => { frames.push(frame); return true; },
|
|
1217
|
+
on: (event: string, listener: (value: Record<string, unknown>) => void) => listeners.set(event, [...(listeners.get(event) ?? []), listener]),
|
|
1218
|
+
},
|
|
1219
|
+
...overrides,
|
|
1220
|
+
});
|
|
1221
|
+
return { child, frames, listeners };
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
test("a child with the forwarded job capability registers bash_background/job_list/job_stop privately, never the monitor", () => {
|
|
1225
|
+
const jobs = fakeJobShell();
|
|
1226
|
+
const { child } = childJobsChild({ GENTLE_PI_AGENTS_CHILD_JOBS: "1" }, { jobShell: jobs.shell, jobOutputDir: () => jobs.dir, now: () => 1_000 });
|
|
1227
|
+
try {
|
|
1228
|
+
assert.deepEqual([...child.tools.keys()].sort(), ["bash_background", "job_list", "job_stop", "subagent_parent_message"]);
|
|
1229
|
+
assert.equal(child.tools.has("monitor"), false, "the monitor stays parent-only");
|
|
1230
|
+
} finally { jobs.cleanup(); }
|
|
1231
|
+
});
|
|
1232
|
+
|
|
1233
|
+
test("a child without the forwarded job capability keeps only parent messaging", () => {
|
|
1234
|
+
const child = fakePi();
|
|
1235
|
+
gentleAgents(child.pi, { GENTLE_PI_AGENTS_CHILD: "1", GENTLE_PI_AGENTS_OWNED_IPC: "fixture" }, {
|
|
1236
|
+
childIpc: { send: () => true, on: () => undefined },
|
|
1237
|
+
});
|
|
1238
|
+
assert.deepEqual([...child.tools.keys()], ["subagent_parent_message"]);
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
test("a child without owned IPC never registers background job tools even with the forwarded capability", () => {
|
|
1242
|
+
const child = fakePi();
|
|
1243
|
+
gentleAgents(child.pi, { GENTLE_PI_AGENTS_CHILD: "1", GENTLE_PI_AGENTS_CHILD_JOBS: "1" });
|
|
1244
|
+
assert.deepEqual([...child.tools.keys()], []);
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
test("a child reports its background job state to the parent and delivers the exit notice to its own session", async () => {
|
|
1248
|
+
const jobs = fakeJobShell();
|
|
1249
|
+
const { child, frames } = childJobsChild({ GENTLE_PI_AGENTS_CHILD_JOBS: "1" }, { jobShell: jobs.shell, jobOutputDir: () => jobs.dir, now: () => 1_000 });
|
|
1250
|
+
const { ctx } = fakeContext();
|
|
1251
|
+
try {
|
|
1252
|
+
await child.tools.get("bash_background")!.execute("b1", { command: "gh run watch 1 --exit-status", label: "CI" }, undefined, undefined, ctx);
|
|
1253
|
+
assert.deepEqual(frames.at(-1), { id: "j1", kind: "job", message: JSON.stringify({ running: 1, pending: true }) });
|
|
1254
|
+
await child.fire("agent_settled", ctx);
|
|
1255
|
+
assert.deepEqual(frames.at(-1), { id: "j2", kind: "job", message: JSON.stringify({ running: 1, pending: true }) }, "settlement reports the still-running job");
|
|
1256
|
+
jobs.runs[0]!.exit(0);
|
|
1257
|
+
await eventually(() => child.sent.some((entry) => entry.message.customType === "gentle-jobs.notice"), "the child delivers its own job exit notice");
|
|
1258
|
+
assert.deepEqual(frames.at(-1), { id: "j3", kind: "job", message: JSON.stringify({ running: 0, pending: false }) }, "the settlement report clears the running count");
|
|
1259
|
+
const notice = child.sent.find((entry) => entry.message.customType === "gentle-jobs.notice")!;
|
|
1260
|
+
assert.deepEqual(notice.options, { deliverAs: "steer", triggerTurn: true });
|
|
1261
|
+
assert.equal(notice.message.display, true);
|
|
1262
|
+
assert.match(String(notice.message.content), /Background job job-1/);
|
|
1263
|
+
} finally { jobs.cleanup(); }
|
|
1264
|
+
});
|
|
1265
|
+
|
|
1207
1266
|
for (const boundary of ["allowed", "env", "session", "replacement", "bus-throws", "no-spawn", "long-running"] as const) {
|
|
1208
1267
|
test(`local child composition through real extensions and RPC runner: ${boundary}`, async (t) => {
|
|
1209
1268
|
const discarded: number[] = [];
|
|
@@ -4460,6 +4519,124 @@ test("a task that finishes live stays visible as history, in both scopes, and it
|
|
|
4460
4519
|
await opened;
|
|
4461
4520
|
});
|
|
4462
4521
|
|
|
4522
|
+
test("an in-flight task is persisted on launch, and reconciles to interrupted if the parent dies before it finishes (#1741)", async () => {
|
|
4523
|
+
const { pi, tools, fire } = fakePi();
|
|
4524
|
+
const harness = deps();
|
|
4525
|
+
gentleAgents(pi, {}, harness.deps);
|
|
4526
|
+
const { ctx } = fakeContext();
|
|
4527
|
+
await fire("session_start", ctx);
|
|
4528
|
+
const started = await tools.get("subagent_run")!.execute("c1", { agent: "explore", task: "Survive abrupt crash", mode: "background" }, undefined, undefined, ctx);
|
|
4529
|
+
const id = (started.details.gentleAgents as { taskId: string }).taskId;
|
|
4530
|
+
assert.ok(id, "task ID allocated");
|
|
4531
|
+
|
|
4532
|
+
// Wait for the async launch persistence to write the file
|
|
4533
|
+
const tasksDir = join(home, ".pi", "agent", "gentle-agents", "tasks");
|
|
4534
|
+
let stored = await loadStoredTask(tasksDir, id);
|
|
4535
|
+
for (let attempt = 0; attempt < 10 && !stored; attempt += 1) {
|
|
4536
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
4537
|
+
stored = await loadStoredTask(tasksDir, id);
|
|
4538
|
+
}
|
|
4539
|
+
assert.ok(stored, "the in-flight task is written to disk upon launch");
|
|
4540
|
+
assert.equal(stored.task.id, id);
|
|
4541
|
+
assert.ok(stored.task.status === "queued" || stored.task.status === "running", "task status is in-flight on disk");
|
|
4542
|
+
assert.equal(stored.task.endedAt, null, "task is not ended yet");
|
|
4543
|
+
|
|
4544
|
+
// Simulate abrupt death of parent: no session_shutdown, no runner.cancelAll.
|
|
4545
|
+
// A completely new session in another process starts up with the same disk store.
|
|
4546
|
+
const fresh = fakePi();
|
|
4547
|
+
const freshHarness = deps();
|
|
4548
|
+
gentleAgents(fresh.pi, {}, freshHarness.deps);
|
|
4549
|
+
const freshCtx = fakeContext();
|
|
4550
|
+
await fresh.fire("session_start", freshCtx.ctx);
|
|
4551
|
+
|
|
4552
|
+
// In the new session, subagent_status must NOT fail with "Error: no task <id>"
|
|
4553
|
+
const statusResult = await fresh.tools.get("subagent_status")!.execute("s1", { task_id: id }, undefined, undefined, freshCtx.ctx);
|
|
4554
|
+
assert.doesNotMatch(statusResult.content[0].text, /Error: no task/, "interrupted task must resolve");
|
|
4555
|
+
assert.match(statusResult.content[0].text, /failed/, "status must report terminal failure");
|
|
4556
|
+
assert.match(statusResult.content[0].text, /interrupted/i, "status must explain interruption");
|
|
4557
|
+
|
|
4558
|
+
// The disk record must now be updated to the terminal reconciled state
|
|
4559
|
+
const reconciledOnDisk = await loadStoredTask(tasksDir, id);
|
|
4560
|
+
assert.ok(reconciledOnDisk, "reconciled record on disk");
|
|
4561
|
+
assert.equal(reconciledOnDisk.task.status, "failed");
|
|
4562
|
+
assert.match(reconciledOnDisk.task.error ?? "", /interrupted/i);
|
|
4563
|
+
assert.ok(typeof reconciledOnDisk.task.endedAt === "number", "endedAt is populated");
|
|
4564
|
+
|
|
4565
|
+
// On resume of the original session, subagent_list_tasks must list the interrupted task
|
|
4566
|
+
const resumedPi = fakePi();
|
|
4567
|
+
const resumedHarness = deps();
|
|
4568
|
+
gentleAgents(resumedPi.pi, {}, resumedHarness.deps);
|
|
4569
|
+
const resumedCtx = fakeContext();
|
|
4570
|
+
(resumedCtx.ctx.sessionManager as { getSessionId(): string }).getSessionId = () => ctx.sessionManager.getSessionId();
|
|
4571
|
+
(resumedCtx.ctx.sessionManager as { getEntries(): unknown[] }).getEntries = () => [{ type: "custom" }];
|
|
4572
|
+
await resumedPi.fire("session_start", resumedCtx.ctx, { reason: "resume" });
|
|
4573
|
+
// No delay: list_tasks waits for the resumed session's restoration itself.
|
|
4574
|
+
const listResult = await resumedPi.tools.get("subagent_list_tasks")!.execute("l1", {}, undefined, undefined, resumedCtx.ctx);
|
|
4575
|
+
assert.match(listResult.content[0].text, new RegExp(id), "interrupted task must appear in resumed session task list");
|
|
4576
|
+
assert.match(listResult.content[0].text, /interrupted/i);
|
|
4577
|
+
});
|
|
4578
|
+
|
|
4579
|
+
test("a task that finishes before its launch save settles ends terminal on disk (#1741)", async (t) => {
|
|
4580
|
+
const { pi, tools, fire } = fakePi();
|
|
4581
|
+
const harness = deps();
|
|
4582
|
+
// A large in-flight thread makes the stale launch write slower than the terminal one.
|
|
4583
|
+
const thread = TaskStore.prototype.thread;
|
|
4584
|
+
const slow = applyTaskEvent(emptyThread(), { type: TASK_EVENT.TEXT, text: "x".repeat(32 * 1024 * 1024) });
|
|
4585
|
+
t.mock.method(TaskStore.prototype, "thread", function (this: TaskStore, id: string) {
|
|
4586
|
+
const current = this.get(id);
|
|
4587
|
+
return current && current.status !== TASK_STATUS.COMPLETED ? slow : thread.call(this, id);
|
|
4588
|
+
});
|
|
4589
|
+
gentleAgents(pi, {}, harness.deps);
|
|
4590
|
+
const { ctx } = fakeContext();
|
|
4591
|
+
await fire("session_start", ctx);
|
|
4592
|
+
const started = await tools.get("subagent_run")!.execute("race", { agent: "explore", task: "Finish fast", mode: "background" }, undefined, undefined, ctx);
|
|
4593
|
+
const id = (started.details.gentleAgents as { taskId: string }).taskId;
|
|
4594
|
+
await tick();
|
|
4595
|
+
harness.children[0].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "done" }], stopReason: "stop" }] });
|
|
4596
|
+
harness.children[0].emit({ type: "agent_settled" });
|
|
4597
|
+
const tasksDir = historyDir(home);
|
|
4598
|
+
const pendingWrites = () => { try { return readdirSync(tasksDir).filter((name) => name.startsWith(`${id}.json.`)).length; } catch { return 1; } };
|
|
4599
|
+
let stored = await loadStoredTask(tasksDir, id);
|
|
4600
|
+
for (let attempt = 0; attempt < 120 && (stored?.task.status !== TASK_STATUS.COMPLETED || pendingWrites() > 0); attempt += 1) {
|
|
4601
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
4602
|
+
stored = await loadStoredTask(tasksDir, id);
|
|
4603
|
+
}
|
|
4604
|
+
// Give any stale launch write that is still in flight time to land.
|
|
4605
|
+
for (let settle = 0; settle < 8; settle += 1) {
|
|
4606
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
4607
|
+
assert.equal(pendingWrites(), 0);
|
|
4608
|
+
}
|
|
4609
|
+
stored = await loadStoredTask(tasksDir, id);
|
|
4610
|
+
assert.equal(stored?.task.status, TASK_STATUS.COMPLETED, "the terminal record is never overwritten by a launch write");
|
|
4611
|
+
assert.equal(stored?.task.result, "done");
|
|
4612
|
+
});
|
|
4613
|
+
|
|
4614
|
+
test("a resumed session reconciles an interrupted task before publishing restored history (#1741)", async (t) => {
|
|
4615
|
+
const { pi, fire } = fakePi();
|
|
4616
|
+
const harness = deps();
|
|
4617
|
+
const resumeHome = join(root, "reconcile-resume-home");
|
|
4618
|
+
const interrupted: TaskRecord = { id: "interrupted-1", agent: "explore", mode: "background", prompt: "p", label: "p", cwd, parentSessionId: "reconcile-session", status: TASK_STATUS.RUNNING, createdAt: 1, startedAt: 1, endedAt: null, model: "m", thinking: undefined, sessionPath: null, error: null, result: null, lastStep: "working", lastActivityAt: 1, turns: 0, toolCalls: 0, tokens: 0, cost: 0 };
|
|
4619
|
+
await saveTask(historyDir(resumeHome), interrupted, emptyThread());
|
|
4620
|
+
harness.deps.home = resumeHome;
|
|
4621
|
+
let store: TaskStore | undefined;
|
|
4622
|
+
const restore = TaskStore.prototype.restore;
|
|
4623
|
+
t.mock.method(TaskStore.prototype, "restore", function (this: TaskStore, ...args: Parameters<TaskStore["restore"]>) {
|
|
4624
|
+
store = this;
|
|
4625
|
+
return restore.apply(this, args);
|
|
4626
|
+
});
|
|
4627
|
+
gentleAgents(pi, {}, harness.deps);
|
|
4628
|
+
const { ctx } = fakeContext();
|
|
4629
|
+
ctx.sessionManager.getSessionId = () => "reconcile-session";
|
|
4630
|
+
await fire("session_start", ctx, { reason: "resume" });
|
|
4631
|
+
await eventually(() => store?.get("interrupted-1") !== undefined, "restored history published");
|
|
4632
|
+
const restored = store!.get("interrupted-1")!;
|
|
4633
|
+
assert.equal(restored.status, TASK_STATUS.FAILED);
|
|
4634
|
+
assert.match(restored.error ?? "", /interrupted/);
|
|
4635
|
+
assert.equal(typeof restored.endedAt, "number");
|
|
4636
|
+
assert.equal((await loadStoredTask(historyDir(resumeHome), "interrupted-1"))?.task.status, TASK_STATUS.FAILED);
|
|
4637
|
+
await fire("session_shutdown", ctx);
|
|
4638
|
+
});
|
|
4639
|
+
|
|
4463
4640
|
test("the overlay confirms a running task once and reports when it finishes during confirmation", async () => {
|
|
4464
4641
|
const { pi, tools, fire, commands, sent } = fakePi();
|
|
4465
4642
|
const harness = deps();
|
|
@@ -4589,7 +4766,10 @@ test("restored task history cannot enter the live panel or discovery during sync
|
|
|
4589
4766
|
assert.deepEqual(readDiscovery(profile, listPresence(profile).entries[0])?.tasks, []);
|
|
4590
4767
|
const opened = commands.get("gentle:agents")!.handler("", ctx);
|
|
4591
4768
|
for (let attempt = 0; attempt < 40 && overlays.length === 0; attempt += 1) await new Promise((resolve) => setTimeout(resolve, 25));
|
|
4592
|
-
|
|
4769
|
+
// The interrupted record is reconciled on resume, so it shows as finished history, never as stoppable work (#1741).
|
|
4770
|
+
const rendered = stripAnsi(overlays[0]!.render(80).join("\n"));
|
|
4771
|
+
assert.doesNotMatch(rendered, /Stop selected|running/);
|
|
4772
|
+
assert.match(rendered, /failed/);
|
|
4593
4773
|
overlays[0]!.handleInput("s");
|
|
4594
4774
|
overlays[0]!.handleInput("c");
|
|
4595
4775
|
await tick();
|
|
@@ -4804,6 +4984,70 @@ test("default session transport selects Windows or POSIX classes without mutatin
|
|
|
4804
4984
|
assert.notEqual(windows.createRegistry, posix.createRegistry);
|
|
4805
4985
|
});
|
|
4806
4986
|
|
|
4987
|
+
test("session transport startup diagnostic reports only bounded current failures", async (t) => {
|
|
4988
|
+
for (const mode of ["initialize", "registry", "listener", "malformed", "success", "stale-id", "reload", "shutdown"] as const) {
|
|
4989
|
+
await t.test(mode, async () => {
|
|
4990
|
+
const h = fakePi(), runtime = deps(), { ctx } = fakeContext();
|
|
4991
|
+
const notices: Array<{ message: string; level: unknown }> = [];
|
|
4992
|
+
ctx.ui.notify = (message, level) => { notices.push({ message, level }); };
|
|
4993
|
+
let release!: () => void;
|
|
4994
|
+
const pending = new Promise<void>((resolve) => { release = resolve; });
|
|
4995
|
+
let entered = false;
|
|
4996
|
+
let starts = 0;
|
|
4997
|
+
let observerResult: unknown = "not called";
|
|
4998
|
+
const registry = { list: async () => [], listActivations: async () => [] };
|
|
4999
|
+
runtime.deps.sessionTransport = {
|
|
5000
|
+
createRegistry: async (_home, observe) => {
|
|
5001
|
+
if (mode === "initialize") {
|
|
5002
|
+
observerResult = observe?.({ phase: "start", status: "succeeded", error: null, lastStartupMarker: "native-ready" });
|
|
5003
|
+
observe?.({ phase: "initialize", status: "failed", error: { class: "timed-out", code: "deadline" }, lastStartupMarker: "native-ready" });
|
|
5004
|
+
observe?.({ phase: "cleanup", status: "succeeded", error: null, lastStartupMarker: "native-ready" });
|
|
5005
|
+
throw new Error("SECRET path SID stderr session-id");
|
|
5006
|
+
}
|
|
5007
|
+
if (mode === "malformed") {
|
|
5008
|
+
observe?.({ phase: "SECRET", status: "failed", error: { class: "SECRET", code: "SECRET" }, lastStartupMarker: "SECRET" } as never);
|
|
5009
|
+
throw new Error("SECRET");
|
|
5010
|
+
}
|
|
5011
|
+
if (mode === "registry") throw new Error("SECRET path SID stderr session-id");
|
|
5012
|
+
if (mode === "stale-id" || mode === "reload" || mode === "shutdown") {
|
|
5013
|
+
entered = true;
|
|
5014
|
+
await pending;
|
|
5015
|
+
throw new Error("SECRET");
|
|
5016
|
+
}
|
|
5017
|
+
return registry;
|
|
5018
|
+
},
|
|
5019
|
+
createListener: () => ({ registry, start: async () => { starts++; if (mode === "listener") throw new Error("SECRET"); }, close: async () => {} }),
|
|
5020
|
+
createClient: inertSessionTransport.createClient,
|
|
5021
|
+
};
|
|
5022
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
5023
|
+
await h.fire("session_start", ctx);
|
|
5024
|
+
if (mode === "stale-id" || mode === "reload" || mode === "shutdown") {
|
|
5025
|
+
await eventually(() => entered, "registry startup entered");
|
|
5026
|
+
if (mode === "stale-id") Object.assign(ctx.sessionManager, { getSessionId: () => "replacement" });
|
|
5027
|
+
if (mode === "reload") await h.fire("session_start", fakeContext().ctx);
|
|
5028
|
+
if (mode === "shutdown") {
|
|
5029
|
+
const closing = h.fire("session_shutdown", ctx);
|
|
5030
|
+
release();
|
|
5031
|
+
await closing;
|
|
5032
|
+
}
|
|
5033
|
+
release();
|
|
5034
|
+
}
|
|
5035
|
+
// Shutdown drains tracked startup operations, including catch and cleanup.
|
|
5036
|
+
if (mode === "success") await eventually(() => starts === 1, "successful listener start");
|
|
5037
|
+
if (["initialize", "registry", "listener", "malformed"].includes(mode)) {
|
|
5038
|
+
await eventually(() => notices.length === 1, "startup diagnostic notification");
|
|
5039
|
+
}
|
|
5040
|
+
await h.fire("session_shutdown", ctx);
|
|
5041
|
+
const expected = mode === "initialize"
|
|
5042
|
+
? "Session transport startup failed: phase=initialize class=timed-out code=deadline lastStartupMarker=native-ready."
|
|
5043
|
+
: mode === "listener" ? "Session transport startup failed: phase=listener diagnostics=unavailable."
|
|
5044
|
+
: mode === "registry" || mode === "malformed" ? "Session transport startup failed: phase=registry diagnostics=unavailable." : undefined;
|
|
5045
|
+
assert.deepEqual(notices, expected ? [{ message: expected, level: "warning" }] : []);
|
|
5046
|
+
if (mode === "initialize") assert.equal(observerResult, undefined);
|
|
5047
|
+
});
|
|
5048
|
+
}
|
|
5049
|
+
});
|
|
5050
|
+
|
|
4807
5051
|
test("session transport startup failure cleans the constructed Windows-capable transport and stays unavailable", async () => {
|
|
4808
5052
|
const h = fakePi();
|
|
4809
5053
|
const runtime = deps();
|
|
@@ -4838,6 +5082,179 @@ test("session transport startup failure cleans the constructed Windows-capable t
|
|
|
4838
5082
|
assert.match((await h.tools.get("orchestrator_session_id")!.execute("id", {}, undefined, undefined, ctx)).content[0].text, /not ready/);
|
|
4839
5083
|
});
|
|
4840
5084
|
|
|
5085
|
+
test("session transport startup failure re-arms exactly once on a later session event", async (t) => {
|
|
5086
|
+
for (const mode of ["recovers", "fails-again", "first-succeeds", "agent-start"] as const) {
|
|
5087
|
+
await t.test(mode, async () => {
|
|
5088
|
+
const h = fakePi(), runtime = deps(), { ctx } = fakeContext();
|
|
5089
|
+
const notices: Array<{ message: string; level: unknown }> = [];
|
|
5090
|
+
ctx.ui.notify = (message, level) => { notices.push({ message, level }); };
|
|
5091
|
+
let registries = 0, starts = 0, closes = 0;
|
|
5092
|
+
const registry = { list: async () => [], listActivations: async () => [] };
|
|
5093
|
+
runtime.deps.sessionTransport = {
|
|
5094
|
+
createRegistry: async () => { registries++; return registry; },
|
|
5095
|
+
createListener: () => ({ registry, start: async () => {
|
|
5096
|
+
starts++;
|
|
5097
|
+
if (mode !== "first-succeeds" && (starts === 1 || mode === "fails-again")) throw new Error("SECRET path token");
|
|
5098
|
+
}, close: async () => { closes++; } }),
|
|
5099
|
+
createClient: inertSessionTransport.createClient,
|
|
5100
|
+
};
|
|
5101
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
5102
|
+
await h.fire("session_start", ctx);
|
|
5103
|
+
const id = async () => (await h.tools.get("orchestrator_session_id")!.execute("id", {}, undefined, undefined, ctx)).content[0].text;
|
|
5104
|
+
const warning = { message: "Session transport startup failed: phase=listener diagnostics=unavailable.", level: "warning" };
|
|
5105
|
+
if (mode === "first-succeeds") {
|
|
5106
|
+
await eventually(() => starts === 1, "first startup");
|
|
5107
|
+
await h.fire("turn_end", ctx);
|
|
5108
|
+
await h.fire("agent_start", ctx);
|
|
5109
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
5110
|
+
assert.equal(registries, 1, "a live transport is never re-armed");
|
|
5111
|
+
assert.deepEqual(notices, []);
|
|
5112
|
+
await h.fire("session_shutdown", ctx);
|
|
5113
|
+
return;
|
|
5114
|
+
}
|
|
5115
|
+
await eventually(() => notices.length === 1 && closes === 1, "first startup failure and cleanup");
|
|
5116
|
+
assert.match(await id(), /not ready/);
|
|
5117
|
+
await h.fire(mode === "agent-start" ? "agent_start" : "turn_end", ctx);
|
|
5118
|
+
await eventually(() => starts === 2, "one re-arm attempt");
|
|
5119
|
+
if (mode === "fails-again") {
|
|
5120
|
+
await eventually(() => notices.length === 2 && closes === 2, "second failure warns again");
|
|
5121
|
+
for (const event of ["turn_end", "agent_start", "turn_end"]) await h.fire(event, ctx);
|
|
5122
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
5123
|
+
assert.equal(registries, 2, "no further retries after the bounded re-arm");
|
|
5124
|
+
assert.deepEqual(notices, [warning, warning]);
|
|
5125
|
+
assert.match(await id(), /not ready/);
|
|
5126
|
+
} else {
|
|
5127
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
5128
|
+
assert.doesNotMatch(await id(), /not ready/, "re-armed transport is active");
|
|
5129
|
+
await h.fire("turn_end", ctx);
|
|
5130
|
+
assert.equal(registries, 2);
|
|
5131
|
+
assert.deepEqual(notices, [warning]);
|
|
5132
|
+
}
|
|
5133
|
+
await h.fire("session_shutdown", ctx);
|
|
5134
|
+
});
|
|
5135
|
+
}
|
|
5136
|
+
});
|
|
5137
|
+
|
|
5138
|
+
test("session transport re-arm stays bounded across shutdown, pending close, and session replacement races", async (t) => {
|
|
5139
|
+
for (const mode of ["shutdown", "close-pending", "session-switch", "changed-id"] as const) {
|
|
5140
|
+
await t.test(mode, async () => {
|
|
5141
|
+
const h = fakePi(), runtime = deps(), { ctx } = fakeContext(), { ctx: other } = fakeContext();
|
|
5142
|
+
Object.assign(other.sessionManager, { getSessionId: () => "s2" });
|
|
5143
|
+
const notices: string[] = [];
|
|
5144
|
+
ctx.ui.notify = (message) => { notices.push(message); };
|
|
5145
|
+
other.ui.notify = (message) => { notices.push(message); };
|
|
5146
|
+
const starts = new Map<string, number>();
|
|
5147
|
+
let registries = 0, closes = 0;
|
|
5148
|
+
let releaseClose: (() => void) | undefined;
|
|
5149
|
+
const closeGate = mode === "close-pending" ? new Promise<void>((resolve) => { releaseClose = resolve; }) : undefined;
|
|
5150
|
+
const registry = { list: async () => [], listActivations: async () => [] };
|
|
5151
|
+
runtime.deps.sessionTransport = {
|
|
5152
|
+
createRegistry: async () => { registries++; return registry; },
|
|
5153
|
+
createListener: (_registry, sessionId) => ({ registry, start: async () => {
|
|
5154
|
+
starts.set(sessionId, (starts.get(sessionId) ?? 0) + 1);
|
|
5155
|
+
throw new Error("SECRET");
|
|
5156
|
+
}, close: async () => { closes++; if (closes === 1) await closeGate; } }),
|
|
5157
|
+
createClient: inertSessionTransport.createClient,
|
|
5158
|
+
};
|
|
5159
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
5160
|
+
await h.fire("session_start", ctx);
|
|
5161
|
+
await eventually(() => notices.length === 1, "first startup failure");
|
|
5162
|
+
const settle = () => new Promise((resolve) => setTimeout(resolve, 20));
|
|
5163
|
+
if (mode === "shutdown") {
|
|
5164
|
+
await Promise.all([h.fire("session_shutdown", ctx), h.fire("agent_start", ctx), h.fire("turn_end", ctx)]);
|
|
5165
|
+
const after = registries;
|
|
5166
|
+
for (const event of ["agent_start", "turn_end"]) await h.fire(event, ctx);
|
|
5167
|
+
await settle();
|
|
5168
|
+
assert.equal(starts.get("s1"), 1, "no listener starts after shutdown");
|
|
5169
|
+
assert.equal(registries, after, "no startup begins after shutdown completed");
|
|
5170
|
+
return;
|
|
5171
|
+
}
|
|
5172
|
+
if (mode === "close-pending") {
|
|
5173
|
+
try {
|
|
5174
|
+
await h.fire("turn_end", ctx);
|
|
5175
|
+
await h.fire("agent_start", ctx);
|
|
5176
|
+
await settle();
|
|
5177
|
+
assert.equal(registries, 1, "no re-arm while the failed startup is still closing");
|
|
5178
|
+
} finally {
|
|
5179
|
+
// A failed assertion must not leave shutdown waiting on the gated close.
|
|
5180
|
+
releaseClose!();
|
|
5181
|
+
}
|
|
5182
|
+
await settle();
|
|
5183
|
+
await h.fire("turn_end", ctx);
|
|
5184
|
+
await eventually(() => starts.get("s1") === 2, "exactly one re-arm after close resolves");
|
|
5185
|
+
await eventually(() => notices.length === 2, "re-arm failure warns");
|
|
5186
|
+
for (const event of ["turn_end", "agent_start"]) await h.fire(event, ctx);
|
|
5187
|
+
await settle();
|
|
5188
|
+
assert.equal(registries, 2);
|
|
5189
|
+
}
|
|
5190
|
+
if (mode === "session-switch") {
|
|
5191
|
+
await settle();
|
|
5192
|
+
await h.fire("session_start", other);
|
|
5193
|
+
await eventually(() => notices.length === 2, "replacement session startup failure");
|
|
5194
|
+
await settle();
|
|
5195
|
+
await h.fire("turn_end", ctx);
|
|
5196
|
+
await h.fire("agent_start", ctx);
|
|
5197
|
+
await settle();
|
|
5198
|
+
assert.equal(starts.get("s1"), 1, "the retired session is never re-armed");
|
|
5199
|
+
assert.equal(starts.get("s2"), 1);
|
|
5200
|
+
await h.fire("turn_end", other);
|
|
5201
|
+
await eventually(() => starts.get("s2") === 2, "the replacement session gets its own single re-arm");
|
|
5202
|
+
await eventually(() => notices.length === 3, "replacement re-arm failure warns");
|
|
5203
|
+
for (const event of ["turn_end", "agent_start"]) await h.fire(event, other);
|
|
5204
|
+
await settle();
|
|
5205
|
+
assert.equal(starts.get("s2"), 2);
|
|
5206
|
+
assert.equal(starts.get("s1"), 1);
|
|
5207
|
+
await h.fire("session_shutdown", other);
|
|
5208
|
+
return;
|
|
5209
|
+
}
|
|
5210
|
+
if (mode === "changed-id") {
|
|
5211
|
+
await settle();
|
|
5212
|
+
Object.assign(ctx.sessionManager, { getSessionId: () => "replacement" });
|
|
5213
|
+
for (const event of ["turn_end", "agent_start"]) await h.fire(event, ctx);
|
|
5214
|
+
await settle();
|
|
5215
|
+
assert.equal(registries, 1, "a changed session id on the same manager is never re-armed");
|
|
5216
|
+
assert.equal(notices.length, 1);
|
|
5217
|
+
}
|
|
5218
|
+
await h.fire("session_shutdown", ctx);
|
|
5219
|
+
});
|
|
5220
|
+
}
|
|
5221
|
+
});
|
|
5222
|
+
|
|
5223
|
+
test("a failed presence start at session_start warns with a fixed code and clears presence", async (t) => {
|
|
5224
|
+
const start = t.mock.method(PresencePublisher, "start", () => { throw new Error("SECRET C:\\Users\\private token"); });
|
|
5225
|
+
const h = fakePi(), runtime = deps(), { ctx } = fakeContext();
|
|
5226
|
+
const notices: Array<{ message: string; level: unknown }> = [];
|
|
5227
|
+
ctx.ui.notify = (message, level) => { notices.push({ message, level }); };
|
|
5228
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
5229
|
+
await h.fire("session_start", ctx);
|
|
5230
|
+
assert.ok(start.mock.callCount() >= 1);
|
|
5231
|
+
assert.deepEqual(notices.filter((notice) => notice.message.includes("presence")), [{ message: "Session presence unavailable: phase=presence class=transport code=presence-cleared.", level: "warning" }]);
|
|
5232
|
+
assert.ok(notices.every((notice) => !notice.message.includes("SECRET")));
|
|
5233
|
+
await h.fire("session_shutdown", ctx);
|
|
5234
|
+
});
|
|
5235
|
+
|
|
5236
|
+
test("Windows bootstrap stderr codes reach the startup warning without raw stderr", async () => {
|
|
5237
|
+
const h = fakePi(), runtime = deps(), { ctx } = fakeContext();
|
|
5238
|
+
const notices: Array<{ message: string; level: unknown }> = [];
|
|
5239
|
+
ctx.ui.notify = (message, level) => { notices.push({ message, level }); };
|
|
5240
|
+
runtime.deps.sessionTransport = {
|
|
5241
|
+
...inertSessionTransport,
|
|
5242
|
+
createRegistry: async (_home, observe, observeBootstrap) => {
|
|
5243
|
+
observeBootstrap?.("rejection-transport-assert-owned");
|
|
5244
|
+
observeBootstrap?.("SECRET stderr" as never);
|
|
5245
|
+
observe?.({ phase: "start", status: "succeeded", error: null, lastStartupMarker: "native-ready" });
|
|
5246
|
+
observe?.({ phase: "initialize", status: "failed", error: { class: "rejected", code: "protocol" }, lastStartupMarker: "native-ready" });
|
|
5247
|
+
observe?.({ phase: "cleanup", status: "succeeded", error: null, lastStartupMarker: "native-ready" });
|
|
5248
|
+
throw new Error("SECRET");
|
|
5249
|
+
},
|
|
5250
|
+
};
|
|
5251
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
5252
|
+
await h.fire("session_start", ctx);
|
|
5253
|
+
await eventually(() => notices.length === 1, "startup warning");
|
|
5254
|
+
await h.fire("session_shutdown", ctx);
|
|
5255
|
+
assert.deepEqual(notices, [{ message: "Session transport startup failed: phase=initialize class=rejected code=protocol lastStartupMarker=native-ready bootstrap=rejection-transport-assert-owned.", level: "warning" }]);
|
|
5256
|
+
});
|
|
5257
|
+
|
|
4841
5258
|
test("registered task aliases persist independently of human names and curated state", async () => {
|
|
4842
5259
|
const h = fakePi(), runtime = deps(), { ctx } = fakeContext();
|
|
4843
5260
|
const timers = recordTimers(runtime.deps);
|
|
@@ -5383,6 +5800,9 @@ test("session transport adds host tools, forwards notifications, and closes on s
|
|
|
5383
5800
|
assert.match((await h.tools.get("orchestrator_list")!.execute("list", {}, undefined, undefined, ctx)).content[0].text, /peer/);
|
|
5384
5801
|
assert.ok(callback, "listener receives the inbound callback");
|
|
5385
5802
|
Object.assign(ctx.sessionManager, { getSessionName: () => "Integration" });
|
|
5803
|
+
// Idle and held routing are covered by the orchestrator delivery tests; a
|
|
5804
|
+
// running parent keeps the original follow-up delivery.
|
|
5805
|
+
await h.fire("agent_start", ctx);
|
|
5386
5806
|
await callback!({ id: "message-1", senderSessionId: "peer", message: "\u001b[31mraw model content" });
|
|
5387
5807
|
assert.equal(h.sent.at(-1)?.message.customType, "gentle-agents.orchestrator-message");
|
|
5388
5808
|
assert.match(String(h.sent.at(-1)?.message.content), /\u001b\[31mraw model content/);
|
|
@@ -5454,7 +5874,7 @@ test("session transport selects a peer for outbound delivery and rejects stale c
|
|
|
5454
5874
|
Object.assign(ctx.sessionManager, { getSessionName: () => "Backend" });
|
|
5455
5875
|
const result = await h.tools.get("orchestrator_send_message")!.execute("send", { message: "hello peer", reason: "because the peer needs an update" }, undefined, undefined, ctx);
|
|
5456
5876
|
assert.deepEqual(dialogs, [
|
|
5457
|
-
"select:Select recipient orchestrator:Orchestrator alpha|Orchestrator beta",
|
|
5877
|
+
"select:Select recipient orchestrator:Orchestrator · alpha|Orchestrator · beta",
|
|
5458
5878
|
"select:Authorize cross-orchestrator message to alpha?\nReason: because the peer needs an update\nMessage: hello peer:Allow once|Allow for this session|Deny",
|
|
5459
5879
|
]);
|
|
5460
5880
|
assert.deepEqual(sent, [{ recipient: "alpha", message: "hello peer", expectedActivation: records[0] }]);
|
|
@@ -5482,6 +5902,95 @@ test("session transport selects a peer for outbound delivery and rejects stale c
|
|
|
5482
5902
|
await h.fire("session_shutdown", ctx);
|
|
5483
5903
|
});
|
|
5484
5904
|
|
|
5905
|
+
test("recipient picker uses published labels and grows the suffix until every label is unique", async () => {
|
|
5906
|
+
const h = fakePi();
|
|
5907
|
+
const runtime = deps();
|
|
5908
|
+
// Three long ids share their last four characters, and two peers share the same
|
|
5909
|
+
// published label, so only a grown suffix can tell the whole list apart.
|
|
5910
|
+
const alphaId = "11111111-1111-4111-8111-11111111abcd";
|
|
5911
|
+
const betaId = "22222222-2222-4222-8222-22222222abcd";
|
|
5912
|
+
const gammaId = "33333333-3333-4333-8333-33333333abcd";
|
|
5913
|
+
const activations: PresenceRecord[] = [
|
|
5914
|
+
{ version: 1, sessionId: alphaId, endpoint: "/alpha.sock", createdAt: 1 },
|
|
5915
|
+
{ version: 1, sessionId: betaId, endpoint: "/beta.sock", createdAt: 2 },
|
|
5916
|
+
{ version: 1, sessionId: gammaId, endpoint: "/gamma.sock", createdAt: 3 },
|
|
5917
|
+
];
|
|
5918
|
+
const profile = realpathSync(mkdtempSync(join(tmpdir(), "gentle-agents-labels-")));
|
|
5919
|
+
const publishers = [
|
|
5920
|
+
PresencePublisher.start({ profile, sessionId: alphaId, label: "api", activity: [] }),
|
|
5921
|
+
PresencePublisher.start({ profile, sessionId: betaId, label: "api", activity: [] }),
|
|
5922
|
+
PresencePublisher.start({ profile, sessionId: gammaId, label: "database", activity: [] }),
|
|
5923
|
+
];
|
|
5924
|
+
publishers[0]!.updateDiscovery(activations[0]!, { workspace: "/repo/api", tasks: [] });
|
|
5925
|
+
publishers[1]!.updateDiscovery(activations[1]!, { workspace: "/repo/api", tasks: [] });
|
|
5926
|
+
publishers[2]!.updateDiscovery(activations[2]!, { workspace: "/repo/melia/db", tasks: [] });
|
|
5927
|
+
const sent: Array<{ recipient: string }> = [];
|
|
5928
|
+
const registry = { list: async () => [], listActivations: async () => activations };
|
|
5929
|
+
runtime.deps.sessionTransport = {
|
|
5930
|
+
createRegistry: async () => registry,
|
|
5931
|
+
createListener: () => ({ registry, start: async () => {}, close: async () => {} }),
|
|
5932
|
+
createClient: () => ({ close: () => {}, sendNotification: async (recipient: string) => { sent.push({ recipient }); return { id: "accepted-1", accepted: true }; } }),
|
|
5933
|
+
} as never;
|
|
5934
|
+
let chosen = 0;
|
|
5935
|
+
const { ctx, dialogs } = fakeContext(undefined, undefined, undefined, undefined, async (title, options) => title.startsWith("Select recipient") ? options[chosen] : options[0]);
|
|
5936
|
+
gentleAgents(h.pi, {}, { ...runtime.deps, agentHome: profile });
|
|
5937
|
+
try {
|
|
5938
|
+
await h.fire("session_start", ctx);
|
|
5939
|
+
const tool = h.tools.get("orchestrator_send_message")!;
|
|
5940
|
+
const params = { message: "hello", reason: "because the peer needs an update" };
|
|
5941
|
+
for (chosen = 0; chosen < 3; chosen += 1) await tool.execute("send", params, undefined, undefined, ctx);
|
|
5942
|
+
} finally {
|
|
5943
|
+
for (const publisher of publishers) publisher.dispose();
|
|
5944
|
+
rmSync(profile, { recursive: true, force: true });
|
|
5945
|
+
}
|
|
5946
|
+
// The published label leads, the workspace basename follows only when it adds
|
|
5947
|
+
// something, and the shared four-character tail forces the suffix to grow to six.
|
|
5948
|
+
assert.equal(dialogs[0], "select:Select recipient orchestrator:api · 11abcd|api · 22abcd|database (db) · 33abcd");
|
|
5949
|
+
assert.deepEqual(sent, [{ recipient: alphaId }, { recipient: betaId }, { recipient: gammaId }], "each displayed label must send to its own session");
|
|
5950
|
+
});
|
|
5951
|
+
|
|
5952
|
+
test("recipient picker keeps one row per session when a transport repeats an activation", async () => {
|
|
5953
|
+
const h = fakePi();
|
|
5954
|
+
const runtime = deps();
|
|
5955
|
+
const alphaId = "11111111-1111-4111-8111-111111111111";
|
|
5956
|
+
const betaId = "22222222-2222-4222-8222-222222222222";
|
|
5957
|
+
// The canonical activation is the one the publication binds to, and it comes last, so a
|
|
5958
|
+
// deduplication that keeps only one record would resolve the label of an ambiguous peer.
|
|
5959
|
+
const activations: PresenceRecord[] = [
|
|
5960
|
+
{ version: 1, sessionId: alphaId, endpoint: "/alpha-again.sock", createdAt: 1 },
|
|
5961
|
+
{ version: 1, sessionId: alphaId, endpoint: "/alpha.sock", createdAt: 2 },
|
|
5962
|
+
{ version: 1, sessionId: betaId, endpoint: "/beta.sock", createdAt: 3 },
|
|
5963
|
+
];
|
|
5964
|
+
const profile = realpathSync(mkdtempSync(join(tmpdir(), "gentle-agents-dedupe-")));
|
|
5965
|
+
const publishers = [
|
|
5966
|
+
PresencePublisher.start({ profile, sessionId: alphaId, label: "api", activity: [] }),
|
|
5967
|
+
PresencePublisher.start({ profile, sessionId: betaId, label: "database", activity: [] }),
|
|
5968
|
+
];
|
|
5969
|
+
publishers[0]!.updateDiscovery(activations[1]!, { workspace: "/repo/api", tasks: [] });
|
|
5970
|
+
publishers[1]!.updateDiscovery(activations[2]!, { workspace: "/repo/melia/db", tasks: [] });
|
|
5971
|
+
const sent: Array<{ recipient: string }> = [];
|
|
5972
|
+
const registry = { list: async () => [], listActivations: async () => activations };
|
|
5973
|
+
runtime.deps.sessionTransport = {
|
|
5974
|
+
createRegistry: async () => registry,
|
|
5975
|
+
createListener: () => ({ registry, start: async () => {}, close: async () => {} }),
|
|
5976
|
+
createClient: () => ({ close: () => {}, sendNotification: async (recipient: string) => { sent.push({ recipient }); return { id: "accepted-1", accepted: true }; } }),
|
|
5977
|
+
} as never;
|
|
5978
|
+
let chosen = 1;
|
|
5979
|
+
const { ctx, dialogs } = fakeContext(undefined, undefined, undefined, undefined, async (title, options) => title.startsWith("Select recipient") ? options[chosen] : options[0]);
|
|
5980
|
+
gentleAgents(h.pi, {}, { ...runtime.deps, agentHome: profile });
|
|
5981
|
+
try {
|
|
5982
|
+
await h.fire("session_start", ctx);
|
|
5983
|
+
await h.tools.get("orchestrator_send_message")!.execute("send", { message: "hello", reason: "because the peer needs an update" }, undefined, undefined, ctx);
|
|
5984
|
+
} finally {
|
|
5985
|
+
for (const publisher of publishers) publisher.dispose();
|
|
5986
|
+
rmSync(profile, { recursive: true, force: true });
|
|
5987
|
+
}
|
|
5988
|
+
// One row per session, and the duplicated session stays unlabelled: discovery still
|
|
5989
|
+
// sees both activations and fails closed instead of guessing which one it is.
|
|
5990
|
+
assert.equal(dialogs[0], "select:Select recipient orchestrator:Orchestrator · 1111|database (db) · 2222");
|
|
5991
|
+
assert.deepEqual(sent, [{ recipient: betaId }], "the second row must still be the second session");
|
|
5992
|
+
});
|
|
5993
|
+
|
|
5485
5994
|
test("all orchestrator tools own compact and expanded card rendering", () => {
|
|
5486
5995
|
const h = fakePi();
|
|
5487
5996
|
gentleAgents(h.pi, {}, deps().deps);
|
|
@@ -5695,7 +6204,7 @@ test("orchestrator_send_message snapshots message and reason before recipient an
|
|
|
5695
6204
|
await eventually(() => dialogs.length === 1, "recipient selector opens");
|
|
5696
6205
|
params.message = "mutated during recipient selection";
|
|
5697
6206
|
params.reason = "mutated reason one";
|
|
5698
|
-
chooseRecipient("Orchestrator alpha");
|
|
6207
|
+
chooseRecipient("Orchestrator · alpha");
|
|
5699
6208
|
await eventually(() => dialogs.length === 2, "consent selector opens");
|
|
5700
6209
|
params.message = "mutated during consent selection";
|
|
5701
6210
|
params.reason = "mutated reason two";
|
|
@@ -6022,6 +6531,104 @@ for (const boundary of ["session_compact", "session_compact_failed"] as const) {
|
|
|
6022
6531
|
});
|
|
6023
6532
|
}
|
|
6024
6533
|
|
|
6534
|
+
// Incoming orchestrator session messages share the child-content delivery
|
|
6535
|
+
// router: an idle parent must be woken through the prompt lifecycle, a busy
|
|
6536
|
+
// run keeps the follow-up route, and a parent compacting without a run holds
|
|
6537
|
+
// the message for the next boundary.
|
|
6538
|
+
async function orchestratorHost() {
|
|
6539
|
+
const host = fakePi();
|
|
6540
|
+
const harness = deps();
|
|
6541
|
+
const timers = recordTimers(harness.deps);
|
|
6542
|
+
let received: ((notification: { id: string; senderSessionId: string; message: string }) => Promise<void>) | undefined;
|
|
6543
|
+
harness.deps.sessionTransport = {
|
|
6544
|
+
...inertSessionTransport,
|
|
6545
|
+
createListener: (registry, _sessionId, callback) => {
|
|
6546
|
+
received = callback;
|
|
6547
|
+
return { registry, start: async () => {}, close: async () => {} };
|
|
6548
|
+
},
|
|
6549
|
+
};
|
|
6550
|
+
gentleAgents(host.pi, {}, harness.deps);
|
|
6551
|
+
const { ctx } = fakeContext();
|
|
6552
|
+
await host.fire("session_start", ctx);
|
|
6553
|
+
await eventually(() => received !== undefined, "session transport listener starts");
|
|
6554
|
+
const notify = (message: string) => received!({ id: "m1", senderSessionId: "peer", message });
|
|
6555
|
+
return { ...host, ctx, timers, notify };
|
|
6556
|
+
}
|
|
6557
|
+
|
|
6558
|
+
test("an orchestrator message to an idle parent is stored without a direct turn and wakes the parent once", async () => {
|
|
6559
|
+
const { fire, ctx, sent, userMessages, delivery, notify } = await orchestratorHost();
|
|
6560
|
+
await notify("hello idle");
|
|
6561
|
+
await tick();
|
|
6562
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }], "the message is stored without triggerTurn");
|
|
6563
|
+
assert.equal(sent[0]!.message.customType, "gentle-agents.orchestrator-message");
|
|
6564
|
+
assert.match(String(sent[0]!.message.content), /hello idle/);
|
|
6565
|
+
assert.equal(userMessages.length, 1, "one wake starts the turn through the prompt lifecycle");
|
|
6566
|
+
assert.doesNotMatch(String(userMessages[0]!.content), /hello idle/, "the wake never repeats the message");
|
|
6567
|
+
assert.deepEqual(delivery, ["custom:gentle-agents.orchestrator-message", "user"]);
|
|
6568
|
+
await fire("session_shutdown", ctx);
|
|
6569
|
+
});
|
|
6570
|
+
|
|
6571
|
+
test("an orchestrator message during a parent run keeps the follow-up route and sends no wake", async () => {
|
|
6572
|
+
const { fire, ctx, sent, userMessages, notify } = await orchestratorHost();
|
|
6573
|
+
await fire("agent_start", ctx);
|
|
6574
|
+
await notify("hello run");
|
|
6575
|
+
await tick();
|
|
6576
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ deliverAs: "followUp", triggerTurn: true }]);
|
|
6577
|
+
assert.equal(userMessages.length, 0);
|
|
6578
|
+
await fire("session_shutdown", ctx);
|
|
6579
|
+
});
|
|
6580
|
+
|
|
6581
|
+
test("an orchestrator message held while the parent compacts is routed after the boundary", async () => {
|
|
6582
|
+
const { fire, ctx, sent, userMessages, delivery, notify, setIdle, timers } = await orchestratorHost();
|
|
6583
|
+
setIdle(false);
|
|
6584
|
+
await notify("hello compaction");
|
|
6585
|
+
await tick();
|
|
6586
|
+
assert.equal(sent.length, 0, "no direct turn starts while the parent compacts");
|
|
6587
|
+
assert.equal(userMessages.length, 0, "no wake is sent while the parent compacts");
|
|
6588
|
+
await fire("session_compact", ctx);
|
|
6589
|
+
setIdle(true);
|
|
6590
|
+
assert.equal(timers.run(0), 1, "one deferred flush is scheduled for the boundary");
|
|
6591
|
+
await tick();
|
|
6592
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }], "the held message is stored without a direct turn");
|
|
6593
|
+
assert.deepEqual(delivery, ["custom:gentle-agents.orchestrator-message", "user"]);
|
|
6594
|
+
await fire("session_shutdown", ctx);
|
|
6595
|
+
});
|
|
6596
|
+
|
|
6597
|
+
test("an orchestrator message held for a busy parent is delivered by the next turn boundary flush", async () => {
|
|
6598
|
+
const { fire, ctx, sent, notify, setIdle } = await orchestratorHost();
|
|
6599
|
+
setIdle(false);
|
|
6600
|
+
await notify("hello hold");
|
|
6601
|
+
assert.equal(sent.length, 0, "nothing is sent while the parent is busy without a run");
|
|
6602
|
+
await fire("agent_start", ctx);
|
|
6603
|
+
await fire("turn_end", ctx);
|
|
6604
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ deliverAs: "followUp", triggerTurn: true }], "a run that started meanwhile receives it as a follow-up");
|
|
6605
|
+
await fire("session_shutdown", ctx);
|
|
6606
|
+
});
|
|
6607
|
+
|
|
6608
|
+
test("an orchestrator message to a parent with a stale context fails delivery so the sender learns", async () => {
|
|
6609
|
+
const { fire, ctx, sent, userMessages, notify } = await orchestratorHost();
|
|
6610
|
+
Object.assign(ctx, { isIdle: () => { throw new Error("This extension ctx is stale after session replacement or reload."); } });
|
|
6611
|
+
await assert.rejects(notify("hello stale"), /stale/);
|
|
6612
|
+
assert.equal(sent.length, 0);
|
|
6613
|
+
assert.equal(userMessages.length, 0);
|
|
6614
|
+
await fire("session_shutdown", ctx);
|
|
6615
|
+
});
|
|
6616
|
+
|
|
6617
|
+
test("a held orchestrator message does not survive a session change", async () => {
|
|
6618
|
+
const { fire, ctx, sent, userMessages, notify, setIdle, timers } = await orchestratorHost();
|
|
6619
|
+
setIdle(false);
|
|
6620
|
+
await notify("hello dropped");
|
|
6621
|
+
await fire("session_start", ctx, { reason: "new" });
|
|
6622
|
+
setIdle(true);
|
|
6623
|
+
await fire("agent_settled", ctx);
|
|
6624
|
+
await fire("session_compact", ctx);
|
|
6625
|
+
timers.run(0);
|
|
6626
|
+
await tick();
|
|
6627
|
+
assert.equal(sent.length, 0, "the old session's held message is not replayed into the new one");
|
|
6628
|
+
assert.equal(userMessages.length, 0);
|
|
6629
|
+
await fire("session_shutdown", ctx);
|
|
6630
|
+
});
|
|
6631
|
+
|
|
6025
6632
|
test("between agent_end and agent_settled the parent run is still active, so child content keeps the steer route", async () => {
|
|
6026
6633
|
const { pi, tools, fire, sent, userMessages } = fakePi();
|
|
6027
6634
|
const harness = deps();
|
|
@@ -6869,6 +7476,11 @@ test("a busy parent gets the exit notice steered into its run at the next turn b
|
|
|
6869
7476
|
await jobIo();
|
|
6870
7477
|
assert.equal(sent.length, 0, "a busy parent is not interrupted mid-tool-call");
|
|
6871
7478
|
await fire("turn_end", ctx);
|
|
7479
|
+
// The notice lands when the job log closes, which can outlast this boundary under load; a later turn boundary then delivers it.
|
|
7480
|
+
for (let boundary = 0; boundary < 40 && sent.length === 0; boundary++) {
|
|
7481
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
7482
|
+
await fire("turn_end", ctx);
|
|
7483
|
+
}
|
|
6872
7484
|
assert.equal(sent.length, 1);
|
|
6873
7485
|
assert.deepEqual(sent[0]!.options, { deliverAs: "steer", triggerTurn: true });
|
|
6874
7486
|
assert.match(String(sent[0]!.message.content), /job-1 \("make build"\) exited with code 0/);
|
|
@@ -6932,7 +7544,8 @@ test("/gentle:jobs opens this session's jobs overlay, stops the selected job, an
|
|
|
6932
7544
|
assert.equal(jobs.runs[0]!.signal?.aborted, true, "s stops the selected job");
|
|
6933
7545
|
assert.equal(statuses.at(-1), undefined, "the footer count clears when nothing runs");
|
|
6934
7546
|
assert.deepEqual(snapshots.at(-1)?.snapshot.jobs.map(({ status }) => status), ["stopped"], "the finished tail keeps the stopped job visible once the count clears");
|
|
6935
|
-
|
|
7547
|
+
// The stop notice follows the job log close, which can outlast a fixed wait under load.
|
|
7548
|
+
await eventually(() => sent.some((entry) => entry.message.customType === "gentle-jobs.notice"), "the stopped job must report its stop notice");
|
|
6936
7549
|
const notices = sent.filter((entry) => entry.message.customType === "gentle-jobs.notice");
|
|
6937
7550
|
assert.equal(notices.length, 1, "the agent was told it would be notified, so a human stop is reported once");
|
|
6938
7551
|
assert.match(String(notices[0]!.message.content), /job-1 \("CI"\) was stopped by the user/);
|
|
@@ -6945,6 +7558,48 @@ test("/gentle:jobs opens this session's jobs overlay, stops the selected job, an
|
|
|
6945
7558
|
}
|
|
6946
7559
|
});
|
|
6947
7560
|
|
|
7561
|
+
test("/gentle:jobs mouse controls route the chosen running job through the existing stop and notice path", async () => {
|
|
7562
|
+
const { pi, tools, commands, fire, sent } = fakePi();
|
|
7563
|
+
const jobs = fakeJobShell();
|
|
7564
|
+
gentleAgents(pi, {}, { ...deps().deps, jobShell: jobs.shell, jobOutputDir: () => jobs.dir });
|
|
7565
|
+
const { ctx, overlays } = fakeContext();
|
|
7566
|
+
try {
|
|
7567
|
+
assert.match(commands.get("gentle:jobs")?.description ?? "", /click.*Stop/i, "command help advertises the explicit mouse control");
|
|
7568
|
+
await fire("session_start", ctx);
|
|
7569
|
+
await tools.get("bash_background")!.execute("b1", { command: "first command", label: "first job" }, undefined, undefined, ctx);
|
|
7570
|
+
await tools.get("bash_background")!.execute("b2", { command: "second command", label: "second job" }, undefined, undefined, ctx);
|
|
7571
|
+
const opened = commands.get("gentle:jobs")!.handler("", ctx);
|
|
7572
|
+
await tick();
|
|
7573
|
+
const overlay = overlays.at(-1)!;
|
|
7574
|
+
const eventFor = (text: string, type: TuiMouseEvent["type"]) => {
|
|
7575
|
+
const lines = overlay.render(100).map(stripAnsi);
|
|
7576
|
+
const y = lines.findIndex((line) => line.includes(text));
|
|
7577
|
+
assert.ok(y >= 0, `Missing ${text}`);
|
|
7578
|
+
const x = visibleWidth(lines[y]!.slice(0, lines[y]!.indexOf(text)));
|
|
7579
|
+
return mouse(type, type === "move" ? "none" : "left", x, y, 100, lines.length);
|
|
7580
|
+
};
|
|
7581
|
+
overlay.handleMouse?.(eventFor("second job", "move"));
|
|
7582
|
+
assert.equal(jobs.runs[0]!.signal?.aborted, false);
|
|
7583
|
+
assert.equal(jobs.runs[1]!.signal?.aborted, false);
|
|
7584
|
+
overlay.handleMouse?.(eventFor("second job", "press"));
|
|
7585
|
+
overlay.handleMouse?.(eventFor("second job", "click"));
|
|
7586
|
+
assert.equal(jobs.runs[1]!.signal?.aborted, false, "selecting a row does not stop it");
|
|
7587
|
+
overlay.handleMouse?.(eventFor("s Stop", "press"));
|
|
7588
|
+
overlay.handleMouse?.(eventFor("s Stop", "click"));
|
|
7589
|
+
assert.equal(jobs.runs[0]!.signal?.aborted, false);
|
|
7590
|
+
assert.equal(jobs.runs[1]!.signal?.aborted, true, "the selected job alone is stopped");
|
|
7591
|
+
await eventually(() => sent.some((entry) => entry.message.customType === "gentle-jobs.notice"), "the stopped job must report its stop notice");
|
|
7592
|
+
const notices = sent.filter((entry) => entry.message.customType === "gentle-jobs.notice");
|
|
7593
|
+
assert.equal(notices.length, 1);
|
|
7594
|
+
assert.match(String(notices[0]!.message.content), /job-2 \("second job"\) was stopped by the user/);
|
|
7595
|
+
overlay.handleInput("q");
|
|
7596
|
+
await opened;
|
|
7597
|
+
} finally {
|
|
7598
|
+
await fire("session_shutdown", ctx);
|
|
7599
|
+
jobs.cleanup();
|
|
7600
|
+
}
|
|
7601
|
+
});
|
|
7602
|
+
|
|
6948
7603
|
test("a job exit notice whose forwarding throws while the parent is idle is retried after the bounded grace", async () => {
|
|
6949
7604
|
const { pi, tools, fire, sent, userMessages } = fakePi();
|
|
6950
7605
|
const harness = deps();
|
|
@@ -6961,9 +7616,13 @@ test("a job exit notice whose forwarding throws while the parent is idle is retr
|
|
|
6961
7616
|
await jobIo();
|
|
6962
7617
|
assert.equal(sent.length, 0);
|
|
6963
7618
|
assert.equal(userMessages.length, 0);
|
|
7619
|
+
assert.equal(sent.length, 0);
|
|
7620
|
+
assert.equal(userMessages.length, 0);
|
|
7621
|
+
// Forwarding keeps throwing until the job settles: the failed flush is what arms the bounded retry.
|
|
7622
|
+
await eventually(() => timers.pending(PARENT_WAKE_GRACE_MS) >= 1, "the failed flush arms the bounded retry timer");
|
|
6964
7623
|
Object.assign(pi, { sendMessage });
|
|
6965
7624
|
// No turn boundary is coming for an idle parent, so the retry is a timer.
|
|
6966
|
-
assert.equal(timers.run(PARENT_WAKE_GRACE_MS), 1, "one bounded retry flush is armed");
|
|
7625
|
+
assert.equal(timers.run(PARENT_WAKE_GRACE_MS), 1, "exactly one bounded retry flush is armed");
|
|
6967
7626
|
await tick();
|
|
6968
7627
|
const notices = sent.filter((entry) => entry.message.customType === "gentle-jobs.notice");
|
|
6969
7628
|
assert.equal(notices.length, 1, "the requeued notice reaches the idle parent");
|
|
@@ -6998,7 +7657,8 @@ for (const boundary of ["session_compact", "session_compact_failed"] as const) {
|
|
|
6998
7657
|
assert.equal(sent.length, 0, "the boundary handler runs before Pi leaves the compacting state");
|
|
6999
7658
|
setIdle(true);
|
|
7000
7659
|
assert.equal(timers.run(0), 1, "one deferred flush is scheduled for the compaction boundary");
|
|
7001
|
-
|
|
7660
|
+
// The flush only succeeds once the job log close settles, which can outlast the boundary under load.
|
|
7661
|
+
await eventually(() => sent.length >= 1, "the held notice is flushed after the compaction boundary");
|
|
7002
7662
|
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }], "the held notice is stored without a direct turn");
|
|
7003
7663
|
assert.deepEqual(delivery, ["custom:gentle-jobs.notice", "user"], "one wake follows the held notice");
|
|
7004
7664
|
} finally {
|
|
@@ -7067,7 +7727,8 @@ test("monitor delivers line events to an idle parent with one wake, and reports
|
|
|
7067
7727
|
assert.match(renderers.get("gentle-jobs.notice")!(events[0]!.message, { expanded: true }, plainTheme).render(70).map(stripAnsi).join("\n"), /unit: fail/);
|
|
7068
7728
|
jobs.runs[0]!.onData(Buffer.from("e2e: pass\n"));
|
|
7069
7729
|
jobs.runs[0]!.exit(1);
|
|
7070
|
-
|
|
7730
|
+
// Pending lines and the end notice follow the job log close, which can outlast a fixed wait under load.
|
|
7731
|
+
await eventually(() => sent.filter((entry) => entry.message.customType === "gentle-jobs.notice").length >= 3, "the closed monitor log must deliver its pending lines and end notice");
|
|
7071
7732
|
const contents = sent.filter((entry) => entry.message.customType === "gentle-jobs.notice").map((entry) => String(entry.message.content));
|
|
7072
7733
|
assert.equal(contents.length, 3, "pending lines are delivered before the end notice");
|
|
7073
7734
|
assert.match(contents[1]!, /reported 1 new line:\ne2e: pass/);
|
|
@@ -7190,6 +7851,160 @@ test("a human stop of a monitor from /gentle:jobs delivers its pending lines, th
|
|
|
7190
7851
|
}
|
|
7191
7852
|
});
|
|
7192
7853
|
|
|
7854
|
+
// gentle-shell#626: the herdr pane stays busy while owned background subagents
|
|
7855
|
+
// of the active session run, even after the parent itself settles. Mirrors the
|
|
7856
|
+
// pi-subagents edge-triggered herdr producer exactly.
|
|
7857
|
+
const busyEvents = (h: ReturnType<typeof fakePi>) => h.events.filter((entry) => entry.name === "herdr:busy").map((entry) => entry.data);
|
|
7858
|
+
|
|
7859
|
+
test("herdr:busy follows owned background subagents, not the parent run", async () => {
|
|
7860
|
+
const h = fakePi();
|
|
7861
|
+
const runtime = deps();
|
|
7862
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
7863
|
+
const { ctx } = fakeContext();
|
|
7864
|
+
await h.fire("session_start", ctx);
|
|
7865
|
+
assert.deepEqual(busyEvents(h), [], "no busy event before any subagent work");
|
|
7866
|
+
|
|
7867
|
+
await h.tools.get("subagent_run")!.execute("busy-a", { agent: "explore", task: "Map one", mode: "background" }, undefined, undefined, ctx);
|
|
7868
|
+
await tick();
|
|
7869
|
+
assert.deepEqual(busyEvents(h), [{ active: true, label: "1 subagent running" }]);
|
|
7870
|
+
|
|
7871
|
+
await h.tools.get("subagent_run")!.execute("busy-b", { agent: "explore", task: "Map two", mode: "background" }, undefined, undefined, ctx);
|
|
7872
|
+
await tick();
|
|
7873
|
+
assert.deepEqual(busyEvents(h), [
|
|
7874
|
+
{ active: true, label: "1 subagent running" },
|
|
7875
|
+
{ active: false },
|
|
7876
|
+
{ active: true, label: "2 subagents running" },
|
|
7877
|
+
], "a label change emits the lower before the raise, in one step");
|
|
7878
|
+
|
|
7879
|
+
// The parent's own run settling must not drop busy while children still run.
|
|
7880
|
+
const raised = busyEvents(h).length;
|
|
7881
|
+
await h.fire("agent_start", ctx);
|
|
7882
|
+
await h.fire("agent_settled", ctx);
|
|
7883
|
+
assert.equal(busyEvents(h).length, raised, "an idle parent never lowers busy while a child still runs");
|
|
7884
|
+
|
|
7885
|
+
runtime.children[0].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "one" }] }] });
|
|
7886
|
+
runtime.children[0].emit({ type: "agent_settled" });
|
|
7887
|
+
await tick();
|
|
7888
|
+
assert.deepEqual(busyEvents(h).slice(-2), [{ active: false }, { active: true, label: "1 subagent running" }], "the first settlement relabels with lower then raise");
|
|
7889
|
+
|
|
7890
|
+
runtime.children[1].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "two" }] }] });
|
|
7891
|
+
runtime.children[1].emit({ type: "agent_settled" });
|
|
7892
|
+
await tick();
|
|
7893
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: false }, "the last settlement lowers busy exactly once");
|
|
7894
|
+
const lowered = busyEvents(h).length;
|
|
7895
|
+
await tick();
|
|
7896
|
+
assert.equal(busyEvents(h).length, lowered, "no stale busy after the last settlement");
|
|
7897
|
+
});
|
|
7898
|
+
|
|
7899
|
+
test("herdr:busy lowers on failure and cancellation", async () => {
|
|
7900
|
+
const h = fakePi();
|
|
7901
|
+
const runtime = deps();
|
|
7902
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
7903
|
+
const { ctx } = fakeContext();
|
|
7904
|
+
await h.fire("session_start", ctx);
|
|
7905
|
+
|
|
7906
|
+
await h.tools.get("subagent_run")!.execute("busy-fail", { agent: "explore", task: "Fail", mode: "background" }, undefined, undefined, ctx);
|
|
7907
|
+
await tick();
|
|
7908
|
+
assert.deepEqual(busyEvents(h), [{ active: true, label: "1 subagent running" }]);
|
|
7909
|
+
runtime.children[0].fail("boom");
|
|
7910
|
+
await tick();
|
|
7911
|
+
assert.deepEqual(busyEvents(h), [{ active: true, label: "1 subagent running" }, { active: false }], "a failed child lowers busy");
|
|
7912
|
+
|
|
7913
|
+
const cancelled = await h.tools.get("subagent_run")!.execute("busy-cancel", { agent: "explore", task: "Cancel me", mode: "background" }, undefined, undefined, ctx);
|
|
7914
|
+
await tick();
|
|
7915
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: true, label: "1 subagent running" });
|
|
7916
|
+
const cancelId = (cancelled.details.gentleAgents as { taskId: string }).taskId;
|
|
7917
|
+
await h.tools.get("subagent_cancel")!.execute("busy-stop", { task_id: cancelId }, undefined, undefined, ctx);
|
|
7918
|
+
await tick();
|
|
7919
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: false }, "a cancelled task lowers busy");
|
|
7920
|
+
});
|
|
7921
|
+
|
|
7922
|
+
test("herdr:busy restores on session_start and lowers on session_shutdown", async () => {
|
|
7923
|
+
const h = fakePi();
|
|
7924
|
+
const runtime = deps();
|
|
7925
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
7926
|
+
const { ctx } = fakeContext();
|
|
7927
|
+
await h.fire("session_start", ctx);
|
|
7928
|
+
|
|
7929
|
+
await h.tools.get("subagent_run")!.execute("busy-edge", { agent: "explore", task: "Map", mode: "background" }, undefined, undefined, ctx);
|
|
7930
|
+
await tick();
|
|
7931
|
+
assert.deepEqual(busyEvents(h), [{ active: true, label: "1 subagent running" }]);
|
|
7932
|
+
|
|
7933
|
+
// A reload of the same session keeps the pane busy: the consumer already
|
|
7934
|
+
// holds the raise, so the unchanged label dedups to nothing.
|
|
7935
|
+
await h.fire("session_start", ctx, { reason: "reload" });
|
|
7936
|
+
assert.deepEqual(busyEvents(h), [{ active: true, label: "1 subagent running" }], "reload neither duplicates nor drops the raise");
|
|
7937
|
+
|
|
7938
|
+
// Switching to a session that owns no running work lowers busy.
|
|
7939
|
+
const other = fakeContext();
|
|
7940
|
+
other.ctx.sessionManager = { ...other.ctx.sessionManager, getSessionId: () => "s2" };
|
|
7941
|
+
await h.fire("session_start", other.ctx, { reason: "new" });
|
|
7942
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: false }, "a session without owned running work is not busy");
|
|
7943
|
+
|
|
7944
|
+
// Resuming the original session restores busy from its still-running child.
|
|
7945
|
+
await h.fire("session_start", ctx, { reason: "resume" });
|
|
7946
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: true, label: "1 subagent running" }, "session_start restores busy for owned running work");
|
|
7947
|
+
|
|
7948
|
+
await h.fire("session_shutdown", ctx);
|
|
7949
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: false }, "session_shutdown lowers busy");
|
|
7950
|
+
const lowered = busyEvents(h).length;
|
|
7951
|
+
await tick();
|
|
7952
|
+
assert.equal(busyEvents(h).length, lowered, "no busy event trails the shutdown lower");
|
|
7953
|
+
});
|
|
7954
|
+
|
|
7955
|
+
test("herdr:busy ignores a disk-restored running task via the ownership filter", async () => {
|
|
7956
|
+
const h = fakePi();
|
|
7957
|
+
const runtime = deps();
|
|
7958
|
+
const historyHome = join(root, "busy-restore-history-home");
|
|
7959
|
+
const restored: TaskRecord = { id: "busy-restored", agent: "explore", mode: "background", prompt: "p", label: "p", cwd, parentSessionId: "busy-restore-session", status: TASK_STATUS.RUNNING, createdAt: 1, startedAt: 1, endedAt: null, model: "m", thinking: undefined, sessionPath: null, error: null, result: null, lastStep: "running", lastActivityAt: 1, turns: 1, toolCalls: 0, tokens: 0, cost: 0 };
|
|
7960
|
+
await saveTask(historyDir(historyHome), restored, emptyThread());
|
|
7961
|
+
runtime.deps.home = historyHome;
|
|
7962
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
7963
|
+
const { ctx } = fakeContext();
|
|
7964
|
+
ctx.sessionManager.getSessionId = () => "busy-restore-session";
|
|
7965
|
+
await h.fire("session_start", ctx, { reason: "resume" });
|
|
7966
|
+
|
|
7967
|
+
// Pull the task from disk into the store: it lands in restoredTaskIds,
|
|
7968
|
+
// never ownedTaskIds, so the pane must stay quiet -- it is not live work
|
|
7969
|
+
// this runtime owns, and counting it would report busy for work that no
|
|
7970
|
+
// longer exists.
|
|
7971
|
+
await h.tools.get("subagent_status")!.execute("status", { task_id: "busy-restored" }, undefined, undefined, ctx);
|
|
7972
|
+
await tick();
|
|
7973
|
+
assert.deepEqual(busyEvents(h), [], "a disk-restored running task never raises busy");
|
|
7974
|
+
await h.fire("session_shutdown", ctx);
|
|
7975
|
+
});
|
|
7976
|
+
|
|
7977
|
+
test("herdr:busy treats an empty session id as no active session", async () => {
|
|
7978
|
+
const h = fakePi();
|
|
7979
|
+
const runtime = deps();
|
|
7980
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
7981
|
+
const { ctx } = fakeContext();
|
|
7982
|
+
ctx.sessionManager.getSessionId = () => "";
|
|
7983
|
+
await h.fire("session_start", ctx);
|
|
7984
|
+
|
|
7985
|
+
// An empty session id has no session profile authority, so the launch is
|
|
7986
|
+
// rejected before it becomes owned work and busy is never raised.
|
|
7987
|
+
await assert.rejects(
|
|
7988
|
+
h.tools.get("subagent_run")!.execute("busy-blank", { agent: "explore", task: "Map", mode: "background" }, undefined, undefined, ctx),
|
|
7989
|
+
/Session profile authority unavailable/,
|
|
7990
|
+
);
|
|
7991
|
+
await tick();
|
|
7992
|
+
assert.deepEqual(busyEvents(h), [], "an empty session id never raises busy");
|
|
7993
|
+
|
|
7994
|
+
// A busy state raised by a real session must lower once the active session
|
|
7995
|
+
// id becomes empty, even though the blank session still owns running work.
|
|
7996
|
+
const real = fakeContext();
|
|
7997
|
+
await h.fire("session_start", real.ctx, { reason: "new" });
|
|
7998
|
+
await h.tools.get("subagent_run")!.execute("busy-real", { agent: "explore", task: "Map", mode: "background" }, undefined, undefined, real.ctx);
|
|
7999
|
+
await tick();
|
|
8000
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: true, label: "1 subagent running" });
|
|
8001
|
+
await h.fire("session_start", ctx, { reason: "resume" });
|
|
8002
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: false }, "an empty session id lowers already-raised busy");
|
|
8003
|
+
const lowered = busyEvents(h).length;
|
|
8004
|
+
await tick();
|
|
8005
|
+
assert.equal(busyEvents(h).length, lowered, "an empty session id never re-raises busy");
|
|
8006
|
+
});
|
|
8007
|
+
|
|
7193
8008
|
// Harness roadmap T6: todo progress reaches peers without a model turn spent on
|
|
7194
8009
|
// orchestrator_session_id, and never replaces the owner's curated fields.
|
|
7195
8010
|
test("todo progress publishes merged into the owner's curated state, only for this session", async () => {
|
|
@@ -7519,3 +8334,246 @@ test("the orchestrator's usage limit moves the session to the profile's orchestr
|
|
|
7519
8334
|
const child = await run({ GENTLE_PI_AGENTS_CHILD: "1" });
|
|
7520
8335
|
assert.deepEqual(child.selected, [], "a child leaves its fallback to the parent's runner");
|
|
7521
8336
|
});
|
|
8337
|
+
|
|
8338
|
+
// Held content is released by lifecycle events (the fast path), and by a
|
|
8339
|
+
// held-only re-check that does not depend on any event: a cancelled `/tree`
|
|
8340
|
+
// summarization emits none.
|
|
8341
|
+
test("session_tree releases content held while the parent summarized a branch", async () => {
|
|
8342
|
+
const { fire, ctx, sent, userMessages, notify, setIdle, timers } = await orchestratorHost();
|
|
8343
|
+
setIdle(false);
|
|
8344
|
+
await notify("hello tree");
|
|
8345
|
+
assert.equal(sent.length, 0, "nothing is sent while the parent is busy without a run");
|
|
8346
|
+
await fire("session_tree", ctx);
|
|
8347
|
+
setIdle(true);
|
|
8348
|
+
assert.equal(timers.run(0), 1, "one deferred flush is scheduled for the tree boundary");
|
|
8349
|
+
await tick();
|
|
8350
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }]);
|
|
8351
|
+
assert.equal(userMessages.length, 1, "one wake follows the held content");
|
|
8352
|
+
await fire("session_shutdown", ctx);
|
|
8353
|
+
});
|
|
8354
|
+
|
|
8355
|
+
test("a held-only re-check releases content when the busy state ends without any event", async () => {
|
|
8356
|
+
const { fire, ctx, sent, userMessages, notify, setIdle, timers } = await orchestratorHost();
|
|
8357
|
+
setIdle(false);
|
|
8358
|
+
await notify("hello cancelled summary");
|
|
8359
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 1, "holding content arms exactly one re-check");
|
|
8360
|
+
assert.equal(timers.run(HOLD_RECHECK_MS), 1);
|
|
8361
|
+
assert.equal(sent.length, 0, "still busy: nothing is delivered");
|
|
8362
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 1, "a still-busy parent keeps one re-check armed");
|
|
8363
|
+
setIdle(true);
|
|
8364
|
+
assert.equal(timers.run(HOLD_RECHECK_MS), 1);
|
|
8365
|
+
await tick();
|
|
8366
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }]);
|
|
8367
|
+
assert.equal(userMessages.length, 1);
|
|
8368
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "the re-check stops once the content was delivered");
|
|
8369
|
+
await fire("session_shutdown", ctx);
|
|
8370
|
+
});
|
|
8371
|
+
|
|
8372
|
+
test("the held-only re-check also releases child completions and child messages", async () => {
|
|
8373
|
+
const { pi, tools, fire, sent, userMessages, setIdle } = fakePi();
|
|
8374
|
+
const harness = deps();
|
|
8375
|
+
const timers = recordTimers(harness.deps);
|
|
8376
|
+
gentleAgents(pi, {}, harness.deps);
|
|
8377
|
+
const { ctx } = fakeContext();
|
|
8378
|
+
await fire("session_start", ctx);
|
|
8379
|
+
await tools.get("subagent_run")!.execute("c1", { agent: "explore", task: "Asks while busy", mode: "background" }, undefined, undefined, ctx);
|
|
8380
|
+
await tools.get("subagent_run")!.execute("c2", { agent: "explore", task: "Ends while busy", mode: "background" }, undefined, undefined, ctx);
|
|
8381
|
+
await tick();
|
|
8382
|
+
// The runner's own clock tick shares HOLD_RECHECK_MS, so count against it.
|
|
8383
|
+
const clockTicks = timers.pending(HOLD_RECHECK_MS);
|
|
8384
|
+
setIdle(false);
|
|
8385
|
+
harness.children[0].message({ id: "q1", kind: "query", message: "Which branch?" });
|
|
8386
|
+
harness.children[1].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "done" }] }] });
|
|
8387
|
+
harness.children[1].emit({ type: "agent_settled" });
|
|
8388
|
+
await tick();
|
|
8389
|
+
assert.equal(sent.length, 0);
|
|
8390
|
+
const armed = timers.pending(HOLD_RECHECK_MS) - clockTicks;
|
|
8391
|
+
assert.equal(armed, 1, "held child content arms exactly one re-check");
|
|
8392
|
+
setIdle(true);
|
|
8393
|
+
timers.run(HOLD_RECHECK_MS);
|
|
8394
|
+
await tick();
|
|
8395
|
+
assert.equal(sent.length, 2, "the query and the completion are both delivered");
|
|
8396
|
+
assert.equal(userMessages.length, 1);
|
|
8397
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS) <= clockTicks, true, "the re-check stops once the content was delivered");
|
|
8398
|
+
await fire("session_shutdown", ctx);
|
|
8399
|
+
});
|
|
8400
|
+
|
|
8401
|
+
test("a completion re-queued after a failed forward still arms the held-only re-check", async () => {
|
|
8402
|
+
const { pi, tools, fire, sent, setIdle } = fakePi();
|
|
8403
|
+
const harness = deps();
|
|
8404
|
+
const timers = recordTimers(harness.deps);
|
|
8405
|
+
gentleAgents(pi, {}, harness.deps);
|
|
8406
|
+
const { ctx } = fakeContext();
|
|
8407
|
+
await fire("session_start", ctx);
|
|
8408
|
+
await tools.get("subagent_run")!.execute("c1", { agent: "explore", task: "Fails to forward", mode: "background" }, undefined, undefined, ctx);
|
|
8409
|
+
await tick();
|
|
8410
|
+
const sendMessage = pi.sendMessage;
|
|
8411
|
+
Object.assign(pi, { sendMessage: () => { throw new Error("host busy"); } });
|
|
8412
|
+
harness.children[0].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "Requeued answer." }] }] });
|
|
8413
|
+
harness.children[0].emit({ type: "agent_settled" });
|
|
8414
|
+
await tick();
|
|
8415
|
+
assert.equal(sent.length, 0, "the idle forward failed and the completion was re-queued");
|
|
8416
|
+
Object.assign(pi, { sendMessage });
|
|
8417
|
+
// The runner's own clock tick shares HOLD_RECHECK_MS, so count against it.
|
|
8418
|
+
const clockTicks = timers.pending(HOLD_RECHECK_MS);
|
|
8419
|
+
// The bounded retry fires while the parent compacts without a run, so the
|
|
8420
|
+
// re-queued completion is held and only the re-check can release it.
|
|
8421
|
+
setIdle(false);
|
|
8422
|
+
assert.equal(timers.run(PARENT_WAKE_GRACE_MS), 1, "the idle failure armed one bounded retry");
|
|
8423
|
+
await tick();
|
|
8424
|
+
assert.equal(sent.length, 0, "still busy: nothing is delivered");
|
|
8425
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS) - clockTicks, 1, "the re-queued completion arms exactly one re-check");
|
|
8426
|
+
setIdle(true);
|
|
8427
|
+
timers.run(HOLD_RECHECK_MS);
|
|
8428
|
+
await tick();
|
|
8429
|
+
const results = sent.filter((entry) => entry.message.customType === "gentle-agents.result");
|
|
8430
|
+
assert.equal(results.length, 1, "the re-check delivers the re-queued completion");
|
|
8431
|
+
assert.match(String(results[0]!.message.content), /Requeued answer\./);
|
|
8432
|
+
await fire("session_shutdown", ctx);
|
|
8433
|
+
});
|
|
8434
|
+
|
|
8435
|
+
test("no held-only re-check is armed when nothing is held", async () => {
|
|
8436
|
+
const { fire, ctx, notify, setIdle, timers } = await orchestratorHost();
|
|
8437
|
+
setIdle(false);
|
|
8438
|
+
await fire("turn_end", ctx);
|
|
8439
|
+
await fire("session_tree", ctx);
|
|
8440
|
+
timers.run(0);
|
|
8441
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "a busy parent with nothing held is never polled");
|
|
8442
|
+
setIdle(true);
|
|
8443
|
+
await notify("hello idle");
|
|
8444
|
+
await tick();
|
|
8445
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "an idle parent is never polled");
|
|
8446
|
+
await fire("agent_start", ctx);
|
|
8447
|
+
await notify("hello run");
|
|
8448
|
+
await tick();
|
|
8449
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "a running parent is never polled");
|
|
8450
|
+
await fire("session_shutdown", ctx);
|
|
8451
|
+
});
|
|
8452
|
+
|
|
8453
|
+
test("a boundary flush that delivers held content cancels the re-check", async () => {
|
|
8454
|
+
const { fire, ctx, sent, notify, setIdle, timers } = await orchestratorHost();
|
|
8455
|
+
setIdle(false);
|
|
8456
|
+
await notify("hello boundary");
|
|
8457
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 1);
|
|
8458
|
+
await fire("agent_start", ctx);
|
|
8459
|
+
await fire("turn_end", ctx);
|
|
8460
|
+
assert.equal(sent.length, 1, "the boundary flush delivered the held message");
|
|
8461
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "nothing is left to re-check");
|
|
8462
|
+
await fire("session_shutdown", ctx);
|
|
8463
|
+
});
|
|
8464
|
+
|
|
8465
|
+
test("a session change cancels the held-only re-check and drops the held content", async () => {
|
|
8466
|
+
const { fire, ctx, sent, notify, setIdle, timers } = await orchestratorHost();
|
|
8467
|
+
setIdle(false);
|
|
8468
|
+
await notify("hello replaced");
|
|
8469
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 1);
|
|
8470
|
+
await fire("session_start", fakeContext().ctx);
|
|
8471
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "the old session's re-check is cancelled");
|
|
8472
|
+
setIdle(true);
|
|
8473
|
+
timers.run(HOLD_RECHECK_MS);
|
|
8474
|
+
await tick();
|
|
8475
|
+
assert.equal(sent.length, 0, "the old session's message is not replayed into the new one");
|
|
8476
|
+
await fire("session_shutdown", ctx);
|
|
8477
|
+
});
|
|
8478
|
+
|
|
8479
|
+
// A user prompt is "starting" from `input` until `before_agent_start`, while
|
|
8480
|
+
// the host still reports idle. A wake dispatched in that window races the
|
|
8481
|
+
// user's prompt into Agent.prompt().
|
|
8482
|
+
test("content stored while a user prompt is starting sends no wake and rides that prompt's run", async () => {
|
|
8483
|
+
const { fire, ctx, sent, userMessages, notify, timers } = await orchestratorHost();
|
|
8484
|
+
await fire("input", ctx, { type: "input", text: "hi", source: "interactive" });
|
|
8485
|
+
assert.equal(timers.pending(INPUT_PROMPT_GRACE_MS), 1, "the starting prompt is bounded by its own grace");
|
|
8486
|
+
await notify("hello starting");
|
|
8487
|
+
await tick();
|
|
8488
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }], "the message is stored");
|
|
8489
|
+
assert.equal(userMessages.length, 0, "no wake races the starting prompt");
|
|
8490
|
+
await fire("before_agent_start", ctx, { prompt: "hi" });
|
|
8491
|
+
await fire("agent_start", ctx);
|
|
8492
|
+
assert.equal(timers.pending(INPUT_PROMPT_GRACE_MS), 0);
|
|
8493
|
+
assert.equal(timers.pending(PARENT_WAKE_GRACE_MS), 0);
|
|
8494
|
+
await fire("agent_settled", ctx);
|
|
8495
|
+
await tick();
|
|
8496
|
+
assert.equal(userMessages.length, 0, "the run that started carried the content, so no wake is owed");
|
|
8497
|
+
await fire("session_shutdown", ctx);
|
|
8498
|
+
});
|
|
8499
|
+
|
|
8500
|
+
test("an input that never starts a run lets the owed wake go out after INPUT_PROMPT_GRACE_MS", async () => {
|
|
8501
|
+
const { fire, ctx, userMessages, notify, timers } = await orchestratorHost();
|
|
8502
|
+
await fire("input", ctx, { type: "input", text: "handled elsewhere", source: "interactive" });
|
|
8503
|
+
await notify("hello expired");
|
|
8504
|
+
await tick();
|
|
8505
|
+
assert.equal(userMessages.length, 0);
|
|
8506
|
+
assert.equal(timers.run(INPUT_PROMPT_GRACE_MS), 1);
|
|
8507
|
+
await tick();
|
|
8508
|
+
assert.equal(userMessages.length, 1, "the owed wake is sent once the starting state expires");
|
|
8509
|
+
await fire("session_shutdown", ctx);
|
|
8510
|
+
});
|
|
8511
|
+
|
|
8512
|
+
// A dispatched wake is itself a prompt: it reaches `input` too. That must not
|
|
8513
|
+
// shorten the wake's own PARENT_WAKE_GRACE_MS window to INPUT_PROMPT_GRACE_MS,
|
|
8514
|
+
// or content arriving while the wake is still in its pre-run phase would send
|
|
8515
|
+
// a second wake that races the first into Agent.prompt().
|
|
8516
|
+
test("the dispatched wake's own input does not shorten its start window", async () => {
|
|
8517
|
+
const { fire, ctx, userMessages, notify, timers } = await orchestratorHost();
|
|
8518
|
+
await notify("first");
|
|
8519
|
+
await tick();
|
|
8520
|
+
assert.equal(userMessages.length, 1, "the idle wake is dispatched");
|
|
8521
|
+
await fire("input", ctx, { type: "input", text: String(userMessages[0]!.content), source: "extension" });
|
|
8522
|
+
await notify("second");
|
|
8523
|
+
await tick();
|
|
8524
|
+
timers.run(INPUT_PROMPT_GRACE_MS);
|
|
8525
|
+
await tick();
|
|
8526
|
+
assert.equal(userMessages.length, 1, "no second wake while the first is still starting");
|
|
8527
|
+
assert.equal(timers.pending(PARENT_WAKE_GRACE_MS), 1, "the wake keeps its own start window");
|
|
8528
|
+
await fire("session_shutdown", ctx);
|
|
8529
|
+
});
|
|
8530
|
+
|
|
8531
|
+
test("an input during a run or with a streaming behavior changes nothing", async () => {
|
|
8532
|
+
const { fire, ctx, userMessages, notify, timers } = await orchestratorHost();
|
|
8533
|
+
await fire("input", ctx, { type: "input", text: "queued", source: "interactive", streamingBehavior: "steer" });
|
|
8534
|
+
assert.equal(timers.pending(INPUT_PROMPT_GRACE_MS), 0, "a queued input is not a starting prompt");
|
|
8535
|
+
await notify("hello idle");
|
|
8536
|
+
await tick();
|
|
8537
|
+
assert.equal(userMessages.length, 1, "the idle wake is unaffected");
|
|
8538
|
+
await fire("agent_start", ctx);
|
|
8539
|
+
await fire("input", ctx, { type: "input", text: "mid-run", source: "interactive" });
|
|
8540
|
+
assert.equal(timers.pending(INPUT_PROMPT_GRACE_MS), 0, "an input during a run is not a starting prompt");
|
|
8541
|
+
await fire("session_shutdown", ctx);
|
|
8542
|
+
});
|
|
8543
|
+
|
|
8544
|
+
// A job notice is held content too: one stored while the parent is busy
|
|
8545
|
+
// without a run (a cancelled `/tree` summarization emits no event) must arm the
|
|
8546
|
+
// held-only re-check like any other held content.
|
|
8547
|
+
test("a job notice held for a parent busy without a run is delivered by the held-only re-check", async () => {
|
|
8548
|
+
const { pi, tools, fire, sent, userMessages, setIdle } = fakePi();
|
|
8549
|
+
const jobs = fakeJobShell();
|
|
8550
|
+
const harness = deps();
|
|
8551
|
+
const timers = recordTimers(harness.deps);
|
|
8552
|
+
gentleAgents(pi, {}, { ...harness.deps, jobShell: jobs.shell, jobOutputDir: () => jobs.dir });
|
|
8553
|
+
const { ctx } = fakeContext();
|
|
8554
|
+
try {
|
|
8555
|
+
await fire("session_start", ctx);
|
|
8556
|
+
await tools.get("bash_background")!.execute("b1", { command: "make build" }, undefined, undefined, ctx);
|
|
8557
|
+
// The runner's own clock tick shares HOLD_RECHECK_MS, so count against it.
|
|
8558
|
+
const clockTicks = timers.pending(HOLD_RECHECK_MS);
|
|
8559
|
+
setIdle(false);
|
|
8560
|
+
jobs.runs[0]!.exit(0);
|
|
8561
|
+
await jobIo();
|
|
8562
|
+
assert.equal(sent.length, 0, "a parent busy without a run gets nothing yet");
|
|
8563
|
+
// The notice arms the re-check when the job settles, which can outlast a fixed wait under load.
|
|
8564
|
+
await eventually(() => timers.pending(HOLD_RECHECK_MS) > clockTicks, "the held job notice arms the re-check once it settles");
|
|
8565
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS) - clockTicks, 1, "the held job notice arms exactly one re-check");
|
|
8566
|
+
setIdle(true);
|
|
8567
|
+
timers.run(HOLD_RECHECK_MS);
|
|
8568
|
+
await tick();
|
|
8569
|
+
const notices = sent.filter((entry) => entry.message.customType === "gentle-jobs.notice");
|
|
8570
|
+
assert.equal(notices.length, 1, "the re-check delivers the held job notice");
|
|
8571
|
+
assert.deepEqual(notices[0]!.options, { triggerTurn: false });
|
|
8572
|
+
assert.match(String(notices[0]!.message.content), /job-1 \("make build"\) exited with code 0/);
|
|
8573
|
+
assert.equal(userMessages.length, 1, "one wake follows the notice");
|
|
8574
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS) <= clockTicks, true, "the re-check stops once the notice was delivered");
|
|
8575
|
+
} finally {
|
|
8576
|
+
await fire("session_shutdown", ctx);
|
|
8577
|
+
jobs.cleanup();
|
|
8578
|
+
}
|
|
8579
|
+
});
|