Skip to content

Commit 9514a49

Browse files
committed
feat(github_sync): cap receive-pack diagnostics with a byte budget (GS-26)
Bump mega2 to 0.38.18. Signed-off-by: Eli Ma <eli@patch.sh>
1 parent a4ada24 commit 9514a49

11 files changed

Lines changed: 551 additions & 54 deletions

File tree

‎Cargo.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mega2"
3-
version = "0.38.17"
3+
version = "0.38.18"
44
edition = "2024"
55
# Two [[bin]] targets exist; keep `cargo run -p mega2` unambiguous.
66
default-run = "mega2"

‎config/config.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ enforcement = "off"
355355
# send_timeout_seconds = 300
356356
# report_timeout_seconds = 60
357357
# exit_timeout_seconds = 15
358+
# diagnostic_budget_bytes = 4096
358359
# [[github_sync.bindings]]
359360
# id = "core"
360361
# path = "/project/core"

‎docs/plan/plan-20260916.md‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**模板版本:** v2.1。源码核对日期 2026-09-19;tip `a61ed5f`,crate `0.38.1`。
44

5-
**计划状态(2026-09-20):** **实施中**。设计双评已通过(Codex R9 / R11 `VERDICT: PASS`,Claude R11 `VERDICT: PASS`)。发布窗口已落到 `GS-20`(`v0.38.17`);下一张是 `GS-26`。其余活动卡仍按单链执行,不得跳卡。
5+
**计划状态(2026-09-20):** **实施中**。设计双评已通过(Codex R9 / R11 `VERDICT: PASS`,Claude R11 `VERDICT: PASS`)。发布窗口已落到 `GS-26`(`v0.38.18`);下一张是 `GS-09`。其余活动卡仍按单链执行,不得跳卡。
66

77
## 文档职责
88

@@ -208,6 +208,7 @@
208208
| 2026-09-20 | 实施卡 GS-15 | 报告层终止判定;R1 FAIL 已关(channel 1 内层 pkt-line、`unpack <error>`);Codex/Claude R2 PASS | 卡号不变 | `target/tmp/plan-20260916-gs15-codex-r2.txt`;`target/tmp/plan-20260916-gs15-claude-r2.txt` |
209209
| 2026-09-20 | 实施卡 GS-25 | SSH 终止事件与失败优先级;R1 FAIL 已关(fatal 立即返回、exit 后继续排空 stdout);Codex/Claude R2 PASS | 卡号不变 | `target/tmp/plan-20260916-gs25-codex-r2.txt`;`target/tmp/plan-20260916-gs25-claude-r2.txt` |
210210
| 2026-09-20 | 实施卡 GS-20 | receive-pack 四处独立期限;写集补 `ssh.rs`(AC-5 abort);Codex R1–R5 FAIL / R6–R7 PASS;Claude R1/R4/R6 FAIL、R2/R3/R5/R7 PASS | 卡号不变 | `target/tmp/plan-20260916-gs20-codex-r7.txt`;`target/tmp/plan-20260916-gs20-claude-r7.txt` |
211+
| 2026-09-20 | 实施卡 GS-26 | receive-pack 诊断字节预算;ch2/ch3/stderr 单帽;ch3/stderr 优先;lossy UTF-8;Codex R1 FAIL / R2–R4 PASS;Claude R1–R3 FAIL / R4 PASS | 卡号不变 | `target/tmp/plan-20260916-gs26-codex-r4.txt`;`target/tmp/plan-20260916-gs26-claude-r4.txt` |
211212

212213
## 已决议设计决策
213214

@@ -1505,7 +1506,7 @@ G-07 对齐(R7):`implementation` 卡 `Release boundary=independent`,自
15051506

15061507
**Task type:** `implementation`
15071508

1508-
**Lifecycle / Acceptance:** `pending` / 空
1509+
**Lifecycle / Acceptance:** `done` / `complete`
15091510

15101511
**Description:** 为诊断输出设定字节预算并在超出时截断标记。本卡唯一行为轴:**诊断的容量边界**。 自 `GS-20` 拆出(R5 P1-01:合卡按独立谓词超 G-03 上限)。
15111512

