fix(harmonyos): clamp the open foreground probe's hdc read to the request deadline

Merged
ST
2d ago
+530-16

Summary

Follow-up to #4860 (answered yes): the pre-dispatch already-foreground probe read the device on a fixed 15s hdc timeout, so a hung aa dump -l could hold the dispatch past the request deadline the #4293 poll already respects. readForegroundBundle now receives the request deadline beside the signal, and the probe clamps its read to the remaining budget (Math.min against 15s); a spent deadline skips the device. A deadline or cancel mid-read keeps the advisory outcome: the probe claims nothing, no new error code or CLI change. The post-open poll is untouched.

Before / after

open <bundle>, 2s of request budget left, hung foreground read (unit test, fake timers):

before: dispatch delayed ~15s — the probe held its fixed 15s timeout past the request deadline
after:  probe gives up at the 2s clamp and stops holding the dispatch at the deadline

The clamp test pins the read timeout at 2000ms under a +2s deadline (15000 far); a spent deadline reads nothing.

Validation

  • Targeted vitest: platform-harmonyos 141, contracts 807, daemon sessions 1272; integration node 153. pnpm tsc -b and pnpm format zero-diff; reason tables unchanged.
  • check:affected stops at the local layering gate; detach control at base ecb2089867 gives byte-identical violation lists at the polish head — zero PR-introduced violations.
  • Live on the JDY-AL50 via node bin/agent-device.mjs after pnpm build + pnpm clean:daemon (doc docs/evidence/harmonyos-open-probe-clamp-2026-11-24.md): the already-foreground open warned alreadyForeground in 0.84 s; at the polish head 9e23b8a13, replay --timeout 3000 against an hdc wrapper hanging on aa dump -l cut the probe's read at +3.29 s (2.23 s lived, not 15 s), dispatched without waiting, settled daemon_request_timeout/3000, no alreadyForeground claim (wall 3.68 s). An unlocked-screen re-record awaits the next device unlock.

Refs #4860


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.