oh-my-codex 0.21.48 → 0.22.1
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 +104 -3
- package/dist/cli/__tests__/plugin-cache-live-pin-3790.test.js.map +1 -1
- package/dist/cli/__tests__/question.test.js +33 -0
- package/dist/cli/__tests__/question.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__/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 +11 -4
- package/dist/cli/plugin-marketplace.js.map +1 -1
- package/dist/cli/question.d.ts.map +1 -1
- package/dist/cli/question.js +8 -1
- package/dist/cli/question.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/question/__tests__/ui.test.js +40 -1
- package/dist/question/__tests__/ui.test.js.map +1 -1
- package/dist/question/ui.d.ts.map +1 -1
- package/dist/question/ui.js +37 -7
- package/dist/question/ui.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/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/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__/completion-evidence.test.js +31 -1
- package/dist/team/__tests__/completion-evidence.test.js.map +1 -1
- 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__/hook-primary-e2e-contract.test.js +9 -3
- package/dist/team/__tests__/hook-primary-e2e-contract.test.js.map +1 -1
- 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__/mcp-comm.test.js +25 -1
- package/dist/team/__tests__/mcp-comm.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 +938 -70
- package/dist/team/__tests__/runtime.test.js.map +1 -1
- package/dist/team/__tests__/scaling.test.js +645 -1
- 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__/state.test.js +121 -2
- package/dist/team/__tests__/state.test.js.map +1 -1
- 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/completion-evidence.d.ts +1 -1
- package/dist/team/completion-evidence.d.ts.map +1 -1
- package/dist/team/completion-evidence.js +9 -0
- package/dist/team/completion-evidence.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 +6 -4
- package/dist/team/mcp-comm.d.ts.map +1 -1
- package/dist/team/mcp-comm.js +4 -0
- package/dist/team/mcp-comm.js.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 +463 -166
- package/dist/team/runtime.js.map +1 -1
- package/dist/team/scaling.d.ts +3 -3
- package/dist/team/scaling.d.ts.map +1 -1
- package/dist/team/scaling.js +394 -200
- 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 +4 -1
- package/dist/team/state/tasks.d.ts.map +1 -1
- package/dist/team/state/tasks.js +36 -5
- package/dist/team/state/tasks.js.map +1 -1
- package/dist/team/state/types.d.ts +9 -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 +15 -2
- package/dist/team/state.d.ts.map +1 -1
- package/dist/team/state.js +73 -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 +16 -3
- 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 +4 -1
- package/plugins/oh-my-codex/skills/worker/SKILL.md +7 -1
- package/skills/worker/SKILL.md +7 -1
- package/src/scripts/__tests__/codex-native-hook.test.ts +279 -0
- package/src/scripts/codex-native-hook.ts +8 -2
- 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
|
@@ -7,8 +7,8 @@ import { join, relative, dirname } from 'path';
|
|
|
7
7
|
import { tmpdir } from 'os';
|
|
8
8
|
import { existsSync } from 'fs';
|
|
9
9
|
import { HUD_TMUX_TEAM_HEIGHT_LINES } from '../../hud/constants.js';
|
|
10
|
-
import { DEFAULT_MAX_WORKERS, initTeamState, createTask, writeWorkerInbox, readTeamConfig, saveTeamConfig, listMailboxMessages, sendDirectMessage, listDispatchRequests, transitionDispatchRequest, updateWorkerHeartbeat, writeAtomic, readTask, readMonitorSnapshot, claimTask, transitionTaskStatus, readWorkerStatus, writeWorkerStatus, readTeamPhase, writeTeamPhase, } from '../state.js';
|
|
11
|
-
import { monitorTeam, shutdownTeam, resumeTeam, startTeam, assignTask, sendWorkerMessage, applyCreatedInteractiveSessionToConfig, reconcileStartupCleanupPanes, rethrowStartupRollbackProofDebt, resolveWorkerLaunchArgsFromEnv, resolveTeamWorkerCliForResolvedLaunchArgs, shouldPrekillInteractiveShutdownProcessTrees, waitForWorkerStartupEvidence, waitForClaudeStartupEvidence, cleanupTeamWorkerLaunchOrphanedMcpProcesses, settleStartupAttemptResults, setDetachedSessionDestroyAfterJournalHookForTest, setTerminalEpochStartedHookForTest, } from '../runtime.js';
|
|
10
|
+
import { DEFAULT_MAX_WORKERS, initTeamState, createTask, writeWorkerInbox, readTeamConfig, readTeamManifestV2, saveTeamConfig, listMailboxMessages, sendDirectMessage, listDispatchRequests, listTasks, transitionDispatchRequest, updateWorkerHeartbeat, writeAtomic, readTask, readMonitorSnapshot, claimTask, transitionTaskStatus, releaseTaskClaim, readWorkerStatus, writeWorkerStatus, readTeamPhase, writeTeamPhase, } from '../state.js';
|
|
11
|
+
import { monitorTeam, shutdownTeam, resumeTeam, startTeam, assignTask, reassignTask, sendWorkerMessage, applyCreatedInteractiveSessionToConfig, reconcileStartupCleanupPanes, rethrowStartupRollbackProofDebt, resolveWorkerLaunchArgsFromEnv, resolveTeamWorkerCliForResolvedLaunchArgs, shouldPrekillInteractiveShutdownProcessTrees, waitForWorkerStartupEvidence, waitForClaudeStartupEvidence, cleanupTeamWorkerLaunchOrphanedMcpProcesses, settleStartupAttemptResults, setDetachedSessionDestroyAfterJournalHookForTest, setTerminalEpochStartedHookForTest, } from '../runtime.js';
|
|
12
12
|
import { resolveAgentReasoningEffort, resolveTeamLowComplexityDefaultModel, TEAM_WORKER_INHERITED_MODEL_ENV, } from '../model-contract.js';
|
|
13
13
|
import { readTeamEvents } from '../state/events.js';
|
|
14
14
|
import { sanitizeTeamName } from '../tmux-session.js';
|
|
@@ -16,6 +16,7 @@ import { buildInternalTeamName, resolveTeamIdentityScope } from '../team-identit
|
|
|
16
16
|
import { writePersistedApprovedTeamExecutionBinding } from '../approved-execution.js';
|
|
17
17
|
import { planWorktreeTarget } from '../worktree.js';
|
|
18
18
|
import { scaleDown } from '../scaling.js';
|
|
19
|
+
import { buildRebalanceDecisions } from '../rebalance-policy.js';
|
|
19
20
|
import { registerTeamNotice, teamNoticeLedgerPath, teamNoticeTargetKey } from '../notice-ledger.js';
|
|
20
21
|
const coverageRun = process.env.NODE_V8_COVERAGE ? true : false;
|
|
21
22
|
const skipSlowLifecycleUnderCoverage = coverageRun
|
|
@@ -39,6 +40,7 @@ async function initRepo() {
|
|
|
39
40
|
execFileSync('git', ['init'], { cwd, stdio: 'ignore' });
|
|
40
41
|
execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd, stdio: 'ignore' });
|
|
41
42
|
execFileSync('git', ['config', 'user.name', 'Test User'], { cwd, stdio: 'ignore' });
|
|
43
|
+
await writeFile(join(cwd, '.git/info/exclude'), '.omx/\n');
|
|
42
44
|
await writeFile(join(cwd, 'README.md'), 'hello\n', 'utf-8');
|
|
43
45
|
execFileSync('git', ['add', 'README.md'], { cwd, stdio: 'ignore' });
|
|
44
46
|
execFileSync('git', ['commit', '-m', 'init'], { cwd, stdio: 'ignore' });
|
|
@@ -49,6 +51,30 @@ async function addWorktree(repo, branchName, pathPrefix) {
|
|
|
49
51
|
execFileSync('git', ['worktree', 'add', '-b', branchName, worktreePath, 'HEAD'], { cwd: repo, stdio: 'ignore' });
|
|
50
52
|
return worktreePath;
|
|
51
53
|
}
|
|
54
|
+
async function handOffVerifiedIntegrationTasks(teamName, cwd) {
|
|
55
|
+
const config = await readTeamConfig(teamName, cwd);
|
|
56
|
+
assert.ok(config);
|
|
57
|
+
for (const worker of config.workers) {
|
|
58
|
+
const task = await createTask(teamName, {
|
|
59
|
+
subject: `Verified output from ${worker.name}`, description: 'Ready for integration',
|
|
60
|
+
status: 'pending', owner: worker.name, requires_code_change: true,
|
|
61
|
+
}, cwd);
|
|
62
|
+
const claim = await claimTask(teamName, task.id, worker.name, null, cwd);
|
|
63
|
+
assert.ok(claim.ok);
|
|
64
|
+
const workerCwd = worker.worktree_path;
|
|
65
|
+
await mkdir(join(workerCwd, '.omx/evidence'), { recursive: true });
|
|
66
|
+
await writeFile(join(workerCwd, '.omx/evidence/handoff.json'), JSON.stringify({
|
|
67
|
+
teamName, taskId: task.id, claimTokenSha256: createHash('sha256').update(claim.claimToken).digest('hex'),
|
|
68
|
+
verifiedHead: execFileSync('git', ['rev-parse', 'HEAD'], { cwd: workerCwd, encoding: 'utf8' }).trim(),
|
|
69
|
+
summary: 'Verified worker output', verification: [{ command: 'npm test', result: 'passed', output: 'Tests passed' }], unverified: [],
|
|
70
|
+
}));
|
|
71
|
+
const completed = await transitionTaskStatus(teamName, task.id, 'in_progress', 'completed', claim.claimToken, cwd, {
|
|
72
|
+
result: 'Verification: PASS `npm test` for worker output.\nEVIDENCE_RECORDED: .omx/evidence/handoff.json',
|
|
73
|
+
}, workerCwd);
|
|
74
|
+
assert.ok(completed.ok, JSON.stringify(completed));
|
|
75
|
+
await writeWorkerStatus(teamName, worker.name, { state: 'done', updated_at: new Date().toISOString() }, cwd);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
52
78
|
function computeGitBlobSha1(content) {
|
|
53
79
|
const buffer = Buffer.from(content, 'utf-8');
|
|
54
80
|
const header = Buffer.from(`blob ${buffer.length}\0`, 'utf-8');
|
|
@@ -3120,7 +3146,7 @@ esac
|
|
|
3120
3146
|
it('startTeam saves interactive pane ids before concurrent readiness attempts', async () => {
|
|
3121
3147
|
const source = await readFile(join(process.cwd(), 'src', 'team', 'runtime.ts'), 'utf-8');
|
|
3122
3148
|
const applyMatch = source.match(/applyCreatedInteractiveSessionToConfig\(\s*config,\s*createdSession,\s*workerPaneIds\s*\);/m);
|
|
3123
|
-
const saveMatch = source.match(/await
|
|
3149
|
+
const saveMatch = source.match(/await persistStartupTransport\(\);/m);
|
|
3124
3150
|
const readyMatch = source.match(/waitForWorkerReadyAsync\(/m);
|
|
3125
3151
|
const applyIndex = applyMatch?.index ?? -1;
|
|
3126
3152
|
const saveIndex = saveMatch?.index ?? -1;
|
|
@@ -3679,6 +3705,394 @@ esac
|
|
|
3679
3705
|
await rm(cwd, { recursive: true, force: true });
|
|
3680
3706
|
}
|
|
3681
3707
|
});
|
|
3708
|
+
for (const { partialFailure, followupDispatch } of [
|
|
3709
|
+
{ partialFailure: false, followupDispatch: undefined },
|
|
3710
|
+
{ partialFailure: true, followupDispatch: undefined },
|
|
3711
|
+
{ partialFailure: false, followupDispatch: 'gemini' },
|
|
3712
|
+
{ partialFailure: false, followupDispatch: 'codex-direct' },
|
|
3713
|
+
{ partialFailure: false, followupDispatch: 'codex-queued' },
|
|
3714
|
+
]) {
|
|
3715
|
+
it(followupDispatch
|
|
3716
|
+
? `startTeam preserves a follow-up inbox assigned after transport publication (${followupDispatch})`
|
|
3717
|
+
: `startTeam preserves early Gemini ownership changes ${partialFailure ? 'with partial-create proof debt' : 'before transport publication'}`, async () => {
|
|
3718
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-early-startup-'));
|
|
3719
|
+
try {
|
|
3720
|
+
await withMockTmuxFixture({
|
|
3721
|
+
dirPrefix: 'omx-runtime-early-startup-bin-',
|
|
3722
|
+
tmuxScript: (tmuxLogPath) => `#!/bin/sh
|
|
3723
|
+
set -eu
|
|
3724
|
+
${tmuxOwnerProofShim}
|
|
3725
|
+
printf '%s\n' "$*" >> "${tmuxLogPath}"
|
|
3726
|
+
case "$1" in
|
|
3727
|
+
-V)
|
|
3728
|
+
echo "tmux 3.4"
|
|
3729
|
+
exit 0
|
|
3730
|
+
;;
|
|
3731
|
+
display-message)
|
|
3732
|
+
case "$*" in
|
|
3733
|
+
*"#{window_width}"*) echo "120" ;;
|
|
3734
|
+
*) echo "leader:0 %1" ;;
|
|
3735
|
+
esac
|
|
3736
|
+
exit 0
|
|
3737
|
+
;;
|
|
3738
|
+
list-panes)
|
|
3739
|
+
case "$*" in
|
|
3740
|
+
*"-a -F #{pane_id}"*)
|
|
3741
|
+
${followupDispatch ? `if [ -f "${cwd}/early-ownership.json" ] && [ ! -f "${cwd}/handoff-started" ]; then gemini handoff > /dev/null; fi` : ':'}
|
|
3742
|
+
if [ -f "${cwd}/partial-proof-failure" ]; then printf 'malformed-pane-snapshot\n'; exit 0; fi
|
|
3743
|
+
printf "%%1\t0\t2000004141\n"
|
|
3744
|
+
if [ -f "${cwd}/early-startup-w1" ]; then printf "%%2\t0\t2000004242\n"; fi
|
|
3745
|
+
if [ -f "${cwd}/early-startup-w2" ]; then printf "%%3\t0\t2000004343\n"; fi
|
|
3746
|
+
if [ -f "${cwd}/early-startup-hud" ]; then printf "%%4\t0\t2000004444\n"; fi
|
|
3747
|
+
;;
|
|
3748
|
+
*"pane_current_command"*)
|
|
3749
|
+
printf "%%1\tnode\t'codex'\n"
|
|
3750
|
+
if [ -f "${cwd}/early-startup-w1" ]; then printf "%%2\tcodex\tcodex\n"; fi
|
|
3751
|
+
if [ -f "${cwd}/early-startup-w2" ]; then printf "%%3\tcodex\tcodex\n"; fi
|
|
3752
|
+
if [ -f "${cwd}/early-startup-hud" ]; then printf "%%4\tnode\thud --watch\n"; fi
|
|
3753
|
+
;;
|
|
3754
|
+
*"#{pane_dead} #{pane_pid}"*) echo "0 2000004242" ;;
|
|
3755
|
+
*"#{pane_dead}"*) echo "0" ;;
|
|
3756
|
+
*"-t %2"*"#{pane_pid}"*) echo "2000004242" ;;
|
|
3757
|
+
*"-t %3"*"#{pane_pid}"*) echo "2000004343" ;;
|
|
3758
|
+
*"#{pane_pid}"*) echo "2000004141" ;;
|
|
3759
|
+
*) exit 0 ;;
|
|
3760
|
+
esac
|
|
3761
|
+
exit 0
|
|
3762
|
+
;;
|
|
3763
|
+
capture-pane)
|
|
3764
|
+
printf '${followupDispatch === 'codex-queued' ? 'plain shell\n' : 'OpenAI Codex\nmodel: test\n› \n'}'
|
|
3765
|
+
exit 0
|
|
3766
|
+
;;
|
|
3767
|
+
split-window)
|
|
3768
|
+
count_file="${cwd}/early-startup-split-count"
|
|
3769
|
+
count=0
|
|
3770
|
+
if [ -f "$count_file" ]; then count=$(cat "$count_file"); fi
|
|
3771
|
+
count=$((count + 1))
|
|
3772
|
+
printf '%s' "$count" > "$count_file"
|
|
3773
|
+
case "$count" in
|
|
3774
|
+
1)
|
|
3775
|
+
: > "${cwd}/early-startup-w1"
|
|
3776
|
+
gemini
|
|
3777
|
+
echo "%2"
|
|
3778
|
+
;;
|
|
3779
|
+
2) : > "${cwd}/early-startup-w2"; echo "%3" ;;
|
|
3780
|
+
*)
|
|
3781
|
+
: > "${cwd}/early-startup-hud"
|
|
3782
|
+
${partialFailure ? `: > "${cwd}/partial-proof-failure"` : ':'}
|
|
3783
|
+
echo "%4"
|
|
3784
|
+
;;
|
|
3785
|
+
esac
|
|
3786
|
+
exit 0
|
|
3787
|
+
;;
|
|
3788
|
+
set-hook|run-shell|select-layout|set-window-option|select-pane|send-keys|kill-pane|kill-session|resize-pane)
|
|
3789
|
+
exit 0
|
|
3790
|
+
;;
|
|
3791
|
+
*)
|
|
3792
|
+
exit 0
|
|
3793
|
+
;;
|
|
3794
|
+
esac
|
|
3795
|
+
`,
|
|
3796
|
+
binaries: [{ name: 'gemini', content: `#!/usr/bin/env node
|
|
3797
|
+
if (process.argv.includes('--version')) { console.log('gemini test'); process.exit(0); }
|
|
3798
|
+
(async () => {
|
|
3799
|
+
const { readdir, readFile, writeFile } = await import('node:fs/promises');
|
|
3800
|
+
const { join } = await import('node:path');
|
|
3801
|
+
const { readTeamConfig, claimTask, releaseTaskClaim, createTask, readTask, readTeamManifestV2, writeTeamManifestV2, writeWorkerStatus } = await import(${JSON.stringify(new URL('../state.js', import.meta.url).href)});
|
|
3802
|
+
const cwd = ${JSON.stringify(cwd)};
|
|
3803
|
+
const [name] = await readdir(join(cwd, '.omx/state/team'));
|
|
3804
|
+
if (process.argv.includes('handoff')) {
|
|
3805
|
+
const transport = await readTeamConfig(name, cwd);
|
|
3806
|
+
if (!transport.workers[0].pane_id) return;
|
|
3807
|
+
const assert = (await import('node:assert/strict')).default;
|
|
3808
|
+
assert.equal(transport.workers[0].pane_id, '%2');
|
|
3809
|
+
assert.equal(transport.workers[0].pid, 2000004242);
|
|
3810
|
+
assert.equal(transport.hud_pane_id, '%4');
|
|
3811
|
+
await writeFile(join(cwd, 'handoff-started'), '');
|
|
3812
|
+
const { created } = JSON.parse(await readFile(join(cwd, 'early-ownership.json'), 'utf8'));
|
|
3813
|
+
const { assignTask } = await import(${JSON.stringify(new URL('../runtime.js', import.meta.url).href)});
|
|
3814
|
+
await assignTask(name, 'worker-1', created.id, cwd);
|
|
3815
|
+
const assigned = await readTask(name, created.id, cwd);
|
|
3816
|
+
const inbox = await readFile(join(cwd, '.omx/state/team', name, 'workers/worker-1/inbox.md'), 'utf8');
|
|
3817
|
+
await writeFile(join(cwd, 'followup-assigned.json'), JSON.stringify({ transport, assigned, inbox }));
|
|
3818
|
+
return;
|
|
3819
|
+
}
|
|
3820
|
+
const before = await readTeamConfig(name, cwd);
|
|
3821
|
+
const identities = await Promise.all(before.workers.map(async (worker) => {
|
|
3822
|
+
try { return JSON.parse(await readFile(join(cwd, '.omx/state/team', name, 'workers', worker.name, 'identity.json'), 'utf8')); }
|
|
3823
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
3824
|
+
}));
|
|
3825
|
+
const claim = await claimTask(name, '1', 'worker-1', null, cwd);
|
|
3826
|
+
if (!claim.ok) throw new Error('early_claim_failed');
|
|
3827
|
+
if (!(await releaseTaskClaim(name, '1', claim.claimToken, 'worker-1', cwd)).ok) throw new Error('early_release_failed');
|
|
3828
|
+
const created = await createTask(name, { subject: 'early followup', description: 'preserve task counter', status: 'pending' }, cwd);
|
|
3829
|
+
${followupDispatch ? `const manifest = await readTeamManifestV2(name, cwd);
|
|
3830
|
+
manifest.policy.dispatch_mode = 'transport_direct';
|
|
3831
|
+
await writeTeamManifestV2(manifest, cwd);
|
|
3832
|
+
for (const worker of before.workers) {
|
|
3833
|
+
await writeWorkerStatus(name, worker.name, { state: 'working', updated_at: new Date().toISOString() }, cwd);
|
|
3834
|
+
}` : ''}
|
|
3835
|
+
const released = await readTeamConfig(name, cwd);
|
|
3836
|
+
await writeFile(join(cwd, 'early-ownership.json'), JSON.stringify({ before, identities, released, created }));
|
|
3837
|
+
})().catch((error) => { console.error(error); process.exitCode = 1; });
|
|
3838
|
+
` }, { name: 'codex', content: fakeCodexNodeScript('process.stdin.resume();\n') }],
|
|
3839
|
+
env: {
|
|
3840
|
+
TMUX: undefined,
|
|
3841
|
+
TMUX_PANE: '%1',
|
|
3842
|
+
OMX_TEAM_WORKER_LAUNCH_MODE: 'interactive',
|
|
3843
|
+
OMX_TEAM_WORKER_CLI: followupDispatch?.startsWith('codex') ? 'codex' : 'gemini',
|
|
3844
|
+
OMX_TEAM_SKIP_READY_WAIT: followupDispatch === 'codex-queued' ? '1' : undefined,
|
|
3845
|
+
},
|
|
3846
|
+
}, async ({ tmuxLogPath }) => {
|
|
3847
|
+
const startup = withoutTeamWorkerEnv(() => startTeam('team-early-startup', 'initial prompt ownership changes', 'executor', 2, [
|
|
3848
|
+
{ subject: 'w1', description: 'worker one', owner: 'worker-1' },
|
|
3849
|
+
{ subject: 'w2', description: 'worker two', owner: 'worker-2' },
|
|
3850
|
+
], cwd));
|
|
3851
|
+
let teamName;
|
|
3852
|
+
if (partialFailure) {
|
|
3853
|
+
await assert.rejects(startup, (error) => {
|
|
3854
|
+
assert.ok(error instanceof Error);
|
|
3855
|
+
assert.match(error.message, /startup_rollback_pane_proof_unavailable:.*malformed_snapshot/);
|
|
3856
|
+
assert.match(error.message, /during startup_rollback of: create_team_session_cleanup_incomplete/);
|
|
3857
|
+
assert.doesNotMatch(error.message, /stale_generation/);
|
|
3858
|
+
assert.ok(error.cause instanceof Error);
|
|
3859
|
+
assert.match(error.cause.message, /create_team_session_cleanup_incomplete/);
|
|
3860
|
+
return true;
|
|
3861
|
+
});
|
|
3862
|
+
teamName = await resolveRuntimeTeamName(cwd, 'team-early-startup');
|
|
3863
|
+
}
|
|
3864
|
+
else {
|
|
3865
|
+
const runtime = await startup;
|
|
3866
|
+
teamName = runtime.teamName;
|
|
3867
|
+
assert.deepEqual(runtime.config, await readTeamConfig(teamName, cwd));
|
|
3868
|
+
}
|
|
3869
|
+
const { before, identities, released, created } = JSON.parse(await readFile(join(cwd, 'early-ownership.json'), 'utf8'));
|
|
3870
|
+
assert.deepEqual(before.workers.map((worker) => worker.assigned_tasks), [['1'], ['2']]);
|
|
3871
|
+
assert.deepEqual(identities.map((worker) => worker.assigned_tasks), [['1'], ['2']]);
|
|
3872
|
+
assert.ok(released.config_generation > before.config_generation);
|
|
3873
|
+
const canonical = await readTeamConfig(teamName, cwd);
|
|
3874
|
+
const manifest = await readTeamManifestV2(teamName, cwd);
|
|
3875
|
+
assert.ok(canonical);
|
|
3876
|
+
assert.deepEqual(canonical.workers.map((worker) => worker.assigned_tasks), [followupDispatch ? [created.id] : [], ['2']]);
|
|
3877
|
+
assert.equal(canonical.next_task_id, Number(created.id) + 1);
|
|
3878
|
+
assert.equal(canonical.next_task_id, released.next_task_id);
|
|
3879
|
+
assert.deepEqual(manifest?.workers, canonical.workers);
|
|
3880
|
+
assert.equal(manifest?.next_task_id, canonical.next_task_id);
|
|
3881
|
+
assert.equal(manifest?.config_generation, canonical.config_generation);
|
|
3882
|
+
assert.equal((await readTask(teamName, '1', cwd))?.owner, undefined);
|
|
3883
|
+
assert.equal((await readTask(teamName, created.id, cwd))?.subject, 'early followup');
|
|
3884
|
+
if (followupDispatch) {
|
|
3885
|
+
const handoff = JSON.parse(await readFile(join(cwd, 'followup-assigned.json'), 'utf8'));
|
|
3886
|
+
const assigned = await readTask(teamName, created.id, cwd);
|
|
3887
|
+
assert.equal(assigned?.status, 'in_progress');
|
|
3888
|
+
assert.equal(assigned?.owner, 'worker-1');
|
|
3889
|
+
assert.ok(assigned?.claim?.token);
|
|
3890
|
+
assert.equal(assigned.claim.token, handoff.assigned.claim.token);
|
|
3891
|
+
assert.deepEqual(assigned, handoff.assigned);
|
|
3892
|
+
const inbox = await readFile(join(cwd, '.omx/state/team', teamName, 'workers/worker-1/inbox.md'), 'utf8');
|
|
3893
|
+
assert.match(inbox, /early followup/);
|
|
3894
|
+
assert.match(inbox, new RegExp(`Task ${created.id}`));
|
|
3895
|
+
assert.equal(inbox, handoff.inbox, 'startup must preserve the entire current handoff, including any claim token');
|
|
3896
|
+
const requests = await listDispatchRequests(teamName, cwd);
|
|
3897
|
+
assert.ok(requests.some((request) => request.inbox_correlation_key === `assign:${created.id}:worker-1`));
|
|
3898
|
+
if (followupDispatch.startsWith('codex')) {
|
|
3899
|
+
const prefix = followupDispatch === 'codex-direct' ? 'startup-direct' : 'startup';
|
|
3900
|
+
assert.ok(requests.some((request) => request.inbox_correlation_key === `${prefix}:worker-1`), 'the later startup notification path must also preserve the follow-up inbox');
|
|
3901
|
+
}
|
|
3902
|
+
}
|
|
3903
|
+
if (partialFailure) {
|
|
3904
|
+
assert.equal(canonical.workers[0]?.pane_id, '%2');
|
|
3905
|
+
assert.equal(canonical.hud_pane_id, '%4');
|
|
3906
|
+
assert.ok((await readTeamEvents(teamName, cwd)).some((event) => event.reason?.startsWith('startup_create_session_cleanup_debt:')));
|
|
3907
|
+
}
|
|
3908
|
+
else {
|
|
3909
|
+
assert.doesNotMatch(await readFile(tmuxLogPath, 'utf8'), /^(?:kill-pane|kill-session|set-hook -u)\b/m);
|
|
3910
|
+
}
|
|
3911
|
+
for (const marker of ['early-startup-w1', 'early-startup-w2', 'early-startup-hud']) {
|
|
3912
|
+
assert.ok(existsSync(join(cwd, marker)));
|
|
3913
|
+
}
|
|
3914
|
+
});
|
|
3915
|
+
}
|
|
3916
|
+
finally {
|
|
3917
|
+
await rm(cwd, { recursive: true, force: true });
|
|
3918
|
+
}
|
|
3919
|
+
});
|
|
3920
|
+
}
|
|
3921
|
+
for (const failStartup of [false, true]) {
|
|
3922
|
+
it(failStartup
|
|
3923
|
+
? 'startTeam preserves ownership and rollback proof debt after concurrent startup failure'
|
|
3924
|
+
: 'startTeam preserves released assignments when ownership changes during concurrent startup', async () => {
|
|
3925
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-startup-generation-'));
|
|
3926
|
+
const teamName = 'team-startup-generation';
|
|
3927
|
+
try {
|
|
3928
|
+
await withMockTmuxFixture({
|
|
3929
|
+
dirPrefix: 'omx-runtime-startup-generation-bin-',
|
|
3930
|
+
tmuxScript: (tmuxLogPath) => `#!/bin/sh
|
|
3931
|
+
set -eu
|
|
3932
|
+
${tmuxOwnerProofShim}
|
|
3933
|
+
printf '%s\n' "$*" >> "${tmuxLogPath}"
|
|
3934
|
+
case "$1" in
|
|
3935
|
+
-V)
|
|
3936
|
+
echo "tmux 3.4"
|
|
3937
|
+
exit 0
|
|
3938
|
+
;;
|
|
3939
|
+
display-message)
|
|
3940
|
+
case "$*" in
|
|
3941
|
+
*"#{window_width}"*) echo "120" ;;
|
|
3942
|
+
*) echo "leader:0 %1" ;;
|
|
3943
|
+
esac
|
|
3944
|
+
exit 0
|
|
3945
|
+
;;
|
|
3946
|
+
list-panes)
|
|
3947
|
+
case "$*" in
|
|
3948
|
+
*"-a -F #{pane_id}"*)
|
|
3949
|
+
if [ -f "${cwd}/rollback-proof-failure" ]; then printf 'malformed-pane-snapshot\n'; exit 0; fi
|
|
3950
|
+
printf "%%1\t0\t2000004141\n"
|
|
3951
|
+
if [ -f "${cwd}/startup-generation-w1" ]; then printf "%%2\t0\t2000004242\n"; fi
|
|
3952
|
+
if [ -f "${cwd}/startup-generation-w2" ]; then printf "%%3\t0\t2000004343\n"; fi
|
|
3953
|
+
if [ -f "${cwd}/startup-generation-hud" ]; then printf "%%4\t0\t2000004444\n"; fi
|
|
3954
|
+
;;
|
|
3955
|
+
*"pane_current_command"*)
|
|
3956
|
+
printf "%%1\tnode\t'codex'\n"
|
|
3957
|
+
if [ -f "${cwd}/startup-generation-w1" ]; then printf "%%2\tcodex\tcodex\n"; fi
|
|
3958
|
+
if [ -f "${cwd}/startup-generation-w2" ]; then printf "%%3\tcodex\tcodex\n"; fi
|
|
3959
|
+
if [ -f "${cwd}/startup-generation-hud" ]; then printf "%%4\tnode\thud --watch\n"; fi
|
|
3960
|
+
;;
|
|
3961
|
+
*"#{pane_dead} #{pane_pid}"*) echo "0 2000004242" ;;
|
|
3962
|
+
*"#{pane_dead}"*) echo "0" ;;
|
|
3963
|
+
*"-t %2"*"#{pane_pid}"*) echo "2000004242" ;;
|
|
3964
|
+
*"-t %3"*"#{pane_pid}"*) echo "2000004343" ;;
|
|
3965
|
+
*"#{pane_pid}"*) echo "2000004141" ;;
|
|
3966
|
+
*) exit 0 ;;
|
|
3967
|
+
esac
|
|
3968
|
+
exit 0
|
|
3969
|
+
;;
|
|
3970
|
+
capture-pane)
|
|
3971
|
+
printf 'OpenAI Codex\nmodel: test\n› \n'
|
|
3972
|
+
exit 0
|
|
3973
|
+
;;
|
|
3974
|
+
split-window)
|
|
3975
|
+
count_file="${cwd}/startup-generation-split-count"
|
|
3976
|
+
count=0
|
|
3977
|
+
if [ -f "$count_file" ]; then count=$(cat "$count_file"); fi
|
|
3978
|
+
count=$((count + 1))
|
|
3979
|
+
printf '%s' "$count" > "$count_file"
|
|
3980
|
+
case "$count" in
|
|
3981
|
+
1) : > "${cwd}/startup-generation-w1"; echo "%2" ;;
|
|
3982
|
+
2) : > "${cwd}/startup-generation-w2"; echo "%3" ;;
|
|
3983
|
+
*) : > "${cwd}/startup-generation-hud"; echo "%4" ;;
|
|
3984
|
+
esac
|
|
3985
|
+
exit 0
|
|
3986
|
+
;;
|
|
3987
|
+
set-hook|run-shell|select-layout|set-window-option|select-pane|send-keys|kill-pane|kill-session|resize-pane)
|
|
3988
|
+
exit 0
|
|
3989
|
+
;;
|
|
3990
|
+
*)
|
|
3991
|
+
exit 0
|
|
3992
|
+
;;
|
|
3993
|
+
esac
|
|
3994
|
+
`,
|
|
3995
|
+
binaries: [{ name: 'codex', content: fakeCodexNodeScript('process.stdin.resume();\n') }],
|
|
3996
|
+
env: {
|
|
3997
|
+
TMUX: undefined,
|
|
3998
|
+
TMUX_PANE: '%1',
|
|
3999
|
+
OMX_TEAM_WORKER_LAUNCH_MODE: 'interactive',
|
|
4000
|
+
OMX_TEAM_WORKER_CLI: 'codex',
|
|
4001
|
+
OMX_TEAM_READY_TIMEOUT_MS: '500',
|
|
4002
|
+
OMX_TEAM_STARTUP_EVIDENCE_TIMEOUT_MS: '50',
|
|
4003
|
+
OMX_TEAM_STARTUP_DISPATCH_RETRIES: '1',
|
|
4004
|
+
},
|
|
4005
|
+
}, async ({ tmuxLogPath }) => {
|
|
4006
|
+
let settled = false;
|
|
4007
|
+
const startup = withoutTeamWorkerEnv(() => startTeam(teamName, 'ownership changes during startup', 'executor', 2, [
|
|
4008
|
+
{ subject: 'w1', description: 'worker one', owner: 'worker-1' },
|
|
4009
|
+
{ subject: 'w2', description: 'worker two', owner: 'worker-2' },
|
|
4010
|
+
], cwd));
|
|
4011
|
+
void startup.then(() => { settled = true; }, () => { settled = true; });
|
|
4012
|
+
try {
|
|
4013
|
+
// Keep worker-2's hook receipt pending while worker-1 starts and releases its task.
|
|
4014
|
+
const deadline = Date.now() + 10_000;
|
|
4015
|
+
while (true) {
|
|
4016
|
+
const requests = await listDispatchRequests(await resolveRuntimeTeamName(cwd, teamName), cwd);
|
|
4017
|
+
if (['worker-1', 'worker-2'].every((worker) => requests.some((request) => request.to_worker === worker && request.inbox_correlation_key === `startup:${worker}`
|
|
4018
|
+
&& request.status === 'pending')))
|
|
4019
|
+
break;
|
|
4020
|
+
assert.equal(settled, false, 'startup must still be waiting for dispatch');
|
|
4021
|
+
assert.ok(Date.now() < deadline, 'both workers must reach startup dispatch');
|
|
4022
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
4023
|
+
}
|
|
4024
|
+
const canonicalName = await resolveRuntimeTeamName(cwd, teamName);
|
|
4025
|
+
await markPendingInboxDispatchesDelivered(canonicalName, cwd, { toWorker: 'worker-1' });
|
|
4026
|
+
const beforeRelease = await readTeamConfig(canonicalName, cwd);
|
|
4027
|
+
assert.ok(beforeRelease);
|
|
4028
|
+
const taskId = beforeRelease.workers[0].assigned_tasks[0];
|
|
4029
|
+
const claim = await claimTask(canonicalName, taskId, 'worker-1', null, cwd);
|
|
4030
|
+
assert.ok(claim.ok);
|
|
4031
|
+
assert.ok((await releaseTaskClaim(canonicalName, taskId, claim.claimToken, 'worker-1', cwd)).ok);
|
|
4032
|
+
const releasedConfig = await readTeamConfig(canonicalName, cwd);
|
|
4033
|
+
assert.ok(releasedConfig);
|
|
4034
|
+
assert.ok(releasedConfig.config_generation > beforeRelease.config_generation);
|
|
4035
|
+
assert.equal(settled, false, 'worker-2 dispatch must hold startup open through release');
|
|
4036
|
+
assert.ok((await listDispatchRequests(canonicalName, cwd)).some((request) => request.to_worker === 'worker-2' && request.status === 'pending'));
|
|
4037
|
+
if (failStartup) {
|
|
4038
|
+
const worker2Dispatch = (await listDispatchRequests(canonicalName, cwd)).find((request) => request.to_worker === 'worker-2' && request.status === 'pending');
|
|
4039
|
+
assert.ok(worker2Dispatch);
|
|
4040
|
+
await writeFile(join(cwd, 'rollback-proof-failure'), '');
|
|
4041
|
+
await transitionDispatchRequest(canonicalName, worker2Dispatch.request_id, 'pending', 'failed', {
|
|
4042
|
+
last_reason: 'hook_failed:test_startup_failure',
|
|
4043
|
+
}, cwd);
|
|
4044
|
+
await assert.rejects(startup, (error) => {
|
|
4045
|
+
assert.ok(error instanceof Error);
|
|
4046
|
+
assert.match(error.message, /startup_rollback_pane_proof_unavailable:%2:malformed_snapshot/);
|
|
4047
|
+
assert.doesNotMatch(error.message, /stale_generation/);
|
|
4048
|
+
return true;
|
|
4049
|
+
});
|
|
4050
|
+
const preserved = await readTeamConfig(canonicalName, cwd);
|
|
4051
|
+
const manifest = await readTeamManifestV2(canonicalName, cwd);
|
|
4052
|
+
assert.ok(preserved);
|
|
4053
|
+
assert.deepEqual(preserved.workers.map((worker) => worker.assigned_tasks), [[], beforeRelease.workers[1].assigned_tasks]);
|
|
4054
|
+
assert.equal(preserved.next_task_id, releasedConfig.next_task_id);
|
|
4055
|
+
assert.equal(preserved.workers[0]?.pane_id, '%2');
|
|
4056
|
+
assert.equal(preserved.hud_pane_id, '%4');
|
|
4057
|
+
assert.ok(preserved.resize_hook_name);
|
|
4058
|
+
assert.deepEqual(manifest?.workers, preserved.workers);
|
|
4059
|
+
assert.equal(manifest?.config_generation, preserved.config_generation);
|
|
4060
|
+
assert.ok(preserved.config_generation > releasedConfig.config_generation);
|
|
4061
|
+
assert.equal((await readTask(canonicalName, taskId, cwd))?.owner, undefined);
|
|
4062
|
+
assert.doesNotMatch(await readFile(tmuxLogPath, 'utf8'), /^(?:kill-pane|kill-session)\b/m);
|
|
4063
|
+
return;
|
|
4064
|
+
}
|
|
4065
|
+
await markPendingInboxDispatchesDelivered(canonicalName, cwd, { toWorker: 'worker-2' });
|
|
4066
|
+
const runtime = await startup;
|
|
4067
|
+
const canonical = await readTeamConfig(runtime.teamName, cwd);
|
|
4068
|
+
const manifest = await readTeamManifestV2(runtime.teamName, cwd);
|
|
4069
|
+
assert.deepEqual(runtime.config, canonical);
|
|
4070
|
+
assert.deepEqual(canonical, releasedConfig, 'startup must not rewrite canonical membership');
|
|
4071
|
+
assert.deepEqual(canonical?.workers.map((worker) => worker.assigned_tasks), [[], beforeRelease.workers[1].assigned_tasks]);
|
|
4072
|
+
assert.deepEqual(manifest?.workers, canonical?.workers);
|
|
4073
|
+
assert.equal(manifest?.config_generation, canonical?.config_generation);
|
|
4074
|
+
const releasedTask = await readTask(runtime.teamName, taskId, cwd);
|
|
4075
|
+
assert.equal(releasedTask?.status, 'pending');
|
|
4076
|
+
assert.equal(releasedTask?.owner, undefined);
|
|
4077
|
+
assert.equal(releasedTask?.claim, undefined);
|
|
4078
|
+
for (const worker of runtime.config.workers) {
|
|
4079
|
+
assert.ok(existsSync(join(cwd, '.omx/state/team', runtime.teamName, 'workers', worker.name, 'identity.json')));
|
|
4080
|
+
}
|
|
4081
|
+
for (const marker of ['startup-generation-w1', 'startup-generation-w2', 'startup-generation-hud']) {
|
|
4082
|
+
assert.ok(existsSync(join(cwd, marker)), 'created pane resources must remain');
|
|
4083
|
+
}
|
|
4084
|
+
assert.doesNotMatch(await readFile(tmuxLogPath, 'utf-8'), /^(?:kill-pane|kill-session|set-hook -u)\b/m);
|
|
4085
|
+
}
|
|
4086
|
+
finally {
|
|
4087
|
+
await startup.catch(() => { });
|
|
4088
|
+
}
|
|
4089
|
+
});
|
|
4090
|
+
}
|
|
4091
|
+
finally {
|
|
4092
|
+
await rm(cwd, { recursive: true, force: true });
|
|
4093
|
+
}
|
|
4094
|
+
});
|
|
4095
|
+
}
|
|
3682
4096
|
it('startTeam starts worker-2 readiness before delayed worker-1 readiness settles', async () => {
|
|
3683
4097
|
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-parallel-ready-'));
|
|
3684
4098
|
const previousTmux = process.env.TMUX;
|
|
@@ -5982,6 +6396,82 @@ process.on('SIGTERM', () => process.exit(0));
|
|
|
5982
6396
|
await rm(cwd, { recursive: true, force: true });
|
|
5983
6397
|
}
|
|
5984
6398
|
});
|
|
6399
|
+
it('monitorTeam preserves an owned pending startup inbox before the first claim', async () => {
|
|
6400
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-pending-inbox-'));
|
|
6401
|
+
try {
|
|
6402
|
+
await withMockTmuxFixture({
|
|
6403
|
+
dirPrefix: 'omx-pending-inbox-tmux-',
|
|
6404
|
+
tmuxScript: () => `#!/bin/sh
|
|
6405
|
+
case "$1" in
|
|
6406
|
+
-V) echo 'tmux 3.4' ;;
|
|
6407
|
+
list-panes) echo '0 ${process.pid}' ;;
|
|
6408
|
+
capture-pane) echo 'working' ;;
|
|
6409
|
+
esac
|
|
6410
|
+
`,
|
|
6411
|
+
}, async () => {
|
|
6412
|
+
await initTeamState('pending-inbox', 'startup', 'executor', 1, cwd);
|
|
6413
|
+
const initial = await createTask('pending-inbox', { subject: 'startup', description: 'work', status: 'pending', owner: 'worker-1' }, cwd);
|
|
6414
|
+
const overflow = await createTask('pending-inbox', { subject: 'overflow', description: 'work', status: 'pending' }, cwd);
|
|
6415
|
+
await writeWorkerInbox('pending-inbox', 'worker-1', `Initial Task ${initial.id}`, cwd);
|
|
6416
|
+
await writeWorkerStatus('pending-inbox', 'worker-1', { state: 'idle', updated_at: new Date().toISOString() }, cwd);
|
|
6417
|
+
await monitorTeam('pending-inbox', cwd);
|
|
6418
|
+
assert.equal(await readFile(join(cwd, '.omx/state/team/pending-inbox/workers/worker-1/inbox.md'), 'utf8'), `Initial Task ${initial.id}`);
|
|
6419
|
+
assert.equal((await readTask('pending-inbox', overflow.id, cwd))?.owner, undefined);
|
|
6420
|
+
assert.equal((await readTask('pending-inbox', initial.id, cwd))?.status, 'pending');
|
|
6421
|
+
assert.equal((await listDispatchRequests('pending-inbox', cwd)).length, 0);
|
|
6422
|
+
});
|
|
6423
|
+
}
|
|
6424
|
+
finally {
|
|
6425
|
+
await rm(cwd, { recursive: true, force: true });
|
|
6426
|
+
}
|
|
6427
|
+
});
|
|
6428
|
+
it('monitorTeam leaves overflow pending and preserves the only inbox while its claim is outstanding', async () => {
|
|
6429
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-rebalance-inbox-'));
|
|
6430
|
+
try {
|
|
6431
|
+
await withMockTmuxFixture({
|
|
6432
|
+
dirPrefix: 'omx-rebalance-inbox-tmux-',
|
|
6433
|
+
tmuxScript: () => `#!/bin/sh
|
|
6434
|
+
case "$1" in
|
|
6435
|
+
-V) echo 'tmux 3.4' ;;
|
|
6436
|
+
list-panes) echo '0 ${process.pid}' ;;
|
|
6437
|
+
capture-pane) echo 'working' ;;
|
|
6438
|
+
esac
|
|
6439
|
+
`,
|
|
6440
|
+
}, async () => {
|
|
6441
|
+
await initTeamState('team-one-inbox', 'followups', 'executor', 1, cwd);
|
|
6442
|
+
const tasks = await Promise.all(Array.from({ length: 3 }, (_, i) => createTask('team-one-inbox', {
|
|
6443
|
+
subject: `followup ${i}`, description: 'work', status: 'pending',
|
|
6444
|
+
}, cwd)));
|
|
6445
|
+
const manifestPath = join(cwd, '.omx/state/team/team-one-inbox/manifest.v2.json');
|
|
6446
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
6447
|
+
manifest.policy.dispatch_mode = 'transport_direct';
|
|
6448
|
+
manifest.tmux_session = 'omx-team-one-inbox';
|
|
6449
|
+
await writeAtomic(manifestPath, JSON.stringify(manifest));
|
|
6450
|
+
await writeWorkerStatus('team-one-inbox', 'worker-1', { state: 'idle', updated_at: new Date().toISOString() }, cwd);
|
|
6451
|
+
const first = await monitorTeam('team-one-inbox', cwd);
|
|
6452
|
+
assert.equal(first?.tasks.in_progress, 1, JSON.stringify(first?.recommendations));
|
|
6453
|
+
assert.equal(first?.tasks.pending, 2);
|
|
6454
|
+
const inboxPath = join(cwd, '.omx/state/team/team-one-inbox/workers/worker-1/inbox.md');
|
|
6455
|
+
const inbox = await readFile(inboxPath, 'utf8');
|
|
6456
|
+
const claimed = (await Promise.all(tasks.map((task) => readTask('team-one-inbox', task.id, cwd)))).find((task) => task?.status === 'in_progress');
|
|
6457
|
+
assert.match(inbox, new RegExp(`Task ${claimed.id}`));
|
|
6458
|
+
assert.equal((await listDispatchRequests('team-one-inbox', cwd)).filter((request) => request.kind === 'inbox').length, 1);
|
|
6459
|
+
// The worker has not updated its idle status yet; the live claim still excludes it.
|
|
6460
|
+
await monitorTeam('team-one-inbox', cwd);
|
|
6461
|
+
assert.equal(await readFile(inboxPath, 'utf8'), inbox);
|
|
6462
|
+
assert.equal((await listDispatchRequests('team-one-inbox', cwd)).filter((request) => request.kind === 'inbox').length, 1);
|
|
6463
|
+
assert.equal((await Promise.all(tasks.map((task) => readTask('team-one-inbox', task.id, cwd)))).filter((task) => task?.status === 'pending').length, 2);
|
|
6464
|
+
const done = await transitionTaskStatus('team-one-inbox', claimed.id, 'in_progress', 'completed', claimed.claim.token, cwd);
|
|
6465
|
+
assert.equal(done.ok, true);
|
|
6466
|
+
const next = await monitorTeam('team-one-inbox', cwd);
|
|
6467
|
+
assert.equal(next?.tasks.in_progress, 1);
|
|
6468
|
+
assert.equal(next?.tasks.pending, 1, 'overflow becomes available on a later monitor');
|
|
6469
|
+
});
|
|
6470
|
+
}
|
|
6471
|
+
finally {
|
|
6472
|
+
await rm(cwd, { recursive: true, force: true });
|
|
6473
|
+
}
|
|
6474
|
+
});
|
|
5985
6475
|
it('monitorTeam surfaces reclaimed work pickup attempts when an idle worker is available', async () => {
|
|
5986
6476
|
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-reassign-reclaimed-'));
|
|
5987
6477
|
const prevTeamStateRoot = process.env.OMX_TEAM_STATE_ROOT;
|
|
@@ -6104,6 +6594,32 @@ process.on('SIGTERM', () => process.exit(0));
|
|
|
6104
6594
|
await rm(cwd, { recursive: true, force: true });
|
|
6105
6595
|
}
|
|
6106
6596
|
});
|
|
6597
|
+
it('monitorTeam does not reactivate an ordinary completed root from pending task counts alone without worktrees', async () => {
|
|
6598
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-root-counts-only-'));
|
|
6599
|
+
const teamName = 'team-root-counts-only';
|
|
6600
|
+
try {
|
|
6601
|
+
await initTeamState(teamName, 'counts-only root sync', 'executor', 1, cwd);
|
|
6602
|
+
const config = await readTeamConfig(teamName, cwd);
|
|
6603
|
+
assert.ok(config?.workers.every((worker) => !worker.worktree_path && !worker.worktree_repo_root));
|
|
6604
|
+
const task = await createTask(teamName, { subject: 'initial work', description: 'pending', status: 'pending' }, cwd);
|
|
6605
|
+
const phase = await readTeamPhase(teamName, cwd);
|
|
6606
|
+
assert.ok(phase);
|
|
6607
|
+
await writeTeamPhase(teamName, { ...phase, current_phase: 'complete' }, cwd);
|
|
6608
|
+
const rootStatePath = join(cwd, '.omx/state/team-state.json');
|
|
6609
|
+
const rootBefore = JSON.stringify({
|
|
6610
|
+
active: false, current_phase: 'complete', team_name: teamName, completed_at: new Date().toISOString(),
|
|
6611
|
+
});
|
|
6612
|
+
await writeFile(rootStatePath, rootBefore);
|
|
6613
|
+
assert.equal((await monitorTeam(teamName, cwd, { readOnly: true }))?.phase, 'team-exec');
|
|
6614
|
+
assert.equal(await readFile(rootStatePath, 'utf8'), rootBefore);
|
|
6615
|
+
assert.equal((await monitorTeam(teamName, cwd))?.phase, 'team-exec');
|
|
6616
|
+
assert.equal(await readFile(rootStatePath, 'utf8'), rootBefore);
|
|
6617
|
+
assert.equal((await readTask(teamName, task.id, cwd))?.status, 'pending');
|
|
6618
|
+
}
|
|
6619
|
+
finally {
|
|
6620
|
+
await rm(cwd, { recursive: true, force: true });
|
|
6621
|
+
}
|
|
6622
|
+
});
|
|
6107
6623
|
it('monitorTeam deactivates root team-state.json when the local phase becomes terminal', async () => {
|
|
6108
6624
|
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-root-team-state-'));
|
|
6109
6625
|
try {
|
|
@@ -6179,6 +6695,7 @@ process.on('SIGTERM', () => process.exit(0));
|
|
|
6179
6695
|
worktree_created: false,
|
|
6180
6696
|
};
|
|
6181
6697
|
await saveTeamConfig(cfg, repo);
|
|
6698
|
+
await handOffVerifiedIntegrationTasks('team-integration-ledger', repo);
|
|
6182
6699
|
await monitorTeam('team-integration-ledger', repo);
|
|
6183
6700
|
const firstSnapshot = await readMonitorSnapshot('team-integration-ledger', repo);
|
|
6184
6701
|
assert.equal(firstSnapshot?.integrationByWorker?.['worker-1']?.last_seen_head, workerHead);
|
|
@@ -6211,52 +6728,216 @@ process.on('SIGTERM', () => process.exit(0));
|
|
|
6211
6728
|
await rm(repo, { recursive: true, force: true });
|
|
6212
6729
|
}
|
|
6213
6730
|
});
|
|
6214
|
-
|
|
6731
|
+
for (const mutation of ['tracked-edit', 'untracked-file', 'different-head', 'research-only', 'legacy-completion']) {
|
|
6732
|
+
it(`monitorTeam refuses publication without a matching clean code handoff (${mutation})`, async () => {
|
|
6733
|
+
const repo = await initRepo();
|
|
6734
|
+
let workerPath = '';
|
|
6735
|
+
try {
|
|
6736
|
+
const team = 'team-handoff-identity';
|
|
6737
|
+
workerPath = await addWorktree(repo, 'handoff-identity-worker', 'omx-runtime-handoff-identity-');
|
|
6738
|
+
await writeFile(join(workerPath, 'code.txt'), 'verified worker code\n');
|
|
6739
|
+
execFileSync('git', ['add', 'code.txt'], { cwd: workerPath });
|
|
6740
|
+
execFileSync('git', ['commit', '-m', 'verified worker commit'], { cwd: workerPath, stdio: 'ignore' });
|
|
6741
|
+
await initTeamState(team, 'handoff identity test', 'executor', 1, repo);
|
|
6742
|
+
const config = await readTeamConfig(team, repo);
|
|
6743
|
+
assert.ok(config);
|
|
6744
|
+
Object.assign(config.workers[0], { worktree_repo_root: repo, worktree_path: workerPath, worktree_branch: 'handoff-identity-worker' });
|
|
6745
|
+
await saveTeamConfig(config, repo);
|
|
6746
|
+
if (mutation === 'research-only') {
|
|
6747
|
+
const research = await createTask(team, { subject: 'research', description: 'read only', status: 'pending', requires_code_change: false }, repo);
|
|
6748
|
+
const claim = await claimTask(team, research.id, 'worker-1', null, repo);
|
|
6749
|
+
assert.ok(claim.ok);
|
|
6750
|
+
assert.ok((await transitionTaskStatus(team, research.id, 'in_progress', 'completed', claim.claimToken, repo, { result: 'Research complete; no code changes requested.' })).ok);
|
|
6751
|
+
await writeWorkerStatus(team, 'worker-1', { state: 'idle', updated_at: new Date().toISOString() }, repo);
|
|
6752
|
+
}
|
|
6753
|
+
else if (mutation === 'legacy-completion') {
|
|
6754
|
+
// Persisted legacy completions have no authoritative Git identity.
|
|
6755
|
+
await createTask(team, { subject: 'legacy code', description: 'old completion', status: 'completed', owner: 'worker-1', requires_code_change: true, result: 'Verification: PASS `npm test`.' }, repo);
|
|
6756
|
+
await writeWorkerStatus(team, 'worker-1', { state: 'idle', updated_at: new Date().toISOString() }, repo);
|
|
6757
|
+
}
|
|
6758
|
+
else {
|
|
6759
|
+
await handOffVerifiedIntegrationTasks(team, repo);
|
|
6760
|
+
if (mutation === 'untracked-file') {
|
|
6761
|
+
await writeFile(join(workerPath, 'later.txt'), 'unverified untracked content\n');
|
|
6762
|
+
}
|
|
6763
|
+
else {
|
|
6764
|
+
await writeFile(join(workerPath, 'code.txt'), 'later unverified tracked bytes\n');
|
|
6765
|
+
if (mutation === 'different-head') {
|
|
6766
|
+
execFileSync('git', ['add', 'code.txt'], { cwd: workerPath });
|
|
6767
|
+
execFileSync('git', ['commit', '-m', 'later unverified commit'], { cwd: workerPath, stdio: 'ignore' });
|
|
6768
|
+
}
|
|
6769
|
+
}
|
|
6770
|
+
}
|
|
6771
|
+
const git = (cwd, args) => execFileSync('git', args, { cwd, encoding: 'utf8' }).trim();
|
|
6772
|
+
if (mutation === 'legacy-completion' || mutation === 'different-head') {
|
|
6773
|
+
await createTask(team, { subject: 'leader follow-up', description: 'keep execution open for re-verification', status: 'pending' }, repo);
|
|
6774
|
+
}
|
|
6775
|
+
const leaderHead = git(repo, ['rev-parse', 'HEAD']);
|
|
6776
|
+
const workerHead = git(workerPath, ['rev-parse', 'HEAD']);
|
|
6777
|
+
const workerStatus = git(workerPath, ['status', '--porcelain']);
|
|
6778
|
+
await monitorTeam(team, repo);
|
|
6779
|
+
assert.equal(git(repo, ['rev-parse', 'HEAD']), leaderHead);
|
|
6780
|
+
assert.equal(git(workerPath, ['rev-parse', 'HEAD']), workerHead);
|
|
6781
|
+
assert.equal(git(workerPath, ['status', '--porcelain']), workerStatus);
|
|
6782
|
+
assert.equal(existsSync(join(repo, 'code.txt')), false);
|
|
6783
|
+
if (mutation === 'tracked-edit' || mutation === 'different-head')
|
|
6784
|
+
assert.equal(await readFile(join(workerPath, 'code.txt'), 'utf8'), 'later unverified tracked bytes\n');
|
|
6785
|
+
const events = await readTeamEvents(team, repo, { wakeableOnly: false });
|
|
6786
|
+
assert.equal(events.some((event) => ['worker_auto_commit', 'worker_merge_applied', 'worker_cherry_pick_applied', 'worker_cross_rebase_applied'].includes(event.type)), false);
|
|
6787
|
+
if (mutation === 'legacy-completion' || mutation === 'different-head') {
|
|
6788
|
+
// A fresh verified code task is the supported migration/reverification path.
|
|
6789
|
+
await handOffVerifiedIntegrationTasks(team, repo);
|
|
6790
|
+
await monitorTeam(team, repo);
|
|
6791
|
+
assert.equal(await readFile(join(repo, 'code.txt'), 'utf8'), mutation === 'different-head' ? 'later unverified tracked bytes\n' : 'verified worker code\n');
|
|
6792
|
+
}
|
|
6793
|
+
}
|
|
6794
|
+
finally {
|
|
6795
|
+
if (workerPath)
|
|
6796
|
+
await rm(workerPath, { recursive: true, force: true });
|
|
6797
|
+
await rm(repo, { recursive: true, force: true });
|
|
6798
|
+
}
|
|
6799
|
+
});
|
|
6800
|
+
}
|
|
6801
|
+
it('monitorTeam integrates verified B after public release and reassignment of bootstrap A', async () => {
|
|
6215
6802
|
const repo = await initRepo();
|
|
6216
6803
|
let workerPath = '';
|
|
6217
6804
|
try {
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
await
|
|
6221
|
-
await
|
|
6222
|
-
const
|
|
6223
|
-
assert.ok(
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
const
|
|
6240
|
-
assert.
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
assert.
|
|
6805
|
+
const team = 'team-transfer-handoff';
|
|
6806
|
+
workerPath = await addWorktree(repo, 'transfer-handoff-worker', 'omx-runtime-transfer-handoff-');
|
|
6807
|
+
await initTeamState(team, 'release A then verify B', 'executor', 2, repo);
|
|
6808
|
+
const taskA = await createTask(team, { subject: 'A', description: 'reassigned research', status: 'pending', requires_code_change: false }, repo);
|
|
6809
|
+
const config = await readTeamConfig(team, repo);
|
|
6810
|
+
assert.ok(config);
|
|
6811
|
+
Object.assign(config.workers[0], {
|
|
6812
|
+
assigned_tasks: [taskA.id], worktree_repo_root: repo,
|
|
6813
|
+
worktree_path: workerPath, worktree_branch: 'transfer-handoff-worker',
|
|
6814
|
+
});
|
|
6815
|
+
await saveTeamConfig(config, repo);
|
|
6816
|
+
const first = await claimTask(team, taskA.id, 'worker-1', null, repo);
|
|
6817
|
+
assert.ok(first.ok);
|
|
6818
|
+
assert.ok((await releaseTaskClaim(team, taskA.id, first.claimToken, 'worker-1', repo)).ok);
|
|
6819
|
+
const transferred = await claimTask(team, taskA.id, 'worker-2', null, repo);
|
|
6820
|
+
assert.ok(transferred.ok);
|
|
6821
|
+
assert.ok((await transitionTaskStatus(team, taskA.id, 'in_progress', 'completed', transferred.claimToken, repo, { result: 'Research A complete.' })).ok);
|
|
6822
|
+
await writeFile(join(workerPath, 'code-b.txt'), 'verified B after transferring A\n');
|
|
6823
|
+
execFileSync('git', ['add', 'code-b.txt'], { cwd: workerPath });
|
|
6824
|
+
execFileSync('git', ['commit', '-m', 'verified B'], { cwd: workerPath, stdio: 'ignore' });
|
|
6825
|
+
const taskB = await createTask(team, { subject: 'B', description: 'verified code', status: 'pending', requires_code_change: true }, repo);
|
|
6826
|
+
const claimB = await claimTask(team, taskB.id, 'worker-1', null, repo);
|
|
6827
|
+
assert.ok(claimB.ok);
|
|
6828
|
+
const verifiedHead = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: workerPath, encoding: 'utf8' }).trim();
|
|
6829
|
+
await mkdir(join(workerPath, '.omx/evidence'), { recursive: true });
|
|
6830
|
+
await writeFile(join(workerPath, '.omx/evidence/b.json'), JSON.stringify({
|
|
6831
|
+
teamName: team, taskId: taskB.id,
|
|
6832
|
+
claimTokenSha256: createHash('sha256').update(claimB.claimToken).digest('hex'), verifiedHead,
|
|
6833
|
+
summary: 'Verified B', verification: [{ command: 'npm test', result: 'passed', output: 'B passed' }], unverified: [],
|
|
6834
|
+
}));
|
|
6835
|
+
const completed = await transitionTaskStatus(team, taskB.id, 'in_progress', 'completed', claimB.claimToken, repo, {
|
|
6836
|
+
result: 'Verification: PASS `npm test` for B.\nEVIDENCE_RECORDED: .omx/evidence/b.json',
|
|
6837
|
+
});
|
|
6838
|
+
assert.ok(completed.ok, JSON.stringify(completed));
|
|
6839
|
+
assert.equal(completed.task.verified_head, verifiedHead);
|
|
6840
|
+
await writeWorkerStatus(team, 'worker-1', { state: 'done', updated_at: new Date().toISOString() }, repo);
|
|
6841
|
+
assert.deepEqual((await readTeamConfig(team, repo))?.workers.map((worker) => worker.assigned_tasks), [[taskB.id], [taskA.id]]);
|
|
6842
|
+
await monitorTeam(team, repo);
|
|
6843
|
+
assert.equal(await readFile(join(repo, 'code-b.txt'), 'utf8'), 'verified B after transferring A\n');
|
|
6844
|
+
assert.ok((await readMonitorSnapshot(team, repo))?.integrationByWorker?.['worker-1']?.last_integrated_head);
|
|
6252
6845
|
}
|
|
6253
6846
|
finally {
|
|
6254
|
-
if (workerPath)
|
|
6847
|
+
if (workerPath)
|
|
6848
|
+
await rm(workerPath, { recursive: true, force: true });
|
|
6849
|
+
await rm(repo, { recursive: true, force: true });
|
|
6850
|
+
}
|
|
6851
|
+
});
|
|
6852
|
+
it('monitorTeam integrates verified code after exempt historical research completion', async () => {
|
|
6853
|
+
const repo = await initRepo();
|
|
6854
|
+
let workerPath = '';
|
|
6855
|
+
try {
|
|
6856
|
+
const team = 'team-research-code';
|
|
6857
|
+
workerPath = await addWorktree(repo, 'research-code-worker', 'omx-runtime-research-code-');
|
|
6858
|
+
await initTeamState(team, 'research then code', 'executor', 1, repo);
|
|
6859
|
+
const config = await readTeamConfig(team, repo);
|
|
6860
|
+
assert.ok(config);
|
|
6861
|
+
Object.assign(config.workers[0], { worktree_repo_root: repo, worktree_path: workerPath, worktree_branch: 'research-code-worker' });
|
|
6862
|
+
await saveTeamConfig(config, repo);
|
|
6863
|
+
const research = await createTask(team, { subject: 'research', description: 'read only', status: 'pending', requires_code_change: false }, repo);
|
|
6864
|
+
const claim = await claimTask(team, research.id, 'worker-1', null, repo);
|
|
6865
|
+
assert.ok(claim.ok);
|
|
6866
|
+
assert.ok((await transitionTaskStatus(team, research.id, 'in_progress', 'completed', claim.claimToken, repo, { result: 'Research findings delivered.' })).ok);
|
|
6867
|
+
await writeFile(join(workerPath, 'code.txt'), 'separately verified code\n');
|
|
6868
|
+
execFileSync('git', ['add', 'code.txt'], { cwd: workerPath });
|
|
6869
|
+
execFileSync('git', ['commit', '-m', 'verified code after research'], { cwd: workerPath, stdio: 'ignore' });
|
|
6870
|
+
await handOffVerifiedIntegrationTasks(team, repo);
|
|
6871
|
+
await monitorTeam(team, repo);
|
|
6872
|
+
assert.equal(await readFile(join(repo, 'code.txt'), 'utf8'), 'separately verified code\n');
|
|
6873
|
+
assert.ok((await readMonitorSnapshot(team, repo))?.integrationByWorker?.['worker-1']?.last_integrated_head);
|
|
6874
|
+
}
|
|
6875
|
+
finally {
|
|
6876
|
+
if (workerPath)
|
|
6255
6877
|
await rm(workerPath, { recursive: true, force: true });
|
|
6256
|
-
}
|
|
6257
6878
|
await rm(repo, { recursive: true, force: true });
|
|
6258
6879
|
}
|
|
6259
6880
|
});
|
|
6881
|
+
for (const scenario of ['working', 'idle-unfinished', 'idle-unverified', 'idle-missing-task', 'idle-other-owner', 'idle-unfinished-current', 'idle-unfinished-owned', 'idle-conflicting-claim']) {
|
|
6882
|
+
for (const dirty of [false, true]) {
|
|
6883
|
+
it(`monitorTeam leaves unfinished worker output local (${scenario}, ${dirty ? 'dirty' : 'clean'})`, async () => {
|
|
6884
|
+
const repo = await initRepo();
|
|
6885
|
+
let workerPath = '';
|
|
6886
|
+
try {
|
|
6887
|
+
const team = 'team-not-ready';
|
|
6888
|
+
workerPath = await addWorktree(repo, 'not-ready-worker', 'omx-runtime-not-ready-');
|
|
6889
|
+
await writeFile(join(workerPath, 'committed.txt'), 'not yet handed off\n');
|
|
6890
|
+
execFileSync('git', ['add', 'committed.txt'], { cwd: workerPath });
|
|
6891
|
+
execFileSync('git', ['commit', '-m', 'unfinished worker commit'], { cwd: workerPath, stdio: 'ignore' });
|
|
6892
|
+
await initTeamState(team, 'unsafe integration regression', 'executor', 1, repo);
|
|
6893
|
+
const task = await createTask(team, {
|
|
6894
|
+
subject: 'worker output', description: 'not safe until completed and verified',
|
|
6895
|
+
status: scenario === 'idle-unfinished' ? 'in_progress' : 'completed',
|
|
6896
|
+
owner: scenario === 'idle-other-owner' ? 'worker-2' : 'worker-1', requires_code_change: true,
|
|
6897
|
+
...(scenario === 'idle-unverified' ? {} : { result: 'Verification: PASS `npm test`.' }),
|
|
6898
|
+
...(scenario === 'idle-conflicting-claim' ? { claim: { owner: 'worker-2', token: 'other-claim', leased_until: new Date(Date.now() + 60_000).toISOString() } } : {}),
|
|
6899
|
+
}, repo);
|
|
6900
|
+
const extraTask = scenario === 'idle-unfinished-current' || scenario === 'idle-unfinished-owned'
|
|
6901
|
+
? await createTask(team, { subject: 'new ongoing work', description: 'must block integration', status: 'in_progress', ...(scenario === 'idle-unfinished-owned' ? { owner: 'worker-1' } : {}) }, repo)
|
|
6902
|
+
: undefined;
|
|
6903
|
+
const config = await readTeamConfig(team, repo);
|
|
6904
|
+
assert.ok(config);
|
|
6905
|
+
Object.assign(config.workers[0], {
|
|
6906
|
+
assigned_tasks: [scenario === 'idle-missing-task' ? 'missing' : task.id],
|
|
6907
|
+
worktree_repo_root: repo, worktree_path: workerPath, worktree_branch: 'not-ready-worker',
|
|
6908
|
+
});
|
|
6909
|
+
await saveTeamConfig(config, repo);
|
|
6910
|
+
if (scenario !== 'idle-unverified')
|
|
6911
|
+
await handOffVerifiedIntegrationTasks(team, repo);
|
|
6912
|
+
if (dirty)
|
|
6913
|
+
await writeFile(join(workerPath, 'dirty.txt'), 'half-written output\n');
|
|
6914
|
+
await writeWorkerStatus(team, 'worker-1', {
|
|
6915
|
+
state: scenario === 'working' ? 'working' : 'idle',
|
|
6916
|
+
...(scenario === 'idle-unfinished-current' ? { current_task_id: extraTask.id } : {}),
|
|
6917
|
+
updated_at: new Date().toISOString(),
|
|
6918
|
+
}, repo);
|
|
6919
|
+
const workerHead = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: workerPath, encoding: 'utf8' }).trim();
|
|
6920
|
+
const leaderHead = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: repo, encoding: 'utf8' }).trim();
|
|
6921
|
+
await monitorTeam(team, repo);
|
|
6922
|
+
assert.equal(execFileSync('git', ['rev-parse', 'HEAD'], { cwd: repo, encoding: 'utf8' }).trim(), leaderHead);
|
|
6923
|
+
assert.equal(execFileSync('git', ['rev-parse', 'HEAD'], { cwd: workerPath, encoding: 'utf8' }).trim(), workerHead);
|
|
6924
|
+
if (dirty) {
|
|
6925
|
+
assert.equal(await readFile(join(workerPath, 'dirty.txt'), 'utf8'), 'half-written output\n');
|
|
6926
|
+
assert.match(execFileSync('git', ['status', '--porcelain'], { cwd: workerPath, encoding: 'utf8' }), /dirty.txt/);
|
|
6927
|
+
}
|
|
6928
|
+
assert.equal(existsSync(join(repo, 'committed.txt')), false);
|
|
6929
|
+
assert.equal(existsSync(join(repo, 'dirty.txt')), false);
|
|
6930
|
+
const events = await readTeamEvents(team, repo, { wakeableOnly: false });
|
|
6931
|
+
assert.equal(events.some((event) => ['worker_auto_commit', 'worker_merge_applied', 'worker_cherry_pick_applied'].includes(event.type)), false);
|
|
6932
|
+
}
|
|
6933
|
+
finally {
|
|
6934
|
+
if (workerPath)
|
|
6935
|
+
await rm(workerPath, { recursive: true, force: true });
|
|
6936
|
+
await rm(repo, { recursive: true, force: true });
|
|
6937
|
+
}
|
|
6938
|
+
});
|
|
6939
|
+
}
|
|
6940
|
+
}
|
|
6260
6941
|
it('(#3717) monitorTeam does not commit runtime instructions to leader AGENTS.md', async () => {
|
|
6261
6942
|
const repo = await initRepo();
|
|
6262
6943
|
let workerPath = '';
|
|
@@ -6267,8 +6948,9 @@ process.on('SIGTERM', () => process.exit(0));
|
|
|
6267
6948
|
execFileSync('git', ['add', 'AGENTS.md'], { cwd: repo, stdio: 'ignore' });
|
|
6268
6949
|
execFileSync('git', ['commit', '-m', 'initial'], { cwd: repo, stdio: 'ignore' });
|
|
6269
6950
|
workerPath = await addWorktree(repo, 'wk1-agents-branch', 'omx-runtime-wk1-agents-');
|
|
6270
|
-
// Add uncommitted change in worker
|
|
6271
6951
|
await writeFile(join(workerPath, 'work.txt'), 'worker output\n', 'utf-8');
|
|
6952
|
+
execFileSync('git', ['add', 'work.txt'], { cwd: workerPath });
|
|
6953
|
+
execFileSync('git', ['commit', '-m', 'verified worker output'], { cwd: workerPath, stdio: 'ignore' });
|
|
6272
6954
|
await initTeamState('team-agents-check', 'agents regression test', 'executor', 1, repo);
|
|
6273
6955
|
const cfg = await readTeamConfig('team-agents-check', repo);
|
|
6274
6956
|
assert.ok(cfg);
|
|
@@ -6285,23 +6967,15 @@ process.on('SIGTERM', () => process.exit(0));
|
|
|
6285
6967
|
worktree_created: false,
|
|
6286
6968
|
};
|
|
6287
6969
|
await saveTeamConfig(cfg, repo);
|
|
6970
|
+
await handOffVerifiedIntegrationTasks('team-agents-check', repo);
|
|
6288
6971
|
await monitorTeam('team-agents-check', repo);
|
|
6289
6972
|
// Verify leader AGENTS.md is byte-identical to original
|
|
6290
6973
|
const leaderAgentsAfter = await readFile(join(repo, 'AGENTS.md'), 'utf-8');
|
|
6291
6974
|
assert.equal(leaderAgentsAfter, originalAgents, 'leader AGENTS.md should not be modified by team operations');
|
|
6292
|
-
|
|
6293
|
-
const log = execFileSync('git', ['log', '--
|
|
6294
|
-
assert.match(log, /
|
|
6295
|
-
|
|
6296
|
-
const autoCheckpointCommit = execFileSync('git', ['log', '--oneline', '--all'], { cwd: workerPath, encoding: 'utf-8' })
|
|
6297
|
-
.split('\n')
|
|
6298
|
-
.find((line) => line.includes('auto-checkpoint'));
|
|
6299
|
-
assert.ok(autoCheckpointCommit, 'auto-checkpoint commit should exist');
|
|
6300
|
-
if (autoCheckpointCommit) {
|
|
6301
|
-
const commitSha = autoCheckpointCommit.split(' ')[0];
|
|
6302
|
-
const diff = execFileSync('git', ['diff', `${commitSha}^..${commitSha}`, '--name-only'], { cwd: workerPath, encoding: 'utf-8' });
|
|
6303
|
-
assert.doesNotMatch(diff, /AGENTS\.md/, 'auto-checkpoint should not include AGENTS.md');
|
|
6304
|
-
}
|
|
6975
|
+
assert.equal(await readFile(join(repo, 'work.txt'), 'utf8'), 'worker output\n');
|
|
6976
|
+
const log = execFileSync('git', ['log', '--format=%s'], { cwd: repo, encoding: 'utf8' });
|
|
6977
|
+
assert.match(log, /merge/);
|
|
6978
|
+
assert.doesNotMatch(log, /auto-checkpoint/);
|
|
6305
6979
|
}
|
|
6306
6980
|
finally {
|
|
6307
6981
|
if (workerPath) {
|
|
@@ -6336,6 +7010,7 @@ process.on('SIGTERM', () => process.exit(0));
|
|
|
6336
7010
|
worktree_created: false,
|
|
6337
7011
|
};
|
|
6338
7012
|
await saveTeamConfig(cfg, repo);
|
|
7013
|
+
await handOffVerifiedIntegrationTasks('team-merge-clean', repo);
|
|
6339
7014
|
await monitorTeam('team-merge-clean', repo);
|
|
6340
7015
|
// Verify worker content is on leader
|
|
6341
7016
|
const content = await readFile(join(repo, 'feature.txt'), 'utf-8');
|
|
@@ -6383,6 +7058,7 @@ process.on('SIGTERM', () => process.exit(0));
|
|
|
6383
7058
|
worktree_created: false,
|
|
6384
7059
|
};
|
|
6385
7060
|
await saveTeamConfig(cfg, repo);
|
|
7061
|
+
await handOffVerifiedIntegrationTasks('team-merge-detached', repo);
|
|
6386
7062
|
await monitorTeam('team-merge-detached', repo);
|
|
6387
7063
|
const leaderHeadAfter = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: repo, encoding: 'utf-8' }).trim();
|
|
6388
7064
|
assert.notEqual(leaderHeadAfter, leaderHeadBefore, 'leader HEAD should advance for detached worker integration');
|
|
@@ -6436,6 +7112,7 @@ process.on('SIGTERM', () => process.exit(0));
|
|
|
6436
7112
|
worktree_created: false,
|
|
6437
7113
|
};
|
|
6438
7114
|
await saveTeamConfig(cfg, repo);
|
|
7115
|
+
await handOffVerifiedIntegrationTasks('team-merge-noadvance', repo);
|
|
6439
7116
|
const realGit = execFileSync('bash', ['-lc', 'command -v git'], { encoding: 'utf-8' }).trim();
|
|
6440
7117
|
await writeFile(join(fakeBinDir, 'git'), `#!/usr/bin/env bash
|
|
6441
7118
|
set -euo pipefail
|
|
@@ -6504,6 +7181,7 @@ exec "${realGit}" "$@"
|
|
|
6504
7181
|
worktree_created: false,
|
|
6505
7182
|
};
|
|
6506
7183
|
await saveTeamConfig(cfg, repo);
|
|
7184
|
+
await handOffVerifiedIntegrationTasks('team-diverged', repo);
|
|
6507
7185
|
await monitorTeam('team-diverged', repo);
|
|
6508
7186
|
// Verify both contents are on leader
|
|
6509
7187
|
assert.equal(await readFile(join(repo, 'worker-file.txt'), 'utf-8'), 'worker content\n');
|
|
@@ -6563,6 +7241,7 @@ exec "${realGit}" "$@"
|
|
|
6563
7241
|
worktree_created: false,
|
|
6564
7242
|
};
|
|
6565
7243
|
await saveTeamConfig(cfg, repo);
|
|
7244
|
+
await handOffVerifiedIntegrationTasks('team-cross-rebase', repo);
|
|
6566
7245
|
// Set worker-2 status to idle (eligible for rebase)
|
|
6567
7246
|
await writeWorkerStatus('team-cross-rebase', 'worker-2', { state: 'idle', updated_at: new Date().toISOString() }, repo);
|
|
6568
7247
|
await monitorTeam('team-cross-rebase', repo);
|
|
@@ -6590,7 +7269,7 @@ exec "${realGit}" "$@"
|
|
|
6590
7269
|
await rm(repo, { recursive: true, force: true });
|
|
6591
7270
|
}
|
|
6592
7271
|
});
|
|
6593
|
-
it('monitorTeam
|
|
7272
|
+
it('monitorTeam fails closed on same-line leader/worker conflicts', async () => {
|
|
6594
7273
|
const repo = await initRepo();
|
|
6595
7274
|
let workerPath = '';
|
|
6596
7275
|
try {
|
|
@@ -6619,16 +7298,21 @@ exec "${realGit}" "$@"
|
|
|
6619
7298
|
worktree_created: false,
|
|
6620
7299
|
};
|
|
6621
7300
|
await saveTeamConfig(cfg, repo);
|
|
7301
|
+
await handOffVerifiedIntegrationTasks('team-conflict-resolve', repo);
|
|
7302
|
+
await handOffVerifiedIntegrationTasks('team-conflict-resolve', repo);
|
|
6622
7303
|
await monitorTeam('team-conflict-resolve', repo);
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
assert.equal(
|
|
6626
|
-
// Verify integration was not blocked
|
|
7304
|
+
assert.equal(await readFile(join(repo, 'README.md'), 'utf-8'), 'leader version\n');
|
|
7305
|
+
assert.equal(await readFile(join(workerPath, 'README.md'), 'utf-8'), 'worker version\n');
|
|
7306
|
+
assert.equal(execFileSync('git', ['diff', '--name-only', '--diff-filter=U'], { cwd: repo, encoding: 'utf-8' }), '');
|
|
6627
7307
|
const snapshot = await readMonitorSnapshot('team-conflict-resolve', repo);
|
|
6628
|
-
assert.
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
7308
|
+
assert.equal(snapshot?.integrationByWorker?.['worker-1']?.status, 'cherry_pick_conflict');
|
|
7309
|
+
assert.deepEqual(snapshot?.integrationByWorker?.['worker-1']?.conflict_files, ['README.md']);
|
|
7310
|
+
assert.equal(snapshot?.integrationByWorker?.['worker-1']?.last_integrated_head, undefined);
|
|
7311
|
+
const events = await readTeamEvents('team-conflict-resolve', repo, { wakeableOnly: true });
|
|
7312
|
+
assert.equal(events.some((event) => event.type === 'worker_cherry_pick_conflict'), true);
|
|
7313
|
+
const mailbox = await listMailboxMessages('team-conflict-resolve', 'leader-fixed', repo);
|
|
7314
|
+
assert.equal(mailbox.some((message) => /INTEGRATION CONFLICT:.*Resolve the conflict/.test(message.body)), true);
|
|
7315
|
+
assert.equal(mailbox.some((message) => /INTEGRATED:/.test(message.body)), false);
|
|
6632
7316
|
}
|
|
6633
7317
|
finally {
|
|
6634
7318
|
if (workerPath) {
|
|
@@ -6675,6 +7359,7 @@ exec "${realGit}" "$@"
|
|
|
6675
7359
|
worktree_created: false,
|
|
6676
7360
|
};
|
|
6677
7361
|
await saveTeamConfig(cfg, repo);
|
|
7362
|
+
await handOffVerifiedIntegrationTasks('team-rebase-gate', repo);
|
|
6678
7363
|
// Set worker-2 status to "working" (NOT eligible for rebase)
|
|
6679
7364
|
await writeWorkerStatus('team-rebase-gate', 'worker-2', { state: 'working', updated_at: new Date().toISOString() }, repo);
|
|
6680
7365
|
await monitorTeam('team-rebase-gate', repo);
|
|
@@ -6692,7 +7377,7 @@ exec "${realGit}" "$@"
|
|
|
6692
7377
|
await rm(repo, { recursive: true, force: true });
|
|
6693
7378
|
}
|
|
6694
7379
|
});
|
|
6695
|
-
it('monitorTeam
|
|
7380
|
+
it('monitorTeam skips cross-rebase after integration conflict and preserves the worker', async () => {
|
|
6696
7381
|
const repo = await initRepo();
|
|
6697
7382
|
let worker1Path = '';
|
|
6698
7383
|
let worker2Path = '';
|
|
@@ -6706,7 +7391,7 @@ exec "${realGit}" "$@"
|
|
|
6706
7391
|
// Worker-1 renames original.txt → renamed-by-w1.txt (will be integrated to leader)
|
|
6707
7392
|
execFileSync('git', ['mv', 'original.txt', 'renamed-by-w1.txt'], { cwd: worker1Path, stdio: 'ignore' });
|
|
6708
7393
|
execFileSync('git', ['commit', '-m', 'worker-1 renames original'], { cwd: worker1Path, stdio: 'ignore' });
|
|
6709
|
-
// Worker-2 renames original.txt → renamed-by-w2.txt (will conflict
|
|
7394
|
+
// Worker-2 renames original.txt → renamed-by-w2.txt (will conflict during integration)
|
|
6710
7395
|
execFileSync('git', ['mv', 'original.txt', 'renamed-by-w2.txt'], { cwd: worker2Path, stdio: 'ignore' });
|
|
6711
7396
|
execFileSync('git', ['commit', '-m', 'worker-2 renames original'], { cwd: worker2Path, stdio: 'ignore' });
|
|
6712
7397
|
const worker2HeadBefore = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: worker2Path, encoding: 'utf-8' }).trim();
|
|
@@ -6735,22 +7420,29 @@ exec "${realGit}" "$@"
|
|
|
6735
7420
|
worktree_created: false,
|
|
6736
7421
|
};
|
|
6737
7422
|
await saveTeamConfig(cfg, repo);
|
|
7423
|
+
await handOffVerifiedIntegrationTasks('team-rebase-fail', repo);
|
|
6738
7424
|
// Set worker-2 status to idle (eligible for rebase attempt)
|
|
6739
7425
|
await writeWorkerStatus('team-rebase-fail', 'worker-2', { state: 'idle', updated_at: new Date().toISOString() }, repo);
|
|
7426
|
+
await handOffVerifiedIntegrationTasks('team-rebase-fail', repo);
|
|
6740
7427
|
await monitorTeam('team-rebase-fail', repo);
|
|
6741
7428
|
// Verify worker-1's changes landed on leader
|
|
6742
7429
|
assert.equal(existsSync(join(repo, 'renamed-by-w1.txt')), true, 'leader should have worker-1 renamed file');
|
|
6743
|
-
//
|
|
7430
|
+
// Failed source integration must not be followed by a history rewrite.
|
|
6744
7431
|
const worker2HeadAfter = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: worker2Path, encoding: 'utf-8' }).trim();
|
|
6745
|
-
assert.equal(worker2HeadAfter, worker2HeadBefore, 'worker-2 HEAD should
|
|
7432
|
+
assert.equal(worker2HeadAfter, worker2HeadBefore, 'worker-2 HEAD should remain unchanged after failed integration');
|
|
6746
7433
|
// Verify no rebase-in-progress markers
|
|
6747
7434
|
const gitStatusOutput = execFileSync('git', ['status'], { cwd: worker2Path, encoding: 'utf-8' });
|
|
6748
7435
|
assert.doesNotMatch(gitStatusOutput, /rebase in progress/, 'worktree should not have rebase in progress');
|
|
6749
|
-
|
|
7436
|
+
const integration = (await readMonitorSnapshot('team-rebase-fail', repo))?.integrationByWorker?.['worker-2'];
|
|
7437
|
+
assert.equal(integration?.status, 'cherry_pick_conflict');
|
|
7438
|
+
assert.equal(integration?.last_rebased_leader_head, undefined);
|
|
6750
7439
|
const reportPath = join(repo, '.omx', 'state', 'team', 'team-rebase-fail', 'integration-report.md');
|
|
6751
|
-
assert.equal(existsSync(reportPath), true, 'integration report should exist after rebase failure');
|
|
6752
7440
|
const report = await readFile(reportPath, 'utf-8');
|
|
6753
|
-
assert.match(report, /
|
|
7441
|
+
assert.match(report, /cherry-pick.*aborted/, 'report should mention the aborted integration');
|
|
7442
|
+
assert.doesNotMatch(report, /rebase -X/);
|
|
7443
|
+
const events = await readTeamEvents('team-rebase-fail', repo, { wakeableOnly: false });
|
|
7444
|
+
assert.equal(events.some((event) => event.type === 'worker_cross_rebase_skipped' && event.metadata?.reason === 'unintegrated_changes'), true);
|
|
7445
|
+
assert.equal(events.some((event) => event.type === 'worker_cross_rebase_applied' && event.worker === 'worker-2'), false);
|
|
6754
7446
|
}
|
|
6755
7447
|
finally {
|
|
6756
7448
|
if (worker1Path) {
|
|
@@ -11092,6 +11784,126 @@ esac
|
|
|
11092
11784
|
await rm(cwd, { recursive: true, force: true });
|
|
11093
11785
|
}
|
|
11094
11786
|
});
|
|
11787
|
+
it('assignTask rejects a stale rebalance plan without changing the outstanding claim or inbox', async () => {
|
|
11788
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-stale-assignment-'));
|
|
11789
|
+
const teamName = 'team-stale-assignment';
|
|
11790
|
+
try {
|
|
11791
|
+
await withMockTmuxFixture({
|
|
11792
|
+
dirPrefix: 'omx-stale-assignment-tmux-',
|
|
11793
|
+
tmuxScript: () => `#!/bin/sh
|
|
11794
|
+
case "$1" in
|
|
11795
|
+
-V) echo 'tmux 3.4' ;;
|
|
11796
|
+
list-panes) echo '0 ${process.pid}' ;;
|
|
11797
|
+
capture-pane) echo 'working' ;;
|
|
11798
|
+
esac
|
|
11799
|
+
`,
|
|
11800
|
+
}, async () => {
|
|
11801
|
+
await initTeamState(teamName, 'stale assignment', 'executor', 2, cwd);
|
|
11802
|
+
const dependency = await createTask(teamName, { subject: 'dependency', description: 'work', status: 'pending' }, cwd);
|
|
11803
|
+
const first = await createTask(teamName, { subject: 'blocked first', description: 'work', status: 'pending', depends_on: [dependency.id] }, cwd);
|
|
11804
|
+
const second = await createTask(teamName, { subject: 'ready second', description: 'work', status: 'pending' }, cwd);
|
|
11805
|
+
const dependencyClaim = await claimTask(teamName, dependency.id, 'worker-2', dependency.version, cwd);
|
|
11806
|
+
assert.ok(dependencyClaim.ok);
|
|
11807
|
+
const manifestPath = join(cwd, '.omx/state/team', teamName, 'manifest.v2.json');
|
|
11808
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
11809
|
+
manifest.policy.dispatch_mode = 'transport_direct';
|
|
11810
|
+
await writeAtomic(manifestPath, JSON.stringify(manifest));
|
|
11811
|
+
const workers = [{ name: 'worker-1', role: 'executor', alive: true, status: { state: 'idle', updated_at: new Date().toISOString() } }];
|
|
11812
|
+
const stalePlan = buildRebalanceDecisions({ tasks: await listTasks(teamName, cwd), workers, reclaimedTaskIds: [] });
|
|
11813
|
+
assert.equal(stalePlan[0]?.taskId, second.id);
|
|
11814
|
+
assert.equal((await transitionTaskStatus(teamName, dependency.id, 'in_progress', 'completed', dependencyClaim.claimToken, cwd)).ok, true);
|
|
11815
|
+
const freshPlan = buildRebalanceDecisions({ tasks: await listTasks(teamName, cwd), workers, reclaimedTaskIds: [] });
|
|
11816
|
+
assert.equal(freshPlan[0]?.taskId, first.id);
|
|
11817
|
+
await assignTask(teamName, freshPlan[0].workerName, first.id, cwd);
|
|
11818
|
+
const claimed = await readTask(teamName, first.id, cwd);
|
|
11819
|
+
assert.equal(claimed?.status, 'in_progress');
|
|
11820
|
+
assert.equal(claimed?.owner, 'worker-1');
|
|
11821
|
+
assert.ok(claimed?.claim);
|
|
11822
|
+
const pending = await readTask(teamName, second.id, cwd);
|
|
11823
|
+
assert.equal(pending?.status, 'pending');
|
|
11824
|
+
assert.equal(pending?.version, second.version);
|
|
11825
|
+
assert.equal(pending?.owner, undefined);
|
|
11826
|
+
assert.equal(pending?.claim, undefined);
|
|
11827
|
+
const inboxPath = join(cwd, '.omx/state/team', teamName, 'workers/worker-1/inbox.md');
|
|
11828
|
+
const inbox = await readFile(inboxPath);
|
|
11829
|
+
assert.match(inbox.toString(), new RegExp(`Task ${first.id}`));
|
|
11830
|
+
const dispatches = await listDispatchRequests(teamName, cwd);
|
|
11831
|
+
assert.equal(dispatches.length, 1);
|
|
11832
|
+
await assert.rejects(() => assignTask(teamName, stalePlan[0].workerName, second.id, cwd), /already owns outstanding task/);
|
|
11833
|
+
assert.deepEqual(await readTask(teamName, first.id, cwd), claimed, 'first version, owner, token and lease stay unchanged');
|
|
11834
|
+
assert.deepEqual(await readTask(teamName, second.id, cwd), pending, 'second stays unclaimed at its original version');
|
|
11835
|
+
assert.deepEqual(await readFile(inboxPath), inbox, 'rejection must not write an assignment or cancellation');
|
|
11836
|
+
assert.deepEqual(await listDispatchRequests(teamName, cwd), dispatches, 'no second dispatch');
|
|
11837
|
+
});
|
|
11838
|
+
}
|
|
11839
|
+
finally {
|
|
11840
|
+
await rm(cwd, { recursive: true, force: true });
|
|
11841
|
+
}
|
|
11842
|
+
});
|
|
11843
|
+
it('assignTask and reassignTask preserve another owned pending startup reservation', async () => {
|
|
11844
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-assignment-reservation-'));
|
|
11845
|
+
const teamName = 'team-assignment-reservation';
|
|
11846
|
+
try {
|
|
11847
|
+
await initTeamState(teamName, 'pending reservation', 'executor', 1, cwd);
|
|
11848
|
+
const reserved = await createTask(teamName, { subject: 'startup', description: 'work', status: 'pending', owner: 'worker-1' }, cwd);
|
|
11849
|
+
const selected = await createTask(teamName, { subject: 'queued', description: 'work', status: 'pending', owner: 'worker-1' }, cwd);
|
|
11850
|
+
const reservedBefore = await readTask(teamName, reserved.id, cwd);
|
|
11851
|
+
const selectedBefore = await readTask(teamName, selected.id, cwd);
|
|
11852
|
+
assert.ok(reservedBefore);
|
|
11853
|
+
assert.ok(selectedBefore);
|
|
11854
|
+
await writeWorkerInbox(teamName, 'worker-1', 'Original startup handoff', cwd);
|
|
11855
|
+
const inboxPath = join(cwd, '.omx/state/team', teamName, 'workers/worker-1/inbox.md');
|
|
11856
|
+
const inbox = await readFile(inboxPath);
|
|
11857
|
+
await assert.rejects(() => assignTask(teamName, 'worker-1', selected.id, cwd), /already owns outstanding task/);
|
|
11858
|
+
await assert.rejects(() => reassignTask(teamName, selected.id, 'worker-2', 'worker-1', cwd), /already owns outstanding task/);
|
|
11859
|
+
assert.deepEqual(await readTask(teamName, reserved.id, cwd), reservedBefore);
|
|
11860
|
+
assert.deepEqual(await readTask(teamName, selected.id, cwd), selectedBefore);
|
|
11861
|
+
assert.deepEqual(await readFile(inboxPath), inbox);
|
|
11862
|
+
assert.equal((await listDispatchRequests(teamName, cwd)).length, 0);
|
|
11863
|
+
// Bootstrap may claim an owned queue directly; only assignment owns the fixed-inbox capacity rule.
|
|
11864
|
+
assert.equal((await claimTask(teamName, selected.id, 'worker-1', selected.version, cwd)).ok, true);
|
|
11865
|
+
assert.deepEqual(await readTask(teamName, reserved.id, cwd), reservedBefore);
|
|
11866
|
+
}
|
|
11867
|
+
finally {
|
|
11868
|
+
await rm(cwd, { recursive: true, force: true });
|
|
11869
|
+
}
|
|
11870
|
+
});
|
|
11871
|
+
it('assignTask permits the selected owned pending reservation when no other work is outstanding', async () => {
|
|
11872
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-assign-own-pending-'));
|
|
11873
|
+
const teamName = 'team-assign-own-pending';
|
|
11874
|
+
try {
|
|
11875
|
+
await withMockTmuxFixture({
|
|
11876
|
+
dirPrefix: 'omx-own-pending-tmux-',
|
|
11877
|
+
tmuxScript: () => `#!/bin/sh
|
|
11878
|
+
case "$1" in
|
|
11879
|
+
-V) echo 'tmux 3.4' ;;
|
|
11880
|
+
list-panes) echo '0 ${process.pid}' ;;
|
|
11881
|
+
capture-pane) echo 'working' ;;
|
|
11882
|
+
esac
|
|
11883
|
+
`,
|
|
11884
|
+
}, async () => {
|
|
11885
|
+
await initTeamState(teamName, 'own pending assignment', 'executor', 1, cwd);
|
|
11886
|
+
const task = await createTask(teamName, { subject: 'startup', description: 'work', status: 'pending', owner: 'worker-1' }, cwd);
|
|
11887
|
+
const finished = await createTask(teamName, { subject: 'finished', description: 'work', status: 'pending' }, cwd);
|
|
11888
|
+
const claim = await claimTask(teamName, finished.id, 'worker-1', finished.version, cwd);
|
|
11889
|
+
assert.ok(claim.ok);
|
|
11890
|
+
assert.equal((await transitionTaskStatus(teamName, finished.id, 'in_progress', 'completed', claim.claimToken, cwd)).ok, true);
|
|
11891
|
+
const manifestPath = join(cwd, '.omx/state/team', teamName, 'manifest.v2.json');
|
|
11892
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
11893
|
+
manifest.policy.dispatch_mode = 'transport_direct';
|
|
11894
|
+
await writeAtomic(manifestPath, JSON.stringify(manifest));
|
|
11895
|
+
await assignTask(teamName, 'worker-1', task.id, cwd);
|
|
11896
|
+
const assigned = await readTask(teamName, task.id, cwd);
|
|
11897
|
+
assert.equal(assigned?.status, 'in_progress');
|
|
11898
|
+
assert.equal(assigned?.owner, 'worker-1');
|
|
11899
|
+
assert.ok(assigned?.claim);
|
|
11900
|
+
assert.equal((await listDispatchRequests(teamName, cwd)).length, 1);
|
|
11901
|
+
});
|
|
11902
|
+
}
|
|
11903
|
+
finally {
|
|
11904
|
+
await rm(cwd, { recursive: true, force: true });
|
|
11905
|
+
}
|
|
11906
|
+
});
|
|
11095
11907
|
it('assignTask enforces delegation_only policy for leader-fixed worker', async () => {
|
|
11096
11908
|
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-'));
|
|
11097
11909
|
try {
|
|
@@ -11627,6 +12439,62 @@ esac
|
|
|
11627
12439
|
await rm(cwd, { recursive: true, force: true });
|
|
11628
12440
|
}
|
|
11629
12441
|
});
|
|
12442
|
+
for (const existingPlans of [false, true]) {
|
|
12443
|
+
it(`assignTask hands off the current claim for lifecycle completion (existing plans: ${existingPlans})`, async () => {
|
|
12444
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-claim-handoff-'));
|
|
12445
|
+
const team = 'team-claim-handoff';
|
|
12446
|
+
try {
|
|
12447
|
+
await initTeamState(team, 'claim handoff', 'executor', 1, cwd);
|
|
12448
|
+
const manifestPath = teamStateTestPath(cwd, 'team', team, 'manifest.v2.json');
|
|
12449
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf-8'));
|
|
12450
|
+
manifest.policy = { ...(manifest.policy || {}), dispatch_ack_timeout_ms: 250 };
|
|
12451
|
+
await writeFile(manifestPath, JSON.stringify(manifest));
|
|
12452
|
+
const task = await createTask(team, {
|
|
12453
|
+
subject: 'Fix typo', description: 'Fix one typo', status: 'pending',
|
|
12454
|
+
...(existingPlans ? {
|
|
12455
|
+
delegation: { mode: 'none' },
|
|
12456
|
+
coordination: { mode: 'lightweight', source: 'explicit', activation_reasons: [] },
|
|
12457
|
+
} : {}),
|
|
12458
|
+
}, cwd);
|
|
12459
|
+
const assignment = assignTask(team, 'worker-1', task.id, cwd);
|
|
12460
|
+
const deadline = Date.now() + 2_000;
|
|
12461
|
+
let delivered = false;
|
|
12462
|
+
while (Date.now() < deadline && !delivered) {
|
|
12463
|
+
const requests = await listDispatchRequests(team, cwd, { kind: 'inbox', to_worker: 'worker-1' });
|
|
12464
|
+
if (requests.some((request) => request.status === 'pending')) {
|
|
12465
|
+
await markPendingInboxDispatchesDelivered(team, cwd, { toWorker: 'worker-1', lastReason: 'test_delivered_receipt' });
|
|
12466
|
+
delivered = true;
|
|
12467
|
+
}
|
|
12468
|
+
else {
|
|
12469
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
12470
|
+
}
|
|
12471
|
+
}
|
|
12472
|
+
await assignment;
|
|
12473
|
+
assert.ok(delivered);
|
|
12474
|
+
const current = await readTask(team, task.id, cwd);
|
|
12475
|
+
assert.ok(current?.claim);
|
|
12476
|
+
assert.equal(current.status, 'in_progress');
|
|
12477
|
+
const inbox = await readFile(join(cwd, '.omx', 'state', 'team', team, 'workers', 'worker-1', 'inbox.md'), 'utf-8');
|
|
12478
|
+
assert.match(inbox, /Do NOT re-claim/);
|
|
12479
|
+
assert.doesNotMatch(inbox, /Request a claim/);
|
|
12480
|
+
assert.match(inbox, /with_task_lease/);
|
|
12481
|
+
assert.match(inbox, /current_claim_token/);
|
|
12482
|
+
assert.ok(inbox.includes(`claim_token: "${current.claim.token}"`));
|
|
12483
|
+
assert.ok(inbox.includes(`version: ${current.version}`));
|
|
12484
|
+
assert.ok(inbox.includes(`leased_until: "${current.claim.leased_until}"`));
|
|
12485
|
+
const duplicate = await claimTask(team, task.id, 'worker-1', current.version ?? null, cwd);
|
|
12486
|
+
assert.deepEqual(duplicate, { ok: false, error: 'claim_conflict' });
|
|
12487
|
+
const handedOffToken = inbox.match(/claim_token: "([^"]+)"/)?.[1];
|
|
12488
|
+
assert.ok(handedOffToken);
|
|
12489
|
+
const completed = await transitionTaskStatus(team, task.id, 'in_progress', 'completed', handedOffToken, cwd, { result: 'PASS: findings reported' });
|
|
12490
|
+
assert.equal(completed.ok, true, JSON.stringify(completed));
|
|
12491
|
+
assert.equal((await readTask(team, task.id, cwd))?.status, 'completed');
|
|
12492
|
+
}
|
|
12493
|
+
finally {
|
|
12494
|
+
await rm(cwd, { recursive: true, force: true });
|
|
12495
|
+
}
|
|
12496
|
+
});
|
|
12497
|
+
}
|
|
11630
12498
|
it('assignTask injects approved handoff context when the persisted approved binding remains ready', async () => {
|
|
11631
12499
|
const cwd = await mkdtemp(join(tmpdir(), 'omx-runtime-approved-followup-'));
|
|
11632
12500
|
const approvedTask = 'Execute approved issue 1320 plan';
|