@@ -1517,20 +1518,22 @@ G-07 对齐(R7):`implementation` 卡 `Release boundary=independent`,自
15171518
|---|---|
15181519
| 诊断来源为 side-band channel 2/3 与 SSH stderr | GS-15 AC-8(channel 3 fatal);GS-25 AC-1(SSH stderr) |
15191520
| GC-10 禁止无界内存 | 「全局工程约束」 |
1521+
| 可配置预算默认 4096、下限 9 | `src/config/model.rs:98`、`:105`、`:107` |
1522+
| 单帽 sink:progress=ch2,important=ch3/stderr;UTF-8 lossy | `src/ceres/github_sync/send_pack.rs:758`、`:777`、`:792` |
15201523

15211524
**Acceptance criteria:**
15221525

1523-
- [ ] AC-1:诊断输出有字节预算上限。
1524-
- [ ] AC-2:该预算为可配置字段。
1525-
- [ ] AC-3:该预算有默认值。
1526-
- [ ] AC-4:诊断超出预算时截断。
1527-
- [ ] AC-5:AC-4 的截断结果置「已截断」标记。
1528-
- [ ] AC-6:截断按字节边界安全处理,不产生非法 UTF-8 片段。
1526+
- [x] AC-1:诊断输出有字节预算上限。
1527+
- [x] AC-2:该预算为可配置字段。
1528+
- [x] AC-3:该预算有默认值。
1529+
- [x] AC-4:诊断超出预算时截断。
1530+
- [x] AC-5:AC-4 的截断结果置「已截断」标记。
1531+
- [x] AC-6:截断按字节边界安全处理,不产生非法 UTF-8 片段。
15291532

15301533
**Verification:**
15311534

1532-
- [ ] VER-1:`source .env.test && cargo test -p mega2 --lib 'ceres::github_sync::send_pack::tests::diagnostic_budget_truncates' -- --test-threads=1` (new;覆盖 AC-1、AC-4..AC-6)
1533-
- [ ] VER-2:`source .env.test && cargo test -p mega2 --lib 'config::tests::github_sync_diagnostic_budget_default' -- --test-threads=1` (new;覆盖 AC-2/AC-3)
1535+
- [x] VER-1:`source .env.test && cargo test -p mega2 --lib 'ceres::github_sync::send_pack::tests::diagnostic_budget_truncates' -- --test-threads=1` (new;覆盖 AC-1、AC-4..AC-6)
1536+
- [x] VER-2:`source .env.test && cargo test -p mega2 --lib 'config::tests::github_sync_diagnostic_budget_default' -- --test-threads=1` (new;覆盖 AC-2/AC-3)
15341537

15351538
**Dependencies:** `GS-20`(与其共享写集,以顺序边消解 I–I 相交)
15361539

