bailinghub 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.en.md +6 -6
  2. package/README.md +6 -6
  3. package/docker-compose.images.yml +2 -2
  4. package/docs/CHANGELOG.en.md +23 -1
  5. package/docs/CHANGELOG.md +23 -1
  6. package/docs/CORE_RELIABILITY.en.md +79 -0
  7. package/docs/CORE_RELIABILITY.md +79 -0
  8. package/docs/DEPLOYMENT_DIAGNOSTICS.en.md +78 -0
  9. package/docs/DEPLOYMENT_DIAGNOSTICS.md +78 -0
  10. package/docs/IMPLEMENTATION_STATUS.en.md +27 -15
  11. package/docs/IMPLEMENTATION_STATUS.md +27 -15
  12. package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
  13. package/docs/INDEPENDENT_VALIDATION.md +4 -4
  14. package/docs/KERNEL_HOST_API.en.md +2 -0
  15. package/docs/KERNEL_HOST_API.md +2 -0
  16. package/docs/MODEL_BILLING.en.md +4 -0
  17. package/docs/MODEL_BILLING.md +4 -0
  18. package/docs/MODEL_PROCESS_RECOVERY.en.md +32 -0
  19. package/docs/MODEL_PROCESS_RECOVERY.md +37 -0
  20. package/docs/OPERATIONS.en.md +13 -0
  21. package/docs/OPERATIONS.md +12 -0
  22. package/docs/README.en.md +7 -0
  23. package/docs/README.md +7 -0
  24. package/docs/RELEASE_NOTES_v0.9.2.en.md +45 -0
  25. package/docs/RELEASE_NOTES_v0.9.2.md +45 -0
  26. package/docs/RELEASE_NOTES_v0.9.3.en.md +51 -0
  27. package/docs/RELEASE_NOTES_v0.9.3.md +51 -0
  28. package/docs/TOOLS_DESIGN.md +1 -0
  29. package/docs/UPGRADE_v0.9.2.en.md +62 -0
  30. package/docs/UPGRADE_v0.9.2.md +62 -0
  31. package/docs/UPGRADE_v0.9.3.en.md +63 -0
  32. package/docs/UPGRADE_v0.9.3.md +63 -0
  33. package/package.json +7 -3
  34. package/scripts/check-doc-links.mjs +4 -0
  35. package/scripts/check-image-tags.sh +1 -1
  36. package/scripts/check-release-consistency.test.mjs +2 -2
  37. package/scripts/doctor-deployment.test.ts +419 -0
  38. package/scripts/doctor-deployment.ts +357 -0
  39. package/scripts/doctor.ts +8 -1
  40. package/scripts/install-secrets.test.mjs +185 -0
  41. package/scripts/install.sh +10 -6
  42. package/scripts/publish-images.sh +1 -1
  43. package/scripts/release-audit.mjs +8 -0
  44. package/scripts/verify-github-repo.mjs +8 -0
  45. package/security/dependency-audit-exceptions.json +1 -1
  46. package/sql/065_usage_reconciliation_scan.sql +4 -0
  47. package/sql/066_approval_continuations.sql +15 -0
  48. package/sql/067_delivery_dlq_replay.sql +10 -0
  49. package/sql/README.en.md +6 -0
  50. package/sql/README.md +15 -0
  51. package/src/adapters/llm/file.test.ts +59 -0
  52. package/src/adapters/llm/file.ts +11 -4
  53. package/src/app/agent-tool-invocations.test.ts +3 -1
  54. package/src/app/approval-continuations.mysql.test.ts +138 -0
  55. package/src/app/approval-continuations.test.ts +351 -0
  56. package/src/app/approval-continuations.ts +148 -0
  57. package/src/app/channels-attachments.test.ts +63 -0
  58. package/src/app/channels.ts +7 -4
  59. package/src/app/delivery-dlq-replay.mysql.test.ts +139 -0
  60. package/src/app/delivery-dlq-replay.test.ts +75 -0
  61. package/src/app/delivery-dlq-replay.ts +41 -0
  62. package/src/app/delivery.ts +3 -2
  63. package/src/app/http-server.ts +3 -0
  64. package/src/app/kernel-model-process-crash.mysql.test.ts +377 -0
  65. package/src/app/kernel-notification-lifecycle.test.ts +49 -0
  66. package/src/app/kernel.ts +22 -0
  67. package/src/app/notification-outbound.test.ts +53 -0
  68. package/src/app/operational-metrics.test.ts +37 -1
  69. package/src/app/operational-metrics.ts +25 -2
  70. package/src/app/outbound.ts +13 -2
  71. package/src/app/runtime-evidence-maintenance.test.ts +55 -0
  72. package/src/app/runtime-lifecycle-default.ts +7 -0
  73. package/src/app/runtime-lifecycle.test.ts +89 -0
  74. package/src/app/runtime-lifecycle.ts +52 -11
  75. package/src/app/tool-approvals.ts +2 -1
  76. package/src/core/contracts/approval-continuation.ts +43 -0
  77. package/src/core/contracts/delivery-replay.ts +41 -0
  78. package/src/core/contracts/tools-idempotency.test.ts +121 -5
  79. package/src/core/contracts/tools.ts +21 -11
  80. package/src/core/contracts/types.ts +4 -0
  81. package/src/core/observability/openmetrics.test.ts +28 -0
  82. package/src/core/observability/openmetrics.ts +91 -0
  83. package/src/core/platform/http-body.test.ts +185 -0
  84. package/src/core/platform/http-body.ts +58 -0
  85. package/src/core/runtime/finish-runtime.test.ts +2 -0
  86. package/src/core/runtime/finish-runtime.ts +10 -7
  87. package/src/core/runtime/notification-background-work.test.ts +50 -0
  88. package/src/core/runtime/notification-background-work.ts +101 -0
  89. package/src/core/state/approval-continuation.ts +22 -0
  90. package/src/core/state/delivery-replay.ts +19 -0
  91. package/src/core/state/state-codec.ts +2 -0
  92. package/src/core/state/state-contracts.ts +6 -0
  93. package/src/infrastructure/config/config-approval-ledger.ts +75 -0
  94. package/src/infrastructure/config/config-delivery-dlq-ledger.ts +36 -10
  95. package/src/infrastructure/config/configstore.ts +4 -3
  96. package/src/infrastructure/state/state-jsonl.ts +56 -11
  97. package/src/infrastructure/state/state-mysql.ts +54 -0
  98. package/src/modules/usage/background-work.test.ts +28 -0
  99. package/src/modules/usage/background-work.ts +43 -7
  100. package/src/modules/usage/billing-reconciliation.mysql.test.ts +163 -0
  101. package/src/modules/usage/billing-reconciliation.test.ts +85 -0
  102. package/src/modules/usage/billing-repository.ts +63 -11
  103. package/src/modules/usage/maintenance.test.ts +78 -0
  104. package/src/modules/usage/maintenance.ts +39 -0
  105. package/src/modules/usage/model-gateway.ts +2 -1
  106. package/src/routes/admin-default.ts +2 -2
  107. package/src/routes/admin-runtime-default.ts +2 -2
  108. package/src/routes/admin-runtime.test.ts +1 -1
  109. package/src/routes/admin-runtime.ts +39 -18
  110. package/src/routes/admin.ts +1 -1
  111. package/src/routes/approvals-default.ts +2 -2
  112. package/src/routes/approvals.ts +30 -33
  113. package/src/routes/critical-routes.test.ts +16 -3
  114. package/src/test-support/approval-continuation-crash-child.ts +24 -0
  115. package/src/test-support/model-process-crash-child.ts +78 -0
package/README.en.md CHANGED
@@ -29,13 +29,13 @@ You choose which business APIs become available. BailingHub connects the convers
29
29
  <img src="assets/readme-product-overview.en.svg" width="100%" alt="BailingHub connects conversational entry points to governed business capabilities while the business system remains the authority">
30
30
  </picture>
31
31
 
32
- ## v0.9.1: asynchronous shutdown and public capability evidence
32
+ ## v0.9.3: bounded bodies and reliable notification shutdown
33
33
 
