oh-my-codex 0.20.2 → 0.20.3
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 +7 -6
- package/Cargo.toml +1 -1
- package/README.md +26 -0
- package/crates/omx-runtime/Cargo.toml +1 -0
- package/crates/omx-runtime/src/main.rs +25 -2
- package/crates/omx-runtime/tests/execution.rs +219 -0
- package/crates/omx-runtime-core/src/dispatch.rs +96 -10
- package/crates/omx-runtime-core/src/engine.rs +839 -29
- package/crates/omx-runtime-core/src/lib.rs +8 -0
- package/dist/agents/__tests__/definitions.test.js +81 -0
- package/dist/agents/__tests__/definitions.test.js.map +1 -1
- package/dist/agents/__tests__/native-config.test.js +25 -0
- package/dist/agents/__tests__/native-config.test.js.map +1 -1
- package/dist/agents/native-config.d.ts +2 -1
- package/dist/agents/native-config.d.ts.map +1 -1
- package/dist/agents/native-config.js.map +1 -1
- package/dist/auth/hotswap.d.ts +6 -0
- package/dist/auth/hotswap.d.ts.map +1 -1
- package/dist/auth/hotswap.js +85 -15
- package/dist/auth/hotswap.js.map +1 -1
- package/dist/autopilot/__tests__/ralplan-gate.test.js +1 -1
- package/dist/autopilot/__tests__/ralplan-gate.test.js.map +1 -1
- package/dist/cli/__tests__/auth.test.js +60 -6
- package/dist/cli/__tests__/auth.test.js.map +1 -1
- package/dist/cli/__tests__/codex-plugin-layout.test.js +80 -0
- package/dist/cli/__tests__/codex-plugin-layout.test.js.map +1 -1
- package/dist/cli/__tests__/doctor-warning-copy.test.js +103 -1
- package/dist/cli/__tests__/doctor-warning-copy.test.js.map +1 -1
- package/dist/cli/__tests__/exec.test.js +136 -0
- package/dist/cli/__tests__/exec.test.js.map +1 -1
- package/dist/cli/__tests__/index.test.js +258 -4
- package/dist/cli/__tests__/index.test.js.map +1 -1
- package/dist/cli/__tests__/launch-fallback.test.js +287 -1
- package/dist/cli/__tests__/launch-fallback.test.js.map +1 -1
- package/dist/cli/__tests__/mcp-parity.test.js +4 -1
- package/dist/cli/__tests__/mcp-parity.test.js.map +1 -1
- package/dist/cli/__tests__/native-hook-claim-journal.test.js +84 -6
- package/dist/cli/__tests__/native-hook-claim-journal.test.js.map +1 -1
- package/dist/cli/__tests__/ralph-goal-mode-contract.test.js +3 -3
- package/dist/cli/__tests__/ralph-goal-mode-contract.test.js.map +1 -1
- package/dist/cli/__tests__/ralph.test.js +3 -3
- package/dist/cli/__tests__/ralph.test.js.map +1 -1
- package/dist/cli/__tests__/ralplan-bootstrap-3181.test.js +56 -171
- package/dist/cli/__tests__/ralplan-bootstrap-3181.test.js.map +1 -1
- package/dist/cli/__tests__/ralplan.test.js +37 -111
- package/dist/cli/__tests__/ralplan.test.js.map +1 -1
- package/dist/cli/__tests__/resume.test.js +11 -10
- package/dist/cli/__tests__/resume.test.js.map +1 -1
- package/dist/cli/__tests__/session-search-help.test.js +25 -1
- package/dist/cli/__tests__/session-search-help.test.js.map +1 -1
- package/dist/cli/__tests__/setup-install-mode.test.js +42 -4
- package/dist/cli/__tests__/setup-install-mode.test.js.map +1 -1
- package/dist/cli/__tests__/team.test.js +105 -7
- package/dist/cli/__tests__/team.test.js.map +1 -1
- package/dist/cli/__tests__/uninstall.test.js +46 -0
- package/dist/cli/__tests__/uninstall.test.js.map +1 -1
- package/dist/cli/__tests__/windows-popup-loop-contract.test.js +2 -1
- package/dist/cli/__tests__/windows-popup-loop-contract.test.js.map +1 -1
- package/dist/cli/doctor.d.ts +3 -0
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +15 -2
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/index.d.ts +4 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +138 -38
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/mcp-parity.js +2 -2
- package/dist/cli/mcp-parity.js.map +1 -1
- package/dist/cli/native-hook-claim-journal.d.ts +16 -5
- package/dist/cli/native-hook-claim-journal.d.ts.map +1 -1
- package/dist/cli/native-hook-claim-journal.js +42 -29
- package/dist/cli/native-hook-claim-journal.js.map +1 -1
- package/dist/cli/ralph.js +2 -2
- package/dist/cli/ralph.js.map +1 -1
- package/dist/cli/ralplan.d.ts +4 -8
- package/dist/cli/ralplan.d.ts.map +1 -1
- package/dist/cli/ralplan.js +19 -112
- package/dist/cli/ralplan.js.map +1 -1
- package/dist/cli/session-search.d.ts +5 -0
- package/dist/cli/session-search.d.ts.map +1 -1
- package/dist/cli/session-search.js +87 -0
- package/dist/cli/session-search.js.map +1 -1
- package/dist/cli/setup.d.ts +5 -0
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +80 -31
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/uninstall.d.ts +9 -0
- package/dist/cli/uninstall.d.ts.map +1 -1
- package/dist/cli/uninstall.js +61 -19
- package/dist/cli/uninstall.js.map +1 -1
- package/dist/compat/__tests__/rust-runtime-compat.test.js +1 -1
- package/dist/config/__tests__/generator-idempotent.test.js +330 -1
- package/dist/config/__tests__/generator-idempotent.test.js.map +1 -1
- package/dist/config/__tests__/generator-notify.test.js +2 -2
- package/dist/config/__tests__/generator-notify.test.js.map +1 -1
- package/dist/config/__tests__/models.test.js +67 -3
- package/dist/config/__tests__/models.test.js.map +1 -1
- package/dist/config/generator.d.ts +4 -20
- package/dist/config/generator.d.ts.map +1 -1
- package/dist/config/generator.js +499 -119
- package/dist/config/generator.js.map +1 -1
- package/dist/config/models.d.ts +12 -2
- package/dist/config/models.d.ts.map +1 -1
- package/dist/config/models.js +15 -1
- package/dist/config/models.js.map +1 -1
- package/dist/hooks/__tests__/agents-overlay.test.js +2 -2
- package/dist/hooks/__tests__/agents-overlay.test.js.map +1 -1
- package/dist/hooks/__tests__/keyword-detector.test.js +4 -4
- package/dist/hooks/__tests__/keyword-detector.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-fallback-watcher.test.js +238 -543
- package/dist/hooks/__tests__/notify-fallback-watcher.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-all-workers-idle.test.js +38 -4
- package/dist/hooks/__tests__/notify-hook-all-workers-idle.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-auto-nudge.test.js +96 -9
- package/dist/hooks/__tests__/notify-hook-auto-nudge.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-team-dispatch.test.js +531 -12
- package/dist/hooks/__tests__/notify-hook-team-dispatch.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-team-leader-nudge.test.js +155 -23
- package/dist/hooks/__tests__/notify-hook-team-leader-nudge.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-team-tmux-guard.test.js +482 -32
- package/dist/hooks/__tests__/notify-hook-team-tmux-guard.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-tmux-heal.test.js +68 -1
- package/dist/hooks/__tests__/notify-hook-tmux-heal.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-tmux-scrollback.test.js +7 -1
- package/dist/hooks/__tests__/notify-hook-tmux-scrollback.test.js.map +1 -1
- package/dist/hooks/__tests__/notify-hook-worker-idle.test.js +43 -4
- package/dist/hooks/__tests__/notify-hook-worker-idle.test.js.map +1 -1
- package/dist/hooks/__tests__/session.test.js +348 -2
- package/dist/hooks/__tests__/session.test.js.map +1 -1
- package/dist/hooks/agents-overlay.js +1 -1
- package/dist/hooks/session.d.ts +26 -2
- package/dist/hooks/session.d.ts.map +1 -1
- package/dist/hooks/session.js +169 -13
- package/dist/hooks/session.js.map +1 -1
- package/dist/leader/__tests__/contract.test.js +57 -7
- package/dist/leader/__tests__/contract.test.js.map +1 -1
- package/dist/leader/contract.d.ts +16 -0
- package/dist/leader/contract.d.ts.map +1 -1
- package/dist/leader/contract.js +79 -4
- package/dist/leader/contract.js.map +1 -1
- package/dist/mcp/__tests__/code-intel-server.test.js +31 -3
- package/dist/mcp/__tests__/code-intel-server.test.js.map +1 -1
- package/dist/mcp/__tests__/wiki-server.test.js +18 -0
- package/dist/mcp/__tests__/wiki-server.test.js.map +1 -1
- package/dist/mcp/code-intel-server.d.ts.map +1 -1
- package/dist/mcp/code-intel-server.js +13 -3
- package/dist/mcp/code-intel-server.js.map +1 -1
- package/dist/mcp/wiki-server.d.ts +11 -0
- package/dist/mcp/wiki-server.d.ts.map +1 -1
- package/dist/mcp/wiki-server.js +9 -2
- package/dist/mcp/wiki-server.js.map +1 -1
- package/dist/modes/__tests__/base-tmux-pane.test.js +4 -4
- package/dist/modes/__tests__/base-tmux-pane.test.js.map +1 -1
- package/dist/notifications/temp-contract.d.ts.map +1 -1
- package/dist/notifications/temp-contract.js +4 -0
- package/dist/notifications/temp-contract.js.map +1 -1
- package/dist/pipeline/__tests__/orchestrator.test.js +4 -4
- package/dist/pipeline/__tests__/orchestrator.test.js.map +1 -1
- package/dist/pipeline/__tests__/stages.test.js +8 -8
- package/dist/pipeline/__tests__/stages.test.js.map +1 -1
- package/dist/ralplan/__tests__/consensus-gate.test.js +134 -10
- package/dist/ralplan/__tests__/consensus-gate.test.js.map +1 -1
- package/dist/ralplan/__tests__/documented-leader-preflight.test.d.ts +2 -0
- package/dist/ralplan/__tests__/documented-leader-preflight.test.d.ts.map +1 -0
- package/dist/ralplan/__tests__/documented-leader-preflight.test.js +46 -0
- package/dist/ralplan/__tests__/documented-leader-preflight.test.js.map +1 -0
- package/dist/ralplan/__tests__/runtime.test.js +8 -4
- package/dist/ralplan/__tests__/runtime.test.js.map +1 -1
- package/dist/ralplan/consensus-gate.d.ts.map +1 -1
- package/dist/ralplan/consensus-gate.js +58 -50
- package/dist/ralplan/consensus-gate.js.map +1 -1
- package/dist/ralplan/documented-leader-preflight.d.ts +34 -0
- package/dist/ralplan/documented-leader-preflight.d.ts.map +1 -0
- package/dist/ralplan/documented-leader-preflight.js +58 -0
- package/dist/ralplan/documented-leader-preflight.js.map +1 -0
- package/dist/ralplan/runtime.d.ts +1 -0
- package/dist/ralplan/runtime.d.ts.map +1 -1
- package/dist/ralplan/runtime.js +11 -7
- package/dist/ralplan/runtime.js.map +1 -1
- package/dist/runtime/__tests__/bridge.test.js +42 -1
- package/dist/runtime/__tests__/bridge.test.js.map +1 -1
- package/dist/runtime/bridge.d.ts +12 -0
- package/dist/runtime/bridge.d.ts.map +1 -1
- package/dist/runtime/bridge.js +52 -1
- package/dist/runtime/bridge.js.map +1 -1
- package/dist/scripts/__tests__/codex-native-hook.test.js +2620 -487
- package/dist/scripts/__tests__/codex-native-hook.test.js.map +1 -1
- package/dist/scripts/__tests__/reasoning-artifact-contract.test.d.ts +2 -0
- package/dist/scripts/__tests__/reasoning-artifact-contract.test.d.ts.map +1 -0
- package/dist/scripts/__tests__/reasoning-artifact-contract.test.js +108 -0
- package/dist/scripts/__tests__/reasoning-artifact-contract.test.js.map +1 -0
- package/dist/scripts/__tests__/role-intent-bootstrap-e2e-3181.test.js +46 -173
- package/dist/scripts/__tests__/role-intent-bootstrap-e2e-3181.test.js.map +1 -1
- package/dist/scripts/__tests__/role-intent-durable-recovery-3181.test.js +39 -159
- package/dist/scripts/__tests__/role-intent-durable-recovery-3181.test.js.map +1 -1
- package/dist/scripts/__tests__/smoke-packed-install.test.js +254 -2
- package/dist/scripts/__tests__/smoke-packed-install.test.js.map +1 -1
- package/dist/scripts/codex-native-hook.d.ts +4 -1
- package/dist/scripts/codex-native-hook.d.ts.map +1 -1
- package/dist/scripts/codex-native-hook.js +11013 -1153
- package/dist/scripts/codex-native-hook.js.map +1 -1
- package/dist/scripts/notify-fallback-watcher.js +82 -108
- package/dist/scripts/notify-fallback-watcher.js.map +1 -1
- package/dist/scripts/notify-hook/auto-nudge.d.ts.map +1 -1
- package/dist/scripts/notify-hook/auto-nudge.js +74 -3
- package/dist/scripts/notify-hook/auto-nudge.js.map +1 -1
- package/dist/scripts/notify-hook/team-dispatch.d.ts +9 -0
- package/dist/scripts/notify-hook/team-dispatch.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-dispatch.js +234 -79
- package/dist/scripts/notify-hook/team-dispatch.js.map +1 -1
- package/dist/scripts/notify-hook/team-leader-nudge.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-leader-nudge.js +39 -13
- package/dist/scripts/notify-hook/team-leader-nudge.js.map +1 -1
- package/dist/scripts/notify-hook/team-tmux-guard.d.ts +12 -4
- package/dist/scripts/notify-hook/team-tmux-guard.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-tmux-guard.js +365 -44
- package/dist/scripts/notify-hook/team-tmux-guard.js.map +1 -1
- package/dist/scripts/notify-hook/team-worker-stop.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-worker-stop.js +19 -18
- package/dist/scripts/notify-hook/team-worker-stop.js.map +1 -1
- package/dist/scripts/notify-hook/team-worker.d.ts +3 -0
- package/dist/scripts/notify-hook/team-worker.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-worker.js +37 -28
- package/dist/scripts/notify-hook/team-worker.js.map +1 -1
- package/dist/scripts/notify-hook/tmux-injection.d.ts.map +1 -1
- package/dist/scripts/notify-hook/tmux-injection.js +28 -2
- package/dist/scripts/notify-hook/tmux-injection.js.map +1 -1
- package/dist/scripts/notify-hook.js +1 -0
- package/dist/scripts/notify-hook.js.map +1 -1
- package/dist/scripts/smoke-packed-install.d.ts +48 -3
- package/dist/scripts/smoke-packed-install.d.ts.map +1 -1
- package/dist/scripts/smoke-packed-install.js +2796 -13
- package/dist/scripts/smoke-packed-install.js.map +1 -1
- package/dist/state/__tests__/mode-state-context.test.js +54 -0
- package/dist/state/__tests__/mode-state-context.test.js.map +1 -1
- package/dist/state/__tests__/operations.test.js +2 -0
- package/dist/state/__tests__/operations.test.js.map +1 -1
- package/dist/state/mode-state-context.d.ts +5 -0
- package/dist/state/mode-state-context.d.ts.map +1 -1
- package/dist/state/mode-state-context.js +59 -0
- package/dist/state/mode-state-context.js.map +1 -1
- package/dist/subagents/__tests__/leader-bootstrap-3181.test.js +24 -245
- package/dist/subagents/__tests__/leader-bootstrap-3181.test.js.map +1 -1
- package/dist/subagents/tracker.d.ts +1 -82
- package/dist/subagents/tracker.d.ts.map +1 -1
- package/dist/subagents/tracker.js +3 -275
- package/dist/subagents/tracker.js.map +1 -1
- package/dist/team/__tests__/api-interop.test.js +91 -1
- package/dist/team/__tests__/api-interop.test.js.map +1 -1
- package/dist/team/__tests__/delivery-e2e-smoke.test.js +52 -10
- package/dist/team/__tests__/delivery-e2e-smoke.test.js.map +1 -1
- package/dist/team/__tests__/idle-nudge.test.js +45 -15
- package/dist/team/__tests__/idle-nudge.test.js.map +1 -1
- package/dist/team/__tests__/mcp-comm.test.js +93 -27
- package/dist/team/__tests__/mcp-comm.test.js.map +1 -1
- package/dist/team/__tests__/model-contract.test.js +110 -3
- package/dist/team/__tests__/model-contract.test.js.map +1 -1
- package/dist/team/__tests__/runtime-cli.test.js +9 -0
- package/dist/team/__tests__/runtime-cli.test.js.map +1 -1
- package/dist/team/__tests__/runtime.test.js +3204 -335
- package/dist/team/__tests__/runtime.test.js.map +1 -1
- package/dist/team/__tests__/scaling.test.js +2359 -142
- package/dist/team/__tests__/scaling.test.js.map +1 -1
- package/dist/team/__tests__/state.test.js +804 -36
- package/dist/team/__tests__/state.test.js.map +1 -1
- package/dist/team/__tests__/team-ops-contract.test.js +6 -0
- package/dist/team/__tests__/team-ops-contract.test.js.map +1 -1
- package/dist/team/__tests__/tmux-session.test.js +3049 -784
- package/dist/team/__tests__/tmux-session.test.js.map +1 -1
- package/dist/team/__tests__/worker-runtime-identity.test.js +38 -2
- package/dist/team/__tests__/worker-runtime-identity.test.js.map +1 -1
- package/dist/team/__tests__/worktree.test.js +6 -0
- package/dist/team/__tests__/worktree.test.js.map +1 -1
- package/dist/team/api-interop.d.ts.map +1 -1
- package/dist/team/api-interop.js +15 -9
- package/dist/team/api-interop.js.map +1 -1
- package/dist/team/exact-pane.d.ts +23 -0
- package/dist/team/exact-pane.d.ts.map +1 -0
- package/dist/team/exact-pane.js +133 -0
- package/dist/team/exact-pane.js.map +1 -0
- package/dist/team/idle-nudge.d.ts +12 -1
- package/dist/team/idle-nudge.d.ts.map +1 -1
- package/dist/team/idle-nudge.js +41 -14
- package/dist/team/idle-nudge.js.map +1 -1
- package/dist/team/model-contract.d.ts +2 -5
- package/dist/team/model-contract.d.ts.map +1 -1
- package/dist/team/model-contract.js +59 -17
- package/dist/team/model-contract.js.map +1 -1
- package/dist/team/runtime.d.ts +1 -0
- package/dist/team/runtime.d.ts.map +1 -1
- package/dist/team/runtime.js +1244 -180
- package/dist/team/runtime.js.map +1 -1
- package/dist/team/scaling.d.ts +13 -1
- package/dist/team/scaling.d.ts.map +1 -1
- package/dist/team/scaling.js +1430 -384
- package/dist/team/scaling.js.map +1 -1
- package/dist/team/state/dispatch.d.ts.map +1 -1
- package/dist/team/state/dispatch.js +26 -8
- package/dist/team/state/dispatch.js.map +1 -1
- package/dist/team/state/locks.d.ts.map +1 -1
- package/dist/team/state/locks.js +61 -13
- package/dist/team/state/locks.js.map +1 -1
- package/dist/team/state/tasks.d.ts.map +1 -1
- package/dist/team/state/tasks.js +4 -3
- package/dist/team/state/tasks.js.map +1 -1
- package/dist/team/state.d.ts +67 -1
- package/dist/team/state.d.ts.map +1 -1
- package/dist/team/state.js +636 -129
- package/dist/team/state.js.map +1 -1
- package/dist/team/team-ops.d.ts +5 -0
- package/dist/team/team-ops.d.ts.map +1 -1
- package/dist/team/team-ops.js +4 -0
- package/dist/team/team-ops.js.map +1 -1
- package/dist/team/tmux-session.d.ts +123 -23
- package/dist/team/tmux-session.d.ts.map +1 -1
- package/dist/team/tmux-session.js +1250 -291
- package/dist/team/tmux-session.js.map +1 -1
- package/dist/team/worktree.d.ts.map +1 -1
- package/dist/team/worktree.js +4 -0
- package/dist/team/worktree.js.map +1 -1
- package/dist/utils/__tests__/file-durability.test.d.ts +2 -0
- package/dist/utils/__tests__/file-durability.test.d.ts.map +1 -0
- package/dist/utils/__tests__/file-durability.test.js +57 -0
- package/dist/utils/__tests__/file-durability.test.js.map +1 -0
- package/dist/utils/file-durability.d.ts +15 -0
- package/dist/utils/file-durability.d.ts.map +1 -0
- package/dist/utils/file-durability.js +37 -0
- package/dist/utils/file-durability.js.map +1 -0
- package/dist/verification/__tests__/dev-merge-issue-close-workflow.test.js +3 -0
- package/dist/verification/__tests__/dev-merge-issue-close-workflow.test.js.map +1 -1
- package/dist/wiki/lint.d.ts +4 -1
- package/dist/wiki/lint.d.ts.map +1 -1
- package/dist/wiki/lint.js +3 -2
- package/dist/wiki/lint.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 +24 -0
- package/plugins/oh-my-codex/skills/ralph/SKILL.md +6 -4
- package/plugins/oh-my-codex/skills/ralplan/SKILL.md +3 -2
- package/plugins/oh-my-codex/skills/team/SKILL.md +13 -9
- package/skills/ralph/SKILL.md +6 -4
- package/skills/ralplan/SKILL.md +3 -2
- package/skills/team/SKILL.md +13 -9
- package/src/scripts/__tests__/codex-native-hook.test.ts +2826 -497
- package/src/scripts/__tests__/reasoning-artifact-contract.test.ts +129 -0
- package/src/scripts/__tests__/role-intent-bootstrap-e2e-3181.test.ts +48 -185
- package/src/scripts/__tests__/role-intent-durable-recovery-3181.test.ts +44 -177
- package/src/scripts/__tests__/smoke-packed-install.test.ts +320 -2
- package/src/scripts/codex-native-hook.ts +10715 -1069
- package/src/scripts/notify-fallback-watcher.ts +84 -115
- package/src/scripts/notify-hook/auto-nudge.ts +71 -3
- package/src/scripts/notify-hook/team-dispatch.ts +242 -75
- package/src/scripts/notify-hook/team-leader-nudge.ts +40 -18
- package/src/scripts/notify-hook/team-tmux-guard.ts +366 -39
- package/src/scripts/notify-hook/team-worker-stop.ts +20 -16
- package/src/scripts/notify-hook/team-worker.ts +39 -26
- package/src/scripts/notify-hook/tmux-injection.ts +28 -2
- package/src/scripts/notify-hook.ts +1 -0
- package/src/scripts/smoke-packed-install.ts +3196 -14
- package/dist/subagents/__tests__/adapted-role-binding.test.d.ts +0 -2
- package/dist/subagents/__tests__/adapted-role-binding.test.d.ts.map +0 -1
- package/dist/subagents/__tests__/adapted-role-binding.test.js +0 -988
- package/dist/subagents/__tests__/adapted-role-binding.test.js.map +0 -1
- package/dist/subagents/adapted-role-binding.d.ts +0 -17
- package/dist/subagents/adapted-role-binding.d.ts.map +0 -1
- package/dist/subagents/adapted-role-binding.js +0 -75
- package/dist/subagents/adapted-role-binding.js.map +0 -1
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
use std::collections::BTreeSet;
|
|
1
2
|
use std::fmt;
|
|
2
|
-
use std::
|
|
3
|
+
use std::io::Write;
|
|
4
|
+
use std::path::{Path, PathBuf};
|
|
3
5
|
|
|
4
6
|
use fs2::FileExt;
|
|
7
|
+
use serde::{Deserialize, Serialize};
|
|
5
8
|
|
|
6
9
|
use crate::authority::{AuthorityError, AuthorityLease};
|
|
7
10
|
use crate::dispatch::{DispatchError, DispatchLog};
|
|
@@ -77,17 +80,45 @@ impl From<serde_json::Error> for EngineError {
|
|
|
77
80
|
pub struct RuntimeEngine {
|
|
78
81
|
authority: AuthorityLease,
|
|
79
82
|
dispatch: DispatchLog,
|
|
83
|
+
seen_dispatch_ids: BTreeSet<String>,
|
|
80
84
|
mailbox: MailboxLog,
|
|
81
85
|
replay: ReplayState,
|
|
82
86
|
event_log: Vec<RuntimeEvent>,
|
|
83
87
|
state_dir: Option<PathBuf>,
|
|
84
88
|
}
|
|
85
89
|
|
|
90
|
+
#[derive(Debug, Deserialize)]
|
|
91
|
+
#[serde(deny_unknown_fields)]
|
|
92
|
+
struct DispatchSeenLedgerV1 {
|
|
93
|
+
schema_version: u32,
|
|
94
|
+
request_ids: Vec<String>,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#[derive(Debug, Serialize, Deserialize)]
|
|
98
|
+
#[serde(deny_unknown_fields)]
|
|
99
|
+
struct DispatchSeenLedgerV2 {
|
|
100
|
+
schema_version: u32,
|
|
101
|
+
ledger_epoch: u64,
|
|
102
|
+
request_ids: Vec<String>,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
#[derive(Debug, Deserialize)]
|
|
106
|
+
#[serde(untagged)]
|
|
107
|
+
enum DispatchSeenLedger {
|
|
108
|
+
V1(DispatchSeenLedgerV1),
|
|
109
|
+
V2(DispatchSeenLedgerV2),
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const DISPATCH_SEEN_LEDGER_SCHEMA_VERSION: u32 = 2;
|
|
113
|
+
const DISPATCH_SEEN_LEDGER_EPOCH: u64 = 1;
|
|
114
|
+
const DISPATCH_SEEN_LEDGER_FILE: &str = "dispatch-seen.json";
|
|
115
|
+
|
|
86
116
|
impl RuntimeEngine {
|
|
87
117
|
pub fn new() -> Self {
|
|
88
118
|
Self {
|
|
89
119
|
authority: AuthorityLease::new(),
|
|
90
120
|
dispatch: DispatchLog::new(),
|
|
121
|
+
seen_dispatch_ids: BTreeSet::new(),
|
|
91
122
|
mailbox: MailboxLog::new(),
|
|
92
123
|
replay: ReplayState::new(),
|
|
93
124
|
event_log: Vec::new(),
|
|
@@ -131,7 +162,12 @@ impl RuntimeEngine {
|
|
|
131
162
|
target,
|
|
132
163
|
metadata,
|
|
133
164
|
} => {
|
|
134
|
-
self.
|
|
165
|
+
if self.seen_dispatch_ids.contains(&request_id) {
|
|
166
|
+
return Err(DispatchError::DuplicateRequestId { request_id }.into());
|
|
167
|
+
}
|
|
168
|
+
self.dispatch
|
|
169
|
+
.queue(&request_id, &target, metadata.clone())?;
|
|
170
|
+
self.seen_dispatch_ids.insert(request_id.clone());
|
|
135
171
|
RuntimeEvent::DispatchQueued {
|
|
136
172
|
request_id,
|
|
137
173
|
target,
|
|
@@ -156,6 +192,26 @@ impl RuntimeEngine {
|
|
|
156
192
|
self.dispatch.mark_failed(&request_id, &reason)?;
|
|
157
193
|
RuntimeEvent::DispatchFailed { request_id, reason }
|
|
158
194
|
}
|
|
195
|
+
RuntimeCommand::RemoveDispatchRecords { request_ids } => {
|
|
196
|
+
let request_ids = canonical_remove_dispatch_ids(&request_ids)?;
|
|
197
|
+
for request_id in &request_ids {
|
|
198
|
+
if !self.dispatch.contains_request_id(request_id) {
|
|
199
|
+
return Err(DispatchError::NotFound {
|
|
200
|
+
request_id: request_id.clone(),
|
|
201
|
+
}
|
|
202
|
+
.into());
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
let request_id_set: std::collections::HashSet<&str> =
|
|
206
|
+
request_ids.iter().map(String::as_str).collect();
|
|
207
|
+
self.event_log
|
|
208
|
+
.retain(|event| !dispatch_event_matches_request_ids(event, &request_id_set));
|
|
209
|
+
self.dispatch = DispatchLog::new();
|
|
210
|
+
for event in &self.event_log {
|
|
211
|
+
replay_dispatch_event(&mut self.dispatch, event)?;
|
|
212
|
+
}
|
|
213
|
+
RuntimeEvent::DispatchRecordsRemoved { request_ids }
|
|
214
|
+
}
|
|
159
215
|
RuntimeCommand::RequestReplay { cursor } => {
|
|
160
216
|
self.replay.request_replay(cursor.clone());
|
|
161
217
|
RuntimeEvent::ReplayRequested { cursor }
|
|
@@ -186,7 +242,9 @@ impl RuntimeEngine {
|
|
|
186
242
|
}
|
|
187
243
|
};
|
|
188
244
|
|
|
189
|
-
|
|
245
|
+
if !matches!(event, RuntimeEvent::DispatchRecordsRemoved { .. }) {
|
|
246
|
+
self.event_log.push(event.clone());
|
|
247
|
+
}
|
|
190
248
|
Ok(event)
|
|
191
249
|
}
|
|
192
250
|
|
|
@@ -227,6 +285,7 @@ impl RuntimeEngine {
|
|
|
227
285
|
}
|
|
228
286
|
_ => true,
|
|
229
287
|
});
|
|
288
|
+
self.dispatch.prune_terminal_records();
|
|
230
289
|
}
|
|
231
290
|
|
|
232
291
|
pub fn persist(&self) -> Result<(), EngineError> {
|
|
@@ -241,11 +300,18 @@ impl RuntimeEngine {
|
|
|
241
300
|
let snapshot_json = serde_json::to_string_pretty(&self.snapshot())?;
|
|
242
301
|
std::fs::write(dir.join("snapshot.json"), snapshot_json)?;
|
|
243
302
|
|
|
303
|
+
// Publish the permanent dispatch identity ledger before any compaction/removal
|
|
304
|
+
// can make its corresponding events unavailable. A crash can conservatively
|
|
305
|
+
// retain extra IDs, but can never make an accepted ID reusable.
|
|
306
|
+
persist_dispatch_seen_ledger(dir, &self.seen_dispatch_ids)?;
|
|
307
|
+
|
|
244
308
|
let events_json = serde_json::to_string_pretty(&self.event_log)?;
|
|
245
309
|
std::fs::write(dir.join("events.json"), events_json)?;
|
|
246
310
|
|
|
247
311
|
let mailbox_json = serde_json::to_string_pretty(&self.mailbox)?;
|
|
248
312
|
std::fs::write(dir.join("mailbox.json"), mailbox_json)?;
|
|
313
|
+
let dispatch_json = serde_json::to_string_pretty(&self.dispatch)?;
|
|
314
|
+
std::fs::write(dir.join("dispatch.json"), dispatch_json)?;
|
|
249
315
|
|
|
250
316
|
drop(lock_file);
|
|
251
317
|
Ok(())
|
|
@@ -293,19 +359,50 @@ impl RuntimeEngine {
|
|
|
293
359
|
std::fs::File::open(&lock_path).or_else(|_| std::fs::File::create(&lock_path))?;
|
|
294
360
|
FileExt::lock_shared(&lock_file)?;
|
|
295
361
|
|
|
296
|
-
let
|
|
362
|
+
let events_path = dir.join("events.json");
|
|
363
|
+
let events_json = std::fs::read_to_string(&events_path)?;
|
|
297
364
|
let mut events: Vec<RuntimeEvent> = serde_json::from_str(&events_json)?;
|
|
298
365
|
let mailbox = std::fs::read_to_string(dir.join("mailbox.json"))
|
|
299
366
|
.ok()
|
|
300
367
|
.and_then(|mailbox_json| serde_json::from_str::<MailboxLog>(&mailbox_json).ok());
|
|
368
|
+
let ledger = match std::fs::read_to_string(dir.join(DISPATCH_SEEN_LEDGER_FILE)) {
|
|
369
|
+
Ok(json) => parse_dispatch_seen_ledger(&json)?,
|
|
370
|
+
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
|
|
371
|
+
return Err(std::io::Error::new(
|
|
372
|
+
std::io::ErrorKind::InvalidData,
|
|
373
|
+
"missing dispatch seen ledger; pre-ledger dispatch history is ambiguous",
|
|
374
|
+
)
|
|
375
|
+
.into())
|
|
376
|
+
}
|
|
377
|
+
Err(error) => return Err(error.into()),
|
|
378
|
+
};
|
|
379
|
+
let persisted_dispatch_ids = match std::fs::read_to_string(dir.join("dispatch.json")) {
|
|
380
|
+
Ok(json) => {
|
|
381
|
+
let dispatch: DispatchLog = serde_json::from_str(&json)?;
|
|
382
|
+
collect_unique_dispatch_ids(dispatch.request_ids())?
|
|
383
|
+
}
|
|
384
|
+
Err(error) if error.kind() == std::io::ErrorKind::NotFound => BTreeSet::new(),
|
|
385
|
+
Err(error) => return Err(error.into()),
|
|
386
|
+
};
|
|
301
387
|
|
|
302
388
|
drop(lock_file);
|
|
303
389
|
|
|
304
390
|
let mut engine = Self::new().with_state_dir(&dir);
|
|
305
|
-
// Replay all events to rebuild state
|
|
391
|
+
// Replay all events to rebuild state. Duplicate/out-of-order dispatch history
|
|
392
|
+
// is rejected by replay, rather than silently repaired.
|
|
306
393
|
for event in &events {
|
|
307
|
-
replay_event(&mut engine, event)
|
|
394
|
+
replay_event(&mut engine, event)?;
|
|
308
395
|
}
|
|
396
|
+
let authoritative_dispatch_ids = collect_legacy_dispatch_ids(&events)?;
|
|
397
|
+
if !authoritative_dispatch_ids.is_subset(&ledger)
|
|
398
|
+
|| !persisted_dispatch_ids.is_subset(&ledger)
|
|
399
|
+
{
|
|
400
|
+
return Err(DispatchError::InvalidRequestId {
|
|
401
|
+
request_id: "dispatch seen ledger omits an authoritative dispatch id".into(),
|
|
402
|
+
}
|
|
403
|
+
.into());
|
|
404
|
+
}
|
|
405
|
+
engine.seen_dispatch_ids = ledger;
|
|
309
406
|
|
|
310
407
|
if let Some(mailbox_state) = mailbox {
|
|
311
408
|
let body_by_message_id: std::collections::HashMap<&str, &str> = mailbox_state
|
|
@@ -328,12 +425,10 @@ impl RuntimeEngine {
|
|
|
328
425
|
}
|
|
329
426
|
}
|
|
330
427
|
}
|
|
331
|
-
|
|
332
428
|
engine.mailbox = mailbox_state;
|
|
333
429
|
}
|
|
334
430
|
|
|
335
431
|
engine.event_log = events;
|
|
336
|
-
|
|
337
432
|
Ok(engine)
|
|
338
433
|
}
|
|
339
434
|
}
|
|
@@ -344,7 +439,159 @@ impl Default for RuntimeEngine {
|
|
|
344
439
|
}
|
|
345
440
|
}
|
|
346
441
|
|
|
347
|
-
fn
|
|
442
|
+
fn persist_dispatch_seen_ledger(
|
|
443
|
+
dir: &Path,
|
|
444
|
+
seen_dispatch_ids: &BTreeSet<String>,
|
|
445
|
+
) -> Result<(), EngineError> {
|
|
446
|
+
let ledger = DispatchSeenLedgerV2 {
|
|
447
|
+
schema_version: DISPATCH_SEEN_LEDGER_SCHEMA_VERSION,
|
|
448
|
+
ledger_epoch: DISPATCH_SEEN_LEDGER_EPOCH,
|
|
449
|
+
request_ids: seen_dispatch_ids.iter().cloned().collect(),
|
|
450
|
+
};
|
|
451
|
+
let path = dir.join(DISPATCH_SEEN_LEDGER_FILE);
|
|
452
|
+
let temporary_path = dir.join(format!("{DISPATCH_SEEN_LEDGER_FILE}.tmp"));
|
|
453
|
+
let json = serde_json::to_vec_pretty(&ledger)?;
|
|
454
|
+
let mut temporary_file = std::fs::File::create(&temporary_path)?;
|
|
455
|
+
temporary_file.write_all(&json)?;
|
|
456
|
+
temporary_file.sync_all()?;
|
|
457
|
+
std::fs::rename(temporary_path, path)?;
|
|
458
|
+
sync_directory(dir)?;
|
|
459
|
+
Ok(())
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
fn parse_dispatch_seen_ledger(json: &str) -> Result<BTreeSet<String>, EngineError> {
|
|
463
|
+
let request_ids = match serde_json::from_str(json)? {
|
|
464
|
+
DispatchSeenLedger::V1(ledger) if ledger.schema_version == 1 => ledger.request_ids,
|
|
465
|
+
DispatchSeenLedger::V2(ledger)
|
|
466
|
+
if ledger.schema_version == DISPATCH_SEEN_LEDGER_SCHEMA_VERSION
|
|
467
|
+
&& ledger.ledger_epoch == DISPATCH_SEEN_LEDGER_EPOCH =>
|
|
468
|
+
{
|
|
469
|
+
ledger.request_ids
|
|
470
|
+
}
|
|
471
|
+
DispatchSeenLedger::V1(_) | DispatchSeenLedger::V2(_) => {
|
|
472
|
+
return Err(std::io::Error::new(
|
|
473
|
+
std::io::ErrorKind::InvalidData,
|
|
474
|
+
"unsupported dispatch seen ledger schema version or epoch",
|
|
475
|
+
)
|
|
476
|
+
.into())
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
collect_unique_dispatch_ids(request_ids.iter().map(String::as_str))
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
fn sync_directory(dir: &Path) -> Result<(), EngineError> {
|
|
483
|
+
match std::fs::File::open(dir).and_then(|directory| directory.sync_all()) {
|
|
484
|
+
Ok(()) => Ok(()),
|
|
485
|
+
Err(error) if directory_sync_is_unsupported(&error) => Ok(()),
|
|
486
|
+
Err(error) => Err(error.into()),
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
fn directory_sync_is_unsupported(error: &std::io::Error) -> bool {
|
|
491
|
+
if error.kind() == std::io::ErrorKind::Unsupported {
|
|
492
|
+
return true;
|
|
493
|
+
}
|
|
494
|
+
#[cfg(windows)]
|
|
495
|
+
{
|
|
496
|
+
// Windows does not support opening/syncing directories with the same
|
|
497
|
+
// semantics as Unix. These are the documented unsupported outcomes.
|
|
498
|
+
return matches!(error.raw_os_error(), Some(1 | 5));
|
|
499
|
+
}
|
|
500
|
+
#[cfg(not(windows))]
|
|
501
|
+
{
|
|
502
|
+
false
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
fn canonical_remove_dispatch_ids(request_ids: &[String]) -> Result<Vec<String>, EngineError> {
|
|
507
|
+
if request_ids.is_empty() {
|
|
508
|
+
return Err(DispatchError::InvalidRequestId {
|
|
509
|
+
request_id: String::new(),
|
|
510
|
+
}
|
|
511
|
+
.into());
|
|
512
|
+
}
|
|
513
|
+
let request_ids = collect_unique_dispatch_ids(request_ids.iter().map(String::as_str))?;
|
|
514
|
+
Ok(request_ids.into_iter().collect())
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
fn collect_unique_dispatch_ids<'a>(
|
|
518
|
+
request_ids: impl Iterator<Item = &'a str>,
|
|
519
|
+
) -> Result<BTreeSet<String>, EngineError> {
|
|
520
|
+
let mut seen = BTreeSet::new();
|
|
521
|
+
for request_id in request_ids {
|
|
522
|
+
if request_id.is_empty() {
|
|
523
|
+
return Err(DispatchError::InvalidRequestId {
|
|
524
|
+
request_id: request_id.to_string(),
|
|
525
|
+
}
|
|
526
|
+
.into());
|
|
527
|
+
}
|
|
528
|
+
if !seen.insert(request_id.to_string()) {
|
|
529
|
+
return Err(DispatchError::DuplicateRequestId {
|
|
530
|
+
request_id: request_id.to_string(),
|
|
531
|
+
}
|
|
532
|
+
.into());
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
Ok(seen)
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
fn collect_queued_dispatch_ids(events: &[RuntimeEvent]) -> Result<BTreeSet<String>, EngineError> {
|
|
539
|
+
collect_unique_dispatch_ids(events.iter().filter_map(|event| match event {
|
|
540
|
+
RuntimeEvent::DispatchQueued { request_id, .. } => Some(request_id.as_str()),
|
|
541
|
+
_ => None,
|
|
542
|
+
}))
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
fn collect_legacy_dispatch_ids(events: &[RuntimeEvent]) -> Result<BTreeSet<String>, EngineError> {
|
|
546
|
+
let mut seen_dispatch_ids = collect_queued_dispatch_ids(events)?;
|
|
547
|
+
for event in events {
|
|
548
|
+
if let RuntimeEvent::DispatchRecordsRemoved { request_ids } = event {
|
|
549
|
+
seen_dispatch_ids.extend(collect_unique_dispatch_ids(
|
|
550
|
+
request_ids.iter().map(String::as_str),
|
|
551
|
+
)?);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
Ok(seen_dispatch_ids)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
fn dispatch_event_matches_request_ids(
|
|
558
|
+
event: &RuntimeEvent,
|
|
559
|
+
request_ids: &std::collections::HashSet<&str>,
|
|
560
|
+
) -> bool {
|
|
561
|
+
match event {
|
|
562
|
+
RuntimeEvent::DispatchQueued { request_id, .. }
|
|
563
|
+
| RuntimeEvent::DispatchNotified { request_id, .. }
|
|
564
|
+
| RuntimeEvent::DispatchDelivered { request_id }
|
|
565
|
+
| RuntimeEvent::DispatchFailed { request_id, .. } => {
|
|
566
|
+
request_ids.contains(request_id.as_str())
|
|
567
|
+
}
|
|
568
|
+
_ => false,
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
fn replay_dispatch_event(
|
|
573
|
+
dispatch: &mut DispatchLog,
|
|
574
|
+
event: &RuntimeEvent,
|
|
575
|
+
) -> Result<(), DispatchError> {
|
|
576
|
+
match event {
|
|
577
|
+
RuntimeEvent::DispatchQueued {
|
|
578
|
+
request_id,
|
|
579
|
+
target,
|
|
580
|
+
metadata,
|
|
581
|
+
} => dispatch.queue(request_id, target, metadata.clone()),
|
|
582
|
+
RuntimeEvent::DispatchNotified {
|
|
583
|
+
request_id,
|
|
584
|
+
channel,
|
|
585
|
+
} => dispatch.mark_notified(request_id, channel),
|
|
586
|
+
RuntimeEvent::DispatchDelivered { request_id } => dispatch.mark_delivered(request_id),
|
|
587
|
+
RuntimeEvent::DispatchFailed { request_id, reason } => {
|
|
588
|
+
dispatch.mark_failed(request_id, reason)
|
|
589
|
+
}
|
|
590
|
+
_ => Ok(()),
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
fn replay_event(engine: &mut RuntimeEngine, event: &RuntimeEvent) -> Result<(), DispatchError> {
|
|
348
595
|
match event {
|
|
349
596
|
RuntimeEvent::AuthorityAcquired {
|
|
350
597
|
owner,
|
|
@@ -360,29 +607,9 @@ fn replay_event(engine: &mut RuntimeEngine, event: &RuntimeEvent) {
|
|
|
360
607
|
} => {
|
|
361
608
|
let _ = engine.authority.renew(owner, lease_id, leased_until);
|
|
362
609
|
}
|
|
363
|
-
RuntimeEvent::DispatchQueued {
|
|
364
|
-
request_id,
|
|
365
|
-
target,
|
|
366
|
-
metadata,
|
|
367
|
-
} => {
|
|
368
|
-
engine.dispatch.queue(request_id, target, metadata.clone());
|
|
369
|
-
}
|
|
370
|
-
RuntimeEvent::DispatchNotified {
|
|
371
|
-
request_id,
|
|
372
|
-
channel,
|
|
373
|
-
} => {
|
|
374
|
-
let _ = engine.dispatch.mark_notified(request_id, channel);
|
|
375
|
-
}
|
|
376
|
-
RuntimeEvent::DispatchDelivered { request_id } => {
|
|
377
|
-
let _ = engine.dispatch.mark_delivered(request_id);
|
|
378
|
-
}
|
|
379
|
-
RuntimeEvent::DispatchFailed { request_id, reason } => {
|
|
380
|
-
let _ = engine.dispatch.mark_failed(request_id, reason);
|
|
381
|
-
}
|
|
382
610
|
RuntimeEvent::ReplayRequested { cursor } => {
|
|
383
611
|
engine.replay.request_replay(cursor.clone());
|
|
384
612
|
}
|
|
385
|
-
RuntimeEvent::SnapshotCaptured => {}
|
|
386
613
|
RuntimeEvent::MailboxMessageCreated {
|
|
387
614
|
message_id,
|
|
388
615
|
from_worker,
|
|
@@ -402,7 +629,10 @@ fn replay_event(engine: &mut RuntimeEngine, event: &RuntimeEvent) {
|
|
|
402
629
|
RuntimeEvent::MailboxDelivered { message_id } => {
|
|
403
630
|
let _ = engine.mailbox.mark_delivered(message_id);
|
|
404
631
|
}
|
|
632
|
+
RuntimeEvent::DispatchRecordsRemoved { .. } | RuntimeEvent::SnapshotCaptured => {}
|
|
633
|
+
event => replay_dispatch_event(&mut engine.dispatch, event)?,
|
|
405
634
|
}
|
|
635
|
+
Ok(())
|
|
406
636
|
}
|
|
407
637
|
|
|
408
638
|
pub fn derive_readiness(
|
|
@@ -611,6 +841,11 @@ mod tests {
|
|
|
611
841
|
.unwrap(),
|
|
612
842
|
)
|
|
613
843
|
.unwrap();
|
|
844
|
+
std::fs::write(
|
|
845
|
+
dir.join(DISPATCH_SEEN_LEDGER_FILE),
|
|
846
|
+
r#"{"schema_version":2,"ledger_epoch":1,"request_ids":[]}"#,
|
|
847
|
+
)
|
|
848
|
+
.unwrap();
|
|
614
849
|
std::fs::write(dir.join("engine.lock"), "").unwrap();
|
|
615
850
|
|
|
616
851
|
let loaded = RuntimeEngine::load(&dir).unwrap();
|
|
@@ -788,6 +1023,62 @@ mod tests {
|
|
|
788
1023
|
let _ = std::fs::remove_dir_all(&dir);
|
|
789
1024
|
}
|
|
790
1025
|
|
|
1026
|
+
#[test]
|
|
1027
|
+
fn remove_dispatch_records_persists_unrelated_records_and_survives_reload() {
|
|
1028
|
+
let dir = std::env::temp_dir().join("omx-runtime-test-remove-dispatch-records");
|
|
1029
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1030
|
+
|
|
1031
|
+
let mut engine = RuntimeEngine::new().with_state_dir(&dir);
|
|
1032
|
+
for (request_id, target) in [
|
|
1033
|
+
("req-removed", "worker-removed"),
|
|
1034
|
+
("req-kept", "worker-kept"),
|
|
1035
|
+
] {
|
|
1036
|
+
engine
|
|
1037
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1038
|
+
request_id: request_id.into(),
|
|
1039
|
+
target: target.into(),
|
|
1040
|
+
metadata: None,
|
|
1041
|
+
})
|
|
1042
|
+
.unwrap();
|
|
1043
|
+
}
|
|
1044
|
+
engine.persist().unwrap();
|
|
1045
|
+
let removed = engine
|
|
1046
|
+
.process(RuntimeCommand::RemoveDispatchRecords {
|
|
1047
|
+
request_ids: vec!["req-removed".into()],
|
|
1048
|
+
})
|
|
1049
|
+
.unwrap();
|
|
1050
|
+
assert_eq!(
|
|
1051
|
+
removed,
|
|
1052
|
+
RuntimeEvent::DispatchRecordsRemoved {
|
|
1053
|
+
request_ids: vec!["req-removed".into()],
|
|
1054
|
+
}
|
|
1055
|
+
);
|
|
1056
|
+
engine.persist().unwrap();
|
|
1057
|
+
|
|
1058
|
+
let dispatch: serde_json::Value =
|
|
1059
|
+
serde_json::from_str(&std::fs::read_to_string(dir.join("dispatch.json")).unwrap())
|
|
1060
|
+
.unwrap();
|
|
1061
|
+
assert_eq!(dispatch["records"].as_array().unwrap().len(), 1);
|
|
1062
|
+
assert_eq!(dispatch["records"][0]["request_id"], "req-kept");
|
|
1063
|
+
assert!(engine.event_log().iter().all(|event| {
|
|
1064
|
+
!dispatch_event_matches_request_ids(
|
|
1065
|
+
event,
|
|
1066
|
+
&std::collections::HashSet::from(["req-removed"]),
|
|
1067
|
+
)
|
|
1068
|
+
}));
|
|
1069
|
+
|
|
1070
|
+
let loaded = RuntimeEngine::load(&dir).unwrap();
|
|
1071
|
+
assert_eq!(loaded.snapshot().backlog.pending, 1);
|
|
1072
|
+
loaded.persist().unwrap();
|
|
1073
|
+
let reloaded_dispatch: serde_json::Value =
|
|
1074
|
+
serde_json::from_str(&std::fs::read_to_string(dir.join("dispatch.json")).unwrap())
|
|
1075
|
+
.unwrap();
|
|
1076
|
+
assert_eq!(reloaded_dispatch["records"].as_array().unwrap().len(), 1);
|
|
1077
|
+
assert_eq!(reloaded_dispatch["records"][0]["request_id"], "req-kept");
|
|
1078
|
+
|
|
1079
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
791
1082
|
#[test]
|
|
792
1083
|
fn compact_removes_delivered_and_failed_events() {
|
|
793
1084
|
let mut engine = RuntimeEngine::new();
|
|
@@ -850,4 +1141,523 @@ mod tests {
|
|
|
850
1141
|
RuntimeEvent::DispatchQueued { request_id, .. } if request_id == "req-pending"
|
|
851
1142
|
));
|
|
852
1143
|
}
|
|
1144
|
+
|
|
1145
|
+
#[test]
|
|
1146
|
+
fn queue_dispatch_rejects_duplicate_ids_before_and_after_terminal_lifecycle() {
|
|
1147
|
+
let mut engine = RuntimeEngine::new();
|
|
1148
|
+
engine
|
|
1149
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1150
|
+
request_id: "req-duplicate".into(),
|
|
1151
|
+
target: "worker-1".into(),
|
|
1152
|
+
metadata: None,
|
|
1153
|
+
})
|
|
1154
|
+
.unwrap();
|
|
1155
|
+
|
|
1156
|
+
let pending_duplicate = engine
|
|
1157
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1158
|
+
request_id: "req-duplicate".into(),
|
|
1159
|
+
target: "worker-2".into(),
|
|
1160
|
+
metadata: None,
|
|
1161
|
+
})
|
|
1162
|
+
.unwrap_err();
|
|
1163
|
+
assert!(matches!(
|
|
1164
|
+
pending_duplicate,
|
|
1165
|
+
EngineError::Dispatch(DispatchError::DuplicateRequestId { .. })
|
|
1166
|
+
));
|
|
1167
|
+
|
|
1168
|
+
engine
|
|
1169
|
+
.process(RuntimeCommand::MarkFailed {
|
|
1170
|
+
request_id: "req-duplicate".into(),
|
|
1171
|
+
reason: "unavailable".into(),
|
|
1172
|
+
})
|
|
1173
|
+
.unwrap();
|
|
1174
|
+
let terminal_duplicate = engine
|
|
1175
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1176
|
+
request_id: "req-duplicate".into(),
|
|
1177
|
+
target: "worker-3".into(),
|
|
1178
|
+
metadata: None,
|
|
1179
|
+
})
|
|
1180
|
+
.unwrap_err();
|
|
1181
|
+
assert!(matches!(
|
|
1182
|
+
terminal_duplicate,
|
|
1183
|
+
EngineError::Dispatch(DispatchError::DuplicateRequestId { .. })
|
|
1184
|
+
));
|
|
1185
|
+
assert_eq!(engine.event_log().len(), 2);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
#[test]
|
|
1189
|
+
fn load_rejects_duplicate_and_out_of_order_legacy_dispatch_events() {
|
|
1190
|
+
let cases = [
|
|
1191
|
+
(
|
|
1192
|
+
"duplicate",
|
|
1193
|
+
vec![
|
|
1194
|
+
RuntimeEvent::DispatchQueued {
|
|
1195
|
+
request_id: "req-1".into(),
|
|
1196
|
+
target: "worker-1".into(),
|
|
1197
|
+
metadata: None,
|
|
1198
|
+
},
|
|
1199
|
+
RuntimeEvent::DispatchQueued {
|
|
1200
|
+
request_id: "req-1".into(),
|
|
1201
|
+
target: "worker-2".into(),
|
|
1202
|
+
metadata: None,
|
|
1203
|
+
},
|
|
1204
|
+
],
|
|
1205
|
+
"duplicate dispatch request id: req-1",
|
|
1206
|
+
),
|
|
1207
|
+
(
|
|
1208
|
+
"out-of-order",
|
|
1209
|
+
vec![RuntimeEvent::DispatchDelivered {
|
|
1210
|
+
request_id: "req-1".into(),
|
|
1211
|
+
}],
|
|
1212
|
+
"dispatch record not found: req-1",
|
|
1213
|
+
),
|
|
1214
|
+
];
|
|
1215
|
+
|
|
1216
|
+
for (name, events, expected_error) in cases {
|
|
1217
|
+
let dir = std::env::temp_dir().join(format!("omx-runtime-test-malformed-{name}"));
|
|
1218
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1219
|
+
std::fs::create_dir_all(&dir).unwrap();
|
|
1220
|
+
std::fs::write(
|
|
1221
|
+
dir.join("events.json"),
|
|
1222
|
+
serde_json::to_string(&events).unwrap(),
|
|
1223
|
+
)
|
|
1224
|
+
.unwrap();
|
|
1225
|
+
std::fs::write(
|
|
1226
|
+
dir.join(DISPATCH_SEEN_LEDGER_FILE),
|
|
1227
|
+
r#"{"schema_version":2,"ledger_epoch":1,"request_ids":["req-1"]}"#,
|
|
1228
|
+
)
|
|
1229
|
+
.unwrap();
|
|
1230
|
+
|
|
1231
|
+
let err = match RuntimeEngine::load(&dir) {
|
|
1232
|
+
Ok(_) => panic!("malformed dispatch event log loaded successfully"),
|
|
1233
|
+
Err(err) => err,
|
|
1234
|
+
};
|
|
1235
|
+
assert!(err.to_string().contains(expected_error));
|
|
1236
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
#[test]
|
|
1241
|
+
fn compact_persist_reload_is_idempotent_and_preserves_unrelated_dispatches() {
|
|
1242
|
+
let dir = std::env::temp_dir().join("omx-runtime-test-compact-idempotent");
|
|
1243
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1244
|
+
let mut engine = RuntimeEngine::new().with_state_dir(&dir);
|
|
1245
|
+
|
|
1246
|
+
for request_id in ["pending", "terminal"] {
|
|
1247
|
+
engine
|
|
1248
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1249
|
+
request_id: request_id.into(),
|
|
1250
|
+
target: format!("worker-{request_id}"),
|
|
1251
|
+
metadata: None,
|
|
1252
|
+
})
|
|
1253
|
+
.unwrap();
|
|
1254
|
+
}
|
|
1255
|
+
engine
|
|
1256
|
+
.process(RuntimeCommand::MarkFailed {
|
|
1257
|
+
request_id: "terminal".into(),
|
|
1258
|
+
reason: "target unavailable".into(),
|
|
1259
|
+
})
|
|
1260
|
+
.unwrap();
|
|
1261
|
+
engine.compact();
|
|
1262
|
+
engine.persist().unwrap();
|
|
1263
|
+
|
|
1264
|
+
let immediate_dispatch: DispatchLog =
|
|
1265
|
+
serde_json::from_str(&std::fs::read_to_string(dir.join("dispatch.json")).unwrap())
|
|
1266
|
+
.unwrap();
|
|
1267
|
+
assert_eq!(immediate_dispatch.records().len(), 1);
|
|
1268
|
+
assert_eq!(immediate_dispatch.records()[0].request_id, "pending");
|
|
1269
|
+
|
|
1270
|
+
let mut loaded = RuntimeEngine::load(&dir).unwrap();
|
|
1271
|
+
assert_eq!(loaded.snapshot().backlog, engine.snapshot().backlog);
|
|
1272
|
+
assert_eq!(loaded.event_log(), engine.event_log());
|
|
1273
|
+
loaded.compact();
|
|
1274
|
+
assert_eq!(loaded.event_log(), engine.event_log());
|
|
1275
|
+
loaded.persist().unwrap();
|
|
1276
|
+
|
|
1277
|
+
let reloaded = RuntimeEngine::load(&dir).unwrap();
|
|
1278
|
+
assert_eq!(reloaded.snapshot().backlog, engine.snapshot().backlog);
|
|
1279
|
+
assert_eq!(reloaded.event_log(), engine.event_log());
|
|
1280
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
#[test]
|
|
1284
|
+
fn compacted_and_removed_dispatch_ids_remain_permanently_reserved_after_reload() {
|
|
1285
|
+
let dir = std::env::temp_dir().join("omx-runtime-test-dispatch-seen-ledger");
|
|
1286
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1287
|
+
let mut engine = RuntimeEngine::new().with_state_dir(&dir);
|
|
1288
|
+
for request_id in ["compacted", "removed", "unrelated"] {
|
|
1289
|
+
engine
|
|
1290
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1291
|
+
request_id: request_id.into(),
|
|
1292
|
+
target: format!("worker-{request_id}"),
|
|
1293
|
+
metadata: None,
|
|
1294
|
+
})
|
|
1295
|
+
.unwrap();
|
|
1296
|
+
}
|
|
1297
|
+
engine
|
|
1298
|
+
.process(RuntimeCommand::MarkFailed {
|
|
1299
|
+
request_id: "compacted".into(),
|
|
1300
|
+
reason: "unavailable".into(),
|
|
1301
|
+
})
|
|
1302
|
+
.unwrap();
|
|
1303
|
+
engine.compact();
|
|
1304
|
+
engine
|
|
1305
|
+
.process(RuntimeCommand::RemoveDispatchRecords {
|
|
1306
|
+
request_ids: vec!["removed".into()],
|
|
1307
|
+
})
|
|
1308
|
+
.unwrap();
|
|
1309
|
+
engine.persist().unwrap();
|
|
1310
|
+
|
|
1311
|
+
let mut loaded = RuntimeEngine::load(&dir).unwrap();
|
|
1312
|
+
assert_eq!(loaded.snapshot().backlog.pending, 1);
|
|
1313
|
+
for request_id in ["compacted", "removed"] {
|
|
1314
|
+
assert!(matches!(
|
|
1315
|
+
loaded
|
|
1316
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1317
|
+
request_id: request_id.into(),
|
|
1318
|
+
target: "replacement".into(),
|
|
1319
|
+
metadata: None,
|
|
1320
|
+
})
|
|
1321
|
+
.unwrap_err(),
|
|
1322
|
+
EngineError::Dispatch(DispatchError::DuplicateRequestId { .. })
|
|
1323
|
+
));
|
|
1324
|
+
}
|
|
1325
|
+
loaded
|
|
1326
|
+
.process(RuntimeCommand::MarkFailed {
|
|
1327
|
+
request_id: "unrelated".into(),
|
|
1328
|
+
reason: "unavailable".into(),
|
|
1329
|
+
})
|
|
1330
|
+
.unwrap();
|
|
1331
|
+
assert_eq!(loaded.snapshot().backlog.failed, 1);
|
|
1332
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
#[test]
|
|
1336
|
+
fn schema_1_dispatch_seen_ledger_migrates_with_removed_and_compacted_history() {
|
|
1337
|
+
let dir = std::env::temp_dir().join("omx-runtime-test-schema-1-dispatch-seen-ledger");
|
|
1338
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1339
|
+
std::fs::create_dir_all(&dir).unwrap();
|
|
1340
|
+
let events = vec![
|
|
1341
|
+
RuntimeEvent::DispatchQueued {
|
|
1342
|
+
request_id: "pending".into(),
|
|
1343
|
+
target: "worker-pending".into(),
|
|
1344
|
+
metadata: None,
|
|
1345
|
+
},
|
|
1346
|
+
RuntimeEvent::DispatchRecordsRemoved {
|
|
1347
|
+
request_ids: vec!["removed".into()],
|
|
1348
|
+
},
|
|
1349
|
+
];
|
|
1350
|
+
std::fs::write(
|
|
1351
|
+
dir.join("events.json"),
|
|
1352
|
+
serde_json::to_string(&events).unwrap(),
|
|
1353
|
+
)
|
|
1354
|
+
.unwrap();
|
|
1355
|
+
std::fs::write(
|
|
1356
|
+
dir.join(DISPATCH_SEEN_LEDGER_FILE),
|
|
1357
|
+
r#"{"schema_version":1,"request_ids":["compacted","pending","removed"]}"#,
|
|
1358
|
+
)
|
|
1359
|
+
.unwrap();
|
|
1360
|
+
|
|
1361
|
+
let mut loaded = RuntimeEngine::load(&dir).unwrap();
|
|
1362
|
+
assert_eq!(loaded.snapshot().backlog.pending, 1);
|
|
1363
|
+
for request_id in ["compacted", "pending", "removed"] {
|
|
1364
|
+
assert!(matches!(
|
|
1365
|
+
loaded
|
|
1366
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1367
|
+
request_id: request_id.into(),
|
|
1368
|
+
target: "replacement".into(),
|
|
1369
|
+
metadata: None,
|
|
1370
|
+
})
|
|
1371
|
+
.unwrap_err(),
|
|
1372
|
+
EngineError::Dispatch(DispatchError::DuplicateRequestId { .. })
|
|
1373
|
+
));
|
|
1374
|
+
}
|
|
1375
|
+
loaded.persist().unwrap();
|
|
1376
|
+
|
|
1377
|
+
let ledger: serde_json::Value = serde_json::from_str(
|
|
1378
|
+
&std::fs::read_to_string(dir.join(DISPATCH_SEEN_LEDGER_FILE)).unwrap(),
|
|
1379
|
+
)
|
|
1380
|
+
.unwrap();
|
|
1381
|
+
assert_eq!(ledger["schema_version"], 2);
|
|
1382
|
+
assert_eq!(ledger["ledger_epoch"], 1);
|
|
1383
|
+
assert_eq!(
|
|
1384
|
+
ledger["request_ids"],
|
|
1385
|
+
serde_json::json!(["compacted", "pending", "removed"])
|
|
1386
|
+
);
|
|
1387
|
+
|
|
1388
|
+
let mut reloaded = RuntimeEngine::load(&dir).unwrap();
|
|
1389
|
+
assert_eq!(reloaded.snapshot().backlog.pending, 1);
|
|
1390
|
+
for request_id in ["compacted", "pending", "removed"] {
|
|
1391
|
+
assert!(matches!(
|
|
1392
|
+
reloaded
|
|
1393
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1394
|
+
request_id: request_id.into(),
|
|
1395
|
+
target: "replacement".into(),
|
|
1396
|
+
metadata: None,
|
|
1397
|
+
})
|
|
1398
|
+
.unwrap_err(),
|
|
1399
|
+
EngineError::Dispatch(DispatchError::DuplicateRequestId { .. })
|
|
1400
|
+
));
|
|
1401
|
+
}
|
|
1402
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
#[test]
|
|
1406
|
+
fn load_rejects_malformed_or_duplicate_dispatch_seen_ledger() {
|
|
1407
|
+
let cases = [
|
|
1408
|
+
(
|
|
1409
|
+
"malformed",
|
|
1410
|
+
r#"{"schema_version":2,"ledger_epoch":1,"request_ids":"req-1"}"#,
|
|
1411
|
+
),
|
|
1412
|
+
(
|
|
1413
|
+
"duplicate",
|
|
1414
|
+
r#"{"schema_version":2,"ledger_epoch":1,"request_ids":["req-1","req-1"]}"#,
|
|
1415
|
+
),
|
|
1416
|
+
(
|
|
1417
|
+
"unknown-schema",
|
|
1418
|
+
r#"{"schema_version":3,"ledger_epoch":1,"request_ids":[]}"#,
|
|
1419
|
+
),
|
|
1420
|
+
(
|
|
1421
|
+
"unknown-epoch",
|
|
1422
|
+
r#"{"schema_version":2,"ledger_epoch":2,"request_ids":[]}"#,
|
|
1423
|
+
),
|
|
1424
|
+
(
|
|
1425
|
+
"empty-id",
|
|
1426
|
+
r#"{"schema_version":2,"ledger_epoch":1,"request_ids":[""]}"#,
|
|
1427
|
+
),
|
|
1428
|
+
];
|
|
1429
|
+
for (name, ledger) in cases {
|
|
1430
|
+
let dir = std::env::temp_dir().join(format!("omx-runtime-test-seen-ledger-{name}"));
|
|
1431
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1432
|
+
std::fs::create_dir_all(&dir).unwrap();
|
|
1433
|
+
std::fs::write(dir.join("events.json"), "[]").unwrap();
|
|
1434
|
+
std::fs::write(dir.join(DISPATCH_SEEN_LEDGER_FILE), ledger).unwrap();
|
|
1435
|
+
assert!(RuntimeEngine::load(&dir).is_err());
|
|
1436
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
#[test]
|
|
1441
|
+
fn load_rejects_missing_or_ambiguous_pre_ledger_dispatch_history() {
|
|
1442
|
+
let cases = [
|
|
1443
|
+
(
|
|
1444
|
+
"missing-ledger",
|
|
1445
|
+
vec![RuntimeEvent::DispatchQueued {
|
|
1446
|
+
request_id: "legacy".into(),
|
|
1447
|
+
target: "worker-legacy".into(),
|
|
1448
|
+
metadata: None,
|
|
1449
|
+
}],
|
|
1450
|
+
),
|
|
1451
|
+
(
|
|
1452
|
+
"legacy-removal",
|
|
1453
|
+
vec![RuntimeEvent::DispatchRecordsRemoved {
|
|
1454
|
+
request_ids: vec!["legacy-removed".into()],
|
|
1455
|
+
}],
|
|
1456
|
+
),
|
|
1457
|
+
];
|
|
1458
|
+
for (name, events) in cases {
|
|
1459
|
+
let dir = std::env::temp_dir().join(format!("omx-runtime-test-{name}"));
|
|
1460
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1461
|
+
std::fs::create_dir_all(&dir).unwrap();
|
|
1462
|
+
std::fs::write(
|
|
1463
|
+
dir.join("events.json"),
|
|
1464
|
+
serde_json::to_string(&events).unwrap(),
|
|
1465
|
+
)
|
|
1466
|
+
.unwrap();
|
|
1467
|
+
assert!(RuntimeEngine::load(&dir).is_err());
|
|
1468
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
#[test]
|
|
1473
|
+
fn removal_reserves_ids_immediately_and_after_reload() {
|
|
1474
|
+
let dir = std::env::temp_dir().join("omx-runtime-test-remove-reserves-id");
|
|
1475
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1476
|
+
let mut engine = RuntimeEngine::new().with_state_dir(&dir);
|
|
1477
|
+
for request_id in ["removed", "kept"] {
|
|
1478
|
+
engine
|
|
1479
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1480
|
+
request_id: request_id.into(),
|
|
1481
|
+
target: format!("worker-{request_id}"),
|
|
1482
|
+
metadata: None,
|
|
1483
|
+
})
|
|
1484
|
+
.unwrap();
|
|
1485
|
+
}
|
|
1486
|
+
engine
|
|
1487
|
+
.process(RuntimeCommand::RemoveDispatchRecords {
|
|
1488
|
+
request_ids: vec!["removed".into()],
|
|
1489
|
+
})
|
|
1490
|
+
.unwrap();
|
|
1491
|
+
assert!(matches!(
|
|
1492
|
+
engine
|
|
1493
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1494
|
+
request_id: "removed".into(),
|
|
1495
|
+
target: "replacement".into(),
|
|
1496
|
+
metadata: None,
|
|
1497
|
+
})
|
|
1498
|
+
.unwrap_err(),
|
|
1499
|
+
EngineError::Dispatch(DispatchError::DuplicateRequestId { .. })
|
|
1500
|
+
));
|
|
1501
|
+
engine.persist().unwrap();
|
|
1502
|
+
let mut loaded = RuntimeEngine::load(&dir).unwrap();
|
|
1503
|
+
assert!(matches!(
|
|
1504
|
+
loaded
|
|
1505
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1506
|
+
request_id: "removed".into(),
|
|
1507
|
+
target: "replacement".into(),
|
|
1508
|
+
metadata: None,
|
|
1509
|
+
})
|
|
1510
|
+
.unwrap_err(),
|
|
1511
|
+
EngineError::Dispatch(DispatchError::DuplicateRequestId { .. })
|
|
1512
|
+
));
|
|
1513
|
+
assert_eq!(loaded.snapshot().backlog.pending, 1);
|
|
1514
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
#[test]
|
|
1518
|
+
fn delayed_terminal_commands_and_removal_do_not_mutate_unrelated_dispatch() {
|
|
1519
|
+
let mut engine = RuntimeEngine::new();
|
|
1520
|
+
for request_id in ["terminal", "unrelated"] {
|
|
1521
|
+
engine
|
|
1522
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1523
|
+
request_id: request_id.into(),
|
|
1524
|
+
target: format!("worker-{request_id}"),
|
|
1525
|
+
metadata: None,
|
|
1526
|
+
})
|
|
1527
|
+
.unwrap();
|
|
1528
|
+
}
|
|
1529
|
+
engine
|
|
1530
|
+
.process(RuntimeCommand::MarkFailed {
|
|
1531
|
+
request_id: "terminal".into(),
|
|
1532
|
+
reason: "unavailable".into(),
|
|
1533
|
+
})
|
|
1534
|
+
.unwrap();
|
|
1535
|
+
engine.compact();
|
|
1536
|
+
for command in [
|
|
1537
|
+
RuntimeCommand::MarkNotified {
|
|
1538
|
+
request_id: "terminal".into(),
|
|
1539
|
+
channel: "tmux".into(),
|
|
1540
|
+
},
|
|
1541
|
+
RuntimeCommand::MarkDelivered {
|
|
1542
|
+
request_id: "terminal".into(),
|
|
1543
|
+
},
|
|
1544
|
+
RuntimeCommand::MarkFailed {
|
|
1545
|
+
request_id: "terminal".into(),
|
|
1546
|
+
reason: "late".into(),
|
|
1547
|
+
},
|
|
1548
|
+
] {
|
|
1549
|
+
assert!(matches!(
|
|
1550
|
+
engine.process(command),
|
|
1551
|
+
Err(EngineError::Dispatch(DispatchError::NotFound { .. }))
|
|
1552
|
+
));
|
|
1553
|
+
}
|
|
1554
|
+
assert!(matches!(
|
|
1555
|
+
engine.process(RuntimeCommand::RemoveDispatchRecords {
|
|
1556
|
+
request_ids: vec!["terminal".into()],
|
|
1557
|
+
}),
|
|
1558
|
+
Err(EngineError::Dispatch(DispatchError::NotFound { .. }))
|
|
1559
|
+
));
|
|
1560
|
+
assert_eq!(engine.snapshot().backlog.pending, 1);
|
|
1561
|
+
assert_eq!(engine.dispatch.records()[0].request_id, "unrelated");
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
#[test]
|
|
1565
|
+
fn repeated_terminal_commands_are_rejected_without_replay_events() {
|
|
1566
|
+
let mut engine = RuntimeEngine::new();
|
|
1567
|
+
engine
|
|
1568
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1569
|
+
request_id: "terminal".into(),
|
|
1570
|
+
target: "worker".into(),
|
|
1571
|
+
metadata: None,
|
|
1572
|
+
})
|
|
1573
|
+
.unwrap();
|
|
1574
|
+
engine
|
|
1575
|
+
.process(RuntimeCommand::MarkFailed {
|
|
1576
|
+
request_id: "terminal".into(),
|
|
1577
|
+
reason: "unavailable".into(),
|
|
1578
|
+
})
|
|
1579
|
+
.unwrap();
|
|
1580
|
+
let events_before_replay = engine.event_log().len();
|
|
1581
|
+
assert!(matches!(
|
|
1582
|
+
engine.process(RuntimeCommand::MarkFailed {
|
|
1583
|
+
request_id: "terminal".into(),
|
|
1584
|
+
reason: "replayed".into(),
|
|
1585
|
+
}),
|
|
1586
|
+
Err(EngineError::Dispatch(
|
|
1587
|
+
DispatchError::InvalidTransition { .. }
|
|
1588
|
+
))
|
|
1589
|
+
));
|
|
1590
|
+
assert_eq!(engine.event_log().len(), events_before_replay);
|
|
1591
|
+
engine.compact();
|
|
1592
|
+
engine.compact();
|
|
1593
|
+
assert_eq!(engine.snapshot().backlog.failed, 0);
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
#[test]
|
|
1597
|
+
fn remove_dispatch_records_rejects_noncanonical_or_unknown_ids_without_mutation() {
|
|
1598
|
+
let mut engine = RuntimeEngine::new();
|
|
1599
|
+
for request_id in ["a", "b"] {
|
|
1600
|
+
engine
|
|
1601
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1602
|
+
request_id: request_id.into(),
|
|
1603
|
+
target: "worker".into(),
|
|
1604
|
+
metadata: None,
|
|
1605
|
+
})
|
|
1606
|
+
.unwrap();
|
|
1607
|
+
}
|
|
1608
|
+
let events_before = engine.event_log().to_vec();
|
|
1609
|
+
for request_ids in [
|
|
1610
|
+
vec![],
|
|
1611
|
+
vec!["".into()],
|
|
1612
|
+
vec!["a".into(), "a".into()],
|
|
1613
|
+
vec!["missing".into()],
|
|
1614
|
+
vec!["a".into(), "missing".into()],
|
|
1615
|
+
] {
|
|
1616
|
+
assert!(engine
|
|
1617
|
+
.process(RuntimeCommand::RemoveDispatchRecords { request_ids })
|
|
1618
|
+
.is_err());
|
|
1619
|
+
assert_eq!(engine.event_log(), events_before);
|
|
1620
|
+
assert_eq!(engine.dispatch.records().len(), 2);
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
let removed = engine
|
|
1624
|
+
.process(RuntimeCommand::RemoveDispatchRecords {
|
|
1625
|
+
request_ids: vec!["b".into(), "a".into()],
|
|
1626
|
+
})
|
|
1627
|
+
.unwrap();
|
|
1628
|
+
assert_eq!(
|
|
1629
|
+
removed,
|
|
1630
|
+
RuntimeEvent::DispatchRecordsRemoved {
|
|
1631
|
+
request_ids: vec!["a".into(), "b".into()],
|
|
1632
|
+
}
|
|
1633
|
+
);
|
|
1634
|
+
assert!(engine.event_log().is_empty());
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
#[test]
|
|
1638
|
+
fn torn_or_deleted_seen_ledger_fails_reload_after_compaction() {
|
|
1639
|
+
let dir = std::env::temp_dir().join("omx-runtime-test-torn-seen-ledger");
|
|
1640
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1641
|
+
let mut engine = RuntimeEngine::new().with_state_dir(&dir);
|
|
1642
|
+
engine
|
|
1643
|
+
.process(RuntimeCommand::QueueDispatch {
|
|
1644
|
+
request_id: "retired".into(),
|
|
1645
|
+
target: "worker".into(),
|
|
1646
|
+
metadata: None,
|
|
1647
|
+
})
|
|
1648
|
+
.unwrap();
|
|
1649
|
+
engine
|
|
1650
|
+
.process(RuntimeCommand::MarkFailed {
|
|
1651
|
+
request_id: "retired".into(),
|
|
1652
|
+
reason: "unavailable".into(),
|
|
1653
|
+
})
|
|
1654
|
+
.unwrap();
|
|
1655
|
+
engine.compact();
|
|
1656
|
+
engine.persist().unwrap();
|
|
1657
|
+
std::fs::remove_file(dir.join(DISPATCH_SEEN_LEDGER_FILE)).unwrap();
|
|
1658
|
+
assert!(RuntimeEngine::load(&dir).is_err());
|
|
1659
|
+
std::fs::write(dir.join(DISPATCH_SEEN_LEDGER_FILE), "{").unwrap();
|
|
1660
|
+
assert!(RuntimeEngine::load(&dir).is_err());
|
|
1661
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
1662
|
+
}
|
|
853
1663
|
}
|