Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/command-registry/src/descriptor-timeout-policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { parseTimeout } from './parse-timeout.ts';
import {
DEFAULT_TIMEOUT_POLICY,
INSTALL_REQUEST_TIMEOUT_MS,
INSTALL_SOURCE_DAEMON_DEADLINE_MS,
INSTALL_SOURCE_REQUEST_TIMEOUT_MS,
LEASE_ALLOCATE_REQUEST_TIMEOUT_MS,
MAX_ARMABLE_ALERT_WAIT_WINDOW_MS,
} from './timeout-policy.ts';
Expand All @@ -24,6 +26,17 @@ export const INSTALL_TIMEOUT_POLICY: CommandTimeoutPolicy = {
envelopeMs: INSTALL_REQUEST_TIMEOUT_MS,
};

/**
* The one source-install timeout policy shared by `install-from-source` and `install_source`
* (#4441, decision 6856998913): the 600 s client envelope, with the daemon enforcing the
* envelope less the result margin (570 s) from admission through the descriptor/router path.
*/
export const INSTALL_SOURCE_TIMEOUT_POLICY: CommandTimeoutPolicy = {
...INSTALL_TIMEOUT_POLICY,
envelopeMs: INSTALL_SOURCE_REQUEST_TIMEOUT_MS,
daemonDeadlineMs: INSTALL_SOURCE_DAEMON_DEADLINE_MS,
};
Comment thread
thymikee marked this conversation as resolved.
Resolved

