Răsfoiți Sursa

docs(code-runtime-python): register the open-merge split billing in the settlement note

The review's suggestion: the settlement note's Decision section now states the
shipped split-billing fact (first fragment pays quotes+separator, continuations
and the closing frame pay content only; host caps logBudget-1 / logBudget+2;
child keys off _open_started), paired and re-recorded.
Chinesezjc 2 săptămâni în urmă
părinte
comite
c7d2d4b8b5

+ 2 - 2
.agents/notes/implemented/bug-fix/2026-07-31-code-runtime-python-settlement-fixes.i18n.yaml

@@ -2,5 +2,5 @@
 # side as of the last confirmed-consistent state. Both languages carry equal authority;
 # after editing either side, bring the other along and re-record with:
 #   pnpm run verify-translation-pairing --write .agents/notes/implemented/bug-fix/2026-07-31-code-runtime-python-settlement-fixes.md
-2026-07-31-code-runtime-python-settlement-fixes.md: bffd2836fe6fd7161cb128cb7e6baa625a7a11d9
-2026-07-31-code-runtime-python-settlement-fixes.zh.md: 0bee32de51e95daf9557bf98ba273ff0f4e83587
+2026-07-31-code-runtime-python-settlement-fixes.md: a25075e774928eccf7dfb94673e20cc004cb19cb
+2026-07-31-code-runtime-python-settlement-fixes.zh.md: 2070039324e9bb32ce9daa67d743f8072d4468db

+ 4 - 0
.agents/notes/implemented/bug-fix/2026-07-31-code-runtime-python-settlement-fixes.md

@@ -12,6 +12,10 @@ The CPython subprocess backend for Code Mode, built on the [fd-3 frame protocol]
 
 Independent corrections, each in the package that owns the defect.
 
+### A merged open-log entry is billed once, split across its fragments
+
+An explicit `flush()` of an unterminated line emits a `log` frame with `open: true`, and the host appends the next frame to the SAME entry (`print('a', end='', flush=True); print('b')` reads back as one `'ab'` entry, not a fake newline). The merged entry's wire cost — quotes, content, separator — is billed exactly once, split incrementally across its fragments on both sides (O(k) for k fragments, never a re-walk of the whole hold): the FIRST fragment pays the full JSON-string cost plus the separator, each continuation and the closing frame pay only their content. The host's exact-cost caps are `logBudget - 1` for a first fragment (the ledger's reserved byte, matching `admit`) and `logBudget + 2` for a continuation or closing frame (billed without the two quotes), with `jsonStringCostUpTo` returning `undefined` below a 2-byte cap; the child keys its split billing off `_open_started` alone, so a closing frame bills as the merged tail rather than a fresh entry (which would double-charge quotes+separator and truncate an exact-fit entry).
+
 ### Boot-write failure no longer rejects run()
 
 In [`src/index.ts`](../../../../packages/code-runtime/code-runtime-python/src/index.ts) the fd-3 boot-frame write is the last statement of `run()`'s synchronous setup. Its `catch` calls `finish()`, and `finish()` reads `wallTimer` and `onAbort` and — through `settle()` — `live`. Those bindings are `const` and were declared AFTER the boot-write, so on a synchronous write failure `finish()` touched them in their temporal dead zone and threw a `ReferenceError`. That escaped the Promise executor and REJECTED `run()`, violating the seam's "outcomes resolve" contract: the caller saw a thrown error instead of the `worker-exit` the catch constructs. The boot-write block is now emitted after `wallTimer`, `onAbort`, and `live` are initialized, and the `/* v8 ignore */` that had hidden the branch from coverage is removed so the catch is measured.

+ 4 - 0
.agents/notes/implemented/bug-fix/2026-07-31-code-runtime-python-settlement-fixes.zh.md

@@ -12,6 +12,10 @@ Status: implemented
 
 若干处相互独立的修正,各自位于拥有对应缺陷的包中。
 
+### 合并的 open 日志条目只计费一次,按片段分摊
+
+未结束行的显式 `flush()` 发出带 `open: true` 的 `log` 帧,宿主把下一个帧追加到同一条目(`print('a', end='', flush=True); print('b')` 读回为一条 `'ab'` 条目而不是假换行)。合并条目的线上成本——引号、内容、分隔符——恰好计费一次,在两侧按片段增量分摊(k 个片段 O(k),绝不对整个持有重走):首片段付完整 JSON 字符串成本加分隔符,每个续接与闭合帧只付内容。宿主的精确成本 cap 是首片段 `logBudget - 1`(账本预留字节,与 `admit` 一致)、续接或闭合帧 `logBudget + 2`(不含两个引号计费),且 `jsonStringCostUpTo` 在低于 2 字节 cap 时返回 `undefined`;子进程按 `_open_started` 单独键控拆分计费,因此闭合帧按合并尾部计费而非新条目(新条目会重复计引号加分隔符,并截断恰好适配的条目)。
+
 ### Boot-write failure no longer rejects run()
 
 在 [`src/index.ts`](../../../../packages/code-runtime/code-runtime-python/src/index.ts) 中,fd-3 引导帧写入是 `run()` 同步初始化阶段的最后一条语句。它的 `catch` 会调用 `finish()`,而 `finish()` 读取 `wallTimer` 和 `onAbort`,并通过 `settle()` 读取 `live`。这些绑定是 `const`,且声明在引导写入之后,因此在同步写入失败时,`finish()` 会在它们处于暂时性死区(temporal dead zone)时访问它们,从而抛出一个 `ReferenceError`。该错误逃出了 Promise executor 并 reject 了 `run()`,违反了 seam 的"结果一律 resolve"契约:调用方看到的是一个被抛出的错误,而不是 catch 构造的 `worker-exit`。现在引导写入代码块被放到 `wallTimer`、`onAbort` 和 `live` 初始化之后,并且那处曾把该分支从覆盖率中隐藏的 `/* v8 ignore */` 已被移除,从而使该 catch 被纳入度量。