Skip to content

refactor(limrun): ship Limrun as the @agent-device/limrun plugin - #4846

Merged
thymikee merged 29 commits into
0.22from
refactor/0.22-limrun-provider-plugin
Nov 22, 2026
Merged

thymikee merged 29 commits into
0.22from
refactor/0.22-limrun-provider-plugin

Conversation

@thymikee

@thymikee thymikee commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Limrun leaves the core package. The runtime, connection, iOS runner orchestration, download and @limrun/api move to @agent-device/limrun (packages/provider-limrun), installed through the plugin manager. Core adds lazy device capabilities to every provider setup host. Without the plugin, connect limrun answers plugin-not-installed with its install command. Part of #3311.

Auth is unchanged from the base: a login is saved when it is approved. A cloud-discovered Limrun refusal therefore keeps that login; #4940 tracks it. Preflight edge cases: #4914.

agent-device plugins add @agent-device/limrun@nightly-0.22
agent-device connect limrun --platform android

Value

metric base head
core installed size 6.20 MB 5.74 MB
core package download 1.89 MB 1.74 MB

Validation

Head e710efbfa1d8cacaba69f062f7a899d52bde0005 on 0.22 at 6b86764a11. Layering and typecheck passed at this head. Build and 951 focused tests passed before the final layering correction and base refresh. Hosted CI covers the final head. Checks.

The prior head b47f92a8ff passed 43 local gates. Its packed created-iOS run passed open, snapshot, press, and XCTest, and left an empty Limrun inventory. Review fixes and live evidence. Prior Android and token-only iOS evidence.

@thymikee

Copy link
Copy Markdown
Member Author

Live Limrun evidence at 50a016345a (the gated head; the pushed head 4c0e981abf is the same work rebased, context-only per git range-diff).

Setup: branch CLI (node bin/agent-device.mjs), isolated AGENT_DEVICE_HOME and --state-dir, plugin packed with pnpm pack and installed with agent-device plugins add <tarball>. LIMRUN_API_KEY came from the environment. iOS used a simulator runner built from this checkout with Xcode 27.1 (AGENT_DEVICE_LIMRUN_IOS_RUNNER_APP). Android used the snapshot helper built from this checkout.

Commands per platform: connect limrun --platform <p>, open, snapshot -i, press @ref, (back on iOS), fill @ref wifi, snapshot -i, plugins list --json, close, disconnect, daemon stop. The instance list afterward came from @limrun/api androidInstances.list and iosInstances.list.

head 50a016345a9fbad76a983a06b6ec0be37329b41a
cli 0.22.0-dev
plugin sha256 75dc028b489354764044a394269145589e589e7f161c780d48c3c7f3bd57706d
--- plugin absent
{"code":"UNSUPPORTED_OPERATION","reason":"plugin-not-installed","installCommand":"agent-device plugins add @agent-device/limrun@nightly-0.22"}
--- plugins add
{"name":"@agent-device/limrun","version":"0.22.0-dev"}
{"name":"@agent-device/limrun","version":"0.22.0-dev","provider":"limrun","compatible":true}
--- android
connect exit=0
{"leaseProvider":"limrun","leaseBackend":"android-instance","runId":"limrun-612ca9b316011df3","verification":"verified"}
open exit=0
{"id":"limrun:android:029edf2f2cef64ced7dc142d352af3b0","appBundleId":"com.android.settings"}
snapshot exit=0
{"nodes":33,"backend":"android-helper"}
press exit=0
"Tapped @e3 (360, 171)"
snapshot2 exit=0
fill exit=0
"Filled 4 chars"
snapshot3 exit=0
search field value=wifi
{"provider":"limrun","source":"store","package":"@agent-device/limrun","state":"active"}
close exit=0
{"session":"smoke-a","provider":{"limrunInstanceId":"android_euna_01m7x07n42fk9r7kcsv0yynvfb"},"message":"Closed: smoke-a"}
disconnect exit=0
{"connected":false,"session":"smoke-a","released":false}
Daemon stopped (graceful).
--- ios
connect exit=0
{"leaseProvider":"limrun","leaseBackend":"ios-instance","runId":"limrun-d64b0cbaff0f93bd","verification":"verified"}
open exit=0
{"id":"limrun:ios:739a4b68433f46bfa659a791e0234c70","appBundleId":"com.apple.Preferences"}
snapshot exit=0
{"nodes":18,"backends":{"simulator-ax-bridge":1}}
press exit=0
"Tapped @e7 (201, 319)"
back exit=0
snapshot2 exit=0
fill exit=0
"Filled 4 chars"
snapshot3 exit=0
search field value=wifi
{"provider":"limrun","source":"store","package":"@agent-device/limrun","state":"active"}
close exit=0
{"session":"smoke-i","provider":{"limrunInstanceId":"ios_euna_01m7x07xcyea0rdg0592s3dxyr"},"message":"Closed: smoke-i"}
disconnect exit=0
{"connected":false,"session":"smoke-i","released":false}
Daemon stopped (graceful).
--- instances not terminated after the run:
listed

Packed check on 4c0e981abf:

Packed @agent-device/limrun: TypeScript consumer passed.
Packed @agent-device/limrun: failure contract passed.
Packed @agent-device/limrun: isolated install, host-recognized errors, and CLI connect passed.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.09 MB 5.10 MB -982.5 kB
Package (unpacked) 6.09 MB 5.10 MB -982.5 kB
Package (download) 1.86 MB 1.55 MB -304.0 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 25.1 ms 23.9 ms -1.1 ms
CLI --help 48.4 ms 47.6 ms -0.7 ms

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Reply to the Sentinel finding "Ended Limrun lease stays stored when the command never primes the plugin store" (src/cli/connection/ended-lease.ts:32). No inline thread was posted for it, so this reply is here.

The finding is correct. Route: close and session are in REMOTE_MATERIALIZATION_DEFERRED_COMMANDS (src/cli.ts), so they skip materializeRemoteConnectionForCommand, the only place a device command loads the plugin store. The daemon reply to close names the released lease. forgetEndedConnectionLease then read connectionProviderCapabilities('limrun') from an unloaded store, got the remote-provider default, and kept the lease. The built-in answered that read synchronously, so this was a regression.

Fixed in 82fd39f:

  • connect and connection materialization, where the plugin is loaded, record the provider's declaration on the stored connection (forgetsEndedLease).
  • forgetEndedConnectionLease reads the recorded value. It loads no plugin, so the result is the same with the plugin installed, not loaded, or uninstalled. A connection stored without the value gains it on its next materializing command.
  • Tests: src/cli/connection/ended-lease-unprimed-store.test.ts runs close through the CLI with no plugin installed and a stored ended Limrun lease, and the lease is cleared (it fails without the fix). The same file runs disconnect with the plugin absent, and the stored connection is removed. The connect limrun and materialization tests assert the recorded value.

@apex-sentinel-staging review

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding on 82fd39f. The verdict and the full list are in the summary comment.

Comment thread src/cli/connection/ended-lease.ts Resolved
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding on 1c803c8. The verdict and the full list are in the summary comment.

Comment thread src/cli/connection/ended-lease.ts Resolved
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Reviewed 997f851: a second independent pass found three problems to fix before merge, all where Limrun is now an optional plugin and stored state or the install hint is affected.

The first is in cloud-profile.ts. Run connect cloud with a valid token and no Limrun plugin. If the control plane returns a profile with leaseProvider set to limrun, the command saves the Limrun session and moves the active pointer while it checks only the cloud adapter. Without a daemon URL it leaves the generated profile behind and reports a daemon URL error. Should the provider chosen by the cloud response be checked, and primed, right after the fetch and before the profile is written? The cloud adapter's own check should stay for that route.

The second is in cli.ts. Take a named Limrun remote profile with an HTTP daemon URL that triggers cloud authentication, no current CLI session, and no plugin. Both connect --remote-config and ordinary device commands start authentication before the provider check. Non-interactive calls get an authorization error with no install command. An interactive connect can ask for login and write auth state before it reports the missing plugin. The existing provider admission must run before remote authentication on every known Limrun connect and materialization route. Cleanup commands stay outside that check.

The third is in connection-runtime.ts. Upgrade a state directory that has a named pending Limrun connection A and a newer providerless connection B, with no record named default, and install the plugin. On the 0.22 base, apps --session A leaves B active. At this head, recording forgetsEndedLease makes materialization write A and repoint .active-session.json to it. A later command without a session then refuses the leased fallback instead of using B. An in-memory comparison of the base and head materializers reproduced the pointer switch. A catalog read must not change the active connection. Record the policy only where an existing path already writes the connection, or update only the named record. Until then, use the catalog's policy for older Limrun records.

