Skip to content

feat: add one-click SegmentLoadError repro action#12474

Open
huhuanming wants to merge 1 commit into
xfrom
codex/segment-load-repro
Open

feat: add one-click SegmentLoadError repro action#12474
huhuanming wants to merge 1 commit into
xfrom
codex/segment-load-repro

Conversation

@huhuanming

Copy link
Copy Markdown
Contributor

Summary

  • add a Native-only Load Target Segment action to JS Bundle Manager for downloaded bundles matching the running app version
  • reuse the existing verified install flow, then load a deliberately untouched lazy segment before the scheduled 2.5-second all-runtime restart
  • surface the exact loader error in the bundle row and keep ordinary Switch behavior unchanged
  • add focused tests for the target segment loader helper

Why

This provides a deterministic harness for the SegmentLoadError activation race:

  1. the running main JS runtime keeps manifest A in its isolated JS heap
  2. installing bundle B changes the shared native current-bundle pointer
  3. the restart of main and background runtimes is scheduled 2.5 seconds later
  4. the harness immediately requests seg:components.primitives.Icon.react.brand.ArtifactNews
  5. the old runtime validates B's bytes with A's expected SHA and reports SegmentLoadError

The selected icon is lazy and is not rendered by Bundle Manager before the action, so an already-loaded segment should not short-circuit the repro.

This PR is a QA reproduction tool, not the production fix.

Runtime and resource scope

  • the action runs in the main UI JS runtime
  • the manifest is a per-runtime JS heap copy; main and background deserialize independently
  • the current bundle pointer and extracted files are shared native resources
  • main and background initialize and restart independently; reproducing this in main does not by itself prove a background-runtime occurrence

Test plan

  • open Dev Settings > JS Bundle Manager on iOS or Android
  • select the running app version and download a non-current bundle
  • tap Load Target Segment
  • expect the row to show a SegmentLoadError SHA mismatch before restart
  • verify ordinary Switch still installs and restarts without requesting the target segment

Automated checks:

  • yarn jest packages/kit/src/views/Setting/pages/DevBundleSwitcher/segmentLoadRepro.test.ts --runInBand
  • yarn agent:check --profile commit

);
}

await loadBundleAsync(SEGMENT_LOAD_REPRO_TARGET);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[🟡 P2] 段不存在时 repro 会静默成功而不复现

问题

loadTargetSegmentForRepro__loadBundleAsync 的 resolve 当作"已触发复现",但生产加载器对不在 manifest 中的 key 走的是 eager-fallback 分支(installProdBundleLoader.tsloadedSegments.add(segmentKey); segmentStates.set('ready'); ... return;)——它只打一条 warning 然后正常 resolve,不会抛错

当前 SEGMENT_LOAD_REPRO_TARGET = 'seg:components.primitives.Icon.react.brand.ArtifactNews' 的格式与 deriveSegmentKey 对该文件的推导完全一致,所以现在是对的。但它依赖 ArtifactNews 始终被分配为独立 segment root;一旦 allocator 调整、图标被并入公共/eager bundle,或 key 拼写漂移,该 key 就不再命中 manifest。

影响

此时 await loadBundleAsync(...) 会正常 resolve,UI 停留在 reproducing 后随 2.5s 重启结束,既不抛 SegmentLoadError 也无任何失败提示。QA 会误判为"无法复现/已修复",而实际上工具根本没加载到目标 segment。对一个专门用于复现 SegmentLoadError 的工具而言,这种静默 no-op 是有实际误导性的。

建议

加载后校验目标确实是一个真实 segment:例如通过加载器导出的 getSegmentState/isSegmentLoaded 判断是否命中真实 segment(区分 eager-fallback),或在调用前对照 manifest 断言 key 存在,命中 fallback 时主动抛错,避免"假成功"。

Claude session ↗


Generated by Claude Code

? `${error.name}: ${errMsg}`
: errMsg,
);
if (!isLoadingTargetSegment) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[🟡 P2] 复现成功时丢失结构化证据

问题

loadTargetSegmentForRepro() 真正抛出 SegmentLoadError(即工具达成目的的那一刻),catch 里因 isLoadingTargetSegment === true跳过 installBundleResult(success:false),且没有任何替代事件写入 defaultLogger.app.jsBundleDev。于是 app 侧结构化日志对这次复现完全无记录。

同时 installBundleindex.native.ts)在 install 成功后已 setTimeout(appRestart, 2500) 排定整机重启,该定时器不受这里 catch 影响。

影响

复现出的 SegmentLoadError 只在 error 态 UI 中短暂展示,最多约 2.5s(还要减去 install/段加载耗时)后就被整机重启抹掉;而 app 侧诊断管线里没有留下任何该错误的结构化条目(仅原生 NativeLogger 有)。对一个以"捕获 SegmentLoadError"为唯一目的的工具,证据留存窗口极短且缺失结构化记录。

建议

在 segment 复现分支为成功/失败各补一条专用 jsBundleDev 事件(含 error.name/message/segment key),确保重启前已落库;如需人工观察,也可考虑复现路径下不立即触发 2.5s 重启,或先记录再重启。

Claude session ↗


Generated by Claude Code

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