Skip to content

Commit bfeeb8b

Browse files
committed
fix(limrun): keep daemon boot independent of Limrun attach config
A partial LIM_* instance set no longer stops the daemon: composition skips the Limrun runtime, reports it, and the daemon logs provider_runtime_skipped while every other provider loads. CLI connect still fails fast. Sessions and app-log descriptors carry a typed ownership ('created' or 'attached') instead of an attached- id prefix check; descriptors persisted before the field decode as created. The attached id helper moves into device.ts, so the provider entry evaluates no extra module. Expired-lease recovery is guarded on the API key, the connect message states its daemon condition, and the runtime test resets runCmd between tests.
1 parent 924e202 commit bfeeb8b

22 files changed

Lines changed: 219 additions & 111 deletions

‎packages/provider-limrun/src/android.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {
2121
LimrunRuntimeDependencies,
2222
} from './runtime-dependencies.ts';
2323
import type { AndroidAdbInvocation } from '@agent-device/platform-android/mechanics';
24-
import { isAttachedLimrunInstanceId } from './instance-access.ts';
24+
import type { LimrunInstanceOwnership } from './instance-access.ts';
2525
import { normalizeOptionalString } from './strings.ts';
2626
import {
2727
awaitLimrunDeploymentOperation,
@@ -34,6 +34,7 @@ type LimrunAndroidAdbSession = {
3434
platform: 'android';
3535
lease: DeviceLease;
3636
instanceId: string;
37+
readonly ownership: LimrunInstanceOwnership;
3738
device: DeviceInfo;
3839
client: LimrunAndroidClient;
3940
/** Instance bearer token; the recording download the SDK would run inline is done by the host instead. */
@@ -52,6 +53,7 @@ export async function createLimrunAndroidSession(
5253
options: {
5354
lease: DeviceLease;
5455
instanceId: string;
56+
ownership: LimrunInstanceOwnership;
5557
device: DeviceInfo;
5658
apiUrl: string;
5759
adbUrl: string;
@@ -69,6 +71,7 @@ export async function createLimrunAndroidSession(
6971
platform: 'android',
7072
lease: options.lease,
7173
instanceId: options.instanceId,
74+
ownership: options.ownership,
7275
device: options.device,
7376
client,
7477
token: options.token,
@@ -166,7 +169,7 @@ async function cleanupAndroidPortReverse(session: LimrunAndroidSession): Promise
166169
const mappings = await reverse.list().catch(() => []);
167170
const owners = new Set<string>();
168171
const unownedLocals: LimrunPortReverseEndpoint[] = [];
169-
const sharedDevice = isAttachedLimrunInstanceId(session.instanceId);
172+
const sharedDevice = session.ownership === 'attached';
170173
for (const mapping of mappings) {
171174
if (mapping.ownerId) owners.add(mapping.ownerId);
172175
else if (!sharedDevice) unownedLocals.push(mapping.local);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { expect, test } from 'vitest';
2+
import { limrunAppLogDescriptorCodec } from './app-log-descriptor.ts';
3+
4+
const body = {
5+
transport: 'limrun-log-poller',
6+
platform: 'ios',
7+
leaseId: 'lease-a',
8+
instanceId: 'ios_instance',
9+
appBundleId: 'com.example.app',
10+
outputPath: '/sessions/one/app.log',
11+
};
12+
13+
test('decodes descriptors written before ownership as created instances', () => {
14+
expect(limrunAppLogDescriptorCodec.decode(body)).toMatchObject({
15+
status: 'decoded',
16+
descriptor: { ownership: 'created' },
17+
});
18+
expect(limrunAppLogDescriptorCodec.decode({ ...body, ownership: 'attached' })).toMatchObject({
19+
status: 'decoded',
20+
descriptor: { ownership: 'attached' },
21+
});
22+
expect(limrunAppLogDescriptorCodec.decode({ ...body, ownership: 'borrowed' }).status).toBe(
23+
'invalid',
24+
);
25+
});

‎packages/provider-limrun/src/app-log-descriptor.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import type {
66
import type { RuntimeOwnerRef } from '@agent-device/contracts/platform-runtime';
77
import { APP_LOG_RESOURCE_KIND } from '@agent-device/contracts/app-log-runtime';
88
import { createDurableResourceEnvelope, encodeDurableDescriptor } from '@agent-device/capture-kit';
9+
import type { LimrunInstanceOwnership } from './instance-access.ts';
910

1011
export type LimrunAppLogDescriptor = Readonly<{
1112
transport: 'limrun-log-poller';
1213
platform: 'ios' | 'android';
1314
leaseId: string;
1415
instanceId: string;
16+
ownership: LimrunInstanceOwnership;
1517
appBundleId: string;
1618
outputPath: string;
1719
}>;
@@ -24,7 +26,9 @@ export const limrunAppLogDescriptorCodec: DurableDescriptorCodec<
2426
version: 1,
2527
encode: (descriptor) => ({ ...descriptor }),
2628
decode: (body) => {
29+
const ownership = decodeOwnership(body.ownership);
2730
if (
31+
!ownership ||
2832
body.transport !== 'limrun-log-poller' ||
2933
(body.platform !== 'ios' && body.platform !== 'android') ||
3034
!isNonEmptyString(body.leaseId) ||
@@ -41,6 +45,7 @@ export const limrunAppLogDescriptorCodec: DurableDescriptorCodec<
4145
platform: body.platform,
4246
leaseId: body.leaseId,
4347
instanceId: body.instanceId,
48+
ownership,
4449
appBundleId: body.appBundleId,
4550
outputPath: body.outputPath,
4651
}),
@@ -78,6 +83,12 @@ export function createLimrunAppLogEnvelope(input: {
7883
});
7984
}
8085

86+
/** Descriptors written before attach support carry no ownership; those named created instances. */
87+
function decodeOwnership(value: unknown): LimrunInstanceOwnership | undefined {
88+
if (value === undefined) return 'created';
89+
return value === 'created' || value === 'attached' ? value : undefined;
90+
}
91+
8192
function isNonEmptyString(value: unknown): value is string {
8293
return typeof value === 'string' && value.trim().length > 0;
8394
}

‎packages/provider-limrun/src/app-log-poller.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('Limrun app-log poller', () => {
1212
platform: 'ios',
1313
leaseId: 'lease-1',
1414
instanceId: 'instance-1',
15+
ownership: 'created',
1516
readLogs: vi.fn(async () => 'old line\nshared\nnew line\n'),
1617
[Symbol.asyncDispose]: async () => {
1718
readerDisposed = true;
@@ -50,6 +51,7 @@ describe('Limrun app-log poller', () => {
5051
platform: 'ios',
5152
leaseId: 'lease-1',
5253
instanceId: 'instance-1',
54+
ownership: 'created',
5355
readLogs: async () => '',
5456
[Symbol.asyncDispose]: dispose,
5557
};
@@ -78,6 +80,7 @@ describe('Limrun app-log poller', () => {
7880
platform: 'ios',
7981
leaseId: 'lease-1',
8082
instanceId: 'instance-1',
83+
ownership: 'created',
8184
readLogs: async () => `${'b'.repeat(240_000)}\n`,
8285
[Symbol.asyncDispose]: async () => {},
8386
};
@@ -100,6 +103,7 @@ describe('Limrun app-log poller', () => {
100103
platform: 'ios',
101104
leaseId: 'lease-1',
102105
instanceId: 'instance-1',
106+
ownership: 'created',
103107
readLogs: async () => '',
104108
[Symbol.asyncDispose]: async () => {
105109
throw new Error('reader cleanup failed');
@@ -132,6 +136,7 @@ describe('Limrun app-log poller', () => {
132136
platform: 'android',
133137
leaseId: 'lease-1',
134138
instanceId: 'instance-1',
139+
ownership: 'created',
135140
readLogs: vi.fn(async () => await new Promise<string>(() => {})),
136141
[Symbol.asyncDispose]: async () => {
137142
readerDisposed = true;

‎packages/provider-limrun/src/app-log-poller.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import { AsyncCleanupStack } from '@agent-device/contracts/async-lifecycle';
99
import { createAppLogLiveHandleFromFinish } from '@agent-device/capture-kit';
1010
import type { LogBackend } from '@agent-device/contracts/observability';
1111
import { awaitLimrunOperation } from './request-cancellation.ts';
12+
import type { LimrunInstanceOwnership } from './instance-access.ts';
1213

1314
export type LimrunAppLogReader = AsyncDisposable &
1415
Readonly<{
1516
platform: 'ios' | 'android';
1617
leaseId: string;
1718
instanceId: string;
19+
ownership: LimrunInstanceOwnership;
1820
readLogs(appBundleId: string, lineLimit: number): Promise<string>;
1921
}>;
2022

‎packages/provider-limrun/src/app-log-reconnect.test.ts‎

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
type AndroidAdbInvocation,
3232
} from '@agent-device/platform-android/mechanics';
3333
import { reconnectLimrunAppLogReader } from './app-log-reconnect.ts';
34-
import { attachedLimrunInstanceId } from './instance-access.ts';
34+
import { attachedLimrunInstanceId } from './device.ts';
3535
import { createInstanceClient as createIosInstanceClient } from '@limrun/api/ios-client';
3636
import type {
3737
LimrunAdbCommandOptions,
@@ -46,17 +46,17 @@ test('reattaches an owned Limrun instance without persisting credentials', async
4646
}));
4747
const signal = new AbortController().signal;
4848
const outcome = await reconnectLimrunAppLogReader({
49-
orgClient: () =>
50-
({
51-
iosInstances: {
52-
get,
53-
},
54-
}) as never,
49+
limrun: {
50+
iosInstances: {
51+
get,
52+
},
53+
} as never,
5554
descriptor: {
5655
transport: 'limrun-log-poller',
5756
platform: 'ios',
5857
leaseId: 'lease-a',
5958
instanceId: 'instance-a',
59+
ownership: 'created',
6060
appBundleId: 'com.example.app',
6161
outputPath: '/sessions/one/app.log',
6262
},
@@ -73,20 +73,20 @@ test('reattaches an owned Limrun instance without persisting credentials', async
7373

7474
test('fails closed when the instance labels do not match the descriptor lease', async () => {
7575
const outcome = await reconnectLimrunAppLogReader({
76-
orgClient: () =>
77-
({
78-
iosInstances: {
79-
get: vi.fn(async () => ({
80-
metadata: { labels: { provider: 'limrun', leaseId: 'another-lease' } },
81-
status: { state: 'ready', apiUrl: 'https://instance', token: 'secret' },
82-
})),
83-
},
84-
}) as never,
76+
limrun: {
77+
iosInstances: {
78+
get: vi.fn(async () => ({
79+
metadata: { labels: { provider: 'limrun', leaseId: 'another-lease' } },
80+
status: { state: 'ready', apiUrl: 'https://instance', token: 'secret' },
81+
})),
82+
},
83+
} as never,
8584
descriptor: {
8685
transport: 'limrun-log-poller',
8786
platform: 'ios',
8887
leaseId: 'lease-a',
8988
instanceId: 'instance-a',
89+
ownership: 'created',
9090
appBundleId: 'com.example.app',
9191
outputPath: '/sessions/one/app.log',
9292
},
@@ -99,25 +99,25 @@ test('disconnects the Android instance client when tunnel acquisition fails', as
9999
androidClient.disconnect.mockClear();
100100
await expect(
101101
reconnectLimrunAppLogReader({
102-
orgClient: () =>
103-
({
104-
androidInstances: {
105-
get: vi.fn(async () => ({
106-
metadata: { labels: { provider: 'limrun', leaseId: 'lease-a' } },
107-
status: {
108-
state: 'ready',
109-
apiUrl: 'https://instance',
110-
adbWebSocketUrl: 'wss://adb',
111-
token: 'secret',
112-
},
113-
})),
114-
},
115-
}) as never,
102+
limrun: {
103+
androidInstances: {
104+
get: vi.fn(async () => ({
105+
metadata: { labels: { provider: 'limrun', leaseId: 'lease-a' } },
106+
status: {
107+
state: 'ready',
108+
apiUrl: 'https://instance',
109+
adbWebSocketUrl: 'wss://adb',
110+
token: 'secret',
111+
},
112+
})),
113+
},
114+
} as never,
116115
descriptor: {
117116
transport: 'limrun-log-poller',
118117
platform: 'android',
119118
leaseId: 'lease-a',
120119
instanceId: 'instance-a',
120+
ownership: 'created',
121121
appBundleId: 'com.example.app',
122122
outputPath: '/sessions/one/app.log',
123123
},
@@ -141,25 +141,25 @@ test('addresses app-log adb traffic at the tunnel serial and hands cleanup a com
141141
}));
142142
androidClient.disconnect.mockClear();
143143
const outcome = await reconnectLimrunAppLogReader({
144-
orgClient: () =>
145-
({
146-
androidInstances: {
147-
get: vi.fn(async () => ({
148-
metadata: { labels: { provider: 'limrun', leaseId: 'lease-a' } },
149-
status: {
150-
state: 'ready',
151-
apiUrl: 'https://instance',
152-
adbWebSocketUrl: 'wss://adb',
153-
token: 'secret',
154-
},
155-
})),
156-
},
157-
}) as never,
144+
limrun: {
145+
androidInstances: {
146+
get: vi.fn(async () => ({
147+
metadata: { labels: { provider: 'limrun', leaseId: 'lease-a' } },
148+
status: {
149+
state: 'ready',
150+
apiUrl: 'https://instance',
151+
adbWebSocketUrl: 'wss://adb',
152+
token: 'secret',
153+
},
154+
})),
155+
},
156+
} as never,
158157
descriptor: {
159158
transport: 'limrun-log-poller',
160159
platform: 'android',
161160
leaseId: 'lease-a',
162161
instanceId: 'instance-a',
162+
ownership: 'created',
163163
appBundleId: 'com.example.app',
164164
outputPath: '/sessions/one/app.log',
165165
},
@@ -218,24 +218,23 @@ test('addresses app-log adb traffic at the tunnel serial and hands cleanup a com
218218

219219
const ATTACHED_ACCESS = { apiUrl: 'https://attached.example/api', token: 'instance-token' };
220220

221-
function attachedDescriptor(instanceId = attachedLimrunInstanceId(ATTACHED_ACCESS.apiUrl)) {
221+
function attachedDescriptor(
222+
instanceId = attachedLimrunInstanceId(ATTACHED_ACCESS.apiUrl),
223+
ownership: 'created' | 'attached' = 'attached',
224+
) {
222225
return {
223226
transport: 'limrun-log-poller',
224227
platform: 'ios',
225228
leaseId: 'lease-a',
226229
instanceId,
230+
ownership,
227231
appBundleId: 'com.example.app',
228232
outputPath: '/sessions/one/app.log',
229233
} as const;
230234
}
231235

232-
function unavailableOrgClient(): never {
233-
throw new Error('the organization API must not be used');
234-
}
235-
236236
test('reattaches app logs to the attached instance the descriptor names', async () => {
237237
const outcome = await reconnectLimrunAppLogReader({
238-
orgClient: unavailableOrgClient,
239238
instances: { ios: ATTACHED_ACCESS },
240239
descriptor: attachedDescriptor(),
241240
dependencies: {} as LimrunRuntimeDependencies,
@@ -247,7 +246,6 @@ test('reattaches app logs to the attached instance the descriptor names', async
247246
expect(outcome.status).toBe('opened');
248247

249248
const replaced = await reconnectLimrunAppLogReader({
250-
orgClient: unavailableOrgClient,
251249
instances: { ios: { ...ATTACHED_ACCESS, apiUrl: 'https://another-instance.example/api' } },
252250
descriptor: attachedDescriptor(),
253251
dependencies: {} as LimrunRuntimeDependencies,
@@ -261,9 +259,9 @@ test('reattaches a created instance through the organization API while another i
261259
status: { state: 'ready', apiUrl: 'https://created.example/api', token: 'created-token' },
262260
}));
263261
const outcome = await reconnectLimrunAppLogReader({
264-
orgClient: () => ({ iosInstances: { get } }) as never,
262+
limrun: { iosInstances: { get } } as never,
265263
instances: { ios: ATTACHED_ACCESS },
266-
descriptor: attachedDescriptor('ios_created_instance'),
264+
descriptor: attachedDescriptor('ios_created_instance', 'created'),
267265
dependencies: {} as LimrunRuntimeDependencies,
268266
});
269267
expect(get).toHaveBeenCalledOnce();
@@ -276,7 +274,6 @@ test('does not connect once the reconnect request is aborted', async () => {
276274
vi.mocked(createIosInstanceClient).mockClear();
277275
await expect(
278276
reconnectLimrunAppLogReader({
279-
orgClient: unavailableOrgClient,
280277
instances: { ios: ATTACHED_ACCESS },
281278
descriptor: attachedDescriptor(),
282279
dependencies: {} as LimrunRuntimeDependencies,

0 commit comments

Comments
 (0)