Skip to content

Commit c7a089d

Browse files
thymikeeclaude
andcommitted
fix(revyl): keep a shared start running when its first caller hangs up
The Revyl driver passed the starting caller's signal into the start, so that caller's cancellation ended readiness for every caller that joined it. The start now gets only the caller's deadline; the table stops the device once it is ready if no caller still wants it. A lease without a Revyl platform is refused with a typed error, the fixture ignores only a bare `GET /` probe, and the table documents which waits it bounds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b25dc6c commit c7a089d

5 files changed

Lines changed: 43 additions & 9 deletions

File tree

‎packages/contracts/src/platform-runtime.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export function providerRuntimeOwner(
7777
});
7878
}
7979

80-
// Changing the key length or the scrypt cost re-identifies every derived instance; an explicit
81-
// instance a composition names, such as Limrun's `runtimeInstance`, is unaffected. For a provider that
80+
// Changing the key length or the scrypt cost re-identifies every derived instance; an instance a
81+
// composition names outright, such as Limrun's `runtimeInstance` option, is not derived here at all. For a provider that
8282
// writes its instance into durable state, such as Limrun's app-log descriptors, that orphans every such
8383
// resource; Revyl keeps its instance in-process only. Each provider pins its own digest through the
8484
// wrapper that builds its principal.

‎packages/provider-revyl/src/revyl-backend.fixtures.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ export async function startRevylFixtureBackend(
121121
const raw = Buffer.concat(chunks).toString('utf8');
122122
const url = request.url ?? '/';
123123
const method = request.method ?? 'GET';
124-
// The fixture listens on an ephemeral localhost port that any process on the host can reach. A
125-
// request outside Revyl's API is not the runtime's, so it is not recorded as one of its calls.
126-
if (!url.startsWith('/api/')) {
124+
// The fixture listens on an ephemeral localhost port that any process on the host can reach, and a
125+
// bare `GET /` probe from one is not the runtime's call. Any other path is recorded, so a client
126+
// that leaves Revyl's API still shows up in the assertions.
127+
if (method === 'GET' && url === '/') {
127128
response.writeHead(404).end();
128129
return;
129130
}

‎packages/provider-revyl/src/runtime.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,29 @@ test('a canceled joiner reports its own cancellation while the shared start runs
191191
]);
192192
});
193193

194+
test('a joiner keeps the device when the caller that started it hangs up mid-readiness', async () => {
195+
// The start belongs to every caller that joined it, so the first caller's cancellation answers only
196+
// that caller: readiness goes on, and the caller still waiting gets the device.
197+
const fixture = await backend({ healthDelayMs: 200 });
198+
const runtime = fixture.createRuntime();
199+
const lease = revylLease('ios');
200+
const controller = new AbortController();
201+
const first = runtime.leaseLifecycle!.allocate!(lease, { signal: controller.signal });
202+
const firstCanceled = assert.rejects(
203+
async () => await first,
204+
(error: unknown) => error instanceof AppError && error.details?.reason === 'request_canceled',
205+
);
206+
const joining = runtime.leaseLifecycle!.allocate!(lease);
207+
await waitFor(() => fixture.paths().some((path) => path.endsWith('/health')));
208+
controller.abort();
209+
await firstCanceled;
210+
211+
assert.equal((await joining)?.providerSessionId, revylSessionIdForLease('lease-1'));
212+
assert.deepEqual(stops(fixture), []);
213+
await runtime.shutdown();
214+
assert.deepEqual(stops(fixture), [stopPathFor('lease-1')]);
215+
});
216+
194217
test('a release that lands while the shared start is still running stops the device it rents', async () => {
195218
// The daemon drops the lease the moment its caller is gone, and a canceled joiner is gone: this release
196219
// arrives while the caller that started the device is still waiting for it. The session is not in the

‎packages/provider-revyl/src/runtime.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ function createRevylLeaseDriver(
226226
appUrl: request.appUrl,
227227
deviceModel: request.deviceModel,
228228
osVersion: request.osVersion,
229-
...control.caller,
229+
// The starting caller's signal is not passed on: callers that joined still want the device, and
230+
// the table stops it if nobody does once it is ready.
231+
...(control.caller.deadline === undefined ? {} : { deadline: control.caller.deadline }),
230232
});
231233
if (started.status === 'failed') return started;
232234
const { runId, sessionId } = started.session;
@@ -284,7 +286,13 @@ function revylCleanupDetails(scope: ProviderLeaseCleanupScope): Record<string, u
284286
/** The platform of a lease the runtime already admitted as Revyl's. */
285287
function revylLeasePlatform(lease: DeviceLease): RevylPlatform {
286288
const platform = platformForRevylLeaseBackend(lease.backend);
287-
if (platform === undefined) throw new TypeError(`Revyl lease ${lease.leaseId} has no platform`);
289+
if (platform === undefined) {
290+
throw new AppError('UNSUPPORTED_OPERATION', 'Revyl cannot serve this lease.', {
291+
leaseId: lease.leaseId,
292+
leaseProvider: lease.leaseProvider,
293+
leaseBackend: lease.backend,
294+
});
295+
}
288296
return platform;
289297
}
290298

‎packages/provision-kit/src/provider-lease-table.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export type ProviderLeaseAllocateOptions<Request> = ProviderLeaseBudget &
2828

2929
export type ProviderLeaseStartControl<Handle> = Readonly<{
3030
/**
31-
* The budget of the caller that registered the start, as it asked. The start runs for every caller that
32-
* joins it, so this caller's signal and deadline bound the provider's own work.
31+
* The budget of the caller that registered the start, as it asked. Its deadline bounds the provider's
32+
* own work. Its signal belongs to that caller alone: the start runs for every caller that joins it, so
33+
* a provider that ends the start on that signal takes the device from callers still waiting.
3334
*/
3435
caller: ProviderLeaseBudget;
3536
/** Epoch-ms by which the start should answer: the caller's deadline, cut to `startTimeoutMs`. */
@@ -76,6 +77,7 @@ export type ProviderLeaseDriver<Session, Handle, Request> = Readonly<{
7677
/**
7778
* How long one teardown waits for a stop to answer. A stop that outlives it is reported as unconfirmed,
7879
* and the next teardown joins the same stop instead of sending a second one. Unset waits for the answer.
80+
* Only the stop is bounded here; `findByLease` answers within the provider's own request budget.
7981
*/
8082
stopTimeoutMs?: number;
8183
start(

0 commit comments

Comments
 (0)