// Lease-route commands act on billed cloud sessions the daemon owns; resetting
// the daemon on a client timeout would SIGKILL it mid-create/mid-release and
// orphan them all (#1774). Allocation also gets an envelope sized for remote
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import {
settingsRefFrameEffect,
NO_PLATFORM_EXECUTION,
} from '../descriptor-request-policy.ts';
import {
DEFAULT_TIMEOUT_POLICY,
FOLD_TIMEOUT_POLICY,
INSTALL_SOURCE_REQUEST_TIMEOUT_MS,
} from '../timeout-policy.ts';
import { DEFAULT_TIMEOUT_POLICY, FOLD_TIMEOUT_POLICY } from '../timeout-policy.ts';
import {
FILL_INTERACTION_RESPONSE_DATA_TRANSFORM,
GENERIC_MUTATING_COMMAND_TRAITS,
Expand All @@ -23,6 +19,7 @@ import {
} from '../descriptor-traits.ts';
import {
ALERT_TIMEOUT_POLICY,
INSTALL_SOURCE_TIMEOUT_POLICY,
PRESERVE_DAEMON_TIMEOUT_POLICY,
SETTLE_FLAG_PRESERVE_DAEMON_TIMEOUT_POLICY,
postActionObservationTimeoutPolicy,
Expand Down Expand Up @@ -629,7 +626,7 @@ export const DEVICE_OPERATION_COMMAND_DESCRIPTORS = {
recordsSessionAction: true,
recordingEffect: 'mutates-app',
platformExecution: { kind: 'device-runtime', use: readyMaterializeAndDeployAppUse },
timeoutPolicy: { ...DEFAULT_TIMEOUT_POLICY, envelopeMs: INSTALL_SOURCE_REQUEST_TIMEOUT_MS },
timeoutPolicy: INSTALL_SOURCE_TIMEOUT_POLICY,
batchable: true,
compositeResource: 'none',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import {
COMPOSITE_TIMEOUT_POLICIES,
DEFAULT_TIMEOUT_POLICY,
INSTALL_SOURCE_REQUEST_TIMEOUT_MS,
PREPARE_REQUEST_TIMEOUT_MS,
} from '../timeout-policy.ts';
import {
Expand All @@ -18,7 +17,10 @@ import {
ownerFilesEnabled,
type RawCommandDescriptor,
} from '../descriptor-traits.ts';
import { INSTALL_TIMEOUT_POLICY } from '../descriptor-timeout-policies.ts';
import {
INSTALL_SOURCE_TIMEOUT_POLICY,
INSTALL_TIMEOUT_POLICY,
} from '../descriptor-timeout-policies.ts';
import {
deployAppUse,
readyMaterializeAndDeployAppUse,
Expand Down Expand Up @@ -317,7 +319,7 @@ export const SESSION_OPERATION_COMMAND_DESCRIPTORS = [
androidAvdSelection: 'include-stopped',
},
platformExecution: { kind: 'device-runtime', use: readyMaterializeAndDeployAppUse },
timeoutPolicy: { ...INSTALL_TIMEOUT_POLICY, envelopeMs: INSTALL_SOURCE_REQUEST_TIMEOUT_MS },
timeoutPolicy: INSTALL_SOURCE_TIMEOUT_POLICY,
batchable: false,
},
{
Expand Down
9 changes: 9 additions & 0 deletions packages/command-registry/src/timeout-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ export const INSTALL_SOURCE_REQUEST_TIMEOUT_MS = 600_000;
// envelope below the command's declared base.
const REQUEST_TIMEOUT_BUDGET_MARGIN_MS = 30_000;

/**
* The source-install work budget the daemon enforces from admission (#4441,
* decisions 6827686874/6856998913): readiness, download, extraction and
* installation share one remaining budget, so the daemon deadline is the
* 600 s client envelope less the result margin.
*/
export const INSTALL_SOURCE_DAEMON_DEADLINE_MS =
INSTALL_SOURCE_REQUEST_TIMEOUT_MS - REQUEST_TIMEOUT_BUDGET_MARGIN_MS;

/**
* The longest `alert wait` window the request envelope can be armed for.
*
Expand Down
41 changes: 41 additions & 0 deletions packages/daemon/src/core/__tests__/daemon-command-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
shouldPreferExplicitDeviceOverExistingSession,
shouldValidateSessionSelector,
resolveProviderDeviceResolutionIntent,
resolveDaemonRequestResultDeadlineMs,
resolveDaemonRequestTimeoutMs,
usesSessionlessDefaultProviderDevice,
} from '../daemon-command-registry.ts';
import type { DaemonRequest } from '../daemon-request.ts';
Expand Down Expand Up @@ -328,6 +330,45 @@ function makeRequest(command: string, positionals: string[] = []): DaemonRequest
};
}

// #4441 (decision 6856998913): the router's daemon request timeout for both source-install
// commands is the one 570 s source work budget; the admitting transport registers the same
// result deadline (admittedAt + 570 s), and unrelated commands keep no daemon deadline.
test('source-install requests resolve the 570 s daemon deadline and result deadline', () => {
const request = (command: string) =>
({
token: 't',
session: 'default',
command,
positionals: [],
flags: {},
}) as DaemonRequest;
for (const command of [PUBLIC_COMMANDS.installFromSource, INTERNAL_COMMANDS.installSource]) {
assert.equal(resolveDaemonRequestTimeoutMs(request(command)), 570_000, command);
const admittedAt = 1_000_000;
assert.equal(
resolveDaemonRequestResultDeadlineMs(request(command), admittedAt),
admittedAt + 570_000,
command,
);
}
for (const command of [PUBLIC_COMMANDS.install, PUBLIC_COMMANDS.snapshot]) {
assert.equal(resolveDaemonRequestTimeoutMs(request(command)), undefined, command);
}
});

test('batch and replay transport deadlines match their resolved execution budgets', () => {
const admittedAt = 1_000_000;
for (const command of [PUBLIC_COMMANDS.batch, PUBLIC_COMMANDS.replay]) {
const request = makeRequest(command);
const executionBudgetMs = resolveDaemonRequestTimeoutMs(request);
assert.notEqual(executionBudgetMs, undefined, command);
assert.equal(
resolveDaemonRequestResultDeadlineMs(request, admittedAt),
admittedAt + executionBudgetMs!,
);
}
});

// The fact the transports stamp on each admitted request: only a request with no action in any of
// its steps may let a resend loop spend its deadline.
test('isReadOnlyRequest marks reads, and never a request that dispatches an action', () => {
Expand Down
10 changes: 9 additions & 1 deletion packages/daemon/src/core/lease-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AppError,
BOUNDED_COMPOSITE_RESOURCE_UNSUPPORTED_REASON,
} from '@agent-device/kernel/errors';
import { INTERNAL_COMMANDS, PUBLIC_COMMANDS } from '@agent-device/command-registry/catalog';
import { resolveCommandStandaloneProjection } from '@agent-device/command-registry/registry';
import type { LeaseBackend } from '@agent-device/kernel/contracts';
import type { DeviceLease } from '@agent-device/contracts/device';
Expand Down Expand Up @@ -31,7 +32,14 @@ export function refuseBoundedCompositeResourceOperation(req: DaemonRequest, shap
}

export function isBoundedCompositeRequest(req: DaemonRequest): boolean {
return getRequestExecutionDeadlineMs(req.meta?.requestId) !== undefined;
if (getRequestExecutionDeadlineMs(req.meta?.requestId) === undefined) return false;
if (
req.command === INTERNAL_COMMANDS.installSource ||
req.command === PUBLIC_COMMANDS.installFromSource
) {
return req.internal?.executionPlan !== undefined || req.internal?.replayPlanStep === true;
}
return true;
}

export type SessionLease = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,26 @@ test('bounded install_source refusal names public install-from-source', async ()
expect(fs.readFileSync(claimPath)).toEqual(before);
});

test('a top-level source install reaches runtime admission under its own deadline', async () => {
const device = { ...makeIosDevice('SIM-DIRECT-SOURCE-RECOVERY'), appleOs: 'ios' as const };
seedClaim(device);
const { handler, runtime } = route(device);
const request = openRequest('takeover', { platform: 'ios' }, 'direct-source-recovery');
const sourcePath = path.join(root('source-recovery-input-'), 'app.ipa');
fs.writeFileSync(sourcePath, 'owned fixture');
const response = await handler({
...request,
command: 'install_source',
positionals: ['com.example.app'],
meta: { ...request.meta, installSource: { kind: 'path', path: sourcePath } },
});
expect(response).toMatchObject({
ok: false,
error: { details: { reason: 'owner-capability-missing' } },
});
expect(runtime.inspectFacts).toHaveBeenCalled();
});

test('bounded install preserves the handler selector error before inventory resolution', async () => {
const device = { ...makeIosDevice('SIM-NO-SELECTOR'), appleOs: 'ios' as const };
const { handler, runtime, recovery } = route(device, { inventory: [] });
Expand Down
Loading
Loading