refactor(serial): Step 2 读循环瘦身 + 帧硬切块 - #6
Merged
Conversation
RFC #3 Step 2: - Replace the four duplicated frame-emission blocks in connect() with a single emit_frame closure driven by FrameSegmenter (read loop ~330 -> ~120 lines). - Add max_frame_bytes hard cap (default 64 KiB): continuous streams with no delimiter are cut into cap-sized chunks during feed instead of accumulating unboundedly until an idle gap. Delimiters within the cap window still win. This is the only intentional behavior change. - Raw file tap stays before segmentation; read-error silent death pinned as Step 3 scope. Tests: 32/32 green (3 new framing unit tests + 1 scripted-port harness test for hard-cap cutting). cargo build warning-free.
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_60cc9f10-ca93-4feb-bf6c-3769c92c96e7) |
This was referenced Sep 2, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RFC #3 Step 2:读循环瘦身 +
max_frame_bytes硬切块跟踪 issue:#3(前置:#4 CI 安全网、#5 FrameSegmenter 抽取)
改动
serial_manager.rs:connect()读循环 ~330 → ~120 行。原先 4 处复制粘贴的产出块(text 录制 → display 格式化 → LogEntry push+trim → stats)合并为单一emit_frame闭包,分帧决策全部委托给FrameSegmenter。framing.rs:新增max_frame_bytes硬上限(DEFAULT_MAX_FRAME_BYTES = 64 KiB)。连续无分隔符数据流在feed()内按上限切块,不再无限积累等空闲间隙;分隔符在上限窗口内仍优先成帧。64 KiB 对齐 Step 4 规划的 IPC 批量预算。唯一有意的行为变化
单帧不再可能无限大:> 64 KiB 的无分隔符连续数据会被切成 64 KiB 大小的帧。Raw 文件 tap 位置不变(分帧前写入),录制内容不受影响。
验证
cargo test32/32 全绿:28 个基线 + 3 个新硬切块单元测试 + 1 个 harness 测试(150 KiB 连续流 → 65536+65536+22528 三帧)cargo build零警告/dev/cu.usbserial-A5069RR4)正确枚举明确不做(后续 Step)
golden_reader_death_is_silent_today钉住现状)→ Step 3 生命周期修复Note
Medium Risk
Touches the hot-path serial RX loop and changes how very large continuous payloads appear as frames, though legacy delimiter/timeout semantics are otherwise preserved and heavily golden-tested.
Overview
RFC #3 Step 2 slims the serial read thread by delegating all framing to
FrameSegmenterand centralizing RX handling in oneemit_framepath (text recording, display formatting, logs, stats), replacing four copy-pasted blocks.FrameSegmenternow enforcesDEFAULT_MAX_FRAME_BYTES(64 KiB) duringfeed(): delimiter matches only count inside the first cap-sized window; otherwise the buffer is emitted in cap-sized chunks even without idle timeout. Timeout-mode idle flush is unchanged; raw recording still taps bytes before framing.Intentional behavior change: delimiter-free streams no longer produce arbitrarily large log frames—they split at 64 KiB (with a pinned edge case when a delimiter straddles the cap). New unit and scripted-port golden tests cover hard cuts and a 150 KiB continuous stream.
Reviewed by Cursor Bugbot for commit 39171ee. Bugbot is set up for automated code reviews on this repo. Configure here.