@kabmo-labs/kabmo 0.42.0 → 0.42.2
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/dist/client/index.html +1 -1
- package/dist/client/index.js +592 -593
- package/dist/client/static/js/{CsvGrid-20k047ht.js → CsvGrid-g6rek8y9.js} +1 -1
- package/dist/client/static/js/{DocxView-qpvhfcmg.js → DocxView-41t9ryws.js} +2 -2
- package/dist/client/static/js/{DrawioView-178skky8.js → DrawioView-mfxhfz1h.js} +1 -1
- package/dist/client/static/js/{ImageView-460th5qa.js → ImageView-bxqw3t4k.js} +1 -1
- package/dist/client/static/js/{LayoutWrapper-5cv0dty8.js → LayoutWrapper-zt14rv9m.js} +2 -2
- package/dist/client/static/js/{Modal-wks6p4r5.js → Modal-cm35g20x.js} +10 -10
- package/dist/client/static/js/{PdfView-y51g03nr.js → PdfView-bek8k888.js} +1 -1
- package/dist/client/static/js/{SessionsView-rsmvn7ks.js → SessionsView-gn53zyn7.js} +1 -1
- package/dist/client/static/js/{SheetView-z7yvb05v.js → SheetView-vezssf6b.js} +1 -1
- package/dist/client/static/js/{SvgPreview-yehgzhem.js → SvgPreview-f1qaw73k.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-6zxpcy8b.js → abnfDiagram-O67JEVCF-4qn94h52.js} +1 -1
- package/dist/client/static/js/architecture-7GRP2DOG-cagtcfhk.js +1 -0
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-m98sgh3c.js → architectureDiagram-NJMV4G6O-tbewzdya.js} +3 -3
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-cp7rervg.js → blockDiagram-BEXU5L5S-njgnwckz.js} +2 -2
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-t31recqm.js → c4Diagram-YGBWAQC7-f58pcvbk.js} +1 -1
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-fy8x3dkx.js → classDiagram-v2-NBCMYWYE-52g73vyw.js} +3 -3
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-va7ybm9e.js → cose-bilkent-JH36ORCC-ptdnshzh.js} +1 -1
- package/dist/client/static/js/cynefin-OW5HDTMX-6g2ydrss.js +1 -0
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-4k0k429c.js → cynefinDiagram-VND7K2PF-qabfdkzr.js} +1 -1
- package/dist/client/static/js/{dagre-6A5THRUB-ykdhxq6t.js → dagre-6A5THRUB-kyf5jetf.js} +2 -2
- package/dist/client/static/js/{diagram-22UHCM2B-5nvwx7b6.js → diagram-22UHCM2B-bxrsjtv9.js} +4 -4
- package/dist/client/static/js/{diagram-3UASUU5V-hc7zsjgw.js → diagram-3UASUU5V-0f41s00j.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-97ae07y7.js → diagram-ATOU4E4O-0z1zx9h1.js} +1 -1
- package/dist/client/static/js/{diagram-CDSNMT55-b56nnbbs.js → diagram-CDSNMT55-znrmr6bk.js} +3 -3
- package/dist/client/static/js/{diagram-MLGK6HIB-37rygr9k.js → diagram-MLGK6HIB-jfe2jhk0.js} +1 -1
- package/dist/client/static/js/{diagram-MPIPVDR6-wv3vhhfk.js → diagram-MPIPVDR6-2kaawmwa.js} +1 -1
- package/dist/client/static/js/{dockerfile-0efb1z6e.js → dockerfile-12exatm9.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-13fv7vxg.js → ebnfDiagram-ZINNZB2B-s5n37rfp.js} +1 -1
- package/dist/client/static/js/{elixir-mabagxwa.js → elixir-szk51ehr.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-xam60ktz.js → elk-276RUBZZ-433rd9fp.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-24ctv2ee.js → erDiagram-OPXOYQCR-key6ah0b.js} +2 -2
- package/dist/client/static/js/eventmodeling-NTZA5JFV-b774qbn2.js +1 -0
- package/dist/client/static/js/flowDiagram-KWPJA3E3-nznq0n36.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-766a8fqw.js → ganttDiagram-FUAMR5RP-4efkhmca.js} +2 -2
- package/dist/client/static/js/gitGraph-4MIJSDKK-b047d6vk.js +1 -0
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-fmwjkgh6.js → gitGraphDiagram-X574FWY7-ac376y2k.js} +1 -1
- package/dist/client/static/js/html-tbz83eke.js +1 -0
- package/dist/client/static/js/{index-13xbwcbz.js → index-02543wk3.js} +1 -1
- package/dist/client/static/js/{index-sx809d6d.js → index-0e9nkc0g.js} +1 -1
- package/dist/client/static/js/{index-1c0pnsjd.js → index-0gbj4270.js} +1 -1
- package/dist/client/static/js/{index-z6kpc98a.js → index-0pabfaac.js} +1 -1
- package/dist/client/static/js/{index-4mstdh41.js → index-1t5ybx9v.js} +1 -1
- package/dist/client/static/js/{index-9vdbnvmk.js → index-1y3rzw6b.js} +1 -1
- package/dist/client/static/js/{index-qj34r6d0.js → index-38xv8h4t.js} +1 -1
- package/dist/client/static/js/{index-4j8rgr4p.js → index-50mdqev0.js} +1 -1
- package/dist/client/static/js/{index-zvazj4va.js → index-5jnvz9hw.js} +1 -1
- package/dist/client/static/js/{index-97qst4k9.js → index-77t0nvt1.js} +1 -1
- package/dist/client/static/js/{index-x7f5ysch.js → index-7a2efrbj.js} +1 -1
- package/dist/client/static/js/{index-yvxa7hd8.js → index-82vk27q1.js} +1 -1
- package/dist/client/static/js/{index-nbexks3x.js → index-8k7vjp8b.js} +1 -1
- package/dist/client/static/js/{index-sq3r1xhf.js → index-8kbp24xg.js} +1 -1
- package/dist/client/static/js/{index-zjydzxhm.js → index-b0v6gwym.js} +2 -2
- package/dist/client/static/js/{index-grczkttn.js → index-b42t14wk.js} +7 -7
- package/dist/client/static/js/{index-13dr1t1r.js → index-cz50ha6x.js} +23 -23
- package/dist/client/static/js/{index-8jqawh3r.js → index-dtj73vs1.js} +1 -1
- package/dist/client/static/js/{index-7t63akyt.js → index-dzmar8jr.js} +1 -1
- package/dist/client/static/js/{index-2x9eqztp.js → index-f33c4paw.js} +1 -1
- package/dist/client/static/js/{index-xxe52zrm.js → index-fb6pw9xb.js} +1 -1
- package/dist/client/static/js/{index-6ge6gk9w.js → index-gp57dx2v.js} +1 -1
- package/dist/client/static/js/{index-2hpy58d0.js → index-gsxebrq9.js} +2 -2
- package/dist/client/static/js/{index-czagykbq.js → index-pxtff3ez.js} +2 -2
- package/dist/client/static/js/{index-8hgm0abr.js → index-pzvr1699.js} +187 -183
- package/dist/client/static/js/{index-dydwcp3n.js → index-r9db1gsf.js} +1 -1
- package/dist/client/static/js/{index-b4y5g48d.js → index-raca8tsh.js} +1 -1
- package/dist/client/static/js/{index-95en3p3g.js → index-rf29f3fq.js} +4 -4
- package/dist/client/static/js/{index-sz3mxjvy.js → index-s4gv0rpk.js} +1 -1
- package/dist/client/static/js/{index-a9t9gdew.js → index-v3f7we4n.js} +4 -4
- package/dist/client/static/js/{index-ejdnjh5c.js → index-yjmm73jm.js} +1 -1
- package/dist/client/static/js/{index-1rxa9zxp.js → index-ykfd2fyj.js} +1 -1
- package/dist/client/static/js/{index-4z4ax55k.js → index-yzda8j2d.js} +6 -6
- package/dist/client/static/js/{index-vcn1kcpy.js → index-z78bzryw.js} +3 -3
- package/dist/client/static/js/{index-tqycj126.js → index-zndbhb9w.js} +1 -1
- package/dist/client/static/js/{index-ka2rc2cr.js → index-zs73zwjz.js} +3 -3
- package/dist/client/static/js/{index-xe5cqwnf.js → index-zs7sjv6x.js} +1 -1
- package/dist/client/static/js/{index-hzwr5fm9.js → index-zw621xez.js} +3 -3
- package/dist/client/static/js/info-A6RAGUB7-n495k952.js +1 -0
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-tqytmzp1.js → infoDiagram-VRGFBTTK-4e7ej63f.js} +2 -2
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-rp77ff6m.js → ishikawaDiagram-OU5B5YK6-k3yet1ec.js} +2 -2
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-c7bxrhf1.js → journeyDiagram-ZHPQQLJL-qe352kyd.js} +2 -2
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-j2pxewqq.js → kanban-definition-PNTS6WVX-58hag75n.js} +4 -4
- package/dist/client/static/js/{mermaid.core-cqqe1krg.js → mermaid.core-6e89h6vm.js} +2 -2
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-s03k32p9.js → mindmap-definition-NLK3R4M7-ncsam2fm.js} +1 -1
- package/dist/client/static/js/one-dark-pro-qmyne0tn.js +1 -0
- package/dist/client/static/js/one-light-dj0ecjcj.js +1 -0
- package/dist/client/static/js/packet-AYTQ26CC-zajj62z6.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-dfg2j0zc.js → pegDiagram-GJSIUBJH-b5ckc39d.js} +1 -1
- package/dist/client/static/js/{perl-5vxax0nr.js → perl-dtn1fccw.js} +1 -1
- package/dist/client/static/js/{php-hgrgdq63.js → php-7av78hch.js} +1 -1
- package/dist/client/static/js/pie-WAS4IAKB-1ve78y5f.js +1 -0
- package/dist/client/static/js/{pieDiagram-5QR66LMP-pshd1j79.js → pieDiagram-5QR66LMP-s4d47ve8.js} +2 -2
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-cvvvmtk2.js → quadrantDiagram-O4NWA36T-zm0ekvjz.js} +1 -1
- package/dist/client/static/js/radar-RG4KPBEZ-8rqadb58.js +1 -0
- package/dist/client/static/js/railroad-74A4TZTK-v6ppm8dy.js +1 -0
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-9j6bae14.js +1 -0
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-56cpyt0g.js +1 -0
- package/dist/client/static/js/railroad-peg-WCYAUIDC-yfdmspf4.js +1 -0
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-h53p3sha.js → railroadDiagram-XR7U4H2S-52vdqf53.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-bdv2fkxd.js → requirementDiagram-PLB6GJNP-7kf8bmk9.js} +1 -1
- package/dist/client/static/js/{ruby-8pxcn21w.js → ruby-s2bqr910.js} +1 -1
- package/dist/client/static/js/{rust-j80dxgjg.js → rust-q98kssv3.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-xqnnvmhy.js → sankeyDiagram-IPEJSGJF-bcb9f54a.js} +1 -1
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-3p67305f.js → sequenceDiagram-PO4LG4MO-76ywvj7g.js} +3 -3
- package/dist/client/static/js/{sizeCapture-INFHLROL-f87525h7.js → sizeCapture-INFHLROL-p9bsf5dc.js} +1 -1
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-e5st1fy3.js → stateDiagram-v2-GCMORJYK-1ecfb3fs.js} +1 -1
- package/dist/client/static/js/{swimlanes-2SLR337P-ceghkbez.js → swimlanes-2SLR337P-2pyjr946.js} +1 -1
- package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-vc8hvfya.js → swimlanesDiagram-TC7HE7FX-qr5hdxm4.js} +1 -1
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-f7evs443.js → timeline-definition-EJHVYXUP-4csxwmn2.js} +3 -3
- package/dist/client/static/js/treeView-Q6P3EWNA-vwpg3wp8.js +1 -0
- package/dist/client/static/js/treemap-WGGIJYW6-htfxwd32.js +1 -0
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-0gpn21p7.js → usecaseDiagram-POWQR4AR-0p1jnbsn.js} +7 -7
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-4spzy428.js → vennDiagram-UO4OBE2U-y1hgdet4.js} +2 -2
- package/dist/client/static/js/{vue-xm1dxpmy.js → vue-cbqm4bed.js} +1 -1
- package/dist/client/static/js/wardley-WFR3VGLG-hapfjkzq.js +1 -0
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-745xr2pa.js → wardleyDiagram-VNRHLVJA-p578yrgm.js} +2 -2
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-7dr9qwx5.js → xychartDiagram-PMCCYNJV-b08b4ah0.js} +3 -3
- package/package.json +1 -1
- package/src/cli/lib/commands/session.js +12 -1
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +14 -123
- package/src/client/components/workspace/chat-timeline/OrchestrationNotice.tsx +214 -0
- package/src/client/components/workspace/chat-timeline/UserTurn.test.tsx +126 -0
- package/src/client/components/workspace/chat-timeline/UserTurn.tsx +183 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolBody.tsx +3 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolRowActions.tsx +45 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/tool-view.ts +14 -4
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Card.tsx +2 -12
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Compact.tsx +42 -38
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Minimal.tsx +25 -21
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Trace.tsx +41 -29
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +47 -43
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/parity.test.tsx +136 -0
- package/src/client/hooks/chat/timeline/composer-modes.ts +10 -7
- package/src/client/hooks/chat/timeline/plan-review-republish.test.ts +121 -0
- package/src/client/hooks/chat/timeline/plan-review.ts +12 -3
- package/src/server/lib/harness/acp/acp-audit.server.ts +1 -1
- package/src/server/lib/harness/acp/session-exit.ts +39 -5
- package/src/server/lib/harness/acp/session-turns.ts +67 -12
- package/src/server/lib/harness/acp/session.test.ts +61 -0
- package/src/server/lib/harness/acp/session.ts +15 -25
- package/src/server/lib/harness/acp/turn-outcome.server.test.ts +97 -0
- package/src/server/lib/harness/acp/turn-outcome.server.ts +71 -0
- package/src/server/lib/harness/acp/turn-silence.ts +52 -0
- package/src/server/lib/harness/acp/turn.test.ts +85 -3
- package/src/server/lib/harness/acp/turn.ts +62 -4
- package/src/server/lib/lifecycle/after-listen.ts +10 -0
- package/src/server/lib/omp/rpc/frame-fold-contract.ts +21 -0
- package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +4 -0
- package/src/server/lib/omp/rpc/frame-fold.ts +25 -2
- package/src/server/lib/omp/rpc/manager.ts +9 -8
- package/src/server/lib/omp/rpc/retry-saga.ts +54 -0
- package/src/server/lib/omp/rpc/run-settle.server.ts +38 -5
- package/src/server/lib/omp/rpc/run-settle.test.ts +5 -2
- package/src/server/lib/omp/rpc/session-commands-dialog.test.ts +6 -20
- package/src/server/lib/omp/rpc/session-commands-mapping.test.ts +131 -0
- package/src/server/lib/omp/rpc/session-commands.test.ts +95 -116
- package/src/server/lib/omp/rpc/session-commands.ts +38 -17
- package/src/server/lib/omp/rpc/terminal-settle.test.ts +223 -0
- package/src/server/lib/omp/rpc/terminal-settle.ts +127 -29
- package/src/server/lib/omp/session/scan.ts +15 -2
- package/src/server/lib/omp/session/session-discovery.test.ts +21 -0
- package/src/server/lib/sessions/notify.server.test.ts +11 -3
- package/src/server/lib/sessions/notify.server.ts +67 -42
- package/src/server/lib/sessions/spawn.server.test.ts +5 -1
- package/src/server/lib/sessions/spawn.server.ts +8 -3
- package/src/server/routes/sessions/answer.test.ts +62 -0
- package/src/server/routes/sessions/answer.ts +13 -2
- package/src/shared/lib/chat/composer/delegation.ts +11 -7
- package/src/shared/lib/chat/export-markdown.ts +19 -0
- package/src/shared/lib/chat/orchestration/notice.test.ts +118 -0
- package/src/shared/lib/chat/orchestration/notice.ts +183 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +6 -1
- package/src/shared/lib/chat/timeline/tool-render-mode.ts +3 -3
- package/src/shared/lib/icons/tint-hues.generated.ts +36 -36
- package/src/shared/lib/omp/session/operator-title.test.ts +21 -0
- package/src/shared/lib/omp/session/operator-title.ts +28 -0
- package/dist/client/static/js/architecture-7GRP2DOG-9q06651f.js +0 -1
- package/dist/client/static/js/cynefin-OW5HDTMX-w7a38g4g.js +0 -1
- package/dist/client/static/js/eventmodeling-NTZA5JFV-6wrjccyw.js +0 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-19vjkg84.js +0 -1
- package/dist/client/static/js/gitGraph-4MIJSDKK-4je2p50v.js +0 -1
- package/dist/client/static/js/html-bwyt0ayy.js +0 -1
- package/dist/client/static/js/info-A6RAGUB7-k0z5qdew.js +0 -1
- package/dist/client/static/js/one-dark-pro-9tt0a020.js +0 -1
- package/dist/client/static/js/one-light-5fg4r0ra.js +0 -1
- package/dist/client/static/js/packet-AYTQ26CC-6cnvmb2z.js +0 -1
- package/dist/client/static/js/pie-WAS4IAKB-m9z1mztn.js +0 -1
- package/dist/client/static/js/radar-RG4KPBEZ-8m9rkex6.js +0 -1
- package/dist/client/static/js/railroad-74A4TZTK-wc55emj8.js +0 -1
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-2y2rnrzq.js +0 -1
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-zzcc9x0v.js +0 -1
- package/dist/client/static/js/railroad-peg-WCYAUIDC-z82na5nb.js +0 -1
- package/dist/client/static/js/treeView-Q6P3EWNA-kzh6cm3f.js +0 -1
- package/dist/client/static/js/treemap-WGGIJYW6-wz5ed560.js +0 -1
- package/dist/client/static/js/wardley-WFR3VGLG-zewbfccz.js +0 -1
|
@@ -40,7 +40,12 @@ import { saveAcpUsage } from '@/server/lib/harness/acp/acp-telemetry.server';
|
|
|
40
40
|
import { lastAssistantText } from '@/server/lib/omp/session/goal-driver.server';
|
|
41
41
|
import { noteChildOutcome } from '@/server/lib/sessions/notify.server';
|
|
42
42
|
import { saveSessionAnswer } from '@/server/lib/sessions/answers.server';
|
|
43
|
+
import { transcriptFailure } from '@/server/lib/harness/acp/turn-outcome.server';
|
|
44
|
+
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
43
45
|
import type { AcpTurns, AcpTurnEndInfo } from '@/server/lib/harness/acp/turn';
|
|
46
|
+
import { driveAcpGoalAfterTurn } from '@/server/lib/harness/acp/acp-goal-driver.server';
|
|
47
|
+
import type { AcpGoalHost } from '@/server/lib/harness/acp/acp-goal.server';
|
|
48
|
+
import { assistantTextOf, spawnsBackgroundWork } from '@/server/lib/harness/acp/background-work';
|
|
44
49
|
|
|
45
50
|
/** What a turn reads and moves on the session. */
|
|
46
51
|
export interface AcpTurnTarget {
|
|
@@ -59,6 +64,35 @@ export interface AcpTurnTarget {
|
|
|
59
64
|
send(command: Record<string, unknown>): Promise<unknown>;
|
|
60
65
|
}
|
|
61
66
|
|
|
67
|
+
/** What the turn-end bookkeeping moves on the session. */
|
|
68
|
+
export interface AcpTurnEndHost
|
|
69
|
+
extends Omit<AcpTurnTarget, 'runModel' | 'sessionId' | 'isAlive' | 'isBusy' | 'send'>, AcpGoalHost {
|
|
70
|
+
assistantCount: number;
|
|
71
|
+
usage: { endTurn(): void };
|
|
72
|
+
background: { start(baseline: string): void };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Everything a turn's END moves: the closed message, the durable marker, the
|
|
77
|
+
* queue, the child outcome, the background probe and the goal driver.
|
|
78
|
+
*
|
|
79
|
+
* A turn closed by the SILENCE CEILING is interrupted, not failed — nothing
|
|
80
|
+
* observed it fail — and its reason still travels so a coordinator can act.
|
|
81
|
+
*/
|
|
82
|
+
export function endAcpTurn(host: AcpTurnEndHost, info: AcpTurnEndInfo): Promise<void> {
|
|
83
|
+
if (info.closedMessage) host.assistantCount += 1;
|
|
84
|
+
host.usage.endTurn();
|
|
85
|
+
const reported = settleAcpTurn(host, info);
|
|
86
|
+
// A subagent outlives the turn that spawned it: antigravity answers
|
|
87
|
+
// `end_turn` right after `invoke_subagent`, and its completion is held until
|
|
88
|
+
// the next request (upstream #1461). Probe the transcript instead.
|
|
89
|
+
if (!info.cancelled && info.failed !== true && spawnsBackgroundWork(info.message)) {
|
|
90
|
+
host.background.start(assistantTextOf(info.message));
|
|
91
|
+
}
|
|
92
|
+
void driveAcpGoalAfterTurn(host, info.message, { cancelled: info.cancelled === true }).catch(() => {});
|
|
93
|
+
return reported;
|
|
94
|
+
}
|
|
95
|
+
|
|
62
96
|
/** Open a turn and mark the run live. Returns the ACK, never the turn. */
|
|
63
97
|
export function beginAcpTurn(
|
|
64
98
|
target: AcpTurnTarget,
|
|
@@ -73,7 +107,10 @@ export function beginAcpTurn(
|
|
|
73
107
|
}
|
|
74
108
|
|
|
75
109
|
/** Turn-end bookkeeping: the closed message, the badge, then the queue. */
|
|
76
|
-
export function settleAcpTurn(
|
|
110
|
+
export async function settleAcpTurn(
|
|
111
|
+
target: AcpTurnTarget & { harness: HarnessId },
|
|
112
|
+
info: AcpTurnEndInfo,
|
|
113
|
+
): Promise<void> {
|
|
77
114
|
if (info.closedMessage) target.messageCount += 1;
|
|
78
115
|
// ACP has no transcript to re-read, so the last usage snapshot is what lets
|
|
79
116
|
// the Context ring answer after a reload or a restart.
|
|
@@ -86,30 +123,48 @@ export function settleAcpTurn(target: AcpTurnTarget, info: AcpTurnEndInfo): void
|
|
|
86
123
|
totalCost: target.totalCost,
|
|
87
124
|
runModel: target.runModel,
|
|
88
125
|
});
|
|
126
|
+
// A turn the envelope calls COMPLETED may still have failed: `omp-acp` answers
|
|
127
|
+
// a provider error as ordinary text and ends the turn normally, so its own
|
|
128
|
+
// transcript is the only record of the failure (see `turn-outcome.server.ts`).
|
|
129
|
+
const recorded = info.failed === true || info.cancelled === true || info.stranded === true
|
|
130
|
+
? null
|
|
131
|
+
: await transcriptFailure(target.harness, target.sessionId);
|
|
132
|
+
// A turn closed by the silence ceiling is INTERRUPTED, not failed: nothing
|
|
133
|
+
// observed it fail, and the reason still travels so the coordinator can act.
|
|
134
|
+
const status = info.cancelled === true || info.stranded === true
|
|
135
|
+
? 'interrupted'
|
|
136
|
+
: info.failed === true || recorded !== null
|
|
137
|
+
? 'failed'
|
|
138
|
+
: 'completed';
|
|
89
139
|
// A cancelled turn is an `abort` badge; every other ending a `finish` — and a
|
|
90
140
|
// failed turn carries the agent's own reason, which is the only copy a tab
|
|
91
141
|
// that never opened the session can read.
|
|
92
|
-
const failure =
|
|
93
|
-
? (info.failure?.trim() || 'The agent ended the turn without an answer')
|
|
142
|
+
const failure = status === 'failed'
|
|
143
|
+
? (info.failure?.trim() || recorded || 'The agent ended the turn without an answer')
|
|
94
144
|
: null;
|
|
95
145
|
target.markStream(info.stopReason === 'cancelled' ? 'abort' : 'finish', failure);
|
|
96
146
|
// Todo/plan/telemetry panels read their own topics; without this signal an
|
|
97
147
|
// ACP turn's usage and titles never republished (the RPC settle path does it).
|
|
98
148
|
emitRealtimeSignal('session-data-dirty', target.sessionId);
|
|
99
149
|
const finalText = lastAssistantText([info.message]);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
void noteChildOutcome({
|
|
150
|
+
// Only a real answer is stored as one: on a failed turn the text IS the
|
|
151
|
+
// error, and `session_answers` is what `kabmo session output` prints.
|
|
152
|
+
if (finalText && status === 'completed') {
|
|
153
|
+
void saveSessionAnswer(target.sessionId, finalText).catch(() => {});
|
|
154
|
+
}
|
|
155
|
+
const reported = noteChildOutcome({
|
|
107
156
|
sessionId: target.sessionId,
|
|
108
157
|
status,
|
|
109
|
-
|
|
110
|
-
|
|
158
|
+
// A failed turn's text is the error, not a report: the reason is the detail.
|
|
159
|
+
output: status === 'completed' ? finalText : null,
|
|
160
|
+
...(status === 'failed'
|
|
161
|
+
? { failure: failure as string }
|
|
162
|
+
: status === 'interrupted' && info.stranded === true
|
|
163
|
+
? { failure: info.failure ?? 'The agent stopped reporting progress.' }
|
|
164
|
+
: {}),
|
|
111
165
|
}).catch((error: unknown) => {
|
|
112
166
|
console.error('[sessions] could not record an ACP child outcome:', error);
|
|
113
167
|
});
|
|
114
168
|
scheduleQueueDelivery(target);
|
|
169
|
+
return reported;
|
|
115
170
|
}
|
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
15
15
|
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
16
16
|
import { mountSession, notify } from '@/server/lib/harness/acp/session.test-util';
|
|
17
|
+
import { createSessionRelation } from '@/server/lib/sessions/relations.server';
|
|
18
|
+
import { materializeNotice } from '@/server/lib/sessions/notify.server';
|
|
19
|
+
import {
|
|
20
|
+
parseChildOutcomeNotice,
|
|
21
|
+
parseOrchestrationBlock,
|
|
22
|
+
} from '@/shared/lib/chat/orchestration/notice';
|
|
17
23
|
import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
|
|
18
24
|
|
|
19
25
|
// A prompt reaches the title writer (`harness/session-title.server.ts`), which
|
|
@@ -231,3 +237,58 @@ describe('ACP model identity', () => {
|
|
|
231
237
|
});
|
|
232
238
|
});
|
|
233
239
|
});
|
|
240
|
+
|
|
241
|
+
describe('a delegated ACP worker reports its outcome', () => {
|
|
242
|
+
/** The exit hook is private; the suite drives it the way the process does. */
|
|
243
|
+
function exit(
|
|
244
|
+
session: ReturnType<typeof mountSession>['session'],
|
|
245
|
+
stderrTail: string,
|
|
246
|
+
): Promise<void> {
|
|
247
|
+
return (session as unknown as { onExit: (info: { code: number | null; stderrTail: string }) => Promise<void> })
|
|
248
|
+
.onExit({ code: 1, stderrTail });
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
test('a process that dies mid-turn tells its coordinator, with the stderr tail', async () => {
|
|
252
|
+
const { session, turn } = mountSession();
|
|
253
|
+
await createSessionRelation({ sessionId: 'acp-1', parentSessionId: 'parent-acp' });
|
|
254
|
+
await session.send({ type: 'prompt', message: 'do the work' });
|
|
255
|
+
await turn.started;
|
|
256
|
+
|
|
257
|
+
await exit(session, 'Error: provider exploded');
|
|
258
|
+
|
|
259
|
+
const text = await materializeNotice('parent-acp');
|
|
260
|
+
expect(text).not.toBeNull();
|
|
261
|
+
const block = parseOrchestrationBlock(text ?? '');
|
|
262
|
+
const [entry] = parseChildOutcomeNotice(block?.body ?? '');
|
|
263
|
+
expect(entry?.status).toBe('failed');
|
|
264
|
+
expect(entry?.failure).toContain('provider exploded');
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test('a turn closed by the silence ceiling is interrupted, with its reason', async () => {
|
|
268
|
+
const { session } = mountSession();
|
|
269
|
+
await createSessionRelation({ sessionId: 'acp-1', parentSessionId: 'parent-acp' });
|
|
270
|
+
|
|
271
|
+
await session.onTurnEnded({
|
|
272
|
+
closedMessage: false,
|
|
273
|
+
stranded: true,
|
|
274
|
+
failed: true,
|
|
275
|
+
failure: 'The agent stopped reporting progress; the turn was closed after a long silence.',
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const text = await materializeNotice('parent-acp');
|
|
279
|
+
const block = parseOrchestrationBlock(text ?? '');
|
|
280
|
+
const [entry] = parseChildOutcomeNotice(block?.body ?? '');
|
|
281
|
+
// Nothing observed it fail, so it is not reported as a failure.
|
|
282
|
+
expect(entry?.status).toBe('interrupted');
|
|
283
|
+
expect(entry?.failure).toContain('stopped reporting');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test('a process that exits between turns reports nothing', async () => {
|
|
287
|
+
const { session } = mountSession();
|
|
288
|
+
await createSessionRelation({ sessionId: 'acp-1', parentSessionId: 'parent-acp' });
|
|
289
|
+
|
|
290
|
+
await exit(session, 'Error: idle crash');
|
|
291
|
+
|
|
292
|
+
expect(await materializeNotice('parent-acp')).toBeNull();
|
|
293
|
+
});
|
|
294
|
+
});
|
|
@@ -29,22 +29,19 @@ import { startAcpSession } from '@/server/lib/harness/acp/session-start';
|
|
|
29
29
|
import type { AcpConfigOption, AcpId, AcpProtocolVersion, AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
|
|
30
30
|
import { promptBlocks } from '@/server/lib/harness/acp/prompt';
|
|
31
31
|
import { setAcpConfig, setAcpMode, settlePermissionDialog, stampMessageModel } from '@/server/lib/harness/acp/session-config';
|
|
32
|
-
import { beginAcpTurn,
|
|
33
|
-
import { driveAcpGoalAfterTurn } from '@/server/lib/harness/acp/acp-goal-driver.server';
|
|
32
|
+
import { beginAcpTurn, endAcpTurn } from '@/server/lib/harness/acp/session-turns';
|
|
34
33
|
import { capabilitiesFrom } from '@/server/lib/harness/launch';
|
|
35
34
|
import { PendingPermissions } from '@/server/lib/harness/acp/permissions';
|
|
36
35
|
import { cancelAllAcpPermissions } from '@/server/lib/harness/acp/session-permissions';
|
|
37
36
|
import { handleSessionNotification } from '@/server/lib/harness/acp/session-notifications';
|
|
38
37
|
import { AcpUsageMeter, type AcpContextUsage } from '@/server/lib/harness/acp/session-usage';
|
|
39
38
|
import { handleAcpClientRequest, handleAcpCancelRequest, type AcpClientRequestAnswer } from '@/server/lib/harness/acp/session-requests';
|
|
40
|
-
import {
|
|
39
|
+
import { reportAcpExit } from '@/server/lib/harness/acp/session-exit';
|
|
41
40
|
import { SessionListeners } from '@/server/lib/harness/acp/session-listeners';
|
|
42
41
|
import {
|
|
43
42
|
AcpBackgroundProbe,
|
|
44
43
|
BACKGROUND_LOAD_TIMEOUT_MS,
|
|
45
|
-
assistantTextOf,
|
|
46
44
|
deliverBackgroundNotice,
|
|
47
|
-
spawnsBackgroundWork,
|
|
48
45
|
} from '@/server/lib/harness/acp/background-work';
|
|
49
46
|
import { acpWebState } from '@/server/lib/harness/acp/session-web-state';
|
|
50
47
|
import { acpIdleReaper } from '@/server/lib/harness/acp/session-idle';
|
|
@@ -79,7 +76,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
79
76
|
/** Assistant messages the mapper closed, for the same panel. */
|
|
80
77
|
assistantCount = 0;
|
|
81
78
|
/** The last `usage_update` the agent reported, or null when it never did. */
|
|
82
|
-
|
|
79
|
+
readonly usage = new AcpUsageMeter();
|
|
83
80
|
get contextUsage(): AcpContextUsage | null { return this.usage.contextUsage; }
|
|
84
81
|
get totalCost(): number { return this.usage.totalCost; }
|
|
85
82
|
get usageTokens(): number { return this.usage.usageTokens; }
|
|
@@ -97,7 +94,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
97
94
|
/** The quiet-window reclaim; the rules live in `session-idle.ts`. */
|
|
98
95
|
readonly idle: IdleReaper;
|
|
99
96
|
/** Watches for work that finishes after `end_turn`; see `background-work.ts`. */
|
|
100
|
-
|
|
97
|
+
readonly background: AcpBackgroundProbe;
|
|
101
98
|
private readonly mapper = new AcpFrameMapper();
|
|
102
99
|
private readonly events = new SessionListeners();
|
|
103
100
|
readonly permissions = new PendingPermissions();
|
|
@@ -210,20 +207,10 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
210
207
|
void markStreamStatus(this.sessionId, status, status === 'stream' ? this.runModel : undefined, failure).catch(() => {});
|
|
211
208
|
};
|
|
212
209
|
|
|
213
|
-
/** Turn-end bookkeeping the panels read — see `
|
|
214
|
-
*
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (info.closedMessage) this.assistantCount += 1;
|
|
218
|
-
this.usage.endTurn();
|
|
219
|
-
settleAcpTurn(this, info);
|
|
220
|
-
// A subagent outlives the turn that spawned it: antigravity answers
|
|
221
|
-
// `end_turn` right after `invoke_subagent`, and its completion is held
|
|
222
|
-
// until the next request (upstream #1461). Probe the transcript instead.
|
|
223
|
-
if (!info.cancelled && info.failed !== true && spawnsBackgroundWork(info.message)) {
|
|
224
|
-
this.background.start(assistantTextOf(info.message));
|
|
225
|
-
}
|
|
226
|
-
void driveAcpGoalAfterTurn(this, info.message, { cancelled: info.cancelled === true }).catch(() => {});
|
|
210
|
+
/** Turn-end bookkeeping the panels read — see `endAcpTurn`. Returns the
|
|
211
|
+
* child-outcome write, so a caller that must observe it can await it. */
|
|
212
|
+
onTurnEnded(info: AcpTurnEndInfo): Promise<void> {
|
|
213
|
+
return endAcpTurn(this, info);
|
|
227
214
|
}
|
|
228
215
|
|
|
229
216
|
/** Dispatcher seam: stop the turn and answer every parked approval. */
|
|
@@ -292,6 +279,9 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
292
279
|
private onNotification(method: string, params: Record<string, unknown>): void {
|
|
293
280
|
// A long turn emits no commands but plenty of `session/update` frames.
|
|
294
281
|
this.idle.reset();
|
|
282
|
+
// The same frames are the only evidence a turn is still alive: ACP has no
|
|
283
|
+
// probe, so the silence ceiling is what bounds a wedged agent.
|
|
284
|
+
this.turns.noteActivity();
|
|
295
285
|
// `$/cancel_request` names an agent→client request the agent no longer
|
|
296
286
|
// wants; the approval it parks is answered `cancelled`.
|
|
297
287
|
if (handleAcpCancelRequest(this, method, params)) return;
|
|
@@ -313,14 +303,14 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
313
303
|
return handleAcpClientRequest(this, id, method, params);
|
|
314
304
|
}
|
|
315
305
|
|
|
316
|
-
|
|
306
|
+
/** The agent's process is gone — see `reportAcpExit`; returns its notice write. */
|
|
307
|
+
private onExit(info: { code: number | null; stderrTail: string }): Promise<void> {
|
|
317
308
|
this.destroyed = true;
|
|
318
309
|
this.background.stop();
|
|
319
310
|
this.idle.stop();
|
|
320
|
-
|
|
321
|
-
for (const event of acpExitFailureFrames(this.harness, info)) this.emit(event);
|
|
322
|
-
}
|
|
311
|
+
const reported = this.closing ? Promise.resolve() : reportAcpExit(this, info);
|
|
323
312
|
this.destroyHook?.();
|
|
313
|
+
return reported;
|
|
324
314
|
}
|
|
325
315
|
|
|
326
316
|
destroy(): void { void this.destroyAndWait(); }
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The failure a session's own transcript records, for the one harness whose
|
|
8
|
+
* envelope cannot say it.
|
|
9
|
+
*
|
|
10
|
+
* Measured on a real `omp-acp` spawn: the agent answered a provider failure as
|
|
11
|
+
* ordinary assistant text and ended the turn normally, so the ACP envelope said
|
|
12
|
+
* `end_turn` while omp's JSONL for the same turn carried `stopReason: "error"`
|
|
13
|
+
* and the provider's message. Reading only the envelope reported a delegated
|
|
14
|
+
* worker as `completed` and handed its coordinator the error as if it were a
|
|
15
|
+
* report.
|
|
16
|
+
*
|
|
17
|
+
* The rules pinned here are the ones that keep the read honest: only a harness
|
|
18
|
+
* whose transcript Kabmo can read is consulted, the LAST assistant record
|
|
19
|
+
* decides (a retried attempt must not speak for the turn), and an unreadable
|
|
20
|
+
* file is not evidence of a failure.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
24
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
|
25
|
+
import { tmpdir } from 'node:os';
|
|
26
|
+
import { join } from 'node:path';
|
|
27
|
+
|
|
28
|
+
import { transcriptFailure } from '@/server/lib/harness/acp/turn-outcome.server';
|
|
29
|
+
import { clearSessionFileCaches } from '@/server/lib/omp/session/files';
|
|
30
|
+
import { removeDir } from '@/test-support/remove-dir';
|
|
31
|
+
|
|
32
|
+
const ROOT = mkdtempSync(join(tmpdir(), 'kabmo-turn-outcome-'));
|
|
33
|
+
const SESSIONS = join(ROOT, 'sessions', 'proj');
|
|
34
|
+
const previousAgentDir = Bun.env.PI_CODING_AGENT_DIR;
|
|
35
|
+
|
|
36
|
+
function writeSession(id: string, records: Record<string, unknown>[]): void {
|
|
37
|
+
writeFileSync(
|
|
38
|
+
join(SESSIONS, `2026-11-18T00-00-00-000Z_${id}.jsonl`),
|
|
39
|
+
records.map((record) => JSON.stringify(record)).join('\n'),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const header = (id: string) => ({ type: 'session', id, cwd: '/tmp', timestamp: '2026-11-18T00:00:00.000Z' });
|
|
44
|
+
const assistant = (extra: Record<string, unknown>) => ({
|
|
45
|
+
type: 'message',
|
|
46
|
+
message: { role: 'assistant', content: [{ type: 'text', text: 'hi' }], ...extra },
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
beforeAll(() => {
|
|
50
|
+
mkdirSync(SESSIONS, { recursive: true });
|
|
51
|
+
Bun.env.PI_CODING_AGENT_DIR = ROOT;
|
|
52
|
+
clearSessionFileCaches();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterAll(() => {
|
|
56
|
+
if (previousAgentDir === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
|
|
57
|
+
else Bun.env.PI_CODING_AGENT_DIR = previousAgentDir;
|
|
58
|
+
clearSessionFileCaches();
|
|
59
|
+
removeDir(ROOT);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('transcriptFailure', () => {
|
|
63
|
+
test('reads the provider reason omp recorded for the last turn', async () => {
|
|
64
|
+
writeSession('failed-1', [
|
|
65
|
+
header('failed-1'),
|
|
66
|
+
assistant({ stopReason: 'error', errorMessage: '400 The model is unavailable' }),
|
|
67
|
+
]);
|
|
68
|
+
clearSessionFileCaches();
|
|
69
|
+
|
|
70
|
+
expect(await transcriptFailure('omp-acp', 'failed-1')).toBe('400 The model is unavailable');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('a normal last turn answers null, even after an earlier failure', async () => {
|
|
74
|
+
writeSession('recovered-1', [
|
|
75
|
+
header('recovered-1'),
|
|
76
|
+
assistant({ stopReason: 'error', errorMessage: '429 rate limited' }),
|
|
77
|
+
assistant({ stopReason: 'stop' }),
|
|
78
|
+
]);
|
|
79
|
+
clearSessionFileCaches();
|
|
80
|
+
|
|
81
|
+
expect(await transcriptFailure('omp-acp', 'recovered-1')).toBeNull();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('a harness whose transcript Kabmo cannot read is never consulted', async () => {
|
|
85
|
+
writeSession('claude-1', [
|
|
86
|
+
header('claude-1'),
|
|
87
|
+
assistant({ stopReason: 'error', errorMessage: 'should not be read' }),
|
|
88
|
+
]);
|
|
89
|
+
clearSessionFileCaches();
|
|
90
|
+
|
|
91
|
+
expect(await transcriptFailure('claude', 'claude-1')).toBeNull();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('a missing session is not a failure', async () => {
|
|
95
|
+
expect(await transcriptFailure('omp-acp', 'never-existed')).toBeNull();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The failure a session's OWN transcript records for its last turn.
|
|
8
|
+
*
|
|
9
|
+
* One harness needs this: `omp-acp`. Its agent answers a provider failure as
|
|
10
|
+
* ordinary assistant text and then ends the turn normally — measured on a real
|
|
11
|
+
* spawn, the ACP envelope said `end_turn` with the body
|
|
12
|
+
* `400 The model agnes-2-5-flash:free is currently unavailable…`, while omp's
|
|
13
|
+
* own JSONL for the same turn carried `stopReason: "error"` and the same
|
|
14
|
+
* message. Reading only the envelope therefore reported a delegated worker as
|
|
15
|
+
* `completed` and handed its coordinator the provider's error as if it were a
|
|
16
|
+
* report.
|
|
17
|
+
*
|
|
18
|
+
* The transcript is authoritative where Kabmo can read it, and `omp-acp` writes
|
|
19
|
+
* omp's JSONL — the one store this module reads. Every other harness reports
|
|
20
|
+
* failure in the envelope itself (`stopReason: "error"`, a rejected prompt, or
|
|
21
|
+
* a v2 idle with an error), so nothing is guessed for them: a harness with no
|
|
22
|
+
* readable transcript answers null and the envelope's verdict stands.
|
|
23
|
+
*
|
|
24
|
+
* The read is a TAIL, not the file: the answer is always the last assistant
|
|
25
|
+
* record, and a session can be tens of megabytes.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
29
|
+
import { findSessionFileById } from '@/server/lib/omp/session/locator';
|
|
30
|
+
import { readJsonlTail } from '@/server/lib/omp/session/jsonl-tail';
|
|
31
|
+
import { parseJsonlLenient } from '@/shared/lib/omp/session/jsonl';
|
|
32
|
+
import { deriveTurnError } from '@/shared/lib/omp/session/turn-error';
|
|
33
|
+
|
|
34
|
+
/** Enough for the last turn of any real session; a miss falls back to nothing. */
|
|
35
|
+
const TAIL_BYTES = 64 * 1024;
|
|
36
|
+
|
|
37
|
+
/** Harnesses whose transcript Kabmo can read, and therefore trust over the
|
|
38
|
+
* envelope. `omp-acp` is omp behind the ACP transport. */
|
|
39
|
+
const READABLE_TRANSCRIPT: Readonly<Record<string, true>> = { 'omp-acp': true };
|
|
40
|
+
|
|
41
|
+
export async function transcriptFailure(
|
|
42
|
+
harness: HarnessId | undefined,
|
|
43
|
+
sessionId: string,
|
|
44
|
+
): Promise<string | null> {
|
|
45
|
+
if (!harness || READABLE_TRANSCRIPT[harness] !== true || !sessionId) return null;
|
|
46
|
+
try {
|
|
47
|
+
const file = await findSessionFileById(sessionId);
|
|
48
|
+
if (!file) return null;
|
|
49
|
+
const tail = await readJsonlTail(file, TAIL_BYTES, (body) =>
|
|
50
|
+
parseJsonlLenient<Record<string, unknown>>(body),
|
|
51
|
+
);
|
|
52
|
+
for (let index = tail.records.length - 1; index >= 0; index -= 1) {
|
|
53
|
+
const record = tail.records[index] as Record<string, unknown>;
|
|
54
|
+
if (record.type !== 'message') continue;
|
|
55
|
+
const message = record.message;
|
|
56
|
+
if (!message || typeof message !== 'object' || Array.isArray(message)) continue;
|
|
57
|
+
const entry = message as Record<string, unknown>;
|
|
58
|
+
if (entry.role !== 'assistant') continue;
|
|
59
|
+
// The LAST assistant record decides: an earlier failed attempt that was
|
|
60
|
+
// retried into a good answer must not be reported as this turn's ending.
|
|
61
|
+
const error = deriveTurnError(entry);
|
|
62
|
+
const reason = error?.message?.trim();
|
|
63
|
+
if (reason) return reason;
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
} catch {
|
|
68
|
+
// An unreadable transcript is not evidence of a failure.
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The silence ceiling for one open ACP turn.
|
|
8
|
+
*
|
|
9
|
+
* ACP has no `get_state` probe: unlike omp, nothing can ask the agent "are you
|
|
10
|
+
* still working?", so a turn whose agent stopped answering stays open forever —
|
|
11
|
+
* `isBusy()` keeps the idle reclaim away, the process lives on, and a delegated
|
|
12
|
+
* worker's coordinator waits for a result that will never come. The only
|
|
13
|
+
* evidence left is silence, so this is a CEILING, not a detector: an hour with
|
|
14
|
+
* no frame at all. A working agent streams token deltas or tool updates, and
|
|
15
|
+
* the repo's own background-work ceiling is 10 minutes, so an hour of complete
|
|
16
|
+
* silence is six times more generous than the precedent beside it.
|
|
17
|
+
*
|
|
18
|
+
* The clock is fed by every frame (`noteActivity`) and stopped by the turn's own
|
|
19
|
+
* end, so a settled turn can never strand a later one.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** Quiet stretch after which an open turn is presumed stranded. */
|
|
23
|
+
export const TURN_SILENCE_MS = 60 * 60_000;
|
|
24
|
+
|
|
25
|
+
export class TurnSilence {
|
|
26
|
+
#timer: ReturnType<typeof setTimeout> | null = null;
|
|
27
|
+
readonly #ms: number;
|
|
28
|
+
readonly #onStranded: () => void;
|
|
29
|
+
|
|
30
|
+
constructor(onStranded: () => void, ms: number = TURN_SILENCE_MS) {
|
|
31
|
+
this.#onStranded = onStranded;
|
|
32
|
+
this.#ms = ms;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** (Re-)arm for the open turn. Called on every frame the agent sends. */
|
|
36
|
+
arm(): void {
|
|
37
|
+
this.stop();
|
|
38
|
+
const timer = setTimeout(() => {
|
|
39
|
+
this.#timer = null;
|
|
40
|
+
this.#onStranded();
|
|
41
|
+
}, this.#ms);
|
|
42
|
+
// Must never keep the event loop alive on its own.
|
|
43
|
+
timer.unref?.();
|
|
44
|
+
this.#timer = timer;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The turn ended (settled, cancelled, or the session is going away). */
|
|
48
|
+
stop(): void {
|
|
49
|
+
clearTimeout(this.#timer ?? undefined);
|
|
50
|
+
this.#timer = null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
1
|
+
import { describe, expect, test, vi } from 'bun:test';
|
|
2
2
|
import { AcpRequestError } from '@/server/lib/harness/acp/calls';
|
|
3
3
|
import { AcpTurns, type AcpTurnSeams } from '@/server/lib/harness/acp/turn';
|
|
4
4
|
|
|
5
5
|
type TurnEnd = Parameters<AcpTurnSeams['onTurnEnd']>[0];
|
|
6
6
|
|
|
7
|
-
function harness(
|
|
7
|
+
function harness(
|
|
8
|
+
overrides: Partial<AcpTurnSeams> = {},
|
|
9
|
+
options: { silenceMs?: number } = {},
|
|
10
|
+
): {
|
|
8
11
|
turns: AcpTurns;
|
|
9
12
|
events: { type: string; errorMessage?: string }[];
|
|
10
13
|
ended: Promise<TurnEnd>;
|
|
@@ -21,7 +24,7 @@ function harness(overrides: Partial<AcpTurnSeams> = {}): {
|
|
|
21
24
|
openCalls: () => [],
|
|
22
25
|
onTurnEnd: (info) => resolveEnd(info),
|
|
23
26
|
...overrides,
|
|
24
|
-
});
|
|
27
|
+
}, options);
|
|
25
28
|
return { turns, events, ended };
|
|
26
29
|
}
|
|
27
30
|
|
|
@@ -66,6 +69,30 @@ describe('AcpTurns failure classification', () => {
|
|
|
66
69
|
expect(info.closedMessage).toBe(true);
|
|
67
70
|
});
|
|
68
71
|
|
|
72
|
+
test('a v1 error stop is failed even when the agent streamed a partial answer', async () => {
|
|
73
|
+
// Measured shape: a provider failure mid-answer still closes the message,
|
|
74
|
+
// so "did it answer" is true — and reading only that reported the turn as
|
|
75
|
+
// completed, which told a delegated worker's coordinator it had finished.
|
|
76
|
+
const { promise, resolve } = Promise.withResolvers<{ stopReason?: string }>();
|
|
77
|
+
const { turns, ended } = harness({
|
|
78
|
+
prompt: () => promise,
|
|
79
|
+
closeMessage: () => [
|
|
80
|
+
{
|
|
81
|
+
type: 'message_end',
|
|
82
|
+
message: { role: 'assistant', content: [{ type: 'text', text: 'partial' }] },
|
|
83
|
+
},
|
|
84
|
+
] as never,
|
|
85
|
+
});
|
|
86
|
+
turns.start('do the work', undefined);
|
|
87
|
+
await Promise.resolve();
|
|
88
|
+
await Promise.resolve();
|
|
89
|
+
resolve({ stopReason: 'error' });
|
|
90
|
+
|
|
91
|
+
const info = await ended;
|
|
92
|
+
expect(info.failed).toBe(true);
|
|
93
|
+
expect(info.failure).toContain('with an error');
|
|
94
|
+
});
|
|
95
|
+
|
|
69
96
|
test('an ACP -32800 answer is a cancelled turn, not a prompt error', async () => {
|
|
70
97
|
const { turns, events, ended } = harness({
|
|
71
98
|
prompt: async () => {
|
|
@@ -95,6 +122,61 @@ describe('AcpTurns failure classification', () => {
|
|
|
95
122
|
});
|
|
96
123
|
});
|
|
97
124
|
|
|
125
|
+
describe('AcpTurns silence ceiling', () => {
|
|
126
|
+
test('a turn the agent stops reporting on is closed as stranded', async () => {
|
|
127
|
+
vi.useFakeTimers();
|
|
128
|
+
try {
|
|
129
|
+
const { turns, ended } = harness({ prompt: () => new Promise(() => {}) }, { silenceMs: 1_000 });
|
|
130
|
+
turns.start('do the work', undefined);
|
|
131
|
+
await Promise.resolve();
|
|
132
|
+
await Promise.resolve();
|
|
133
|
+
vi.advanceTimersByTime(1_000);
|
|
134
|
+
|
|
135
|
+
const info = await ended;
|
|
136
|
+
expect(info.stranded).toBe(true);
|
|
137
|
+
expect(info.failed).toBe(true);
|
|
138
|
+
expect(info.failure).toContain('stopped reporting');
|
|
139
|
+
expect(turns.isStreaming).toBe(false);
|
|
140
|
+
} finally {
|
|
141
|
+
vi.useRealTimers();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('a frame from the agent defers the ceiling', async () => {
|
|
146
|
+
vi.useFakeTimers();
|
|
147
|
+
try {
|
|
148
|
+
const { turns } = harness({ prompt: () => new Promise(() => {}) }, { silenceMs: 1_000 });
|
|
149
|
+
turns.start('do the work', undefined);
|
|
150
|
+
await Promise.resolve();
|
|
151
|
+
await Promise.resolve();
|
|
152
|
+
vi.advanceTimersByTime(900);
|
|
153
|
+
turns.noteActivity();
|
|
154
|
+
vi.advanceTimersByTime(900);
|
|
155
|
+
// 1.8s of wall clock, but never 1s of SILENCE.
|
|
156
|
+
expect(turns.isStreaming).toBe(true);
|
|
157
|
+
vi.advanceTimersByTime(200);
|
|
158
|
+
expect(turns.isStreaming).toBe(false);
|
|
159
|
+
} finally {
|
|
160
|
+
vi.useRealTimers();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('a settled turn cannot strand a later one', async () => {
|
|
165
|
+
vi.useFakeTimers();
|
|
166
|
+
try {
|
|
167
|
+
const { turns, events, ended } = harness({}, { silenceMs: 1_000 });
|
|
168
|
+
turns.start('do the work', undefined);
|
|
169
|
+
await ended;
|
|
170
|
+
const before = events.length;
|
|
171
|
+
vi.advanceTimersByTime(5_000);
|
|
172
|
+
expect(events.length).toBe(before);
|
|
173
|
+
expect(turns.isStreaming).toBe(false);
|
|
174
|
+
} finally {
|
|
175
|
+
vi.useRealTimers();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
98
180
|
describe('AcpTurns v2 completion', () => {
|
|
99
181
|
test('acceptance does not end the turn; an idle state_update does', async () => {
|
|
100
182
|
const { turns, ended } = harness();
|