@open-mercato/cezar 0.17.0-pr976.3708 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/agent-config/validate.d.ts +2 -1
- package/dist/agent-config/validate.js.map +1 -1
- package/dist/api-origin.d.ts +0 -4
- package/dist/api-origin.js +0 -22
- package/dist/api-origin.js.map +1 -1
- package/dist/cockpit-address.d.ts +5 -0
- package/dist/cockpit-address.js +7 -0
- package/dist/cockpit-address.js.map +1 -1
- package/dist/contract/health.d.ts +30 -0
- package/dist/contract/index.d.ts +1 -0
- package/dist/contract/index.js +2370 -2054
- package/dist/contract/projects.d.ts +1 -0
- package/dist/contract/runs.d.ts +178 -2
- package/dist/contract/skills.d.ts +23 -0
- package/dist/contract/webhooks.d.ts +1136 -0
- package/dist/contract/workspace.d.ts +2 -0
- package/dist/core/agent-errors.d.ts +6 -0
- package/dist/core/agent-errors.js +13 -0
- package/dist/core/agent-errors.js.map +1 -1
- package/dist/core/agent-failure-class.d.ts +24 -0
- package/dist/core/agent-failure-class.js +99 -0
- package/dist/core/agent-failure-class.js.map +1 -0
- package/dist/core/agent-runner.d.ts +1 -1
- package/dist/core/claude-cli-runner.d.ts +2 -2
- package/dist/core/claude-cli-runner.js +17 -21
- package/dist/core/claude-cli-runner.js.map +1 -1
- package/dist/core/codex-app-server-runner.d.ts +1 -1
- package/dist/core/codex-app-server-runner.js +20 -23
- package/dist/core/codex-app-server-runner.js.map +1 -1
- package/dist/core/copilot-acp-runner.d.ts +1 -1
- package/dist/core/copilot-acp-runner.js +10 -10
- package/dist/core/copilot-acp-runner.js.map +1 -1
- package/dist/core/cursor-agent-runner.js +18 -22
- package/dist/core/cursor-agent-runner.js.map +1 -1
- package/dist/core/inactivity-deadline.d.ts +21 -0
- package/dist/core/inactivity-deadline.js +49 -0
- package/dist/core/inactivity-deadline.js.map +1 -0
- package/dist/core/junie-runner.d.ts +1 -1
- package/dist/core/junie-runner.js +16 -20
- package/dist/core/junie-runner.js.map +1 -1
- package/dist/core/opencode-server-runner.d.ts +2 -2
- package/dist/core/opencode-server-runner.js +23 -15
- package/dist/core/opencode-server-runner.js.map +1 -1
- package/dist/core/pi-runner.d.ts +1 -1
- package/dist/core/pi-runner.js +8 -10
- package/dist/core/pi-runner.js.map +1 -1
- package/dist/core/provider-auth.js +18 -6
- package/dist/core/provider-auth.js.map +1 -1
- package/dist/core/runner-factory.d.ts +2 -0
- package/dist/core/runner-factory.js +39 -0
- package/dist/core/runner-factory.js.map +1 -1
- package/dist/core/secret-redaction.js +38 -6
- package/dist/core/secret-redaction.js.map +1 -1
- package/dist/data-gitignore.d.ts +1 -1
- package/dist/data-gitignore.js +1 -0
- package/dist/data-gitignore.js.map +1 -1
- package/dist/disk-space.d.ts +38 -0
- package/dist/disk-space.js +113 -0
- package/dist/disk-space.js.map +1 -0
- package/dist/dispatch/prompts.js +1 -1
- package/dist/git-worktree.d.ts +2 -0
- package/dist/git-worktree.js +16 -0
- package/dist/git-worktree.js.map +1 -1
- package/dist/handoff.d.ts +2 -2
- package/dist/handoff.js +1 -1
- package/dist/index.js +24 -3
- package/dist/index.js.map +1 -1
- package/dist/pack-check.d.ts +10 -0
- package/dist/pack-check.js +7 -0
- package/dist/pack-check.js.map +1 -1
- package/dist/release/backport.d.ts +34 -0
- package/dist/release/backport.js +33 -0
- package/dist/release/backport.js.map +1 -0
- package/dist/runs/agent-error-telemetry.d.ts +5 -1
- package/dist/runs/agent-error-telemetry.js +17 -10
- package/dist/runs/agent-error-telemetry.js.map +1 -1
- package/dist/runs/failure-kind.d.ts +1 -1
- package/dist/runs/failure-kind.js +5 -8
- package/dist/runs/failure-kind.js.map +1 -1
- package/dist/runs/lifecycle.d.ts +55 -0
- package/dist/runs/lifecycle.js +24 -0
- package/dist/runs/lifecycle.js.map +1 -0
- package/dist/runs/retention.js +36 -4
- package/dist/runs/retention.js.map +1 -1
- package/dist/runs/store.d.ts +31 -0
- package/dist/runs/store.js +59 -5
- package/dist/runs/store.js.map +1 -1
- package/dist/server/capabilities.js +3 -0
- package/dist/server/capabilities.js.map +1 -1
- package/dist/server/disk-health.d.ts +11 -0
- package/dist/server/disk-health.js +26 -0
- package/dist/server/disk-health.js.map +1 -0
- package/dist/server/forge/github.d.ts +9 -1
- package/dist/server/forge/github.js +42 -3
- package/dist/server/forge/github.js.map +1 -1
- package/dist/server/message-receipts.d.ts +27 -0
- package/dist/server/message-receipts.js +54 -0
- package/dist/server/message-receipts.js.map +1 -0
- package/dist/server/project-context.d.ts +5 -0
- package/dist/server/project-context.js +35 -1
- package/dist/server/project-context.js.map +1 -1
- package/dist/server/server.d.ts +2744 -866
- package/dist/server/server.js +191 -148
- package/dist/server/server.js.map +1 -1
- package/dist/server/webhooks.d.ts +817 -0
- package/dist/server/webhooks.js +91 -0
- package/dist/server/webhooks.js.map +1 -0
- package/dist/server/worktree-lifecycle.d.ts +88 -88
- package/dist/startup-port.d.ts +12 -0
- package/dist/startup-port.js +33 -0
- package/dist/startup-port.js.map +1 -0
- package/dist/telemetry-service.json +1 -0
- package/dist/webhooks/admission.d.ts +360 -0
- package/dist/webhooks/admission.js +294 -0
- package/dist/webhooks/admission.js.map +1 -0
- package/dist/webhooks/coordinator.d.ts +39 -0
- package/dist/webhooks/coordinator.js +215 -0
- package/dist/webhooks/coordinator.js.map +1 -0
- package/dist/webhooks/destination.d.ts +24 -0
- package/dist/webhooks/destination.js +111 -0
- package/dist/webhooks/destination.js.map +1 -0
- package/dist/webhooks/discord.d.ts +4 -0
- package/dist/webhooks/discord.js +102 -0
- package/dist/webhooks/discord.js.map +1 -0
- package/dist/webhooks/endpoints.d.ts +201 -0
- package/dist/webhooks/endpoints.js +345 -0
- package/dist/webhooks/endpoints.js.map +1 -0
- package/dist/webhooks/history.d.ts +42 -0
- package/dist/webhooks/history.js +222 -0
- package/dist/webhooks/history.js.map +1 -0
- package/dist/webhooks/lifecycle.d.ts +34 -0
- package/dist/webhooks/lifecycle.js +60 -0
- package/dist/webhooks/lifecycle.js.map +1 -0
- package/dist/webhooks/limits.d.ts +19 -0
- package/dist/webhooks/limits.js +101 -0
- package/dist/webhooks/limits.js.map +1 -0
- package/dist/webhooks/links.d.ts +12 -0
- package/dist/webhooks/links.js +40 -0
- package/dist/webhooks/links.js.map +1 -0
- package/dist/webhooks/operations.d.ts +24 -0
- package/dist/webhooks/operations.js +128 -0
- package/dist/webhooks/operations.js.map +1 -0
- package/dist/webhooks/outbox.d.ts +37 -0
- package/dist/webhooks/outbox.js +221 -0
- package/dist/webhooks/outbox.js.map +1 -0
- package/dist/webhooks/ownership.d.ts +17 -0
- package/dist/webhooks/ownership.js +254 -0
- package/dist/webhooks/ownership.js.map +1 -0
- package/dist/webhooks/payload.d.ts +6 -0
- package/dist/webhooks/payload.js +112 -0
- package/dist/webhooks/payload.js.map +1 -0
- package/dist/webhooks/platform.d.ts +9 -0
- package/dist/webhooks/platform.js +12 -0
- package/dist/webhooks/platform.js.map +1 -0
- package/dist/webhooks/privacy.d.ts +4 -0
- package/dist/webhooks/privacy.js +43 -0
- package/dist/webhooks/privacy.js.map +1 -0
- package/dist/webhooks/process-identity.d.ts +36 -0
- package/dist/webhooks/process-identity.js +240 -0
- package/dist/webhooks/process-identity.js.map +1 -0
- package/dist/webhooks/scheduler.d.ts +10 -0
- package/dist/webhooks/scheduler.js +43 -0
- package/dist/webhooks/scheduler.js.map +1 -0
- package/dist/webhooks/service.d.ts +313 -0
- package/dist/webhooks/service.js +1005 -0
- package/dist/webhooks/service.js.map +1 -0
- package/dist/webhooks/signing.d.ts +3 -0
- package/dist/webhooks/signing.js +36 -0
- package/dist/webhooks/signing.js.map +1 -0
- package/dist/webhooks/slack.d.ts +4 -0
- package/dist/webhooks/slack.js +56 -0
- package/dist/webhooks/slack.js.map +1 -0
- package/dist/webhooks/source.d.ts +178 -0
- package/dist/webhooks/source.js +23 -0
- package/dist/webhooks/source.js.map +1 -0
- package/dist/webhooks/storage.d.ts +21 -0
- package/dist/webhooks/storage.js +202 -0
- package/dist/webhooks/storage.js.map +1 -0
- package/dist/webhooks/transport.d.ts +30 -0
- package/dist/webhooks/transport.js +235 -0
- package/dist/webhooks/transport.js.map +1 -0
- package/dist/workflows/completion-reason.d.ts +4 -0
- package/dist/workflows/completion-reason.js +39 -0
- package/dist/workflows/completion-reason.js.map +1 -0
- package/dist/workflows/queued-bounds.d.ts +31 -0
- package/dist/workflows/queued-bounds.js +81 -0
- package/dist/workflows/queued-bounds.js.map +1 -0
- package/dist/workflows/run.d.ts +113 -20
- package/dist/workflows/run.js +726 -191
- package/dist/workflows/run.js.map +1 -1
- package/dist/workspace/config.d.ts +8 -0
- package/dist/workspace/config.js +62 -19
- package/dist/workspace/config.js.map +1 -1
- package/dist/workspace/ui-state.d.ts +4 -2
- package/dist/workspace/ui-state.js +13 -9
- package/dist/workspace/ui-state.js.map +1 -1
- package/package.json +4 -3
- package/scripts/check-pack.mjs +2 -4
- package/scripts/mock-claude.mjs +30 -5
- package/scripts/webhooks-schema.mjs +5 -0
- package/web/dist/assets/23I4SOAX-B4MCXPfc.js +2 -0
- package/web/dist/assets/26H2HVXD-DnN7AaEY.js +2 -0
- package/web/dist/assets/2IZ5MNOH-CgfSuFFL.js +1 -0
- package/web/dist/assets/2P3CZEXH-kInGrvHu.js +2 -0
- package/web/dist/assets/3E5HRNYT-DLbBxF6y.js +5 -0
- package/web/dist/assets/3JIRLDUO-B9tVJ8E_.js +1 -0
- package/web/dist/assets/5MJ3UKSG-nDfsJSF7.js +2 -0
- package/web/dist/assets/5THPTBWS-Ce_hS451.js +1 -0
- package/web/dist/assets/7OAKGN26-t-mlpHkx.js +25 -0
- package/web/dist/assets/7WLXJQOR-D6QVYUu9.js +1 -0
- package/web/dist/assets/A255FCTW-Bx0Z-P1v.js +1 -0
- package/web/dist/assets/AM43MQ64-C_UmP8Ka.js +2 -0
- package/web/dist/assets/AOZTNTMC-Di2iVwCo.js +5 -0
- package/web/dist/assets/AQNLM6KG-CcWg0kGq.js +4 -0
- package/web/dist/assets/BNU2RHQB-M1l5nkNs.js +2 -0
- package/web/dist/assets/C5HTQT3I-B50g1XeK.js +4 -0
- package/web/dist/assets/CPKRWH5G-DHdVktma.js +12 -0
- package/web/dist/assets/CUVCMPQX-75g4RQep.js +1 -0
- package/web/dist/assets/D4V2MWCI-Bm34L6wL.js +1 -0
- package/web/dist/assets/DHKBVIA3-Db-JqVOb.js +1 -0
- package/web/dist/assets/DKTLEL5E-DciMwFJ1.js +1 -0
- package/web/dist/assets/DUZNPW7S-4AKJemkg.js +2 -0
- package/web/dist/assets/E3FWOBN4-AT8jzYgb.js +4 -0
- package/web/dist/assets/E65FQMJL-eiWd8F8c.js +1 -0
- package/web/dist/assets/FTXIJQGB-CggtIYAM.js +1 -0
- package/web/dist/assets/G3MDBVQH-BZmnMkFw.js +1 -0
- package/web/dist/assets/G3OATVW2-D5zJu3ib.js +8 -0
- package/web/dist/assets/GUJTEFZK-DPEFMf5Q.js +1 -0
- package/web/dist/assets/IHVFDU4A-pP0Mb5Iu.js +10 -0
- package/web/dist/assets/IV52FOAS-jWHN2JLM.js +5 -0
- package/web/dist/assets/JTJEEBDN-DZeTEWqk.js +2 -0
- package/web/dist/assets/K7FUICZ3-C9JebvoP.js +2 -0
- package/web/dist/assets/LHH2HHRB-DZSZGD4x.js +2 -0
- package/web/dist/assets/MSPQPZZY-DOCBMJ70.js +4 -0
- package/web/dist/assets/OB6ZFVKF-D6V5f56z.js +2 -0
- package/web/dist/assets/PLTZDMI2-DltbYIQQ.js +1 -0
- package/web/dist/assets/R7EPXMMD-Dk_RDmvY.js +5 -0
- package/web/dist/assets/RVARI57O-CgA1WoRv.js +1 -0
- package/web/dist/assets/SPBWZ4VS-8FnOEPzw.js +1 -0
- package/web/dist/assets/SR7OOV3Q-3uZPNU1G.js +4 -0
- package/web/dist/assets/STAXBNH4-C4N6ZLTR.js +2 -0
- package/web/dist/assets/SXFARSFO-DHdVQB4G.js +1 -0
- package/web/dist/assets/TC77ISAL-BgUbI3Of.js +2 -0
- package/web/dist/assets/TYIQQHVC-S2gy0AUp.js +13 -0
- package/web/dist/assets/TZUXETIT-C6qyTEYa.js +2 -0
- package/web/dist/assets/U7N72BGE-8vTdAst9.js +6 -0
- package/web/dist/assets/UFPIB6EZ-BVjLTP07.js +3 -0
- package/web/dist/assets/UO52YEYL-EHYBNpY5.js +3 -0
- package/web/dist/assets/VIK3ONSK-Cton0Rgg.js +2 -0
- package/web/dist/assets/VVVO4ZVP-CdFWI9EE.js +2 -0
- package/web/dist/assets/WRGXZO53-DYQ4OW92.js +3 -0
- package/web/dist/assets/X5SG7MGC-DtC_vaXe.js +2 -0
- package/web/dist/assets/XLHPVVFU-MQkW7HpM.js +2 -0
- package/web/dist/assets/XXYPNCD5-Ib-xj97c.js +5 -0
- package/web/dist/assets/Z6WRYFJC-C6TE3q4J.js +7 -0
- package/web/dist/assets/ZI2QNEGF-DwOKsV8B.js +8 -0
- package/web/dist/assets/{agent-task-pickers-CJAx53eR.js → agent-task-pickers-C_2o0KYX.js} +1 -1
- package/web/dist/assets/{alert-dialog-BugYooRk.js → alert-dialog-fzSWCIyG.js} +1 -1
- package/web/dist/assets/arrow-left-CpV00riO.js +1 -0
- package/web/dist/assets/{automation-format-Bxe-TVRX.js → automation-format-BgAhuFNq.js} +1 -1
- package/web/dist/assets/automations-route-Ca648Wyc.js +1 -0
- package/web/dist/assets/bundle-mjs-rHxsej31.js +1 -0
- package/web/dist/assets/button-vdGgKu1b.js +100 -0
- package/web/dist/assets/{centered-state-Cm8_dS47.js → centered-state-C1nDqaTs.js} +1 -1
- package/web/dist/assets/check-DA3yaTey.js +1 -0
- package/web/dist/assets/chevron-left-D1eW2pzs.js +1 -0
- package/web/dist/assets/chevron-right-DwqBinJp.js +1 -0
- package/web/dist/assets/{chunk-BO2N2NFS-CFvlB0rH.js → chunk-BO2N2NFS-Bde6epwZ.js} +4 -4
- package/web/dist/assets/circle-check-G0BDdNX3.js +1 -0
- package/web/dist/assets/clipboard-B9AGRj3s.js +1 -0
- package/web/dist/assets/{collapsible-BoDLSmkP.js → collapsible-Ci-k9Y0m.js} +1 -1
- package/web/dist/assets/{commit-list-C_l41PzR.js → commit-list-B8qutNJ9.js} +1 -1
- package/web/dist/assets/{compare-variants-Du6vJ7FF.js → compare-variants-CD-H9QV0.js} +1 -1
- package/web/dist/assets/dashboard-BuNIEyIc.js +44 -0
- package/web/dist/assets/diff-DdDwJ41q.js +3 -0
- package/web/dist/assets/{diff-view-D7b6T1ik.js → diff-view-D4eUaNtD.js} +4 -4
- package/web/dist/assets/{download-CHsOA7RH.js → download-C9cyRK4D.js} +1 -1
- package/web/dist/assets/facet-filter-BpaMiUU2.js +5 -0
- package/web/dist/assets/{file-Bu00nVUj.js → file-CcDDcqzK.js} +1 -1
- package/web/dist/assets/file-preview-DyqTWb0f.js +2 -0
- package/web/dist/assets/{file-text-CISqp5LY.js → file-text-C5N0APxx.js} +1 -1
- package/web/dist/assets/{git-pull-request-draft-D2Lm-pPz.js → git-pull-request-draft-Bqwhflhv.js} +1 -1
- package/web/dist/assets/git-tab-loading-BXSixY5p.js +1 -0
- package/web/dist/assets/git-toolbar-CB3F5Ztu.js +1 -0
- package/web/dist/assets/github-CjHl4MMe.js +1 -0
- package/web/dist/assets/{highlighted-body-OFNGDK62-CDHv8VkT.js → highlighted-body-OFNGDK62-k8gmH63p.js} +1 -1
- package/web/dist/assets/{host-usage-CRNpjHr0.js → host-usage-EIcPz8s9.js} +1 -1
- package/web/dist/assets/{icon-tooltip-BrV8FoZY.js → icon-tooltip-CCXhXgac.js} +1 -1
- package/web/dist/assets/index-C_k6g6fh.js +29 -0
- package/web/dist/assets/index-DvagaaKL.css +2 -0
- package/web/dist/assets/{input-6sILF4ZL.js → input-DXFchFdf.js} +1 -1
- package/web/dist/assets/layout-cards-DrC84hQa.js +1 -0
- package/web/dist/assets/lazy-DaFjwB-q.js +11 -0
- package/web/dist/assets/lib-xgA2N1t8.js +1 -0
- package/web/dist/assets/loader-circle-B2Lhi0xN.js +1 -0
- package/web/dist/assets/{markdown-DDUUmNxl.js → markdown-3VbTQcD0.js} +1 -1
- package/web/dist/assets/markdown-DxPHdOwB.js +4 -0
- package/web/dist/assets/mermaid-GHXKKRXX-CQo8vsdt.js +1 -0
- package/web/dist/assets/{message-square-CUcOsOeK.js → message-square-9JNzSy42.js} +1 -1
- package/web/dist/assets/plus-BHSN5Uog.js +1 -0
- package/web/dist/assets/preload-helper-Czpn1I53.js +1 -0
- package/web/dist/assets/{project-router-Uv5K_t7U.js → project-router-BzcW5R3O.js} +2 -2
- package/web/dist/assets/queries-XYjXpa8s.js +1 -0
- package/web/dist/assets/reference-chip-JX3G6Wkk.js +1 -0
- package/web/dist/assets/repo-git-CZTtXETi.js +1 -0
- package/web/dist/assets/{run-diff-CaQSFkcv.js → run-diff-C_s9tHfS.js} +2 -2
- package/web/dist/assets/{save-D8UGIAXq.js → save-B4O7rFCS.js} +1 -1
- package/web/dist/assets/{scroll-within-CEDDAUiO.js → scroll-within-DTBX-TR6.js} +1 -1
- package/web/dist/assets/{search-x-CG0S6SUu.js → search-x-CQPbQgV6.js} +1 -1
- package/web/dist/assets/{settings-2-ogt1zu3P.js → settings-2-CrmZbb_8.js} +1 -1
- package/web/dist/assets/skills-DXkSdyb8.js +1 -0
- package/web/dist/assets/{square-VAdlYQJn.js → square-DCg6avOT.js} +1 -1
- package/web/dist/assets/{tabs-BP29AtfS.js → tabs-Cb8MmIEQ.js} +1 -1
- package/web/dist/assets/{tag-4juVmU06.js → tag-CEWhwfVf.js} +1 -1
- package/web/dist/assets/task-commits-BruCWCkF.js +1 -0
- package/web/dist/assets/{task-graph-4GzVwwdu.js → task-graph-D_OLXJSk.js} +1 -1
- package/web/dist/assets/{task-notes-CCT7q8Fr.js → task-notes-DzOdZjqZ.js} +1 -1
- package/web/dist/assets/task-workspace-C5Conyc1.js +29 -0
- package/web/dist/assets/{terminal-DEjD4n5K.js → terminal-BVAfyHZI.js} +1 -1
- package/web/dist/assets/terminal-drawer-Dcg67RS8.js +3 -0
- package/web/dist/assets/{textarea-DJjpA11v.js → textarea-DywMDkfl.js} +1 -1
- package/web/dist/assets/{token-metrics-BJ1naBNS.js → token-metrics-BiFl2ovY.js} +1 -1
- package/web/dist/assets/{tooltip-BieGyrAz.js → tooltip-7suUQClM.js} +1 -1
- package/web/dist/assets/{tracker-DitRxloO.js → tracker-BFYcbTEV.js} +2 -2
- package/web/dist/assets/{triangle-alert-lwmk_SnN.js → triangle-alert-hMpQrXJS.js} +1 -1
- package/web/dist/assets/{upload-Dx8IzFX_.js → upload-Ddh5Fb-A.js} +1 -1
- package/web/dist/assets/use-now-BlhSvP80.js +1 -0
- package/web/dist/assets/{use-submit-shortcut-B-uDwQhP.js → use-submit-shortcut-BC7gmgDS.js} +1 -1
- package/web/dist/assets/workflow-graph-BljUjNdF.js +13 -0
- package/web/dist/assets/worktree-lifecycle-operation-psNUwGwT.js +18 -0
- package/web/dist/index.html +41 -41
- package/web/dist/assets/arrow-left-FG-BtI91.js +0 -1
- package/web/dist/assets/automations-route-BRN9qRg1.js +0 -1
- package/web/dist/assets/bundle-mjs-BT31bpU6.js +0 -1
- package/web/dist/assets/button-DFlig-3W.js +0 -100
- package/web/dist/assets/check-Bg7-Ecuy.js +0 -1
- package/web/dist/assets/chevron-left-Cd_qkrfl.js +0 -1
- package/web/dist/assets/chevron-right-7BUoNLSN.js +0 -1
- package/web/dist/assets/circle-check-D3dWBsEI.js +0 -1
- package/web/dist/assets/dashboard-BDtFQg4f.js +0 -44
- package/web/dist/assets/diff-DZjcij_W.js +0 -3
- package/web/dist/assets/diff-stat-BIAV32IP.js +0 -1
- package/web/dist/assets/facet-filter-BCQvQXmA.js +0 -5
- package/web/dist/assets/file-preview-B0UXYkxB.js +0 -2
- package/web/dist/assets/git-tab-loading-Dcf8fCoC.js +0 -1
- package/web/dist/assets/git-toolbar-aXyXLu2P.js +0 -1
- package/web/dist/assets/github-PjL79xgT.js +0 -1
- package/web/dist/assets/index-DvwYGTi3.css +0 -2
- package/web/dist/assets/index-DxwI2MZD.js +0 -25
- package/web/dist/assets/layout-cards-Det2whh-.js +0 -1
- package/web/dist/assets/lib-BQXq3kEf.js +0 -1
- package/web/dist/assets/loader-circle-DDkRpp8X.js +0 -1
- package/web/dist/assets/markdown-lc7gwiQQ.js +0 -4
- package/web/dist/assets/mermaid-GHXKKRXX-CbLTa2tM.js +0 -1
- package/web/dist/assets/plus-BqHBcC4w.js +0 -1
- package/web/dist/assets/queries-C09jaXiS.js +0 -1
- package/web/dist/assets/reference-chip-CHF-Sbml.js +0 -1
- package/web/dist/assets/repo-git-DT0rQqvz.js +0 -1
- package/web/dist/assets/skills-Cf8xEPei.js +0 -1
- package/web/dist/assets/task-commits-CyO2Q8jS.js +0 -1
- package/web/dist/assets/task-workspace-C6o0DzgB.js +0 -29
- package/web/dist/assets/terminal-drawer-TV4K7S4u.js +0 -3
- package/web/dist/assets/use-now-Cr9QvR5I.js +0 -1
- package/web/dist/assets/workflow-graph-g3f0xPwZ.js +0 -13
- package/web/dist/assets/worktree-lifecycle-operation-COUqhS7A.js +0 -18
- package/web/dist/assets/x-BrRT8S7Q.js +0 -1
package/dist/workflows/run.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { completionReason } from './completion-reason.js';
|
|
1
2
|
import { WorktreeLifecycleCoordinator } from '../worktree-lifecycle/coordinator.js';
|
|
2
3
|
import { saveUsageWindows } from '../workspace/usage-windows.js';
|
|
3
4
|
import { probeCodexIdentity } from '../core/codex-usage-probe.js';
|
|
@@ -15,12 +16,16 @@ import { loadPrivateMcp, PRIVATE_MCP_FILE, skippedServersNote, supportsPrivateMc
|
|
|
15
16
|
import { onUsage, registerRunProcess, unregisterRunProcess } from '../core/process-usage.js';
|
|
16
17
|
import { describeReaped, reapTaskProcesses, taskProcessReapEnabled } from '../core/task-processes.js';
|
|
17
18
|
import { parseUsageLimit } from '../core/usage-limit.js';
|
|
19
|
+
import { diskFullAgentErrorText } from '../disk-space.js';
|
|
20
|
+
import { accountStateHint, classifyAgentFailure, MAX_TRANSIENT_RETRIES, transientRetryDelayMs } from '../core/agent-failure-class.js';
|
|
21
|
+
import { reportAgentError } from '../runs/agent-error-telemetry.js';
|
|
18
22
|
import { createRunner } from '../core/runner-factory.js';
|
|
19
23
|
import { modelConflictsWithRunner, modelNativeToRunner } from '../core/model-presets.js';
|
|
20
24
|
import { AGENT_MODELS_LOCKED_ERROR, agentModelsLocked } from '../core/agent-model-policy.js';
|
|
21
25
|
import { ModelIdentityError, formatModelIdentity, normalizeModelForBackend, } from '../core/model-identity.js';
|
|
22
26
|
import { HANDOFF_ONLY_INSTRUCTIONS, HANDOFF_INSTRUCTIONS, appendHandoffHeartbeat, followupsEnabled, handoffPath, readHandoff, seedHandoffFile, } from '../handoff.js';
|
|
23
27
|
import { todosPath } from '../todos.js';
|
|
28
|
+
import { continuePromptRefusal, messageText, queuedStackRefusal } from './queued-bounds.js';
|
|
24
29
|
// Contract VALUES, like `workspaceUiStateSchema` in workspace/migrations.ts: the attachment
|
|
25
30
|
// vocabulary the routes validate with is the same one the engine stores and re-reads by, so the
|
|
26
31
|
// wire and the disk can never disagree about what counts as an image (#950).
|
|
@@ -54,9 +59,10 @@ import { autoNamingActive, generateRunName, liveTitleUpdatesEnabled, NAMER_TIMEO
|
|
|
54
59
|
import { reviewGateEnabled } from '../runs/review-gate.js';
|
|
55
60
|
import { resolveProfileEnvForRoot } from '../workspace/agent-profiles.js';
|
|
56
61
|
import { DEFAULT_AGENT_ACCOUNT_ID } from '../workspace/agent-accounts.js';
|
|
62
|
+
import { DEFAULT_IDLE_TIMEOUT_MINUTES } from '../workspace/config.js';
|
|
57
63
|
import { WorkspaceSemaphore } from '../workspace/semaphore.js';
|
|
58
64
|
import { SecretStore } from '../workspace/secrets.js';
|
|
59
|
-
import { PROJECT_ID_RE } from '../workspace/config.js';
|
|
65
|
+
import { PROJECT_ID_RE, loadWorkspaceConfig } from '../workspace/config.js';
|
|
60
66
|
import { prunePrHeadRefs } from '../automations/pr-head.js';
|
|
61
67
|
import { MIN_SECRET_LEN } from '../core/secret-redaction.js';
|
|
62
68
|
import { track } from '../telemetry.js';
|
|
@@ -107,8 +113,12 @@ async function configuredModelProvider(backend, repoRoot) {
|
|
|
107
113
|
}
|
|
108
114
|
/** Maximum time a live provider gets to honor cancellation before its slot is reaped. */
|
|
109
115
|
const CANCEL_GRACE_MS = 1_000;
|
|
116
|
+
/** Fallback monitoring window when the waiting-session idle timeout is disabled. */
|
|
117
|
+
export const MONITORING_LIVENESS_MS = 4 * DEFAULT_IDLE_TIMEOUT_MINUTES * 60_000;
|
|
110
118
|
/** How long a settled task's agent CLI gets to exit on its own before its leftovers are reaped (#1411). */
|
|
111
119
|
const LEFTOVER_SETTLE_GRACE_MS = 5_000;
|
|
120
|
+
/** `runs/<id><suffix>` holds how many messages `deferMessage` is holding for that run. */
|
|
121
|
+
const DEFERRED_MARKER_SUFFIX = '.deferred-messages';
|
|
112
122
|
/** How long a fork waits for the namer's branch (spec 2026-10-11-branch-naming-instructions).
|
|
113
123
|
* On an idle cockpit a task starts the instant it is created, so the wait begins together with
|
|
114
124
|
* the namer call — and a cold `claude -p` alone takes more than five seconds (run 269606ac
|
|
@@ -475,6 +485,16 @@ function deferredBindingActive(run, runs) {
|
|
|
475
485
|
return true;
|
|
476
486
|
}
|
|
477
487
|
const AUTO_RESUME_PROMPT = 'The provider usage limit that interrupted this task has reset. Read the handoff file (CEZ_HANDOFF_FILE) to recover context, then continue the task from where you left off.';
|
|
488
|
+
const TRANSIENT_RETRY_PROMPT = 'Your previous turn stopped on a temporary provider error (overloaded, unreachable or a login refresh race), not on anything in the task. Read the handoff file (CEZ_HANDOFF_FILE) to recover context, then continue the task from where you left off.';
|
|
489
|
+
/** Which automatic resume a failure earns: a usage limit's reset window or a transient retry. */
|
|
490
|
+
function autoResumeReasonFor(error) {
|
|
491
|
+
if (parseUsageLimit(error))
|
|
492
|
+
return 'usage_limit';
|
|
493
|
+
return classifyAgentFailure(error) === 'transient' ? 'transient' : undefined;
|
|
494
|
+
}
|
|
495
|
+
function autoResumeCap(reason) {
|
|
496
|
+
return reason === 'transient' ? MAX_TRANSIENT_RETRIES : MAX_AUTO_RESUMES;
|
|
497
|
+
}
|
|
478
498
|
/**
|
|
479
499
|
* The wake instant as a human reads it — local, to the SECOND, with the zone named. The
|
|
480
500
|
* transcript line is what someone scanning a stalled task actually reads, and "18:41" is not
|
|
@@ -489,13 +509,24 @@ function formatWakeInstant(at) {
|
|
|
489
509
|
* The effective "extra" system prompt for a run (spec §protocol v2, R2 2.3):
|
|
490
510
|
* the per-run override (`POST /api/runs` `systemPrompt`) REPLACES the
|
|
491
511
|
* `config.json` default — they are the same knob at two scopes, so the more
|
|
492
|
-
* specific one wins outright; they never concatenate.
|
|
493
|
-
*
|
|
494
|
-
* along
|
|
512
|
+
* specific one wins outright; they never concatenate. The global instructions
|
|
513
|
+
* (`~/.cezar/config.json` `systemPrompt`) are a different knob: they always
|
|
514
|
+
* ride along, placed FIRST and labelled as yielding to the project's. Whichever
|
|
515
|
+
* wins is ADDITIVE to the skill body and the handoff contract (see
|
|
516
|
+
* `composeSystemPrompt`). Blank strings count as unset.
|
|
495
517
|
*/
|
|
496
|
-
export function resolveExtraSystemPrompt(override, configDefault) {
|
|
497
|
-
|
|
518
|
+
export function resolveExtraSystemPrompt(override, configDefault, globalDefault) {
|
|
519
|
+
const project = override?.trim() || configDefault?.trim() || undefined;
|
|
520
|
+
const global = globalDefault?.trim() || undefined;
|
|
521
|
+
if (!global || !project)
|
|
522
|
+
return project ?? global;
|
|
523
|
+
return [
|
|
524
|
+
`${GLOBAL_INSTRUCTIONS_HEADING}\n\n${global}`,
|
|
525
|
+
`${PROJECT_INSTRUCTIONS_HEADING}\n\n${project}`,
|
|
526
|
+
].join('\n\n---\n\n');
|
|
498
527
|
}
|
|
528
|
+
export const GLOBAL_INSTRUCTIONS_HEADING = '## Global instructions\n\nThese apply to every project. Where they conflict with the project instructions below, the project instructions win.';
|
|
529
|
+
export const PROJECT_INSTRUCTIONS_HEADING = '## Project instructions\n\nThese are specific to this project and take precedence over the global instructions above.';
|
|
499
530
|
/**
|
|
500
531
|
* Joins the parts of one agent step's system prompt in fixed order — skill
|
|
501
532
|
* body (most task-specific), then the run's extra prompt (user guidance, can
|
|
@@ -516,13 +547,14 @@ export function composeSystemPrompt(...parts) {
|
|
|
516
547
|
*
|
|
517
548
|
* De-duplicated against the run's extra system prompt, and that is not a micro-optimisation:
|
|
518
549
|
* `dispatch()` seeds a child's extra prompt with the very same text, so composing both would
|
|
519
|
-
* hand the backend the same instructions twice.
|
|
550
|
+
* hand the backend the same instructions twice. Containment, not equality: with global
|
|
551
|
+
* instructions set, `resolveExtraSystemPrompt` wraps that seed under its own heading.
|
|
520
552
|
*/
|
|
521
553
|
export function dispatchPromptPart(prompt, extra) {
|
|
522
554
|
const part = prompt?.trim();
|
|
523
555
|
if (!part)
|
|
524
556
|
return undefined;
|
|
525
|
-
return
|
|
557
|
+
return extra?.includes(part) ? undefined : part;
|
|
526
558
|
}
|
|
527
559
|
/**
|
|
528
560
|
* The directories a spawned agent may reach outside its worktree: the run-state
|
|
@@ -919,6 +951,7 @@ export class RunManager {
|
|
|
919
951
|
for (const [runId, state] of this.active) {
|
|
920
952
|
this.clearIdleTimer(state);
|
|
921
953
|
this.clearMonitoringWakeTimer(state, runId);
|
|
954
|
+
this.clearMonitoringLivenessTimer(state);
|
|
922
955
|
this.clearAutosaveTimer(state);
|
|
923
956
|
// Project disposal deliberately leaves providers alive. Their directory lease must
|
|
924
957
|
// survive the manager too, until the actual provider result confirms its exit.
|
|
@@ -1327,17 +1360,24 @@ export class RunManager {
|
|
|
1327
1360
|
this.unitParents.add(runId);
|
|
1328
1361
|
else
|
|
1329
1362
|
this.unitParents.delete(runId);
|
|
1363
|
+
const state = this.active.get(runId);
|
|
1364
|
+
if (state)
|
|
1365
|
+
this.armMonitoringLivenessTimer(runId, state);
|
|
1330
1366
|
}
|
|
1331
1367
|
/**
|
|
1332
1368
|
* Leave the monitoring set — the ONE exit, and every transition out of the state goes through
|
|
1333
1369
|
* it: a child's report or a user message (`deliverMessage`), the next turn ending in anything
|
|
1334
|
-
* but a park, a native `ask.requested`, the session's own teardown,
|
|
1335
|
-
* settle, restart recovery)
|
|
1336
|
-
*
|
|
1370
|
+
* but a park, a native `ask.requested`, the session's own teardown, `dropActive` (cancel,
|
|
1371
|
+
* settle, restart recovery), and `parkMonitorAsWaiting` (the wake-up cap and the liveness
|
|
1372
|
+
* timer). An ordinary wake-up is deliberately NOT one: its nudge is delivered into the same
|
|
1373
|
+
* parked session and the turn it starts ends back here.
|
|
1337
1374
|
*/
|
|
1338
1375
|
leaveMonitoring(runId) {
|
|
1339
1376
|
this.monitoring.delete(runId);
|
|
1340
1377
|
this.unitParents.delete(runId);
|
|
1378
|
+
const state = this.active.get(runId);
|
|
1379
|
+
if (state)
|
|
1380
|
+
this.clearMonitoringLivenessTimer(state);
|
|
1341
1381
|
}
|
|
1342
1382
|
/** Epoch ms of this manager's oldest queued run (the semaphore's fairness
|
|
1343
1383
|
* key when a freed slot is broadcast), or null when nothing is queued.
|
|
@@ -1575,25 +1615,7 @@ export class RunManager {
|
|
|
1575
1615
|
// Folded through the same helper `pump()` uses (#472) so a restart carries the stack.
|
|
1576
1616
|
// Idempotent: hydration always composes from `run.task` + the stack, never from an
|
|
1577
1617
|
// already-folded `input.task`, so re-hydrating at dequeue yields the same string.
|
|
1578
|
-
input: this.
|
|
1579
|
-
task: run.task,
|
|
1580
|
-
model: run.model,
|
|
1581
|
-
runner: run.runner,
|
|
1582
|
-
generateFollowups,
|
|
1583
|
-
// Re-thread autonomy (#489): the rebuilt input feeds `execute`, whose mid-run auto-nudge
|
|
1584
|
-
// reads `input.autonomous`. Without this a recovered autonomous run would run
|
|
1585
|
-
// non-autonomously and later wrongly park at `review`.
|
|
1586
|
-
autonomous: run.autonomous,
|
|
1587
|
-
// Re-thread the dispatch the same way and for the same reason (spec
|
|
1588
|
-
// 2026-09-10-dispatch A11): this is the one engine path that rebuilds a StartRunInput
|
|
1589
|
-
// from the record instead of going through `startRun`, so a dispatched run recovered after
|
|
1590
|
-
// a restart would otherwise resume as an ordinary flat task — no tree, no
|
|
1591
|
-
// parent to report to.
|
|
1592
|
-
dispatch: run.dispatch,
|
|
1593
|
-
// Preserve an explicit worktree opt-out across a queued restart.
|
|
1594
|
-
worktree: run.worktree,
|
|
1595
|
-
...(run.readOnly ? { readOnly: true } : {}),
|
|
1596
|
-
}),
|
|
1618
|
+
input: { ...this.workflowInput(run), ...(this.queuedUsageLimitResume(run) ? { usageLimitResume: true } : {}) },
|
|
1597
1619
|
});
|
|
1598
1620
|
this.queue.push(run.id);
|
|
1599
1621
|
this.store.appendEvent(run.id, { type: 'lifecycle', message: `${reason} — task re-queued` });
|
|
@@ -1605,15 +1627,16 @@ export class RunManager {
|
|
|
1605
1627
|
* workflowDef (or the catalog by name for older records);
|
|
1606
1628
|
* - `waiting` → the turn was over and the ball was in the user's court —
|
|
1607
1629
|
* settle exactly like a closed session (review/done, Continue still works),
|
|
1608
|
-
* unless `askParked
|
|
1609
|
-
* which settles `failed` instead so unrun steps are not
|
|
1610
|
-
* with `awaitingAnswerSince` so the task still reads as "needs you";
|
|
1630
|
+
* unless `askParked`, native `attentionRequest`, or an unfinished monitor
|
|
1631
|
+
* records pending work, which settles `failed` instead so unrun steps are not
|
|
1632
|
+
* reported as done, with `awaitingAnswerSince` so the task still reads as "needs you";
|
|
1611
1633
|
* - `running` → mark interrupted, then immediately resume the last agent
|
|
1612
1634
|
* session via the Continue path, pointing the agent at its handoff file.
|
|
1613
1635
|
* Call once, before the server starts taking requests.
|
|
1614
1636
|
*/
|
|
1615
1637
|
async recover() {
|
|
1616
1638
|
await this.lifecycle.reconcile();
|
|
1639
|
+
this.noteDeferredLostInRestart();
|
|
1617
1640
|
const live = this.store
|
|
1618
1641
|
.listRuns()
|
|
1619
1642
|
.filter((r) => ['queued', 'waiting', 'running'].includes(r.status))
|
|
@@ -1668,15 +1691,17 @@ export class RunManager {
|
|
|
1668
1691
|
// Two different parks wear this status. The final interactive step's
|
|
1669
1692
|
// session was open for follow-ups and the workflow had already run to
|
|
1670
1693
|
// its end, so settling it as a success is right. A mid-workflow park on
|
|
1671
|
-
// a `CEZ:ASK` (#917) had NOT run to its end
|
|
1672
|
-
// `pending
|
|
1694
|
+
// a `CEZ:ASK` (#917) or native backend question had NOT run to its end.
|
|
1695
|
+
// Later steps may still be `pending`, so the same settlement would report a workflow that
|
|
1673
1696
|
// stopped at its first question as a finished one. It ends the way any
|
|
1674
1697
|
// interrupted run ends instead: `failed`, with the Continue button that
|
|
1675
1698
|
// reopens the session so the question can still be answered. No
|
|
1676
1699
|
// automatic resume here, unlike the `running` branch below: the agent
|
|
1677
1700
|
// asked for a decision, and nudging it onward would be cezar making
|
|
1678
|
-
// that decision on the user's behalf.
|
|
1679
|
-
|
|
1701
|
+
// that decision on the user's behalf. A monitor handed to the user
|
|
1702
|
+
// (`parkMonitorAsWaiting`) carries the same marker for the same reason:
|
|
1703
|
+
// the agent said its work was still pending.
|
|
1704
|
+
if (run.askParked || run.attentionRequest) {
|
|
1680
1705
|
const interruptedAt = new Date().toISOString();
|
|
1681
1706
|
for (const step of run.steps) {
|
|
1682
1707
|
if (step.status === 'waiting' || step.status === 'running') {
|
|
@@ -1695,6 +1720,9 @@ export class RunManager {
|
|
|
1695
1720
|
type: 'lifecycle',
|
|
1696
1721
|
message: 'cezar restarted — the task was waiting for your answer; continue it to reply',
|
|
1697
1722
|
});
|
|
1723
|
+
// Same as the settled branch below: this terminal transition never passes through
|
|
1724
|
+
// `dropActive`, so a handed-off child still owes its parent a report.
|
|
1725
|
+
this.reportSettledChildToParent(run.id);
|
|
1698
1726
|
continue;
|
|
1699
1727
|
}
|
|
1700
1728
|
for (const step of run.steps) {
|
|
@@ -1804,6 +1832,7 @@ export class RunManager {
|
|
|
1804
1832
|
if (!this.cancelledStarting.delete(runId))
|
|
1805
1833
|
return false;
|
|
1806
1834
|
this.starting.delete(runId);
|
|
1835
|
+
this.redeliverDeferred(runId, 'the run was cancelled');
|
|
1807
1836
|
this.reportSettledChildToParent(runId);
|
|
1808
1837
|
this.releaseSlot();
|
|
1809
1838
|
return true;
|
|
@@ -1834,8 +1863,10 @@ export class RunManager {
|
|
|
1834
1863
|
// An in-place run's accept lands its changes (spec 2026-10-20-trunk-based-projects) — once
|
|
1835
1864
|
// the tree is released below, through the same path as Finish on a settled review.
|
|
1836
1865
|
const landOnAccept = acceptReview && this.store.getRun(runId)?.worktree === false;
|
|
1866
|
+
// Read before the registries below forget it: why a message deferred in this window must not resume the run.
|
|
1867
|
+
const stoppedBy = this.deferredStopReason(runId, state, !!acceptReview, !!queuedContinue);
|
|
1837
1868
|
if (acceptReview && !landOnAccept) {
|
|
1838
|
-
this.store.updateRun(runId, { status: 'done' });
|
|
1869
|
+
this.store.updateRun(runId, { status: 'done', completionReason: 'accepted' });
|
|
1839
1870
|
this.store.appendEvent(runId, { type: 'lifecycle', message: 'review accepted — finished without a PR' });
|
|
1840
1871
|
}
|
|
1841
1872
|
state?.releaseWorktree?.();
|
|
@@ -1899,6 +1930,125 @@ export class RunManager {
|
|
|
1899
1930
|
this.store.appendEvent(runId, { type: 'lifecycle', message: `continue could not start — ${resumed.error}` });
|
|
1900
1931
|
}
|
|
1901
1932
|
}
|
|
1933
|
+
// After `scheduleAutoResumeIfLimited`: a run parked for its usage window keeps that schedule.
|
|
1934
|
+
this.redeliverDeferred(runId, stoppedBy ?? (this.autoResumeTimers.has(runId) ? 'the task is waiting for its usage limit to reset' : undefined));
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* A drop that ends the run on purpose — cancel, an accepted review, Finish, a memory-limit pause
|
|
1938
|
+
* — must not be undone by a message deferred in its teardown window (`redeliverDeferred`).
|
|
1939
|
+
* Undefined for an ordinary settle, which the message resumes.
|
|
1940
|
+
*/
|
|
1941
|
+
deferredStopReason(runId, state, acceptReview, queuedContinue) {
|
|
1942
|
+
if (state?.cancelled)
|
|
1943
|
+
return 'the run was cancelled';
|
|
1944
|
+
if (acceptReview)
|
|
1945
|
+
return 'the review was accepted';
|
|
1946
|
+
// A Continue taken in the same window supersedes a Finish, and its session flushes the buffer.
|
|
1947
|
+
if ((state?.finishRequested || state?.finishedAtWait) && !queuedContinue)
|
|
1948
|
+
return 'the task was finished';
|
|
1949
|
+
if (this.memoryPausing.has(runId))
|
|
1950
|
+
return 'the task was paused for exceeding the memory limit';
|
|
1951
|
+
return undefined;
|
|
1952
|
+
}
|
|
1953
|
+
/**
|
|
1954
|
+
* Messages `deferMessage` accepted for a session that never opened again: the run settled
|
|
1955
|
+
* instead. Delivered the way the cockpit would have — stacked onto a re-queued prompt, else as
|
|
1956
|
+
* a Continue — so an accepted message is never silently lost (telemetry 1408d7cb). A `stoppedBy`
|
|
1957
|
+
* reason (the run was ended on purpose) or a message over the route's bounds is reported
|
|
1958
|
+
* undelivered instead.
|
|
1959
|
+
*/
|
|
1960
|
+
redeliverDeferred(runId, stoppedBy) {
|
|
1961
|
+
// A continuation already owns the run: its session's open flushes the buffer.
|
|
1962
|
+
if (this.active.has(runId) || this.starting.has(runId))
|
|
1963
|
+
return;
|
|
1964
|
+
const pending = this.deferredMessages.get(runId);
|
|
1965
|
+
this.setDeferred(runId, undefined);
|
|
1966
|
+
if (!pending?.length)
|
|
1967
|
+
return;
|
|
1968
|
+
const undelivered = (reason, count = pending.length) => {
|
|
1969
|
+
this.store.appendEvent(runId, {
|
|
1970
|
+
type: 'lifecycle',
|
|
1971
|
+
message: `${count === 1 ? 'a message' : `${count} messages`} sent while the session was closing could not be delivered — ${reason}`,
|
|
1972
|
+
});
|
|
1973
|
+
};
|
|
1974
|
+
if (stoppedBy)
|
|
1975
|
+
return undelivered(stoppedBy);
|
|
1976
|
+
if (this.isQueued(runId)) {
|
|
1977
|
+
for (const content of pending) {
|
|
1978
|
+
const run = this.store.getRun(runId);
|
|
1979
|
+
const refusal = run ? queuedStackRefusal(this.dataDir, run, content) : 'the task is gone';
|
|
1980
|
+
if (refusal || !this.enqueueMessage(runId, content))
|
|
1981
|
+
undelivered(refusal ?? 'the task already started', 1);
|
|
1982
|
+
}
|
|
1983
|
+
return;
|
|
1984
|
+
}
|
|
1985
|
+
const blocks = pending.flat();
|
|
1986
|
+
const text = pending.map(messageText).filter((t) => t.trim()).join('\n\n');
|
|
1987
|
+
const refusal = continuePromptRefusal(text, blocks);
|
|
1988
|
+
if (refusal)
|
|
1989
|
+
return undelivered(refusal);
|
|
1990
|
+
const resumed = this.continueRun(runId, { text, images: blocks.filter((b) => b.type !== 'text') });
|
|
1991
|
+
if (!resumed.ok)
|
|
1992
|
+
undelivered(resumed.error ?? 'continue could not start');
|
|
1993
|
+
}
|
|
1994
|
+
/**
|
|
1995
|
+
* The one writer of `deferredMessages`. A marker file mirrors how many are held, so a restart —
|
|
1996
|
+
* which loses the buffer itself — can still say so on the run (`noteDeferredLostInRestart`).
|
|
1997
|
+
*/
|
|
1998
|
+
setDeferred(runId, pending) {
|
|
1999
|
+
const marker = join(this.dataDir, 'runs', `${runId}${DEFERRED_MARKER_SUFFIX}`);
|
|
2000
|
+
if (pending?.length) {
|
|
2001
|
+
this.deferredMessages.set(runId, pending);
|
|
2002
|
+
try {
|
|
2003
|
+
mkdirSync(dirname(marker), { recursive: true });
|
|
2004
|
+
writeFileSync(marker, String(pending.length));
|
|
2005
|
+
}
|
|
2006
|
+
catch {
|
|
2007
|
+
// Best effort: the marker only explains a loss, it never decides a delivery.
|
|
2008
|
+
}
|
|
2009
|
+
return;
|
|
2010
|
+
}
|
|
2011
|
+
if (!this.deferredMessages.delete(runId))
|
|
2012
|
+
return;
|
|
2013
|
+
try {
|
|
2014
|
+
rmSync(marker, { force: true });
|
|
2015
|
+
}
|
|
2016
|
+
catch {
|
|
2017
|
+
// Best effort, like the write: a stale marker costs one spurious note after a restart.
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
/** Startup: messages a previous process held for a session that never reopened are gone. */
|
|
2021
|
+
noteDeferredLostInRestart() {
|
|
2022
|
+
let names;
|
|
2023
|
+
try {
|
|
2024
|
+
names = readdirSync(join(this.dataDir, 'runs')).filter((name) => name.endsWith(DEFERRED_MARKER_SUFFIX));
|
|
2025
|
+
}
|
|
2026
|
+
catch {
|
|
2027
|
+
return;
|
|
2028
|
+
}
|
|
2029
|
+
for (const name of names) {
|
|
2030
|
+
const runId = name.slice(0, -DEFERRED_MARKER_SUFFIX.length);
|
|
2031
|
+
const path = join(this.dataDir, 'runs', name);
|
|
2032
|
+
let count = 1;
|
|
2033
|
+
try {
|
|
2034
|
+
count = Math.max(1, Number.parseInt(readFileSync(path, 'utf8'), 10) || 1);
|
|
2035
|
+
}
|
|
2036
|
+
catch {
|
|
2037
|
+
// Unreadable: still one lost message at least.
|
|
2038
|
+
}
|
|
2039
|
+
if (this.store.getRun(runId)) {
|
|
2040
|
+
this.store.appendEvent(runId, {
|
|
2041
|
+
type: 'lifecycle',
|
|
2042
|
+
message: `${count === 1 ? 'a message' : `${count} messages`} sent while the session was closing could not be delivered — cezar restarted; send it again`,
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
try {
|
|
2046
|
+
rmSync(path, { force: true });
|
|
2047
|
+
}
|
|
2048
|
+
catch {
|
|
2049
|
+
// A read-only data dir must not fail recovery; the note repeats on the next boot at worst.
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
1902
2052
|
}
|
|
1903
2053
|
/** Is this run settled and not owned by a session again (a Continue inside the grace)? */
|
|
1904
2054
|
runSettled(runId) {
|
|
@@ -2132,9 +2282,10 @@ export class RunManager {
|
|
|
2132
2282
|
*/
|
|
2133
2283
|
recordAsk(runId, sink, ask) {
|
|
2134
2284
|
const requestId = emitAskRequested(sink, ask);
|
|
2285
|
+
const attention = this.recordAttention(requestId, ask.questions);
|
|
2135
2286
|
const dispatch = this.dispatchOf(runId);
|
|
2136
2287
|
if (!dispatch)
|
|
2137
|
-
return;
|
|
2288
|
+
return attention;
|
|
2138
2289
|
const questions = ask.questions.map((question) => question.question.slice(0, 400));
|
|
2139
2290
|
const recorded = questions.slice(0, PENDING_ASK_MAX_QUESTIONS);
|
|
2140
2291
|
const omittedQuestions = questions.length - recorded.length;
|
|
@@ -2144,11 +2295,11 @@ export class RunManager {
|
|
|
2144
2295
|
requestId,
|
|
2145
2296
|
questions: recorded,
|
|
2146
2297
|
...(omittedQuestions > 0 ? { omittedQuestions } : {}),
|
|
2147
|
-
askedAt:
|
|
2298
|
+
askedAt: attention.askedAt,
|
|
2148
2299
|
},
|
|
2149
2300
|
}));
|
|
2150
2301
|
if (!dispatch.parentRunId)
|
|
2151
|
-
return;
|
|
2302
|
+
return attention;
|
|
2152
2303
|
const run = this.store.getRun(runId);
|
|
2153
2304
|
try {
|
|
2154
2305
|
writeInboxMessage(this.dataDir, dispatch.rootRunId, inboxName(dispatch.parentRunId, dispatch.rootRunId), {
|
|
@@ -2167,6 +2318,18 @@ export class RunManager {
|
|
|
2167
2318
|
catch {
|
|
2168
2319
|
// best effort
|
|
2169
2320
|
}
|
|
2321
|
+
return attention;
|
|
2322
|
+
}
|
|
2323
|
+
/** Snapshot all attention sources; only explicit CEZ:ASK carries dispatch Guard semantics. */
|
|
2324
|
+
recordAttention(requestId, input) {
|
|
2325
|
+
const attention = {
|
|
2326
|
+
requestId, askedAt: new Date().toISOString(),
|
|
2327
|
+
questions: input.slice(0, 20).map(q => ({
|
|
2328
|
+
question: q.question.slice(0, 2000),
|
|
2329
|
+
...(q.options ? { options: q.options.slice(0, 10).map(o => ({ label: o.label.slice(0, 120), ...(o.description ? { description: o.description.slice(0, 500) } : {}) })) } : {}),
|
|
2330
|
+
})),
|
|
2331
|
+
};
|
|
2332
|
+
return attention;
|
|
2170
2333
|
}
|
|
2171
2334
|
/** The answer arrived (any message delivered into the session): the question is no longer pending. */
|
|
2172
2335
|
clearPendingAsk(runId) {
|
|
@@ -2394,8 +2557,10 @@ export class RunManager {
|
|
|
2394
2557
|
// question remains under the user's control (`awaitingAnswerSince`). That is a hold, not
|
|
2395
2558
|
// an outcome: reporting it now would make the parent plan around work that may still be
|
|
2396
2559
|
// resumed. The existing status transition that answers or explicitly retires the question
|
|
2397
|
-
// clears this field and reaches this hook again with the real outcome.
|
|
2398
|
-
|
|
2560
|
+
// clears this field and reaches this hook again with the real outcome. A monitor handed
|
|
2561
|
+
// to the user carries the same marker but no pending question: its work is unfinished
|
|
2562
|
+
// and nobody is waiting on an answer the parent could pre-empt, so it reports.
|
|
2563
|
+
if (child.awaitingAnswerSince !== undefined && child.dispatch?.pendingAsk)
|
|
2399
2564
|
return;
|
|
2400
2565
|
const parent = this.store.getRun(parentId);
|
|
2401
2566
|
if (!parent?.dispatch)
|
|
@@ -2448,12 +2613,6 @@ export class RunManager {
|
|
|
2448
2613
|
// parent is already cancelled — or about to be — and every live rung below would fight that.
|
|
2449
2614
|
if (child.status === 'cancelled')
|
|
2450
2615
|
return;
|
|
2451
|
-
const parentState = this.active.get(parentId);
|
|
2452
|
-
if (parentState)
|
|
2453
|
-
parentState.monitoringWakeups = 0;
|
|
2454
|
-
if (parent.monitoringWakeCapReached) {
|
|
2455
|
-
this.store.updateRun(parentId, { monitoringWakeCapReached: undefined });
|
|
2456
|
-
}
|
|
2457
2616
|
const blocks = [{ type: 'text', text }];
|
|
2458
2617
|
if (this.deliverMessage(parentId, blocks, false) || this.enqueueMessage(parentId, blocks)) {
|
|
2459
2618
|
this.ackPendingReport(parentId, child.id, at);
|
|
@@ -2502,6 +2661,59 @@ export class RunManager {
|
|
|
2502
2661
|
const run = this.store.getRun(runId);
|
|
2503
2662
|
if (!run || run.status !== 'failed')
|
|
2504
2663
|
return;
|
|
2664
|
+
const failure = classifyAgentFailure(run.error);
|
|
2665
|
+
if (failure === 'transient') {
|
|
2666
|
+
this.scheduleTransientRetry(run);
|
|
2667
|
+
return;
|
|
2668
|
+
}
|
|
2669
|
+
this.armUsageLimitResume(run);
|
|
2670
|
+
// Account and conversation state is the user's to fix: say how, instead of a bare failure.
|
|
2671
|
+
const hint = failure === 'disk_full'
|
|
2672
|
+
? diskFullAgentErrorText(run.error ?? '', run.worktreePath ?? this.repoRoot) ?? undefined
|
|
2673
|
+
: accountStateHint(failure, this.failedBackend(run), { resetKnown: parseUsageLimit(run.error) !== null });
|
|
2674
|
+
if (hint)
|
|
2675
|
+
this.store.appendEvent(runId, { type: 'lifecycle', message: hint });
|
|
2676
|
+
}
|
|
2677
|
+
/** The backend whose session failed — a per-step runner or a Continue override, else the run's. */
|
|
2678
|
+
failedBackend(run) {
|
|
2679
|
+
return [...run.steps].reverse().find((step) => step.status === 'failed' && step.backend)?.backend ?? run.runner;
|
|
2680
|
+
}
|
|
2681
|
+
/**
|
|
2682
|
+
* A transient provider failure (an overload, no response, the OAuth refresh race between two of
|
|
2683
|
+
* cezar's own Claude processes): resume the same session after a short backoff, at most
|
|
2684
|
+
* `MAX_TRANSIENT_RETRIES` times per streak, through the usage-limit resume's timer and exits.
|
|
2685
|
+
*/
|
|
2686
|
+
scheduleTransientRetry(run) {
|
|
2687
|
+
// Same refusals as a usage-limit resume: an archived task, the switch off, no session.
|
|
2688
|
+
if (run.archived || !this.semaphore.autoResumeOnUsageLimit() || !run.steps.some((step) => step.sessionId)) {
|
|
2689
|
+
this.reportUnretriedTransient(run, 'not_retried');
|
|
2690
|
+
return;
|
|
2691
|
+
}
|
|
2692
|
+
const attempts = run.autoResumeAttempts ?? 0;
|
|
2693
|
+
if (attempts >= MAX_TRANSIENT_RETRIES) {
|
|
2694
|
+
this.store.appendEvent(run.id, {
|
|
2695
|
+
type: 'note',
|
|
2696
|
+
message: `the provider is still failing after ${MAX_TRANSIENT_RETRIES} automatic retries — continue this task manually`,
|
|
2697
|
+
});
|
|
2698
|
+
this.reportUnretriedTransient(run, 'retries_exhausted');
|
|
2699
|
+
return;
|
|
2700
|
+
}
|
|
2701
|
+
const wakeAt = new Date(Date.now() + transientRetryDelayMs(attempts + 1, run.error));
|
|
2702
|
+
this.armAutoResume(run.id, wakeAt.getTime(), 'transient');
|
|
2703
|
+
this.store.appendEvent(run.id, {
|
|
2704
|
+
type: 'lifecycle',
|
|
2705
|
+
message: `temporary provider failure — retrying automatically at ${formatWakeInstant(wakeAt)} (${attempts + 1}/${MAX_TRANSIENT_RETRIES})`,
|
|
2706
|
+
});
|
|
2707
|
+
}
|
|
2708
|
+
/** A transient failure cezar will not retry carries signal again: report it as the agent error
|
|
2709
|
+
* `reportAgentError` held back when the event arrived. */
|
|
2710
|
+
reportUnretriedTransient(run, outcome) {
|
|
2711
|
+
if (!run.error)
|
|
2712
|
+
return;
|
|
2713
|
+
reportAgentError(this.failedBackend(run), { type: 'error', message: run.error }, { transientOutcome: outcome });
|
|
2714
|
+
}
|
|
2715
|
+
armUsageLimitResume(run) {
|
|
2716
|
+
const runId = run.id;
|
|
2505
2717
|
// Archiving IS resigning from a task. Reviving one because a window happened to reopen would
|
|
2506
2718
|
// be the feature working against the clearest signal the user can give it.
|
|
2507
2719
|
if (run.archived)
|
|
@@ -2523,15 +2735,15 @@ export class RunManager {
|
|
|
2523
2735
|
return;
|
|
2524
2736
|
}
|
|
2525
2737
|
const wakeAt = new Date(limit.resetAt.getTime() + AUTO_RESUME_GRACE_MS);
|
|
2526
|
-
this.armAutoResume(runId, wakeAt.getTime());
|
|
2738
|
+
this.armAutoResume(runId, wakeAt.getTime(), 'usage_limit');
|
|
2527
2739
|
this.store.appendEvent(runId, {
|
|
2528
2740
|
type: 'lifecycle',
|
|
2529
2741
|
message: `usage limit reached — resuming automatically at ${formatWakeInstant(wakeAt)}`,
|
|
2530
2742
|
});
|
|
2531
2743
|
}
|
|
2532
2744
|
/** Publish the deadline on the record (the cockpit's only source) and arm the timer for it. */
|
|
2533
|
-
armAutoResume(runId, deadline) {
|
|
2534
|
-
this.store.updateRun(runId, { autoResumeAt: new Date(deadline).toISOString() });
|
|
2745
|
+
armAutoResume(runId, deadline, reason) {
|
|
2746
|
+
this.store.updateRun(runId, { autoResumeAt: new Date(deadline).toISOString(), autoResumeReason: reason });
|
|
2535
2747
|
const timer = setTimeout(() => this.fireAutoResume(runId), Math.max(0, deadline - Date.now()));
|
|
2536
2748
|
timer.unref?.();
|
|
2537
2749
|
this.autoResumeTimers.set(runId, timer);
|
|
@@ -2539,7 +2751,7 @@ export class RunManager {
|
|
|
2539
2751
|
/**
|
|
2540
2752
|
* The window has reopened. Re-check the record synchronously — hours may have passed, and the
|
|
2541
2753
|
* user may have continued, deleted or cancelled the run in them — then hand the resume to the
|
|
2542
|
-
* ordinary
|
|
2754
|
+
* ordinary scheduler so it obeys both concurrency caps like any other work.
|
|
2543
2755
|
*/
|
|
2544
2756
|
fireAutoResume(runId) {
|
|
2545
2757
|
this.autoResumeTimers.delete(runId);
|
|
@@ -2553,9 +2765,29 @@ export class RunManager {
|
|
|
2553
2765
|
return;
|
|
2554
2766
|
}
|
|
2555
2767
|
const attempts = (run.autoResumeAttempts ?? 0) + 1;
|
|
2556
|
-
|
|
2557
|
-
//
|
|
2558
|
-
|
|
2768
|
+
const reason = run.autoResumeReason ?? 'usage_limit';
|
|
2769
|
+
// #1300: a workflow interruption must return to its executor after the resumed session.
|
|
2770
|
+
// The saved workflow and failed step/session already supply the recovery checkpoint,
|
|
2771
|
+
// including when the queued run is reconstructed after a restart.
|
|
2772
|
+
const workflowStep = this.interruptedWorkflowStep(run);
|
|
2773
|
+
let resumed;
|
|
2774
|
+
if (workflowStep && run.workflowDef) {
|
|
2775
|
+
this.clearAutoResume(runId);
|
|
2776
|
+
this.pendingJobs.set(runId, {
|
|
2777
|
+
workflow: run.workflowDef,
|
|
2778
|
+
input: { ...this.workflowInput(run), usageLimitResume: true },
|
|
2779
|
+
});
|
|
2780
|
+
this.queue.push(runId);
|
|
2781
|
+
this.store.updateRun(runId, {
|
|
2782
|
+
status: 'queued', error: undefined, finishedAt: undefined, currentStepId: undefined,
|
|
2783
|
+
});
|
|
2784
|
+
resumed = { ok: true };
|
|
2785
|
+
}
|
|
2786
|
+
else {
|
|
2787
|
+
// Legacy records without a recoverable definition and standalone continuations retain
|
|
2788
|
+
// their existing session recovery. Manual Continue also keeps its existing semantics.
|
|
2789
|
+
resumed = this.continueRun(runId, { text: reason === 'transient' ? TRANSIENT_RETRY_PROMPT : AUTO_RESUME_PROMPT }, true);
|
|
2790
|
+
}
|
|
2559
2791
|
if (!resumed.ok) {
|
|
2560
2792
|
// Refusals happen before `continueRun` retires anything, so the deadline is still on the
|
|
2561
2793
|
// record — and a deadline in the past is a promise the cockpit keeps displaying and the
|
|
@@ -2565,12 +2797,18 @@ export class RunManager {
|
|
|
2565
2797
|
type: 'note',
|
|
2566
2798
|
message: `automatic resume could not start — ${resumed.error ?? 'unknown'}`,
|
|
2567
2799
|
});
|
|
2800
|
+
if (reason === 'transient')
|
|
2801
|
+
this.reportUnretriedTransient(run, 'resume_refused');
|
|
2568
2802
|
return;
|
|
2569
2803
|
}
|
|
2570
|
-
|
|
2804
|
+
// `clearAutoResume` above retired the reason with the deadline; the resume in flight keeps it,
|
|
2805
|
+
// so `accountHolds` knows a transient retry holds no account.
|
|
2806
|
+
this.store.updateRun(runId, { autoResumeAttempts: attempts, autoResumeReason: reason });
|
|
2571
2807
|
this.store.appendEvent(runId, {
|
|
2572
2808
|
type: 'lifecycle',
|
|
2573
|
-
message:
|
|
2809
|
+
message: reason === 'transient'
|
|
2810
|
+
? `retrying after a temporary provider failure (${attempts}/${MAX_TRANSIENT_RETRIES})`
|
|
2811
|
+
: `usage limit reset — resuming automatically (${attempts}/${MAX_AUTO_RESUMES})`,
|
|
2574
2812
|
});
|
|
2575
2813
|
// A deferred continuation only ENQUEUES itself; the queue moves when something pumps it, and
|
|
2576
2814
|
// `recover()` — the other deferring caller — pumps once after its whole bulk sweep. A timer
|
|
@@ -2578,6 +2816,45 @@ export class RunManager {
|
|
|
2578
2816
|
// until some unrelated run happens to finish. This is the pump for it.
|
|
2579
2817
|
void this.pump();
|
|
2580
2818
|
}
|
|
2819
|
+
/** Recover the failed workflow agent from the existing durable step/session checkpoint. */
|
|
2820
|
+
interruptedWorkflowStep(run) {
|
|
2821
|
+
// Later steps can retain old session ids when a check loops back to an earlier agent.
|
|
2822
|
+
// Only the failed agent is the interruption; a pending retry is not a newer session.
|
|
2823
|
+
const step = [...run.steps].reverse().find((candidate) => candidate.kind === 'agent' && candidate.status === 'failed');
|
|
2824
|
+
if (!step?.sessionId || !autoResumeReasonFor(step.error))
|
|
2825
|
+
return undefined;
|
|
2826
|
+
return run.workflowDef?.steps.some((definition) => definition.id === step.id && stepKind(definition) === 'agent')
|
|
2827
|
+
? { ...step }
|
|
2828
|
+
: undefined;
|
|
2829
|
+
}
|
|
2830
|
+
/**
|
|
2831
|
+
* A queued run revived after a restart was an auto-resume `fireAutoResume` queued (#1300) when
|
|
2832
|
+
* its walk stopped on the interrupted agent. A walk parked at another node (a restart-resume
|
|
2833
|
+
* cursor) keeps that cursor — a failed agent behind a wired `failed` port must not hijack it.
|
|
2834
|
+
*/
|
|
2835
|
+
queuedUsageLimitResume(run) {
|
|
2836
|
+
const step = this.interruptedWorkflowStep(run);
|
|
2837
|
+
const cursor = run.graphState?.cursor;
|
|
2838
|
+
return step !== undefined && (cursor === undefined || cursor === step.id);
|
|
2839
|
+
}
|
|
2840
|
+
/** Rebuild executable input from the durable record, for auto-resume and queued recovery. */
|
|
2841
|
+
workflowInput(run) {
|
|
2842
|
+
return this.hydrateQueuedInput(run.id, {
|
|
2843
|
+
task: run.task,
|
|
2844
|
+
model: run.model,
|
|
2845
|
+
runner: run.runner,
|
|
2846
|
+
agentProfile: run.agentProfile,
|
|
2847
|
+
// No `systemPrompt`: the record keeps only the COMPOSED prompt, never the bare override, so
|
|
2848
|
+
// feeding it back would re-compose it; a usage-limit resume reuses it verbatim in `execute`.
|
|
2849
|
+
generateFollowups: followupsEnabled() ? run.generateFollowups : false,
|
|
2850
|
+
// Both lifecycle entry points must restore autonomy, dispatch, isolation and read-only
|
|
2851
|
+
// (#489, spec 2026-09-10-dispatch A11, #1597), as well as the task's account.
|
|
2852
|
+
autonomous: run.autonomous,
|
|
2853
|
+
dispatch: run.dispatch,
|
|
2854
|
+
worktree: run.worktree,
|
|
2855
|
+
...(run.readOnly ? { readOnly: true } : {}),
|
|
2856
|
+
});
|
|
2857
|
+
}
|
|
2581
2858
|
/**
|
|
2582
2859
|
* Make the armed timers agree with the records and the current setting. Runs on every `pump()`
|
|
2583
2860
|
* — which is where a settings change lands (a config PUT refreshes the shared semaphore, which
|
|
@@ -2626,7 +2903,7 @@ export class RunManager {
|
|
|
2626
2903
|
// that has just passed arms at zero — the window is open, which is the point.
|
|
2627
2904
|
if (run.archived
|
|
2628
2905
|
|| !Number.isFinite(deadline)
|
|
2629
|
-
|| (run.autoResumeAttempts ?? 0) >=
|
|
2906
|
+
|| (run.autoResumeAttempts ?? 0) >= autoResumeCap(run.autoResumeReason)) {
|
|
2630
2907
|
this.store.updateRun(run.id, { autoResumeAt: undefined });
|
|
2631
2908
|
continue;
|
|
2632
2909
|
}
|
|
@@ -2641,7 +2918,7 @@ export class RunManager {
|
|
|
2641
2918
|
});
|
|
2642
2919
|
continue;
|
|
2643
2920
|
}
|
|
2644
|
-
this.armAutoResume(run.id, deadline);
|
|
2921
|
+
this.armAutoResume(run.id, deadline, run.autoResumeReason ?? 'usage_limit');
|
|
2645
2922
|
}
|
|
2646
2923
|
}
|
|
2647
2924
|
/**
|
|
@@ -2675,7 +2952,11 @@ export class RunManager {
|
|
|
2675
2952
|
state.releaseRepoRoot = undefined;
|
|
2676
2953
|
this.pendingJobs.set(runId, { workflow, input });
|
|
2677
2954
|
this.queue.push(runId);
|
|
2678
|
-
this.store.updateRun(runId, {
|
|
2955
|
+
this.store.updateRun(runId, {
|
|
2956
|
+
status: 'queued',
|
|
2957
|
+
startedAt: input.usageLimitResume ? run.startedAt : undefined,
|
|
2958
|
+
currentStepId: undefined,
|
|
2959
|
+
});
|
|
2679
2960
|
this.store.appendEvent(runId, {
|
|
2680
2961
|
type: 'note',
|
|
2681
2962
|
message: 'held in the queue — this agent account is waiting out a usage limit',
|
|
@@ -2762,7 +3043,7 @@ export class RunManager {
|
|
|
2762
3043
|
* notification re-derives every participant's queue reasons, so only hold inputs notify (#1340). */
|
|
2763
3044
|
holdInputs = new Map();
|
|
2764
3045
|
onRunHoldInputs = (run) => {
|
|
2765
|
-
const inputs = JSON.stringify([run.status, run.autoResumeAt, run.autoResumeAttempts, run.runner, run.agentProfile]);
|
|
3046
|
+
const inputs = JSON.stringify([run.status, run.autoResumeAt, run.autoResumeAttempts, run.autoResumeReason, run.runner, run.agentProfile]);
|
|
2766
3047
|
if (this.holdInputs.get(run.id) === inputs)
|
|
2767
3048
|
return;
|
|
2768
3049
|
this.holdInputs.set(run.id, inputs);
|
|
@@ -2807,6 +3088,9 @@ export class RunManager {
|
|
|
2807
3088
|
// A holding run always carries the runner it actually ran on, so the fallback is unused
|
|
2808
3089
|
// here — it is spelled out rather than `!` so a future record shape degrades, not throws.
|
|
2809
3090
|
const key = () => runAccountKey(run, run.runner ?? 'claude');
|
|
3091
|
+
// A transient retry says nothing about the account's window, so it holds nothing.
|
|
3092
|
+
if (run.autoResumeReason === 'transient')
|
|
3093
|
+
continue;
|
|
2810
3094
|
if (run.status === 'failed' && run.autoResumeAt) {
|
|
2811
3095
|
const at = Date.parse(run.autoResumeAt);
|
|
2812
3096
|
if (Number.isFinite(at) && at > now) {
|
|
@@ -2855,8 +3139,8 @@ export class RunManager {
|
|
|
2855
3139
|
const run = this.store.getRun(runId);
|
|
2856
3140
|
if (!run)
|
|
2857
3141
|
return;
|
|
2858
|
-
if (run.autoResumeAt !== undefined || run.autoResumeAttempts !== undefined) {
|
|
2859
|
-
this.store.updateRun(runId, { autoResumeAt: undefined, autoResumeAttempts: undefined });
|
|
3142
|
+
if (run.autoResumeAt !== undefined || run.autoResumeAttempts !== undefined || run.autoResumeReason !== undefined) {
|
|
3143
|
+
this.store.updateRun(runId, { autoResumeAt: undefined, autoResumeAttempts: undefined, autoResumeReason: undefined });
|
|
2860
3144
|
}
|
|
2861
3145
|
}
|
|
2862
3146
|
/** Reclaim finished worktrees beyond the keep-limit (#483) — directory only,
|
|
@@ -3072,8 +3356,14 @@ export class RunManager {
|
|
|
3072
3356
|
if (!state) {
|
|
3073
3357
|
// Dequeued but not yet registered: a continuation awaits its lifecycle gate first (#1495).
|
|
3074
3358
|
// Refusing here let the run start right after the user cancelled it.
|
|
3075
|
-
if (!this.starting.has(runId))
|
|
3076
|
-
|
|
3359
|
+
if (!this.starting.has(runId)) {
|
|
3360
|
+
// A failed run with a resume booked is the one idle run Cancel still has work on: the
|
|
3361
|
+
// resume (a usage-limit wait or a transient retry), so it — and a cancelled parent — stops it.
|
|
3362
|
+
const run = this.store.getRun(runId);
|
|
3363
|
+
if (run?.status !== 'failed' || (run.autoResumeAt === undefined && !this.autoResumeTimers.has(runId)))
|
|
3364
|
+
return false;
|
|
3365
|
+
return this.cancelAutoResume(runId);
|
|
3366
|
+
}
|
|
3077
3367
|
this.cancelledStarting.add(runId);
|
|
3078
3368
|
this.store.updateRun(runId, { status: 'cancelled', finishedAt: new Date().toISOString(), currentStepId: undefined });
|
|
3079
3369
|
this.store.appendEvent(runId, { type: 'lifecycle', message: 'run cancelled' });
|
|
@@ -3122,6 +3412,10 @@ export class RunManager {
|
|
|
3122
3412
|
}
|
|
3123
3413
|
return true;
|
|
3124
3414
|
}
|
|
3415
|
+
/** Process-local proof, not merely a deadline left in the run record. */
|
|
3416
|
+
hasScheduledAutoResume(runId) {
|
|
3417
|
+
return this.autoResumeTimers.has(runId);
|
|
3418
|
+
}
|
|
3125
3419
|
/** Removal waits for the captured provider result, never merely the cancel flag. */
|
|
3126
3420
|
async cancelAndWait(runId) {
|
|
3127
3421
|
const state = this.active.get(runId);
|
|
@@ -3152,6 +3446,7 @@ export class RunManager {
|
|
|
3152
3446
|
this.clearIdleTimer(state);
|
|
3153
3447
|
this.clearAutosaveTimer(state);
|
|
3154
3448
|
this.clearMonitoringWakeTimer(state, runId);
|
|
3449
|
+
this.clearMonitoringLivenessTimer(state);
|
|
3155
3450
|
state.releaseWorktree?.();
|
|
3156
3451
|
state.releaseRepoRoot?.();
|
|
3157
3452
|
this.active.delete(runId);
|
|
@@ -3417,8 +3712,8 @@ export class RunManager {
|
|
|
3417
3712
|
* backend, so there is nothing left to amend and no session to deliver into —
|
|
3418
3713
|
* without this rung the message would 409, a genuinely dropped message in the
|
|
3419
3714
|
* feature built to stop dropping them. Flushed as an ordinary follow-up turn
|
|
3420
|
-
* the instant the session opens;
|
|
3421
|
-
*
|
|
3715
|
+
* the instant the session opens; a run that settles first resumes with it
|
|
3716
|
+
* (`redeliverDeferred`).
|
|
3422
3717
|
*
|
|
3423
3718
|
* The buffer lives on the manager rather than the `ActiveRun` because the
|
|
3424
3719
|
* `ActiveRun` does not exist yet for part of this window.
|
|
@@ -3431,11 +3726,15 @@ export class RunManager {
|
|
|
3431
3726
|
// alone would reopen exactly the drop this rung exists to close.
|
|
3432
3727
|
const state = this.active.get(runId);
|
|
3433
3728
|
const startingUp = (this.starting.has(runId) && !this.cancelledStarting.has(runId)) || (state !== undefined && !state.sessionEverOpened && !state.cancelled);
|
|
3434
|
-
|
|
3729
|
+
// A session gap on a live owner — between workflow steps, or settling after the last turn
|
|
3730
|
+
// (landing, review gate: well over ten seconds on a busy Windows host) while the record still
|
|
3731
|
+
// says `running`. The next session's open flushes it; `dropActive` resumes with it otherwise
|
|
3732
|
+
// (telemetry 1408d7cb). A park (`waiting`: a CI or children wait, the review gate) is not a gap —
|
|
3733
|
+
// nothing opens a session there soon, so the message would sit unseen; it answers 409 as before.
|
|
3734
|
+
const sessionGap = state !== undefined && !state.cancelled && !state.session?.open && !this.waiting.has(runId) && !this.lifecycle.isBlocked(runId);
|
|
3735
|
+
if (!startingUp && !sessionGap)
|
|
3435
3736
|
return false;
|
|
3436
|
-
|
|
3437
|
-
pending.push(content);
|
|
3438
|
-
this.deferredMessages.set(runId, pending);
|
|
3737
|
+
this.setDeferred(runId, [...(this.deferredMessages.get(runId) ?? []), content]);
|
|
3439
3738
|
return true;
|
|
3440
3739
|
}
|
|
3441
3740
|
/** Deliver anything `deferMessage` buffered, once the session is live. */
|
|
@@ -3448,10 +3747,7 @@ export class RunManager {
|
|
|
3448
3747
|
// here would be precisely the failure `deferMessage` exists to prevent. Anything
|
|
3449
3748
|
// left over is retried by the next session that opens on this run.
|
|
3450
3749
|
const unsent = pending.filter((content) => !this.sendMessage(runId, content));
|
|
3451
|
-
|
|
3452
|
-
this.deferredMessages.set(runId, unsent);
|
|
3453
|
-
else
|
|
3454
|
-
this.deferredMessages.delete(runId);
|
|
3750
|
+
this.setDeferred(runId, unsent);
|
|
3455
3751
|
}
|
|
3456
3752
|
/**
|
|
3457
3753
|
* Deliver a user message into the run's live claude session (mid-turn or
|
|
@@ -3593,6 +3889,7 @@ export class RunManager {
|
|
|
3593
3889
|
const state = this.active.get(runId);
|
|
3594
3890
|
if (state?.graphFinish && !state.session?.open) {
|
|
3595
3891
|
this.store.appendEvent(runId, { type: 'lifecycle', message: 'finished by user at a workflow wait' });
|
|
3892
|
+
state.finishedAtWait = true;
|
|
3596
3893
|
state.graphFinish();
|
|
3597
3894
|
return true;
|
|
3598
3895
|
}
|
|
@@ -3657,7 +3954,7 @@ export class RunManager {
|
|
|
3657
3954
|
return true;
|
|
3658
3955
|
}
|
|
3659
3956
|
if (run?.status === 'review' && !this.isActive(runId)) {
|
|
3660
|
-
this.store.updateRun(runId, { status: 'done' });
|
|
3957
|
+
this.store.updateRun(runId, { status: 'done', completionReason: 'accepted' });
|
|
3661
3958
|
this.store.appendEvent(runId, { type: 'lifecycle', message: 'review accepted — finished without a PR' });
|
|
3662
3959
|
return true;
|
|
3663
3960
|
}
|
|
@@ -4032,6 +4329,13 @@ export class RunManager {
|
|
|
4032
4329
|
state.session?.interrupt();
|
|
4033
4330
|
return;
|
|
4034
4331
|
}
|
|
4332
|
+
// Error results can report the charge after the error event. Keep accounting
|
|
4333
|
+
// while the session-error guard still prevents later success transitions.
|
|
4334
|
+
if (event.type === 'cost') {
|
|
4335
|
+
stepCost += event.usd;
|
|
4336
|
+
this.store.updateStep(runId, stepId, { costUsd: stepCost });
|
|
4337
|
+
return;
|
|
4338
|
+
}
|
|
4035
4339
|
if (sessionError)
|
|
4036
4340
|
return;
|
|
4037
4341
|
if (event.type === 'session') {
|
|
@@ -4040,10 +4344,6 @@ export class RunManager {
|
|
|
4040
4344
|
if (event.type === 'token-usage') {
|
|
4041
4345
|
this.store.updateStep(runId, stepId, { tokensUsed: event.tokensUsed });
|
|
4042
4346
|
}
|
|
4043
|
-
if (event.type === 'cost') {
|
|
4044
|
-
stepCost += event.usd;
|
|
4045
|
-
this.store.updateStep(runId, stepId, { costUsd: stepCost });
|
|
4046
|
-
}
|
|
4047
4347
|
if (event.type === 'turn-end') {
|
|
4048
4348
|
// Belt-and-braces: v2 `turn.completed` already flushed the delta
|
|
4049
4349
|
// coalescers; the v1 turn boundary flushes again (idempotent) so no
|
|
@@ -4129,10 +4429,11 @@ export class RunManager {
|
|
|
4129
4429
|
// `running`/`activity:'monitoring'` (#490). Both share the waiting
|
|
4130
4430
|
// lifecycle (free the slot), while only plain waiting keeps the idle timer. Monitoring is
|
|
4131
4431
|
// checked before the autonomous nudge, so it remains non-attention.
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
if (ask)
|
|
4432
|
+
const attentionRequest = ask ? this.recordAsk(runId, sink, ask) : undefined;
|
|
4433
|
+
if (ask) {
|
|
4135
4434
|
state.askPark = 'waiting';
|
|
4435
|
+
state.monitorHandoff = false;
|
|
4436
|
+
}
|
|
4136
4437
|
if (monitoring) {
|
|
4137
4438
|
this.store.updateRun(runId, { status: 'running', activity: 'monitoring' });
|
|
4138
4439
|
this.store.updateStep(runId, stepId, { status: 'running' });
|
|
@@ -4143,7 +4444,7 @@ export class RunManager {
|
|
|
4143
4444
|
this.armMonitoringWakeTimer(runId, state);
|
|
4144
4445
|
}
|
|
4145
4446
|
else {
|
|
4146
|
-
this.store.updateRun(runId, { status: 'waiting', activity: undefined, askParked: ask ? true : undefined });
|
|
4447
|
+
this.store.updateRun(runId, { status: 'waiting', activity: undefined, askParked: ask ? true : undefined, attentionRequest });
|
|
4147
4448
|
this.store.updateStep(runId, stepId, { status: 'waiting' });
|
|
4148
4449
|
this.leaveMonitoring(runId);
|
|
4149
4450
|
this.clearMonitoringWakeTimer(state, runId);
|
|
@@ -4161,7 +4462,7 @@ export class RunManager {
|
|
|
4161
4462
|
// 2026-08-03-auto-resume-after-usage-limit). `settleSuccess` does the same for a run that
|
|
4162
4463
|
// finishes outright; this covers the far more common "parked for the user" ending.
|
|
4163
4464
|
if (this.store.getRun(runId)?.autoResumeAttempts !== undefined) {
|
|
4164
|
-
this.store.updateRun(runId, { autoResumeAttempts: undefined });
|
|
4465
|
+
this.store.updateRun(runId, { autoResumeAttempts: undefined, autoResumeReason: undefined });
|
|
4165
4466
|
}
|
|
4166
4467
|
// A nudged turn did NOT park, so it must not report that it did: the handoff file is
|
|
4167
4468
|
// the rolling context the agent reads back on resume (spec 007), not a log, and an
|
|
@@ -4369,29 +4670,23 @@ export class RunManager {
|
|
|
4369
4670
|
// Before any branch below publishes a terminal status: the finally's autosave comes after it.
|
|
4370
4671
|
state.turnSettled = true;
|
|
4371
4672
|
sink.sessionEnded(state.cancelled ? 'cancelled' : 'end_turn');
|
|
4372
|
-
if (
|
|
4673
|
+
if (this.active.get(runId) !== state)
|
|
4674
|
+
return;
|
|
4675
|
+
if (state.cancelled) {
|
|
4373
4676
|
this.store.updateStep(runId, stepId, { status: 'cancelled', finishedAt: finishedAt() });
|
|
4374
4677
|
this.store.updateRun(runId, { status: 'cancelled', finishedAt: finishedAt(), currentStepId: undefined });
|
|
4375
4678
|
this.store.appendEvent(runId, { type: 'lifecycle', message: 'run cancelled' });
|
|
4376
4679
|
appendHandoffHeartbeat(this.dataDir, runId, `step "${stepId}" complete — status=cancelled`);
|
|
4377
4680
|
}
|
|
4378
4681
|
else if (state.askPark === 'waiting' && this.active.get(runId) === state) {
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
this.store.updateStep(runId, stepId, { status: 'failed', error: message, finishedAt: failedAt });
|
|
4383
|
-
this.store.updateRun(runId, {
|
|
4384
|
-
status: 'failed',
|
|
4385
|
-
error: message,
|
|
4386
|
-
finishedAt: failedAt,
|
|
4387
|
-
currentStepId: undefined,
|
|
4388
|
-
askParked: undefined,
|
|
4389
|
-
// The question is still unanswered: the run stays under "needs you" (see `execute`).
|
|
4390
|
-
awaitingAnswerSince: failedAt,
|
|
4391
|
-
});
|
|
4392
|
-
this.store.appendEvent(runId, { type: 'lifecycle', message: `run stopped — ${message}` });
|
|
4682
|
+
state.askPark = undefined;
|
|
4683
|
+
this.settleUnansweredPark(runId, finishedAt(), state.monitorHandoff === true);
|
|
4684
|
+
appendHandoffHeartbeat(this.dataDir, runId, `step "${stepId}" complete — status=failed`);
|
|
4393
4685
|
}
|
|
4394
4686
|
else if (this.active.get(runId) === state && (await this.idleClosedFails(runId, state))) {
|
|
4687
|
+
// Review Git can outlive cancellation and retirement of this continuation.
|
|
4688
|
+
if (state.cancelled || this.active.get(runId) !== state)
|
|
4689
|
+
return;
|
|
4395
4690
|
const message = this.inactivityFailureMessage();
|
|
4396
4691
|
const failedAt = finishedAt();
|
|
4397
4692
|
this.store.updateStep(runId, stepId, { status: 'failed', error: message, finishedAt: failedAt });
|
|
@@ -4403,11 +4698,12 @@ export class RunManager {
|
|
|
4403
4698
|
});
|
|
4404
4699
|
this.store.appendEvent(runId, { type: 'lifecycle', message: `run stopped — ${message}` });
|
|
4405
4700
|
}
|
|
4406
|
-
else {
|
|
4701
|
+
else if (!state.cancelled && this.active.get(runId) === state) {
|
|
4407
4702
|
this.store.updateStep(runId, stepId, { status: 'done', finishedAt: finishedAt() });
|
|
4408
4703
|
this.store.appendEvent(runId, { type: 'step-end', stepId, status: 'done' });
|
|
4409
|
-
await this.settleSuccess(runId)
|
|
4410
|
-
|
|
4704
|
+
if (await this.settleSuccess(runId, state)) {
|
|
4705
|
+
appendHandoffHeartbeat(this.dataDir, runId, `step "${stepId}" complete — status=done`);
|
|
4706
|
+
}
|
|
4411
4707
|
}
|
|
4412
4708
|
}
|
|
4413
4709
|
catch (err) {
|
|
@@ -4444,6 +4740,10 @@ export class RunManager {
|
|
|
4444
4740
|
}
|
|
4445
4741
|
// ---- execution -----------------------------------------------------------
|
|
4446
4742
|
async execute(runId, workflow, input, ownerToken) {
|
|
4743
|
+
const original = this.store.getRun(runId);
|
|
4744
|
+
// Only a job queued as a usage-limit resume re-enters its interrupted agent (#1300); the
|
|
4745
|
+
// step/session checkpoint survives missing optional attempt accounting.
|
|
4746
|
+
const resumeStep = input.usageLimitResume && original ? this.interruptedWorkflowStep(original) : undefined;
|
|
4447
4747
|
const state = {
|
|
4448
4748
|
ownerToken: ownerToken ?? Symbol('run-owner'),
|
|
4449
4749
|
cancelled: false,
|
|
@@ -4490,7 +4790,11 @@ export class RunManager {
|
|
|
4490
4790
|
// Extra system prompt (R2 2.3): POST override > config default; echoed on
|
|
4491
4791
|
// the record so the UI/API can show what the run actually used. The landing permission or the
|
|
4492
4792
|
// read-only rule rides along, so a Continue (which reads the record) keeps it.
|
|
4493
|
-
|
|
4793
|
+
// A usage-limit resume reuses the recorded prompt verbatim, as Continue does: the record holds
|
|
4794
|
+
// only the composed form, and re-composing it would repeat its landing/read-only parts.
|
|
4795
|
+
const extraSystemPrompt = resumeStep && original?.systemPrompt !== undefined
|
|
4796
|
+
? original.systemPrompt
|
|
4797
|
+
: composeSystemPrompt(resolveExtraSystemPrompt(input.systemPrompt, config.systemPrompt, (await loadWorkspaceConfig().catch(() => null))?.systemPrompt), state.autoLand ? landingPromptPart(state.autoLand.baseLabel, state.autoLand.checks, state.autonomous === true) : undefined, state.readOnly ? READ_ONLY_PROMPT : undefined) || undefined;
|
|
4494
4798
|
// Canonical provider/model identity (#405) — the normalised `provider/model`
|
|
4495
4799
|
// the task ran with, persisted for cost attribution / reproducible replay
|
|
4496
4800
|
// beside the free-text `model`. Best-effort here (a per-step `runner`/`model`
|
|
@@ -4506,12 +4810,12 @@ export class RunManager {
|
|
|
4506
4810
|
}
|
|
4507
4811
|
this.store.updateRun(runId, {
|
|
4508
4812
|
status: 'running',
|
|
4509
|
-
startedAt: new Date().toISOString(),
|
|
4813
|
+
startedAt: resumeStep ? original?.startedAt : new Date().toISOString(),
|
|
4510
4814
|
runner: taskBackend,
|
|
4511
4815
|
systemPrompt: extraSystemPrompt,
|
|
4512
4816
|
modelIdentity,
|
|
4513
4817
|
});
|
|
4514
|
-
emit({ type: 'lifecycle', message: `run started — workflow "${workflow.name}" (runner: ${taskBackend})` });
|
|
4818
|
+
emit({ type: 'lifecycle', message: `run ${resumeStep ? 'resumed' : 'started'} — workflow "${workflow.name}" (runner: ${taskBackend})` });
|
|
4515
4819
|
// Worktree per task (spec 006): the agent works on its own branch in
|
|
4516
4820
|
// `.ai/cezar/worktrees/<id>`, never in the user's working tree. A Git task
|
|
4517
4821
|
// that requests isolation fails closed if the worktree cannot be
|
|
@@ -4522,7 +4826,20 @@ export class RunManager {
|
|
|
4522
4826
|
return;
|
|
4523
4827
|
}
|
|
4524
4828
|
let switchInPlaceTo;
|
|
4525
|
-
if (
|
|
4829
|
+
if (resumeStep) {
|
|
4830
|
+
await rematerializeReclaimedWorktree(this.repoRoot, this.store, runId);
|
|
4831
|
+
const worktreePath = this.store.getRun(runId)?.worktreePath;
|
|
4832
|
+
if (worktreePath && existsSync(worktreePath))
|
|
4833
|
+
state.cwd = worktreePath;
|
|
4834
|
+
}
|
|
4835
|
+
if (resumeStep && state.cwd !== this.repoRoot) {
|
|
4836
|
+
// Reuse the tree as the agent left it, including a branch it checked out itself — under the
|
|
4837
|
+
// same agent lease the fresh path and `runContinuation` hold, so no reclaim races the agent.
|
|
4838
|
+
state.releaseWorktree = await this.lifecycle.acquireAgentLease(runId);
|
|
4839
|
+
this.armAutosave(runId, state);
|
|
4840
|
+
emit({ type: 'note', message: 'resuming in the existing task worktree' });
|
|
4841
|
+
}
|
|
4842
|
+
else if (repo && input.worktree === false) {
|
|
4526
4843
|
// Composer opt-out: run in the repo working tree, no branch/worktree. The
|
|
4527
4844
|
// repository-root lease serializes these runs by default; the explicit
|
|
4528
4845
|
// CEZ_DISABLE_REPO_LOCK=1 escape hatch allows unsafe overlap.
|
|
@@ -4547,7 +4864,7 @@ export class RunManager {
|
|
|
4547
4864
|
emit({ type: 'note', message: 'worktree off — running in the repo working tree' });
|
|
4548
4865
|
// Pin the starting commit: the session's Changes and Commits views use it
|
|
4549
4866
|
// as their stable lower bound while reading the current working copy.
|
|
4550
|
-
const startingCommit = await getHeadCommit(repo.root);
|
|
4867
|
+
const startingCommit = resumeStep ? undefined : await getHeadCommit(repo.root);
|
|
4551
4868
|
if (startingCommit)
|
|
4552
4869
|
this.store.updateRun(runId, { baseBranch: startingCommit });
|
|
4553
4870
|
}
|
|
@@ -4755,7 +5072,11 @@ export class RunManager {
|
|
|
4755
5072
|
extraSystemPrompt,
|
|
4756
5073
|
startImages,
|
|
4757
5074
|
startAttachments,
|
|
4758
|
-
|
|
5075
|
+
// #1300: a usage-limit resume re-enters the walk at its interrupted agent node.
|
|
5076
|
+
resume: resumeStep
|
|
5077
|
+
? { loops: {}, taken: [], ...this.store.getRun(runId)?.graphState, cursor: resumeStep.id }
|
|
5078
|
+
: this.store.getRun(runId)?.graphState,
|
|
5079
|
+
usageLimitResume: resumeStep,
|
|
4759
5080
|
});
|
|
4760
5081
|
// How a mid-workflow ask park (#917) ended, read once before the settlement
|
|
4761
5082
|
// below clears it. A LIVE park never reaches this line: the parked session
|
|
@@ -4767,6 +5088,7 @@ export class RunManager {
|
|
|
4767
5088
|
// of the process. Cancellation and step failures keep their own branches
|
|
4768
5089
|
// below, ahead of the park, so they still land as `cancelled`/`failed`.
|
|
4769
5090
|
const askPark = state.askPark;
|
|
5091
|
+
const monitorHandoff = state.monitorHandoff === true;
|
|
4770
5092
|
state.askPark = undefined;
|
|
4771
5093
|
// Final autosave: the branch always ends holding the finished state.
|
|
4772
5094
|
this.clearAutosaveTimer(state);
|
|
@@ -4800,38 +5122,13 @@ export class RunManager {
|
|
|
4800
5122
|
error: runError,
|
|
4801
5123
|
finishedAt,
|
|
4802
5124
|
currentStepId: undefined,
|
|
4803
|
-
// A crash or a
|
|
5125
|
+
// A crash or a runner timeout while parked on a question does not answer it either.
|
|
4804
5126
|
...(askPark === 'waiting' ? { awaitingAnswerSince: finishedAt } : {}),
|
|
4805
5127
|
});
|
|
4806
5128
|
emit({ type: 'lifecycle', message: `run failed — ${runError}` });
|
|
4807
5129
|
}
|
|
4808
5130
|
else if (askPark === 'waiting') {
|
|
4809
|
-
|
|
4810
|
-
// `settleSuccess` would put a finished badge on a workflow that stopped at
|
|
4811
|
-
// its first question; `failed` says what happened and keeps the Continue
|
|
4812
|
-
// button, which reopens the session so the answer can still be given.
|
|
4813
|
-
const run = this.store.getRun(runId);
|
|
4814
|
-
for (const s of run?.steps ?? []) {
|
|
4815
|
-
if (s.status === 'running' || s.status === 'waiting') {
|
|
4816
|
-
this.store.updateStep(runId, s.id, { status: 'failed', finishedAt });
|
|
4817
|
-
}
|
|
4818
|
-
}
|
|
4819
|
-
// Say what Continue will and will not do. It reopens the session through
|
|
4820
|
-
// `runContinuation`, so the question can still be answered — but that is a
|
|
4821
|
-
// standalone continuation, not a re-entry into `execute`, so the steps this
|
|
4822
|
-
// park never reached stay `pending` and nothing will run them automatically.
|
|
4823
|
-
const error = 'the session closed before the question was answered — continue to answer it, ' +
|
|
4824
|
-
'but the remaining workflow steps will not resume automatically';
|
|
4825
|
-
// `awaitingAnswerSince`: closing the session freed the process and the slot, but the
|
|
4826
|
-
// question is still the user's to answer, so the task keeps reading as "needs you".
|
|
4827
|
-
this.store.updateRun(runId, {
|
|
4828
|
-
status: 'failed',
|
|
4829
|
-
error,
|
|
4830
|
-
finishedAt,
|
|
4831
|
-
currentStepId: undefined,
|
|
4832
|
-
awaitingAnswerSince: finishedAt,
|
|
4833
|
-
});
|
|
4834
|
-
emit({ type: 'lifecycle', message: `run stopped — ${error}` });
|
|
5131
|
+
this.settleUnansweredPark(runId, finishedAt, monitorHandoff);
|
|
4835
5132
|
}
|
|
4836
5133
|
else if (idleFailed) {
|
|
4837
5134
|
const error = this.inactivityFailureMessage();
|
|
@@ -4847,7 +5144,7 @@ export class RunManager {
|
|
|
4847
5144
|
else {
|
|
4848
5145
|
// Includes `askPark === 'abandoned'`: Finish on a parked run ends it the
|
|
4849
5146
|
// way Finish always does, with the later steps left honestly at `pending`.
|
|
4850
|
-
await this.settleSuccess(runId);
|
|
5147
|
+
await this.settleSuccess(runId, state);
|
|
4851
5148
|
}
|
|
4852
5149
|
this.clearIdleTimer(state);
|
|
4853
5150
|
this.dropActive(runId, state);
|
|
@@ -4872,6 +5169,41 @@ export class RunManager {
|
|
|
4872
5169
|
const resume = resumeNode ? ctx.resume : undefined;
|
|
4873
5170
|
const loopCounts = new Map(Object.entries(resume?.loops ?? {}));
|
|
4874
5171
|
const outputs = new Map(Object.entries(resume?.outputs ?? {}));
|
|
5172
|
+
// #1300: a v1 check's consumed retries live on its step record (`retriesUsed`), so recovery
|
|
5173
|
+
// never depends on the transcript. An older executed check has unknown accounting, so
|
|
5174
|
+
// conservatively spend its cap rather than grant retries.
|
|
5175
|
+
const checkLoops = new Map();
|
|
5176
|
+
if (!workflow.graph) {
|
|
5177
|
+
const checkpoint = this.store.getRun(runId);
|
|
5178
|
+
let initializedRetryBudget = false;
|
|
5179
|
+
for (const def of workflow.steps) {
|
|
5180
|
+
if (!def.command || !def.onFail)
|
|
5181
|
+
continue;
|
|
5182
|
+
const loopId = graph.edges.find((e) => e.from === `${def.id}.fail`)?.to;
|
|
5183
|
+
if (!loopId)
|
|
5184
|
+
continue;
|
|
5185
|
+
checkLoops.set(loopId, def.id);
|
|
5186
|
+
const rec = checkpoint?.steps.find((candidate) => candidate.id === def.id);
|
|
5187
|
+
// A walk resumed after a restart already carries the exact count; only a record with
|
|
5188
|
+
// neither falls back to the conservative legacy rule.
|
|
5189
|
+
const walked = resume?.loops?.[loopId];
|
|
5190
|
+
const legacyExecuted = rec?.retriesUsed === undefined && walked === undefined && (rec?.iterations ?? 0) > 0;
|
|
5191
|
+
const used = rec?.retriesUsed ?? walked ?? (legacyExecuted ? def.onFail.max : 0);
|
|
5192
|
+
loopCounts.set(loopId, used);
|
|
5193
|
+
if (rec?.retriesUsed === undefined) {
|
|
5194
|
+
this.store.updateStep(runId, def.id, { retriesUsed: used });
|
|
5195
|
+
initializedRetryBudget = true;
|
|
5196
|
+
}
|
|
5197
|
+
if (legacyExecuted) {
|
|
5198
|
+
emit({
|
|
5199
|
+
type: 'note', stepId: def.id,
|
|
5200
|
+
message: 'check retry accounting unavailable on this older record — no further retries granted',
|
|
5201
|
+
});
|
|
5202
|
+
}
|
|
5203
|
+
}
|
|
5204
|
+
if (initializedRetryBudget)
|
|
5205
|
+
this.store.flush();
|
|
5206
|
+
}
|
|
4875
5207
|
let checkFailure = null;
|
|
4876
5208
|
/** The last agent failure, for the run error when its `failed` port is unwired (v1 wording). */
|
|
4877
5209
|
let agentFailure;
|
|
@@ -4890,6 +5222,12 @@ export class RunManager {
|
|
|
4890
5222
|
const loop = graph.nodes.find((n) => n.id === t.from && n.type === 'loop');
|
|
4891
5223
|
if (loop && loop.type === 'loop') {
|
|
4892
5224
|
const iteration = loopCounts.get(loop.id) ?? 0;
|
|
5225
|
+
const check = checkLoops.get(loop.id);
|
|
5226
|
+
if (check && t.port === 'repeat') {
|
|
5227
|
+
// #1300: commit the consumed retry before another agent can start, even after a crash.
|
|
5228
|
+
this.store.updateStep(runId, check, { retriesUsed: iteration });
|
|
5229
|
+
this.store.flush();
|
|
5230
|
+
}
|
|
4893
5231
|
outputs.set(loop.id, { iteration, max: loop.max });
|
|
4894
5232
|
emit({
|
|
4895
5233
|
type: 'note',
|
|
@@ -4921,8 +5259,11 @@ export class RunManager {
|
|
|
4921
5259
|
let step = resumeNode
|
|
4922
5260
|
? { kind: 'node', node: resumeNode, transitions: [] }
|
|
4923
5261
|
: enterGraph(graph, loopCounts);
|
|
4924
|
-
if (resumeNode)
|
|
4925
|
-
|
|
5262
|
+
if (resumeNode) {
|
|
5263
|
+
const why = ctx.usageLimitResume?.id !== resumeNode.id ? 'a restart'
|
|
5264
|
+
: autoResumeReasonFor(ctx.usageLimitResume.error) === 'transient' ? 'a temporary provider failure' : 'a usage limit';
|
|
5265
|
+
emit({ type: 'note', message: `resuming the workflow at "${resumeNode.name ?? resumeNode.id}" after ${why}` });
|
|
5266
|
+
}
|
|
4926
5267
|
else
|
|
4927
5268
|
record(step.transitions);
|
|
4928
5269
|
while (step.kind === 'node') {
|
|
@@ -4939,6 +5280,7 @@ export class RunManager {
|
|
|
4939
5280
|
status: 'running',
|
|
4940
5281
|
iterations: iteration,
|
|
4941
5282
|
startedAt: new Date().toISOString(),
|
|
5283
|
+
finishedAt: undefined,
|
|
4942
5284
|
error: undefined,
|
|
4943
5285
|
});
|
|
4944
5286
|
emit({ type: 'step-start', stepId: node.id, name: node.name ?? node.id, kind, iteration });
|
|
@@ -4996,7 +5338,15 @@ export class RunManager {
|
|
|
4996
5338
|
rendered.prompt = `${rendered.prompt ?? '{{task}}'}\n\n${verdictInstruction(verdicts)}`;
|
|
4997
5339
|
const backend = node.runner ?? taskBackend;
|
|
4998
5340
|
const lastTurn = { text: '' };
|
|
4999
|
-
const failure = await this.runAgentStep(runId, state, rendered, input, skills, checkFailure, isTerminalAgent(graph, node.id), emit, startImages, taskBackend, extraSystemPrompt, stepIdx >= 0 ? chainStepNote(workflow.steps, stepIdx) : undefined, startAttachments, resuming
|
|
5341
|
+
const failure = await this.runAgentStep(runId, state, rendered, input, skills, checkFailure, isTerminalAgent(graph, node.id), emit, startImages, taskBackend, extraSystemPrompt, stepIdx >= 0 ? chainStepNote(workflow.steps, stepIdx) : undefined, startAttachments, resuming && ctx.usageLimitResume?.id === node.id
|
|
5342
|
+
? {
|
|
5343
|
+
...(RESUMABLE_BACKENDS.has(backend) ? { resumeSessionId: ctx.usageLimitResume.sessionId } : {}),
|
|
5344
|
+
lastTurn,
|
|
5345
|
+
usageLimitResume: ctx.usageLimitResume,
|
|
5346
|
+
}
|
|
5347
|
+
: resuming
|
|
5348
|
+
? this.resumeInterruptedAgent(runId, node, backend, rendered, lastTurn)
|
|
5349
|
+
: { resumeSessionId: this.graphResumeSession(runId, node, backend, emit), lastTurn });
|
|
5000
5350
|
startImages = undefined;
|
|
5001
5351
|
startAttachments = [];
|
|
5002
5352
|
checkFailure = null;
|
|
@@ -5701,8 +6051,10 @@ export class RunManager {
|
|
|
5701
6051
|
}
|
|
5702
6052
|
/** Ask the user through an ask card and park until they answer (see `parkGraphNode`). */
|
|
5703
6053
|
parkForUser(runId, state, nodeId, questions, timeoutMs) {
|
|
5704
|
-
|
|
5705
|
-
|
|
6054
|
+
const requestId = randomUUID();
|
|
6055
|
+
this.makeUiSink(runId, nodeId).handle({ type: 'ask.requested', requestId, questions, source: 'workflow' });
|
|
6056
|
+
const attentionRequest = this.recordAttention(requestId, questions);
|
|
6057
|
+
return this.parkGraphNode(runId, state, nodeId, { askParked: true, attentionRequest, timeoutMs }, (resolve) => {
|
|
5706
6058
|
state.graphAnswer = (text) => resolve({ kind: 'answer', text });
|
|
5707
6059
|
return () => {
|
|
5708
6060
|
state.graphAnswer = undefined;
|
|
@@ -5721,7 +6073,7 @@ export class RunManager {
|
|
|
5721
6073
|
if (state.cancelled)
|
|
5722
6074
|
return { kind: 'cancelled' };
|
|
5723
6075
|
this.store.updateRun(runId, opts.askParked
|
|
5724
|
-
? { status: 'waiting', askParked: true }
|
|
6076
|
+
? { status: 'waiting', askParked: true, attentionRequest: opts.attentionRequest }
|
|
5725
6077
|
: { status: 'running', activity: opts.activity });
|
|
5726
6078
|
this.store.updateStep(runId, nodeId, { status: 'waiting' });
|
|
5727
6079
|
this.waiting.add(runId);
|
|
@@ -5892,8 +6244,10 @@ export class RunManager {
|
|
|
5892
6244
|
* real files, not just view the inline image blocks. */
|
|
5893
6245
|
attachments = [],
|
|
5894
6246
|
/** Graph-workflow hooks (spec 2026-09-30-workflow-node-editor): reopen an earlier session
|
|
5895
|
-
* instead of minting one, and hand back the last turn's text for verdict parsing.
|
|
6247
|
+
* instead of minting one, and hand back the last turn's text for verdict parsing.
|
|
6248
|
+
* `usageLimitResume` reopens a step a usage limit interrupted (#1300). */
|
|
5896
6249
|
graphHooks) {
|
|
6250
|
+
const resumeStep = graphHooks?.usageLimitResume;
|
|
5897
6251
|
let systemPrompt;
|
|
5898
6252
|
// An attachment-only task (telemetry 18c930de) — the note stands in for the missing text, so a
|
|
5899
6253
|
// step template (`Review: {{task}}`) still reads as a sentence.
|
|
@@ -5930,6 +6284,10 @@ export class RunManager {
|
|
|
5930
6284
|
// `execute`. Expand before the chain/check/attachment prefixes so the leading slash still
|
|
5931
6285
|
// matches; a leading `/name` that is not a known skill passes through byte-for-byte.
|
|
5932
6286
|
userPrompt = expandRegistrySlashSkillText(userPrompt, state.skills ?? []);
|
|
6287
|
+
if (resumeStep) {
|
|
6288
|
+
const resumePrompt = autoResumeReasonFor(resumeStep.error) === 'transient' ? TRANSIENT_RETRY_PROMPT : AUTO_RESUME_PROMPT;
|
|
6289
|
+
userPrompt = `${resumePrompt}\n\nCurrent task and queued updates:\n\n${userPrompt}`;
|
|
6290
|
+
}
|
|
5933
6291
|
if (chainNote)
|
|
5934
6292
|
userPrompt = `${chainNote}\n\n---\n\n${userPrompt}`;
|
|
5935
6293
|
// A commander recovered after a restart opens its first session holding whatever its children
|
|
@@ -6003,6 +6361,13 @@ export class RunManager {
|
|
|
6003
6361
|
state.session?.interrupt();
|
|
6004
6362
|
return;
|
|
6005
6363
|
}
|
|
6364
|
+
// Error results can report the charge after the error event. Keep accounting
|
|
6365
|
+
// while the session-error guard still prevents later success transitions.
|
|
6366
|
+
if (event.type === 'cost') {
|
|
6367
|
+
stepCost += event.usd;
|
|
6368
|
+
this.store.updateStep(runId, step.id, { costUsd: stepCost });
|
|
6369
|
+
return;
|
|
6370
|
+
}
|
|
6006
6371
|
if (sessionError)
|
|
6007
6372
|
return;
|
|
6008
6373
|
if (event.type === 'session') {
|
|
@@ -6012,10 +6377,6 @@ export class RunManager {
|
|
|
6012
6377
|
if (event.type === 'token-usage') {
|
|
6013
6378
|
this.store.updateStep(runId, step.id, { tokensUsed: startTokens + event.tokensUsed });
|
|
6014
6379
|
}
|
|
6015
|
-
if (event.type === 'cost') {
|
|
6016
|
-
stepCost += event.usd;
|
|
6017
|
-
this.store.updateStep(runId, step.id, { costUsd: stepCost });
|
|
6018
|
-
}
|
|
6019
6380
|
if (event.type === 'turn-end') {
|
|
6020
6381
|
// v2 `turn.completed` already flushed the coalescers; the v1 turn
|
|
6021
6382
|
// boundary flushes again (idempotent) as a backstop.
|
|
@@ -6140,16 +6501,17 @@ export class RunManager {
|
|
|
6140
6501
|
// instead of raising "needs you" (#490). Lifecycle is identical: the
|
|
6141
6502
|
// run frees its slot; only plain waiting keeps the idle timer. The autonomous nudge
|
|
6142
6503
|
// above still wins over either.
|
|
6143
|
-
|
|
6144
|
-
this.recordAsk(runId, sink, ask);
|
|
6504
|
+
const attentionRequest = ask ? this.recordAsk(runId, sink, ask) : undefined;
|
|
6145
6505
|
// The final interactive step already parks at `waiting` by its own
|
|
6146
6506
|
// lifecycle; only a non-final step needs the workflow held back, so
|
|
6147
6507
|
// `execute` does not mark it done and run the next check (#917).
|
|
6148
6508
|
// Inside the `!autoContinued` branch on purpose: a nudged autonomous
|
|
6149
6509
|
// turn did not park, so it must not leave a park behind for `execute`
|
|
6150
6510
|
// to settle.
|
|
6151
|
-
if (ask)
|
|
6511
|
+
if (ask) {
|
|
6152
6512
|
state.askPark = 'waiting';
|
|
6513
|
+
state.monitorHandoff = false;
|
|
6514
|
+
}
|
|
6153
6515
|
if (monitoring) {
|
|
6154
6516
|
this.store.updateRun(runId, { status: 'running', activity: 'monitoring' });
|
|
6155
6517
|
this.store.updateStep(runId, step.id, { status: 'running' });
|
|
@@ -6167,6 +6529,7 @@ export class RunManager {
|
|
|
6167
6529
|
// read: without it `recover()` cannot tell this `waiting` from a
|
|
6168
6530
|
// finished interactive session and settles it as a success.
|
|
6169
6531
|
askParked: ask ? true : undefined,
|
|
6532
|
+
attentionRequest,
|
|
6170
6533
|
});
|
|
6171
6534
|
this.store.updateStep(runId, step.id, { status: 'waiting' });
|
|
6172
6535
|
this.leaveMonitoring(runId);
|
|
@@ -6206,7 +6569,7 @@ export class RunManager {
|
|
|
6206
6569
|
}
|
|
6207
6570
|
// The window is proven open — see the twin in `runContinuation`.
|
|
6208
6571
|
if (this.store.getRun(runId)?.autoResumeAttempts !== undefined) {
|
|
6209
|
-
this.store.updateRun(runId, { autoResumeAttempts: undefined });
|
|
6572
|
+
this.store.updateRun(runId, { autoResumeAttempts: undefined, autoResumeReason: undefined });
|
|
6210
6573
|
}
|
|
6211
6574
|
// Cez's own heartbeat — the handoff stays current even when the
|
|
6212
6575
|
// agent forgets to write (spec 007).
|
|
@@ -6259,6 +6622,7 @@ export class RunManager {
|
|
|
6259
6622
|
try {
|
|
6260
6623
|
stepProfile = await this.agentEnvForStep(runId, stepBackend, {
|
|
6261
6624
|
generateFollowups: followupsEnabled() && input.generateFollowups !== false,
|
|
6625
|
+
...(resumeStep ? { recordedProfileId: resumeStep.profileId ?? DEFAULT_AGENT_ACCOUNT_ID } : {}),
|
|
6262
6626
|
});
|
|
6263
6627
|
}
|
|
6264
6628
|
catch (err) {
|
|
@@ -6296,11 +6660,12 @@ export class RunManager {
|
|
|
6296
6660
|
model: backendModel,
|
|
6297
6661
|
sessionId: launchSessionId,
|
|
6298
6662
|
resume,
|
|
6299
|
-
// Interactive sessions have no
|
|
6663
|
+
// Interactive sessions have no runner timeout — the idle timer rules.
|
|
6300
6664
|
//
|
|
6301
|
-
// A non-final step keeps
|
|
6302
|
-
//
|
|
6303
|
-
//
|
|
6665
|
+
// A non-final step keeps the runner's timeout (`DEFAULT_RUN_TIMEOUT_MS`
|
|
6666
|
+
// of silence, with a hard ceiling behind it — cf2191f1) even though it
|
|
6667
|
+
// may now park on a `CEZ:ASK` and sit open waiting for an answer (#917).
|
|
6668
|
+
// Dropping it for every intermediate step is the
|
|
6304
6669
|
// wrong trade: it would leave a runaway step with nothing to stop it,
|
|
6305
6670
|
// to buy a park that is bounded by the 15-minute idle timer first in
|
|
6306
6671
|
// all but the longest steps. What matters is that neither expiry can
|
|
@@ -6432,7 +6797,7 @@ export class RunManager {
|
|
|
6432
6797
|
this.leaveMonitoring(runId);
|
|
6433
6798
|
this.clearMonitoringWakeTimer(state, runId);
|
|
6434
6799
|
this.waiting.add(runId);
|
|
6435
|
-
this.store.updateRun(runId, { status: 'waiting', activity: undefined });
|
|
6800
|
+
this.store.updateRun(runId, { status: 'waiting', activity: undefined, attentionRequest: this.recordAttention(event.requestId, event.questions) });
|
|
6436
6801
|
if (state.currentStepId)
|
|
6437
6802
|
this.store.updateStep(runId, state.currentStepId, { status: 'waiting' });
|
|
6438
6803
|
this.releaseSlot();
|
|
@@ -6726,6 +7091,37 @@ export class RunManager {
|
|
|
6726
7091
|
peakProcCount: Math.max(run?.peakProcCount ?? 0, peaks.peakProcCount),
|
|
6727
7092
|
});
|
|
6728
7093
|
}
|
|
7094
|
+
/**
|
|
7095
|
+
* Settle a run whose session closed while it was parked for a reply that never came — a
|
|
7096
|
+
* mid-workflow `CEZ:ASK` (#917) or a monitor handed to the user. `settleSuccess` would put a
|
|
7097
|
+
* finished badge on work the agent said was still open; `failed` says what happened and keeps
|
|
7098
|
+
* the Continue button, which reopens the session so the reply can still be given.
|
|
7099
|
+
*/
|
|
7100
|
+
settleUnansweredPark(runId, finishedAt, monitorHandoff) {
|
|
7101
|
+
const run = this.store.getRun(runId);
|
|
7102
|
+
const stepsLeft = run?.steps.some((s) => s.status === 'pending') ?? false;
|
|
7103
|
+
for (const s of run?.steps ?? []) {
|
|
7104
|
+
if (s.status === 'running' || s.status === 'waiting') {
|
|
7105
|
+
this.store.updateStep(runId, s.id, { status: 'failed', finishedAt });
|
|
7106
|
+
}
|
|
7107
|
+
}
|
|
7108
|
+
// Continue reopens the session through `runContinuation`, a standalone continuation rather
|
|
7109
|
+
// than a re-entry into `execute`, so steps the park never reached stay `pending`.
|
|
7110
|
+
const error = monitorHandoff && !stepsLeft
|
|
7111
|
+
? 'the session closed before you replied — continue to reply'
|
|
7112
|
+
: 'the session closed before the question was answered — continue to answer it' +
|
|
7113
|
+
(stepsLeft ? ', but the remaining workflow steps will not resume automatically' : '');
|
|
7114
|
+
this.store.updateRun(runId, {
|
|
7115
|
+
status: 'failed',
|
|
7116
|
+
error,
|
|
7117
|
+
finishedAt,
|
|
7118
|
+
currentStepId: undefined,
|
|
7119
|
+
askParked: undefined,
|
|
7120
|
+
// The question is still unanswered: the run stays under "needs you".
|
|
7121
|
+
awaitingAnswerSince: finishedAt,
|
|
7122
|
+
});
|
|
7123
|
+
this.store.appendEvent(runId, { type: 'lifecycle', message: `run stopped — ${error}` });
|
|
7124
|
+
}
|
|
6729
7125
|
/**
|
|
6730
7126
|
* Diff-first review gate (spec 009), shared by `execute` and
|
|
6731
7127
|
* `runContinuation`: a *successful* run whose worktree holds changes rests
|
|
@@ -6738,20 +7134,32 @@ export class RunManager {
|
|
|
6738
7134
|
* OFF) AND the run is not autonomous. Autonomous runs — and runs with the gate
|
|
6739
7135
|
* off — settle straight to `done`, leaving the diff in the worktree untouched.
|
|
6740
7136
|
*/
|
|
6741
|
-
async settleSuccess(runId) {
|
|
7137
|
+
async settleSuccess(runId, owner) {
|
|
7138
|
+
const run = this.store.getRun(runId);
|
|
7139
|
+
const status = run?.status;
|
|
7140
|
+
// Recovery has no active owner. Both recovery and execution must still own the
|
|
7141
|
+
// same lifecycle decision after Git yields: cancellation or a new continuation wins.
|
|
7142
|
+
const canSettle = () => !!run && this.store.getRun(runId) === run && run.status === status &&
|
|
7143
|
+
this.active.get(runId) === owner && !owner?.cancelled &&
|
|
7144
|
+
(status === 'running' || status === 'waiting');
|
|
7145
|
+
if (!canSettle())
|
|
7146
|
+
return false;
|
|
6742
7147
|
const landingError = await this.landBeforeSettle(runId);
|
|
7148
|
+
if (!canSettle())
|
|
7149
|
+
return false;
|
|
6743
7150
|
if (landingError === 'review') {
|
|
6744
7151
|
this.store.updateRun(runId, {
|
|
6745
7152
|
status: 'review',
|
|
6746
7153
|
finishedAt: new Date().toISOString(),
|
|
6747
7154
|
currentStepId: undefined,
|
|
6748
7155
|
autoResumeAttempts: undefined,
|
|
7156
|
+
autoResumeReason: undefined,
|
|
6749
7157
|
});
|
|
6750
7158
|
this.store.appendEvent(runId, {
|
|
6751
7159
|
type: 'lifecycle',
|
|
6752
7160
|
message: 'changes ready for review — check Changes, Continue with corrections, or Commit (or Finish) to land them',
|
|
6753
7161
|
});
|
|
6754
|
-
return;
|
|
7162
|
+
return true;
|
|
6755
7163
|
}
|
|
6756
7164
|
if (landingError) {
|
|
6757
7165
|
this.store.updateRun(runId, {
|
|
@@ -6761,17 +7169,24 @@ export class RunManager {
|
|
|
6761
7169
|
currentStepId: undefined,
|
|
6762
7170
|
});
|
|
6763
7171
|
this.store.appendEvent(runId, { type: 'lifecycle', message: `run failed — ${landingError}` });
|
|
6764
|
-
return;
|
|
7172
|
+
return true;
|
|
6765
7173
|
}
|
|
6766
7174
|
const review = await this.reviewGateApplies(runId);
|
|
7175
|
+
if (!canSettle())
|
|
7176
|
+
return false;
|
|
7177
|
+
const resolution = !review && this.store.hasLifecycleObserver ? await completionReason(run) : 'completed';
|
|
7178
|
+
if (!canSettle())
|
|
7179
|
+
return false;
|
|
6767
7180
|
this.store.updateRun(runId, {
|
|
6768
7181
|
status: review ? 'review' : 'done',
|
|
7182
|
+
completionReason: review ? undefined : resolution,
|
|
6769
7183
|
finishedAt: new Date().toISOString(),
|
|
6770
7184
|
currentStepId: undefined,
|
|
6771
7185
|
// A run that got all the way to a settled turn is not in a limit loop, so the resume
|
|
6772
7186
|
// counter starts over — otherwise a task that legitimately met the limit once a week would
|
|
6773
7187
|
// creep toward the cap forever and stop resuming for no reason anyone could see.
|
|
6774
7188
|
autoResumeAttempts: undefined,
|
|
7189
|
+
autoResumeReason: undefined,
|
|
6775
7190
|
});
|
|
6776
7191
|
this.store.appendEvent(runId, {
|
|
6777
7192
|
type: 'lifecycle',
|
|
@@ -6779,6 +7194,7 @@ export class RunManager {
|
|
|
6779
7194
|
? 'changes ready for review — send feedback, open a draft PR, or finish'
|
|
6780
7195
|
: 'run finished',
|
|
6781
7196
|
});
|
|
7197
|
+
return true;
|
|
6782
7198
|
}
|
|
6783
7199
|
/**
|
|
6784
7200
|
* The auto-land policy of an in-place run (spec 2026-10-20-trunk-based-projects), or
|
|
@@ -6807,8 +7223,25 @@ export class RunManager {
|
|
|
6807
7223
|
}
|
|
6808
7224
|
return this.store.getRun(runId)?.task;
|
|
6809
7225
|
}
|
|
7226
|
+
/**
|
|
7227
|
+
* Capture the lifecycle that requested a landing before any await. Continue appends a
|
|
7228
|
+
* step synchronously, even when deferred, so its step count is a durable generation
|
|
7229
|
+
* fence (including a newer turn that has already returned to the same status).
|
|
7230
|
+
* Owner identity alone cannot fence detached review/Commit operations.
|
|
7231
|
+
*/
|
|
7232
|
+
landingFence(runId) {
|
|
7233
|
+
const run = this.store.getRun(runId);
|
|
7234
|
+
const status = run?.status;
|
|
7235
|
+
const generation = run?.steps.length;
|
|
7236
|
+
const owner = this.active.get(runId);
|
|
7237
|
+
return () => !!run && this.store.getRun(runId) === run &&
|
|
7238
|
+
run.status === status && run.steps.length === generation &&
|
|
7239
|
+
this.active.get(runId) === owner && !owner?.cancelled &&
|
|
7240
|
+
(!!owner || !this.isActive(runId));
|
|
7241
|
+
}
|
|
6810
7242
|
/** Land now and record the outcome on the run. A `nothing` never overwrites an earlier result. */
|
|
6811
7243
|
async landNow(runId, policy) {
|
|
7244
|
+
const canLand = this.landingFence(runId);
|
|
6812
7245
|
const run = this.store.getRun(runId);
|
|
6813
7246
|
this.store.appendEvent(runId, {
|
|
6814
7247
|
type: 'note',
|
|
@@ -6832,6 +7265,8 @@ export class RunManager {
|
|
|
6832
7265
|
checks: policy.checks,
|
|
6833
7266
|
env,
|
|
6834
7267
|
});
|
|
7268
|
+
if (!canLand())
|
|
7269
|
+
return outcome;
|
|
6835
7270
|
const at = new Date().toISOString();
|
|
6836
7271
|
if (outcome.result === 'landed') {
|
|
6837
7272
|
this.store.updateRun(runId, {
|
|
@@ -6937,14 +7372,20 @@ export class RunManager {
|
|
|
6937
7372
|
* failure reopens the task with the error so the agent fixes it. Never throws.
|
|
6938
7373
|
*/
|
|
6939
7374
|
async land(runId) {
|
|
7375
|
+
const canLand = this.landingFence(runId);
|
|
7376
|
+
const superseded = { outcome: 'busy', message: 'the task changed while landing — use its current state' };
|
|
6940
7377
|
const run = this.store.getRun(runId);
|
|
6941
7378
|
if (!run || run.worktree !== false || run.readOnly) {
|
|
6942
7379
|
return { outcome: 'unavailable', message: 'only a task that works in the checkout can commit to the base branch' };
|
|
6943
7380
|
}
|
|
6944
7381
|
const policy = await this.landingPolicy(run, await loadConfig(this.repoRoot));
|
|
7382
|
+
if (!canLand())
|
|
7383
|
+
return superseded;
|
|
6945
7384
|
if (!policy)
|
|
6946
7385
|
return { outcome: 'unavailable', message: 'auto-land is not enabled for this project' };
|
|
6947
7386
|
const base = policy.baseBranch ?? (await getRepoInfo(this.repoRoot))?.branch ?? 'the base branch';
|
|
7387
|
+
if (!canLand())
|
|
7388
|
+
return superseded;
|
|
6948
7389
|
const state = this.active.get(runId);
|
|
6949
7390
|
if (state?.session?.open && run.status === 'waiting') {
|
|
6950
7391
|
if (state.repoRootParked) {
|
|
@@ -6972,13 +7413,18 @@ export class RunManager {
|
|
|
6972
7413
|
const lease = this.chainRepoRoot();
|
|
6973
7414
|
let outcome;
|
|
6974
7415
|
try {
|
|
6975
|
-
|
|
7416
|
+
const pending = await hasUnlanded(this.repoRoot);
|
|
7417
|
+
if (!canLand())
|
|
7418
|
+
return superseded;
|
|
7419
|
+
if (!pending)
|
|
6976
7420
|
return { outcome: 'nothing', message: 'nothing to commit' };
|
|
6977
7421
|
outcome = await this.landNow(runId, policy);
|
|
6978
7422
|
}
|
|
6979
7423
|
finally {
|
|
6980
7424
|
lease.release();
|
|
6981
7425
|
}
|
|
7426
|
+
if (!canLand())
|
|
7427
|
+
return superseded;
|
|
6982
7428
|
if (outcome.result === 'failed') {
|
|
6983
7429
|
// Help rather than refuse: the session is gone, so reopen the task with the error.
|
|
6984
7430
|
const reopened = this.continueRun(runId, { text: landFailurePrompt(outcome) });
|
|
@@ -6987,7 +7433,7 @@ export class RunManager {
|
|
|
6987
7433
|
: { outcome: 'failed', message: `${outcome.stage} failed: ${this.store.redactRunText(runId, outcome.error).split('\n')[0]}` };
|
|
6988
7434
|
}
|
|
6989
7435
|
if (run.status !== 'done') {
|
|
6990
|
-
this.store.updateRun(runId, { status: 'done', error: undefined });
|
|
7436
|
+
this.store.updateRun(runId, { status: 'done', completionReason: 'accepted', error: undefined });
|
|
6991
7437
|
this.store.appendEvent(runId, { type: 'lifecycle', message: 'changes landed' });
|
|
6992
7438
|
}
|
|
6993
7439
|
return landAnswer(outcome, base, false);
|
|
@@ -6995,22 +7441,18 @@ export class RunManager {
|
|
|
6995
7441
|
/** Accept an in-place run resting at `review`: land it when the project auto-lands, else the
|
|
6996
7442
|
* ordinary accept. */
|
|
6997
7443
|
async finishReview(runId) {
|
|
6998
|
-
|
|
6999
|
-
const after = this.store.getRun(runId);
|
|
7000
|
-
if (after?.status === 'review' && !(await this.landingPolicy(after, await loadConfig(this.repoRoot)))) {
|
|
7001
|
-
this.store.updateRun(runId, { status: 'done' });
|
|
7002
|
-
this.store.appendEvent(runId, { type: 'lifecycle', message: 'review accepted — finished without a PR' });
|
|
7003
|
-
}
|
|
7004
|
-
}
|
|
7005
|
-
/**
|
|
7006
|
-
* Finish on a run resting at `review` with unlanded in-place changes: land them, then `done`.
|
|
7007
|
-
* Refused while another task works in the checkout — it would commit that task's edits too.
|
|
7008
|
-
*/
|
|
7009
|
-
async landReviewed(runId) {
|
|
7444
|
+
const canLand = this.landingFence(runId);
|
|
7010
7445
|
const run = this.store.getRun(runId);
|
|
7011
|
-
|
|
7012
|
-
if (!policy)
|
|
7446
|
+
if (run?.status !== 'review' || !canLand())
|
|
7013
7447
|
return;
|
|
7448
|
+
const policy = await this.landingPolicy(run, await loadConfig(this.repoRoot));
|
|
7449
|
+
if (!canLand())
|
|
7450
|
+
return;
|
|
7451
|
+
if (!policy) {
|
|
7452
|
+
this.store.updateRun(runId, { status: 'done', completionReason: 'accepted' });
|
|
7453
|
+
this.store.appendEvent(runId, { type: 'lifecycle', message: 'review accepted — finished without a PR' });
|
|
7454
|
+
return;
|
|
7455
|
+
}
|
|
7014
7456
|
if (this.repoRootBusy > 0) {
|
|
7015
7457
|
this.store.appendEvent(runId, {
|
|
7016
7458
|
type: 'note',
|
|
@@ -7026,6 +7468,8 @@ export class RunManager {
|
|
|
7026
7468
|
finally {
|
|
7027
7469
|
lease.release();
|
|
7028
7470
|
}
|
|
7471
|
+
if (!canLand())
|
|
7472
|
+
return;
|
|
7029
7473
|
if (outcome.result === 'failed') {
|
|
7030
7474
|
this.store.appendEvent(runId, {
|
|
7031
7475
|
type: 'note',
|
|
@@ -7033,7 +7477,7 @@ export class RunManager {
|
|
|
7033
7477
|
});
|
|
7034
7478
|
return;
|
|
7035
7479
|
}
|
|
7036
|
-
this.store.updateRun(runId, { status: 'done' });
|
|
7480
|
+
this.store.updateRun(runId, { status: 'done', completionReason: 'accepted' });
|
|
7037
7481
|
this.store.appendEvent(runId, { type: 'lifecycle', message: 'review accepted — changes landed' });
|
|
7038
7482
|
}
|
|
7039
7483
|
/**
|
|
@@ -7042,11 +7486,12 @@ export class RunManager {
|
|
|
7042
7486
|
* than wearing a success badge. Answers the failure message, or undefined.
|
|
7043
7487
|
*/
|
|
7044
7488
|
async landBeforeSettle(runId) {
|
|
7489
|
+
const canLand = this.landingFence(runId);
|
|
7045
7490
|
const run = this.store.getRun(runId);
|
|
7046
7491
|
if (!run || run.worktree !== false || run.readOnly)
|
|
7047
7492
|
return undefined;
|
|
7048
7493
|
const policy = await this.landingPolicy(run, await loadConfig(this.repoRoot));
|
|
7049
|
-
if (!policy || !(await hasUnlanded(this.repoRoot)))
|
|
7494
|
+
if (!canLand() || !policy || !(await hasUnlanded(this.repoRoot)) || !canLand())
|
|
7050
7495
|
return undefined;
|
|
7051
7496
|
// Only an autonomous run or the user's Finish may land; anything else rests at review.
|
|
7052
7497
|
const state = this.active.get(runId);
|
|
@@ -7446,19 +7891,20 @@ export class RunManager {
|
|
|
7446
7891
|
const minutes = this.semaphore.monitoringWakeIntervalMinutes();
|
|
7447
7892
|
if (minutes === null) {
|
|
7448
7893
|
this.clearMonitoringWakeTimer(state, runId);
|
|
7894
|
+
// Reconcile can be reached on any pump, so arm only a park that has none — a pump must not
|
|
7895
|
+
// push the liveness deadline out from under an already-bounded park.
|
|
7896
|
+
if (!state.monitoringLivenessTimer)
|
|
7897
|
+
this.armMonitoringLivenessTimer(runId, state);
|
|
7449
7898
|
return;
|
|
7450
7899
|
}
|
|
7451
7900
|
if ((state.monitoringWakeups ?? 0) >= MAX_AUTO_CONTINUES) {
|
|
7452
7901
|
this.clearMonitoringWakeTimer(state, runId);
|
|
7453
|
-
|
|
7454
|
-
this.store.updateRun(runId, { monitoringWakeCapReached: true });
|
|
7455
|
-
this.store.appendEvent(runId, {
|
|
7456
|
-
type: 'note',
|
|
7457
|
-
message: `automatic monitoring wake-up cap reached (${MAX_AUTO_CONTINUES}); session remains parked`,
|
|
7458
|
-
});
|
|
7459
|
-
}
|
|
7902
|
+
this.monitoringWakeCapReached(runId, state);
|
|
7460
7903
|
return;
|
|
7461
7904
|
}
|
|
7905
|
+
// Below the cap an interval IS the exit, so a configured run must not also carry the liveness
|
|
7906
|
+
// bound; see `armMonitoringLivenessTimer` for why the two cannot coexist.
|
|
7907
|
+
this.clearMonitoringLivenessTimer(state);
|
|
7462
7908
|
if (state.monitoringWakeTimer && state.monitoringWakeIntervalMinutes === minutes)
|
|
7463
7909
|
return;
|
|
7464
7910
|
this.clearMonitoringWakeTimer(state, runId);
|
|
@@ -7471,13 +7917,18 @@ export class RunManager {
|
|
|
7471
7917
|
this.store.updateRun(runId, { monitoringWakeAt: undefined });
|
|
7472
7918
|
if (!this.monitoring.has(runId) || !state.session?.open || state.cancelled)
|
|
7473
7919
|
return;
|
|
7920
|
+
// A dispatched child's settle report wakes this run on its own; a blind re-check while
|
|
7921
|
+
// one is still in flight is a model turn that can only re-park.
|
|
7922
|
+
if (this.hasInFlightChildren(runId)) {
|
|
7923
|
+
this.armMonitoringWakeTimer(runId, state);
|
|
7924
|
+
// The child's report is what wakes this run; the re-armed timer is a fallback, so the
|
|
7925
|
+
// cockpit must not promise a scheduled check that a report will pre-empt.
|
|
7926
|
+
this.store.updateRun(runId, { monitoringWakeAt: undefined });
|
|
7927
|
+
return;
|
|
7928
|
+
}
|
|
7474
7929
|
const wakeups = state.monitoringWakeups ?? 0;
|
|
7475
7930
|
if (wakeups >= MAX_AUTO_CONTINUES) {
|
|
7476
|
-
this.
|
|
7477
|
-
this.store.appendEvent(runId, {
|
|
7478
|
-
type: 'note',
|
|
7479
|
-
message: `automatic monitoring wake-up cap reached (${MAX_AUTO_CONTINUES}); session remains parked`,
|
|
7480
|
-
});
|
|
7931
|
+
this.monitoringWakeCapReached(runId, state);
|
|
7481
7932
|
return;
|
|
7482
7933
|
}
|
|
7483
7934
|
state.monitoringWakeups = wakeups + 1;
|
|
@@ -7497,6 +7948,90 @@ export class RunManager {
|
|
|
7497
7948
|
if (runId)
|
|
7498
7949
|
this.store.updateRun(runId, { monitoringWakeAt: undefined });
|
|
7499
7950
|
}
|
|
7951
|
+
/**
|
|
7952
|
+
* The wake-up cap is a lifetime budget: only a user message (`sendMessage`) refills it. At the
|
|
7953
|
+
* cap a run with a dispatched child still in flight stays parked for that child's report;
|
|
7954
|
+
* any other run is handed to the user. That stay must still be bounded: a child that settles
|
|
7955
|
+
* without delivering (cancelled from the queue) would otherwise leave the run with no timer.
|
|
7956
|
+
*/
|
|
7957
|
+
monitoringWakeCapReached(runId, state) {
|
|
7958
|
+
const awaitsChildren = this.hasInFlightChildren(runId);
|
|
7959
|
+
if (!this.store.getRun(runId)?.monitoringWakeCapReached) {
|
|
7960
|
+
this.store.updateRun(runId, { monitoringWakeCapReached: true });
|
|
7961
|
+
if (awaitsChildren) {
|
|
7962
|
+
this.store.appendEvent(runId, {
|
|
7963
|
+
type: 'note',
|
|
7964
|
+
message: `automatic monitoring wake-up cap reached (${MAX_AUTO_CONTINUES}); session remains parked for its dispatched tasks' reports`,
|
|
7965
|
+
});
|
|
7966
|
+
}
|
|
7967
|
+
}
|
|
7968
|
+
if (!awaitsChildren) {
|
|
7969
|
+
this.parkMonitorAsWaiting(runId, state, `automatic monitoring wake-up cap reached (${MAX_AUTO_CONTINUES}); parked for your reply`);
|
|
7970
|
+
return;
|
|
7971
|
+
}
|
|
7972
|
+
// The cap spends the interval's exit, so the liveness bound returns as the last-resort
|
|
7973
|
+
// hand-off. Arm only when none is set, so a routine pump cannot push the deadline out.
|
|
7974
|
+
if (!state.monitoringLivenessTimer)
|
|
7975
|
+
this.armMonitoringLivenessTimer(runId, state, true);
|
|
7976
|
+
}
|
|
7977
|
+
armMonitoringLivenessTimer(runId, state, atCap = false) {
|
|
7978
|
+
this.clearMonitoringLivenessTimer(state);
|
|
7979
|
+
state.monitoringLivenessAtCap = atCap;
|
|
7980
|
+
// With a wake interval configured, a wake-up turn re-parks and resets this timer, so at the
|
|
7981
|
+
// interval's maximum (60m) the two would fire together and the liveness hand-off would win —
|
|
7982
|
+
// disabling the configured re-checks. Liveness therefore bounds only a park-mode (null) run;
|
|
7983
|
+
// at the wake-up cap (`atCap`) those re-checks no longer fire, so it is an exit again.
|
|
7984
|
+
if (!atCap && this.semaphore.monitoringWakeIntervalMinutes() !== null)
|
|
7985
|
+
return;
|
|
7986
|
+
const timeoutMinutes = this.semaphore.idleTimeoutMinutes();
|
|
7987
|
+
const timeoutMs = timeoutMinutes === null || timeoutMinutes === 0
|
|
7988
|
+
? MONITORING_LIVENESS_MS
|
|
7989
|
+
: 4 * timeoutMinutes * 60_000;
|
|
7990
|
+
state.monitoringLivenessTimer = setTimeout(() => {
|
|
7991
|
+
state.monitoringLivenessTimer = undefined;
|
|
7992
|
+
if (!this.monitoring.has(runId) || !state.session?.open || state.cancelled)
|
|
7993
|
+
return;
|
|
7994
|
+
if (this.hasInFlightChildren(runId)) {
|
|
7995
|
+
// A child still in flight outlives this window; carry the cap override into the re-arm, or
|
|
7996
|
+
// the interval guard above would leave the run with no timer at all.
|
|
7997
|
+
this.armMonitoringLivenessTimer(runId, state, state.monitoringLivenessAtCap === true);
|
|
7998
|
+
return;
|
|
7999
|
+
}
|
|
8000
|
+
this.parkMonitorAsWaiting(runId, state, `monitoring with no activity for ${Math.round(timeoutMs / 60_000)}m; parked for your reply`);
|
|
8001
|
+
}, timeoutMs);
|
|
8002
|
+
state.monitoringLivenessTimer.unref?.();
|
|
8003
|
+
}
|
|
8004
|
+
clearMonitoringLivenessTimer(state) {
|
|
8005
|
+
if (state.monitoringLivenessTimer)
|
|
8006
|
+
clearTimeout(state.monitoringLivenessTimer);
|
|
8007
|
+
state.monitoringLivenessTimer = undefined;
|
|
8008
|
+
state.monitoringLivenessAtCap = undefined;
|
|
8009
|
+
}
|
|
8010
|
+
hasInFlightChildren(runId) {
|
|
8011
|
+
return inFlightChildren(this.store.listRuns(), runId).length > 0;
|
|
8012
|
+
}
|
|
8013
|
+
/**
|
|
8014
|
+
* Turn a monitoring park into a `waiting` park: attention raised, idle timer armed if enabled,
|
|
8015
|
+
* session left open so a reply still lands in it. Parked like a `CEZ:ASK` (`askPark`), so a
|
|
8016
|
+
* hand-off nobody answers settles `failed` with Continue when the idle timer closes it.
|
|
8017
|
+
*/
|
|
8018
|
+
parkMonitorAsWaiting(runId, state, message) {
|
|
8019
|
+
if (!this.monitoring.has(runId) || !state.session?.open || state.cancelled)
|
|
8020
|
+
return;
|
|
8021
|
+
this.leaveMonitoring(runId);
|
|
8022
|
+
this.clearMonitoringWakeTimer(state, runId);
|
|
8023
|
+
state.askPark = 'waiting';
|
|
8024
|
+
state.monitorHandoff = true;
|
|
8025
|
+
this.store.updateRun(runId, { status: 'waiting', activity: undefined, askParked: true });
|
|
8026
|
+
if (state.currentStepId)
|
|
8027
|
+
this.store.updateStep(runId, state.currentStepId, { status: 'waiting' });
|
|
8028
|
+
this.store.appendEvent(runId, { type: 'note', message });
|
|
8029
|
+
// Deferred past a turn-end handler that re-parked straight into the cap, so this line follows
|
|
8030
|
+
// its `turn complete — status=monitoring` heartbeat instead of preceding it.
|
|
8031
|
+
queueMicrotask(() => appendHandoffHeartbeat(this.dataDir, runId, 'monitoring ended — status=waiting'));
|
|
8032
|
+
this.armIdleTimer(runId, state);
|
|
8033
|
+
this.releaseSlot();
|
|
8034
|
+
}
|
|
7500
8035
|
/** Autosave-commit the worktree every 90 s while the run lives (spec 006).
|
|
7501
8036
|
* Opt-in via CEZ_AUTOSAVE=1 (#471) — see periodicAutosaveEnabled. */
|
|
7502
8037
|
armAutosave(runId, state) {
|