@@ -2308,6 +2311,14 @@ Result 只允许 `PASS` 或 `FAIL`。
23082311
| GS-20 R6 | 实施卡;Claude CLI 只读 | `FAIL` | P1:15s inactivity 抢先于 30/300/60 默认期限 | — | `target/tmp/plan-20260916-gs20-claude-r6.txt` |
23092312
| GS-20 R7 | 实施卡;Codex CLI 只读 | `PASS` | 无 P0/P1 | R6 P1 已关(inactivity = max 四处期限) | `target/tmp/plan-20260916-gs20-codex-r7.txt` |
23102313
| GS-20 R7 | 实施卡;Claude CLI 只读 | `PASS` | 无 P0/P1 | P2:写集补 `ssh.rs`(本轮已记);其余不扩卡 | `target/tmp/plan-20260916-gs20-claude-r7.txt` |
2314+
| GS-26 R1 | 实施卡;Codex CLI 只读 | `FAIL` | P1:ch2 留在 report buf;小预算切掉 marker | — | `target/tmp/plan-20260916-gs26-codex-r1.txt` |
2315+
| GS-26 R1 | 实施卡;Claude CLI 只读 | `FAIL` | P1:非 UTF-8 诊断被 `valid_up_to` 整段丢弃 | P2:小预算切 marker | `target/tmp/plan-20260916-gs26-claude-r1.txt` |
2316+
| GS-26 R2 | 实施卡;Codex CLI 只读 | `PASS` | 无 P0/P1 | R1 已关(demux / min=9 / lossy) | `target/tmp/plan-20260916-gs26-codex-r2.txt` |
2317+
| GS-26 R2 | 实施卡;Claude CLI 只读 | `FAIL` | P1:溢出仍用 raw `valid_up_to`;ch2 饿死 ch3 | — | `target/tmp/plan-20260916-gs26-claude-r2.txt` |
2318+
| GS-26 R3 | 实施卡;Codex CLI 只读 | `PASS` | 无 P0/P1 | R2 P1 已关(fit 只按字节;important 优先) | `target/tmp/plan-20260916-gs26-codex-r3.txt` |
2319+
| GS-26 R3 | 实施卡;Claude CLI 只读 | `FAIL` | P1:`repeat().take()` 触 clippy `manual_repeat_n` | P2:SIDEBAND_PKT_CAP / trim | `target/tmp/plan-20260916-gs26-claude-r3.txt` |
2320+
| GS-26 R4 | 实施卡;Codex CLI 只读 | `PASS` | 无 P0/P1 | clippy 行改为 `repeat_n` | `target/tmp/plan-20260916-gs26-codex-r4.txt` |
2321+
| GS-26 R4 | 实施卡;Claude CLI 只读 | `PASS` | 无 P0/P1 | P2 不扩卡 | `target/tmp/plan-20260916-gs26-claude-r4.txt` |
23112322

23122323
### R1 逐条关闭矩阵
23132324

‎docs/refactoring/github-sync.md‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,13 @@ stops without waiting for later report lines.
238238

239239
When `side-band-64k` is negotiated, channel 1 carries the inner
240240
pkt-line `report-status` stream and may split a pkt-line across
241-
packets. Channel 2 is ignored. Channel 3 is fatal immediately. An
242-
outer multiplex flush without a complete inner report is
241+
packets. Channel 2 is collected into the diagnostic budget. Channel 3
242+
is fatal immediately and also counts toward that budget. An outer
243+
multiplex flush without a complete inner report is
243244
`report_incomplete`, not a disconnect.
244245

245246
SSH transport termination is below. Deadlines are GS-20. Diagnostic
246-
byte budgets are GS-26.
247+
byte budgets are in 「诊断容量边界」.
247248

248249
## 传输层终止事件
249250

@@ -281,4 +282,20 @@ session inactivity bound is at least the max of these four fields
281282
`exit_timeout_seconds` starts when report-status parses successfully
282283
or stdout closes, then covers the SSH exit-status/exit-signal wait
283284
and any remaining stdout drain. Zero is rejected at config validate.
284-
Diagnostic byte budgets are GS-26.
285+
Diagnostic byte budgets are in 「诊断容量边界」.
286+
287+
## 诊断容量边界
288+
289+
`[github_sync].diagnostic_budget_bytes` (default 4096) is the single
290+
cap for receive-pack diagnostic output: side-band channel 2, side-band
291+
channel 3, and SSH stderr. Values below 9 (the complete `truncated`
292+
marker) are rejected at validate. The field is restart-required.
293+
Side-band channel 2/3 payloads are counted and discarded after the
294+
sink; they are not retained on the report buffer. Channel 3 and SSH
295+
stderr take priority over channel 2 when the cap is full.
296+
297+
Collection stops at the cap. Overflow truncates on a UTF-8 character
298+
boundary (no illegal fragment) and appends the `truncated` marker
299+
(计划 AC-5「已截断」). Non-UTF-8 remote bytes are shown with U+FFFD
300+
so ASCII around them survives (GS-15 / GS-25). Rendered diagnostic
301+
bytes stay within the configured cap.

0 commit comments

Comments
 (0)