@markus-global/cli 0.11.2-rc.0 → 0.11.3-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/commands/start.js +5 -2
- package/dist/commands/start.js.map +1 -1
- package/dist/markus.mjs +1260 -1125
- package/dist/web-ui/assets/{CommentInput-Cqi5Hldw.js → CommentInput-C-niUbUY.js} +1 -1
- package/dist/web-ui/assets/{ContentRenderer-BAB3il9e.js → ContentRenderer-DxsnJJRX.js} +2 -2
- package/dist/web-ui/assets/{DeliverableShareModal-DJXkM66x.js → DeliverableShareModal-DV3TiZx0.js} +1 -1
- package/dist/web-ui/assets/{Deliverables-zKPxgZAN.js → Deliverables-tlLsJnxZ.js} +1 -1
- package/dist/web-ui/assets/{Notifications-HAycgg2x.js → Notifications-4KXYRdkr.js} +1 -1
- package/dist/web-ui/assets/{Search-SZuDcxy0.js → Search-CPFwZv1U.js} +1 -1
- package/dist/web-ui/assets/{Settings-CZgNsYSC.js → Settings-DIa-_qre.js} +6 -6
- package/dist/web-ui/assets/{Store-BS7VNrsr.js → Store-JWjwXfTU.js} +1 -1
- package/dist/web-ui/assets/Team-COBxn96h.js +84 -0
- package/dist/web-ui/assets/{Work-BN-LsW3k.js → Work-BScJUqWL.js} +1 -1
- package/dist/web-ui/assets/{arc-CsnWE2QW.js → arc-DPZmpo1U.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-CLek8I2z.js → architectureDiagram-3BPJPVTR-DlOs02JO.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-jSgWEHN7.js → blockDiagram-GPEHLZMM-C7qsXNUe.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-BaC188UT.js → c4Diagram-AAUBKEIU-Drwp-rtM.js} +1 -1
- package/dist/web-ui/assets/channel-DCChB-1T.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-CdtP4-T4.js → chunk-2J33WTMH-VgR09Mqk.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-BSgBKyC9.js → chunk-4BX2VUAB-CuwDpBRL.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-XB_ZMqfw.js → chunk-55IACEB6-nC7YWJ_i.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-YFPBFW4M.js → chunk-727SXJPM-Dw6mBsRE.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-CDbFN1Un.js → chunk-AQP2D5EJ-CPhNJbHl.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-BGKt8xP8.js → chunk-FMBD7UC4-AyhQakG8.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-DKicpX2b.js → chunk-ND2GUHAM-DgYemv8I.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-BD4tv8RZ.js → chunk-QZHKN3VN-CLdqxrFB.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-CrNiYfSI.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-CrNiYfSI.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-BjOoIarG.js → cose-bilkent-S5V4N54A-DrOgwDIH.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-BWal5GOH.js → dagre-BM42HDAG-DhoJiA83.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-CJj-CzRg.js → diagram-2AECGRRQ-BDILSgqK.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-4IMjuEPm.js → diagram-5GNKFQAL-CeXywd1i.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-DQiRAfss.js → diagram-KO2AKTUF-Bi4RlMT0.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-BMPvbEbY.js → diagram-LMA3HP47-Cw1yxk8b.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-D5_vmdXl.js → diagram-OG6HWLK6-Bl857da2.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-Cdouj_6e.js → docx-preview-CjoUhrMq.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-DOnDuvXd.js → erDiagram-TEJ5UH35-DEiaMhuV.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-DL6G76eC.js → flowDiagram-I6XJVG4X-BgKZhO0h.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-CwHnuRR8.js → ganttDiagram-6RSMTGT7-Dkx-EaS8.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-BFUnsmW_.js → gitGraphDiagram-PVQCEYII-DXaQwA0y.js} +1 -1
- package/dist/web-ui/assets/{index-BSktaJwx.js → index-C_QhfMcC.js} +74 -74
- package/dist/web-ui/assets/index-DEN_qReg.css +1 -0
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-DhU1bQNw.js → infoDiagram-5YYISTIA-Dpx9IOkx.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-o6ujfUJF.js → ishikawaDiagram-YF4QCWOH-BWqWgitQ.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-Dx_SZ8zv.js → journeyDiagram-JHISSGLW-BBwIZ4k9.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-D4BWXcIn.js → kanban-definition-UN3LZRKU-C_MRWV8R.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-BHDulYyB.js → mermaid.core-BMAh3nnq.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-BVy6py_h.js → mindmap-definition-RKZ34NQL-B6vJQcat.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-CUr5__J1.js → pieDiagram-4H26LBE5-BxdEttqt.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-C5Owt_r4.js → quadrantDiagram-W4KKPZXB-gsNs2VfP.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-Bb933lBb.js → requirementDiagram-4Y6WPE33-BSC9KvC2.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-CJq-boMJ.js → sankeyDiagram-5OEKKPKP-DktAZfe_.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-BP8L47v3.js → sequenceDiagram-3UESZ5HK-BIPt8kGU.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-Byk9-Yrm.js → stateDiagram-AJRCARHV-DiXmJWB0.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-COOgTXIX.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-2z8RR-l_.js → timeline-definition-PNZ67QCA-LRi7H35g.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-CSwDDhHv.js → vennDiagram-CIIHVFJN-DWQ1I022.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-DW30MdHd.js → wardley-L42UT6IY-BUb6dYqN.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-DUb2r21l.js → wardleyDiagram-YWT4CUSO-BYE1B3xT.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-4DTcVUL8.js → xychartDiagram-2RQKCTM6-D-pS2-Sa.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/docs/README.md +93 -0
- package/docs/api/api.md +353 -0
- package/docs/architecture/agent-runtime.md +341 -0
- package/docs/architecture/architecture-fragility.md +184 -0
- package/docs/architecture/architecture.md +938 -0
- package/docs/architecture/cognitive-architecture.md +322 -0
- package/docs/architecture/concurrent-processing.md +550 -0
- package/docs/architecture/frontend/team-chat.md +312 -0
- package/docs/architecture/learning-loop.md +340 -0
- package/docs/architecture/llm-provider-timeouts.md +60 -0
- package/docs/architecture/mailbox-system.md +1635 -0
- package/docs/architecture/memory-system.md +533 -0
- package/docs/architecture/prompt-engineering.md +1377 -0
- package/docs/architecture/state-machines.md +665 -0
- package/docs/architecture/state-ownership.md +83 -0
- package/docs/architecture/streaming-and-reattach.md +193 -0
- package/docs/architecture/tool-system.md +266 -0
- package/docs/design/deliverable-sharing.md +238 -0
- package/docs/guides/coding-tools.md +765 -0
- package/docs/guides/community.md +104 -0
- package/docs/guides/development.md +179 -0
- package/docs/guides/guide.md +362 -0
- package/docs/guides/release-and-distribution.md +165 -0
- package/docs/guides/remote-access.md +286 -0
- package/docs/guides/skill-ecosystem.md +129 -0
- package/docs/records/agent-platform-friction-2026-10.md +98 -0
- package/docs/records/animation-budget-focus-vs-visibility-2026-10-08.md +110 -0
- package/docs/records/audit-fixes-2026-09.md +173 -0
- package/docs/records/branch-consolidation.md +597 -0
- package/docs/records/file-edit-literal-replacement-fix.md +132 -0
- package/docs/records/message-stop-cancel-fix-plan.md +209 -0
- package/docs/records/platform-hardening-2026-10.md +1365 -0
- package/docs/records/session-identity-plan.md +130 -0
- package/docs/records/settings-model-routing-first-visit-fix.md +101 -0
- package/docs/records/team-chat-stream-transport-vs-turn-2026-10-08.md +152 -0
- package/package.json +2 -1
- package/templates/roles/HANDBOOK.md +12 -7
- package/dist/web-ui/assets/Team-B6vw2Oj5.js +0 -84
- package/dist/web-ui/assets/channel-CqbBz9iL.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-DDQJP38f.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-DDQJP38f.js +0 -1
- package/dist/web-ui/assets/index-3PQIqBtv.css +0 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-CWa-Q2Gf.js +0 -1
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
# Markus Agent Runtime
|
|
2
|
+
|
|
3
|
+
> Single source of truth for **Context Economics + Learning Loop**.
|
|
4
|
+
> Spec language: **MUST** / **SHOULD** / **MUST NOT**. Test IDs map to plan Wave A/B/C.
|
|
5
|
+
> Related: [prompt-engineering.md](./prompt-engineering.md), [tool-system.md](./tool-system.md),
|
|
6
|
+
> [memory-system.md](./memory-system.md), [learning-loop.md](./learning-loop.md),
|
|
7
|
+
> [state-machines.md](./state-machines.md).
|
|
8
|
+
|
|
9
|
+
**Formula**: `Agent = LLM + Harness + Learning Loop`.
|
|
10
|
+
**Hard constraint**: the Context Surface keeps cold-start fixed prefix cheap while skills/experience grow unbounded.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## §1 Invariants
|
|
15
|
+
|
|
16
|
+
### §1.1 Fixed-prefix budget
|
|
17
|
+
|
|
18
|
+
MUST: Every LLM call's fixed prefix `systemTokens + toolDefTokens` MUST fit the active scenario pack budget (see §3) before history is considered.
|
|
19
|
+
|
|
20
|
+
MUST: When `promptAffordTokens` is known and
|
|
21
|
+
`systemTokens + toolDefTokens + PROMPT_AFFORD_OUTPUT_RESERVE + safetyMargin > promptAffordTokens`,
|
|
22
|
+
the runtime MUST downgrade once to the `reflex` pack+profile and re-pack; if still over, it MUST NOT call the provider (`prompt_pack_rejected`).
|
|
23
|
+
|
|
24
|
+
MUST (§Afford.S1): The same afford gate MUST run on **every** LLM entry that calls
|
|
25
|
+
`prepareMessages` before the provider — including `handleMessage` **and**
|
|
26
|
+
`handleMessageStream` (and task streams that share prepare). Shared helper
|
|
27
|
+
`ensureAffordablePromptPack` MUST be used so stream/non-stream cannot drift.
|
|
28
|
+
|
|
29
|
+
MUST NOT: Shrink only `messageBudget` while shipping a fixed prefix that already exceeds afford.
|
|
30
|
+
|
|
31
|
+
Test IDs: `A-afford-downgrade`, `A-afford-heartbeat-fail`, `A-budget-contract-converse`,
|
|
32
|
+
`A-budget-contract-reflex`, `S-stream-afford-reject`, `S-stream-afford-downgrade`.
|
|
33
|
+
|
|
34
|
+
### §1.2 Unlimited capability, limited visibility
|
|
35
|
+
|
|
36
|
+
MUST: Skill full bodies and deferred tool schemas MUST enter context only via `discover_tools` (or equivalent L1 load). Cold start exposes L0 catalog (name + short description) only.
|
|
37
|
+
|
|
38
|
+
MUST NOT: Inject full SKILL.md bodies at spawn into the system prompt.
|
|
39
|
+
|
|
40
|
+
Test IDs: `A-skill-l0-only`, `A-tooldef-budget`.
|
|
41
|
+
|
|
42
|
+
### §1.3 Execute ≠ learn
|
|
43
|
+
|
|
44
|
+
MUST: Task execution MUST NOT write new team skills. Distillation runs after **`completed`**
|
|
45
|
+
(including rejection→revision→approval) via the Learning Loop hook with **`scenario: distillation`**
|
|
46
|
+
([learning-loop.md](./learning-loop.md) §2) — MUST NOT reuse Dream's `memory_consolidation`.
|
|
47
|
+
MUST NOT: Distill on `failed`.
|
|
48
|
+
|
|
49
|
+
Test IDs: `B-hook-skip-trivial`, `B-hook-fire-complex`, `B-hook-skip-failed`,
|
|
50
|
+
`B-distill-uses-distillation-scenario`.
|
|
51
|
+
|
|
52
|
+
### §1.4 Human gate for evolution
|
|
53
|
+
|
|
54
|
+
MUST: High-impact (or impact-omitted) skill installs require human approve via HITL
|
|
55
|
+
([learning-loop.md](./learning-loop.md) §8.3). Low-impact skill installs MAY proceed without HITL.
|
|
56
|
+
Optional `.pending/` staging (§3) remains a helper path.
|
|
57
|
+
|
|
58
|
+
MUST NOT: Couple skill usage/success metrics to trust score.
|
|
59
|
+
|
|
60
|
+
Test IDs: `B-approve-install`, `B-reject-feedback`, `B-stats-reject-feedback`.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## §2 Scenario Capability Packs
|
|
65
|
+
|
|
66
|
+
### §2.1 Pack definitions
|
|
67
|
+
|
|
68
|
+
| Pack | Scenarios | ToolDef budget (tokens) | Prompt profile |
|
|
69
|
+
|------|-----------|-------------------------|----------------|
|
|
70
|
+
| `reflex` | `memory_consolidation` (Dream), `memory_flush`, `distillation` | 3_000 | `reflex` |
|
|
71
|
+
| `converse` | `heartbeat`, `chat`, `a2a`, `group_chat`, `comment_response`, `requirement_action`, `workflow_action` | 8_000 | `converse` |
|
|
72
|
+
| `execute` | `task_execution` | 10_000 | `execute` |
|
|
73
|
+
| `govern` | `review`, `deliberation` | 8_000 | `govern` |
|
|
74
|
+
|
|
75
|
+
MUST: `selectTools` / allowlists MUST resolve through the pack for the active scenario.
|
|
76
|
+
|
|
77
|
+
### §2.2 Reflex core tools
|
|
78
|
+
|
|
79
|
+
MUST: `reflex` tool set MUST be a subset of:
|
|
80
|
+
|
|
81
|
+
`task_list`, `task_get`, `memory_save`, `memory_search`, `notify_user`, `request_user_input`,
|
|
82
|
+
`schedule_wakeup`, `cancel_wakeup`, `set_heartbeat_interval`, `discover_tools`,
|
|
83
|
+
`check_mailbox`, `file_read`, `agent_send_message`, `notebook_upsert`,
|
|
84
|
+
and for managers additionally `team_status`.
|
|
85
|
+
|
|
86
|
+
MUST NOT: Include `package_install`, `package_list`, `goal_create`, `goal_update`, `goal_status`,
|
|
87
|
+
`spawn_subagent`, `spawn_subagents`, `deliverable_create`, `requirement_propose`,
|
|
88
|
+
`memory_update_longterm` in the default reflex allowlist (reachable only via `discover_tools`).
|
|
89
|
+
|
|
90
|
+
### §2.2.1 Distillation allowlist extras
|
|
91
|
+
|
|
92
|
+
MUST: When `scenario: distillation`, the runtime MAY widen the allowlist with:
|
|
93
|
+
`memory_update`, `memory_update_longterm`, `file_write`, `file_edit`,
|
|
94
|
+
`package_list`, `package_install` (plus reflex core, which already includes `request_user_input`).
|
|
95
|
+
MUST NOT: Add `hub_install` on the distillation turn.
|
|
96
|
+
MUST: Skill `package_install` follows Learning Habits impact/HITL
|
|
97
|
+
([learning-loop.md](./learning-loop.md) §2.2 / §8.3) — high/omitted impact asks first.
|
|
98
|
+
MUST: Inject Learning Habits for `distillation`; MUST NOT inject them for `memory_consolidation`.
|
|
99
|
+
|
|
100
|
+
Test IDs: `A-pack-reflex-tools`, `B-hb-no-evolution-essay`, `B-distill-package-install-allowed`,
|
|
101
|
+
`B-distill-habits-injected`, `B-dream-no-habits`.
|
|
102
|
+
|
|
103
|
+
### §2.3 Converse / execute / govern
|
|
104
|
+
|
|
105
|
+
MUST: Default `converse` MUST NOT include `spawn_subagents` or `deliverable_create` (discover only).
|
|
106
|
+
|
|
107
|
+
MUST: `execute` MUST include code/shell/coding groups (or equivalent) needed for task work.
|
|
108
|
+
|
|
109
|
+
MUST: Keyword matching and `recentToolNames` MAY accelerate loading but MUST NOT exceed the pack `toolDefTokens` budget.
|
|
110
|
+
|
|
111
|
+
Test IDs: `A-pack-converse-no-spawn`, `A-pack-execute-has-code`, `A-tooldef-sticky-capped`.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## §3 Budgets
|
|
116
|
+
|
|
117
|
+
| Constant | Value | Purpose |
|
|
118
|
+
|----------|-------|---------|
|
|
119
|
+
| `TOOL_DEF_BUDGET_REFLEX` | 3_000 | Max tool schema tokens |
|
|
120
|
+
| `TOOL_DEF_BUDGET_CONVERSE` | 8_000 | Max tool schema tokens |
|
|
121
|
+
| `TOOL_DEF_BUDGET_EXECUTE` | 10_000 | Max tool schema tokens |
|
|
122
|
+
| `TOOL_DEF_BUDGET_GOVERN` | 8_000 | Max tool schema tokens |
|
|
123
|
+
| `ROLE_PROMPT_MAX_TOKENS` | 6_000 | ROLE soft size metric (warn only; never truncate) |
|
|
124
|
+
| `KNOWLEDGE_PROMPT_MAX_TOKENS` | 1_500 | knowledge.md injection (`execute`/`govern`) |
|
|
125
|
+
| `KNOWLEDGE_PROMPT_MAX_TOKENS_CONVERSE` | 1_200 | knowledge.md injection (`converse`) |
|
|
126
|
+
| `KNOWLEDGE_PROMPT_MAX_TOKENS_REFLEX` | 0 | reflex: no full knowledge dump |
|
|
127
|
+
| ~~`STATE_PROMPT_MAX_LINES_REFLEX`~~ | — | **removed 2026-09-16**: retired with the state.md store — situational state now rides in the notebook's `system` tier |
|
|
128
|
+
| ~~`STATE_TTL_DAYS`~~ | — | **removed 2026-09-16**: replaced by the notebook's per-tier TTL (`NOTEBOOK_TTL_MS_*`) |
|
|
129
|
+
| `COLD_CONVERSE_FIXED_MAX` | 28_000 | Acceptance: system+tools |
|
|
130
|
+
| `COLD_REFLEX_FIXED_MAX` | 8_000 | Acceptance: system+tools |
|
|
131
|
+
| `SYSTEM_PROMPT_BUDGET_CONVERSE` | 16_000 | Soft size metric for converse system (observe/warn; never truncate ROLE/L0) |
|
|
132
|
+
| `SYSTEM_ANNOUNCEMENTS_CHARS_CONVERSE` | 400 | Team announcements body cap (converse) |
|
|
133
|
+
| `SYSTEM_NORMS_CHARS_CONVERSE` | 400 | Team norms body cap (converse) |
|
|
134
|
+
| `SYSTEM_ANNOUNCEMENTS_CHARS` | 2_000 | Team announcements body cap (execute/govern) |
|
|
135
|
+
| `SYSTEM_NORMS_CHARS` | 2_000 | Team norms body cap (execute/govern) |
|
|
136
|
+
| `SYSTEM_WORKFLOWS_MAX_CONVERSE` | 3 | Available-workflow lines in converse |
|
|
137
|
+
| `SYSTEM_DYNAMIC_CONTEXT_CHARS_CONVERSE` | 800 | Caller `dynamicContext` blob cap (converse) |
|
|
138
|
+
| `DEFERRED_CATALOG_MAX_CHARS` | 1_500 | Tier-3 rediscovery catalog hard cap |
|
|
139
|
+
| `DEEP_SLEEP_IDLE_HEARTBEATS` | 3 | Consecutive idle before skip LLM |
|
|
140
|
+
| `SUBTASK_SOFT_CAP` | 8 | Warn at/above this count |
|
|
141
|
+
|
|
142
|
+
Constants live in `@markus/shared` `limits.ts`.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## §4 Prompt Profiles
|
|
147
|
+
|
|
148
|
+
### §4.1 Profile → sections
|
|
149
|
+
|
|
150
|
+
| Section | reflex | converse | execute/govern |
|
|
151
|
+
|---------|--------|----------|----------------|
|
|
152
|
+
| ROLE (full; soft warn metric) | yes | yes | yes |
|
|
153
|
+
| L0 + Collaboration Rules | yes (complete, concise) | yes (complete, concise) | yes (complete, concise) |
|
|
154
|
+
| Identity (roster) | manager + ≤3 active | capped (existing max) | capped |
|
|
155
|
+
| knowledge.md | no | capped (`KNOWLEDGE_PROMPT_MAX_TOKENS_CONVERSE`) | capped (`KNOWLEDGE_PROMPT_MAX_TOKENS`) |
|
|
156
|
+
| ~~state.md~~ | — | retired 2026-09-16 → notebook `system` tier | — |
|
|
157
|
+
| Skill L0 catalog | yes | yes | yes |
|
|
158
|
+
| Skill full bodies | discover only | discover only | discover only |
|
|
159
|
+
| L3 checklists (quality/git/error recovery) | no | **no** (incl. `comment_response`) | yes |
|
|
160
|
+
| Team announcements / norms | capped | capped (400 chars) | capped (2000 chars) |
|
|
161
|
+
| Available workflows | as needed | ≤3 short lines | full list |
|
|
162
|
+
| Channel history / shared deliverables | no | optional short | as needed |
|
|
163
|
+
| Task board detail | counts + top blocked/failed | only when non-empty | existing caps (empty stub ok) |
|
|
164
|
+
| Date / locale / Interaction Mode | yes | **always** (never trimmed) | yes |
|
|
165
|
+
|
|
166
|
+
MUST: `buildSystemPrompt` MUST accept `promptProfile` derived from scenario pack.
|
|
167
|
+
|
|
168
|
+
MUST: Size control is **progressive disclosure**, not truncation of always-on text:
|
|
169
|
+
- Always-on (never truncated): ROLE.md (persona only — **not** HANDBOOK.md), L0 capability
|
|
170
|
+
rules, **`## Markus Collaboration Rules`** (distilled from HANDBOOK.md), Interaction Mode,
|
|
171
|
+
date/locale.
|
|
172
|
+
- Collaboration Rules MUST encode **Conversation-first + Task-when-needed**: chat may
|
|
173
|
+
pair-build; tasks for async/delegation/formal review; STOP only after `task_create`
|
|
174
|
+
for that work. Managers are player-coach (ROLE may build; Position routes when useful).
|
|
175
|
+
- Progressive at assemble: knowledge digest (demote `##`→`###`, deprioritize stale
|
|
176
|
+
fault/transcript sections), announcements/norms, workflows, CONTEXT.md
|
|
177
|
+
(full content on disk / via tools). HANDBOOK.md long-form is the **AGENT HANDBOOK** —
|
|
178
|
+
a single source of truth (`templates/roles/HANDBOOK.md`) that ships with the build and
|
|
179
|
+
upgrades on rebuild/release; it is **NOT injected** and **NOT copied per-agent**. The
|
|
180
|
+
`## Platform Handbook (on demand)` section injects the **resolved absolute path**
|
|
181
|
+
(via `AgentManager.resolveHandbookPath`), so agents `file_read` the handbook directly
|
|
182
|
+
without searching it.
|
|
183
|
+
- Progressive at tool layer: Markus core schemas LIVE; skill/MCP schemas only after
|
|
184
|
+
`discover_tools` (boot MUST register without activate; sticky/recent MUST NOT
|
|
185
|
+
re-activate skill/MCP). Activated skill/MCP MAY LRU-defer under toolDef budget;
|
|
186
|
+
CORE_KEEP + HITL + discover never defer.
|
|
187
|
+
- Heartbeat MUST skip/defer LLM turns while `human_chat` is focused or queued.
|
|
188
|
+
- Team Status SHOULD label stopped agents as `stopped` (not scary `offline`); when
|
|
189
|
+
all listed teammates are stopped, hint `agent_start` and that Owner chat work may continue.
|
|
190
|
+
- Work-context-bound tools (`task_submit_review`, subtasks, `task_note`, …) MUST appear
|
|
191
|
+
LIVE only in **entity-bound sessions**: `execute` / `govern`, or converse scenarios
|
|
192
|
+
`comment_response` / `requirement_action` / `workflow_action`. MUST NOT sticky into
|
|
193
|
+
free `chat` / `a2a` / `group_chat` / reflex. `task_submit_review` resolves `task_id`
|
|
194
|
+
from ALS/`activeTasks` when present; otherwise the agent MUST pass `task_id`
|
|
195
|
+
(no board guessing).
|
|
196
|
+
|
|
197
|
+
MUST (§Afford.S3): `SYSTEM_PROMPT_BUDGET_CONVERSE` is an observe/warn metric only.
|
|
198
|
+
MUST NOT: Runtime-truncate ROLE, L0, or Collaboration Rules to fit that metric.
|
|
199
|
+
Provider afford guard handles hard limits (downgrade/reject).
|
|
200
|
+
|
|
201
|
+
Test IDs: `A-profile-reflex-omits`, `A-profile-role-full`, `A-collab-rules-always-on`,
|
|
202
|
+
`A-role-no-shared-append`, `A-knowledge-cap`, `A-profile-converse-no-l3`,
|
|
203
|
+
`S-converse-keeps-essentials`, `S-converse-keeps-date`, `S-tool-mcp-progressive`.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## §5 ToolDef budget eviction (Hermes Tool Search style)
|
|
208
|
+
|
|
209
|
+
MUST: Skill/MCP tool schemas (`feishu_*`, `*__*`, `chrome-devtools*`) MUST NOT enter
|
|
210
|
+
the LIVE tool list except via explicit `discover_tools` activation.
|
|
211
|
+
MUST: Markus core tools (`TOOL_DEF_CORE_KEEP`: shell/file/task/memory/…) +
|
|
212
|
+
`discover_tools` + HITL MUST stay LIVE for converse/execute/govern.
|
|
213
|
+
MUST: When estimated tool-definition tokens still exceed the pack budget, evict
|
|
214
|
+
optional extras / activated skill-MCP (LRU) only — never CORE_KEEP or HITL/discover.
|
|
215
|
+
Prefer catalog (Tier 3 / inactive namespace list) over schema dump.
|
|
216
|
+
|
|
217
|
+
Test IDs: `S-tool-mcp-progressive`, `S-tooldef-evict-mcp-before-core`, `S-activated-mcp-lru`.
|
|
218
|
+
|
|
219
|
+
MUST (§Afford.S2): Evicted tool rediscovery catalog MUST be injected into the volatile
|
|
220
|
+
`[Live context]` tail (never a system segment — byte-stable prefix must be preserved), as a
|
|
221
|
+
short name-only (or name + ≤40 chars) list, total ≤ `DEFERRED_CATALOG_MAX_CHARS`.
|
|
222
|
+
|
|
223
|
+
MUST NOT: Append the eviction catalog to `discover_tools.description` (that re-inflates
|
|
224
|
+
`toolDefTokens` and defeats the budget).
|
|
225
|
+
|
|
226
|
+
MUST: After `discover_tools` activates tool names, the runtime MUST rebuild the LLM
|
|
227
|
+
`tools` schema list before the next provider call (stream / chat / task / session
|
|
228
|
+
continuations). Core + HITL stay immune; skill/MCP activations may later LRU-defer.
|
|
229
|
+
MUST NOT: Reuse a stale pre-discover `llmTools` array across tool-loop iterations —
|
|
230
|
+
that makes activation a no-op and causes discover_tools death spirals.
|
|
231
|
+
MUST: Consecutive `discover_tools` calls (any args) ≥ 5 MUST be treated as a
|
|
232
|
+
critical loop and break the tool loop.
|
|
233
|
+
|
|
234
|
+
Test IDs: `A-tooldef-budget`, `A-tooldef-sticky-capped`, `S-catalog-not-in-tooldef`,
|
|
235
|
+
`S-discover-activated-protected`, `S-discover-tools-spin`.
|
|
236
|
+
|
|
237
|
+
### §5.1 max_tokens reservation clamp (§Afford.S4)
|
|
238
|
+
|
|
239
|
+
MUST: On OpenRouter reservation 402 (`requested up to N … can only afford M`), retry with
|
|
240
|
+
`max_tokens = min(M, max(512, M - safety))`.
|
|
241
|
+
|
|
242
|
+
MUST: When `lastPromptAffordTokens` is known, **first** request MUST also clamp
|
|
243
|
+
`max_tokens ≤ promptAfford - estimatedPrompt - margin` so the client does not send a
|
|
244
|
+
doomed high reservation (e.g. 13156) before failing.
|
|
245
|
+
|
|
246
|
+
Test IDs: `S-max-tokens-clamp-remaining`.
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## §6 Memory taxonomy
|
|
251
|
+
|
|
252
|
+
MUST: Persistent semantic storage MUST use:
|
|
253
|
+
|
|
254
|
+
| File | Role |
|
|
255
|
+
|------|------|
|
|
256
|
+
| `knowledge.md` | Permanent curated knowledge |
|
|
257
|
+
| ~~`state.md`~~ | Retired 2026-09-16 — folded into the notebook's `system` tier via a one-time migration (key `legacy-state`). See [memory-system.md](./memory-system.md) §2 |
|
|
258
|
+
| `NOTEBOOK.md` | Situational workspace |
|
|
259
|
+
| observations buffer | Raw insights; never fully injected |
|
|
260
|
+
|
|
261
|
+
MUST: On first load, migrate legacy `MEMORY.md` (heuristic: dated/silent/current → state; else knowledge).
|
|
262
|
+
|
|
263
|
+
Details: [memory-system.md](./memory-system.md).
|
|
264
|
+
|
|
265
|
+
Test IDs: `A-knowledge-cap`, `C-dream-state-ttl`.
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## §7 Learning Loop (summary)
|
|
270
|
+
|
|
271
|
+
State machine: `task completed → DistillationHook → Habits encode (memory / skill+HITL) → stats → DreamLibrarian → fanout`.
|
|
272
|
+
|
|
273
|
+
Also: platform **Learning Habits** L0 (look-back / encode-where / skill impact) and user-initiated
|
|
274
|
+
**Remember-from-message** → child evolution session (user↔agent DM only).
|
|
275
|
+
|
|
276
|
+
Details and MUST rules: [learning-loop.md](./learning-loop.md) §2–§9.
|
|
277
|
+
|
|
278
|
+
Test IDs (habits / remember): `B-prompt-learning-habits-*`, `B-skill-install-*`,
|
|
279
|
+
`B-self-evolution-skill-retired`, `B-evolve-*`, `B-recall-chat-session-*`, `B-ui-remember-*`.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## §8 Governance (summary)
|
|
284
|
+
|
|
285
|
+
- Review verdicts: `approved` | `approved_with_notes` | `rejected`
|
|
286
|
+
- `task_context` attached on assign
|
|
287
|
+
- Deliverable `version` + `changelog`
|
|
288
|
+
- Deep sleep after idle heartbeats
|
|
289
|
+
- Subtask soft cap warning
|
|
290
|
+
|
|
291
|
+
Details: [state-machines.md](./state-machines.md) and TOOL/MEMORY docs.
|
|
292
|
+
|
|
293
|
+
Test IDs: `C-review-notes`, `C-task-context-inject`, `C-deliv-version`, `C-subtask-soft-cap`, `A-deep-sleep-skip`, `A-deep-sleep-wake`.
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## §9 Acceptance metrics
|
|
298
|
+
|
|
299
|
+
| Metric | Target | Verify |
|
|
300
|
+
|--------|--------|--------|
|
|
301
|
+
| Cold converse fixed | ≤ 28_000 | `A-budget-contract-converse` + live |
|
|
302
|
+
| Cold reflex fixed | ≤ 8_000 | `A-budget-contract-reflex` + live |
|
|
303
|
+
| Deep sleep quiet period | 0 LLM calls | `A-deep-sleep-skip` + live |
|
|
304
|
+
| Afford over fixed | 0 provider calls | `A-afford-downgrade` |
|
|
305
|
+
| Skill library growth | Does not increase fixed L0 cost beyond catalog | `A-skill-l0-only` |
|
|
306
|
+
| Evolution rates API | reuse / first-pass / distill rate | `C-metrics-api` |
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## §10 Spec → Test → Implement → Verify
|
|
311
|
+
|
|
312
|
+
1. Spec merged (this doc + linked specs).
|
|
313
|
+
2. Failing tests with Test IDs above.
|
|
314
|
+
3. Minimal implementation to green.
|
|
315
|
+
4. Verify checklist against MUST rows; live cold-start logs for Wave D.
|
|
316
|
+
|
|
317
|
+
If Spec is wrong: fix Spec → fix tests → fix code (never hack around Spec).
|
|
318
|
+
|
|
319
|
+
## §11 Verification checklist (Wave D)
|
|
320
|
+
|
|
321
|
+
Automated (must be green):
|
|
322
|
+
|
|
323
|
+
- [x] `packages/core/test/capability-packs.test.ts` (A-pack-*, A-tooldef-*)
|
|
324
|
+
- [x] `packages/core/test/afford-guard.test.ts` (A-afford-*)
|
|
325
|
+
- [x] `packages/core/test/deep-sleep.test.ts` (A-deep-sleep-*)
|
|
326
|
+
- [x] `packages/core/test/prompt-profiles.test.ts` (A-profile-*, B-hb-no-evolution-essay)
|
|
327
|
+
- [x] `packages/core/test/prompt-budget.contract.test.ts` (A-budget-contract-*)
|
|
328
|
+
- [x] `packages/core/test/learning-loop.test.ts` (B-hook-*, B-stats-*)
|
|
329
|
+
- [x] `packages/core/test/memory-taxonomy.test.ts` (A-knowledge / C-dream-state-ttl)
|
|
330
|
+
- [x] `packages/core/test/skill-fanout.test.ts` (C-fanout-*, C-task-context-inject)
|
|
331
|
+
- [x] `packages/core/test/evolution-metrics.test.ts` + `GET /api/evolution/metrics` (C-metrics-api)
|
|
332
|
+
- [x] `packages/core/test/governance-runtime.test.ts` (C-review-notes / C-subtask-soft-cap)
|
|
333
|
+
|
|
334
|
+
Live (operator):
|
|
335
|
+
|
|
336
|
+
1. Cold chat: log `systemTokens`+`toolDefTokens` ≤ 12k
|
|
337
|
+
2. Cold heartbeat / deep sleep: ≤ 8k fixed; idle skips LLM
|
|
338
|
+
3. Low afford: `prompt_pack_rejected` without OR call
|
|
339
|
+
4. Complex task complete → distillation (Habits encode; skill install via §8.3 HITL)
|
|
340
|
+
5. Deliverable update returns `version` bump
|
|
341
|
+
6. `acceptTask(..., notes)` stores `approved_with_notes`
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Markus Architecture Fragility Root-Cause Analysis
|
|
2
|
+
|
|
3
|
+
> **Status: analysis record (2026-09), largely resolved.** Fragilities fixed since are marked ✅
|
|
4
|
+
> in place rather than deleted, so the reasoning stays available.
|
|
5
|
+
|
|
6
|
+
> 2026-09-11 · Origin: after fixing "later requests in the same session can't see history", the boss raised
|
|
7
|
+
> a more fundamental question — why does this system always have fragile bugs? Is it an architecture problem?
|
|
8
|
+
> Why are we always patching, always depending on manual test feedback?
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 0. Conclusion in one sentence
|
|
13
|
+
|
|
14
|
+
**It is not that "some bug wasn't fixed properly"; it is that three classes of hard constraint are missing:
|
|
15
|
+
the state ownership contract, failure visibility, and invariant tests.**
|
|
16
|
+
|
|
17
|
+
Every fix on its own was correct; but the **implicit premises** those fixes rest on were neither written into
|
|
18
|
+
the docs nor guarded by tests. So the next structural change (for example a change in the right direction such
|
|
19
|
+
as "push state down into per-worker workspaces") breaks those premises **without anyone noticing**. Today's bug
|
|
20
|
+
is a **necessary window** produced by three individually-reasonable decisions stacking up — not a random failure.
|
|
21
|
+
|
|
22
|
+
Another brutal fact: before and after this fix, the core package's **2568 tests were all green** — test count
|
|
23
|
+
does not equal invariant coverage. The real gap is not "too few tests", it is that **we're testing the wrong
|
|
24
|
+
things**: the vast majority of cases assert implementation snapshots, while very few assert properties the
|
|
25
|
+
system must always satisfy.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 1. Evidence list (all from today's actual findings, not gut feeling)
|
|
30
|
+
|
|
31
|
+
| # | Fact | Problem exposed |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| 1 | The same fix was delivered **twice**: `2bbdc7d7` (this branch) and `4454b4f3` (another branch), equivalent in content, sitting on two branches | Missing delivery de-duplication; unclear branch semantics |
|
|
34
|
+
| 2 | That fix internally **copy-pasted the `isResume` 400 guard twice** | Copy-paste patching; missing pre-commit static checks |
|
|
35
|
+
| 3 | In `packages/core/src/agent.ts`, **12** `console.error('[HM]/[PMC]/[CAS]')` debug prints were left in production code, spitting the sessionId to stderr on every message — **✅ resolved:** none remain, and `scripts/architecture-guard.mjs` enforces `no-console` | Missing pre-commit gate (no-console) |
|
|
36
|
+
| 4 | 1200 lines of legacy dead code lingered for months, justified by "the file tool that contains `<thinking>` can't be deleted" — **it actually can be deleted when you test it** | A wrong conclusion inherited as fact; nobody reproduced it |
|
|
37
|
+
| 5 | `MemoryStore.getRecentMessages` **silently returns `[]`** for an unknown id, and doesn't check disk — **✅ resolved:** it now lazily loads from disk and `log.warn`s on unknown/empty ids (`memory/store.ts`) | Silent degradation: an error disguised as "no history" |
|
|
38
|
+
| 6 | Session context is written to `rootWorkspace` only on the HTTP thread, while messages are processed by a worker in its own workspace | No state ownership contract; scope changed behind our backs |
|
|
39
|
+
| 7 | Two concurrency gates contradict each other (worker gate = 3 / task gate = 1); 3 workers grab 3 tasks while 2 of them wait for nothing | The same semantics implemented twice; no single source of truth |
|
|
40
|
+
| 8 | Two id spaces, DB session id (`cs_*`) and in-memory session id (`sess_*`), kept consistent via `dbSessionMap` + metadata binding | Dual storage held together by convention, with no invariant checking |
|
|
41
|
+
| 9 | Across the whole repo there is **not a single** test for "two consecutive messages in the same session must see history" — **✅ resolved:** `packages/core/test/conversation-session-invariants.test.ts` now asserts it | Zero coverage of a critical invariant → only users can discover it |
|
|
42
|
+
| 10 | When `OPENAI_API_KEY` is present on the machine, tests really call the embedding API, hanging for ~10s per run — **✅ resolved:** session-invariant tests now delete `OPENAI_API_KEY` to stay offline | Test environment not isolated; CI noise masks real problems |
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 2. Five classes of structural root cause
|
|
47
|
+
|
|
48
|
+
### R1 Implicit shared mutable state + silent scope change ← **today's main culprit**
|
|
49
|
+
State such as `currentSessionId`, `activeScenario`, `turnModelOverride` was pushed down from "agent-level
|
|
50
|
+
singleton" to "per-worker workspace" (`workspace() = ALS ?? rootWorkspace`). This is the right direction, but it
|
|
51
|
+
**changes the meaning of every existing read site**: the HTTP thread always reads the root workspace, a worker
|
|
52
|
+
always reads its own. Any "written by an external thread, read by a worker" pattern silently breaks — and that is
|
|
53
|
+
exactly what happened today.
|
|
54
|
+
|
|
55
|
+
**Signature**: the change itself is legitimate, the code compiles, existing tests stay green, but the semantics
|
|
56
|
+
have already changed.
|
|
57
|
+
|
|
58
|
+
### R2 Silent degradation: failures disguised as normal
|
|
59
|
+
- `getRecentMessages(unknown id)` → `[]`
|
|
60
|
+
- `persistUserMessage` failure → returns `null` (the client carries on with a placeholder id)
|
|
61
|
+
- `getSession(not found)` → straight to `createSession` creating a new one
|
|
62
|
+
- `catch {}` / exceptions swallowed at `debug` level only
|
|
63
|
+
- fire-and-forget refresh with no de-duplication, results possibly overwriting each other out of order
|
|
64
|
+
|
|
65
|
+
**Harm**: errors stop producing noise and only show up on the user's side as "something feels off". **This is the
|
|
66
|
+
primary reason bugs stay latent for so long**.
|
|
67
|
+
|
|
68
|
+
### R3 Dual storage / dual id spaces held together by convention
|
|
69
|
+
`chatSessionRepo(cs_*)` and `MemoryStore(sess_*)` are two sources of truth, kept consistent by a "binding table +
|
|
70
|
+
metadata", but with no single SSOT, no startup self-check, and no consistency alerting. Once a binding write is
|
|
71
|
+
missed (common under concurrency), the system "falls back to a thin rebuild" (history is left with only
|
|
72
|
+
user/assistant rows; tool calls and results are all lost — measured 57 → 3 entries).
|
|
73
|
+
|
|
74
|
+
### R4 Multiple implementations of the same semantics
|
|
75
|
+
- Two message-processing pipelines, stream and non-stream (discovered today: **only the non-streaming one honors an explicit session id**)
|
|
76
|
+
- Two frontend implementations, legacy and hook, coexisting for a long time
|
|
77
|
+
- Two concurrency gates, each independent
|
|
78
|
+
- Two id namespaces, each resolved separately
|
|
79
|
+
|
|
80
|
+
**Consequence**: fix one path and the other becomes a hidden trap; "fixed" holds only on one path.
|
|
81
|
+
|
|
82
|
+
### R5 Missing invariant tests and commit gates, verification depends on humans
|
|
83
|
+
- Critical invariants (same-session history continuity, cross-worker session consistency, restart recoverability, no id-space mixing) have **zero coverage**
|
|
84
|
+
- Debug prints, dead code, empty `catch`, duplicate fixes all make it into the repo
|
|
85
|
+
- Structural changes have no "writer-reader" checklist; everything relies on memory
|
|
86
|
+
|
|
87
|
+
**Result**: the boss became the only integration test environment.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 3. Why "refactoring" actually amplifies fragility (mechanism)
|
|
92
|
+
|
|
93
|
+
It is not that the refactoring direction was wrong; it is that **the way the refactoring was verified was wrong**:
|
|
94
|
+
|
|
95
|
+
1. **Structural changes legitimately change implicit premises.** Pushing state from agent level down to per-worker
|
|
96
|
+
workspaces is an architectural upgrade; but at the same time it turns the **implicit assumption** spread across
|
|
97
|
+
the whole repo — "reading `currentSessionId` gives you this request's session" — into something false.
|
|
98
|
+
2. **There is no "writer-reader matrix".** So every unaudited read site becomes a time bomb — rather than failing
|
|
99
|
+
to compile like a syntax error, they **silently return a default value** (an empty session), showing up
|
|
100
|
+
eventually as "the agent has amnesia".
|
|
101
|
+
3. **Concurrency being on by default amplifies the hit probability.** With a single worker, "the shared pointer" and
|
|
102
|
+
"the request's session" happen to be equivalent, so the problem is masked; once 3 workers are the default, any
|
|
103
|
+
shared pointer may belong to a different session.
|
|
104
|
+
4. **Conclusion**: the risk of a refactor lies not in what it does, but in **the dependency inventory it failed to
|
|
105
|
+
update at the same time**. No inventory exists → you can only hit the problems by stepping on them in production.
|
|
106
|
+
|
|
107
|
+
> To judge whether a refactor is safe, don't look at "are the tests all green", look at "can you articulate where
|
|
108
|
+
> the semantics changed".
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 4. Countermeasures (ordered by leverage, all actionable)
|
|
113
|
+
|
|
114
|
+
### C1 Write down and enforce the "state ownership contract" (1 day, immediately)
|
|
115
|
+
- Add the **writer-reader matrix** that accompanies this document: each row = a state × who writes × who reads ×
|
|
116
|
+
which thread/workspace × whether implicit reads are allowed.
|
|
117
|
+
- Code-level enforcement: per-worker state must not be read implicitly across threads. Remove from the signatures
|
|
118
|
+
any entry point where "the HTTP thread decides the turn's session" — **pass values explicitly, don't rely on
|
|
119
|
+
shared pointers**.
|
|
120
|
+
- The template already landed in this round: `sendMessageStream` explicitly carries the request session id;
|
|
121
|
+
`handleMessageStream` resolves by "DB-id-bound in-memory session > workspace pointer > create new", and
|
|
122
|
+
"has a DB id but no binding" must warn.
|
|
123
|
+
|
|
124
|
+
### C2 Eliminate silent degradation (this week, best value for effort)
|
|
125
|
+
Rule: any "not found → return empty / create new / swallow the exception" must distinguish three states —
|
|
126
|
+
`found | missing | notLoaded` — and the latter two must `log.warn` + emit metrics.
|
|
127
|
+
- Already landed in this round: `getRecentMessages` **lazily loads a non-resident session from disk by id first**,
|
|
128
|
+
and warns on an unknown/empty id; a failed session-history load is no longer disguised as a "new session"
|
|
129
|
+
(`null` = explicitly a new conversation, `undefined` = unknown identity → keep the original session).
|
|
130
|
+
- **✅ landed:** `scripts/architecture-guard.mjs` enforces `no-console` / `no-empty-catch` on server packages (`packages/core`, `packages/org-manager`) as a CI gate.
|
|
131
|
+
|
|
132
|
+
### C3 Single source of truth / eliminate split-brain (this week)
|
|
133
|
+
- The one external identity = the DB session (`cs_*`); the in-memory session (`sess_*`) is an internal cache, and
|
|
134
|
+
the binding **may only be written in one place** (this round already changed it to write the binding in "the
|
|
135
|
+
workspace that actually handles the message").
|
|
136
|
+
- Run a cheap consistency self-check at startup / each round: bindings consistent in both directions, no orphaned
|
|
137
|
+
in-memory sessions, disk session count reconciled.
|
|
138
|
+
|
|
139
|
+
### C4 Converge multiple paths (2 weeks)
|
|
140
|
+
- **✅ landed (identity resolution):** both paths now resolve session identity through the single point `resolveTurnSession()` (called from `processMailboxItemCore`); convergence onto one message-processing kernel remains the target.
|
|
141
|
+
- Delete the coexisting legacy/hook dual implementation (this round already removed 1232 lines of dead code).
|
|
142
|
+
|
|
143
|
+
### C5 "Session invariants" test suite (**highest leverage**, kicked off in this round)
|
|
144
|
+
This round added `packages/core/test/conversation-session-invariants.test.ts` (6 invariants), and proved it
|
|
145
|
+
effective with **mutation validation**: revert the fix → 6/6 go red. The properties it guards:
|
|
146
|
+
1. the second message in the same session (even if handled by another worker) must see the history of the first;
|
|
147
|
+
2. a DB id is never used as an in-memory session key (no split-brain);
|
|
148
|
+
3. a non-resident session must be lazily loadable from disk (history is not lost after restart/eviction);
|
|
149
|
+
4. an unknown/empty id must warn, and must not silently return empty history;
|
|
150
|
+
5. sessions do not cross wires under concurrency;
|
|
151
|
+
6. behaviour must be observable when the binding is missing (warn), and must not be disguised as an "empty conversation".
|
|
152
|
+
|
|
153
|
+
**Extension direction**: any session/concurrency-related change must first add an invariant, then change the code.
|
|
154
|
+
|
|
155
|
+
### C6 Real end-to-end smoke gate (this week)
|
|
156
|
+
Spin up a real server + real SSE + two consecutive messages in the same session (3 workers), finish in under
|
|
157
|
+
10 seconds, must pass in CI.
|
|
158
|
+
Rationale: however complete the unit tests are, they cannot cover cross-thread semantics like "the HTTP thread
|
|
159
|
+
writes, the worker reads".
|
|
160
|
+
|
|
161
|
+
### C7 Structural changes must ship with a "writer-reader matrix" + canary rollout
|
|
162
|
+
Changing state scope = you must first produce the matrix and reconcile it cell by cell; "changing scope on the
|
|
163
|
+
side" is forbidden.
|
|
164
|
+
The focus of review for such changes is not code style, but **whether the matrix has blank cells**.
|
|
165
|
+
|
|
166
|
+
### C8 Delivery hygiene (this week)
|
|
167
|
+
- Must pass in CI: lint (no-console / no-empty-catch / no-unused) + `pnpm quality` + dead-code detection.
|
|
168
|
+
- Check for duplicate fixes before merging: the same problem appearing in multiple equivalent commits (today we
|
|
169
|
+
found that `2bbdc7d7` and `4454b4f3` were duplicate deliveries).
|
|
170
|
+
- Test environment isolation: we found today that when `OPENAI_API_KEY` is present on the machine, tests really hit
|
|
171
|
+
the embedding API and hang for ~10s per run — CI noise masks real failures, so isolation is mandatory.
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 5. Three things to do right now (suggested order)
|
|
176
|
+
|
|
177
|
+
1. **Complete C5+C6**: extend the invariant suite to "restart recovery / attachments / a2a / group_chat", and get
|
|
178
|
+
the smoke case into CI. This is the foundation for **never again depending on manual feedback**.
|
|
179
|
+
2. **C2 silent-degradation cleanup + lint gates**: turn "invisible failures" into visible warnings and metrics.
|
|
180
|
+
3. **C1 state ownership doc + explicit sessionId**: eliminate implicit dependencies at the signature level.
|
|
181
|
+
|
|
182
|
+
> This round's fix already incidentally completed the core channel of C1, the two key points of C2, the first
|
|
183
|
+
> version of C5, and the debug-residue cleanup in delivery hygiene. What remains is not "fix one more bug", but
|
|
184
|
+
> turning these three classes of constraint into something **machine-enforceable**.
|