oh-my-codex 0.21.47 → 0.22.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/Cargo.lock +6 -6
- package/Cargo.toml +1 -1
- package/README.md +15 -0
- package/crates/omx-mux/src/herdr.rs +481 -0
- package/crates/omx-mux/src/lib.rs +5 -0
- package/dist/cli/__tests__/plugin-cache-live-pin-3790.test.js +707 -47
- package/dist/cli/__tests__/plugin-cache-live-pin-3790.test.js.map +1 -1
- package/dist/cli/__tests__/session-compare.test.d.ts +2 -0
- package/dist/cli/__tests__/session-compare.test.d.ts.map +1 -0
- package/dist/cli/__tests__/session-compare.test.js +183 -0
- package/dist/cli/__tests__/session-compare.test.js.map +1 -0
- package/dist/cli/__tests__/setup-install-mode.test.js +7 -1
- package/dist/cli/__tests__/setup-install-mode.test.js.map +1 -1
- package/dist/cli/__tests__/team.test.js +8 -0
- package/dist/cli/__tests__/team.test.js.map +1 -1
- package/dist/cli/plugin-marketplace.d.ts.map +1 -1
- package/dist/cli/plugin-marketplace.js +328 -142
- package/dist/cli/plugin-marketplace.js.map +1 -1
- package/dist/cli/session-compare.d.ts +11 -0
- package/dist/cli/session-compare.d.ts.map +1 -0
- package/dist/cli/session-compare.js +172 -0
- package/dist/cli/session-compare.js.map +1 -0
- package/dist/cli/session-search.d.ts.map +1 -1
- package/dist/cli/session-search.js +7 -0
- package/dist/cli/session-search.js.map +1 -1
- package/dist/cli/team.d.ts.map +1 -1
- package/dist/cli/team.js +2 -0
- package/dist/cli/team.js.map +1 -1
- package/dist/config/__tests__/multiplexer.test.d.ts +2 -0
- package/dist/config/__tests__/multiplexer.test.d.ts.map +1 -0
- package/dist/config/__tests__/multiplexer.test.js +118 -0
- package/dist/config/__tests__/multiplexer.test.js.map +1 -0
- package/dist/config/multiplexer.d.ts +29 -0
- package/dist/config/multiplexer.d.ts.map +1 -0
- package/dist/config/multiplexer.js +91 -0
- package/dist/config/multiplexer.js.map +1 -0
- package/dist/hooks/__tests__/sunset-routing-contract.test.js +4 -2
- package/dist/hooks/__tests__/sunset-routing-contract.test.js.map +1 -1
- package/dist/scripts/__tests__/codex-native-hook.test.js +281 -1
- package/dist/scripts/__tests__/codex-native-hook.test.js.map +1 -1
- package/dist/scripts/__tests__/generate-release-body.test.js +142 -5
- package/dist/scripts/__tests__/generate-release-body.test.js.map +1 -1
- package/dist/scripts/codex-native-hook.d.ts.map +1 -1
- package/dist/scripts/codex-native-hook.js +8 -2
- package/dist/scripts/codex-native-hook.js.map +1 -1
- package/dist/scripts/generate-release-body.d.ts.map +1 -1
- package/dist/scripts/generate-release-body.js +14 -0
- package/dist/scripts/generate-release-body.js.map +1 -1
- package/dist/scripts/notify-hook/team-worker-lease.d.ts +15 -0
- package/dist/scripts/notify-hook/team-worker-lease.d.ts.map +1 -0
- package/dist/scripts/notify-hook/team-worker-lease.js +63 -0
- package/dist/scripts/notify-hook/team-worker-lease.js.map +1 -0
- package/dist/scripts/notify-hook/team-worker-posttooluse.d.ts +1 -0
- package/dist/scripts/notify-hook/team-worker-posttooluse.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-worker-posttooluse.js +16 -5
- package/dist/scripts/notify-hook/team-worker-posttooluse.js.map +1 -1
- package/dist/scripts/notify-hook/team-worker.d.ts +12 -1
- package/dist/scripts/notify-hook/team-worker.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-worker.js +16 -4
- package/dist/scripts/notify-hook/team-worker.js.map +1 -1
- package/dist/session-history/__tests__/compare.test.d.ts +2 -0
- package/dist/session-history/__tests__/compare.test.d.ts.map +1 -0
- package/dist/session-history/__tests__/compare.test.js +257 -0
- package/dist/session-history/__tests__/compare.test.js.map +1 -0
- package/dist/session-history/compare.d.ts +74 -0
- package/dist/session-history/compare.d.ts.map +1 -0
- package/dist/session-history/compare.js +165 -0
- package/dist/session-history/compare.js.map +1 -0
- package/dist/team/__tests__/api-interop.test.js +3 -3
- package/dist/team/__tests__/cross-rebase-smoke.test.js +263 -31
- package/dist/team/__tests__/cross-rebase-smoke.test.js.map +1 -1
- package/dist/team/__tests__/herdr-session-realherdr.test.d.ts +2 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.d.ts.map +1 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.js +68 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.js.map +1 -0
- package/dist/team/__tests__/herdr-session.test.d.ts +2 -0
- package/dist/team/__tests__/herdr-session.test.d.ts.map +1 -0
- package/dist/team/__tests__/herdr-session.test.js +228 -0
- package/dist/team/__tests__/herdr-session.test.js.map +1 -0
- package/dist/team/__tests__/idle-nudge.test.js +84 -0
- package/dist/team/__tests__/idle-nudge.test.js.map +1 -1
- package/dist/team/__tests__/rebalance-policy.test.js +27 -9
- package/dist/team/__tests__/rebalance-policy.test.js.map +1 -1
- package/dist/team/__tests__/runtime-delivery.test.d.ts +2 -0
- package/dist/team/__tests__/runtime-delivery.test.d.ts.map +1 -0
- package/dist/team/__tests__/runtime-delivery.test.js +570 -0
- package/dist/team/__tests__/runtime-delivery.test.js.map +1 -0
- package/dist/team/__tests__/runtime.test.js +332 -18
- package/dist/team/__tests__/runtime.test.js.map +1 -1
- package/dist/team/__tests__/scaling.test.js +293 -0
- package/dist/team/__tests__/scaling.test.js.map +1 -1
- package/dist/team/__tests__/state-renewal.test.d.ts +2 -0
- package/dist/team/__tests__/state-renewal.test.d.ts.map +1 -0
- package/dist/team/__tests__/state-renewal.test.js +555 -0
- package/dist/team/__tests__/state-renewal.test.js.map +1 -0
- package/dist/team/__tests__/task-lease.test.d.ts +2 -0
- package/dist/team/__tests__/task-lease.test.d.ts.map +1 -0
- package/dist/team/__tests__/task-lease.test.js +179 -0
- package/dist/team/__tests__/task-lease.test.js.map +1 -0
- package/dist/team/__tests__/team-ops-contract.test.js +1 -0
- package/dist/team/__tests__/team-ops-contract.test.js.map +1 -1
- package/dist/team/__tests__/worker-bootstrap.test.js +2 -0
- package/dist/team/__tests__/worker-bootstrap.test.js.map +1 -1
- package/dist/team/api-interop.d.ts +1 -1
- package/dist/team/api-interop.d.ts.map +1 -1
- package/dist/team/api-interop.js +13 -1
- package/dist/team/api-interop.js.map +1 -1
- package/dist/team/goal-workflow.js +1 -1
- package/dist/team/herdr-session.d.ts +234 -0
- package/dist/team/herdr-session.d.ts.map +1 -0
- package/dist/team/herdr-session.js +489 -0
- package/dist/team/herdr-session.js.map +1 -0
- package/dist/team/idle-nudge.d.ts +16 -4
- package/dist/team/idle-nudge.d.ts.map +1 -1
- package/dist/team/idle-nudge.js +51 -19
- package/dist/team/idle-nudge.js.map +1 -1
- package/dist/team/mcp-comm.d.ts +1 -1
- package/dist/team/mcp-comm.d.ts.map +1 -1
- package/dist/team/rebalance-policy.d.ts.map +1 -1
- package/dist/team/rebalance-policy.js +5 -2
- package/dist/team/rebalance-policy.js.map +1 -1
- package/dist/team/runtime.d.ts.map +1 -1
- package/dist/team/runtime.js +356 -81
- package/dist/team/runtime.js.map +1 -1
- package/dist/team/scaling.d.ts.map +1 -1
- package/dist/team/scaling.js +332 -143
- package/dist/team/scaling.js.map +1 -1
- package/dist/team/state/monitor.d.ts +3 -0
- package/dist/team/state/monitor.d.ts.map +1 -1
- package/dist/team/state/monitor.js +3 -0
- package/dist/team/state/monitor.js.map +1 -1
- package/dist/team/state/tasks.d.ts +2 -1
- package/dist/team/state/tasks.d.ts.map +1 -1
- package/dist/team/state/tasks.js +28 -0
- package/dist/team/state/tasks.js.map +1 -1
- package/dist/team/state/types.d.ts +8 -0
- package/dist/team/state/types.d.ts.map +1 -1
- package/dist/team/state/types.js.map +1 -1
- package/dist/team/state.d.ts +14 -2
- package/dist/team/state.d.ts.map +1 -1
- package/dist/team/state.js +29 -5
- package/dist/team/state.js.map +1 -1
- package/dist/team/task-lease.d.ts +4 -0
- package/dist/team/task-lease.d.ts.map +1 -0
- package/dist/team/task-lease.js +74 -0
- package/dist/team/task-lease.js.map +1 -0
- package/dist/team/team-ops.d.ts +2 -1
- package/dist/team/team-ops.d.ts.map +1 -1
- package/dist/team/team-ops.js +1 -0
- package/dist/team/team-ops.js.map +1 -1
- package/dist/team/tmux-session.d.ts +1 -1
- package/dist/team/tmux-session.d.ts.map +1 -1
- package/dist/team/tmux-session.js +10 -2
- package/dist/team/tmux-session.js.map +1 -1
- package/dist/team/worker-bootstrap.d.ts.map +1 -1
- package/dist/team/worker-bootstrap.js +14 -1
- package/dist/team/worker-bootstrap.js.map +1 -1
- package/package.json +1 -1
- package/plugins/oh-my-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/oh-my-codex/hooks/codex-native-hook.mjs +208 -25
- package/plugins/oh-my-codex/skills/worker/SKILL.md +7 -1
- package/prompts/build-fixer.md +2 -1
- package/prompts/debugger.md +2 -1
- package/prompts/git-master.md +2 -1
- package/prompts/style-reviewer.md +2 -1
- package/prompts/team-executor.md +3 -2
- package/prompts/vision.md +2 -1
- package/prompts/writer.md +2 -1
- package/skills/worker/SKILL.md +7 -1
- package/src/scripts/__tests__/codex-native-hook.test.ts +279 -0
- package/src/scripts/__tests__/generate-release-body.test.ts +151 -5
- package/src/scripts/codex-native-hook.ts +8 -2
- package/src/scripts/generate-release-body.ts +16 -0
- package/src/scripts/notify-hook/team-worker-lease.ts +69 -0
- package/src/scripts/notify-hook/team-worker-posttooluse.ts +16 -4
- package/src/scripts/notify-hook/team-worker.ts +15 -4
package/dist/team/scaling.js
CHANGED
|
@@ -13,7 +13,9 @@ import { randomUUID } from 'crypto';
|
|
|
13
13
|
import { dirname, isAbsolute, join, relative, resolve, sep } from 'path';
|
|
14
14
|
import { mkdir, readFile, realpath, rm, writeFile } from 'fs/promises';
|
|
15
15
|
import { existsSync } from 'fs';
|
|
16
|
-
import {
|
|
16
|
+
import { readMultiplexerConfig } from '../config/multiplexer.js';
|
|
17
|
+
import { HerdrError, ensureHerdrServer, herdrWorkspaceIdFromPaneId, isHerdrBinaryCallable, isHerdrPaneId, isHerdrWorkerAlive, resolveHerdrBinary, spawnOneHerdrWorker, submitToHerdrWorker, teardownHerdrWorker, } from './herdr-session.js';
|
|
18
|
+
import { sanitizeTeamName, isTmuxAvailable, waitForWorkerReady, dismissTrustPromptIfPresent, isWorkerAlive, buildWorkerProcessLaunchSpec, buildWorkerStartupCommand, trustWorkerMiseConfigIfAvailable, writeWorkerStartupScriptCommand, resolveTeamWorkerCliForResolvedLaunchArgs, assertTeamWorkerCliPolicyCompatibility, readPaneTeamOwnerTagResult, teardownWorkerPanes, } from './tmux-session.js';
|
|
17
19
|
import { readExactPaneProofSync } from './exact-pane.js';
|
|
18
20
|
import { spawnSync } from 'child_process';
|
|
19
21
|
import { teamReadConfig as readTeamConfig, teamSaveConfig as saveTeamConfig, teamWriteWorkerIdentity as writeWorkerIdentity, teamReadManifest as readTeamManifestV2, teamNormalizePolicy as normalizeTeamPolicy, teamReadWorkerStatus as readWorkerStatus, teamWriteWorkerStatus as writeWorkerStatus, teamWithScalingLock as withScalingLock, teamWithTaskMembershipBarrier as withTaskMembershipBarrier, recoverTeamMembershipTaskTransaction, commitTeamMembershipTaskTransaction, finalizeTeamMembershipTaskTransaction, writeAtomic, teamRemoveDurableFile as removeDurableFile, teamAppendEvent as appendTeamEvent, teamCreateTask as createStateTask, teamListTasks as listTasks, teamReadTask as readTask, teamMarkDispatchRequestNotified as markDispatchRequestNotified, teamReadDispatchRequest as readDispatchRequest, teamTransitionDispatchRequest as transitionDispatchRequest, teamRemoveDispatchRequestsForWorkers as removeDispatchRequestsForWorkers, } from './team-ops.js';
|
|
@@ -357,7 +359,14 @@ export async function scaleUp(teamName, count, agentType, tasks, cwd, env = proc
|
|
|
357
359
|
if (!Number.isInteger(count) || count < 1) {
|
|
358
360
|
return { ok: false, error: `count must be a positive integer (got ${count})` };
|
|
359
361
|
}
|
|
360
|
-
|
|
362
|
+
const backend = readMultiplexerConfig({ env }).backend;
|
|
363
|
+
if (backend === 'herdr' && !(await isHerdrBinaryCallable(resolveHerdrBinary(env), env))) {
|
|
364
|
+
return {
|
|
365
|
+
ok: false,
|
|
366
|
+
error: 'herdr backend is selected but the herdr binary is not callable. Install from https://herdr.dev and retry.',
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
if (backend !== 'herdr' && !isTmuxAvailable()) {
|
|
361
370
|
return { ok: false, error: 'tmux is not available' };
|
|
362
371
|
}
|
|
363
372
|
const sanitized = sanitizeTeamName(teamName);
|
|
@@ -428,87 +437,116 @@ export async function scaleUp(teamName, count, agentType, tasks, cwd, env = proc
|
|
|
428
437
|
}
|
|
429
438
|
const persistedUltragoalContext = await readPersistedTeamUltragoalContext(sanitized, config.leader_cwd ?? leaderCwd, config.team_state_root ?? teamStateRoot);
|
|
430
439
|
const approvedContextSection = joinContextSections(approvedExecutionGate.approvedContextSection, renderLeaderOwnedUltragoalContextSection(persistedUltragoalContext));
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
440
|
+
// Herdr teams scale inside the existing workspace: no tmux split target,
|
|
441
|
+
// owner tag, or pane-PID proof applies (herdr pane ids are never reused,
|
|
442
|
+
// so the recorded pane id is itself the stable address).
|
|
443
|
+
const herdrBackend = config.worker_launch_mode === 'herdr';
|
|
444
|
+
const herdrWorkspacePane = herdrBackend
|
|
445
|
+
? config.workers.find((worker) => typeof worker.pane_id === 'string' && isHerdrPaneId(worker.pane_id))
|
|
434
446
|
: undefined;
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
if (!initialSplitTargetOwnerId) {
|
|
447
|
+
const herdrWorkspaceId = herdrWorkspacePane?.pane_id
|
|
448
|
+
? herdrWorkspaceIdFromPaneId(herdrWorkspacePane.pane_id)
|
|
449
|
+
: null;
|
|
450
|
+
if (herdrBackend && !herdrWorkspaceId) {
|
|
440
451
|
return {
|
|
441
452
|
ok: false,
|
|
442
|
-
error: `
|
|
453
|
+
error: `scale_up_herdr_workspace_unavailable:${sanitized}:no worker pane id to derive the herdr workspace from`,
|
|
443
454
|
};
|
|
444
455
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
if (typeof initialExpectedSplitTargetPid !== 'number'
|
|
449
|
-
|| !Number.isSafeInteger(initialExpectedSplitTargetPid)
|
|
450
|
-
|| initialExpectedSplitTargetPid <= 0) {
|
|
451
|
-
// Legacy configs may lack a persisted PID, but the persisted pane ID and
|
|
452
|
-
// canonical owner remain mandatory. Pin only the exact live pane proven
|
|
453
|
-
// from one global snapshot, then re-prove it after reading the owner tag
|
|
454
|
-
// so a recycled pane ID cannot be backfilled.
|
|
455
|
-
const migrationProof = readExactPaneProofSync(initialSplitTarget);
|
|
456
|
-
if (migrationProof.status !== 'live') {
|
|
457
|
-
return {
|
|
458
|
-
ok: false,
|
|
459
|
-
error: `scale_up_split_target_proof_unavailable:${initialSplitTarget}:${migrationProof.reason}`,
|
|
460
|
-
};
|
|
456
|
+
if (herdrBackend) {
|
|
457
|
+
try {
|
|
458
|
+
await ensureHerdrServer({ env: launchEnv });
|
|
461
459
|
}
|
|
462
|
-
|
|
463
|
-
if (migrationOwner.status !== 'value' || migrationOwner.value !== initialSplitTargetOwnerId) {
|
|
460
|
+
catch (error) {
|
|
464
461
|
return {
|
|
465
462
|
ok: false,
|
|
466
|
-
error: `
|
|
463
|
+
error: `scale_up_herdr_server_unavailable:${sanitized}:${error instanceof Error ? error.message : String(error)}`,
|
|
467
464
|
};
|
|
468
465
|
}
|
|
469
|
-
|
|
470
|
-
|
|
466
|
+
}
|
|
467
|
+
const initialSplitTargetCandidate = config.workers[config.workers.length - 1];
|
|
468
|
+
const initialSplitTargetWorker = initialSplitTargetCandidate?.pane_id?.trim()
|
|
469
|
+
? initialSplitTargetCandidate
|
|
470
|
+
: undefined;
|
|
471
|
+
const initialSplitTarget = initialSplitTargetWorker?.pane_id ?? config.leader_pane_id ?? '';
|
|
472
|
+
if (!herdrBackend) {
|
|
473
|
+
const initialSplitTargetOwnerId = typeof config.tmux_pane_owner_id === 'string'
|
|
474
|
+
? config.tmux_pane_owner_id.trim()
|
|
475
|
+
: '';
|
|
476
|
+
if (!initialSplitTargetOwnerId) {
|
|
471
477
|
return {
|
|
472
478
|
ok: false,
|
|
473
|
-
error: `
|
|
479
|
+
error: `scale_up_split_target_owner_unavailable:${initialSplitTarget}`,
|
|
474
480
|
};
|
|
475
481
|
}
|
|
476
|
-
|
|
482
|
+
let initialExpectedSplitTargetPid = initialSplitTargetWorker
|
|
483
|
+
? initialSplitTargetWorker.pid
|
|
484
|
+
: config.leader_pane_pid;
|
|
485
|
+
if (typeof initialExpectedSplitTargetPid !== 'number'
|
|
486
|
+
|| !Number.isSafeInteger(initialExpectedSplitTargetPid)
|
|
487
|
+
|| initialExpectedSplitTargetPid <= 0) {
|
|
488
|
+
// Legacy configs may lack a persisted PID, but the persisted pane ID and
|
|
489
|
+
// canonical owner remain mandatory. Pin only the exact live pane proven
|
|
490
|
+
// from one global snapshot, then re-prove it after reading the owner tag
|
|
491
|
+
// so a recycled pane ID cannot be backfilled.
|
|
492
|
+
const migrationProof = readExactPaneProofSync(initialSplitTarget);
|
|
493
|
+
if (migrationProof.status !== 'live') {
|
|
494
|
+
return {
|
|
495
|
+
ok: false,
|
|
496
|
+
error: `scale_up_split_target_proof_unavailable:${initialSplitTarget}:${migrationProof.reason}`,
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
const migrationOwner = readPaneTeamOwnerTagResult(migrationProof.paneId);
|
|
500
|
+
if (migrationOwner.status !== 'value' || migrationOwner.value !== initialSplitTargetOwnerId) {
|
|
501
|
+
return {
|
|
502
|
+
ok: false,
|
|
503
|
+
error: `scale_up_split_target_owner_changed:${migrationProof.paneId}`,
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
const finalMigrationProof = readExactPaneProofSync(migrationProof.paneId);
|
|
507
|
+
if (finalMigrationProof.status !== 'live') {
|
|
508
|
+
return {
|
|
509
|
+
ok: false,
|
|
510
|
+
error: `scale_up_split_target_proof_unavailable:${migrationProof.paneId}:${finalMigrationProof.reason}`,
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
if (finalMigrationProof.pid !== migrationProof.pid) {
|
|
514
|
+
return {
|
|
515
|
+
ok: false,
|
|
516
|
+
error: `scale_up_split_target_pid_changed:${migrationProof.paneId}:${migrationProof.pid}:${finalMigrationProof.pid}`,
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
if (initialSplitTargetWorker) {
|
|
520
|
+
initialSplitTargetWorker.pid = finalMigrationProof.pid;
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
config.leader_pane_pid = finalMigrationProof.pid;
|
|
524
|
+
}
|
|
525
|
+
try {
|
|
526
|
+
await saveTeamConfig(config, leaderCwd);
|
|
527
|
+
}
|
|
528
|
+
catch (error) {
|
|
529
|
+
return {
|
|
530
|
+
ok: false,
|
|
531
|
+
error: `scale_up_split_target_pid_persistence_failed:${initialSplitTarget}:${error instanceof Error ? error.message : String(error)}`,
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
Object.assign(originalConfig, JSON.parse(JSON.stringify(config)));
|
|
535
|
+
initialExpectedSplitTargetPid = finalMigrationProof.pid;
|
|
536
|
+
}
|
|
537
|
+
const initialSplitTargetProof = readExactPaneProofSync(initialSplitTarget);
|
|
538
|
+
if (initialSplitTargetProof.status !== 'live') {
|
|
477
539
|
return {
|
|
478
540
|
ok: false,
|
|
479
|
-
error: `
|
|
541
|
+
error: `scale_up_split_target_proof_unavailable:${initialSplitTarget}:${initialSplitTargetProof.reason}`,
|
|
480
542
|
};
|
|
481
543
|
}
|
|
482
|
-
if (
|
|
483
|
-
initialSplitTargetWorker.pid = finalMigrationProof.pid;
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
config.leader_pane_pid = finalMigrationProof.pid;
|
|
487
|
-
}
|
|
488
|
-
try {
|
|
489
|
-
await saveTeamConfig(config, leaderCwd);
|
|
490
|
-
}
|
|
491
|
-
catch (error) {
|
|
544
|
+
if (initialSplitTargetProof.pid !== initialExpectedSplitTargetPid) {
|
|
492
545
|
return {
|
|
493
546
|
ok: false,
|
|
494
|
-
error: `
|
|
547
|
+
error: `scale_up_split_target_pid_changed:${initialSplitTarget}:${initialExpectedSplitTargetPid}:${initialSplitTargetProof.pid}`,
|
|
495
548
|
};
|
|
496
549
|
}
|
|
497
|
-
Object.assign(originalConfig, JSON.parse(JSON.stringify(config)));
|
|
498
|
-
initialExpectedSplitTargetPid = finalMigrationProof.pid;
|
|
499
|
-
}
|
|
500
|
-
const initialSplitTargetProof = readExactPaneProofSync(initialSplitTarget);
|
|
501
|
-
if (initialSplitTargetProof.status !== 'live') {
|
|
502
|
-
return {
|
|
503
|
-
ok: false,
|
|
504
|
-
error: `scale_up_split_target_proof_unavailable:${initialSplitTarget}:${initialSplitTargetProof.reason}`,
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
if (initialSplitTargetProof.pid !== initialExpectedSplitTargetPid) {
|
|
508
|
-
return {
|
|
509
|
-
ok: false,
|
|
510
|
-
error: `scale_up_split_target_pid_changed:${initialSplitTarget}:${initialExpectedSplitTargetPid}:${initialSplitTargetProof.pid}`,
|
|
511
|
-
};
|
|
512
550
|
}
|
|
513
551
|
const effectiveWorktreeMode = config.worktree_mode ?? resolveScaleUpWorktreeMode(config);
|
|
514
552
|
if (!config.worktree_mode && effectiveWorktreeMode.enabled) {
|
|
@@ -584,13 +622,32 @@ export async function scaleUp(teamName, count, agentType, tasks, cwd, env = proc
|
|
|
584
622
|
const rollbackPaneIds = [...new Set([
|
|
585
623
|
...rollbackWorkers.map((worker) => worker.pane_id),
|
|
586
624
|
context.paneId,
|
|
587
|
-
].filter((paneId) => typeof paneId === 'string'
|
|
625
|
+
].filter((paneId) => typeof paneId === 'string'
|
|
626
|
+
&& (paneId.trim().startsWith('%') || isHerdrPaneId(paneId.trim()))))];
|
|
588
627
|
const resolvedPaneIds = new Set();
|
|
589
628
|
const unresolvedPaneIds = new Set();
|
|
629
|
+
// Herdr pane ids are unique for the pane's whole lifetime (never
|
|
630
|
+
// recycled), so the recorded id is itself teardown authority — close the
|
|
631
|
+
// pane directly; a pane_not_found answer proves it is already gone.
|
|
632
|
+
for (const paneId of rollbackPaneIds.filter((paneId) => isHerdrPaneId(paneId))) {
|
|
633
|
+
try {
|
|
634
|
+
await teardownHerdrWorker(paneId, { env });
|
|
635
|
+
resolvedPaneIds.add(paneId);
|
|
636
|
+
}
|
|
637
|
+
catch (error) {
|
|
638
|
+
if (error instanceof HerdrError && error.code === 'pane_not_found') {
|
|
639
|
+
resolvedPaneIds.add(paneId);
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
642
|
+
unresolvedPaneIds.add(paneId);
|
|
643
|
+
cleanupDebt.push(`herdr_pane_teardown_failed:${paneId}:${error instanceof Error ? error.message : String(error)}`);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
const tmuxRollbackPaneIds = rollbackPaneIds.filter((paneId) => paneId.startsWith('%'));
|
|
590
647
|
const requiredTeamOwnerId = config.tmux_pane_owner_id?.trim();
|
|
591
648
|
const authorizedRollbackPaneIds = new Set();
|
|
592
649
|
const rollbackInstances = new Map();
|
|
593
|
-
for (const paneId of
|
|
650
|
+
for (const paneId of tmuxRollbackPaneIds) {
|
|
594
651
|
const matchingWorkers = rollbackWorkers.filter((worker) => worker.pane_id === paneId);
|
|
595
652
|
const worker = matchingWorkers.length === 1 ? matchingWorkers[0] : undefined;
|
|
596
653
|
const expectedPanePid = worker?.pid;
|
|
@@ -801,25 +858,33 @@ export async function scaleUp(teamName, count, agentType, tasks, cwd, env = proc
|
|
|
801
858
|
const { workerIndex, workerName, runtimeRole, workerLaunchArgs, workerCli, } = workerLaunchPlan;
|
|
802
859
|
// Freeze the split target and its identity before preparing any artifacts.
|
|
803
860
|
// Later proof must establish that this exact pane process still owns the
|
|
804
|
-
// target; a recycled pane ID must never become split authority.
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
:
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
861
|
+
// target; a recycled pane ID must never become split authority. Herdr
|
|
862
|
+
// teams skip this: workers spawn as new tabs pinned to the workspace id,
|
|
863
|
+
// not splits of an existing tmux pane.
|
|
864
|
+
let splitTarget = '';
|
|
865
|
+
let expectedSplitTargetPid;
|
|
866
|
+
let expectedSplitTargetOwnerId = '';
|
|
867
|
+
let splitDirection = '-v';
|
|
868
|
+
if (!herdrBackend) {
|
|
869
|
+
const splitTargetCandidate = config.workers[config.workers.length - 1];
|
|
870
|
+
const splitTargetWorker = splitTargetCandidate?.pane_id?.trim() ? splitTargetCandidate : undefined;
|
|
871
|
+
splitTarget = splitTargetWorker?.pane_id ?? config.leader_pane_id ?? '';
|
|
872
|
+
expectedSplitTargetPid = (splitTargetWorker
|
|
873
|
+
? splitTargetWorker.pid
|
|
874
|
+
: config.leader_pane_pid) ?? undefined;
|
|
875
|
+
expectedSplitTargetOwnerId = typeof config.tmux_pane_owner_id === 'string'
|
|
876
|
+
? config.tmux_pane_owner_id.trim()
|
|
877
|
+
: '';
|
|
878
|
+
if (typeof expectedSplitTargetPid !== 'number'
|
|
879
|
+
|| !Number.isSafeInteger(expectedSplitTargetPid)
|
|
880
|
+
|| expectedSplitTargetPid <= 0) {
|
|
881
|
+
return await rollbackScaleUp(`scale_up_split_target_pid_missing:${splitTarget}`);
|
|
882
|
+
}
|
|
883
|
+
if (!expectedSplitTargetOwnerId) {
|
|
884
|
+
return await rollbackScaleUp(`scale_up_split_target_owner_unavailable:${splitTarget}`);
|
|
885
|
+
}
|
|
886
|
+
splitDirection = splitTarget === (config.leader_pane_id ?? '') ? '-h' : '-v';
|
|
821
887
|
}
|
|
822
|
-
const splitDirection = splitTarget === (config.leader_pane_id ?? '') ? '-h' : '-v';
|
|
823
888
|
nextIndex = workerIndex + 1;
|
|
824
889
|
if (workerLaunchPlan.mixedTaskRoles.length > 1) {
|
|
825
890
|
console.log(`[omx:scaling] ${workerName}: mixed task roles [${workerLaunchPlan.mixedTaskRoles.join(', ')}], falling back to ${agentType}`);
|
|
@@ -832,6 +897,7 @@ export async function scaleUp(teamName, count, agentType, tasks, cwd, env = proc
|
|
|
832
897
|
let workerWorkspace = null;
|
|
833
898
|
let workerCwd = leaderCwd;
|
|
834
899
|
let cmd;
|
|
900
|
+
let extraEnv = {};
|
|
835
901
|
let rawRolePromptContent = null;
|
|
836
902
|
try {
|
|
837
903
|
preparedWorkerDirectoryOwner.set(workerDirPath, workerName);
|
|
@@ -895,7 +961,7 @@ export async function scaleUp(teamName, count, agentType, tasks, cwd, env = proc
|
|
|
895
961
|
: rolePromptContent
|
|
896
962
|
? await writeWorkerRoleInstructionsFile(sanitized, workerName, leaderCwd, teamInstructionsPath, runtimeRole, rolePromptContent)
|
|
897
963
|
: teamInstructionsPath;
|
|
898
|
-
|
|
964
|
+
extraEnv = {
|
|
899
965
|
OMX_TEAM_STATE_ROOT: teamStateRoot,
|
|
900
966
|
OMX_TEAM_LEADER_CWD: leaderCwd,
|
|
901
967
|
OMX_MODEL_INSTRUCTIONS_FILE: instructionsFilePath,
|
|
@@ -909,75 +975,142 @@ export async function scaleUp(teamName, count, agentType, tasks, cwd, env = proc
|
|
|
909
975
|
extraEnv.OMX_TEAM_WORKTREE_DETACHED = workerWorkspace.detached ? '1' : '0';
|
|
910
976
|
}
|
|
911
977
|
trustWorkerMiseConfigIfAvailable(workerCwd);
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
978
|
+
if (herdrBackend) {
|
|
979
|
+
// Herdr workers launch through `agent start` in a fresh tab — the
|
|
980
|
+
// tmux startup script never runs there, so skip writing it.
|
|
981
|
+
cmd = '';
|
|
982
|
+
}
|
|
983
|
+
else {
|
|
984
|
+
preparedStartupScriptOwner.set(startupScriptPath, workerName);
|
|
985
|
+
const startupCommand = writeWorkerStartupScriptCommand(sanitized, workerIndex, workerLaunchArgs, workerCwd, extraEnv, workerCli, undefined, runtimeRole);
|
|
986
|
+
cmd = startupCommand ?? buildWorkerStartupCommand(sanitized, workerIndex, workerLaunchArgs, workerCwd, extraEnv, workerCli, undefined, runtimeRole);
|
|
987
|
+
}
|
|
915
988
|
}
|
|
916
989
|
catch (error) {
|
|
917
990
|
return await rollbackScaleUp(`scale_up_worker_preparation_failed:${workerName}:${error instanceof Error ? error.message : String(error)}`, { workerName, worktreePath: workerWorkspace?.worktreePath });
|
|
918
991
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
992
|
+
let paneId;
|
|
993
|
+
let workerInfo;
|
|
994
|
+
if (herdrBackend) {
|
|
995
|
+
// Spawn one tab + agent in the live team workspace. The spawn helper
|
|
996
|
+
// proves the agent promptable (first-run trust dialogs dismissed) and
|
|
997
|
+
// closes its own pane on failure, so a failed spawn is pure rollback.
|
|
998
|
+
let spawned;
|
|
999
|
+
try {
|
|
1000
|
+
const spec = buildWorkerProcessLaunchSpec(sanitized, workerIndex, workerLaunchArgs, workerCwd, extraEnv, workerCli);
|
|
1001
|
+
const herdrSpawnPlan = {
|
|
1002
|
+
kind: spec.workerCli,
|
|
1003
|
+
agentArgs: spec.args,
|
|
1004
|
+
env: spec.env,
|
|
1005
|
+
cwd: workerCwd,
|
|
1006
|
+
};
|
|
1007
|
+
spawned = await spawnOneHerdrWorker(sanitized, herdrWorkspaceId, workerIndex, herdrSpawnPlan, { env: launchEnv });
|
|
1008
|
+
}
|
|
1009
|
+
catch (error) {
|
|
1010
|
+
return await rollbackScaleUp(`scale_up_herdr_spawn_failed:${workerName}:${error instanceof Error ? error.message : String(error)}`, { workerName, worktreePath: workerWorkspace?.worktreePath });
|
|
1011
|
+
}
|
|
1012
|
+
paneId = spawned.paneId;
|
|
1013
|
+
workerInfo = {
|
|
1014
|
+
name: workerName,
|
|
1015
|
+
index: workerIndex,
|
|
1016
|
+
role: runtimeRole,
|
|
1017
|
+
worker_cli: workerCli,
|
|
1018
|
+
assigned_tasks: [],
|
|
1019
|
+
pid: undefined,
|
|
1020
|
+
pane_id: paneId,
|
|
1021
|
+
working_dir: workerCwd,
|
|
1022
|
+
worktree_repo_root: workerWorkspace ? workerWorkspace.repoRoot : undefined,
|
|
1023
|
+
worktree_path: workerWorkspace ? workerWorkspace.worktreePath : undefined,
|
|
1024
|
+
worktree_branch: workerWorkspace ? (workerWorkspace.branchName ?? undefined) : undefined,
|
|
1025
|
+
worktree_detached: workerWorkspace ? workerWorkspace.detached : undefined,
|
|
1026
|
+
worktree_created: workerWorkspace ? workerWorkspace.created : undefined,
|
|
1027
|
+
team_state_root: teamStateRoot,
|
|
1028
|
+
};
|
|
940
1029
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1030
|
+
else {
|
|
1031
|
+
// Freeze and validate the full source-pane incarnation. The server owns
|
|
1032
|
+
// the final comparison and split, so a recycled pane ID cannot become a
|
|
1033
|
+
// split target between client-side proof and the topology mutation.
|
|
1034
|
+
const splitTargetProof = readExactPaneProofSync(splitTarget);
|
|
1035
|
+
const splitTargetInstance = splitTargetProof.status === 'live'
|
|
1036
|
+
? readScalePaneInstance(splitTargetProof.paneId)
|
|
1037
|
+
: null;
|
|
1038
|
+
if (!splitTargetInstance) {
|
|
1039
|
+
return await rollbackScaleUp(`scale_up_split_target_proof_unavailable:${splitTarget}`, { workerName, worktreePath: workerWorkspace?.worktreePath });
|
|
1040
|
+
}
|
|
1041
|
+
if (splitTargetInstance.pid !== expectedSplitTargetPid) {
|
|
1042
|
+
return await rollbackScaleUp(`scale_up_split_target_pid_changed:${splitTarget}:${expectedSplitTargetPid}:${splitTargetInstance.pid}`, { workerName, worktreePath: workerWorkspace?.worktreePath });
|
|
1043
|
+
}
|
|
1044
|
+
if (splitTargetInstance.sessionName !== sessionName
|
|
1045
|
+
|| (config.tmux_session_id && splitTargetInstance.sessionId !== config.tmux_session_id)
|
|
1046
|
+
|| splitTargetInstance.teamOwnerId !== expectedSplitTargetOwnerId) {
|
|
1047
|
+
return await rollbackScaleUp(`scale_up_split_target_authority_changed:${splitTargetInstance.paneId}`, { workerName, worktreePath: workerWorkspace?.worktreePath });
|
|
1048
|
+
}
|
|
1049
|
+
const createdPane = splitWorkerPaneWithScaleAuthority(splitTargetInstance, splitDirection, workerCwd, cmd);
|
|
1050
|
+
if (!createdPane) {
|
|
1051
|
+
return await rollbackScaleUp(`scale_up_split_target_authority_lost:${splitTargetInstance.paneId}`, { workerName, worktreePath: workerWorkspace?.worktreePath });
|
|
1052
|
+
}
|
|
1053
|
+
paneId = createdPane.paneId;
|
|
1054
|
+
workerInfo = {
|
|
1055
|
+
name: workerName,
|
|
1056
|
+
index: workerIndex,
|
|
1057
|
+
role: runtimeRole,
|
|
1058
|
+
worker_cli: workerCli,
|
|
1059
|
+
assigned_tasks: [],
|
|
1060
|
+
pid: createdPane.pid,
|
|
1061
|
+
pane_id: paneId,
|
|
1062
|
+
session_id: createdPane.sessionId,
|
|
1063
|
+
window_id: createdPane.windowId,
|
|
1064
|
+
working_dir: workerCwd,
|
|
1065
|
+
worktree_repo_root: workerWorkspace ? workerWorkspace.repoRoot : undefined,
|
|
1066
|
+
worktree_path: workerWorkspace ? workerWorkspace.worktreePath : undefined,
|
|
1067
|
+
worktree_branch: workerWorkspace ? (workerWorkspace.branchName ?? undefined) : undefined,
|
|
1068
|
+
worktree_detached: workerWorkspace ? workerWorkspace.detached : undefined,
|
|
1069
|
+
worktree_created: workerWorkspace ? workerWorkspace.created : undefined,
|
|
1070
|
+
team_state_root: teamStateRoot,
|
|
1071
|
+
};
|
|
1072
|
+
const taggedPane = config.tmux_pane_owner_id
|
|
1073
|
+
? tagScalePaneWithAuthority(createdPane, config.tmux_pane_owner_id.trim())
|
|
1074
|
+
: null;
|
|
1075
|
+
if (!taggedPane) {
|
|
1076
|
+
return await rollbackScaleUp(`scale_up_created_pane_owner_tag_authority_lost:${paneId}`, { paneId, worker: workerInfo });
|
|
1077
|
+
}
|
|
1078
|
+
rollbackTaggedPaneOwnerIds.set(paneId, taggedPane.teamOwnerId);
|
|
965
1079
|
}
|
|
966
|
-
rollbackTaggedPaneOwnerIds.set(paneId, taggedPane.teamOwnerId);
|
|
967
1080
|
// Intentionally avoid forcing `select-layout tiled` here.
|
|
968
1081
|
// Tiled relayout reflows leader/HUD panes and breaks team window layout.
|
|
969
1082
|
try {
|
|
970
1083
|
await writeWorkerIdentity(sanitized, workerName, workerInfo, leaderCwd);
|
|
971
1084
|
throwIfScaleUpFailureInjected(env, 'identity');
|
|
972
|
-
// Wait for worker readiness
|
|
1085
|
+
// Wait for worker readiness. Herdr spawn already proves the agent
|
|
1086
|
+
// promptable (agent-start readiness + settle polling), so the tmux
|
|
1087
|
+
// ready-wait does not apply.
|
|
973
1088
|
const readyTimeoutMs = resolveWorkerReadyTimeoutMs(env);
|
|
974
|
-
const skipReadyWait = env.OMX_TEAM_SKIP_READY_WAIT === '1';
|
|
1089
|
+
const skipReadyWait = env.OMX_TEAM_SKIP_READY_WAIT === '1' || herdrBackend;
|
|
975
1090
|
if (!skipReadyWait) {
|
|
976
1091
|
const ready = waitForWorkerReady(sessionName, workerIndex, readyTimeoutMs, paneId, workerInfo.pid, config.tmux_pane_owner_id ?? undefined, config.hud_pane_id ?? undefined);
|
|
977
1092
|
if (!ready) {
|
|
978
1093
|
console.log(`[omx:scaling] Warning: worker ${workerName} did not become ready within timeout`);
|
|
979
1094
|
}
|
|
980
1095
|
}
|
|
1096
|
+
// Backend-aware pane notification: herdr prompts the pane's agent,
|
|
1097
|
+
// tmux proves session/window authority and sends keys.
|
|
1098
|
+
const notifyPane = async (message) => {
|
|
1099
|
+
if (herdrBackend) {
|
|
1100
|
+
try {
|
|
1101
|
+
await submitToHerdrWorker(paneId, message, { env: launchEnv });
|
|
1102
|
+
return { ok: true, transport: 'herdr_prompt', reason: 'herdr_prompt_sent' };
|
|
1103
|
+
}
|
|
1104
|
+
catch (error) {
|
|
1105
|
+
return {
|
|
1106
|
+
ok: false,
|
|
1107
|
+
transport: 'herdr_prompt',
|
|
1108
|
+
reason: `herdr_prompt_failed:${error instanceof Error ? error.message : String(error)}`,
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
return await notifyWorkerPaneOutcome(sessionName, message, paneId, workerInfo.pid, config.tmux_pane_owner_id ?? undefined, workerInfo.session_id, workerInfo.window_id);
|
|
1113
|
+
};
|
|
981
1114
|
// Get assigned tasks for this worker
|
|
982
1115
|
const workerTasks = materializedTasks.filter(t => t.owner === workerName);
|
|
983
1116
|
const inbox = generateInitialInbox(workerName, sanitized, agentType, workerTasks, {
|
|
@@ -1007,7 +1140,7 @@ export async function scaleUp(teamName, count, agentType, tasks, cwd, env = proc
|
|
|
1007
1140
|
if (dispatchPolicy.dispatch_mode === 'hook_preferred_with_fallback') {
|
|
1008
1141
|
return { ok: true, transport: 'hook', reason: 'queued_for_hook_dispatch' };
|
|
1009
1142
|
}
|
|
1010
|
-
return await
|
|
1143
|
+
return await notifyPane(message);
|
|
1011
1144
|
},
|
|
1012
1145
|
});
|
|
1013
1146
|
let outcome = queued;
|
|
@@ -1020,7 +1153,7 @@ export async function scaleUp(teamName, count, agentType, tasks, cwd, env = proc
|
|
|
1020
1153
|
outcome = { ok: true, transport: 'hook', reason: `hook_receipt_${receipt.status}`, request_id: queued.request_id };
|
|
1021
1154
|
}
|
|
1022
1155
|
else {
|
|
1023
|
-
const fallback = await
|
|
1156
|
+
const fallback = await notifyPane(triggerDirective.text);
|
|
1024
1157
|
if (receipt?.status === 'failed') {
|
|
1025
1158
|
if (fallback.ok) {
|
|
1026
1159
|
await transitionDispatchRequest(sanitized, queued.request_id, 'failed', 'failed', { last_reason: `fallback_confirmed_after_failed_receipt:${fallback.reason}` }, leaderCwd).catch(() => { });
|
|
@@ -1068,9 +1201,10 @@ export async function scaleUp(teamName, count, agentType, tasks, cwd, env = proc
|
|
|
1068
1201
|
}
|
|
1069
1202
|
}
|
|
1070
1203
|
// Retry dispatch once if a trust prompt is blocking the worker pane (fixes #393).
|
|
1071
|
-
|
|
1204
|
+
// Herdr spawns dismiss trust dialogs during agent start, so the retry is tmux-only.
|
|
1205
|
+
if (!outcome.ok && !herdrBackend && dismissTrustPromptIfPresent(sessionName, workerIndex, paneId, workerInfo.pid, config.tmux_pane_owner_id ?? undefined, config.hud_pane_id ?? undefined)) {
|
|
1072
1206
|
waitForWorkerReady(sessionName, workerIndex, readyTimeoutMs, paneId, workerInfo.pid, config.tmux_pane_owner_id ?? undefined, config.hud_pane_id ?? undefined);
|
|
1073
|
-
const retry = await
|
|
1207
|
+
const retry = await notifyPane(triggerDirective.text);
|
|
1074
1208
|
if (retry.ok) {
|
|
1075
1209
|
outcome = retry;
|
|
1076
1210
|
}
|
|
@@ -1246,9 +1380,14 @@ function asScaleDownDebtPanes(debt, removedWorkerNames, resources, leaderPaneId,
|
|
|
1246
1380
|
if (!pane || typeof pane.name !== 'string' || !expectedNames.has(pane.name) || !resourceNames.has(pane.name)
|
|
1247
1381
|
|| typeof pane.index !== 'number' || !Number.isInteger(pane.index) || pane.index <= 0
|
|
1248
1382
|
|| pane.index !== Number(pane.name.slice('worker-'.length))
|
|
1249
|
-
|| typeof pane.pane_id !== 'string'
|
|
1383
|
+
|| typeof pane.pane_id !== 'string'
|
|
1384
|
+
|| !(/^%\d+$/.test(pane.pane_id) || isHerdrPaneId(pane.pane_id))
|
|
1250
1385
|
|| pane.pane_id === normalizedLeaderPaneId || pane.pane_id === normalizedHudPaneId
|
|
1251
|
-
|
|
1386
|
+
// Herdr records carry no pane PID (ids are never reused, so there is
|
|
1387
|
+
// nothing to pin); tmux records keep the positive-PID invariant.
|
|
1388
|
+
|| (isHerdrPaneId(pane.pane_id)
|
|
1389
|
+
? pane.pid !== null
|
|
1390
|
+
: (pane.pid !== null && (!Number.isSafeInteger(pane.pid) || pane.pid <= 0))))
|
|
1252
1391
|
return false;
|
|
1253
1392
|
const canonical = canonicalByName.get(pane.name);
|
|
1254
1393
|
if (requireCanonicalMatch) {
|
|
@@ -1358,6 +1497,24 @@ export async function reconcileScaleDownCleanupDebt(teamName, cwd, _callerConfig
|
|
|
1358
1497
|
? config.tmux_pane_owner_id.trim()
|
|
1359
1498
|
: '';
|
|
1360
1499
|
for (const pane of panes) {
|
|
1500
|
+
// Herdr pane ids are unique for the pane's whole lifetime: the committed
|
|
1501
|
+
// debt record is itself teardown authority, and a pane_not_found answer
|
|
1502
|
+
// proves convergence. No tmux PID/owner proof applies.
|
|
1503
|
+
if (isHerdrPaneId(pane.pane_id)) {
|
|
1504
|
+
try {
|
|
1505
|
+
await teardownHerdrWorker(pane.pane_id);
|
|
1506
|
+
resolvedPaneIds.add(pane.pane_id);
|
|
1507
|
+
}
|
|
1508
|
+
catch (error) {
|
|
1509
|
+
if (error instanceof HerdrError && error.code === 'pane_not_found') {
|
|
1510
|
+
resolvedPaneIds.add(pane.pane_id);
|
|
1511
|
+
}
|
|
1512
|
+
else {
|
|
1513
|
+
reasons.push(`${pane.pane_id}:herdr_teardown_failed:${error instanceof Error ? error.message : String(error)}`);
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
continue;
|
|
1517
|
+
}
|
|
1361
1518
|
// Legacy PID-less records can establish convergence from an authoritative
|
|
1362
1519
|
// global absence/dead proof, but can never authorize a live-pane effect.
|
|
1363
1520
|
const freshProof = readExactPaneProofSync(pane.pane_id);
|
|
@@ -1562,8 +1719,15 @@ export async function scaleDown(teamName, cwd, options = {}, env = process.env)
|
|
|
1562
1719
|
while (Date.now() < deadline) {
|
|
1563
1720
|
const allDrained = await Promise.all(targetWorkers.map(async (w) => {
|
|
1564
1721
|
const status = await readWorkerStatus(sanitized, w.name, leaderCwd);
|
|
1565
|
-
|
|
1566
|
-
|
|
1722
|
+
if (status.state === 'idle' || status.state === 'done' || status.state === 'draining') {
|
|
1723
|
+
return true;
|
|
1724
|
+
}
|
|
1725
|
+
// Herdr liveness is the live-agent inventory; tmux keeps the
|
|
1726
|
+
// PID-pinned pane proof.
|
|
1727
|
+
if (typeof w.pane_id === 'string' && isHerdrPaneId(w.pane_id)) {
|
|
1728
|
+
return !(await isHerdrWorkerAlive(w.pane_id));
|
|
1729
|
+
}
|
|
1730
|
+
return !isWorkerAlive(sessionName, w.index, w.pane_id, w.pid, config.tmux_pane_owner_id ?? undefined, config.hud_pane_id ?? undefined);
|
|
1567
1731
|
}));
|
|
1568
1732
|
if (allDrained.every(Boolean))
|
|
1569
1733
|
break;
|
|
@@ -1659,7 +1823,8 @@ export async function scaleDown(teamName, cwd, options = {}, env = process.env)
|
|
|
1659
1823
|
created_at: new Date().toISOString(),
|
|
1660
1824
|
removed_worker_names: removableWorkers.map((worker) => worker.name),
|
|
1661
1825
|
workers: removableWorkers
|
|
1662
|
-
.filter((worker) => (typeof worker.pane_id === 'string'
|
|
1826
|
+
.filter((worker) => (typeof worker.pane_id === 'string'
|
|
1827
|
+
&& (/^%\d+$/.test(worker.pane_id) || isHerdrPaneId(worker.pane_id))))
|
|
1663
1828
|
.map((worker) => ({
|
|
1664
1829
|
name: worker.name,
|
|
1665
1830
|
index: worker.index,
|
|
@@ -1690,6 +1855,25 @@ export async function scaleDown(teamName, cwd, options = {}, env = process.env)
|
|
|
1690
1855
|
throw new Error(`canonical_scale_down_task_verification_failed:${task.id}`);
|
|
1691
1856
|
}
|
|
1692
1857
|
}
|
|
1858
|
+
// Herdr panes close directly: ids are never reused, so the recorded
|
|
1859
|
+
// pane id is itself teardown authority and a pane_not_found answer
|
|
1860
|
+
// proves the pane is already gone.
|
|
1861
|
+
const herdrPaneWorkers = removableWorkers.filter((worker) => (typeof worker.pane_id === 'string' && isHerdrPaneId(worker.pane_id)));
|
|
1862
|
+
const herdrResolvedPaneIds = new Set();
|
|
1863
|
+
const herdrProofDebt = [];
|
|
1864
|
+
for (const worker of herdrPaneWorkers) {
|
|
1865
|
+
try {
|
|
1866
|
+
await teardownHerdrWorker(worker.pane_id, { env });
|
|
1867
|
+
herdrResolvedPaneIds.add(worker.pane_id);
|
|
1868
|
+
}
|
|
1869
|
+
catch (error) {
|
|
1870
|
+
if (error instanceof HerdrError && error.code === 'pane_not_found') {
|
|
1871
|
+
herdrResolvedPaneIds.add(worker.pane_id);
|
|
1872
|
+
continue;
|
|
1873
|
+
}
|
|
1874
|
+
herdrProofDebt.push(`${worker.pane_id}:herdr_teardown_failed:${error instanceof Error ? error.message : String(error)}`);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1693
1877
|
// PID-less rollback records are cleanup debt, not effect authority. A
|
|
1694
1878
|
// fresh gone proof may resolve one, but a live or unavailable proof
|
|
1695
1879
|
// must remain debt rather than letting teardown adopt its current PID.
|
|
@@ -1731,6 +1915,7 @@ export async function scaleDown(teamName, cwd, options = {}, env = process.env)
|
|
|
1731
1915
|
},
|
|
1732
1916
|
});
|
|
1733
1917
|
const resolvedPaneIds = new Set([
|
|
1918
|
+
...herdrResolvedPaneIds,
|
|
1734
1919
|
...unpinnedResolvedPaneIds,
|
|
1735
1920
|
...paneTeardown.provenGonePaneIds,
|
|
1736
1921
|
...paneTeardown.killedPaneIds,
|
|
@@ -1738,7 +1923,11 @@ export async function scaleDown(teamName, cwd, options = {}, env = process.env)
|
|
|
1738
1923
|
const unresolvedWorkers = removableWorkers.filter((worker) => (typeof worker.pane_id === 'string' && !resolvedPaneIds.has(worker.pane_id)));
|
|
1739
1924
|
if (unresolvedWorkers.length > 0) {
|
|
1740
1925
|
await restorePriorWorkerStatuses(unresolvedWorkers);
|
|
1741
|
-
const proofDebt = [
|
|
1926
|
+
const proofDebt = [
|
|
1927
|
+
...herdrProofDebt,
|
|
1928
|
+
...unpinnedProofDebt,
|
|
1929
|
+
...paneTeardown.proofUnavailable.map((proof) => `${proof.paneId}:${proof.reason}`),
|
|
1930
|
+
];
|
|
1742
1931
|
const killDebt = paneTeardown.kill.failedPaneIds.map((paneId) => `${paneId}:kill_failed`);
|
|
1743
1932
|
await writeAtomic(cleanupDebtPath, JSON.stringify({
|
|
1744
1933
|
...cleanupDebtBase,
|