For a follow-up issue, not for this PR:

  • Provider names are not normalized in provider-policy.ts. A remote profile with leaseProvider set to limrun (with spaces) passes the profile parser unchanged. connect --remote-config then misses both the plugin and catalog lookups, treats the profile as generic, and commits it with no plugin. A later open can reach the daemon, which trims the name to limrun. Provider lookups for profiles and stored connections must use the same name normalization as the daemon, before any capability check. Old records must stay readable, and new state must be written with the canonical name.
  • The daemon-side hint is thin in lease.ts. The documented SDK leases.allocate call with leaseProvider set to limrun, against a daemon that has Limrun credentials but no plugin, fails with a restart hint that names no package or install command. The same happens for an embedded host started without the factory. CLI open can hit this guard when the plugin is in the CLI store but not in the running daemon. apps on a pending connection can say the instance is unallocated. The daemon's missing-runtime and catalog admission paths must use the managed provider catalog and, for an absent managed provider, give the package, the versioned install command, and the restart or embedded-host guidance. Errors for failed registrations and unallocated instances of registered providers should stay as they are.

Not blocking, and fine to take or leave: the stored forgetsEndedLease field in ended-lease.ts duplicates providerForgetsEndedConnectionLease, which already answers from the loaded declaration and then the catalog, so it could be dropped along with withEndedLeasePolicy and the extra state write; the Limrun plugin's setup in plugin.ts fails when LIMRUN_* is unset, so the claim shows as failed where the old built-in stayed dormant, which suits a follow-up issue; and the moved test in cloud-connect-profile-fields.test.ts no longer asserts that no state file exists after the refusal, which its name still says.

The two earlier inline threads on ended-lease policy are fixed at this head and can be resolved: #4846 (comment) and #4846 (comment).

CI is unclear. The failing jobs are the advisory mutation shards kernel-errors-3 and kernel-errors-4, which this PR triggers because it touches package manifests and the lockfile. The diff does not touch errors.ts, but it moves many tests that import AppError, so a failing or slow test in those shards could be related. No failure log was available. Please re-run those shards or say why they fail. Not verified here: whether the failure is a harness timeout or a test failure, any local test run, the emitted dist/agent-device.d.mts, or a live device run at 997f851 (the last transcript is from 50a0163, and the later changes touch CLI connection state only).

Required evidence is present. Before merge, the three fixes above are needed, and the mutation shards need a re-run or an explanation.

@thymikee

Copy link
Copy Markdown
Member Author

Mutation shards kernel-errors-3 and kernel-errors-4: cause

They are not test failures from this diff. Both shards died in the Stryker dry run, before any mutant ran, on one test:

ERROR DryRunExecutor One or more tests failed in the initial test run:
	ensureDaemon reports contention when the daemon keeps changing under it
		Test timed out in 5000ms.

That test is packages/daemon-client/src/__tests__/daemon-client-ensure-explicit-lifecycle.test.ts, which this PR does not touch. It waits out the real contention budget: daemon-client-ensure.ts sleeps 250 ms per attempt for the whole teardown grace. Measured: 1.3–2.4 s on main and 0.8–0.9 s on 0.22 on a developer Mac; 4.7–5.1 s on the 2-core CI runners (it also tripped the slow-test gate once on #4828); over 5 s under the mutation tool. The same failure repeated on three heads of this PR (1c803c8 once, 997f851 twice), so a re-run does not help. Affected decision-kernel mutants is red only because the sweep is incomplete (4 of 6 shard reports).

The fix is in progress as a separate change (inject the wait budget; no timeout raise), as one PR against main and the same patch against 0.22. When the 0.22 one merges, this branch is rebased onto it and the shards run again.

Follow-up notes from the review (provider-name normalization, daemon-side hint naming the package, plugin without credentials listed as failed) are filed as #4852.

@thymikee

Copy link
Copy Markdown
Member Author

Reply to the review of 997f851 (#4846 (comment)).

1. connect cloud saving a Limrun session without the plugin — fixed in cf9e4d4. resolveCloudConnectProfile admits the provider the control plane names right after the fetch and before the profile or any state is written. A missing plugin answers plugin-not-installed with the install command. The cloud adapter's own check is unchanged. Test: connect cloud refuses a Limrun profile from the control plane before anything is written (src/cli/connection/provider-admission.test.ts) compares every file under the state directory before and after, including .active-session.json, with a providerless connection active. The lost assertion in cloud-connect-profile-fields.test.ts is restored: no remote-connections directory exists after the refusal.

2. Provider admission after remote authentication — fixed in cf9e4d4. resolveRemoteContext admits the provider before resolveRemoteAuthForCli, for connect (the named provider, or the remote config profile's) and for commands that materialize a connection (the profile's, or the stored connection's). The deferred-materialization commands (close, session, disconnect, and the rest of that set) admit no provider. The check lives in src/cli/connection/provider-admission.ts and is loaded with a dynamic import only when a remote connection is in play, so src/cli.ts gains no static import. Tests in the same file: connect --remote-config with --no-login and without it, and apps on a stored Limrun connection, each with a daemon URL that triggers cloud auth. Each asserts the install command, that the auth seam was not called, and that no state was written. A disconnect test shows cleanup stays outside the check.

3. A catalog read changing the active connection — fixed in 5d14a0d with the simpler option. The stored forgetsEndedLease field, withEndedLeasePolicy and the extra state write are gone. forgetEndedConnectionLease asks providerForgetsEndedConnectionLease (loaded declaration, then the catalog) at the point of use. A record that still carries the field parses and the field is ignored; no migration. Test: materializing a named Limrun connection leaves the newer active connection active and writes nothing (src/__tests__/cli-config-limrun.test.ts). Kept: the catalog drift test and the unprimed close tests (unrecorded Limrun forgets, unknown provider keeps).

Known limit after dropping the field: a third-party plugin that declares forgetsEndedConnectionLease: true, is not in the catalog, and is not loaded on close keeps its stored lease. close loads no plugin store, so nothing answers for it. That is the behaviour at 4c0e981 too. I added no machinery for it.

Not changed, per the review: provider-name normalization, the daemon-side hint, and the plugin showing as failed without LIMRUN_*. The mutation shards are not changed either.

Checks on the new head: typecheck, lint, format, layering, fallow audit --base origin/0.22, production-exports, eager-closure budgets, 5,876 CLI and remote tests, 1,219 command, repo-guard and plugin-package tests, 20 Limrun provider scenarios. No local check:affected.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Correction to my note above on the mutation shards: the cause of the slow test is not the 250 ms sleeps (those were already mocked). The contention loop runs 300 iterations, and each one re-reads the daemon registration; reading a held lock takes one host ps process-table snapshot. That is about 700 ms locally and several seconds on a 2-core runner. The conclusion is unchanged: the failure is in a daemon-client test this PR does not touch.

The fix is up as #4856 (against 0.22) and #4855 (the same patch against main): the test replays one real lock inspection and asserts the full judge-again budget instead of spending it. The two tests go from 0.7–1.1 s to about 0.2 s locally. After #4856 merges, this branch is rebased and the shards run again.

@thymikee

Copy link
Copy Markdown
Member Author

Two problems remain at cf9e4d4, and both are about when the CLI admits the Limrun provider. The two earlier inline threads on the ended-lease policy are fixed at this head and can be resolved: #4846 (comment) (withEndedLeasePolicy no longer exists) and #4846 (comment) (upgraded connections forget ended leases through the catalog fallback, covered by the ended-lease-unprimed-store.test.ts close test).

A second independent pass found that interactive cloud discovery saves a CLI session before it refuses Limrun. Run connect cloud --session ci, or connect --session ci, with no token, no valid CLI login and no Limrun plugin, then approve the device login for an account whose profile names limrun. resolveCloudAccessForConnect calls loginWithDeviceAuth (auth-session.ts:185), which writes auth/cli-session.json (auth-session.ts:268). The profile is fetched and refused only afterward (cloud-profile.ts:31). The command prints the install hint, but it leaves new stored authentication state on a refused route. The rule: a newly approved login stays in memory until cloud profile discovery admits the selected provider. This must hold for every cloud discovery route, including when --daemon-base-url would otherwise start login in the generic auth step.

A second independent pass also found that an inherited profile can select a different connection during materialization (provider-admission.ts:37). Connect session ci in state directory B with a profile whose stateDir is B and leaseProvider is limrun. Change that profile's provider to cloud, then connect ci in directory A with --state-dir A, leaving the B record in place. After upgrade, run AGENT_DEVICE_STATE_DIR=A agent-device apps --session ci with no plugin and no token. Defaults come from the A record, but the profile's stateDir replaces the environment default during the merge (src/cli.ts lines 399-415 and 839-849). Admission checks cloud from A and the auth step returns UNAUTHORIZED. With auth available, materialization reads the Limrun record in B and refuses it only afterward (connection-runtime.ts:57-88). The rule: the provider and record that materialization will use are selected once, before authentication, from the effective state directory and session, and that selection is passed into materialization. The stored provider takes precedence over the profile fallback.

Not blocking, and fine to take or leave: admission derives the provider as remoteConfigLeaseProvider ?? connection.leaseProvider, while materialization derives it as existingState.leaseProvider ?? profile.leaseProvider, so one helper both call would remove the opposite precedence (they cannot diverge today because a changed profile fails remoteConfigHash validation first); and storedConnection() in ended-lease-unprimed-store.test.ts rewrites every record to add forgetsEndedLease:false, a field no released build wrote, so the loop can go and the test can be renamed to say that close forgets an ended Limrun lease through the catalog.

The code needs the two fixes above. CI shows one red check, the kernel-errors-4 mutation shard, which died in the Stryker dry run on ensureDaemon reports contention when the daemon keeps changing under it in packages/daemon-client. This PR touches nothing in that package or the kernel errors module, so the failure looks unrelated, and the fix is #4856 against 0.22. Not verified here: the shard failure log, because the attribution rests on the quoted dry-run error. Live device evidence is from 50a0163, and the changes since then touch only CLI admission ordering and connection-state writes, so no new device run is needed. Not verified here: local test runs, because this was a read-only review. After the two fixes, the next step before merge is for kernel-errors-4 to go green once #4856 lands in 0.22 and this branch is rebased.

@thymikee

Copy link
Copy Markdown
Member Author

Scope note for the review at cf9e4d4 (#4846 (comment)):

  • Point 1 (a newly approved login is written before the provider is admitted): in scope, being fixed in this PR at the auth-session owner.
  • Point 2 (select the materialization record and provider once, before authentication, from the effective state directory): not fixed in this PR. It needs two state directories and a profile edited between connects, and it changes how the CLI merges stateDir and orders materialization, which is wider than the Limrun extraction. Tracked as cli: select the remote connection record and provider once, before authentication #4858 for the maintainer to decide. This PR takes the related optional item: one provider-of-command helper for admission and materialization, with the stored provider first.

The author's per-point reply with SHAs follows after the push.

@thymikee

Copy link
Copy Markdown
Member Author

Reply to the review of cf9e4d4 (#4846 (comment)).

Point 1, a new login saved before Limrun is refused — fixed in 2240079. The fix is in the auth-session owner. A login that connect approves stays pending in memory: loginWithDeviceAuth takes deferSessionWrite, and commitPendingCliLogin stores it. resolveCloudConnectProfile commits right after it admits the provider the profile names. connect also commits after its provider profile resolves, which covers the route where --daemon-base-url starts login in the generic auth step. auth login stores at once, as before. Nothing is deleted afterward: a refused route never writes. Tests in src/cli/__tests__/auth-session-connect-admission.test.ts approve a device login, let the profile name limrun with no plugin, and assert plugin-not-installed with the install command and no auth/cli-session.json, for connect cloud, plain connect, and connect --daemon-base-url. A fourth test shows the admitted route writes the session once with the same contents. The three refusal tests fail without the deferral.

One consequence to know: a connect that fails before its provider is admitted for another reason, for example the profile fetch fails, also stores no login. The rule as written keeps the login in memory until admission.

Point 2, an inherited profile selecting a different connection during materialization — not fixed in this PR. 37b7e68 adds one helper, connectionLeaseProvider, that admission and materialization both call, with one precedence: the stored connection's provider, then the profile's. That removes the opposite precedence the review notes. The remaining part, selecting the materialization record and provider once from the effective state directory and session before authentication and passing that selection into materialization, is not done here. It is tracked in the follow-up issue the coordinator opens.

Optional items, taken in 37b7e68: the shared helper above, and ended-lease-unprimed-store.test.ts no longer rewrites records with forgetsEndedLease: false; the test is named close forgets an ended Limrun lease through the plugin catalog.

Checks on the new head: typecheck, lint, format, layering, fallow audit --base origin/0.22, production-exports, eager-closure budgets, 5,879 CLI and remote tests, 20 Limrun provider scenarios. No local check:affected.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding on 37b7e68. The verdict and the full list are in the summary comment.

Comment thread src/cli/auth-session.ts Resolved
@thymikee
thymikee force-pushed the refactor/0.22-limrun-provider-plugin branch from 37b7e68 to 6d735ae Compare November 20, 2026 20:21
@thymikee

Copy link
Copy Markdown
Member Author

Update to my reply on the review of cf9e4d4 (#4846 (comment)). The branch is rebased onto 6d9beca29d, so the SHAs changed. Current head: 6d735ae.

Point 1, a new login saved before Limrun is refused — fixed. The final shape is in 6d735ae (it replaces the per-site commits of the earlier push). withCommandLogin in the auth-session owner wraps the login-bearing part of every command. A login approved inside it is stored when the command ends. Only the typed plugin-not-installed refusal discards it. So the earlier consequence is gone: a connect that fails after login for another reason, such as a failed profile fetch, keeps the login (Sentinel thread r4647199321, resolved). Tests cover connect cloud, plain connect, and connect --daemon-base-url on the refused route, plus the fetch-failure, generic-auth-failure and success routes.

One limit on test (c) as asked: no device command can approve a login, because only connect allows interactive login. The route tested is connect --remote-config, where the generic auth step logs in.

Point 2, an inherited profile selecting a different connection during materialization — not fixed in this PR. 9d55d0d adds one helper, connectionLeaseProvider, that admission and materialization both call: the stored connection's provider, then the profile's. That removes the opposite precedence. Selecting the materialization record and provider once from the effective state directory and session before authentication is not done here and is tracked in the follow-up issue the coordinator opens.

Optional items — both taken in the same commit: the shared helper, and the ended-lease-unprimed-store test no longer rewrites records; it is named close forgets an ended Limrun lease through the plugin catalog.

Checks on 6d735ae: typecheck, lint, format, layering, fallow audit --base origin/0.22, production-exports, eager-closure budgets, 5,881 CLI and remote tests, 20 Limrun provider scenarios. No local check:affected.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The earlier findings from cf9e4d4 are fixed at 6d735ae, and a second independent pass found three login-timing defects that remain. Login is no longer discarded on non-refusal failures (auth-session.ts:91-101), withEndedLeasePolicy is gone, and upgraded connections forget ended Limrun leases through the catalog.

A second independent pass found that cloud discovery can save a login that admission then refuses. Set the user config to valid JSON with "plugins": [] and leave Limrun uninstalled. The CLI flag reader ignores that key (cli-config.ts:139), but the plugin store requires an object there and records an unnamed store failure (store.ts:39, store.ts:229). Approve a login during connect cloud --session ci, plain connect --session ci, or connect --daemon-base-url https://bridge.agent-device.dev/api --tenant acme --session ci when discovery returns leaseProvider: "limrun". Admission refuses with plugin-unavailable (cloud-profile.ts:46, provider-policy.ts:93), yet the finalizer still writes auth/cli-session.json (auth-session.ts:100). A selected Limrun package whose entry fails to load reaches the same refusal and write. The rule: when the selected provider's admission fails with either typed plugin refusal, including plugin-unavailable, the pending login must be discarded. Keep the existing repair diagnostic when the store cannot be read.

The same pass found that admitted connect persists state and reports success before the login is saved. Create a writable private state directory with auth/cli-session.json as a directory, then approve login during connect cloud --session ci --json for an admitted profile. The head writes the generated profile and connection record, emits success: true (connection.ts:107, shared.ts:14), then fails the auth rename (atomic-publish.ts:44) and emits success: false on the same stream (cli.ts:684). Plain cloud discovery and the admitted generic-auth paths, including --daemon-base-url, --remote-config and proxy, share this ordering. Base 6d9beca saved during loginWithDeviceAuth (auth-session.ts:268), so a failed auth write stopped connect before it published anything. The rule: the pending login must be flushed at provider admission, before connection state is generated or published. For cloud discovery, flush right after the provider check. For a route whose provider is already admitted, save in the auth step. Keep the fallback write for unrelated discovery failures.

The same ordering problem affects explicit auth login. With auth/cli-session.json a directory inside an otherwise valid state root, approve auth login --json. The command-wide scope captures the login as pending (auth-session.ts:302, cli.ts:211). The handler emits success: true with authenticated: true (auth.ts:25, auth.ts:35), then the deferred write fails and a second error object follows. The rule: explicit auth login must stay outside the deferred scope, because only connect can approve a login before provider discovery.

The two open inline threads on provider-selection and ended-lease handling no longer apply and can be resolved: login is no longer discarded on non-refusal failures (#4846 (comment)), withEndedLeasePolicy no longer exists at head (#4846 (comment)), and upgraded connections forget ended leases through the catalog (#4846 (comment)).

CI shows 26 checks with none failing at 6d735ae. The earlier kernel-errors-4 dry-run failure was fixed upstream by #4856, which arrived with the rebase. There are no conflicts. This was a read-only review, so no local test run was done. Not verified here: that the new tests pass, which rests on green CI and the author's report. Live device evidence is from 50a0163, and the changes since then touch only CLI auth-state timing and the provider-precedence helper, so no new device run is needed. Merge needs the three fixes above, with a test for each failing route.

@thymikee

Copy link
Copy Markdown
Member Author

Reply to the round-three review at 6d735ae (#4846 (comment)). No push yet; this asks for the scope decision.

Classification. None of the three belongs in #4858 (that issue is the cross-state-directory record selection). All three are consequences of the deferred-login change this PR added in round two:

  1. plugin-unavailable also discards the pending login: same invariant as the plugin move (a refused provider writes no auth state). Part of this PR.
  2. Admitted connect publishes state and reports success before the login is saved: a regression against base 6d9beca, introduced by the deferral. Must not merge as is.
  3. auth login reports success before the write: the same regression. Must not merge as is.

Two ways to resolve, maintainer's choice:

  • A. Narrow the deferral (recommended). The pending login exists only between login approval and provider admission. At admission: admitted → write at once, so a failed write stops connect before anything is generated or published, as on base; refused with either typed plugin refusal (plugin-not-installed, plugin-unavailable) → discard, keeping the store repair diagnostic; a discovery failure before admission → fallback write. A route whose provider is already admitted writes in the auth step. auth login is never deferred. This replaces the command-wide finalizer and fixes all three with one mechanism, with a test per failing route.
  • B. Remove the deferral. Return to base behavior: the login is saved when it is approved, also when the provider is then refused. Points 2 and 3 disappear with the mechanism. "No auth state on a refused provider route" (round two, point 1) moves to an issue. This is the smaller PR.

I will implement the one you choose and not push before that.

R84 test-colocation judges a unit test against the modules beside it.
`auth-login-write-timing.test.ts` sits in `src/cli/__tests__`, where no
module is named `auth-login-write-timing`, and
`connect-provider-credential-order.test.ts` sits in `src/cli/connection`
with no such module either. Each is renamed for the module whose behavior
it pins: `auth-session.ts` holds the login save timing, and
`provider-admission.ts` owns the admission that precedes the credential.

Part of #3311
A `connect` that learns its provider from the control plane holds the login it
approves until that provider is admitted. An explicit `auth login` or `auth
logout` completed in that gap was overwritten when the connect resumed, so the
older approval won and a logout left the state directory signed in.

Every write of one state directory's auth state now passes one guard: a
revision record beside the session it governs, republished by each write. A
held login reads that revision before its device authorization and saves only
while it still stands, which logs the stand-down rather than failing the
command. The record counts writes rather than reading the stored session,
because a logout leaves no session, which is what a first login finds too.

Name the Limrun plugin in the README Cloud / remote install instruction, since
a clean core install refuses a Limrun profile without it.

Refs #4846 (review 7068516663)
Remove the deferred-login scope and the auth revision record. A login is
written when the cloud approves it, so explicit auth commands and concurrent
connects keep the base ordering. The cloud route still admits a discovered
Limrun provider before it generates a profile or connection record.
The Run anywhere card printed the bare package name, which the plugin store
resolves to latest: the runtime-free placeholder. Use the nightly selector the
docs and the CLI hints use, and point readers at the printed command.
A saved or explicit Limrun connection whose daemon is configured elsewhere was
refused with plugin-not-installed before it authenticated or dispatched, which
no base release did. The plugin is needed where the device is driven: keep the
refusal for a direct connect and for a connection with no configured daemon, and
let the daemon's own provider registration decide runtime admission otherwise.
The connection's metadata is still read and saved either way.
The Limrun SDK echoes a request body in its error message, so an endpoint that
answers a verification with an unlabeled body naming the API key put that key in
the cause the CLI prints, which pattern redaction cannot see. Answer with the
typed verification error, its status and hint, and carry no cause.
An instance that answers an authenticated download or an XCTest start with an
unlabeled body naming the bearer token it was given put that token in the error
details the daemon publishes. Remove each value sent to the endpoint from the
response text before publishing it; the status and typed reason answer for the
failure.
A remote Limrun connection whose host has no plugin was answered from generic remote
capabilities, so `apps` allocated a lease, `lease_allocate` sent the daemon's default TTL,
and `open <app>` dropped the initial app. The plugin catalog now carries the provider's whole
declared `ConnectionProviderCapabilities` and its admission policy, and `declaredConnectionCapabilities`
falls back to that copy before the daemon's own routing, so a connection's lease policy is its
provider's whether or not this host loads the plugin.

The predicate, its without-refusal variant and the three duplicated if/else sites collapse into
`admitProviderForRoute(provider, route, env)`, which primes the store, refuses only where this host
must supply the provider, and answers capabilities from the plugin when loaded, else from the
catalog. `providerRouteForConnection` reads the same two settings the daemon client reads.
The SDK, an attached instance and a forwarding service in front of one all answer with their own
text, and this plugin authenticates each of them with an account key or an instance token. An
unlabelled echo of a bare credential survives core's pattern redaction, so each path that published
peer text is closed at its owner:

- Every client this plugin builds logs nothing: `off` on the organization client and `none` on an
  instance client, which outranks `LIMRUN_LOG`, so the SDK cannot write a failed response body that
  carries an account key or an instance token.
- The scrubber drops a credential however brief — the reader of an attached instance accepts any
  nonempty token — and takes the credential out of both a header value and its bare credential.
- A download publishes its typed reason, its status and a transport code: no URL, no peer body, and
  no fetch message, since an attached instance answers with its token as the download URL.
- An account-API failure is re-raised as an `AppError` carrying status and reason before a create,
  an asset list, a recovery list, a reconnect lookup or a delete records or returns it, keeping the
  404 answer a caller acts on. A termination reason is bounded to one line and scrubbed.
- The runner's forwarded credential reaches its response, its cause and its log redaction boundary,
  including a credential split across stream chunks, and a `/sync` field this upload did not name
  stays out of the upload failure.
- An instance client's own failures are answered through one wrapper, so `listApps`, `pressKey` and
  a remote install cannot return the peer's frame with the session token in it. Only a failure that
  names a sent value is re-raised, so a clean SDK failure keeps the reason and cause the command
  that caught it publishes.
@thymikee
thymikee force-pushed the refactor/0.22-limrun-provider-plugin branch from b47f92a to e710efb Compare November 22, 2026 19:29
@thymikee

Copy link
Copy Markdown
Member Author

Rebased through #4977 onto 0.22 at 6b86764a11. WebDriver stays inside the four provider plugins. The async provider host receives Limrun’s device capabilities from the shared composition, and Limrun emits through host.diagnostics. Runtime composition · Limrun diagnostics.

Layering and typecheck passed on e710efbfa1d8cacaba69f062f7a899d52bde0005. Build and 951 focused tests passed before the final layering correction and base refresh. The full affected gate stopped at the layering issue, which the final layering run cleared. GitHub CI is running on the pushed head. The packed iOS result remains attributed to b47f92a8ff. Live evidence.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of e710efb

Since the review of b47f92a: 0 new · 0 still open · 0 no longer raised

No open findings.

Not in the reviewers' prompt (42 files)
  • .fallowrc.json: left out as an asset or for its size; reviewers could still search it
  • LICENSES/xdelta3-wasm.txt: left out as an asset or for its size; reviewers could still search it
  • README.md: left out as an asset or for its size; reviewers could still search it
  • THIRD_PARTY_NOTICES.md: left out as an asset or for its size; reviewers could still search it
  • examples/sdk/tsconfig.json: left out as an asset or for its size; reviewers could still search it
  • package.json: left out as an asset or for its size; reviewers could still search it
  • packages/apple-runner/src/__tests__/runner-command-recovery.test.ts: left out as an asset or for its size; reviewers could still search it
  • packages/provider-limrun/README.md: left out as an asset or for its size; reviewers could still search it
  • packages/provider-limrun/package.json: left out as an asset or for its size; reviewers could still search it
  • packages/provider-limrun/src/client-options.test.ts: left out as an asset or for its size; reviewers could still search it
  • packages/provider-limrun/src/download-file.test.ts: left out as an asset or for its size; reviewers could still search it
  • packages/provider-limrun/src/error-text.test.ts: left out as an asset or for its size; reviewers could still search it
  • packages/provider-limrun/src/instance-error-scrubbing.test.ts: left out as an asset or for its size; reviewers could still search it
  • packages/provider-limrun/src/internal.ts: left out as an asset or for its size; reviewers could still search it
  • packages/provider-limrun/src/ios-runner-products.test.ts: left out as an asset or for its size; reviewers could still search it
  • packages/provider-limrun/test/package-smoke.mjs: left out as an asset or for its size; reviewers could still search it
  • packages/provider-limrun/tsconfig.json: left out as an asset or for its size; reviewers could still search it
  • pnpm-lock.yaml: generated or a lockfile, so its lines were left out
  • scripts/__tests__/fixtures/bundled-license-build.mts: left out as an asset or for its size; reviewers could still search it
  • src/__tests__/limrun-runtime.test.ts: left out as an asset or for its size; reviewers could still search it
  • src/__tests__/provider-device-runtimes.test.ts: left out as an asset or for its size; reviewers could still search it
  • src/__tests__/test-utils/builtin-plugin-inventory.ts: left out as an asset or for its size; reviewers could still search it
  • src/builtin-provider-ids.ts: left out as an asset or for its size; reviewers could still search it
  • src/builtin-provider-plugins.test.ts: left out as an asset or for its size; reviewers could still search it
  • src/builtin-provider-plugins.ts: left out as an asset or for its size; reviewers could still search it
  • src/cli/connection/ended-lease-unprimed-store.test.ts: left out as an asset or for its size; reviewers could still search it
  • src/cli/connection/provider-admission-credential-order.test.ts: left out as an asset or for its size; reviewers could still search it
  • src/cli/connection/provider-admission-scoping.test.ts: left out as an asset or for its size; reviewers could still search it
  • src/cli/connection/provider-admission.test.ts: left out as an asset or for its size; reviewers could still search it
  • src/cli/connection/provider-policy.test.ts: left out as an asset or for its size; reviewers could still search it
  • src/core/interactors/limrun-ios-runner-errors.ts: left out as an asset or for its size; reviewers could still search it
  • src/core/limrun-download-file.ts: left out as an asset or for its size; reviewers could still search it
  • src/provider-plugin-host-capabilities-limrun-ios-files.test.ts: left out as an asset or for its size; reviewers could still search it
  • src/provider-plugin-host-capabilities-limrun-ios-tools.test.ts: left out as an asset or for its size; reviewers could still search it
  • src/provider-plugin-host-capabilities.test.ts: left out as an asset or for its size; reviewers could still search it
  • src/sdk/limrun-runtime-dependencies.ts: left out as an asset or for its size; reviewers could still search it
  • tsconfig.json: left out as an asset or for its size; reviewers could still search it
  • tsdown.config.ts: left out as an asset or for its size; reviewers could still search it
  • website/docs/docs/device-clouds.md: left out as an asset or for its size; reviewers could still search it
  • website/docs/docs/error-reasons.md: left out as an asset or for its size; reviewers could still search it
  • website/docs/docs/limrun.md: left out as an asset or for its size; reviewers could still search it
  • website/docs/docs/plugins.md: left out as an asset or for its size; reviewers could still search it

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (098c1780b9e5).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee
thymikee merged commit 9c40d42 into 0.22 Nov 22, 2026
29 checks passed
@thymikee
thymikee deleted the refactor/0.22-limrun-provider-plugin branch November 22, 2026 19:40
@thymikee

Copy link
Copy Markdown
Member Author

Cleanup after merge: both worktrees used for this PR (t3-3d81a0af, t3-22e4abfd) are removed, along with their local branches (w4846, refactor/0.22-limrun-provider-plugin); GitHub had already deleted the remote branch. The PR's scratch notes and logs are removed. No T3 device was opened for this PR. The live runs used Limrun cloud instances, and the final inventory showed zero active instances. No daemon or process still references either worktree.

thymikee added a commit that referenced this pull request Nov 23, 2026
* refactor(limrun): ship Limrun as the @agent-device/limrun plugin

Limrun leaves the core package. The runtime, the connection, the iOS runner
orchestration, the file download and the Limrun SDK dependency now live in
packages/provider-limrun, published as @agent-device/limrun and installed
through `agent-device plugins add`.

- Core adds device capabilities to every provider `setup` host: the Android
  lease interactor and ADB mechanics, the shared Apple XCTest runner with its
  tool-provider scope, and the host's retry and archive mechanics. Each facet
  loads on first use.
- The Android interactor is the core-owned one, bound to the lease's
  provider-owned executor. A host that supplies no capabilities gets a typed
  `provider_host_capability_missing` failure.
- `connect limrun` without the plugin answers `plugin-not-installed` with the
  install command. The built-in candidate, its reserved id and the
  `@limrun/api` bundling are removed.

Part of #3311

* chore(gates): admit the Limrun plugin package and its own SDK dependency

The Limrun package publishes its own artifact and installs `@limrun/api`
itself, so the root matches only the dependency ranges it also declares.
The packed-plugin check reads a plugin's own dependencies from its fixture.
The root module zones drop the removed built-in provider modules and place
the provider host capabilities with the platform runtime host.

* fix(connection): forget an ended lease without loading the provider plugin

`close` and `session` skip connection materialization, so they never load
the plugin store. The ended-lease check read the provider's declaration
from that store and kept the stored lease of an installed Limrun plugin.

`connect` and connection materialization now record the declaration on the
stored connection. The ended-lease check reads the recorded value, so it
needs no plugin, installed or not.

Part of #3311

* fix(connection): keep a recorded ended-lease policy as the authority

A device command after the provider's plugin was uninstalled read the
plugin-less default and persisted `false` over a recorded `true`. The
policy is now recorded once, from the provider's own declaration, and a
provider whose plugin is not loaded records nothing.

Part of #3311

* fix(connection): read an unrecorded ended-lease policy from the plugin catalog

A connection stored before the policy was recorded has no value, and
`close` loads no plugin store, so it kept an ended Limrun lease. The
plugin catalog now carries a copy of the plugin's declaration. One lookup
answers without loading a plugin: the provider's own declaration, then the
catalog. A recorded value stays the authority. A test holds the catalog
equal to the declarations of the workspace plugins.

Part of #3311

* fix(connection): answer the ended-lease policy at the point of use

Recording the policy on the stored connection made materialization write a
named connection and repoint the active-session pointer on an upgraded
state directory. The stored field, its writer and the extra state write
are removed. The ended-lease check asks the one lookup that needs no
plugin: the provider's loaded declaration, then the plugin catalog. A
record that still carries the field reads as before.

Part of #3311

* fix(connect): admit the provider plugin before authentication and before cloud state

`connect cloud` saved a Limrun session when the control plane chose Limrun
and the plugin was missing. The provider the cloud response names is now
admitted after the fetch and before the profile or any state is written.

`connect --remote-config` and device commands that materialize a
connection started remote authentication before the provider check. The
provider is now admitted first, so a missing plugin answers with its
install command and no login starts. Cleanup commands admit no provider.

Part of #3311

* fix(auth): keep a new connect login in memory until its provider is admitted

`connect` approved a device login and wrote `auth/cli-session.json` before
cloud profile discovery named the provider. With Limrun chosen and its
plugin missing, the refused route left new auth state behind.

A login `connect` approves is now pending in the auth-session owner. The
cloud profile route stores it after it admits the discovered provider, and
`connect` stores it after its provider profile resolves. This covers
`connect cloud`, plain `connect`, and the route where `--daemon-base-url`
starts login in the generic auth step. `auth login` stores at once, as
before.

Part of #3311

* refactor(connection): read the connection provider from one helper

Admission read the remote config profile's provider first and
materialization read the stored connection's first. Both now call
`connectionLeaseProvider`: the stored connection's provider, then the
profile's. The unprimed `close` test no longer rewrites records with a
field no released build wrote, and its name states the catalog route.

Part of #3311

* fix(auth): store a pending login unless the provider plugin is refused

A `connect` that approved a device login and then failed for any reason
other than provider admission, such as a failed profile fetch, stored no
login, so every retry started device auth again.

The login-bearing part of a command now runs in one login scope. A login
approved inside it is stored when the command ends, on success or on
failure. Only the typed `plugin-not-installed` refusal discards it. The
scope is per command invocation, so a pending login cannot reach another
command in the same process. The per-site commits are removed.

Part of #3311

* fix(connect): hold a login only until its provider is admitted

A `connect` saved a login it approved before it knew the provider that
login was for, so a run whose Limrun plugin was missing reported success
and kept a session it could not use. A pending login now exists only
between its approval and the provider admission of that same run: the
cloud-discovery route saves it right after the provider check, and a
route whose provider is already known saves it in its auth step. No
command-wide finalizer defers anything else, so explicit `auth login`
saves before it reports success.

The plugin store is read through `@agent-device/contracts` reasons, so
both `plugin-not-installed` and `plugin-unavailable` discard the pending
login and keep the install or store-repair diagnostic.

The core ships no Limrun runtime, so Limrun is the only provider the CLI
admits itself: it answers from the positional or the `--remote-config`
profile before that run resolves a credential-bearing option or
registers one for redaction. A named provider the core can supply, such
as BrowserStack, keeps the admission of its connect handler, and a
discovered profile keeps the cloud adapter that reads it.

Part of #3311

* test(connect): name the new tests for the modules they pin

R84 test-colocation judges a unit test against the modules beside it.
`auth-login-write-timing.test.ts` sits in `src/cli/__tests__`, where no
module is named `auth-login-write-timing`, and
`connect-provider-credential-order.test.ts` sits in `src/cli/connection`
with no such module either. Each is renamed for the module whose behavior
it pins: `auth-session.ts` holds the login save timing, and
`provider-admission.ts` owns the admission that precedes the credential.

Part of #3311

* test(cli): drop an unused helper export

* perf(cli): load the connect preflight and pre-command failure modules on demand

* chore(release): make @agent-device/limrun public

* fix(cli): keep a deferred cloud login from overwriting newer auth state

A `connect` that learns its provider from the control plane holds the login it
approves until that provider is admitted. An explicit `auth login` or `auth
logout` completed in that gap was overwritten when the connect resumed, so the
older approval won and a logout left the state directory signed in.

Every write of one state directory's auth state now passes one guard: a
revision record beside the session it governs, republished by each write. A
held login reads that revision before its device authorization and saves only
while it still stands, which logs the stand-down rather than failing the
command. The record counts writes rather than reading the stored session,
because a logout leaves no session, which is what a first login finds too.

Name the Limrun plugin in the README Cloud / remote install instruction, since
a clean core install refuses a Limrun profile without it.

Refs #4846 (review 7068516663)

* refactor(cli): save a connect login when it is approved, as on the base

Remove the deferred-login scope and the auth revision record. A login is
written when the cloud approves it, so explicit auth commands and concurrent
connects keep the base ordering. The cloud route still admits a discovered
Limrun provider before it generates a profile or connection record.

* docs(website): list Limrun with the plugin providers on the Run anywhere card

* fix(website): install the Limrun plugin the 0.22 nightly reader needs

The Run anywhere card printed the bare package name, which the plugin store
resolves to latest: the runtime-free placeholder. Use the nightly selector the
docs and the CLI hints use, and point readers at the printed command.

* fix(cli): let a remote daemon answer for a provider this host lacks

A saved or explicit Limrun connection whose daemon is configured elsewhere was
refused with plugin-not-installed before it authenticated or dispatched, which
no base release did. The plugin is needed where the device is driven: keep the
refusal for a direct connect and for a connection with no configured daemon, and
let the daemon's own provider registration decide runtime admission otherwise.
The connection's metadata is still read and saved either way.

* fix(provider-limrun): keep a verification failure's cause in the plugin

The Limrun SDK echoes a request body in its error message, so an endpoint that
answers a verification with an unlabeled body naming the API key put that key in
the cause the CLI prints, which pattern redaction cannot see. Answer with the
typed verification error, its status and hint, and carry no cause.

* fix(provider-limrun): strip the instance token from error details

An instance that answers an authenticated download or an XCTest start with an
unlabeled body naming the bearer token it was given put that token in the error
details the daemon publishes. Remove each value sent to the endpoint from the
response text before publishing it; the status and typed reason answer for the
failure.

* fix(cli): keep a provider's lease policy on every route

A remote Limrun connection whose host has no plugin was answered from generic remote
capabilities, so `apps` allocated a lease, `lease_allocate` sent the daemon's default TTL,
and `open <app>` dropped the initial app. The plugin catalog now carries the provider's whole
declared `ConnectionProviderCapabilities` and its admission policy, and `declaredConnectionCapabilities`
falls back to that copy before the daemon's own routing, so a connection's lease policy is its
provider's whether or not this host loads the plugin.

The predicate, its without-refusal variant and the three duplicated if/else sites collapse into
`admitProviderForRoute(provider, route, env)`, which primes the store, refuses only where this host
must supply the provider, and answers capabilities from the plugin when loaded, else from the
catalog. `providerRouteForConnection` reads the same two settings the daemon client reads.

* fix(provider-limrun): keep credentials out of published errors

The SDK, an attached instance and a forwarding service in front of one all answer with their own
text, and this plugin authenticates each of them with an account key or an instance token. An
unlabelled echo of a bare credential survives core's pattern redaction, so each path that published
peer text is closed at its owner:

- Every client this plugin builds logs nothing: `off` on the organization client and `none` on an
  instance client, which outranks `LIMRUN_LOG`, so the SDK cannot write a failed response body that
  carries an account key or an instance token.
- The scrubber drops a credential however brief — the reader of an attached instance accepts any
  nonempty token — and takes the credential out of both a header value and its bare credential.
- A download publishes its typed reason, its status and a transport code: no URL, no peer body, and
  no fetch message, since an attached instance answers with its token as the download URL.
- An account-API failure is re-raised as an `AppError` carrying status and reason before a create,
  an asset list, a recovery list, a reconnect lookup or a delete records or returns it, keeping the
  404 answer a caller acts on. A termination reason is bounded to one line and scrubbed.
- The runner's forwarded credential reaches its response, its cause and its log redaction boundary,
  including a credential split across stream chunks, and a `/sync` field this upload did not name
  stays out of the upload failure.
- An instance client's own failures are answered through one wrapper, so `listApps`, `pressKey` and
  a remote install cannot return the peer's frame with the session token in it. Only a failure that
  names a sent value is re-raised, so a clean SDK failure keeps the reason and cause the command
  that caught it publishes.

* fix(limrun): scrub authenticated peer failures at provider boundaries

* fix(limrun): redact diagnostics without changing runner replies

* fix(limrun): preserve classified replies while redacting diagnostics

* fix(limrun): use the shared provider diagnostics facet

* fix(plugins): compose device capabilities in the root runtime
hannojg pushed a commit to hannojg/agent-device that referenced this pull request Nov 23, 2026
…lstack#4846)

* refactor(limrun): ship Limrun as the @agent-device/limrun plugin

Limrun leaves the core package. The runtime, the connection, the iOS runner
orchestration, the file download and the Limrun SDK dependency now live in
packages/provider-limrun, published as @agent-device/limrun and installed
through `agent-device plugins add`.

- Core adds device capabilities to every provider `setup` host: the Android
  lease interactor and ADB mechanics, the shared Apple XCTest runner with its
  tool-provider scope, and the host's retry and archive mechanics. Each facet
  loads on first use.
- The Android interactor is the core-owned one, bound to the lease's
  provider-owned executor. A host that supplies no capabilities gets a typed
  `provider_host_capability_missing` failure.
- `connect limrun` without the plugin answers `plugin-not-installed` with the
  install command. The built-in candidate, its reserved id and the
  `@limrun/api` bundling are removed.

Part of callstack#3311

* chore(gates): admit the Limrun plugin package and its own SDK dependency

The Limrun package publishes its own artifact and installs `@limrun/api`
itself, so the root matches only the dependency ranges it also declares.
The packed-plugin check reads a plugin's own dependencies from its fixture.
The root module zones drop the removed built-in provider modules and place
the provider host capabilities with the platform runtime host.

* fix(connection): forget an ended lease without loading the provider plugin

`close` and `session` skip connection materialization, so they never load
the plugin store. The ended-lease check read the provider's declaration
from that store and kept the stored lease of an installed Limrun plugin.

`connect` and connection materialization now record the declaration on the
stored connection. The ended-lease check reads the recorded value, so it
needs no plugin, installed or not.

Part of callstack#3311

* fix(connection): keep a recorded ended-lease policy as the authority

A device command after the provider's plugin was uninstalled read the
plugin-less default and persisted `false` over a recorded `true`. The
policy is now recorded once, from the provider's own declaration, and a
provider whose plugin is not loaded records nothing.

Part of callstack#3311

* fix(connection): read an unrecorded ended-lease policy from the plugin catalog

A connection stored before the policy was recorded has no value, and
`close` loads no plugin store, so it kept an ended Limrun lease. The
plugin catalog now carries a copy of the plugin's declaration. One lookup
answers without loading a plugin: the provider's own declaration, then the
catalog. A recorded value stays the authority. A test holds the catalog
equal to the declarations of the workspace plugins.

Part of callstack#3311

* fix(connection): answer the ended-lease policy at the point of use

Recording the policy on the stored connection made materialization write a
named connection and repoint the active-session pointer on an upgraded
state directory. The stored field, its writer and the extra state write
are removed. The ended-lease check asks the one lookup that needs no
plugin: the provider's loaded declaration, then the plugin catalog. A
record that still carries the field reads as before.

Part of callstack#3311

* fix(connect): admit the provider plugin before authentication and before cloud state

`connect cloud` saved a Limrun session when the control plane chose Limrun
and the plugin was missing. The provider the cloud response names is now
admitted after the fetch and before the profile or any state is written.

`connect --remote-config` and device commands that materialize a
connection started remote authentication before the provider check. The
provider is now admitted first, so a missing plugin answers with its
install command and no login starts. Cleanup commands admit no provider.

Part of callstack#3311

* fix(auth): keep a new connect login in memory until its provider is admitted

`connect` approved a device login and wrote `auth/cli-session.json` before
cloud profile discovery named the provider. With Limrun chosen and its
plugin missing, the refused route left new auth state behind.

A login `connect` approves is now pending in the auth-session owner. The
cloud profile route stores it after it admits the discovered provider, and
`connect` stores it after its provider profile resolves. This covers
`connect cloud`, plain `connect`, and the route where `--daemon-base-url`
starts login in the generic auth step. `auth login` stores at once, as
before.

Part of callstack#3311

* refactor(connection): read the connection provider from one helper

Admission read the remote config profile's provider first and
materialization read the stored connection's first. Both now call
`connectionLeaseProvider`: the stored connection's provider, then the
profile's. The unprimed `close` test no longer rewrites records with a
field no released build wrote, and its name states the catalog route.

Part of callstack#3311

* fix(auth): store a pending login unless the provider plugin is refused

A `connect` that approved a device login and then failed for any reason
other than provider admission, such as a failed profile fetch, stored no
login, so every retry started device auth again.

The login-bearing part of a command now runs in one login scope. A login
approved inside it is stored when the command ends, on success or on
failure. Only the typed `plugin-not-installed` refusal discards it. The
scope is per command invocation, so a pending login cannot reach another
command in the same process. The per-site commits are removed.

Part of callstack#3311

* fix(connect): hold a login only until its provider is admitted

A `connect` saved a login it approved before it knew the provider that
login was for, so a run whose Limrun plugin was missing reported success
and kept a session it could not use. A pending login now exists only
between its approval and the provider admission of that same run: the
cloud-discovery route saves it right after the provider check, and a
route whose provider is already known saves it in its auth step. No
command-wide finalizer defers anything else, so explicit `auth login`
saves before it reports success.

The plugin store is read through `@agent-device/contracts` reasons, so
both `plugin-not-installed` and `plugin-unavailable` discard the pending
login and keep the install or store-repair diagnostic.

The core ships no Limrun runtime, so Limrun is the only provider the CLI
admits itself: it answers from the positional or the `--remote-config`
profile before that run resolves a credential-bearing option or
registers one for redaction. A named provider the core can supply, such
as BrowserStack, keeps the admission of its connect handler, and a
discovered profile keeps the cloud adapter that reads it.

Part of callstack#3311

* test(connect): name the new tests for the modules they pin

R84 test-colocation judges a unit test against the modules beside it.
`auth-login-write-timing.test.ts` sits in `src/cli/__tests__`, where no
module is named `auth-login-write-timing`, and
`connect-provider-credential-order.test.ts` sits in `src/cli/connection`
with no such module either. Each is renamed for the module whose behavior
it pins: `auth-session.ts` holds the login save timing, and
`provider-admission.ts` owns the admission that precedes the credential.

Part of callstack#3311

* test(cli): drop an unused helper export

* perf(cli): load the connect preflight and pre-command failure modules on demand

* chore(release): make @agent-device/limrun public

* fix(cli): keep a deferred cloud login from overwriting newer auth state

A `connect` that learns its provider from the control plane holds the login it
approves until that provider is admitted. An explicit `auth login` or `auth
logout` completed in that gap was overwritten when the connect resumed, so the
older approval won and a logout left the state directory signed in.

Every write of one state directory's auth state now passes one guard: a
revision record beside the session it governs, republished by each write. A
held login reads that revision before its device authorization and saves only
while it still stands, which logs the stand-down rather than failing the
command. The record counts writes rather than reading the stored session,
because a logout leaves no session, which is what a first login finds too.

Name the Limrun plugin in the README Cloud / remote install instruction, since
a clean core install refuses a Limrun profile without it.

Refs callstack#4846 (review 7068516663)

* refactor(cli): save a connect login when it is approved, as on the base

Remove the deferred-login scope and the auth revision record. A login is
written when the cloud approves it, so explicit auth commands and concurrent
connects keep the base ordering. The cloud route still admits a discovered
Limrun provider before it generates a profile or connection record.

* docs(website): list Limrun with the plugin providers on the Run anywhere card

* fix(website): install the Limrun plugin the 0.22 nightly reader needs

The Run anywhere card printed the bare package name, which the plugin store
resolves to latest: the runtime-free placeholder. Use the nightly selector the
docs and the CLI hints use, and point readers at the printed command.

* fix(cli): let a remote daemon answer for a provider this host lacks

A saved or explicit Limrun connection whose daemon is configured elsewhere was
refused with plugin-not-installed before it authenticated or dispatched, which
no base release did. The plugin is needed where the device is driven: keep the
refusal for a direct connect and for a connection with no configured daemon, and
let the daemon's own provider registration decide runtime admission otherwise.
The connection's metadata is still read and saved either way.

* fix(provider-limrun): keep a verification failure's cause in the plugin

The Limrun SDK echoes a request body in its error message, so an endpoint that
answers a verification with an unlabeled body naming the API key put that key in
the cause the CLI prints, which pattern redaction cannot see. Answer with the
typed verification error, its status and hint, and carry no cause.

* fix(provider-limrun): strip the instance token from error details

An instance that answers an authenticated download or an XCTest start with an
unlabeled body naming the bearer token it was given put that token in the error
details the daemon publishes. Remove each value sent to the endpoint from the
response text before publishing it; the status and typed reason answer for the
failure.

* fix(cli): keep a provider's lease policy on every route

A remote Limrun connection whose host has no plugin was answered from generic remote
capabilities, so `apps` allocated a lease, `lease_allocate` sent the daemon's default TTL,
and `open <app>` dropped the initial app. The plugin catalog now carries the provider's whole
declared `ConnectionProviderCapabilities` and its admission policy, and `declaredConnectionCapabilities`
falls back to that copy before the daemon's own routing, so a connection's lease policy is its
provider's whether or not this host loads the plugin.

The predicate, its without-refusal variant and the three duplicated if/else sites collapse into
`admitProviderForRoute(provider, route, env)`, which primes the store, refuses only where this host
must supply the provider, and answers capabilities from the plugin when loaded, else from the
catalog. `providerRouteForConnection` reads the same two settings the daemon client reads.

* fix(provider-limrun): keep credentials out of published errors

The SDK, an attached instance and a forwarding service in front of one all answer with their own
text, and this plugin authenticates each of them with an account key or an instance token. An
unlabelled echo of a bare credential survives core's pattern redaction, so each path that published
peer text is closed at its owner:

- Every client this plugin builds logs nothing: `off` on the organization client and `none` on an
  instance client, which outranks `LIMRUN_LOG`, so the SDK cannot write a failed response body that
  carries an account key or an instance token.
- The scrubber drops a credential however brief — the reader of an attached instance accepts any
  nonempty token — and takes the credential out of both a header value and its bare credential.
- A download publishes its typed reason, its status and a transport code: no URL, no peer body, and
  no fetch message, since an attached instance answers with its token as the download URL.
- An account-API failure is re-raised as an `AppError` carrying status and reason before a create,
  an asset list, a recovery list, a reconnect lookup or a delete records or returns it, keeping the
  404 answer a caller acts on. A termination reason is bounded to one line and scrubbed.
- The runner's forwarded credential reaches its response, its cause and its log redaction boundary,
  including a credential split across stream chunks, and a `/sync` field this upload did not name
  stays out of the upload failure.
- An instance client's own failures are answered through one wrapper, so `listApps`, `pressKey` and
  a remote install cannot return the peer's frame with the session token in it. Only a failure that
  names a sent value is re-raised, so a clean SDK failure keeps the reason and cause the command
  that caught it publishes.

* fix(limrun): scrub authenticated peer failures at provider boundaries

* fix(limrun): redact diagnostics without changing runner replies

* fix(limrun): preserve classified replies while redacting diagnostics

* fix(limrun): use the shared provider diagnostics facet

* fix(plugins): compose device capabilities in the root runtime
thymikee added a commit that referenced this pull request Nov 24, 2026
* refactor(limrun): ship Limrun as the @agent-device/limrun plugin

Limrun leaves the core package. The runtime, the connection, the iOS runner
orchestration, the file download and the Limrun SDK dependency now live in
packages/provider-limrun, published as @agent-device/limrun and installed
through `agent-device plugins add`.

- Core adds device capabilities to every provider `setup` host: the Android
  lease interactor and ADB mechanics, the shared Apple XCTest runner with its
  tool-provider scope, and the host's retry and archive mechanics. Each facet
  loads on first use.
- The Android interactor is the core-owned one, bound to the lease's
  provider-owned executor. A host that supplies no capabilities gets a typed
  `provider_host_capability_missing` failure.
- `connect limrun` without the plugin answers `plugin-not-installed` with the
  install command. The built-in candidate, its reserved id and the
  `@limrun/api` bundling are removed.

Part of #3311

* chore(gates): admit the Limrun plugin package and its own SDK dependency

The Limrun package publishes its own artifact and installs `@limrun/api`
itself, so the root matches only the dependency ranges it also declares.
The packed-plugin check reads a plugin's own dependencies from its fixture.
The root module zones drop the removed built-in provider modules and place
the provider host capabilities with the platform runtime host.

* fix(connection): forget an ended lease without loading the provider plugin

`close` and `session` skip connection materialization, so they never load
the plugin store. The ended-lease check read the provider's declaration
from that store and kept the stored lease of an installed Limrun plugin.

`connect` and connection materialization now record the declaration on the
stored connection. The ended-lease check reads the recorded value, so it
needs no plugin, installed or not.

Part of #3311

* fix(connection): keep a recorded ended-lease policy as the authority

A device command after the provider's plugin was uninstalled read the
plugin-less default and persisted `false` over a recorded `true`. The
policy is now recorded once, from the provider's own declaration, and a
provider whose plugin is not loaded records nothing.

Part of #3311

* fix(connection): read an unrecorded ended-lease policy from the plugin catalog

A connection stored before the policy was recorded has no value, and
`close` loads no plugin store, so it kept an ended Limrun lease. The
plugin catalog now carries a copy of the plugin's declaration. One lookup
answers without loading a plugin: the provider's own declaration, then the
catalog. A recorded value stays the authority. A test holds the catalog
equal to the declarations of the workspace plugins.

Part of #3311

* fix(connection): answer the ended-lease policy at the point of use

Recording the policy on the stored connection made materialization write a
named connection and repoint the active-session pointer on an upgraded
state directory. The stored field, its writer and the extra state write
are removed. The ended-lease check asks the one lookup that needs no
plugin: the provider's loaded declaration, then the plugin catalog. A
record that still carries the field reads as before.

Part of #3311

* fix(connect): admit the provider plugin before authentication and before cloud state

`connect cloud` saved a Limrun session when the control plane chose Limrun
and the plugin was missing. The provider the cloud response names is now
admitted after the fetch and before the profile or any state is written.

`connect --remote-config` and device commands that materialize a
connection started remote authentication before the provider check. The
provider is now admitted first, so a missing plugin answers with its
install command and no login starts. Cleanup commands admit no provider.

Part of #3311

* fix(auth): keep a new connect login in memory until its provider is admitted

`connect` approved a device login and wrote `auth/cli-session.json` before
cloud profile discovery named the provider. With Limrun chosen and its
plugin missing, the refused route left new auth state behind.

A login `connect` approves is now pending in the auth-session owner. The
cloud profile route stores it after it admits the discovered provider, and
`connect` stores it after its provider profile resolves. This covers
`connect cloud`, plain `connect`, and the route where `--daemon-base-url`
starts login in the generic auth step. `auth login` stores at once, as
before.

Part of #3311

* refactor(connection): read the connection provider from one helper

Admission read the remote config profile's provider first and
materialization read the stored connection's first. Both now call
`connectionLeaseProvider`: the stored connection's provider, then the
profile's. The unprimed `close` test no longer rewrites records with a
field no released build wrote, and its name states the catalog route.

Part of #3311

* fix(auth): store a pending login unless the provider plugin is refused

A `connect` that approved a device login and then failed for any reason
other than provider admission, such as a failed profile fetch, stored no
login, so every retry started device auth again.

The login-bearing part of a command now runs in one login scope. A login
approved inside it is stored when the command ends, on success or on
failure. Only the typed `plugin-not-installed` refusal discards it. The
scope is per command invocation, so a pending login cannot reach another
command in the same process. The per-site commits are removed.

Part of #3311

* fix(connect): hold a login only until its provider is admitted

A `connect` saved a login it approved before it knew the provider that
login was for, so a run whose Limrun plugin was missing reported success
and kept a session it could not use. A pending login now exists only
between its approval and the provider admission of that same run: the
cloud-discovery route saves it right after the provider check, and a
route whose provider is already known saves it in its auth step. No
command-wide finalizer defers anything else, so explicit `auth login`
saves before it reports success.

The plugin store is read through `@agent-device/contracts` reasons, so
both `plugin-not-installed` and `plugin-unavailable` discard the pending
login and keep the install or store-repair diagnostic.

The core ships no Limrun runtime, so Limrun is the only provider the CLI
admits itself: it answers from the positional or the `--remote-config`
profile before that run resolves a credential-bearing option or
registers one for redaction. A named provider the core can supply, such
as BrowserStack, keeps the admission of its connect handler, and a
discovered profile keeps the cloud adapter that reads it.

Part of #3311

* test(connect): name the new tests for the modules they pin

R84 test-colocation judges a unit test against the modules beside it.
`auth-login-write-timing.test.ts` sits in `src/cli/__tests__`, where no
module is named `auth-login-write-timing`, and
`connect-provider-credential-order.test.ts` sits in `src/cli/connection`
with no such module either. Each is renamed for the module whose behavior
it pins: `auth-session.ts` holds the login save timing, and
`provider-admission.ts` owns the admission that precedes the credential.

Part of #3311

* test(cli): drop an unused helper export

* perf(cli): load the connect preflight and pre-command failure modules on demand

* chore(release): make @agent-device/limrun public

* fix(cli): keep a deferred cloud login from overwriting newer auth state

A `connect` that learns its provider from the control plane holds the login it
approves until that provider is admitted. An explicit `auth login` or `auth
logout` completed in that gap was overwritten when the connect resumed, so the
older approval won and a logout left the state directory signed in.

Every write of one state directory's auth state now passes one guard: a
revision record beside the session it governs, republished by each write. A
held login reads that revision before its device authorization and saves only
while it still stands, which logs the stand-down rather than failing the
command. The record counts writes rather than reading the stored session,
because a logout leaves no session, which is what a first login finds too.

Name the Limrun plugin in the README Cloud / remote install instruction, since
a clean core install refuses a Limrun profile without it.

Refs #4846 (review 7068516663)

* refactor(cli): save a connect login when it is approved, as on the base

Remove the deferred-login scope and the auth revision record. A login is
written when the cloud approves it, so explicit auth commands and concurrent
connects keep the base ordering. The cloud route still admits a discovered
Limrun provider before it generates a profile or connection record.

* docs(website): list Limrun with the plugin providers on the Run anywhere card

* fix(website): install the Limrun plugin the 0.22 nightly reader needs

The Run anywhere card printed the bare package name, which the plugin store
resolves to latest: the runtime-free placeholder. Use the nightly selector the
docs and the CLI hints use, and point readers at the printed command.

* fix(cli): let a remote daemon answer for a provider this host lacks

A saved or explicit Limrun connection whose daemon is configured elsewhere was
refused with plugin-not-installed before it authenticated or dispatched, which
no base release did. The plugin is needed where the device is driven: keep the
refusal for a direct connect and for a connection with no configured daemon, and
let the daemon's own provider registration decide runtime admission otherwise.
The connection's metadata is still read and saved either way.

* fix(provider-limrun): keep a verification failure's cause in the plugin

The Limrun SDK echoes a request body in its error message, so an endpoint that
answers a verification with an unlabeled body naming the API key put that key in
the cause the CLI prints, which pattern redaction cannot see. Answer with the
typed verification error, its status and hint, and carry no cause.

* fix(provider-limrun): strip the instance token from error details

An instance that answers an authenticated download or an XCTest start with an
unlabeled body naming the bearer token it was given put that token in the error
details the daemon publishes. Remove each value sent to the endpoint from the
response text before publishing it; the status and typed reason answer for the
failure.

* fix(cli): keep a provider's lease policy on every route

A remote Limrun connection whose host has no plugin was answered from generic remote
capabilities, so `apps` allocated a lease, `lease_allocate` sent the daemon's default TTL,
and `open <app>` dropped the initial app. The plugin catalog now carries the provider's whole
declared `ConnectionProviderCapabilities` and its admission policy, and `declaredConnectionCapabilities`
falls back to that copy before the daemon's own routing, so a connection's lease policy is its
provider's whether or not this host loads the plugin.

The predicate, its without-refusal variant and the three duplicated if/else sites collapse into
`admitProviderForRoute(provider, route, env)`, which primes the store, refuses only where this host
must supply the provider, and answers capabilities from the plugin when loaded, else from the
catalog. `providerRouteForConnection` reads the same two settings the daemon client reads.

* fix(provider-limrun): keep credentials out of published errors

The SDK, an attached instance and a forwarding service in front of one all answer with their own
text, and this plugin authenticates each of them with an account key or an instance token. An
unlabelled echo of a bare credential survives core's pattern redaction, so each path that published
peer text is closed at its owner:

- Every client this plugin builds logs nothing: `off` on the organization client and `none` on an
  instance client, which outranks `LIMRUN_LOG`, so the SDK cannot write a failed response body that
  carries an account key or an instance token.
- The scrubber drops a credential however brief — the reader of an attached instance accepts any
  nonempty token — and takes the credential out of both a header value and its bare credential.
- A download publishes its typed reason, its status and a transport code: no URL, no peer body, and
  no fetch message, since an attached instance answers with its token as the download URL.
- An account-API failure is re-raised as an `AppError` carrying status and reason before a create,
  an asset list, a recovery list, a reconnect lookup or a delete records or returns it, keeping the
  404 answer a caller acts on. A termination reason is bounded to one line and scrubbed.
- The runner's forwarded credential reaches its response, its cause and its log redaction boundary,
  including a credential split across stream chunks, and a `/sync` field this upload did not name
  stays out of the upload failure.
- An instance client's own failures are answered through one wrapper, so `listApps`, `pressKey` and
  a remote install cannot return the peer's frame with the session token in it. Only a failure that
  names a sent value is re-raised, so a clean SDK failure keeps the reason and cause the command
  that caught it publishes.

* fix(limrun): scrub authenticated peer failures at provider boundaries

* fix(limrun): redact diagnostics without changing runner replies

* fix(limrun): preserve classified replies while redacting diagnostics

* fix(limrun): use the shared provider diagnostics facet

* fix(plugins): compose device capabilities in the root runtime
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.

1 participant