Skip to content

Commit e10db99

Browse files
airoweclaude
andcommitted
fix(timeouts): charge every observation variant in the longpress ledger
The ledger's fake answered the first dumpsys variant of every observation, so it charged one read each and never saw the foreground check walk into a second observation. Observation dumps now answer without a focus line, which sends each observation through every variant its shared budget allows. The measured worst case rises to 289,989 ms, so the envelope rises from 310 s to 320 s. Also: name the snapshot-helper hand-off the ledger cannot charge and where it is bounded, say the Android-driven envelope applies to every platform, read timeoutMs once in record(), and rewrap the header. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent da56474 commit e10db99

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

‎packages/command-registry/src/registry.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,10 +1298,10 @@ export const RAW_COMMAND_DESCRIPTORS = [
12981298
frameworkTier: 'extended',
12991299
timeoutPolicy: {
13001300
...SETTLE_FLAG_PRESERVE_DAEMON_TIMEOUT_POLICY,
1301-
// Covers the Android cold-helper worst case at the maximum hold plus the
1302-
// daemon-result margin. Proven by the ledger test:
1301+
// Android cold-helper worst case at the maximum hold plus the daemon-result margin, applied
1302+
// to every platform. Proven by the ledger test:
13031303
// test/integration/provider-scenarios/android-longpress-ledger.test.ts.
1304-
envelopeMs: 310_000,
1304+
envelopeMs: 320_000,
13051305
},
13061306
postActionObservation: postActionObservation('longpress'),
13071307
batchable: true,

‎src/__tests__/command-descriptor-timeout-policy.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ test('request envelopes deviating from the default are bounded, reviewed sets',
151151
install_source: 180_000,
152152
// longpress: proven by the worst-case ledger test in
153153
// test/integration/provider-scenarios/android-longpress-ledger.test.ts.
154-
longpress: 310_000,
154+
longpress: 320_000,
155155
// fold: proven by the worst-case ledger test in
156156
// test/integration/provider-scenarios/ios-fold.test.ts.
157157
fold: 255_000,
@@ -262,7 +262,7 @@ test('interaction --settle budgets add post-action settle time on top of the nor
262262
positionals: ['300', '500', '120000'],
263263
flags: {},
264264
}),
265-
310_000,
265+
320_000,
266266
);
267267
// Bare --settle adds its default budget after the longpress-specific base,
268268
// so a maximum hold still leaves room for post-action observation.
@@ -271,7 +271,7 @@ test('interaction --settle budgets add post-action settle time on top of the nor
271271
...base,
272272
flags: { settle: true },
273273
}),
274-
350_000,
274+
360_000,
275275
);
276276
// Bare timeoutMs without --settle remains wire-compatible with older touch
277277
// command clients: it is ignored instead of opting into settle semantics.

‎test/integration/provider-scenarios/android-longpress-ledger.test.ts‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ import { createProviderScenarioHarness } from './harness.ts';
1717

1818
// The longpress envelope must outlast the Android cold-helper route's worst case plus the margin
1919
// that lets the daemon's own typed result arrive first; otherwise the client gives up on a request
20-
// the device is still finishing. This test proves that bound against the real route: it imports no platform-android step figure, so it stays true
21-
// however the route's steps change. The only imported figure is the hold cap the validator reads.
20+
// the device is still finishing. This test proves that bound against the real route: it imports no
21+
// platform-android step figure, so it stays true however the route's steps change. The only
22+
// imported figure is the hold cap the validator reads.
23+
//
24+
// One step stays outside this ledger: replacing the helper stops a running snapshot helper session
25+
// first, and that hand-off waits on host-side timers in
26+
// packages/platform-android/src/snapshot-helper-session-lifecycle.ts (stop request, graceful exit,
27+
// process exit) rather than on a provider call this fake can charge. Its device-side stop does go
28+
// through the provider and is charged when it runs.
2229
type LongPressLedgerCall = Readonly<{
2330
tool: 'exec' | 'install' | 'pull';
2431
args: readonly string[];
@@ -60,18 +67,22 @@ function createLongPressLedgerAdbProvider(params: {
6067
options?: AndroidAdbExecutorOptions,
6168
): void => {
6269
if (!params.isTracking()) return;
70+
const timeoutMs = options?.timeoutMs;
6371
assert.ok(
64-
Number.isFinite(options?.timeoutMs) && options!.timeoutMs! > 0,
72+
timeoutMs !== undefined && Number.isFinite(timeoutMs) && timeoutMs > 0,
6573
`longpress ledger call has no bounded timeoutMs: ${tool} ${args.join(' ')}`,
6674
);
67-
const call: LongPressLedgerCall = { tool, args: [...args], timeoutMs: options!.timeoutMs! };
75+
const call: LongPressLedgerCall = { tool, args: [...args], timeoutMs };
6876
ledger.push(call);
6977
params.onCall(call);
7078
};
7179
const provider: AndroidAdbProvider = {
7280
snapshotHelperArtifact: ANDROID_SNAPSHOT_HELPER_FIXTURE_ARTIFACT,
7381
exec: async (args, options) => {
7482
record('exec', args, options);
83+
// A dump without a focus line sends the dialog and foreground observations through every
84+
// variant they may read, so each one spends its whole budget.
85+
if (params.isTracking() && isObservationDump(args)) return ok;
7586
if (args.includes('--show-versioncode') && args.includes(HELPER.packageName)) {
7687
return {
7788
...ok,
@@ -113,6 +124,12 @@ function createLongPressLedgerAdbProvider(params: {
113124
return { provider, ledger };
114125
}
115126

127+
function isObservationDump(args: readonly string[]): boolean {
128+
return (
129+
args[0] === 'shell' && args[1] === 'dumpsys' && (args[2] === 'window' || args[2] === 'activity')
130+
);
131+
}
132+
116133
function gestureDurationMs(call: LongPressLedgerCall): number | undefined {
117134
const payloadIndex = call.args.indexOf('payloadBase64');
118135
if (payloadIndex < 0) return undefined;
@@ -146,6 +163,10 @@ function assertLongPressLedgerPhaseCoverage(ledger: readonly LongPressLedgerCall
146163
ledger.some((call) => call.args[0] === 'uninstall'),
147164
`ledger is missing the incompatible-helper uninstall${printed}`,
148165
);
166+
assert.ok(
167+
ledger.some((call) => call.tool === 'exec' && isObservationDump(call.args)),
168+
`ledger is missing the dialog and foreground observation dumps${printed}`,
169+
);
149170
const gestures = ledger.filter(isGesture);
150171
assert.equal(gestures.length, 1, `ledger must record exactly one gesture dispatch${printed}`);
151172
assert.equal(

0 commit comments

Comments
 (0)