Skip to content

fix(daemon): bind runtime hints from one app resolution and clear replaced ones - #5029

Merged
thymikee merged 5 commits into
callstack:mainfrom
imranbarbhuiya:fix/runtime-hints-followups
Nov 23, 2026
Merged

thymikee merged 5 commits into
callstack:mainfrom
imranbarbhuiya:fix/runtime-hints-followups

Conversation

@imranbarbhuiya

@imranbarbhuiya imranbarbhuiya commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #5010, from its review notes.

  • The session and the runtime-hint binding take one app id: the id the open resolved before the launch, else the id the launch reports. Every platform reports the resolved id back when there is one; Android reports the app it saw for a target without one, such as a deep link with no current app. A later open compares that same id, so a reopen, a deep link, or a targetless open keeps the hints.
  • After a successful open that applies hints to another app, only that app keeps native hints: the open removes them from the app an earlier open applied them to. Before, that app kept them and close or runtime clear cleared only the new app. A failed launch leaves them in place. A failed removal is a warning in the open result, not a failed open. Reopening the same app writes over them.
  • SessionStore.getRuntimeHints returns the hints with their app; getStoredRuntimeHints is gone.

Before / after

iPhone 17 Pro simulator, then simctl spawn <udid> defaults read com.apple.mobilesafari RCT_jsLocation:

$ agent-device open com.apple.mobilesafari --metro-port 8082   # base and head: 127.0.0.1:8082
$ agent-device open com.apple.Maps --metro-port 8083            # also with --metro-port 8082
base aecafaf30: com.apple.mobilesafari RCT_jsLocation -> 127.0.0.1:8082
head a666d77c1: com.apple.mobilesafari RCT_jsLocation -> Could not find key 'RCT_jsLocation'
$ agent-device close
base aecafaf30: com.apple.mobilesafari RCT_jsLocation -> 127.0.0.1:8082
head a666d77c1: com.apple.mobilesafari RCT_jsLocation -> Could not find key 'RCT_jsLocation'

Validation

  • Head a666d77c1, check:affected --run --head, exactCommit: true: format, lint, typecheck, layering, fallow, build and vitest-related pass. check:command-docs, check:doc-links and check:doc-prose pass.
  • New cases in session-open-runtime.test.ts cover each rule above, and a mutant of each new guard fails one of them.

… accessor

SessionStore had getRuntimeHints for the hints and getStoredRuntimeHints for
the same map entry with its bound app. getRuntimeHints now returns the stored
entry, and callers that need only the hints read its hints field.
An open bound stored hints to the app id its launch outcome reported, but a
later open compares the binding with the id it resolves for its target
before the launch. When the two differed for the same target, a reopen of
the app the hints were applied to opened it without them.

The binding now uses the id the open resolved before the launch, the same id
the hints were applied to and the one a later open compares.
…d to

An open with new transport hints for another app stored the new hints for
that app and rebound them, but left the old hints written in the app they
had been applied to. Nothing cleared them later: close and runtime clear
target the app the stored hints are bound to.

When an open replaces hints bound to another app, it now clears them from
that app before it applies the new ones, through the open plan that admits
both the apply and the clear operation. Reopening the same app with new
hints writes over the old ones without a clear, and hints that no open
applied are not cleared. The open plan carries the stored hints with their
app as one value.
… they change

Three gaps in how an open rebinds and clears stored hints:

- An open whose target resolves to no app id before the launch, such as a
  deep link with no current app, left the hints unbound, so a later open of
  another app applied them again. The binding now falls back to the app the
  launch reports.
- The clear of the previous app ran before the new app's launch. When the
  apply or the launch failed, the previous app lost its hints while the
  session still bound them to it. The clear now runs after the launch
  succeeds, before the binding moves. An open without transport hints still
  clears before its launch.
- A connection that attaches the same runtime hints to every request made
  each app switch clear the previous app. Identical transport hints leave
  nothing stale there, so only different hints clear it.
@thymikee

Copy link
Copy Markdown
Member

Thanks for the fix. The code at c083dc7 is ready to merge, and the required evidence is in place. The only non-passing checks are two superseded runs of the PR-body lint, both cancelled, and they do not touch the daemon code in this diff. The other 16 checks pass, and there are no conflicts. Not blocking, and each can be taken or left: (1) with open A --metro-port 8081 then open B --metro-port 8081, replacedAppliedRuntimeTransport returns nothing because the values match, so A keeps its native hints with no binding left to clear them; the rule could be that after a successful open only the bound app holds native hints, clearing the previous hints whenever the app id changes, which would also let sameRuntimeTransportHintValues go (https://github.com/callstack/agent-device/blob/c083dc7/packages/daemon/src/sessions/session-runtime.ts#L387); (2) session.appBundleId still takes the reported id while the binding takes the prepared id, so a later deep-link or targetless open can compare two different resolutions and drop the hints; which platform or provider reports a different id, and if none does, could one id feed both (https://github.com/callstack/agent-device/blob/c083dc7/packages/daemon/src/sessions/session-lifecycle/internal/session-open-execution.ts#L361); (3) the awaited clear of the replaced app runs after the launch succeeded, so a throw there (for example the Android prefs write) fails an open that already worked; close treats the same clear as best-effort, and the open could do the same and report a warning (https://github.com/callstack/agent-device/blob/c083dc7/packages/daemon/src/sessions/session-lifecycle/internal/session-open-execution.ts#L378). Not verified here: the tests and the live iOS simulator run were not executed, and not every provider's openApplication outcome was traced, so a remote Android route that reports a different id could make note 2 reachable.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 23, 2026
… them to

- After a successful open that applies hints to another app, the open now
  clears the previously bound app whatever the values are. Identical hints
  left that app holding native hints with no binding left to clear them.
- The session and the hint binding now take one app id: the prepared id,
  else the id the launch reports. Every platform reports the prepared id
  back when there is one, and Android fills one in only for a target
  without it. A later deep-link or targetless open resolves from the
  session id, so it now compares the same id the binding holds.
- A failed removal from the replaced app no longer fails an open that
  already launched. The open reports it as a warning and binds the new
  hints.
@imranbarbhuiya

Copy link
Copy Markdown
Contributor Author
  • Done in a666d77: after a successful open that applies hints to another app, the open clears the previously bound app whatever the values are, and sameRuntimeTransportHintValues is gone.
  • Done in a666d77: no platform reports a different id when the open has a prepared one. Apple, the direct lifecycle (Linux, Vega, web, TV, WebDriver, Revyl) and HarmonyOS return input.appBundleId, Limrun returns it after its alias mapping (already applied when the target was resolved), and Android's inferOpenedAppBundleId returns the prepared id first, inferring only without one. So the session and the binding now take one id, prepared else reported.
  • Done in a666d77: a failed removal from the replaced app is now a warning in the open result, and the open still binds the new hints.

@thymikee thymikee removed the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 23, 2026
@thymikee

Copy link
Copy Markdown
Member

Thanks for the quick follow-up. The new commit a666d77 closes the three earlier notes, keeps one app resolution per binding, and leaves no stale runtime hint unreported when an app is replaced. CI is green at this commit (15 checks, none failing), and no conflicts are known. Not verified here: tests and the live iOS simulator run were not re-executed for this delta, but the earlier live evidence still applies because the change only adjusts when the already-validated native clear runs and makes it best-effort. This is ready for maintainer review.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 23, 2026
@thymikee
thymikee merged commit 49d3af4 into callstack:main Nov 23, 2026
15 checks passed
@imranbarbhuiya
imranbarbhuiya deleted the fix/runtime-hints-followups branch November 23, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants