Skip to content

Commit 3f2fddc

Browse files
committed
fix(daemon): load leased recording retention on demand
- session-teardown.ts imports the retention module only when the session holds a lease, so the daemon entry keeps its merge-base eager closure (eager-closure-budgets, which failed the Coverage job). - The registration-failure rollback removes each file best-effort, so one failed removal does not leak the rest. - The unleased-teardown test also checks the tenant inventory. - Docs: ADR 0007 names close as a teardown that keeps the recording, ADR 0024 scopes forced cleanup to the teardown finish, and the remote-proxy sessionName wording matches the contract.
1 parent c1a4477 commit 3f2fddc

7 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎docs/adr/0007-remote-device-leases.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Idle reap then shuts the daemon down within one more idle window.
7676

7777
A session cannot outlive the lease under which it was opened.
7878
When the lease is released or expires, the daemon tears the session down under its execution locks and clears its device claim.
79-
Teardown finishes an active recording. A finished export at a remote temp path then belongs to the lease's tenant as a downloadable artifact, like the artifact of any `record stop` (ADR 0024 2.5).
79+
Any teardown of a leased session, including `close`, finishes an active recording. A finished export at a remote temp path then belongs to the lease's tenant as a downloadable artifact, like the artifact of any `record stop` (ADR 0024 2.5).
8080
This applies even when the device no longer answers.
8181
A release is a tenant `lease_release` or a host `DELETE /admin/leases/<lease-id>`.
8282
The daemon sweeps for expired leases every second.

‎docs/adr/0024-screen-recording-provable-signal.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ A leased session's teardown that commits an export at a remote temp path registe
346346
The inventory names the session, and the usual delete-after-download and 15-minute expiry apply.
347347
A later `record stop` replay of that manifest serves the same artifact ids.
348348
If registration fails, teardown deletes the files.
349-
A failed finish still runs forced cleanup and registers nothing.
349+
A failed teardown finish still runs forced cleanup (disposal intent) and registers nothing.
350350

351351
### 2.6 Native markers
352352

‎packages/daemon/src/core/session-tenant-scope.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function tenantScopedSessionName(tenant: string, session: string): string
4141
return isTenantOwnedSessionName(tenant, session) ? session : `${tenant}:${session}`;
4242
}
4343

44-
/** The session name the tenant's client used: the inverse of `tenantScopedSessionName`. */
44+
/** The tenant-relative name that addresses this session under tenant scoping. */
4545
export function tenantPublicSessionName(tenant: string, session: string): string {
4646
return isTenantOwnedSessionName(tenant, session) ? session.slice(tenant.length + 1) : session;
4747
}

‎packages/daemon/src/sessions/__tests__/leased-recording-retention.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ test('an unleased session teardown registers nothing for a remote export', async
297297

298298
await teardown(sessionStore);
299299

300+
expect(await listDownloadableArtifacts(TENANT, process.env)).toEqual([]);
300301
expect(await listDownloadableArtifacts(undefined, process.env)).toEqual([]);
301302
expect(fs.existsSync(recordingExport.outPath)).toBe(true);
302303
});

‎packages/daemon/src/sessions/leased-recording-retention.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function retainLeasedSessionRecording(
4343
}
4444
} catch (error) {
4545
for (const artifactId of artifactIds) cleanupDownloadableArtifact(artifactId);
46-
for (const artifact of artifacts) fs.rmSync(artifact.path!, { force: true });
46+
for (const artifact of artifacts) removeBestEffort(artifact.path!);
4747
emitDiagnostic({
4848
level: 'warn',
4949
phase: 'leased_session_recording_retention_failed',
@@ -58,6 +58,14 @@ export function retainLeasedSessionRecording(
5858
});
5959
}
6060

61+
function removeBestEffort(filePath: string): void {
62+
try {
63+
fs.rmSync(filePath, { force: true });
64+
} catch {
65+
// A file that cannot be removed must not stop the removal of the others.
66+
}
67+
}
68+
6169
function isRemoteRecordingExport(completion: ScreenRecordingCompletion): boolean {
6270
return (
6371
completion.clientOutPath !== undefined &&

‎packages/daemon/src/sessions/session-teardown.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { finishLiveAudioProbe } from '@agent-device/capture-kit/audio-probe-sess
1212
import { finishLivePerfCapture } from '@agent-device/capture-kit/perf-capture-session-resource';
1313
import { finishLiveScreenRecording } from '@agent-device/capture-kit/screen-recording-session-resource';
1414
import { openWebSessionNames } from './web-session-names.ts';
15-
import { retainLeasedSessionRecording } from './leased-recording-retention.ts';
1615
import type { PlatformResourceCleanup } from '../core/platform-resource-cleanup.ts';
1716

1817
export async function stopSessionAppLog(params: {
@@ -206,6 +205,8 @@ export async function finishSessionScreenRecording(params: {
206205
const binding = bindSessionScreenRecording(params.sessionStore, params.ref);
207206
if (!binding.read()) return;
208207
const completion = await finishLiveScreenRecording({ binding, intent: 'disposal' });
208+
if (!params.ref.session.lease) return;
209+
const { retainLeasedSessionRecording } = await import('./leased-recording-retention.ts');
209210
retainLeasedSessionRecording(params.ref, completion);
210211
}
211212

‎website/docs/docs/remote-proxy.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ stop that daemon first. A denied request fails with `UNAUTHORIZED` and
240240

241241
## What the proxy exposes
242242

243-
The proxy serves only the daemon HTTP contract: `/health`, `/rpc`, `/upload` plus resumable `/upload/*` routes, and `/artifacts/*`, with the same routes also available under `/agent-device/*`. Health checks are unauthenticated; command, upload, and artifact routes require the bearer token. `GET /artifacts` lists the caller tenant's downloadable artifacts. An entry has `sessionName` when no reply handed the artifact back, for example a recording kept when its leased session ended.
243+
The proxy serves only the daemon HTTP contract: `/health`, `/rpc`, `/upload` plus resumable `/upload/*` routes, and `/artifacts/*`, with the same routes also available under `/agent-device/*`. Health checks are unauthenticated; command, upload, and artifact routes require the bearer token. `GET /artifacts` lists the caller tenant's downloadable artifacts. An entry has `sessionName` when the daemon registered it outside a request reply, for example a recording kept when its leased session ended.
244244

245245
The proxy checks the client token and forwards authorized requests with the local daemon token. Remote clients never see the daemon token.
246246

0 commit comments

Comments
 (0)