@markus-global/cli 0.12.4 → 0.12.5-rc.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/dist/background-maintenance.d.ts +25 -0
- package/dist/background-maintenance.d.ts.map +1 -1
- package/dist/background-maintenance.js +61 -0
- package/dist/background-maintenance.js.map +1 -1
- package/dist/commands/im-inbound-origin.d.ts +38 -0
- package/dist/commands/im-inbound-origin.d.ts.map +1 -0
- package/dist/commands/im-inbound-origin.js +48 -0
- package/dist/commands/im-inbound-origin.js.map +1 -0
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +211 -46
- package/dist/commands/start.js.map +1 -1
- package/dist/markus.mjs +18520 -9886
- package/dist/web-ui/assets/{AsyncState-BTLUPIr1.js → AsyncState-ByYn1wrM.js} +1 -1
- package/dist/web-ui/assets/ChatComponents-Bwh8SlUV.js +14 -0
- package/dist/web-ui/assets/{ContentRenderer-BZXRiKE3.js → ContentRenderer-GLgoGp2a.js} +6 -6
- package/dist/web-ui/assets/DeliverableShareModal-CRfnRuR3.js +1 -0
- package/dist/web-ui/assets/{Deliverables-3Y3zjT_1.js → Deliverables-EFsnf6kU.js} +2 -2
- package/dist/web-ui/assets/MarkdownMessage-CaLBeMto.js +4 -0
- package/dist/web-ui/assets/{Search-BI3hk-5j.js → Search-COiaXUNr.js} +1 -1
- package/dist/web-ui/assets/{SendToChat-D_5zHO-k.js → SendToChat-DleryIlc.js} +1 -1
- package/dist/web-ui/assets/Settings-CzY8z2Yh.js +8 -0
- package/dist/web-ui/assets/{Store-B8ksRjHF.js → Store-C4VpQCM_.js} +1 -1
- package/dist/web-ui/assets/Switch-ByogYoGH.js +1 -0
- package/dist/web-ui/assets/Team-Cutq2J24.js +93 -0
- package/dist/web-ui/assets/Work-BO-mz-na.js +142 -0
- package/dist/web-ui/assets/{arc-VmvI7TpW.js → arc-mYv67jdD.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-CTUtPasm.js → architectureDiagram-3BPJPVTR-Bzpz_1r6.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-xeYAqtZJ.js → blockDiagram-GPEHLZMM-BBrLiivl.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-BiFgoGY5.js → c4Diagram-AAUBKEIU-BwDUoXA_.js} +1 -1
- package/dist/web-ui/assets/channel-Bx09lbhA.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-DueHBqOn.js → chunk-2J33WTMH-DCSfJ-S9.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-B8zgDfSV.js → chunk-4BX2VUAB-CI0n1b2H.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-DieD55CP.js → chunk-55IACEB6-DqlSWLrm.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-Do4Z9LQ0.js → chunk-727SXJPM-BtmAfGYV.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-qrYsW5ml.js → chunk-AQP2D5EJ-BgkA4lpQ.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-BSz3QT1q.js → chunk-FMBD7UC4-DCSr1JH4.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-utDWSydt.js → chunk-ND2GUHAM-CETYBRRm.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-Cd86CYHV.js → chunk-QZHKN3VN-C58yD7lH.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-DGZqU3iA.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-DGZqU3iA.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-Dc6cP9WW.js → cose-bilkent-S5V4N54A-BpvdK03m.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-4b0Wf_6D.js → dagre-BM42HDAG-CZ1K-KD5.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-zS_j1Kf4.js → diagram-2AECGRRQ-D136Ok1V.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-CPo-_Ime.js → diagram-5GNKFQAL-Ji6qPYYV.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-CjHOA4_j.js → diagram-KO2AKTUF-B-s2RC-f.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-CalZRF6K.js → diagram-LMA3HP47-COWaps70.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-DnLAhsLX.js → diagram-OG6HWLK6-bh6MvwWn.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-uRVPnxwM.js → docx-preview-BRynUqJd.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-L0nzlMSn.js → erDiagram-TEJ5UH35-DOPh2LlL.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-Bdc3UwtW.js → flowDiagram-I6XJVG4X-B_kxDHIp.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-CFRmj_qc.js → ganttDiagram-6RSMTGT7-DYBKHOkK.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-B5hZwcoJ.js → gitGraphDiagram-PVQCEYII-D8_0BxLC.js} +1 -1
- package/dist/web-ui/assets/index-9SXWNIl0.css +1 -0
- package/dist/web-ui/assets/index-TAHyKznL.js +867 -0
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-DVT4RgPd.js → infoDiagram-5YYISTIA-DayJP7Ws.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-Bf7pvUY_.js → ishikawaDiagram-YF4QCWOH-vzxCYVSq.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-NVRjJlnd.js → journeyDiagram-JHISSGLW-B-Fud82o.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-Co7BKMut.js → kanban-definition-UN3LZRKU-DzuKdB65.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-CCf28Hq6.js → mermaid.core-D4ql87kI.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-DepMhVEb.js → mindmap-definition-RKZ34NQL-DosvXt2g.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-Cq9ANaI0.js → pieDiagram-4H26LBE5-DhXtMWhr.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-CUY0BWhQ.js → quadrantDiagram-W4KKPZXB-D33pLLOq.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-D9fU5rCm.js → requirementDiagram-4Y6WPE33-B-iIz-XM.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-CMHhuSQF.js → sankeyDiagram-5OEKKPKP-BMd9AFEW.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-Bjx53SID.js → sequenceDiagram-3UESZ5HK-CI1MIdwo.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-DVvatKnO.js → stateDiagram-AJRCARHV-Bq6FKPW2.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-8nMhmWY5.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-9I80LG9m.js → timeline-definition-PNZ67QCA-BDdmmSRo.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-B82Deutq.js → vennDiagram-CIIHVFJN-DP2q5vY2.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-BKXtp57W.js → wardley-L42UT6IY-Bw3fjszD.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-DzqTzfYa.js → wardleyDiagram-YWT4CUSO-37bQUocJ.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-TowyDWYu.js → xychartDiagram-2RQKCTM6-DnLDZyNC.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/docs/README.md +50 -16
- package/docs/api/guides/websocket.md +43 -0
- package/docs/api/reference.md +657 -0
- package/docs/architecture/a2a-communication.md +303 -0
- package/docs/architecture/agent-runtime.md +145 -28
- package/docs/architecture/architecture.md +30 -11
- package/docs/architecture/cognitive-architecture.md +189 -15
- package/docs/architecture/concurrent-processing.md +190 -31
- package/docs/architecture/context-assembly.md +264 -0
- package/docs/architecture/derived-views.md +463 -0
- package/docs/architecture/desktop-auto-update.md +185 -0
- package/docs/architecture/facts.md +406 -0
- package/docs/architecture/learning-loop.md +11 -0
- package/docs/architecture/limits.md +79 -0
- package/docs/architecture/mailbox-system.md +786 -668
- package/docs/architecture/memory-system.md +1 -1
- package/docs/architecture/messaging-gateway.md +7 -0
- package/docs/architecture/notification-delivery.md +221 -0
- package/docs/architecture/notification-sounds.md +177 -0
- package/docs/architecture/prompt-engineering.md +171 -700
- package/docs/{design/remote-access-contract.md → architecture/remote-access.md} +4 -0
- package/docs/architecture/state-machines.md +288 -5
- package/docs/architecture/tool-loop-harness.md +362 -0
- package/docs/architecture/tool-system.md +40 -16
- package/docs/design/background-callback-in-turn-delivery-2026-11-22.md +95 -0
- package/docs/design/c10-0b-pick-identity-leak-2026-11-22.md +233 -0
- package/docs/design/c10-a-identity-columns-2026-11-22.md +182 -0
- package/docs/design/c10-c-trust-boundary-2026-11-23.md +222 -0
- package/docs/design/c10-external-adapters-plan-2026-11-19.md +448 -0
- package/docs/design/c8-residual-mechanisms-2026-11-15.md +984 -0
- package/docs/design/external-signal-decision-loop-2026-11-25.md +579 -0
- package/docs/guides/development.md +1 -1
- package/docs/{architecture → guides}/mailbox-audit-checklist.md +7 -0
- package/docs/guides/remote-access.md +1 -1
- package/docs/{design/agent-stop-intent-audit.md → records/agent-stop-intent-audit-2026-11-08.md} +4 -0
- package/docs/records/c10-l5-gate-verification-2026-11-26.md +72 -0
- package/docs/records/c10-l5-live-verification-2026-11-25.md +117 -0
- package/docs/records/cut6-c4-verification-2026-11-12.md +268 -0
- package/docs/records/cut6-mailbox-address-envelope-design-2026-11-12.md +871 -0
- package/docs/records/cut7-c7a-red-green-evidence-2026-11-13.md +105 -0
- package/docs/records/cut7-c7a-workunit-implementation-2026-11-13.md +116 -0
- package/docs/records/cut7-c7b-verification-2026-11-14.md +90 -0
- package/docs/records/cut7-live-verification-2026-11-14.md +33 -0
- package/docs/records/cut7-wiring-negative-cache-2026-11-14.md +64 -0
- package/docs/records/cut7-workunit-execution-plan-2026-11-13.md +206 -0
- package/docs/records/cut8-a-entity-keys-design-2026-11-14.md +377 -0
- package/docs/records/cut8-b-turn-delta-injection-2026-11-14.md +362 -0
- package/docs/records/cut8-c-single-clock-2026-11-14.md +119 -0
- package/docs/records/cut8-c-single-clock-design-2026-11-14.md +150 -0
- package/docs/records/cut8-d-2026-11-14.md +231 -0
- package/docs/records/cut8-live-verification-2026-11-14.md +1018 -0
- package/docs/records/cut9-adjacent-identity-paths-2026-11-15.md +200 -0
- package/docs/records/cut9-identity-declaration-2026-11-15.md +163 -0
- package/docs/records/cut9-inbox-dual-run-diff-2026-11-15.md +117 -0
- package/docs/records/cut9-live-verification-2026-11-15.md +222 -0
- package/docs/records/cut9-runtime-probe-2026-11-19.md +520 -0
- package/docs/{design/deliverable-sharing.md → records/deliverable-sharing-2026-08-12.md} +10 -3
- package/docs/records/identity-backlog-disposition-2026-11-22.md +143 -0
- package/docs/records/marketplace-orphan-freeze-2026-11-22.md +239 -0
- package/docs/{architecture/notify-user-context-truth.md → records/notify-user-context-truth-2026-10-28.md} +6 -0
- package/docs/{handoff → records}/remote-access-handoff.md +1 -1
- package/package.json +1 -1
- package/templates/roles/HANDBOOK.md +1 -1
- package/templates/skills/agent-building/SKILL.md +1 -1
- package/dist/web-ui/assets/ChatComponents-DTB3H_n2.js +0 -12
- package/dist/web-ui/assets/DeliverableShareModal-BwZP39nd.js +0 -1
- package/dist/web-ui/assets/MarkdownMessage-DVfFMzM9.js +0 -4
- package/dist/web-ui/assets/Settings-DTUjLhJY.js +0 -8
- package/dist/web-ui/assets/Switch-RmZHA47D.js +0 -1
- package/dist/web-ui/assets/Team-BRgI1zM9.js +0 -85
- package/dist/web-ui/assets/Work-nah0UYFz.js +0 -142
- package/dist/web-ui/assets/channel-s7K3KXLr.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-B2mHhFY8.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-B2mHhFY8.js +0 -1
- package/dist/web-ui/assets/index-CzHSs0Vd.css +0 -1
- package/dist/web-ui/assets/index-TPf50ZeO.js +0 -867
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-92MmE2MZ.js +0 -1
- package/docs/api/api.md +0 -353
- package/docs/architecture/llm-provider-timeouts.md +0 -60
- package/docs/architecture/state-ownership.md +0 -83
- /package/docs/architecture/{frontend/team-chat.md → team-chat.md} +0 -0
- /package/docs/{analysis → records}/2026-10-29-a2a-cache-hit-rate.md +0 -0
- /package/docs/{fixes → records}/2026-11-12-session-expiry-and-mention-thinking.md +0 -0
- /package/docs/{handoff → records}/approval-tri-state-handoff.md +0 -0
- /package/docs/{design → records}/overview-attention-redesign.md +0 -0
- /package/docs/{remote-access/fast-path-plan.md → records/remote-access-fast-path-plan-2026-10-17.md} +0 -0
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Markus 远程访问重构 · 冻结契约(T1)
|
|
2
2
|
|
|
3
|
+
> **Moved** here from `docs/design/` on 2026-11-15. `design/` is for work that is not settled yet;
|
|
4
|
+
> this contract is frozen v1.0.0 and is the implementation SSOT, so it belongs with the architecture.
|
|
5
|
+
> User-facing how-to: [`guides/remote-access.md`](../guides/remote-access.md).
|
|
6
|
+
|
|
3
7
|
> 作者:CTO · 2026-10-14 · 状态:**冻结(frozen v1.0.0)**
|
|
4
8
|
> 地位:本文件 + `packages/remote/src/contract.ts` 是本重构**唯一实现依据(单一事实源 / SSOT)**。
|
|
5
9
|
> 上游依据:`remote-access-design.md`(v2,已并入 Owner 决策 D1–D4)、`remote-access-execution-plan.md`。
|
|
@@ -117,6 +117,14 @@ Within a single round, transient retries (network errors, timeouts) reuse the sa
|
|
|
117
117
|
|
|
118
118
|
A new round always gets a fresh LLM session (`task_{taskId}_r{round}`).
|
|
119
119
|
|
|
120
|
+
**Every round also gets its own WorkUnit entity**, ensured *before* the mailbox item references it
|
|
121
|
+
(`WORK_UNIT_REF.task(taskId, round)` → `task_<id>_r<round>`). The reference column
|
|
122
|
+
(`mailbox_items.work_unit_ref`) is plain `TEXT` with no foreign key, so a reference written without
|
|
123
|
+
its entity fails silently: `resolve(ref)` returns null, the session lock key degrades, and a
|
|
124
|
+
delegation started in that round lands `parent_id = NULL`. One execution epoch = one WorkUnit, and
|
|
125
|
+
the only execution point for that rule is `TaskService.linkExecutionEpoch()` — both the main run
|
|
126
|
+
path and the fresh-retry path go through it.
|
|
127
|
+
|
|
120
128
|
### Context by Round Type
|
|
121
129
|
|
|
122
130
|
| Scenario | Previous execution context | LLM session |
|
|
@@ -493,17 +501,22 @@ loopEnabled=false (re-enable / raise max)
|
|
|
493
501
|
|
|
494
502
|
```
|
|
495
503
|
registerBackgroundSession()
|
|
496
|
-
│
|
|
504
|
+
│ (lineage: originSessionId + originScenario + workUnitRef
|
|
505
|
+
│ persisted in the SAME row — one durable store, no parallel maps)
|
|
497
506
|
▼
|
|
498
507
|
pending ────── resolve() ──────► resolved
|
|
499
508
|
│ (operation done) │
|
|
500
|
-
│
|
|
509
|
+
│ ├── result already consumed? ──► (no delivery;
|
|
510
|
+
│ │ queued item skipped at processing)
|
|
511
|
+
│ └── else enqueue callback_result
|
|
512
|
+
│ (same-origin queued siblings coalesce
|
|
513
|
+
│ into ONE turn; siblings → merged)
|
|
501
514
|
│
|
|
502
515
|
├── getTimedOut() ──► timed_out
|
|
503
516
|
│ │
|
|
504
517
|
│ └── expireTimedOut() ──► expired
|
|
505
518
|
│ (removed; surfaced in heartbeat)
|
|
506
|
-
└── (server restart) ──► pending (restored from SQLite)
|
|
519
|
+
└── (server restart) ──► pending (restored from SQLite, lineage intact)
|
|
507
520
|
```
|
|
508
521
|
|
|
509
522
|
### Transitions
|
|
@@ -511,7 +524,7 @@ registerBackgroundSession()
|
|
|
511
524
|
| From | To | Trigger | Side Effect |
|
|
512
525
|
|------|----|---------|-------------|
|
|
513
526
|
| — | `pending` | `registerBackgroundSession()` / `PendingCallbackRegistry.register()` | Persisted via `SqlitePendingCallbackRepo` |
|
|
514
|
-
| `pending` | `resolved` | Operation completes; `resolve(id)` | Registry entry removed; `callback_result`
|
|
527
|
+
| `pending` | `resolved` | Operation completes; `resolve(id)` | Registry entry removed; `callback_result` enqueued UNLESS the result was already consumed (`wasBackgroundResultConsumed`). The queued row is delivered in-turn by `injectTurnDelta` if the launching turn is still running, else drives a lineage continuation |
|
|
515
528
|
| `pending` | `timed_out` | Heartbeat calls `getTimedOut()` (`now - registeredAt > timeoutMs`) | Detected only — entry still in registry |
|
|
516
529
|
| `timed_out` | `expired` | Heartbeat calls `expireTimedOut(id)` | Registry entry removed; details injected into heartbeat prompt (no `callback_result`) |
|
|
517
530
|
| `pending` | `pending` | Server restart | `setPersistence()` restores all pending callbacks |
|
|
@@ -521,6 +534,9 @@ registerBackgroundSession()
|
|
|
521
534
|
1. **Resolved → mailbox** — only the `resolved` path produces a `callback_result` item; timeouts are surfaced for agent investigation, not auto-enqueued
|
|
522
535
|
2. **Default timeout** — 10 minutes for `background_exec`
|
|
523
536
|
3. **Origin session preserved** — `originSessionId` on the callback is copied into `callback_result.extra` for session resumption
|
|
537
|
+
4. **The result belongs to the launching turn** — if that turn is still running, `injectTurnDelta` delivers the full result content in-turn and consumes the row (no separate completion turn); if it has ended, the `callback_result` row drives a lineage continuation. `process poll/log` on a finished session also marks the result consumed, and a queued item for an already-consumed result is skipped at processing
|
|
538
|
+
5. **Lineage is durable** — `originScenario` + `workUnitRef` live in the persisted row (the ONE store); a restart cannot orphan a callback from its launching scenario/entity. The completion replays the registered scenario (task completions keep task tools, not the heartbeat reflex pack)
|
|
539
|
+
6. **One waiting context wakes once** — queued `callback_result` items for the same origin session are coalesced into a single turn; absorbed siblings terminate as `merged`
|
|
524
540
|
|
|
525
541
|
---
|
|
526
542
|
|
|
@@ -559,7 +575,7 @@ After `processFocusedItem` runs, exactly one terminal outcome is chosen (impleme
|
|
|
559
575
|
| Outcome | Trigger | Persistence effect | Resumable? |
|
|
560
576
|
|---------|---------|--------------------|-----------|
|
|
561
577
|
| **completed** | Normal finish (marker present, or accepted without-retry case) | `complete(id)` | No (done) |
|
|
562
|
-
| **
|
|
578
|
+
| **bounced** | Explicit `cancel` decision / `[cancelled]` reply / abnormal terminal | `drop(id, why, dropReason)` → `bounced` → `catch_all` | No (reason queryable) |
|
|
563
579
|
| **deferred** | `preempt` decision / `[preempted]` reply | `deferDequeued(item)` | Yes — `resurfaceDue()` re-queues when idle |
|
|
564
580
|
| **requeued** | Backstop **timeout**, agent stopped mid-flight, or abnormal reply on a background type (< max retries) | `requeue(item)` | Yes — re-processed from queue |
|
|
565
581
|
| **completed (incomplete)** | Marker still missing after in-session continuation, or abnormal reply on a user-interaction item | `complete(id)` | No |
|
|
@@ -663,3 +679,270 @@ agent stop
|
|
|
663
679
|
| Agent stop | Cancel debounce timer; synchronous final `persistNotebookSync()` |
|
|
664
680
|
|
|
665
681
|
See [memory-system.md](./memory-system.md) and [cognitive-architecture.md](./cognitive-architecture.md) for storage format and deterministic context assembly.
|
|
682
|
+
|
|
683
|
+
---
|
|
684
|
+
|
|
685
|
+
## 16. WorkUnit Lifecycle
|
|
686
|
+
|
|
687
|
+
A `WorkUnit` is the identity object for **one piece of work** — one chat turn, one task execution epoch, or one A2A delivery. Before cut 7 the same work was described by five mechanisms and had no queryable identity: "what is this agent doing" could only be inferred from a context block assembled per turn, so the answer could drift from what was actually running.
|
|
688
|
+
|
|
689
|
+
Everything below is taken from the code, not from the design plan:
|
|
690
|
+
|
|
691
|
+
| Fact | Source of truth |
|
|
692
|
+
|---|---|
|
|
693
|
+
| State set and transition matrix | `packages/shared/src/work-unit.ts` (`WU_TRANSITIONS`) |
|
|
694
|
+
| Schema and the only SQL writes | `packages/storage/src/sqlite-storage.ts` (`SqliteWorkUnitRepo`) |
|
|
695
|
+
| Business writer and event contract | `packages/org-manager/src/work-unit-service.ts` (`WorkUnitService`) |
|
|
696
|
+
|
|
697
|
+
### State Set (closed)
|
|
698
|
+
|
|
699
|
+
| State | Meaning |
|
|
700
|
+
|---|---|
|
|
701
|
+
| `running` | executing right now |
|
|
702
|
+
| `idle` | turn settled; the work is still alive and waiting for its next input |
|
|
703
|
+
| `paused_budget` | paused because the budget line was reached (no producer in C7-A) |
|
|
704
|
+
| `terminated` | cancelled or closed as failed |
|
|
705
|
+
| `archived` | terminal; takes part in no scheduling afterwards |
|
|
706
|
+
|
|
707
|
+
Every state is answerable from structure. None of them is inferred from a payload or from prose.
|
|
708
|
+
|
|
709
|
+
### State Diagram
|
|
710
|
+
|
|
711
|
+
```
|
|
712
|
+
(new turn)
|
|
713
|
+
│
|
|
714
|
+
▼
|
|
715
|
+
┌──► running ──────────► idle
|
|
716
|
+
│ │ │ │
|
|
717
|
+
│ │ └──► paused_budget ──┐
|
|
718
|
+
│ │ │ (budget topped up)
|
|
719
|
+
│ └──────────────┐ │
|
|
720
|
+
│ ▼ ▼
|
|
721
|
+
│ terminated ◄─┘
|
|
722
|
+
│ │
|
|
723
|
+
│ ▼
|
|
724
|
+
└───── refused ──── archived (terminal — no outgoing edge)
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
### Transitions
|
|
728
|
+
|
|
729
|
+
Copied verbatim from `WU_TRANSITIONS` — this table is a read of that constant, never a second definition of it.
|
|
730
|
+
|
|
731
|
+
| from | allowed to | trigger |
|
|
732
|
+
|---|---|---|
|
|
733
|
+
| `running` | `idle` / `paused_budget` / `terminated` | turn settled / budget line reached / cancelled |
|
|
734
|
+
| `idle` | `running` / `terminated` | new turn / cancelled |
|
|
735
|
+
| `paused_budget` | `running` / `terminated` | budget topped up / cancelled |
|
|
736
|
+
| `terminated` | `archived` | archived |
|
|
737
|
+
| `archived` | — | terminal |
|
|
738
|
+
|
|
739
|
+
`archived` has no outgoing edge on purpose: archiving is the only way to say "this is over". Resuming the work means a **new** WorkUnit (new `ref`, or a new round) — never resurrecting the old one. Allowing `archived → running` would make archiving a revocable decoration and historical readings would start to drift. The enforcement is a guard fixture, not a convention: `work-unit-single-writer` fails if `archived` stops being `[]`.
|
|
740
|
+
|
|
741
|
+
### Single Writer
|
|
742
|
+
|
|
743
|
+
Three layers, one responsibility each, and no layer reaches into another's:
|
|
744
|
+
|
|
745
|
+
| Layer | File | Owns |
|
|
746
|
+
|---|---|---|
|
|
747
|
+
| Concept | `packages/shared/src/work-unit.ts` | State set, matrix, `ref` format — pure functions, no I/O |
|
|
748
|
+
| Storage | `SqliteWorkUnitRepo` | The **only** SQL that writes `work_units` and `status_transitions` rows for `entity_type='work_unit'` |
|
|
749
|
+
| Business | `WorkUnitService` | The **only** caller of those write methods; decides whether a failed write may interrupt the business path |
|
|
750
|
+
|
|
751
|
+
Both entry points are idempotent or conditional by construction:
|
|
752
|
+
|
|
753
|
+
- `ensure(ref)` uses `INSERT ... ON CONFLICT(ref) DO NOTHING` and then reads back by `ref`. Check-then-insert is not equivalent: under concurrency both workers observe "absent" and the execution epoch ends up with two identities, or the unique index aborts a real delivery. Exactly one row per `ref` is decided by `uq_work_units_ref`, not by caller discipline.
|
|
754
|
+
- `transition(ref, to)` is an optimistic conditional update (`WHERE id = ? AND status = ?`). An unconditional update would overwrite a terminal state back to `running` when two writers race, and the state machine would become decoration.
|
|
755
|
+
|
|
756
|
+
`scripts/architecture-guard.mjs` enforces the boundary as rule group `work-unit-single-writer`, with six checks — each carrying its own compliant/violating fixture, so the detector cannot silently stop detecting:
|
|
757
|
+
|
|
758
|
+
| # | Check |
|
|
759
|
+
|---|---|
|
|
760
|
+
| 1 | `work_units` table and `uq_work_units_ref` unique index exist (identity decided by the index) |
|
|
761
|
+
| 2 | `ensure()` is the atomic `ON CONFLICT(ref) DO NOTHING` insert, not check-then-insert |
|
|
762
|
+
| 3 | `transition()` is the conditional update `WHERE id = ? AND status = ?` |
|
|
763
|
+
| 4 | `WU_TRANSITIONS` is defined in one place and `archived` is terminal |
|
|
764
|
+
| 5 | `task-service.ts` contains no `INSERT INTO work_units` / `UPDATE work_units` |
|
|
765
|
+
| 6 | `api-server.ts` contains no `work_units` SQL and no `entityType: 'work_unit'` |
|
|
766
|
+
|
|
767
|
+
Checks 5 and 6 exist because the realistic regression is not "someone rewrites the repo" — it is "someone adds one convenient UPDATE in the service that already has the data". That is a second writer, and it bypasses both the matrix and the unique index.
|
|
768
|
+
|
|
769
|
+
### Producers and `ref` formats
|
|
770
|
+
|
|
771
|
+
Three producers, one generator (`WORK_UNIT_REF` in `packages/shared/src/work-unit.ts`). A second generator would mean the same execution epoch can grow two WorkUnits, and nobody could later say which one it was.
|
|
772
|
+
|
|
773
|
+
| Producer | Call site | `ref` |
|
|
774
|
+
|---|---|---|
|
|
775
|
+
| Chat turn | `persistChatTurn()` in `org-manager/src/api-server.ts` | `session:<dbSessionId>:r<round>` |
|
|
776
|
+
| Task execution epoch | `TaskService.createTask()` in `org-manager/src/task-service.ts` | `task_<taskId>_r<round>` |
|
|
777
|
+
| A2A delivery | `AgentDelivery.deliver()` in `org-manager/src/agent-delivery.ts` | `a2a:<channelKey>:<deliveryId>` |
|
|
778
|
+
|
|
779
|
+
`task_<taskId>_r<round>` is **reused, not invented**: that string is already the execution-epoch identity (the in-flight registry key and the execution session id). Giving the same epoch a second naming scheme would hand it two identity cards, so this cut only routes the existing format through a single generator.
|
|
780
|
+
|
|
781
|
+
The A2A producer binds the row to the **recipient** (`agentId: targetId`, `contextRef: channelKey`), because the WorkUnit answers "which work is this delivery part of" for the side that owns the delivered mailbox row. `deliveryId` is the same value as the envelope `messageId`, so a retried hop cannot produce a second WorkUnit.
|
|
782
|
+
|
|
783
|
+
### Fact-Source Boundary
|
|
784
|
+
|
|
785
|
+
A message's WorkUnit identity is written in exactly one place: the `mailbox_items.work_unit_ref` column. `DeliveryEnvelope.workUnitRef` stays `null` in cut 7.
|
|
786
|
+
|
|
787
|
+
The reason is structural: two writers of the same fact always drift, and of the two the column is the one that can be indexed and joined while the envelope is a JSON projection. If a projection is ever needed (cross-org delivery carrying WU identity inside the envelope), derive it from the column — do not write both.
|
|
788
|
+
|
|
789
|
+
The write order is fixed and must not be reversed: `ensure()` first, then enqueue **carrying the ref** — the enqueue INSERT is the only writer of `mailbox_items.work_unit_ref` (C10-0B deleted the post-enqueue `linkMailboxItem()` UPDATE: it wrote only the DB column while the in-memory item stayed null, so the decision ledger — which reads memory — recorded picks without identity). Writing the reference before the entity exists is precisely the dangling reference that cut 6 avoided by adding the column and writing zero rows.
|
|
790
|
+
|
|
791
|
+
### Current State in C7-A (what is deliberately not in force)
|
|
792
|
+
|
|
793
|
+
| Thing | State in C7-A |
|
|
794
|
+
|---|---|
|
|
795
|
+
| `work_units.budget` / `used` | Columns only. No producer writes `budget`; `used` stays `0`. No budget semantics exist. |
|
|
796
|
+
| `paused_budget` | Expressible in the matrix, **no producer**. Nothing reaches it in this cut. |
|
|
797
|
+
| `parent_id` | Column exists, written `NULL` only. Parent/child delegation is C7-B. |
|
|
798
|
+
| Subagent budget | `DEFAULT_MAX_SUBAGENT_ITERATIONS` is still `Infinity` (`packages/core/src/tools/subagent.ts`); the aggregate breaker is still `SUBAGENT_MAX_AGGREGATE_ITERATIONS` (`packages/shared/src/limits.ts`). Two budget notions still exist. |
|
|
799
|
+
|
|
800
|
+
Budget unification, `paused_budget` production, `sessionLockKey` derivation from `context_ref`, and parent/child rows all belong to **C7-B**. This section must not describe a single budget semantic until that code exists — a document that runs ahead of the code teaches the next reader that the work is already done.
|
|
801
|
+
|
|
802
|
+
### Failure Semantics
|
|
803
|
+
|
|
804
|
+
Observation must never become a business fault, and it must never fail silently either — cut 6's lesson was a column that stayed empty with nothing to notice it. All business-path writers swallow write errors and emit a structured event. The four event names are the contract; tests assert on names and counters, never on log text:
|
|
805
|
+
|
|
806
|
+
| Event | Meaning |
|
|
807
|
+
|---|---|
|
|
808
|
+
| `work_unit.created` | A row was actually inserted (an idempotent hit is **not** this) |
|
|
809
|
+
| `work_unit.ensure_failed` | The row could not be created; business proceeds without identity, and the miss is counted |
|
|
810
|
+
| `work_unit.transition_failed` | Status update failed for a non-matrix reason (storage, or a concurrent write won) |
|
|
811
|
+
| `work_unit.link_failed` | The WorkUnit exists but the mailbox row could not be pointed at it |
|
|
812
|
+
|
|
813
|
+
One deliberate exception: an illegal transition is a program error, not a recoverable branch. `transition()` throws with `code='invalid_work_unit_transition'` and leaves the state unchanged. Returning `false` instead would let callers believe "the transition failed but the world is fine", which makes the matrix decorative.
|
|
814
|
+
|
|
815
|
+
### Reading It Back
|
|
816
|
+
|
|
817
|
+
`work_status()` answers "which WorkUnits does this agent have" from `work_units` alone, returning `ref / status / parentId / claimedBy / leaseUntil / budget / used`.
|
|
818
|
+
|
|
819
|
+
It reads no payload and no session text. A structural question must be answered by structure: the pre-cut-7 answer was recomputed from an injected text block every turn, which is a snapshot that can drift from what is really executing.
|
|
820
|
+
|
|
821
|
+
See [mailbox-system.md](./mailbox-system.md) for the delivery envelope and mailbox columns this identity is attached to.
|
|
822
|
+
|
|
823
|
+
### C7-B — budget has exactly one meaning now
|
|
824
|
+
|
|
825
|
+
C7-A deliberately left `budget` / `used` as empty columns. C7-B gives them semantics, and
|
|
826
|
+
the point of writing it here is that **there must never be a second budget notion**.
|
|
827
|
+
|
|
828
|
+
| Fact | Single source | What is forbidden |
|
|
829
|
+
|---|---|---|
|
|
830
|
+
| Unit of `budget` / `used` | **iteration count** (same unit as today's loop caps) | A second unit (e.g. tokens) computed anywhere; token quota is a future column, not a reinterpretation |
|
|
831
|
+
| Who writes `used` | `WorkUnitService.recordUsage()` → `SqliteWorkUnitRepo.addUsage()` (`used = used + ?`) | Any delegation path computing or writing its own tally |
|
|
832
|
+
| Who decides "budget reached" | `WorkUnitService.settle()` → the matrix | A path letting a child stop without a state + transition row |
|
|
833
|
+
|
|
834
|
+
Token accounting is not in this cut. When it arrives it gets its own columns; reusing
|
|
835
|
+
`budget` for tokens would silently rewrite the meaning of every existing row.
|
|
836
|
+
|
|
837
|
+
#### `paused_budget` — entry and exit
|
|
838
|
+
|
|
839
|
+
| Direction | Condition | Transition |
|
|
840
|
+
|---|---|---|
|
|
841
|
+
| Enter | the child's own iteration budget is exhausted (`used >= budget`, reported as `budgetHit: 'own'`) | `running → paused_budget` |
|
|
842
|
+
| Leave | budget is topped up | `paused_budget → running` |
|
|
843
|
+
| Leave | the work is cancelled | `paused_budget → terminated` |
|
|
844
|
+
|
|
845
|
+
`idle` and `paused_budget` are **not** the same fact: `idle` means "this unit finished its
|
|
846
|
+
turn", `paused_budget` means "this unit was stopped by money, not by completion". That
|
|
847
|
+
distinction lives in the state (and in the `status_transitions` row), never only in the
|
|
848
|
+
result text — otherwise "why did it stop" has to be re-derived from prose.
|
|
849
|
+
|
|
850
|
+
#### The circuit breaker is a breaker again
|
|
851
|
+
|
|
852
|
+
`SUBAGENT_MAX_AGGREGATE_ITERATIONS` (100) is **not** a schedule. The history is worth
|
|
853
|
+
recording because the prompt text was already right and the code was not: the fan-out used
|
|
854
|
+
to pre-allocate it as a shared pool (`{ remaining: 100 }`), so a wide fan-out consumed it as
|
|
855
|
+
its budget and siblings starved each other — the "zero-product fan-out" failure. The prompt
|
|
856
|
+
said `circuit breaker` the whole time.
|
|
857
|
+
|
|
858
|
+
What is true now:
|
|
859
|
+
|
|
860
|
+
- each child gets a **finite, independent** per-child budget (`iteration_budget`, else
|
|
861
|
+
`SUBAGENT_DEFAULT_ITERATION_BUDGET`); no child can spend a sibling's rope;
|
|
862
|
+
- scheduling lives in `work_units.budget` / `used` — one ledger, one writer;
|
|
863
|
+
- the aggregate constant survives only as an **abnormal fallback ceiling**, and the per-child
|
|
864
|
+
default is derived from it (`breaker / max parallel`), so a correctly configured full-width
|
|
865
|
+
fan-out lands exactly on the ceiling instead of silently exceeding it;
|
|
866
|
+
- an exhausted child returns a structured result (`status`, `budgetHit`, `iterations`,
|
|
867
|
+
`filesTouched`, `toolCalls`, and — from C7-B — its `workUnitRef`), never an empty success.
|
|
868
|
+
|
|
869
|
+
#### Delegation produces the parent/child chain
|
|
870
|
+
|
|
871
|
+
All **three** delegation paths create the child before running it, and all three land
|
|
872
|
+
`parent_id`. They differ only in where the parent comes from, and in each case it is a
|
|
873
|
+
structural fact, never an inference:
|
|
874
|
+
|
|
875
|
+
| Path | Child is created by | `parent_id` source | `ref` |
|
|
876
|
+
|---|---|---|---|
|
|
877
|
+
| `spawn_subagent` | `DelegationWorkUnitPort.ensureChild()` | the current turn's WorkUnit (`onFocusChanged`) | `WORK_UNIT_REF.delegation(parentRef, childKey)` |
|
|
878
|
+
| `spawn_subagents` (fan-out) | same port, once per child | same; `childKey` = caller's `task.id` | same generator |
|
|
879
|
+
| cross-team (A2A `deliver()`) | `DeliveryDeps.workUnits.ensure()` | the **sender** agent's current turn WorkUnit (`currentWorkUnitRef`) | `WORK_UNIT_REF.a2a(channelKey, deliveryId)` |
|
|
880
|
+
|
|
881
|
+
There is no "guess the most recent row". When a turn has no WorkUnit identity the child is
|
|
882
|
+
created with `parent_id = NULL` and its `ref` says so explicitly
|
|
883
|
+
(`delegation:root:<agentId>#<childKey>`); a delivery sent outside any turn (scheduled,
|
|
884
|
+
background) does the same.
|
|
885
|
+
|
|
886
|
+
The two inputs a caller may hand over are `parentId` (a handle it already holds) and
|
|
887
|
+
`parentRef` (it only knows *which* WorkUnit) — and `WorkUnitService.ensure()` owns the
|
|
888
|
+
`ref → id` resolution, with `parentId` winning when both are present. That keeps one
|
|
889
|
+
resolver: if every call site looked the parent up itself, the same fact would grow several
|
|
890
|
+
translations and they would drift.
|
|
891
|
+
|
|
892
|
+
Re-running the same fan-out collapses onto the same rows instead of multiplying identity —
|
|
893
|
+
the ref is idempotent by construction (`uq_work_units_ref` is the arbiter).
|
|
894
|
+
|
|
895
|
+
#### Where each chain's mailbox item comes from
|
|
896
|
+
|
|
897
|
+
`mailbox_items.work_unit_ref` is only honest when the item identity comes from the enqueue
|
|
898
|
+
that actually created it. Each chain has exactly one such moment:
|
|
899
|
+
|
|
900
|
+
| Chain | Item enqueued by | Linked at |
|
|
901
|
+
|---|---|---|
|
|
902
|
+
| chat | the turn's entry enqueue | `openChatTurnWorkUnit()` (turn **start**) |
|
|
903
|
+
| task | the enqueue **inside** `Agent.sendTaskExecution()` | `TaskService` run / retry call sites, via that call's `onItemEnqueued` |
|
|
904
|
+
| a2a | `AgentDelivery.deliver()` | `deliver()` itself, right after the enqueue |
|
|
905
|
+
|
|
906
|
+
The task chain is worth stating because the obvious guess is wrong: the item is **not**
|
|
907
|
+
produced by TaskService's notification enqueues (`task_comment`, `requirement_comment`,
|
|
908
|
+
`task_status_update`). Those address *other* agents or can be sent many times per execution
|
|
909
|
+
round, so they cannot identify "the item that triggered this round" — one epoch, many items.
|
|
910
|
+
The trigger item is the one `sendTaskExecution()` enqueues, and its id exists only as that
|
|
911
|
+
call's return value, which is why the callback is a required parameter rather than an
|
|
912
|
+
optional one: an optional callback would let a caller silently leave the column NULL again.
|
|
913
|
+
|
|
914
|
+
#### `sessionLockKey` derives from `context_ref`
|
|
915
|
+
|
|
916
|
+
The concurrency lock key answers "which memory session will this turn write to". C7-B takes
|
|
917
|
+
it from the WorkUnit ledger (`mailbox_items.work_unit_ref → work_units.context_ref`) instead
|
|
918
|
+
of re-deriving it from the payload, and a pure function
|
|
919
|
+
(`sessionLockKeyOfContextRef`) owns the rule: **only a memory session identity (`sess_*`)
|
|
920
|
+
can be a session lock key**. Anything else (`cs_*` database session ids, `task_…`,
|
|
921
|
+
`delegation:…`) returns `undefined` and the caller falls back to the legacy
|
|
922
|
+
`peekTurnSessionId` path.
|
|
923
|
+
|
|
924
|
+
Two properties follow, and both are load-bearing:
|
|
925
|
+
|
|
926
|
+
- **Equivalence**: for the same memory session, ledger and legacy paths produce the same key
|
|
927
|
+
(`session:<sess_*>`). Semantic drift is the only real risk of this change, so a test pins
|
|
928
|
+
the two paths to each other rather than testing the new one alone.
|
|
929
|
+
- **Fallback is mandatory**: an empty `work_unit_ref` (old rows, non-WorkUnit paths, a chat
|
|
930
|
+
item enqueued before its WorkUnit exists) must fall back, never return `undefined`, because
|
|
931
|
+
a missing lock key silently disables mutual exclusion — the worst possible regression
|
|
932
|
+
(2026-10-22 shape).
|
|
933
|
+
|
|
934
|
+
One benefit is structural: deriving from the ledger does not read the in-memory workspace
|
|
935
|
+
pointer, so it is safe outside the worker's ALS context — the trap the legacy path had to
|
|
936
|
+
document. The legacy path is kept as the fallback and stays the one that must be evaluated
|
|
937
|
+
inside ALS.
|
|
938
|
+
|
|
939
|
+
#### Current state after C7-B (honest boundaries)
|
|
940
|
+
|
|
941
|
+
| Thing | State |
|
|
942
|
+
|---|---|
|
|
943
|
+
| `budget` / `used` | Produced by delegation; unit = iterations; single writer as above |
|
|
944
|
+
| `paused_budget` | Reachable (child budget exhaustion) |
|
|
945
|
+
| `parent_id` | Written for all three delegation paths (subagent, fan-out, cross-team A2A) when the turn has a WorkUnit |
|
|
946
|
+
| `sessionLockKey` | Derived from `context_ref` for chat turns (memory session id, adopted at turn close), `task`/`a2a`/`delegation` context refs fall back |
|
|
947
|
+
| chat WorkUnit creation point | **Turn start** (`openChatTurnWorkUnit`), so `work_status()` can read `running` mid-turn; the close path only settles it to `idle` |
|
|
948
|
+
| task mailbox link | Written from `sendTaskExecution()`'s enqueue callback |
|