Skip to content

fix(emulator): isolate attempt diagnoses and honor software boot budgets - #119

Open
dwgx wants to merge 3 commits into
RoutineMiku:mainfrom
dwgx:fix/attempt-diagnosis-and-tcg-budget
Open

dwgx wants to merge 3 commits into
RoutineMiku:mainfrom
dwgx:fix/attempt-diagnosis-and-tcg-budget

Conversation

@dwgx

@dwgx dwgx commented Nov 21, 2026

Copy link
Copy Markdown

Problem

A failed emulator attempt can leave lastDiagnosis set for the next attempt. If the next process exits after startup settling, its fatal path can reuse the previous UNKNOWN or crash classification even when the current log identifies a different failure.

Software emulation can also inherit the hardware startup budget. The two accel=off fallback plans inherited 240 seconds, and a driver applying forceTcg changed the effective acceleration without updating that budget. A simulated boot ready at 300 seconds therefore timed out despite the existing 600-second software-emulation policy.

Changes

  • Reset the transient diagnosis at the start of each attempt. Preserve attempt history and diagnoses produced later within the same attempt.
  • Use a shared budget calculation based on the final effective accel, including driver-forced TCG. Software emulation receives at least 600 seconds; hardware defaults stay at 240 seconds, and an existing longer budget is preserved.
  • Keep process-exit and fatal-result handling immediate. Retry ordering, retry counts, wipe and snapshot policies are unchanged.
  • Add focused behavior tests and install process guards before loading application modules. GPU discovery and successful-boot network checks use fixtures; unmatched process calls are recorded and rejected, including calls whose exceptions the application catches.

Validation

Reviewed head: 519acfc98e886e3fed370dbdacbf50021f251687.

  • Windows / Node v24.19.0: node test/attempt-diagnosis-budget-test.js passed 10/10, native exit 0, in an independent detached checkout of this head. Coverage includes attempt history, same-attempt fatal diagnoses, budget preservation, simulated 300-second readiness, 10-second exits and the isolation negative control.
  • A frozen independent probe exercised the actual Runtime.ensure through EmulatorEngine.start, including process settling and the exit callback. Baseline a4d4a23cdd20d8943703ae172a0c8734ca23b097 passed 15/17 checks, failing the two intended diagnosis assertions; product candidate 9abeb9e676f2dca27cbf97724529b6f2a6b32f5d passed 17/17, native exit 0.
  • The independent Runtime result is reused from 9abeb9e, not rerun on 519acfc. The latter changes only the test file; the reviewed product code is byte-identical.
  • Fork CI, exact reviewed head: run 44885894583 passed on Windows / Node 20 and 22, including the full configured test command, the focused 10/10 suite on both jobs, and the pointer-hook smoke step. The optional APK fixture test explicitly skipped because no APK was supplied; this is not an Android end-to-end result or upstream workflow approval.

Scope

These checks use a virtual clock and synthetic emulator processes. External GPU discovery, ADB and network interactions use fixtures or are blocked. The focused suite uses private TEMP files; the independent Runtime probe uses an in-memory target filesystem.

The underlying user-reported crash in #60 remains unresolved by this change. This PR improves diagnosis accuracy and startup-budget consistency; it does not establish real Android boot success or hardware compatibility. No issue is automatically closed, and no user-data reset or wipe behavior is added.

dwgx added 3 commits November 21, 2026 17:03
- 每轮 attempt 开始时同时重置 lastExitCode 与 lastDiagnosis,上一轮的 UNKNOWN/崩溃分类不再短路本轮日志。
- 本轮等待循环里写入的 45 秒提前诊断仍优先用于 fatal 结论。
- 新增 attempt-diagnosis-budget-test.js:假时钟 + 假进程 + 依赖桩走真实 start() 决策路径;基线 RED → 修复后 GREEN。
- 不改变重试次数、GPU 策略与用户数据逻辑。
- doctor: BOOT_TIMEOUT_MS 单点定义(auto 240000 / off 600000)与 bootTimeoutFor(plan)。
- planVariants 的两个 off 回退档按最终 accel 重算预算,原本更长的有效预算保留。
- emulator 等待循环改为 doctor.bootTimeoutFor(plan),覆盖驱动 forceTcg 把 auto 改 off 的入口。
- 测试覆盖 300 秒就绪不截止、10 秒退出立即失败、wipe=false/snapshot 原合同;接入 npm test。
- child_process 的执行入口在 require doctor/emulator 之前替换:先装桩再加载,避免解构捕获真实函数。
- GPU 发现给固定夹具;其余任何外部调用记为 blocked,并由用例包装器判失败(即使目标自己 catch)。
- Runtime 成功路径的 checkNetwork 提供 fixture 桩,不联系 PATH 上的 adb / 外部 HTTP。
- 反向控制证明被 catch 的外部调用不会被悄悄放过;测试结束恢复全局钩子与虚拟计时器。
- 收窄误导性用例名:初始 profile 即 off,不经过 auto→off 回退。产品代码不变。
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.

1 participant