34
- Core shutdown now waits within its original deadline for model completion, settlement, and related usage background work. Usage-drain timeouts retain the original instance for retry without redispatch. This patch also provides a public capability/evidence index and general security-governance updates.
34
+ Tool responses and remote attachments are bounded during reading. Oversized write responses retain the original unknown outcome without redispatch. Graceful close drains actual callbacks, notifications and DLQ writes. Executor dead letters replay only the original notification child, with permanent markers deduplicating admission for the same DLQ. New read-only metrics expose background maintenance.
35
35
 
36
- Release pairing: **Core 0.9.1 + MCP / Agent Client SDK 0.7.0 + DSH 0.7.0**. Independent client packages are not bumped for this patch. Shared USD allowances, the uniform multiplier, periodic price/allowance, and business authority remain unchanged, with no new APIs, SQL, or plan rules. Verify versions, Tags, and artifact digests when upgrading.
36
+ The component set is **Core 0.9.3 + MCP / Agent Client SDK 0.7.0 + DSH 0.7.0**. Explicitly apply **067** before new MySQL DLQ reads/writes; earlier upgrades also apply missing preceding migrations. Shared USD allowance, the unified multiplier and client orchestration remain unchanged. Notification drain covers graceful shutdown, without a full durable notification outbox. A release does not establish a deployment has upgraded.
37
37
 
38
- [Release notes](docs/RELEASE_NOTES_v0.9.1.en.md) · [Upgrade guide](docs/UPGRADE_v0.9.1.en.md) · [Model billing](docs/MODEL_BILLING.en.md) · [Previous release](docs/RELEASE_NOTES_v0.9.0.en.md)
38
+ [Release notes](docs/RELEASE_NOTES_v0.9.3.en.md) · [Upgrade guide](docs/UPGRADE_v0.9.3.en.md) · [Reliability and migrations](docs/CORE_RELIABILITY.en.md) · [Previous release](docs/RELEASE_NOTES_v0.9.2.en.md)
39
39
 
40
40
  ## Operate the System by Conversation
41
41
 
