Skip to content

perf(mapping-store): bound startup file reads - #1369

Merged
iruriQ merged 1 commit into
BytePioneer-AI:mainfrom
ChaceLyee2101:perf/mapping-store-startup-reads
Nov 29, 2026
Merged

iruriQ merged 1 commit into
BytePioneer-AI:mainfrom
ChaceLyee2101:perf/mapping-store-startup-reads

Conversation

@ChaceLyee2101

Copy link
Copy Markdown
Contributor

Summary

Mapping Store startup awaited every Thread, metadata, and delegation read serially, which compounds latency on stores with hundreds of records.

  • Read Thread records and their metadata, then delegation records, in ordered batches of up to eight. Keep recovery, quarantine, migration, and map insertion in the original directory order under the existing lock.
  • Drain every read in an active batch before surfacing an error to initialization cleanup. Preserve backup fallback and the existing exclusive lock and takeover protocol.

Related issues

Refs #595. Thanks to #609 for the prior bounded-read work. Archived records still load at startup. Physical HDD and end-to-end Desktop startup remain to be measured.

UI Demo

N/A (Mapping Store startup I/O).

Test plan

  • Both new regressions failed on the base commit and passed with this change. vitest run --config tests/vitest.config.js packages/mapping-store/test passed all 166 tests in 15 files. Coverage includes ordered bounded reads, lock retention on failure, and reopening the same instance.
  • tsc -b packages/mapping-store, focused ESLint, Prettier, and git diff --check passed.
  • Benchmarked MappingStore.initialize() on arm64 macOS, Node 22.23.2, before commit 049b07b91 and after c381ede95. Each alternating sample used a fresh copy of the same synthetic data with 725 Threads (573 archived), 208 metadata files, 204 delegations, and 344 backups. Fixture setup and teardown were outside the measured interval. Both revisions read the same 1,654 record paths per sample and produced matching Thread and delegation data.
Workload Samples per revision Median, before → after p90, before → after
Local disk, warm cache 15 85.0 ms → 38.6 ms 91.3 ms → 43.2 ms
Local files with 5 ms added per record read 7 10.009 s → 1.316 s 10.083 s → 1.392 s

The maximum observed number of simultaneous record reads was 1 before and 8 after. Independent per-read delays model latency, not a physical drive's seek behavior.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 体验优化
    • 启动时可并行加载线程及相关数据,提升线程列表的加载效率,同时保持原有顺序。
  • 问题修复
    • 启动读取失败后会完成清理并释放存储锁,避免后续操作受到阻碍。
    • 无效线程及元数据仍可按既有方式恢复或隔离,减少异常数据对其他线程加载的影响。

Mapping Store 启动读取改为每批最多并发 8 项。Thread 和 Delegation 结果仍按目录顺序处理。读取失败时,当前批次完成后才执行失败清理并释放存储锁。

Changes: Mapping Store 启动读取

Layer / File(s) Summary
有序并发读取批次
packages/mapping-store/src/startup-reads.ts
新增 readStartupBatches,每批最多并发读取 8 项,并按输入顺序产出结果。
启动加载与记录处理
packages/mapping-store/src/mapping-store.ts
Thread 和 Delegation 启动读取改用有序批次。Thread 加载预取元数据文本,并保留备份恢复、无效数据隔离和 abandoned provisional Thread 清理逻辑。
启动行为验证与文档
packages/mapping-store/test/startup-reads.test.ts, docs/architecture/harness-plugin-runtime.md
测试验证并发上限、线程顺序、读取失败时的锁行为及重新初始化。架构文档说明批次读取和失败清理顺序。

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Possibly related issues

  • BytePioneer-AI/codex-host#595:该 issue 描述的启动期串行读取问题与本次改动相关。本次改动将部分启动读取改为最多 8 项的有序批次,但未实现按需加载归档记录或改用 SQLite。

Suggested reviewers: bytepioneer-ai, rafazafar

Merge Risk: Minimal · up to c381e

Mapping Store startup reads are now batched up to eight at a time, with recovery order and lock behavior preserved. Failures are drained before cleanup. No merge-blocking risk was identified, and physical HDD performance remains unmeasured.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“perf(mapping-store): bound startup file reads”准确描述了主要变更:Mapping Store 启动时的文件读取改为分批并发读取,每批最多 8 项。标题与变更集、PR 目标和提交信息一致,没有无关内容。
Description check Passed 描述说明了启动读取串行导致延迟的问题、分批读取(每批最多 8 项)的方案、错误处理与锁协议的保持方式,以及测试与基准结果。该描述与变更集直接相关。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1143c82 and c381ede.

Files selected for processing: 4

  • docs/architecture/harness-plugin-runtime.md
  • packages/mapping-store/src/mapping-store.ts
  • packages/mapping-store/src/startup-reads.ts
  • packages/mapping-store/test/startup-reads.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Recent review details

Context from checks skipped due to timeout: 3

  • GitHub Check: CodeRabbit
  • GitHub Check: Static checks
  • GitHub Check: Vitest
Additional context used

Code guidelines: 2

AGENTS.md — auto-discovered
CLAUDE.md — auto-discovered
Path-based instructions: 1

Source excerpt: `codexhost` runs external Agent Harnesses as independent Threads inside Codex Desktop, preserving the official shell and native Codex path.

CodeRabbit inference engine (AGENTS.md)

Files:

  • docs/architecture/harness-plugin-runtime.md
  • packages/mapping-store/src/mapping-store.ts
  • packages/mapping-store/src/startup-reads.ts
  • packages/mapping-store/test/startup-reads.test.ts
ast-grep (0.51.3)

packages/mapping-store/test/startup-reads.test.ts

[warning] 26-26: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.readFile(file, options)
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename-typescript)

@iruriQ
iruriQ merged commit 7e36414 into BytePioneer-AI:main Nov 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants