Repository navigation
feat(harmonyos): verify foreground after open instead of trusting the launch line - #4293
Conversation
There was a problem hiding this comment.
1 issue found across 14 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/platform-harmonyos/src/runtime.test.ts">
<violation number="1" location="packages/platform-harmonyos/src/runtime.test.ts:454">
P3: This test leaves Vitest fake timers installed after it finishes. Restore real timers in cleanup (as `packages/platform-harmonyos/src/__tests__/app-lifecycle.test.ts` does), otherwise teardown or any additional tests in this worker can observe mocked `Date` and timer APIs.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
|
Thanks for this. At 45a07a8 the change needs a live HarmonyOS run before it can merge, and two open review threads still need fixes. All 13 checks pass, but no CI lane runs a HarmonyOS device or HDC, so green CI proves only the mocked unit tests and gates. No conflicts. This changes the HarmonyOS open lifecycle on a real device, and the PR has no live run (app-lifecycle.ts#L287). The whole fix assumes that on a locked screen On the open threads: the P1 thread on a failed read becoming "not foreground" still stands (#4293 (comment), any hdc failure becomes unconfirmed). The P2 thread on the 5s budget still stands (#4293 (comment), worst case about 10.5s). So do the test helper thread (#4293 (comment)) and the fake-timers thread (#4293 (comment)). The thread on inherited-app reopen (#4293 (comment)) does not apply today: that path fails at Could one typed verdict replace the boolean that is only ever false? For example Not blocking, and fine to take or leave: pollHarmonyOpenForeground compares the bundle only with the first FOREGROUND mission, so split-screen or floating windows on tablets and foldables could report unconfirmed (confirm when any FOREGROUND mission names the bundle, and include a multi-window dump in the run or call it out of scope); openNotForegroundWarning in session-open-execution.ts hard-codes 'HarmonyOS' and the leaf's 5s budget in daemon text; OpenForegroundVerification.confirmed in application-lifecycle-runtime.ts is never true, and the daemon test helper has an unused onOpenApplication parameter; readHarmonyForegroundMission repeats the read in readHarmonyAppState, differing only in timeout and in returning undefined; and the PR body says 10 files (the diff has 14), spells the reason open_not_foreground (the code uses open-not-foreground), links no issue, and lists no device run or open risk. I could not check what Before merge, please post the live run at 45a07a8, then fix the probe-failure and budget threads. |
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="docs/evidence/harmonyos-open-foreground-2026-11-08.md">
<violation number="1" location="docs/evidence/harmonyos-open-foreground-2026-11-08.md:60">
P3: This evidence record misstates the validation result: `app-lifecycle.test.ts` contains 24 tests, not 89. Replace the count with the actual number or record the command and suite that produced 89 so the live-run evidence remains independently verifiable.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
|
Evidence committed to the branch: 🤖 Generated with Claude Code |
|
I reviewed 99e4622 against the earlier findings, and one evidence gap from that review is still open. All 13 checks pass, but no CI lane runs a HarmonyOS device or HDC, so green covers only mocked tests and gates, not the changed device route. I did not run the tests, and I had no HarmonyOS device. I judged the tests by reading the diff and test bodies. The evidence file still records only the unlocked positive route: an elided The rule the code must satisfy is that On the open inline threads: the comments on all-failed probe reads becoming Before merge, please commit the locked plain, locked |
|
This branch now conflicts with main. Please rebase and address the outstanding review findings in the same push. I will review the updated head. |
99e4622 to
70bfed4
Compare
|
Rebased onto current main (the commands.md conflict keeps main's close/relaunch notes beside this branch's HarmonyOS open line), and all three outstanding findings are fixed at 70bfed4. A failed probe is no longer a backgrounded verdict (r4497023199). The poll tracks whether any read parsed a foreground mission at all: each read is bounded by the budget's remainder (both the --foreground contract pinned (r4497023212). The route test passes Budget overrun (r4497023234). The remaining-time check now runs before each read, and both the read timeout and the sleep clamp to that remainder. The thread on URL positionals is resolved as you marked it. 122 platform and 230 lifecycle tests, typecheck, lint, and fallow pass at the pushed head. |
|
I reviewed 70bfed4 after the earlier conflict notice (#4293 (comment)). A failed foreground read no longer reports open-not-foreground, and the poll now clamps each read and sleep to the 5s budget. The new classification has one wrong case, and the help and live evidence do not match it yet. All 16 checks pass at this commit, and there are no conflicts. A successful The new reason The only live run in the evidence record is the confirmed path, and it predates this change. Once the classification is fixed, please attach a live HarmonyOS run at the PR head. With the keyguard up, plain Not blocking, and fine to take or leave: the Could one fact simplify this? The platform owner could return only when unconfirmed On the open threads: the Before merge, the lock-screen classification needs the fix above, then the help and docs need both reasons, and then the live keyguard run needs attaching. |
|
This branch now conflicts with main at 70bfed4. Please rebase onto main and push along with the fixes from the earlier review, and I will re-check the new head. |
70bfed4 to
531eb2e
Compare
|
Rebased onto main (head 531eb2e, MERGEABLE) with the one-fact redesign adopted. The classification fix. Both reasons on every surface. The flag input description, the client-app.ts JSDoc (still pinned verbatim by the option-field test), the open cliDetail, and commands.md all name Budget. Naming the second reason on the input description could not fit: main's own drift through #4513/#4581/#4586 left the 22 KiB line with 30 bytes of headroom and the compact clause costs ~180. The commit raises the budget to 22.5 KiB with that accounting in place — happy to compress further if you would rather hold the line. The changeset is deleted — main removed changesets (#4587), so the rebase had resurrected the file against a dead convention. Live runs at the head (JDY-AL50, HarmonyOS 7.0, serial 77TYD26826028730; all in the evidence doc):
Two of your lower-priority threads fixed (useFakeTimers restore, the stale 89-tests line); all unresolved threads on the PR are now resolved or addressed. One note for the next local gate runner: |
531eb2e to
b2d7476
Compare
|
The earlier conflict is gone, and the open-foreground logic looks right in code at 531eb2e. A failed read now reports probe-failed instead of open-not-foreground, and the One thing is still missing before merge. The evidence record covers the confirmed path and the failed-probe path, but no open at this head reached the no-foreground branch (evidence record, line 44). In that run, Not blocking, take or leave: pollHarmonyOpenForeground should not outlive the request deadline, so pass On the open threads: the higher-priority threads on probe-failed classification, Two open questions: whether |
The interaction backend's capture wrapper returned a bare path, so the lane compared the full frame on every daemon press and click: a clock or battery redraw read as a landed tap, with no warning, exactly what the outside-the-status-bar wording promises not to do. The wrapper now returns the owner's facts beside the path, and the daemon-route pair that differs only inside a declared band pins it red-on-bare-path. The abort check honors the runtime signal, a TV or landscape Android frame declares no band, the always-loaded budget takes the same 22.5 KiB ratchet as callstack#4293 to hold the restored multi-ref and readback guidance, and the stray scratch files go away. Co-Authored-By: Claude Code <noreply@anthropic.com>
|
Both take-or-leave items taken at head dcfa84d (MERGEABLE, full suite green): The poll never outlives the request. The keyguard run: the device went offline between sessions — The budget: the 22.5 KiB raise stays a maintainer call. The accounting is in that commit — main's drift through #4513/#4581/#4586 left the 22 KiB line with 30 bytes of headroom, and the two-reason requirement on the |
|
Thanks for the update. The probe-failed split, the deep-link target check, the per-read budget and the spent-deadline handling at dcfa84d fix the code findings from the earlier review. One item is still open, and CI is green (16 checks, 0 failing). There are no conflicts. The no-foreground branch (lock screen) is the main reason for this PR, and it still has no live device run. The poll path at app-lifecycle.ts:300-305 and :312 is proven only by mocked Not blocking: when the request deadline clamps the budget below 5s, the The raise of ALWAYS_LOADED_BUDGET_BYTES to 22.5 KiB is outside this delta and remains a maintainer call. Of the earlier review threads, all six no longer apply at dcfa84d, so please resolve them: probe-failed vs no-foreground (fixed, sawReadable is set only by answered reads), hard-failure test coverage (covered in the foreground-verification and app-lifecycle tests), deep-link targets (skipped at app-lifecycle.ts:362-363), read budget (each read is bounded and the deadline is clamped), fake timers (restored, file untouched by the delta), and stale test count (corrected in the evidence record). Before merge, the live secure-keyguard run at dcfa84d must reach open-not-foreground, with the |
|
Taken at head 0ecbbef (MERGEABLE): a clamped poll now reports "before the request deadline" instead of "within 5s" in both |
|
One follow-up push: the deadline clamp pushed |
|
Thanks for the update. At 6568e6e the code still has one defect that sends agents the wrong hint on a flaky device, and the live evidence for the lock-screen case is still missing. There are no conflicts, and all 16 checks pass at this commit, but CI cannot see the defect because no test sets a far deadline.
The only deadline test in app-lifecycle.test.ts uses a spent deadline. Every other test leaves The evidence record is unchanged since dcfa84d, still has no live run that reaches the no-foreground branch, and does not cite this commit. The lock-screen case is the reason for this PR, and today only mocked The fixed predicate with a far-deadline regression test is the next change needed. Then the secure-keyguard run at that head is what remains before merge. |
|
The code fix from the earlier review is in at f0c0d44, but one piece of live evidence is still missing. No live run reaches the no-foreground branch yet. The keyguard re-attempt in the evidence doc again had Not blocking: when The delta touches only platform-harmonyos and the evidence doc, and the one check still running (Smoke Tests ios) looks unrelated to it. There are no conflicts. The remaining step before merge is the live keyguard run above. |
|
The simplification is taken at 8c2195d: the builder reads only |
|
The changes since f0c0d44 look good in 8c2195d, and the earlier evidence request is still open. CI is green: all 13 checks pass at this head, and there are no conflicts. The live evidence in harmonyos-open-foreground-2026-11-08.md still never reaches the no-foreground branch. On every keyguard attempt, Not blocking, take or leave: the computed window on the probe-failed branch in app-lifecycle.ts has no test for a budget under 5000ms with every read failing, so a revert to a literal "5s" would still pass; one case with a deadline about 2s out that asserts /within 2s/ would cover it, and Math.max(1, …) rounds a sub-second budget like 300ms up to "within 1s". The next step before merge is that live secure-keyguard run. The six earlier review threads were already resolved, so none are open. |
|
Taken — the pin is at e45b605: a deadline about 2s out with every read failing asserts The secure-keyguard live run remains the one open item. Both re-attempts on my unit woke past the lock: shell |
|
Thanks for the update. The new tests and evidence doc since 8c2195d are in, and all 13 checks pass at e45b605. One piece of evidence is still missing, so the open-not-foreground path is not yet shown on a real device. The new run does not reach the no-foreground branch. The open-not-foreground warning on plain open (app-lifecycle.ts:377) and the open-not-foreground reason on Please record a run at e45b605 or later on a HarmonyOS device with a secure (PIN) keyguard that There are no conflicts. Once the keyguard run is recorded, I expect this to be ready to merge. |
|
The mission-less keyguard shape you named is pinned at 0d7d510: a dump that answers with content but no The maintainer-run protocol stands as you quoted it, at 0d7d510 or later; on my unit the mission list still shows through the lock (12 missions, zero |
|
One correction to the shape rule at 5aaf15a: the classifier reads the dump's own structure, not any non-empty output. A dump that answers with its section headers ( |
… dispatches `aa start` reports an accepted launch, not a visible app, so an open under a lock screen succeeded beside an invisible app and only a later snapshot told the truth. HarmonyOS now polls its foreground read for up to 5s after the dispatch. A launch that never surfaced carries a typed `timing.foregroundVerification` fact and the open warns `open-not-foreground` with the app that held the foreground; `open --foreground` fails with `details.reason: open-not-foreground` instead. Co-Authored-By: Claude Code <noreply@anthropic.com>
Review follow-ups on the foreground verification. The versioned help now states the HarmonyOS side of `--foreground` beside its iOS snapshot semantics, in the flag declaration and in the open command detail that owns the open reasons. The open-not-foreground warning reads as a sentence for both its holder and unreadable-foreground arms, and the patch carries a changeset. Co-Authored-By: Claude Code <noreply@anthropic.com>
…ion list Co-Authored-By: Claude Code <noreply@anthropic.com>
…stayed backgrounded The poll bounds each read by the budget's remainder, tracks whether any read parsed a foreground mission at all, and marks a budget with zero parseable reads as an unreadable probe. The verify carries that as its own typed reason (open-foreground-probe-unreadable) instead of open-not-foreground, the daemon warning says the read claims nothing about the foreground, and the route tests pin the --foreground hard failure and the unreadable warning. Co-Authored-By: Claude Code <noreply@anthropic.com>
OpenForegroundVerification becomes the one fact the poll returns: a discriminated state instead of confirmed-plus-modifiers. A read that answered with no FOREGROUND mission is the lock-screen shape and now reports open-not-foreground (unlock) instead of claiming the probe was unreadable; probe-failed is reserved for budgets whose every read failed to run. The parse owner returns the three-way read, both reasons are stated on every help surface, and the changeset goes away with main's changeset removal. Co-Authored-By: Claude Code <noreply@anthropic.com>
…size The stubbed-hdc run reproduces the maintainer's offered second live case: only the poll's aa dump reads fail, and the plain open carries the open-foreground-probe-unreadable warning while --foreground fails with that reason. The keyguard shape of the mission list is observed live, but this unit's shell launches wake past the suspended screen, so the end-to-end no-foreground open stays maintainer-runnable. The 89-tests line becomes the real count. Co-Authored-By: Claude Code <noreply@anthropic.com>
The poll never outlives the request: the smaller of the 5s budget and the request deadline's remaining room wins, and a deadline already spent answers probe-failed without one read. The stale Android close bullet the rebase left in commands.md goes too. Co-Authored-By: Claude Code <noreply@anthropic.com>
A clamped poll reports before-the-request-deadline instead of within 5s, and a budget the deadline already spent points at the tight deadline rather than the device connection. Co-Authored-By: Claude Code <noreply@anthropic.com>
…re builder The deadline clamp pushed the verify over the complexity threshold; the --foreground throw path moves to one builder that carries both reasons and their deadline-aware windows. Co-Authored-By: Claude Code <noreply@anthropic.com>
Every production open carries a deadline, so presence was never the clamp: the predicate reads the computed budget instead, the deadline hint fires only when no read had room to run, and a partly clamped poll says deadline while a full-budget poll keeps within 5s and the connection hint. The far-deadline and partly-clamped cases pin both. Co-Authored-By: Claude Code <noreply@anthropic.com>
…be at d295556 Co-Authored-By: Claude Code <noreply@anthropic.com>
The builder takes only the budget: the clamp reads from the budget, the nonzero probe-failed window names the seconds the poll actually had, and the deadline hint fires only at zero. Co-Authored-By: Claude Code <noreply@anthropic.com>
…vert A deadline about 2s out with every read failing bounds the poll below the 5s default. The probe failure names the 2s the poll had and keeps the connection hint, so a revert to a literal "5s" fails the suite. Co-Authored-By: Claude Code <noreply@anthropic.com>
A dump that answers with content but no Mission ID block is the lock-screen shape on units whose keyguard hides the mission list. It now classifies as no-foreground-mission, so a locked unit carries the unlock hint instead of the connection hint; an empty answer stays unreadable. Co-Authored-By: Claude Code <noreply@anthropic.com>
The mission-less shape reads the dump's own section headers, not any non-empty output: "aa: error: dump failed" stays unparseable, and only a headered answer names the lock screen. The parser cases live in the app-state suite; the poll-level read keeps the no-foreground pin. Co-Authored-By: Claude Code <noreply@anthropic.com>
The wider-shape paragraph referenced a protocol only the review thread carried. The doc now owns it: the three recorded outputs and the fix-the-parser-in-the-same-push rule. Co-Authored-By: Claude Code <noreply@anthropic.com>
Main pairs the open's transport hints with their apply operation, so the input's runtimeHints is no longer a bare values record. The two open fixtures carry the values-plus-apply shape. Co-Authored-By: Claude Code <noreply@anthropic.com>
…-foreground Co-Authored-By: Claude Code <noreply@anthropic.com>
…head Co-Authored-By: Claude Code <noreply@anthropic.com>
1df833a to
90d7417
Compare
|
Rebased onto current main (17 commits, one conflict resolved in the app-lifecycle imports against the R6b ReasonTable refactor) and the secure-keyguard protocol ran live at fbbe9fa:
Co-Authored-By: Claude Code noreply@anthropic.com |
Co-Authored-By: Claude Code <noreply@anthropic.com>
|
Thanks for the fixes. This PR is ready at 57ecf0c: the three problems from the earlier review (#4293 (comment)) are closed. All 16 checks pass at this head, and there are no conflicts. Not blocking, and fine to take or leave: a plain open can now fail on HarmonyOS with details.reason open-not-foreground when a secure keyguard makes aa refuse the launch (https://github.com/callstack/agent-device/blob/57ecf0c/website/docs/docs/commands.md#L241), but the commands.md text, the open help and the daemon warning still say an unconfirmed plain open succeeds with a warning, so one clause saying a launch refused because the screen is locked fails on both routes with that reason would match the code. Not verified here: the secure-keyguard run, which relies on the recorded device output at fbbe9fa; local tests and typecheck, where CI is green; and Error Code:10106102 on stderr, since it is matched on stdout only and falls back to the base 'Failed to start' error on builds that print it elsewhere. |
…asons * origin/main: refactor(types): drop branches and assertions the types already exclude (#4975) refactor(reasons): declare the durable capture outcomes in ReasonTable rows (#4978) feat(harmonyos): verify foreground after open instead of trusting the launch line (#4293) fix(remote): give each session its own saved-connection file (#4925) # Conflicts: # packages/kernel/src/errors.ts # src/platform-runtime-gateway.ts
…ures * origin/main: refactor(types): drop branches and assertions the types already exclude (#4975) refactor(reasons): declare the durable capture outcomes in ReasonTable rows (#4978) feat(harmonyos): verify foreground after open instead of trusting the launch line (#4293) fix(remote): give each session its own saved-connection file (#4925)
|
Took the docs clause: the open help (command-surface app.ts) and the hand-written commands.md bullet now say a secure keyguard can make the launch itself refuse, and the open then fails with details.reason open-not-foreground and the unlock hint on the plain route too (ffa908c). The generated blocks stay in sync with the help source; command-surface 290 tests pass and the prose gate is clean. On the stderr note: on the JDY-AL50 build that produced the evidence, aa printed the refusal text on stdout — the classification fired live against the real keyguard, and details.output in the recorded run carries that stdout. Matching stays on stdout; if another build prints it elsewhere, the fallback keeps the base Failed to start error with the raw output in details. Co-Authored-By: Claude Code noreply@anthropic.com |
…uest deadline (#5055) * fix(harmonyos): clamp the open foreground probe's hdc read to the request deadline The pre-dispatch already-foreground probe ran one `aa dump -l` read on a fixed 15s timeout, so a hung read could hold the dispatch past a request deadline the post-open foreground poll (#4293) would have respected. The probe now receives the request's deadline beside the signal, clamps its read to the remaining budget (Math.min against the 15s default), skips the device entirely when a spent deadline leaves no room for one read, and still claims nothing when the deadline or a cancel cuts the read — the advisory outcome machinery is unchanged and no reason set grows. Follow-up to the optional question the #4860 review left open. * test: retrigger the android emulator smoke lane (no code change) * docs(evidence): record the JDY-AL50 live runs for the open probe deadline clamp Scenario a: the already-foreground open answers with the alreadyForeground warning at 0.7 s with no added probe latency. Scenario b: an hdc wrapper that sleeps on the probe read cannot hold the dispatch past the admitted request budget — the probe read dies at its 15 s clamp, the poll read at its 5 s budget, and the open returns with the advisory unreadable warning and no alreadyForeground claim. The 2-3 s remaining-deadline variant is not expressible on the shipped CLI (open's result budget is a fixed 60 s floor and the pre-probe route spends at most ~10 s), so the clamp below 15 s stays pinned by the unit suite; the live run is the wiring half of that proof. Refs #5055 * docs(evidence): run the 2-3s deadline replay variant live on the JDY-AL50 * docs(evidence): format the part-b replay JSON artifacts * refactor(harmonyos): take the review polish on the open probe clamp Three take-or-leave items from the #5055 review. The open lifecycle binds readForegroundBundle as DirectApplicationLifecycleParams' own shape, so the contract owns the type. The remaining-read-budget clamp arithmetic (Math.min against a read's default, floored at 0, spent deadline answers 0) moves to one helper beside hdc.ts that both the open-time probe and the post-open poll budget call. The probe's doc comment now says the clamp bounds the read, not the dispatch it precedes. Follow-up to the optional question the #4860 review left open. Co-Authored-By: Claude Code <noreply@anthropic.com> * docs(evidence): re-run the deadline replay leg at the polish head 9e23b8a Same replay route on the JDY-AL50 at the review-polish code SHA, screen PIN-locked: the probe's aa dump -l read lived 2.23s under a 3s replay deadline (cut at +3.29s, not 25s wrapper, not 15s default), the aa start dispatch followed without waiting on the hung read, and the request settled daemon_request_timeout with no alreadyForeground claim. Names the observed hdc resolution mechanism: the daemon prefers its toolchain roots over PATH, so the wrapper rides HDC_SDK_PATH. Co-Authored-By: Claude Code <noreply@anthropic.com> * docs(evidence): fix the two review notes on the evidence artifacts Cite the evidence commits that exist in this PR's history instead of the unreferenced 66e129b, and scrub the local absolute paths from the committed replay JSON artifacts (repo-relative script paths, placeholder state dir). Co-Authored-By: Claude Code <noreply@anthropic.com> --------- Co-authored-by: strzhao <strzhao@users.noreply.github.com> Co-authored-by: Claude Code <noreply@anthropic.com>
Summary
On HarmonyOS,
openreported success off thestart ability successfullystdout line alone — on a screen where the app never reached the foreground the report said Opened.openHarmonyAppnow polls the mission list live after the dispatch: a plain open carries the no-foreground warning,--foregroundescalates it to a typed failure, and an unreadable probe carries the probe reason instead of passing silently. On a secure PIN keyguard,aa startrefuses the launch outright (Error Code:10106102); the refusal is classified as the typedopen-not-foregroundfailure with the unlock hint, so a locked screen never reports a confirmed open on either route.Before / after
Base, a plain open on a screen where the app does not reach the foreground:
Head, same dispatch:
Base, a secure-keyguard screen (raw aa text, no reason, no hint):
Head, same screen:
Validation
fbbe9fa81on JDY-AL50 (HarmonyOS 7.0): the three protocol outputs and the device-side aa answer are recorded indocs/evidence/harmonyos-open-foreground-2026-11-08.md(section "The secure keyguard, live at head fbbe9fa"). The unit stays locked; restoration is manual.pnpm vitest run app-lifecycle --project unit-coreat headfbbe9fa81: 90 passed, including the locked-screen classification test.🤖 Generated with Claude Code