Repository navigation
Reduce temporary Inbox receipt buffer allocations - #8244
Conversation
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent, gpt-6.1-sol, OpenAI, runtime_reported, reasoning_effort=max
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
当前 head 未发现阻塞项。独立核对了普通分页、文件变化后的完整读取、超限拒绝与源修复后的恢复。
动机 / Motivation
接收方打开 Inbox 查看待处理请求时,需要读到每条记录的原文和当前的恢复提示。 在多数记录只有几百字节的两页样例里,旧读法每次读取都预分配 128,001 字节。候选按观测大小分配,碰到文件增长时继续用同一描述符读到上限。 相同 27 条记录完整回读,136 次记录读取的 Buffer.alloc 总量从 17,408,136 字节降到 42,757 字节。 改动限定在 Inbox 文件读取和字节边界。请求权限、回传与分页沿用原流程。 A28 的打包桌面、窄屏、键盘及 Lark 多受众整体验收仍待验证。
改动思路 / Approach
缓冲区负责读取字节,现有 receipt 与生命周期 owner 继续判断可见性、恢复和回传。 这一提交收口单次 Inbox 文件读取的分配成本、字节上限和增长行为。 打开文件后,fstatSync 与 readSync 共用描述符。保留固定缓冲仍会让小记录承担整块分配。共享缓冲则需要引入额外的跨请求生命周期和隔离规则。候选沿现有读路按大小分配,增长时只做一次有界扩容。
具体改动 / Changes
按基线 97cc1e0 的 RFC 核对。5.15 的适用部分是读取完整原文和连续页、保留不可读证据及按源恢复。A28 的完整多受众与打包界面验收仍按原范围推进。基线规范
关键代码讲解
- readRecord 先做原有的普通文件和大小检查,为小文件多留一字节探测增长。读满后扩到 128,001 字节,并按实际读入量检查上限。128,001 字节拒绝,UTF-8 与 JSON 仍走原解析和异常处理。精确代码
- receiptState 和 pendingPage 沿用同一读取结果。前者保留请求、决定和结论的关系,后者按原来源和游标组装可见页。新增事务测试构造恰好 128,000 字节的有效记录,检查完整消息返回。回执关系 · 边界测试
对主干的风险 / Risks
最敏感的反例是 fstat 后追加最后几个字节。File 和 SQLite 的实际 CLI 对照中,增长到 128,000 字节返回完整消息,增长到 128,001 字节报超限。文件缩短、无效 UTF-8、修复后重读也与基线一致。人为截掉候选的后续读取时,同一入口报无效记录。普通两页都返回 20 加 7 条,读取字节、调用次数和源记录内容相同。
- PASS · Inbox TS 事务基线 21 条、候选 22 条。定向 Python Inbox 恢复和 Chat HTTP 分页、坏记录恢复两边各 19 条。候选 typecheck 与 quick premerge 的 4 项直接、2 项选中检查通过。
- FAIL · 仓库要求的 Ruff 命令在两边都只报 tests/control_plane/test_goal_create_completion.py:184 的 F841,质量门仍需独立处理。作者的大套件调度失败保留为原运行记录,本次实证覆盖受影响的 Inbox 读路。
我的整体评价 / Verdict
小记录反复读取的分配量下降,接收方仍能按原游标读完,并在坏记录修复后读到原文。已有生命周期和权限词汇沿用。界面层没有改动,视觉检查不适用。 文件在 fstat 后增长时会额外分配一次并增加一次读取。真实负载的完整延迟和安装后采用仍待验证。 这一缓冲区改动已经收在既有读函数内,相邻异步回传读取有独立的恢复规则。
English verdict: APPROVE at e32eee9. Matched File and SQLite Inbox reads preserve records, byte limits and recovery, with lower temporary allocation in the measured fixture.
Goal And Delivered Outcome
The TypeScript Inbox reader allocated a 128,001-byte buffer for every stored record. The reader now allocates the observed file size plus one byte and expands within the existing byte limit if the file grows after inspection. The same descriptor supplies every byte and the existing record checks handle EOF, malformed content and oversized input.
A synthetic inventory of 396 requests in 33 batches allocated 160,513,254 buffer bytes per pass on the base and 1,669,302 on the candidate, with identical returned results. Across 18 warm samples per revision, the median elapsed time for the receipt stage was 180 ms and 185 ms. The supported improvement is lower buffer allocation. The full-reader latency still needs qualification.
Author Declaration
Written by model_agent, OpenAI GPT-6. The change is scoped to the original Inbox read and recovery requirements in A28. Accepted RFC at the tested base
inbox_read.tsinbox_read.tsScope And Continuation
The change is confined to the existing file reader and its boundary test. File paths, authority decisions, receipt state and returned payloads come from the existing owners. The buffer change can be reverted independently. Earlier lock write reduction is tracked separately. Related PR
Validation
e32eee90b71111ea3f1999aea99cbba273f3c8e2.tests/control_plane/test_goal_create_completion.py:184is present on the verified base and exact headAuthorized read-only parity retains the original request coverage and diagnostics. Whole-reader timing showed no stable improvement. Installed service latency and adoption remain open.
Frontend / Visual Evidence
UI impact none. The packaged Chat tests exercise the existing presentation and API.
Type of Change
LoopX Area
Shared-authority RFC fixture impact
N/A. Existing File and SQLite routes retain the same receipt readback.
Boundary Checklist