Skip to content

Commit f0ef8fe

Browse files
committed
fix(contracts): keep disposal normalization total for non-Error rejections
String() throws for values such as Object.create(null), which let a TypeError escape disposal. Non-Error rejections now keep the facet's default message and the raw value as cause. Drop the unused cause parameter from the perf capture assertion: its cleanup already converts rejections into a cleanup-pending outcome, so forceCleanup() keeps returning outcomes. Remove the stale callstack#4334 drift note from the durable resource recovery contract.
1 parent f8bc385 commit f0ef8fe

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎packages/capture-kit/docs/durable-resource-recovery.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ A durable start returns a process-local live handle and a bounded, JSON-safe, ve
44
The facet-specific handle provides idempotent `finish()` returning `FinishOutcome`, `forceCleanup()` returning `CleanupOutcome`, and an idempotent `[Symbol.asyncDispose]` adapter that carries no typed result.
55
The adapter resolves only for confirmed cleanup or already-missing outcomes.
66
Otherwise, it rejects with a normalized `ownership-lost` or `cleanup-pending` error.
7-
Known drift: today a rejected cleanup operation escapes the shared adapter without normalization (#4334).
87

98
Each destructive finish or cleanup holds the authoritative ownership lease across fence validation, native side effect, and persisted transition, or uses a token atomically enforced by the native or provider operation.
109
A preflight check alone is insufficient.

‎packages/capture-kit/src/app-log-runtime.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ test('app-log async disposal normalizes a rejected cleanup and keeps its cause',
122122
assert.equal(cleanup.mock.calls.length, 2);
123123
});
124124

125+
test('app-log async disposal normalizes a rejected cleanup whose value has no string form', async () => {
126+
const rejection: unknown = Object.create(null);
127+
const handle = createAppLogLiveHandle({
128+
inspect: () => ({ backend: 'android', state: 'failed', startedAt: 12 }),
129+
finish: async () => ({ status: 'completed', result: completion }),
130+
forceCleanup: async () => {
131+
throw rejection;
132+
},
133+
});
134+
135+
await assert.rejects(
136+
async () => await handle[Symbol.asyncDispose](),
137+
(error: unknown) =>
138+
error instanceof AppError &&
139+
error.details?.reason === 'cleanup-unconfirmed' &&
140+
error.cause === rejection,
141+
);
142+
});
143+
125144
test('app-log start result retains pending ownership until explicit transfer', async () => {
126145
let cleanupCount = 0;
127146
const handle = createAppLogLiveHandle({

‎packages/contracts/src/durable-resource.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export function createRetryableCleanup(
9494
outcome: {
9595
status: 'cleanup-pending',
9696
reason: 'cleanup-unconfirmed',
97-
message: error instanceof Error ? error.message : String(error),
97+
// Non-Error rejections keep the facet's default message; `cause` keeps the raw value.
98+
message: error instanceof Error ? error.message : undefined,
9899
} as const,
99100
cause: error,
100101
}),

‎src/platform-runtime-perf-capture-host.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,12 @@ function cleanupPending(error: unknown): CleanupOutcome {
325325
};
326326
}
327327

328-
function assertCleanup(outcome: CleanupOutcome, cause?: unknown): void {
328+
function assertCleanup(outcome: CleanupOutcome): void {
329329
if (outcome.status !== 'cleanup-pending') return;
330330
throw new AppError(
331331
'COMMAND_FAILED',
332332
outcome.message ?? 'Perf capture cleanup could not be confirmed',
333333
{ reason: outcome.reason },
334-
cause,
335334
);
336335
}
337336

0 commit comments

Comments
 (0)