@@ -125,7 +125,7 @@ To explore before installing, use the [online experience](https://trial.bailingh
125
125
  To run the complete disposable loop locally:
126
126
 
127
127
  ```bash
128
- git clone --branch v0.9.1 --depth 1 https://github.com/bailinghub/bailinghub.git
128
+ git clone --branch v0.9.3 --depth 1 https://github.com/bailinghub/bailinghub.git
129
129
  cd bailinghub
130
130
  export BAILING_TOKEN="${BAILING_TOKEN:-$(openssl rand -hex 32)}"
131
131
  docker compose up --build
@@ -214,7 +214,7 @@ Run separate BailingHub deployments for mutually isolated organizations. A `clie
214
214
  - [HTTP Contract](docs/CONTRACT.en.md) — stable network and identity boundaries.
215
215
  - [Architecture](docs/ARCHITECTURE.en.md) — runtime layers and dependency direction.
216
216
  - [English Documentation Map](docs/README.en.md) — the complete public documentation index.
217
- - [Changelog](docs/CHANGELOG.en.md) and [v0.9.1](docs/RELEASE_NOTES_v0.9.1.en.md) — current release changes and upgrade notes.
217
+ - [Changelog](docs/CHANGELOG.en.md) and [v0.9.3](docs/RELEASE_NOTES_v0.9.3.en.md) — current release changes and upgrade notes.
218
218
 
219
219
  ## Feedback and Ecosystem
220
220
 
package/README.md CHANGED
@@ -27,13 +27,13 @@
27
27
 
28
28
  在线体验环境只用于了解产品和配置方式。请勿上传生产凭据、敏感数据或接入真实业务;正式使用请自行部署开源版。
29
29
 
30
- ## v0.9.1:异步工作关闭与公开能力证据
30
+ ## v0.9.3:有限收包与通知可靠收尾
31
31
 
32
- 关闭 Core 时,在原时限内等待模型完成、结算及相关 usage 后台工作;usage 排空超时保留原实例供重试,不重派原请求。本版同时提供公开能力与证据索引,纳入通用安全治理。
32
+ HTTP 工具正文与远程附件在收包时执行限额,超限写操作保留原调用的未知结果,不自动重发。正常关闭等待回调、通知和死信记录的实际收尾;执行器死信只重投原通知子任务,并以持久标记防止同一死信重复入队。新增只读后台维护指标。
33
33
 
34
- 配套为 **Core 0.9.1 + MCP / Agent Client SDK 0.7.0 + DSH 0.7.0**,独立客户端包不因本补丁升版。已有共享 USD 额度、统一倍率、周期售价/额度与业务权限保持;没有新增 API、SQL 或套餐规则。升级时核对版本、Tag 与制品摘要。
34
+ 配套为 **Core 0.9.3 + MCP / Agent Client SDK 0.7.0 + DSH 0.7.0**。升级须显式应用 **067**,更早版本补齐前序迁移;新 MySQL DLQ 读写须先就绪。共享 USD 额度、统一倍率与客户端编排保持。通知排空覆盖正常关闭,未提供全量持久通知 outbox;发行不代表具体环境已升级。
35
35
 
36
- [版本说明](docs/RELEASE_NOTES_v0.9.1.md) · [升级指南](docs/UPGRADE_v0.9.1.md) · [模型计费](docs/MODEL_BILLING.md) · [上一版本](docs/RELEASE_NOTES_v0.9.0.md)
36
+ [版本说明](docs/RELEASE_NOTES_v0.9.3.md) · [升级指南](docs/UPGRADE_v0.9.3.md) · [可靠性与迁移](docs/CORE_RELIABILITY.md) · [上一版本](docs/RELEASE_NOTES_v0.9.2.md)
37
37
 
38
38
  ## 适合哪些团队
39
39
 
@@ -115,7 +115,7 @@
115
115
  在本机启动中枢、MySQL、Demo 业务系统、工具源、路由和接入方:
116
116
 
117
117
  ```bash
118
- git clone --branch v0.9.1 --depth 1 https://github.com/bailinghub/bailinghub.git
118
+ git clone --branch v0.9.3 --depth 1 https://github.com/bailinghub/bailinghub.git
119
119
  cd bailinghub
120
120
  export BAILING_TOKEN="${BAILING_TOKEN:-$(openssl rand -hex 32)}"
121
121
  docker compose up --build
@@ -199,7 +199,7 @@ BailingHub Core 是独立服务,只通过稳定网络契约与业务系统协
199
199
  | 集中开启本地智能体与工具 | [四步配置指南](docs/LOCAL_AGENT_SETUP.md) · [系统说明](docs/AGENT_SYSTEM_INFO.md) |
200
200
  | 查 API 与边界契约 | [HTTP 契约](docs/CONTRACT.md) · [Client API](docs/CLIENT_API.md) |
201
201
  | 理解架构与长期取舍 | [架构](docs/ARCHITECTURE.md) · [项目愿景](VISION.md) |
202
- | 查看版本变化 | [CHANGELOG](docs/CHANGELOG.md) · [v0.9.1](docs/RELEASE_NOTES_v0.9.1.md) |
202
+ | 查看版本变化 | [CHANGELOG](docs/CHANGELOG.md) · [v0.9.3](docs/RELEASE_NOTES_v0.9.3.md) |
203
203
 
204
204
  完整中英文文档地图见 [docs/README.md](docs/README.md)。公共 API、SDK、Schema、Docker Demo 与代码标识保持语言中立。
205
205
 
@@ -18,7 +18,7 @@ services:
18
18
  retries: 30
19
19
 
20
20
  demo-business:
21
- image: ${BAILING_DEMO_BUSINESS_IMAGE:-crpi-xm97pbcjrmf5in3s.cn-shanghai.personal.cr.aliyuncs.com/bailinghub/bailing-demo-business:0.9.1}
21
+ image: ${BAILING_DEMO_BUSINESS_IMAGE:-crpi-xm97pbcjrmf5in3s.cn-shanghai.personal.cr.aliyuncs.com/bailinghub/bailing-demo-business:0.9.3}
22
22
  environment:
23
23
  DEMO_HOST: 0.0.0.0
24
24
  DEMO_PORT: 19080
@@ -29,7 +29,7 @@ services:
29
29
  - "${BAILING_DEMO_PUBLIC_PORT:-19080}:19080"
30
30
 
31
31
  bailinghub:
32
- image: ${BAILINGHUB_IMAGE:-crpi-xm97pbcjrmf5in3s.cn-shanghai.personal.cr.aliyuncs.com/bailinghub/bailinghub:0.9.1}
32
+ image: ${BAILINGHUB_IMAGE:-crpi-xm97pbcjrmf5in3s.cn-shanghai.personal.cr.aliyuncs.com/bailinghub/bailinghub:0.9.3}
33
33
  depends_on:
34
34
  mysql:
35
35
  condition: service_healthy
@@ -12,7 +12,7 @@ For the current integration contract, use:
12
12
 
13
13
  ## Recording Rules
14
14
 
15
- Lead each release with a familiar business-assistant or enterprise-service scenario: the previous problem, changed behavior, affected users and developers, upgrade steps, observable checks and limits. Keep English and Chinese facts aligned and distinguish additions, fixes and existing features. See [the release scenario notes](RELEASE_NOTES_v0.9.1.en.md).
15
+ Lead each release with a familiar business-assistant or enterprise-service scenario: the previous problem, changed behavior, affected users and developers, upgrade steps, observable checks and limits. Keep English and Chinese facts aligned and distinguish additions, fixes and existing features. See [the release scenario notes](RELEASE_NOTES_v0.9.3.en.md).
16
16
 
17
17
  Each public version should describe:
18
18
 
@@ -22,6 +22,28 @@ Each public version should describe:
22
22
  - validation commands;
23
23
  - related docs.
24
24
 
25
+ ## v0.9.3 - Bounded bodies and reliable notification shutdown
26
+
27
+ Version date: 2026-10-14. A patch from Core 0.9.2; MCP / Agent Client SDK 0.7.0 and DSH 0.7.0 remain unchanged. See [release notes](RELEASE_NOTES_v0.9.3.en.md) and the [upgrade guide](UPGRADE_v0.9.3.en.md).
28
+
29
+ - Fix full buffering before body/attachment checks: tool bodies default to 5 MiB, files retain configured limits and channel attachments use 20 MiB, counting actual fetch-decoded bytes while reading. Model/audit views use UTF-8 byte budgets. Overflow discards partial bodies; dispatched writes retain original identity, idempotency and unknown outcome without redispatch.
30
+ - Fix graceful close omitting notification work: per-Kernel tracking covers actual callbacks, delivery creation, approval webhooks, alerts and DLQ writes, sharing the close budget with dynamic children and started maintenance producers. Timeouts preserve resources for same-instance retry. No durable outbox for all notification intents is added.
31
+ - Fix executor DLQs selecting native senders: verify original bindings and requeue only the original notification child, retaining full input and request/job identity. Atomic admission/markers deduplicate concurrent calls, lost acknowledgements and failed resolve/store reopening for the same DLQ. queued does not mean receipt; the business parent is never rerun.
32
+ - Add read-only, fixed-label background snapshots for in-flight/failures/recent runs, drain timeouts, latest settlement/approval pages and backoff. Read no business details, start no model request and do not claim persisted backlog counts.
33
+ - Add 067 DLQ kind/original-child/replay identity and Job admission markers. Explicitly migrate before new Core MySQL DLQ reads/writes and match adapters. Rollback retains queues/markers/history and separately verifies old schema-manifest compatibility in isolation. Dependency versions and the exact Mammoth exception expiry are unchanged.
34
+ - Add public synthetic and dedicated MySQL regressions for bodies, Unicode, close, old-data upgrade, concurrency and exceptions after real COMMIT. Notification tests cover storage interruption, not full SIGKILL recovery or production receipt. ACC, independent Hosts, clients and separate adapters do not release with this Core patch.
35
+
36
+ ## v0.9.2 - Secure installation and persisted continuation
37
+
38
+ Version date: 2026-10-13. A patch from Core 0.9.1; MCP / Agent Client SDK 0.7.0 and DSH 0.7.0 remain unchanged. See [release notes](RELEASE_NOTES_v0.9.2.en.md) and the [upgrade guide](UPGRADE_v0.9.2.en.md).
39
+
40
+ - Fix installation secrets: generate six credentials independently from secure randomness; failed or invalid output stops installation without weak credentials or a partial `.env`. Preserve existing configuration.
41
+ - Fix settlement depending on traffic and a blocking fixed first page: startup/existing tick and minute-based maintenance advance cursor pages of up to 50 records with wraparound, per-row failure isolation and database backoff. Use original metering, prices and multiplier; do not redispatch, read result bodies or invent charges.
42
+ - Fix continuation after a saved approval encounters audit or queue failure: atomically persist the decision and continuation, then recover the original job through original-ID retry and background maintenance. Atomically save queue admission and a decision marker, deduplicate lost acknowledgements and process reopening, and recheck consumed state inside admission. Denials only complete auditing; direct Agent calls retain explicit resume; historical decisions without continuations are not backfilled.
43
+ - Add read-only `doctor --deployment` for specified Core public health/version and optional readiness, with explicit declaration identity, unchecked scope and exit codes. Perform no upgrade, rollback or migration.
44
+ - First ship actual model-child SIGKILL and lost MySQL COMMIT-acknowledgement regressions, plus installation, paging, approval concurrency/process recovery and maintenance-close coverage. Added tests do not add model redispatch behavior or establish production acceptance.
45
+ - Add 065's settlement index and 066's continuation table/job markers. Apply explicit migrations and match custom state/config adapters; new maintenance participates in close draining. Rollback retains continuation records and markers. Queue deduplication does not guarantee exactly-once external effects. ACC, independent Hosts and clients release separately and are outside this Core update.
46
+
25
47
  ## v0.9.1 - Asynchronous model shutdown and public capability evidence
26
48
 
27
49
  Version date: 2026-10-12. Core patch release; MCP / Agent Client SDK 0.7.0 and DSH 0.7.0 remain unchanged. See [release notes](RELEASE_NOTES_v0.9.1.en.md) and the [upgrade guide](UPGRADE_v0.9.1.en.md).
package/docs/CHANGELOG.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  ## 记录规则
7
7
 
8
- 每次先用业务助手、企业服务等通用场景说明原问题与本版行为,再按使用者、业务后端与客户端开发者交代升级影响。中英文使用同一事实,新增能力、修复和已有能力分别标明;参考[本版场景说明](RELEASE_NOTES_v0.9.1.md)。
8
+ 每次先用业务助手、企业服务等通用场景说明原问题与本版行为,再按使用者、业务后端与客户端开发者交代升级影响。中英文使用同一事实,新增能力、修复和已有能力分别标明;参考[本版场景说明](RELEASE_NOTES_v0.9.3.md)。
9
9
 
10
10
  每个公开版本至少说明:
11
11
 
@@ -15,6 +15,28 @@
15
15
  - **验证方式**:部署方如何确认该版本运行正常;
16
16
  - **相关文档**:对应的契约、指南或示例。
17
17
 
18
+ ## v0.9.3 - 有限收包与通知可靠收尾
19
+
20
+ 版本日期:2026-10-14。相对 Core 0.9.2 的补丁;MCP / Agent Client SDK 0.7.0、DSH 0.7.0 不变。[版本说明](RELEASE_NOTES_v0.9.3.md)、[升级指南](UPGRADE_v0.9.3.md)。
21
+
22
+ - 修复 HTTP/附件先完整缓冲再检查限额:工具正文默认 5 MiB,文件沿配置限额、渠道附件 20 MiB,逐块累计 fetch 解码后的实际字节;模型/审计视图按 UTF-8 字节截断。超限丢弃部分正文,已外发写操作保留原 ID、幂等和未知结果,不自动重投。
23
+ - 修复正常关闭遗漏通知工作:每个 Kernel 登记真实回调、通知派生、审批 webhook、告警和 DLQ 写入;共同关闭预算等待动态子工作及已开始维护生产者,超时保留资源供同实例重试。未提供覆盖全部通知意图的持久 outbox。
24
+ - 修复执行器死信错误走原生渠道:核原绑定,只重排原通知子任务,保留完整输入及 request/job;同一 DLQ 入队与标记原子保存,并发、确认丢失、resolve 失败/仓储重开不二次入队。queued 不等于收件方收到,业务父任务不重跑。
25
+ - 增加只读、固定标签的后台维护快照:在途/失败/最近运行、关闭超时、结算/审批最近一页和退避;不读业务明细,不触发模型请求,不冒充持久积压量。
26
+ - 新增 067 的 DLQ 类型/原通知/重投标识与 Job 入队标记;新 Core MySQL DLQ 读写前显式迁移并配套仓储。回退保留队列/标记/账本,旧制品 schema manifest 兼容性须在隔离副本另验。依赖版本和精确 Mammoth 例外期限不变。
27
+ - 公开合成回归及专用 MySQL 专项新增收包、Unicode、关闭、旧数据升级、并发和真实 COMMIT 后的异常检查;通知专项是仓储断点测试,不是 SIGKILL 全通知恢复或生产送达验收。ACC、独立 Host、客户端和其他独立适配层不随本版发行。
28
+
29
+ ## v0.9.2 - 安全安装与原记录补续
30
+
31
+ 版本日期:2026-10-13。相对 Core 0.9.1 的补丁;MCP / Agent Client SDK 0.7.0、DSH 0.7.0 不变。[版本说明](RELEASE_NOTES_v0.9.2.md)、[升级指南](UPGRADE_v0.9.2.md)。
32
+
33
+ - 修复安装凭据生成:六项凭据独立使用安全随机源,失败或输出不合法时停止,不产生弱凭据或半份 `.env`;已有配置保留。
34
+ - 修复异步结算只靠流量触发与固定首批阻塞:启动/既有 tick 和每分钟维护自动推进,最多 50 条游标分页并回绕,单条异常隔离,数据库故障退避;只使用原计量、价格与统一倍率,不重派、不读结果正文、不猜费用。
35
+ - 修复审批决策保存后审计或入队失败无法补续:事务保存决策与补续,原 ID 重试和后台维护继续原任务;原入队与决策标记原子保存,确认丢失和进程重开不重复入队,入队临界区重验已消费状态。拒绝仅补审计,Agent 直调仍显式 resume,历史无补续决策不回填。
36
+ - 新增只读 `doctor --deployment` 模式,核对指定 Core 的公开健康/版本,按需读取 readiness;明确身份声明、未检查范围和退出码,不执行升级、回滚或迁移。
37
+ - 首次发行实际模型子进程 SIGKILL 和 MySQL COMMIT 确认丢失专项,新增安装、分页、审批并发/进程恢复及维护关闭回归;测试覆盖新增不代表新增模型重派能力或生产验收。
38
+ - 新增 065 待结算索引和 066 补续表/任务标记,必须显式迁移并配套自定义 state/config 仓储;新维护纳入关闭排空。回退保留补续记录与标记,队列去重不等于外部业务恰好一次。ACC、独立 Host 与客户端各自发布,不包含在本次 Core 更新中。
39
+
18
40
  ## v0.9.1 - 异步模型工作关闭与公开能力证据
19
41
 
20
42
  版本日期:2026-10-12。Core 补丁版本,MCP / Agent Client SDK 0.7.0、DSH 0.7.0 不变。[版本说明](RELEASE_NOTES_v0.9.1.md)、[升级指南](UPGRADE_v0.9.1.md)。
@@ -0,0 +1,79 @@
1
+ # Core reliability: secrets, continuation, bounded bodies and notifications
2
+
3
+ [简体中文](CORE_RELIABILITY.md)
4
+
5
+ Installation, settlement and approval fixes are available from Core 0.9.2; the final HTTP/notification section is available from Core 0.9.3. Historical artifacts do not contain later fixes. Verify each deployment's source, artifact and migration ledger separately; updated documentation does not establish an upgrade.
6
+
7
+ ## Installation secrets
8
+
9
+ When creating `.env`, the installer calls `openssl rand -base64 24` independently for six credentials. Each producer must exit successfully and return exactly 32 valid Base64 characters. Missing secure randomness, execution failure or invalid output stops installation before a partial `.env` is written or services start. Timestamps and digests are not substitutes for randomness.
10
+
11
+ An existing `.env` is preserved, including an operator's changed administrator password. Failed producers' output is not echoed. Install a working OpenSSL implementation before retrying.
12
+
13
+ Run `npm run installer:secrets:test` to check generation, failed producers, malformed output, late failures and configuration preservation. Tests use synthetic commands and temporary directories, without installing a real service.
14
+
15
+ ## Automatic asynchronous settlement
16
+
17
+ standalone schedules an initial maintenance pass after startup and subsequent passes every minute. A new managed Kernel schedules its first pass on its existing `tick`, with subsequent passes driven by the same tick. Its Host must still call tick; no per-Kernel timers are introduced. HTTP uses the same maintenance port as a fallback, so saved usage recovery no longer depends on incoming traffic.
18
+
19
+ Maintenance reads saved metering, reference prices and the original unified multiplier. It does not read generated result bodies, contact providers or dispatch another model request. Pages contain at most 50 records, advance by `(updated_at, id)` and wrap at the end. Unpriceable or individually corrupt rows do not keep later records behind a fixed first page. Missing authoritative metering remains pending/unknown, rather than becoming an invented zero charge.
20
+
21
+ One usage owner shares an active maintenance pass; different owners remain independent. Database failures back off from one minute to a maximum of five minutes, resetting after success. `getReconciliationProgress()` exposes only the latest page's scanned, settled, deferred, failed and hasMore values. It is not a database-wide pending count and contains no result bodies, identifiers or credentials.
22
+
23
+ Maintenance participates in the existing background-work registry and Kernel close drain. standalone stops new maintenance before draining started evidence writes. A timeout retains unfinished work on the same instance for retry; it is not permission to close its stores.
24
+
25
+ ## Approval decisions and continuation
26
+
27
+ External callbacks and the console save the decision and immutable continuation coordinates in one transaction. They bind the original approval, job, request, argument hash and decision identifier. Retrying the original `decision_id` can complete failed auditing or queue admission; background maintenance pages through unfinished continuations by approval identifier and wraps at the end, so in-flight or faulty records do not block later approvals. A saved decision whose continuation fails returns `503` with `decision_recorded=true / continuation_pending=true`. Do not create another approval to recover it.
28
+
29
+ The state adapter atomically writes original-job queue admission and a separate decision marker, rechecking whether the approval was consumed inside the admission critical section. If the queue write succeeds but its acknowledgement is lost, retries, process reopening and a completed new run cannot admit the job again for that decision. Ordinary job updates cannot remove the marker. An original job still in flight waits for later maintenance. Execution retains existing pause, route and tool governance.
30
+
31
+ Denied decisions only complete auditing. Direct Agent invocations remain manual: approval does not launch a Core model loop, and the original local Agent still explicitly resumes the original `invocation_id`. Consumed approvals and historical decisions without new continuation records are not automatically backfilled or requeued.
32
+
33
+ Losing an acknowledgement after a successful audit append may produce another observation with the same `detail.continuation_id`. Queue admission deduplication does not guarantee exactly-once business effects across systems; business services retain their own idempotency and final authorization. JSONL serial writes support one writer, not multiple processes writing the same file.
34
+
35
+ ## Migrations and adapter boundaries
36
+
37
+ - `065_usage_reconciliation_scan.sql` adds the pending-settlement paging index, without recalculating historical charges.
38
+ - `066_approval_continuations.sql` adds the continuation table and `bz_jobs.approval_continuation_keys`, without changing old decisions or customer business data.
39
+
40
+ Use `npm run db:init` or the official explicit Kernel migration port. Runtime startup does not migrate automatically. Apply 066 before using new approval decision paths. A failed continuation insert rolls the decision back rather than leaving an orphaned decision. Coordinate old writers, retain backups and verify migration plus matching state/config adapters before enabling the new paths.
41
+
42
+ Custom adapters must implement the optional continuation ledger methods together with `RuntimeStateStore.requeueApprovedJobOnce`. New decisions are explicitly unavailable without them; there is no fallback to the old unrecoverable queue path. These are Core interfaces. Independent Host platform identities and tenant upgrade orchestration, and client model loops and long-term memory remain separate projects.
43
+
44
+ These migrations are additive. A code rollback must not delete continuation records or markers. Older code does not provide the guarantees on this page. Coordinate stopping decision and job writes, then reconcile saved decisions, queue state and markers; removing markers and resubmitting is not recovery.
45
+
46
+ ## Regression entry points and limits
47
+
48
+ Default `npm test` covers settlement paging, maintenance, approval continuation, state updates and close behavior. MySQL acceptance uses independent random schemas and synthetic providers:
49
+
50
+ ```bash
51
+ BAILING_USAGE_TEST_MYSQL=1 BAILING_APPROVAL_CONTINUATION_TEST_MYSQL=1 \
52
+ node --import tsx --test --test-concurrency=4 \
53
+ 'src/modules/usage/*.test.ts' src/app/kernel-usage-lifecycle.mysql.test.ts \
54
+ src/app/approval-continuations.mysql.test.ts
55
+ ```
56
+
57
+ Fixtures require a dedicated MySQL on local `127.0.0.1:16307`, an empty root password, and permission to create/drop test databases. Never point them at shared or production databases. Approval acceptance includes actual child-process SIGKILL, recovery in a different PID, lost COMMIT acknowledgements, concurrent continuation and missing-migration rollback. This establishes behavior in the fixtures, not real-provider availability, physical power-loss durability or production business acceptance. Skipped database tests do not count as passes.
58
+
59
+ See the [capability and public evidence index](IMPLEMENTATION_STATUS.en.md) for implementation and test links.
60
+
61
+ ## Core v0.9.3 HTTP and notification fixes
62
+
63
+ Tool HTTP bodies have a separate default transport budget of 5 MiB. Content-Length can reject early, while streaming checks count actual fetch-decoded bytes even when the length is absent or understated. Excess bodies are cancelled and partial contents discarded. HTTP 200 headers cannot establish a completed write: body loss/overflow retains the original unknown-outcome and idempotency path without automatic redispatch. Model and audit views have separate UTF-8 byte budgets. Remote files retain configured max_bytes (20 MiB by default); channel attachments have a 20 MiB download limit. These bound downloads, not decompression or parser resources. See [bounded body tests](../src/core/platform/http-body.test.ts), [tool recovery tests](../src/core/contracts/tools-idempotency.test.ts) and [file tests](../src/adapters/llm/file.test.ts).
64
+
65
+ Each Kernel tracks actual callback, delivery, approval webhook, alert and DLQ continuations, draining them before resource closure within the shared close budget. Accepted work can register children during drain. Stopped standalone timers also drain already-started maintenance producers, so a monitor waiting on SQL cannot register an alert after notification drain. Timeouts preserve resources for another close attempt on the same instance. See the [tracker](../src/core/runtime/notification-background-work.ts), [real Kernel close tests](../src/app/kernel-notification-lifecycle.test.ts), [scheduler tests](../src/app/runtime-lifecycle.test.ts) and [outbound tests](../src/app/notification-outbound.test.ts). This covers graceful close. A durable outbox for all notification intents is still absent; it does not promise complete HTTP notification recovery after SIGKILL.
66
+
67
+ [Migration 067](../sql/067_delivery_dlq_replay.sql) adds DLQ kind, original notification child and replay identity, plus an independent state-store queue marker. Native channels retain their sender. Executor DLQs requeue only the verified original notification child, retaining recipient, full input and request/job identities; they never rerun the business parent. queued acknowledges admission, not receipt. Concurrent calls and lost queue/resolve acknowledgements cannot re-admit the same DLQ identity. A later failed notification produces a new DLQ that an operator may separately handle. JSONL remains single-writer.
68
+
69
+ Apply 067 before new Core MySQL DLQ reads/writes, including native-channel record/get. Custom stores need the optional ensureExecutorReplay and requeueDeliveryJobOnce methods; without them, executor replay is explicitly unavailable rather than sent through the wrong channel. Before rollback, stop related writers and retain migration, queue and marker evidence. Deleting markers and resubmitting is not recovery. Older artifact schema manifests may reject 067 history; verify rollback compatibility in an isolated copy without deleting migration rows to bypass checks. Deployment and independent Host upgrades/rollbacks remain separate operational actions.
70
+
71
+ Default tests cover [original notification replay](../src/app/delivery-dlq-replay.test.ts). The MySQL fixture uses dedicated localhost MySQL and random schemas to check old-data upgrade, concurrent admission, injected acknowledgement exceptions after real COMMIT, resolve failure and store reopening, invalid business bindings and long Unicode content. It tests storage interruption boundaries, not real process killing or production receipt:
72
+
73
+ ```bash
74
+ BAILING_NOTIFICATION_TEST_MYSQL=1 BAILING_NOTIFICATION_TEST_MYSQL_PORT=16307 \
75
+ BAILING_NOTIFICATION_BASELINE_ROOT=/absolute/clean/core-v0.9.2 \
76
+ node --import tsx --test src/app/delivery-dlq-replay.mysql.test.ts
77
+ ```
78
+
79
+ [Fixed-label metrics](OPERATIONS.en.md) expose process-local pending work, failures, drain timeouts and the latest settlement/approval page. Scrapes read memory without starting model requests. Test links do not establish executed passing runs or deployed environments. Verify formal artifact identity and deployment acceptance separately.
@@ -0,0 +1,79 @@
1
+ # Core 可靠性:凭据、补续、收包与通知
2
+
3
+ [English](CORE_RELIABILITY.en.md)
4
+
5
+ 安装凭据、结算维护和审批补续从 Core 0.9.2 提供,末节的 HTTP/通知修复从 Core 0.9.3 提供。历史制品不包含后续版本的修改;具体部署需核对其源码、制品与迁移账本,不能从新版文档推导已经升级。
6
+
7
+ ## 安装凭据
8
+
9
+ 新建 `.env` 时,安装器为六项凭据分别调用 `openssl rand -base64 24`。每次输出必须是 32 个合法 Base64 字符,生产者必须成功退出。缺少安全随机源、执行失败或输出不合法时停止安装,不生成半份 `.env`,不启动服务。不以时间戳或摘要替代随机源。
10
+
11
+ 已有 `.env` 继续保留,重启和升级不因此覆盖运营者修改的管理员密码。生成失败时不回显生产者输出;运营者需安装可用的 OpenSSL 后重试。
12
+
13
+ 运行 `npm run installer:secrets:test` 可检查正常生成、故障退出、错误输出、后续凭据生成失败和已有配置保留。这些测试使用合成命令与临时目录,不安装真实服务。
14
+
15
+ ## 异步结算自动推进
16
+
17
+ standalone 启动后即安排一次维护,以后每分钟安排一次;managed Kernel 在新实例的首个既有 `tick` 上启动,以后由同一 tick 推进周期维护。managed 模式仍由 Host 调用 tick,不新建每个 Kernel 的独立定时器。HTTP 请求保留同一维护入口作为补充,恢复结算不依赖新流量。
18
+
19
+ 维护只读取原请求已保存的计量、参考价格和统一倍率,不读取生成结果正文,不调用供应商,不重新派发模型。每页最多 50 条,以 `(updated_at, id)` 游标前进并在末尾回绕;无法计价或单条损坏的记录不会一直占据首批而阻塞后面的记录。缺少可靠计量的记录继续保留 pending/unknown,不猜测为零费用。
20
+
21
+ 同一 usage owner 的维护合并为一次进行中的工作,不同 owner 独立。数据库故障采用一分钟起、最多五分钟的退避;成功后恢复正常周期。`getReconciliationProgress()` 只提供最近一页的 scanned、settled、deferred、failed、hasMore,不是全库待结算总数,也不包含请求结果、标识或凭据。
22
+
23
+ 维护纳入既有后台工作登记器和 Kernel 关闭等待。standalone 先停止新的维护,再排空已开始的写账;超时保留同实例的待完成工作以供重试,不能将超时当作关库许可。
24
+
25
+ ## 审批决策与补续
26
+
27
+ 外部回调和控制台将审批决策及不可变的补续坐标放在同一事务中保存。补续绑定原 approval、job、request、args hash 与决策标识。审计或排队失败后,使用原 `decision_id` 重试可以补续;后台维护也会检查尚未完成的补续,按审批标识分页推进并回绕,避免在途或异常记录阻塞后续审批。已保存决策但补续失败时返回 `503` 与 `decision_recorded=true / continuation_pending=true`,不得另造一条审批。
28
+
29
+ 原任务入队与独立的审批决策标记由状态仓储原子写入,并在入队临界区重新核对审批是否已消费。入队成功但确认丢失时,重试、进程重开和新一轮任务完成都不会再因同一决策入队。普通任务更新不能清掉此标记。原任务仍在途时等待后续维护,实际执行沿用既有暂停、路由和工具治理。
30
+
31
+ 拒绝的审批只补审计。Agent 直调保持手动模式:批准不启动中枢模型循环,仍由原本地 Agent 使用原 `invocation_id` 显式续执行。已经消费的审批和没有新补续记录的历史决策不被自动回填或重排。
32
+
33
+ 审计追加成功后确认丢失,可能再次出现同一观察,`detail.continuation_id` 可识别这类重复。入队去重不等于跨业务系统恰好执行一次;业务方仍需保持自己的幂等和最终授权。JSONL 的顺序写入适用于一个 writer,不支持多个进程共同写同一文件。
34
+
35
+ ## 迁移与适配边界
36
+
37
+ - `065_usage_reconciliation_scan.sql`:新增待结算分页索引,不重算历史费用。
38
+ - `066_approval_continuations.sql`:新增补续表及 `bz_jobs.approval_continuation_keys`,不改变旧决策或客户业务数据。
39
+
40
+ 沿用 `npm run db:init` 或 Kernel 的显式官方迁移入口,运行时不自动迁移。使用新审批决策入口前必须应用 066;事务写入补续失败会回滚决策,不能留下仅决策成功的孤立记录。升级时协调旧写入,保留备份,并在启用新入口前确认迁移和配套 state/config 仓储就绪。
41
+
42
+ 自定义仓储需配套实现可选的 continuation ledger 方法与 `RuntimeStateStore.requeueApprovedJobOnce`。未实现时新决策明确 unavailable,不退回不能恢复的旧排队方式。这些接口属于 Core;独立 Host 的平台身份、租户升级编排,以及客户端的模型循环和长期记忆均由各自项目维护。
43
+
44
+ 新增结构是增量迁移,回退代码不应删除补续表或标记。回退到旧代码后,本页的补续保证不再适用;先协调停止决策和任务写入,核对已保存的决策、队列与标记,不能清标记后重投来代替恢复。
45
+
46
+ ## 回归入口与限制
47
+
48
+ 默认 `npm test` 包含结算分页、维护、审批补续、状态更新和关闭单测。真实 MySQL 专项使用独立随机 schema 与合成供应商:
49
+
50
+ ```bash
51
+ BAILING_USAGE_TEST_MYSQL=1 BAILING_APPROVAL_CONTINUATION_TEST_MYSQL=1 \
52
+ node --import tsx --test --test-concurrency=4 \
53
+ 'src/modules/usage/*.test.ts' src/app/kernel-usage-lifecycle.mysql.test.ts \
54
+ src/app/approval-continuations.mysql.test.ts
55
+ ```
56
+
57
+ 数据库 fixture 需要本机 `127.0.0.1:16307` 的专用 MySQL、root 空密码及创建/删除测试库权限,禁止指向共享或生产数据库。审批专项含实际子进程 SIGKILL、不同 PID 恢复、COMMIT 确认丢失、并发补续和缺迁移回滚。测试证明给定 fixture 的机制;不证明真实供应商、物理断电持久性或生产业务已验收。跳过的数据库测试不计为通过。
58
+
59
+ 公开实现和测试入口见[能力与证据索引](IMPLEMENTATION_STATUS.md)。
60
+
61
+ ## Core v0.9.3 的 HTTP 与通知修复
62
+
63
+ 工具 HTTP 正文有独立的 5 MiB 默认传输预算;收到 Content-Length 后可以提前拒绝,仍逐块按 fetch 解码后的实际字节检查,缺少或低报长度不能绕过。超限停止下载并丢弃部分正文。HTTP 200 响应头不足以确认写入完成:正文超限/丢失沿原结果未知路径处理,保留原调用及幂等标识,不自动重投。模型视图和审计载荷分别按 UTF-8 字节截断。远程文件读取沿用配置的 max_bytes(默认 20 MiB),渠道附件下载为 20 MiB,均在收包时检查;这些是下载预算,不是解压/解析器资源保证。见[有限收包测试](../src/core/platform/http-body.test.ts)、[工具恢复测试](../src/core/contracts/tools-idempotency.test.ts)和[文件测试](../src/adapters/llm/file.test.ts)。
64
+
65
+ 每个 Kernel 登记回调、通知、审批 webhook、告警与 DLQ 写入的实际收尾工作,在资源关闭前使用共同关闭预算排空;已有工作可以在排空期间登记子工作。standalone 定时器停止后也等待已开始的巡检等维护生产者,避免等待数据库的巡检在通知排空后才登记告警。超时保留资源及同实例重试能力。见[登记器](../src/core/runtime/notification-background-work.ts)、[实际 Kernel 关闭测试](../src/app/kernel-notification-lifecycle.test.ts)、[调度器回归](../src/app/runtime-lifecycle.test.ts)和[通知出口测试](../src/app/notification-outbound.test.ts)。此机制覆盖正常关闭;尚未建立覆盖全部通知意图的持久 outbox,不能据此承诺 SIGKILL 后所有 HTTP 通知都会补投。
66
+
67
+ [067 迁移](../sql/067_delivery_dlq_replay.sql)新增 DLQ 类型、原通知子任务及重投标识,并新增状态仓独立入队标记。原生渠道仍调用原生送达;执行器死信只重排已核对的原通知子任务,保留原收件人、完整输入和 request/job 标识,不重跑业务父任务。返回 queued 表示入队,不表示收件方已收到。并发或入队成功但确认/resolve 写入失败时,同一死信标识不再二次入队;重新失败产生的新死信可由运营者另行处理。JSONL 仍限单 writer。
68
+
69
+ 启动新 Core 的 MySQL DLQ 读写前必须应用 067,包括原生渠道的 record/get;自定义仓储需实现可选的 ensureExecutorReplay 与 requeueDeliveryJobOnce,否则执行器重投明确 unavailable,不降级到错误渠道。回退前停止相关写入并保留迁移账本、队列和标记;删除标记再重投不是恢复。旧制品的 schema manifest 未必接受 067 账本,代码回退须先在隔离副本核验兼容,不能删除迁移记录绕过检查。具体部署与独立 Host 的升级/回滚需各自协调,不由 Core 发行自动部署。
70
+
71
+ 默认测试覆盖[原通知重投](../src/app/delivery-dlq-replay.test.ts)。MySQL 专项使用专用本机 MySQL 和随机测试库,检查旧数据升级、并发入队、真实提交后的确认异常注入、resolve 失败后仓储重开、错误业务绑定及长中文内容;这是仓储断点测试,不是实际杀进程或生产送达验收:
72
+
73
+ ```bash
74
+ BAILING_NOTIFICATION_TEST_MYSQL=1 BAILING_NOTIFICATION_TEST_MYSQL_PORT=16307 \
75
+ BAILING_NOTIFICATION_BASELINE_ROOT=/absolute/clean/core-v0.9.2 \
76
+ node --import tsx --test src/app/delivery-dlq-replay.mysql.test.ts
77
+ ```
78
+
79
+ 后台维护可通过[固定标签指标](OPERATIONS.md)观察在途、失败、关闭超时、最近一页结算/审批进度;抓取只读内存,不触发模型请求。测试入口不等于实际通过记录或已部署环境;正式制品身份和部署验收分别核验。
@@ -0,0 +1,78 @@
1
+ # Read-only deployment diagnostics
2
+
3
+ This deployment mode is available from Core 0.9.2. The historical released `v0.9.1` Tag/npm artifact does not include it. Run the commands below from source or a released artifact that includes `scripts/doctor-deployment.ts`.
4
+
5
+ Deployment diagnostics add a separate mode to `npm run doctor` for an installed Core. Doctor without arguments retains its source, documentation, example and OSS checks. Deployment mode checks the specified instance's public health and version declarations without running the existing check scripts.
6
+
7
+ See [DEPLOYMENT_DIAGNOSTICS.md](DEPLOYMENT_DIAGNOSTICS.md) for Chinese, [OPERATIONS.en.md](OPERATIONS.en.md) for deployment and recovery, and [IMPLEMENTATION_STATUS.en.md](IMPLEMENTATION_STATUS.en.md) for capability and evidence boundaries.
8
+
9
+ ## Usage
10
+
11
+ Run from a Core checkout, source installation or unpacked npm artifact:
12
+
13
+ ```bash
14
+ npm run --silent doctor -- --deployment --url http://127.0.0.1:18900 --json
15
+ ```
16
+
17
+ The operator must provide an explicit URL; the tool does not discover targets from `.env`, `config.json` or smoke environment variables. A controlled Core mount prefix such as `https://hub.example.com/core` is supported but is not printed. URLs containing userinfo, query strings or fragments are rejected. The tool accepts no Token argument and performs no login.
18
+
19
+ The default mode sends only `GET /health` and `GET /version`. It does not connect to a database, read configuration contents, call a model, migrate, install, update, roll back, or control containers or services. It checks only whether `config.json` and `.env` exist. Missing files can indicate environment or host injection, so the effective configuration remains `unknown`. Credential safety is `not_checked`; no claim is made about default Tokens or connection strings.
20
+
21
+ For a container installation, run the same command from the installed Core directory inside the container, or use an externally unpacked Core artifact against the public URL. The tool does not run `docker inspect`, read container environments or infer a running image digest. Container startup, permissions and digest verification belong to the deployment procedure.
22
+
23
+ When the local directory is not the artifact to compare, supply a version and commit from a trusted release record. This example checks a historical v0.9.1 instance:
24
+
25
+ ```bash
26
+ npm run --silent doctor -- --deployment --url https://hub.example.com \
27
+ --expect-version 0.9.1 --expect-commit f37df6042b390405a5f7b1630636d3017607db9f --json
28
+ ```
29
+
30
+ Local identity comes from `package.json` and Git HEAD, falling back to the commit in `build-info.json` when Git is unavailable. By default, both local version and commit are compared; commit prefixes must contain at least 12 hexadecimal characters. A separate read-only Git check reports `clean`, `dirty` or `not_checked`, never filenames, with fsmonitor hooks and optional index writes disabled. A dirty or unavailable Git worktree keeps the default local-source comparison incomplete rather than treating uncommitted contents as the HEAD artifact.
31
+
32
+ Without usable local commit metadata, source remains `unknown` and the exit code is 2. Explicit expectations do not manufacture local source identity. Available public results are still reported; the deployment procedure must supply the missing artifact evidence.
33
+
34
+ Explicit expectations change the comparison target without claiming that another local artifact's SQL list matches the instance. Source evidence uses `local_metadata`; runtime evidence uses `reported_metadata`. Both keep `artifact_integrity: not_checked`. A clean worktree and matching version/commit establish consistent declarations, not artifact contents, signatures or digests. A real upgrade still requires an artifact manifest, integrity verification, backups and compatibility checks.
35
+
36
+ ## Health, readiness and database identity
37
+
38
+ | Evidence | Default behavior | What it establishes |
39
+ |---|---|---|
40
+ | `/health` | Read | Instance response, pause flag and public application identity; a pause flag is not process death. |
41
+ | `/version` | Read | Declared application version, build commit and the latest packaged SQL filename and count. |
42
+ | `/health/ready` | `not_checked` | Read only with explicit `--readiness`; the server reads its database and migration ledger. |
43
+ | `/admin/api/version`, `/admin/api/status` | `not_checked`; no request | Protected state and applied migration details require separately authorized evidence. |
44
+
45
+ Opt in to readiness:
46
+
47
+ ```bash
48
+ npm run --silent doctor -- --deployment --url http://127.0.0.1:18900 --readiness --json
49
+ ```
50
+
51
+ This option causes the server to execute `SELECT 1` and read its migration ledger. It must not be described as having no database access. The tool itself still opens no direct database connection. `migrations.readiness` records only the public server summary, while `migrations.identity` remains `not_checked`. Zero pending migrations cannot prove the database identity, complete checksums or upgrade/downgrade compatibility. A JSONL backend that skips database checks remains `unknown` for this evidence.
52
+
53
+ A 401/403 response is recorded as `authentication_required` and `not_checked`. No authentication bypass or administrator endpoint request follows. Inconsistent health/version declarations, a mismatched expected commit, and a not-ready response are failures.
54
+
55
+ ## JSON and exit codes
56
+
57
+ The report schema is `bailing.deployment-diagnostics.v1`, with source, runtime, comparison, configuration, database, migrations, protected_endpoints, upgrade, checks and request scope. Identity states distinguish `verified`, `mismatch`, `unknown` and `not_checked`. Verified means the corresponding declaration was obtained and compared; it is not cryptographic artifact certification or production adoption evidence.
58
+
59
+ | Exit code | Meaning |
60
+ |---|---|
61
+ | `0` | Selected checks passed. Configuration, direct database access, applied migration identity and protected endpoints may remain unchecked. |
62
+ | `1` | An observed failure, unreachable target, unexpected response, rejected URL or identity mismatch. |
63
+ | `2` | Incomplete evidence: no URL, missing version/commit, authentication required for a selected public endpoint, or skipped database readiness checks. |
64
+ | `64` | Invalid CLI arguments. |
65
+
66
+ `upgrade.state` is always `not_checked`. Exit 0 grants no automatic upgrade or rollback permission and does not replace pause, drain, backup, migration approval or acceptance. Core diagnostics report only the designated Core's public declarations. Host instance management and client task orchestration belong to their respective projects.
67
+
68
+ Each request defaults to 5000 ms, configurable with `--timeout-ms` from 100 to 30000. The deadline includes body reads, with a 64 KiB decoded response cap. All redirects are rejected, including same-origin redirects; retry using the final Core URL. Requests carry JSON Accept only, with no login Cookie, Authorization or configuration credentials. Output retains only fixed allowlisted fields and reason codes, excluding raw exceptions, response bodies, redirect locations and input credentials. Invalid URLs are not echoed.
69
+
70
+ Without `--json`, a short human-readable result is printed. Automation should use `npm run --silent` for clean JSON and check both the exit code and report scope. Deployment mode ignores `BAILING_DOCTOR_FULL`, `BAILING_DOCTOR_SMOKE`, and smoke URL/Token environment variables.
71
+
72
+ ## Local validation
73
+
74
+ ```bash
75
+ node --import tsx --test scripts/doctor-deployment.test.ts
76
+ ```
77
+
78
+ Tests use temporary directories, loopback HTTP services and the existing public routes. They cover method/path restrictions, identity mismatch, authentication, readiness separation, deadlines, response caps, redirects and credential redaction. They do not connect to a real database, model or production service. Passing tests validate these diagnostic boundaries, not the acceptance of a target deployment.
@@ -0,0 +1,78 @@
1
+ # 只读部署诊断
2
+
3
+ 本页部署模式从 Core 0.9.2 提供;历史正式 `v0.9.1` Tag/npm 不包含该模式。请从包含 `scripts/doctor-deployment.ts` 的源码或正式制品执行以下命令。
4
+
5
+ 部署诊断沿用 `npm run doctor`,增加一个面向已安装 Core 的独立模式。原有不带参数的 doctor 继续检查源码、文档、示例和开源边界;部署模式只核对指定实例的公开健康与版本信息,不执行原有 doctor 的检查脚本。
6
+
7
+ 英文版见 [DEPLOYMENT_DIAGNOSTICS.en.md](DEPLOYMENT_DIAGNOSTICS.en.md)。部署与恢复步骤见 [OPERATIONS.md](OPERATIONS.md),能力和证据范围见 [IMPLEMENTATION_STATUS.md](IMPLEMENTATION_STATUS.md)。
8
+
9
+ ## 使用
10
+
11
+ 在 Core 源码、源码安装目录或已解包的 npm 制品目录执行:
12
+
13
+ ```bash
14
+ npm run --silent doctor -- --deployment --url http://127.0.0.1:18900 --json
15
+ ```
16
+
17
+ URL 必须由操作者显式提供,不从 `.env`、`config.json` 或 smoke 环境变量猜测目标。支持受控的 Core 挂载前缀,例如 `https://hub.example.com/core`;输出不显示这个前缀。URL 不能包含用户名、密码、query 或 fragment,诊断不接收 Token 参数,也不自动登录。
18
+
19
+ 默认仅发送 `GET /health` 和 `GET /version`。它不连接数据库、不读配置内容、不调用模型,也不执行迁移、安装、升级、回滚、容器或服务操作。仅检查 `config.json` 和 `.env` 是否存在;文件缺失可能表示由环境或宿主注入配置,因此有效配置仍标为 `unknown`。凭据安全性标为 `not_checked`,不会假装完成默认 Token 或数据库连接串检查。
20
+
21
+ 容器部署可在容器中已安装的 Core 目录执行相同命令,也可在外部解包的 Core 制品目录诊断公开 URL。工具不会运行 `docker inspect`、读取容器环境或推断正在运行的镜像 digest;容器启动、权限和 digest 须由部署流程另行核对。
22
+
23
+ 若本地目录不是要对照的制品,可显式指定受信任发行记录中的版本和提交。下面以核对历史 v0.9.1 实例为例:
24
+
25
+ ```bash
26
+ npm run --silent doctor -- --deployment --url https://hub.example.com \
27
+ --expect-version 0.9.1 --expect-commit f37df6042b390405a5f7b1630636d3017607db9f --json
28
+ ```
29
+
30
+ 本地身份来自 `package.json` 与 Git HEAD;无 Git 时才使用 `build-info.json` 的提交。默认比较本地版本与提交,提交可按至少 12 位十六进制前缀匹配。Git 工作树另行只读检查并标为 `clean`、`dirty` 或 `not_checked`,不会输出文件名,也会禁用 fsmonitor hook 与可选 index 写入。默认对照本地源码时,dirty 或无法检查的 Git 工作树保留不完整结果,不把未提交内容当作 HEAD 对应制品。
31
+
32
+ 安装目录没有可用提交元数据时,source 保留 `unknown`,退出码为 2;显式期待值也不会补造本地源码身份。工具仍会输出已取得的公开结果,后续由部署流程提供缺失的制品证据。
33
+
34
+ 显式期待值只改变对照对象,不将另一个本地制品的 SQL 列表强行视为运行实例的列表。source 的依据是 `local_metadata`,runtime 的依据是 `reported_metadata`;两者的 `artifact_integrity` 均为 `not_checked`。即使工作树 clean、版本和提交完全匹配,也只证明声明一致,不能证明部署制品的内容、签名或 digest。正式升级仍须核验制品清单、完整性、备份和兼容性。
35
+
36
+ ## 健康、readiness 与数据库身份
37
+
38
+ | 证据 | 默认行为 | 能说明什么 |
39
+ |---|---|---|
40
+ | `/health` | 读取 | 实例响应、暂停标记与公开应用身份;暂停标记不等于进程死亡。 |
41
+ | `/version` | 读取 | 实例声明的应用版本、构建提交与制品所带 SQL 最新文件和数量。 |
42
+ | `/health/ready` | `not_checked` | 只有显式 `--readiness` 才读取;服务端会只读检查数据库及迁移账本。 |
43
+ | `/admin/api/version`、`/admin/api/status` | `not_checked`,不发送请求 | 受保护状态和已应用迁移明细需另行取得授权证据。 |
44
+
45
+ 显式检查 readiness:
46
+
47
+ ```bash
48
+ npm run --silent doctor -- --deployment --url http://127.0.0.1:18900 --readiness --json
49
+ ```
50
+
51
+ 此选项会让服务端执行 `SELECT 1` 和迁移账本读取,不应称为“无数据库访问”。工具本身仍不直接连接数据库。报告中 `migrations.readiness` 仅记录服务端公开摘要;`migrations.identity` 始终是 `not_checked`,不会以 pending 为零证明实际数据库身份、全量 checksum 或 SQL 升降级兼容。JSONL 后端跳过数据库检查时保留 `unknown`,不会写成数据库已验证。
52
+
53
+ 公开端点返回 401/403 时记录 `authentication_required` 和 `not_checked`,不尝试绕过权限或调用管理员端点。health 和 version 声明不一致、期待提交不符或 readiness 不就绪均作为失败证据。
54
+
55
+ ## JSON 与退出码
56
+
57
+ JSON 的 `schema` 为 `bailing.deployment-diagnostics.v1`,包含 source、runtime、comparison、configuration、database、migrations、protected_endpoints、upgrade、checks 和请求 scope。身份状态区分 `verified`、`mismatch`、`unknown`、`not_checked`;`verified` 表示取得且核对了对应声明,不是密码学制品认证或生产采用证明。
58
+
59
+ | 退出码 | 含义 |
60
+ |---|---|
61
+ | `0` | 本次选择的检查通过;配置、直接数据库连接、已应用迁移身份和受保护端点仍可能未检查。 |
62
+ | `1` | 实际失败、不可达、非预期响应、拒绝的 URL 或身份不一致。 |
63
+ | `2` | 证据不完整,例如未提供 URL、版本/提交缺失、所选公开端点需认证,或 readiness 跳过数据库。 |
64
+ | `64` | CLI 参数无效。 |
65
+
66
+ `upgrade.state` 始终是 `not_checked`。退出 0 不允许工具自行升级或回滚,也不替代暂停、排空、备份、迁移审批和上线验收。Core 诊断只核对指定 Core 的公开声明;宿主实例管理与客户端任务编排由各自项目负责。
67
+
68
+ 每个请求默认限时 5000 ms,可用 `--timeout-ms 100` 至 `--timeout-ms 30000` 调整;包含响应体读取,最多读取 64 KiB 解码后的内容。所有重定向均拒绝,包括同 origin 跳转,使用最终 Core URL 重试。请求只携带 JSON Accept,不携带登录 Cookie、Authorization 或配置凭据。输出只保留固定白名单字段和原因码,不输出异常正文、响应正文、重定向目标或输入中的凭据;错误 URL 不会原样打印。
69
+
70
+ 不带 `--json` 时输出简短可读结果。自动化应使用 `npm run --silent` 得到纯 JSON,并同时检查退出码与报告范围;`BAILING_DOCTOR_FULL`、`BAILING_DOCTOR_SMOKE` 和 smoke 的 URL/Token 环境变量不影响部署模式。
71
+
72
+ ## 本地验证
73
+
74
+ ```bash
75
+ node --import tsx --test scripts/doctor-deployment.test.ts
76
+ ```
77
+
78
+ 测试使用临时目录、临时 loopback HTTP 服务和现有公共路由,覆盖方法与路径白名单、身份不一致、权限、readiness 区分、超时、响应大小、重定向和凭据脱敏。测试不连接真实数据库、模型或生产服务。测试通过只说明这些诊断边界通过验证,不能替代目标部署的验收。