Repository navigation
feat(remote): surface a script delivery failure on every caller surface #4582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
46a47e1
feat(remote): surface a script delivery failure on every caller surface
thymikee 960854f
fix(remote): deliver a batch answer only on the plan the caller submi…
thymikee de3a92e
fix(remote): deliver one script version per batch, on the plan's prefix
thymikee bf627a8
docs(remote): state the one-download batch budget where the ledger po…
thymikee 9b341ae
fix(remote): disclose a step's script failure on the batch, in a smal…
thymikee 6ea25d0
fix(remote): derive one batch answer's script facts from one validate…
thymikee 0ebfbfb
refactor(remote): keep the script disclosure surfaces and refuse batc…
thymikee 8f0ecc6
docs(replay): state that remote batch steps do not update the script …
thymikee 5de4c76
docs(remote): promise a CLI warning, not a Warning: prefix on every s…
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/client/src/__tests__/index-script-delivery-disclosure.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { test } from 'vitest'; | ||
| import { createAgentDeviceClient } from '../index.ts'; | ||
| import type { DaemonResponse, ScriptDeliveryFailure } from '@agent-device/kernel/contracts'; | ||
| import { createClientTransport } from '@agent-device/test-kit'; | ||
|
|
||
| /** | ||
| * A script version that did not reach the caller file keeps its action successful, so the typed | ||
| * failure and its paired warning are the only disclosure that the file is stale (ADR 0016, #4564). | ||
| * Every SDK result that can carry a script version reads both fields through | ||
| * `readScriptDeliveryDisclosure`; this table pins each one, so a spread that stops carrying either | ||
| * field fails here rather than quietly on one surface. | ||
| */ | ||
|
|
||
| const WARNING = 'The session recorded version 2, but the daemon could not save it.'; | ||
|
|
||
| const FAILURE: ScriptDeliveryFailure = { | ||
| reason: 'script_delivery_failed', | ||
| cause: 'script_write_failed', | ||
| publicationId: '0f61b0c2-6d1a-4d1f-9b7f-2a4f3a1c7d55', | ||
| message: WARNING, | ||
| hint: 'The file keeps the version from the last action that arrived.', | ||
| }; | ||
|
|
||
| /** The two fields one answer carries at the top level of its payload. */ | ||
| const DISCLOSURE = { warnings: [WARNING], scriptDeliveryFailure: FAILURE }; | ||
|
|
||
| /** One SDK action whose answer can carry a script version, with the answer it reads. */ | ||
| type DisclosureSurface = Readonly<{ | ||
| label: string; | ||
| command: string; | ||
| data: Record<string, unknown>; | ||
| read: (client: ReturnType<typeof createAgentDeviceClient>) => Promise<unknown>; | ||
| }>; | ||
|
|
||
| const SURFACES: DisclosureSurface[] = [ | ||
| { | ||
| label: 'sessions.close', | ||
| command: 'close', | ||
| data: { ...DISCLOSURE, savedScript: '/tmp/journey.ad' }, | ||
| read: async (client) => await client.sessions.close(), | ||
| }, | ||
| { | ||
| label: 'apps.close', | ||
| command: 'close', | ||
| data: { ...DISCLOSURE, savedScript: '/tmp/journey.ad' }, | ||
| read: async (client) => await client.apps.close(), | ||
| }, | ||
| { | ||
| label: 'apps.open', | ||
| command: 'open', | ||
| data: { ...DISCLOSURE, appBundleId: 'com.example.demo' }, | ||
| read: async (client) => await client.apps.open({ app: 'Demo' }), | ||
| }, | ||
| { | ||
| label: 'capture.snapshot', | ||
| command: 'snapshot', | ||
| data: { ...DISCLOSURE, nodes: [] }, | ||
| read: async (client) => await client.capture.snapshot(), | ||
| }, | ||
| { | ||
| label: 'capture.screenshot', | ||
| command: 'screenshot', | ||
| data: { ...DISCLOSURE, path: '/tmp/shot.png', width: 40, height: 20 }, | ||
| read: async (client) => await client.capture.screenshot(), | ||
| }, | ||
| ]; | ||
|
|
||
| function clientAnswering(command: string, data: Record<string, unknown>) { | ||
| const setup = createClientTransport(async (req): Promise<DaemonResponse> => { | ||
| if (req.command !== command) throw new Error(`Unexpected command: ${req.command}`); | ||
| return { ok: true, data: { session: 'qa', ...data } }; | ||
| }); | ||
| return createAgentDeviceClient(setup.config, { transport: setup.transport }); | ||
| } | ||
|
|
||
| for (const surface of SURFACES) { | ||
| test(`the ${surface.label} result carries a failed script delivery`, async () => { | ||
| const client = clientAnswering(surface.command, surface.data); | ||
|
|
||
| const result = (await surface.read(client)) as Record<string, unknown>; | ||
|
|
||
| assert.deepEqual(result.scriptDeliveryFailure, FAILURE, surface.label); | ||
| assert.deepEqual(result.warnings, [WARNING], surface.label); | ||
| }); | ||
|
|
||
| test(`the ${surface.label} result names no disclosure for a delivered script`, async () => { | ||
| const plain = Object.fromEntries( | ||
| Object.entries(surface.data).filter( | ||
| ([key]) => key !== 'warnings' && key !== 'scriptDeliveryFailure', | ||
| ), | ||
| ); | ||
| const client = clientAnswering(surface.command, plain); | ||
|
|
||
| const result = (await surface.read(client)) as Record<string, unknown>; | ||
|
|
||
| assert.equal('scriptDeliveryFailure' in result, false, surface.label); | ||
| assert.equal('warnings' in result, false, surface.label); | ||
| }); | ||
|
|
||
| test(`the ${surface.label} result drops a malformed failure object`, async () => { | ||
| const client = clientAnswering(surface.command, { | ||
| ...surface.data, | ||
| scriptDeliveryFailure: { reason: 'script_delivery_failed' }, | ||
| }); | ||
|
|
||
| const result = (await surface.read(client)) as Record<string, unknown>; | ||
|
|
||
| assert.equal('scriptDeliveryFailure' in result, false, surface.label); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ import { | |
| normalizeTargetShutdownResult, | ||
| readOptionalString, | ||
| readRequiredString, | ||
| readScriptDeliveryDisclosure, | ||
| readSnapshotNodes, | ||
| resolveSessionName, | ||
| } from './client-normalizers.ts'; | ||
|
|
@@ -70,7 +71,6 @@ import { | |
| readSnapshotKeyboardBandFact, | ||
| } from '@agent-device/kernel/record'; | ||
| import { readSnapshotViewportSize } from '@agent-device/kernel/rect'; | ||
| import { readResponseWarnings } from '@agent-device/kernel/success-text'; | ||
| import { captureHostEnvironment } from '@agent-device/host-kit/process'; | ||
| import type { HostEnvironment } from '@agent-device/kernel/source-value'; | ||
| import { createLeaseClient } from './lease-client.ts'; | ||
|
|
@@ -273,6 +273,7 @@ export function createAgentDeviceClient( | |
| shutdown: normalizeTargetShutdownResult(data.shutdown), | ||
| provider: asOptionalRecord(data.provider), | ||
| savedScript: readOptionalString(data, 'savedScript'), | ||
| ...readScriptDeliveryDisclosure(data), | ||
| identifiers: { session }, | ||
| }; | ||
| } finally { | ||
|
|
@@ -345,10 +346,9 @@ export function createAgentDeviceClient( | |
| const device = normalizeOpenDevice(data); | ||
| const appBundleId = readOptionalString(data, 'appBundleId'); | ||
| const appId = appBundleId; | ||
| const warnings = readResponseWarnings(data); | ||
| return { | ||
| session, | ||
| ...(warnings.length > 0 ? { warnings } : {}), | ||
| ...readScriptDeliveryDisclosure(data), | ||
| sessionStateDir: readOptionalString(data, 'sessionStateDir'), | ||
| runnerLogPath: readOptionalString(data, 'runnerLogPath'), | ||
| requestLogPath: readOptionalString(data, 'requestLogPath'), | ||
|
|
@@ -381,6 +381,7 @@ export function createAgentDeviceClient( | |
| closedApp: options.app, | ||
| shutdown: normalizeTargetShutdownResult(data.shutdown), | ||
| savedScript: readOptionalString(data, 'savedScript'), | ||
| ...readScriptDeliveryDisclosure(data), | ||
| identifiers: { session }, | ||
| }; | ||
| }, | ||
|
|
@@ -605,6 +606,7 @@ function optionalSnapshotResponseFields( | |
| const snapshotDiagnostics = readSnapshotDiagnosticsSummary(data.snapshotDiagnostics); | ||
| const presentedSurface = readPresentedSurfaceFact(data); | ||
| const postGestureOutcome = readPostGestureOutcome(data.postGestureOutcome); | ||
| const { scriptDeliveryFailure } = readScriptDeliveryDisclosure(data); | ||
| return { | ||
| ...(keyboard ? { keyboard } : {}), | ||
| ...(viewport ? { viewport } : {}), | ||
|
|
@@ -614,6 +616,9 @@ function optionalSnapshotResponseFields( | |
| ...readSerializedSnapshotCaptureAnnotations(data), | ||
| ...(unchanged ? { unchanged: unchanged as CaptureSnapshotResult['unchanged'] } : {}), | ||
| ...(snapshotDiagnostics ? { snapshotDiagnostics } : {}), | ||
| // `readSerializedSnapshotCaptureAnnotations` above already reads this response's `warnings`, so | ||
| // only the typed field needs adding here. | ||
| ...(scriptDeliveryFailure === undefined ? {} : { scriptDeliveryFailure }), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Add Prompt for AI agents |
||
| ...(typeof data.fallbackScreenshotPath === 'string' | ||
| ? { fallbackScreenshotPath: data.fallbackScreenshotPath } | ||
| : {}), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/command-output/src/output/result-serialization-script-delivery.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { test } from 'vitest'; | ||
| import assert from 'node:assert/strict'; | ||
| import type { ScriptDeliveryFailure } from '@agent-device/kernel/contracts'; | ||
| import { | ||
| serializeCloseResult, | ||
| serializeOpenResult, | ||
| serializeSnapshotResult, | ||
| } from './result-serialization.ts'; | ||
|
|
||
| /** | ||
| * A remote recording's script version that did not reach the caller file keeps its action | ||
| * successful, so machine output is where a caller learns the file is stale (ADR 0016, #4564). Every | ||
| * family that can report a script version emits the two fields through one helper; this table pins | ||
| * each of them, so a serializer that stops carrying either field fails here. | ||
| */ | ||
|
|
||
| const WARNING = 'The session recorded version 2, but the daemon could not save it.'; | ||
|
|
||
| const FAILURE: ScriptDeliveryFailure = { | ||
| reason: 'script_delivery_failed', | ||
| cause: 'script_write_failed', | ||
| publicationId: '0f61b0c2-6d1a-4d1f-9b7f-2a4f3a1c7d55', | ||
| message: WARNING, | ||
| hint: 'The file keeps the version from the last action that arrived.', | ||
| }; | ||
|
|
||
| const DISCLOSURE = { warnings: [WARNING], scriptDeliveryFailure: FAILURE }; | ||
|
|
||
| /** The machine output of each family whose result can carry a script version. */ | ||
| const outputs: Array<{ | ||
| label: string; | ||
| /** Called with the disclosure fields, and with PLAIN input that names none of them. */ | ||
| serialize: (input?: Record<string, unknown>) => Record<string, unknown>; | ||
| }> = [ | ||
| { | ||
| label: 'open', | ||
| serialize: (input) => serializeOpenResult({ session: 'qa', ...input } as never), | ||
| }, | ||
| { | ||
| label: 'session close', | ||
| serialize: (input) => | ||
| serializeCloseResult({ session: 'qa', savedScript: '/tmp/journey.ad', ...input } as never), | ||
| }, | ||
| { | ||
| label: 'snapshot', | ||
| serialize: (input) => serializeSnapshotResult({ nodes: [], ...input } as never), | ||
| }, | ||
| ]; | ||
|
|
||
| for (const output of outputs) { | ||
| test(`the ${output.label} machine output carries a failed script delivery`, () => { | ||
| const data = output.serialize(DISCLOSURE); | ||
|
|
||
| assert.deepEqual(data.scriptDeliveryFailure, FAILURE); | ||
| assert.deepEqual(data.warnings, [WARNING]); | ||
| }); | ||
|
|
||
| test(`the ${output.label} machine output omits a disclosure it was not given`, () => { | ||
| // PLAIN input: nothing here names a script, so a serializer that invents either field fails. | ||
| const data = output.serialize(); | ||
|
|
||
| assert.equal('scriptDeliveryFailure' in data, false); | ||
| assert.equal('warnings' in data, false); | ||
| }); | ||
|
|
||
| test(`the ${output.label} machine output keeps the failure beside an empty warning list`, () => { | ||
| const empty = output.serialize({ ...DISCLOSURE, warnings: [] }); | ||
|
|
||
| assert.deepEqual(empty.scriptDeliveryFailure, FAILURE); | ||
| assert.equal('warnings' in empty, false); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: The leveled snapshot branch returns the raw payload, so a malformed
scriptDeliveryFailurereaches the caller unchecked. Pass that field throughreadScriptDeliveryFailureon the leveled path too, aspresentedSurfacealready is.Prompt for AI agents