K1-S0.4: 启动与开发打包性能稳定化 (#19) - #29
Conversation
原因: 实测启动关键路径上 startViewerServer 在 createMainWindow 前 await 初始 snapshot/watcher(102 项根 64-76ms, 521 项根 152-329ms, 随根规模与 I/O 放大), 直接阻塞首窗 改动: T1: startServer 在 HTTP listener 就绪即返回, 初始存储根扫描后台完成; T2: setRoot/setConversationContext 同根时 await 在途基线(pendingWatcher), 代际守卫防旧扫描覆盖新基线, closed 守卫防关闭后泄漏定时器, 保 #23 正向武装不丢变更; T3: 新增 whenWatcherReady() 就绪句柄与 KCC_PROFILE_STARTUP 剖面埋点(仅本地诊断); T4: realtime/轮询测试显式等待基线, 新增解耦契约与同根武装回归测试 Co-Authored-By: Kimicode <noreply@kimicode.com>
原因: 实测确定性打包 total 278.5s 中 zip 阶段约 130s、npm ci 26-47s; 本地迭代不需要 zip 产物, lockfile 未变时无条件 npm ci 是纯浪费 改动: T1: -Fast 走 npm run pack -- fast 产出 dist-fast unpacked(免 zip/免测试), 冻结源 SHA/detached worktree/build-info provenance 不变, 全量 zip 仍为默认; T2: npm ci 成功后写 node_modules/.kcc-dep-stamp(package-lock SHA-256+node/npm 版本+os/arch), 指纹精确匹配才复用, -ForceInstall 强制重装, 禁止裸 node_modules 存在即复用; T3: 同步 DEVELOPMENT_PACKAGING.md 与 AGENTS.md 用法 Co-Authored-By: Kimicode <noreply@kimicode.com>
原因: #19 要求性能结论必须有真实 Windows 实测证据, baseline/根因/改动/回归需落盘可复查 改动: 记录 baseline SHA/机器工具链/启动 5 轮表/打包阶段分解/根因分类/实现项/after 对比/回归结果/拒绝的优化 Co-Authored-By: Kimicode <noreply@kimicode.com>
Architecture Review — REQUEST_CHANGES (R1)Reviewed HEAD: Accepted and not to be reworked:
R1 blocker 1 — dependency reuse must preserve npm-ci source validationCurrent dependency stamp keys reuse on Counterexample: a new develop commit changes Required narrow repair:
Do not redesign caching beyond this. R1 blocker 2 — real #23 regression gate was not executedThe PR changes Viewer startup ordering, and the delivery report explicitly states that the full fresh-Kimi-session E2E was not rerun. Taskbook acceptance requires preserving the product contract:
Mechanism/unit tests and Required real Windows smoke after the R1 code fix:
If an existing KCC instance/profile lock blocks the probe, do not kill it. STOP Process safety rule from this runThe previous probe terminated a pre-existing process tree and accidentally killed the hosting Agent session. From now on:
R1 deliveryKeep the same branch/PR. Rerun focused tests + |
原因: R0 stamp 指纹只含 package-lock.json 哈希+node/npm/os, package.json 单独漂移(lockfile 未同步)时 lock 哈希不变, 会错误复用旧 node_modules, 绕过 npm ci 的 manifest/lockfile 一致性检查 改动: T1: package-dev-lib 新增 makeDependencyFingerprint 与 dep-fingerprint CLI, 指纹=SHA-256(package.json)+SHA-256(package-lock.json)+node/npm/os-arch; T2: package-dev.ps1 install 块改用新指纹比对与写 stamp; T3: 新增 A/B/C 回归(同输入可复用/仅 package.json 变失效/lockfile 变失效)与 CLI-库一致性测试; T4: DEVELOPMENT_PACKAGING.md 同步指纹描述 Co-Authored-By: Kimicode <noreply@kimicode.com>
原因: R1 评审两个 blocker 需要落盘证据(依赖指纹缺 package.json 哈希、缺真实 #23 fresh-session E2E), 且"剩余启动时间 Electron inherent"属未证明判断需收敛 改动: T1: 报告新增 R1 章节, 含指纹修正说明/A-B-C 回归/三次真实 package-dev.ps1 -Fast smoke(旧 stamp 重装/新 stamp 复用 0.5s/ForceInstall 强制重装); T2: 落真实 fresh-session Viewer E2E 证据(session_de26fd73-27cf-4206-b57e-892c2e96d6f0, 工作期间 active tab 始终 kimi 未开 Viewer, notes.md created+modified 与 data.json created+deleted 全记录); T3: "Electron-inherent/只能 rewrite"表述收敛为"本 WP 未继续优化, 进一步拆解收益不足以证明扩大范围" Co-Authored-By: Kimicode <noreply@kimicode.com>
K1-S0.4 R1 — 两个 blocker 已处理
Changed files
Blocker 1 — dependency fingerprint新指纹形状:
真实 packaging smoke(
三次均:source ref Blocker 2 — 真实 fresh-session Viewer E2E(#23 merge gate)PASS真实 Windows 运行(2026-09-08),worktree 代码 + 全新
caveat:文件写入由 harness 直接写入 session 绑定的 root(watcher 层面与 agent 工具写入等价;session 自身 turn 为真实执行)。通过权限审批 UI 驱动 agent 工具写入可作为后续增强,非本 gate 必需。 文档
Limitations
等待 incremental Architecture Review;未 merge、未动 #20、未 dogfood。 |
K1-S0.4 — Startup & Development Package Performance Stabilization
Closes #19. Frozen taskbook:
docs/tasks/kimicode/K1-S0.4-performance-stabilization.md.Full evidence:
docs/performance/K1-S0.4-performance-report.md(in this PR).Exact refs
682a0df5e2935836e7e4bafae1883b799ca9f103(=origin/develop/kcc-1.0, verified at run start)7da49bb(3 commits, see below)Changed files
src/viewer/server.cjs— Viewer server readiness decoupled from initial watcher/snapshot;whenWatcherReady(); generation/closed guardssrc/main/main.js— opt-inKCC_PROFILE_STARTUP=1profiling marksscripts/package-dev.ps1—-Fastunpacked iteration mode;-ForceInstall; lockfile-fingerprint dependency reusetest/viewer-server.test.js,test/viewer-realtime.test.js— timing-assumption fixes + 2 new regression testsdocs/performance/K1-S0.4-performance-report.md— full evidence reportdocs/DEVELOPMENT_PACKAGING.md,AGENTS.md— usage docs syncStartup
Baseline (5 runs, in-process ms to
main-window-shown): median 708 (range 651–978); wall-to-ready median 1205.Phase breakdown (median): Electron bootstrap ~101 · config/quota/migration ~50 · Viewer listener+snapshot/watcher ~90 (64–76 ms at 102-entry root; 152–329 ms at 521-entry root) · window+shell load ~350 · shell→shown ~130.
After (5 runs): median 622 (range 524–894) → −86 ms / −12.1% median (best run −19.5%). Large stored root (521 entries/71 docs/1.24 MB): 329 ms scan now completes in background at 522 ms; shown 717 ms vs modeled-baseline ≈1040 ms → ≈−31% at that root scale. The win grows with root size and I/O load.
Confirmed startup root cause: C (window/renderer/shell creation ~68%) dominates; A (Viewer stored-root scan) was the largest controllable critical-path blocker and is removed. 20% median gate not met at small roots because baseline is already 708 ms and the remainder is Electron-inherent (shell rewrite is out of scope) — absolute savings documented per the taskbook's alternative clause.
Packaging
Baseline (
package-dev.ps1, frozen SHA): total 278.5 s (fetch 1.1 · worktree 0.8 · npm ci 25.8 · test 13.5 · pack 235.8); zip 416.3 MB.packdecomposition: staging (--dir) 179 s cold / 98 s warm; full 311 s → zip ≈ 130 s (~40–45%); unpacked 1302 MB (asar 227 MB + asarUnpack 728 MB, mostly CloudCLI runtimes @openai 410 MB + @Anthropic-AI 270 MB).Confirmed packaging root cause: staging (B) + zip compression (A) co-dominate; npm ci (D) minor.
After (same deterministic path, same worktree):
-Fast): 153.4 s stamp-reuse / 196.1 s cold-install → −45% / −30% vs baseline total; artifactdist-fast/win-unpacked(1302 MB runnable) +build-info.jsonDeterministic proof:
dist/build-info.jsonanddist-fast/build-info.jsonboth recordsourceCommit: 682a0df5e2935836e7e4bafae1883b799ca9f103; packaging worktree detached+clean at that SHA every run; dirty-guard fail-closed unchanged. Dependency reuse only vianode_modules/.kcc-dep-stamp= SHA-256(package-lock.json)+node/npm/os-arch, written solely by successfulnpm ci;-ForceInstallbypasses; no bare node_modules-exists check.Regression
npm test: 158/158 pass (156 existing + 2 new: deferred-readiness contract; same-root arm waits for deferred baseline)npm run build: pass (win-unpacked produced)whenWatcherReady()explicitlyviewer-context.logshows the arm applying the live Kimi session project and re-arming the watcher in background with the Viewer UI never opened; opening Viewer stays review-onlyLimitations / remaining bottlenecks
compression=storezip probe inconclusive (electron-builder network timeout);-Fastalready removes zip from the loop--user-data-dir) seeded with the real stored Viewer root because the default profile was held by a running instance (single-instance lock); phases measured in-process with monotonic marksDo not merge before ChatGPT Architecture Review.
Note
Medium Risk
Deferring the initial viewer snapshot changes startup ordering; correctness depends on new
pendingWatcher/ generation guards in session context paths. Packaging stamp reuse is dev-only but must stay fingerprint-accurate to avoid wrong dependencies.Overview
Addresses #19 (K1-S0.4) by shortening the startup critical path and speeding local deterministic packaging, with a full performance report in
docs/performance/K1-S0.4-performance-report.md.Startup: The Viewer server now becomes ready when the HTTP listener is up; the stored-root snapshot and file watcher run in the background via
launchWatcher(). Callers that need a baseline usewhenWatcherReady();setRoot/setConversationContextstill wait for in-flight baselines (including same-root session arm) so changes are not dropped.KCC_PROFILE_STARTUP=1adds opt-in[kcc-profile]timing marks inmain.jsand the viewer server.Packaging:
scripts/package-dev.ps1adds-Fast(unpackeddist-fast/, skips tests and zip while keeping frozen SHA, detached worktree, andbuild-info.json),-ForceInstall, and stamp-validatednode_modulesreuse (node_modules/.kcc-dep-stampkeyed on lockfile hash plus node/npm/os). Docs inAGENTS.mdandDEVELOPMENT_PACKAGING.mdare updated accordingly.Tests: Viewer tests await
whenWatcherReady()where timing matters; two new tests cover deferred HTTP readiness and same-root session arm after a deferred baseline.Reviewed by Cursor Bugbot for commit 7da49bb. Configure here.