Skip to content

fix(remote): deliver batch recordings through one request receipt - #4627

Merged
thymikee merged 12 commits into
mainfrom
t3/batch-delivery-receipts
Nov 17, 2026
Merged

thymikee merged 12 commits into
mainfrom
t3/batch-delivery-receipts

Conversation

@thymikee

@thymikee thymikee commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Remote batch updates a recording once, including its final close. One daemon receipt names the newest script, close and delivery failures. The client validates recording scope and submitted plan; batch errors and warnings survive. Malformed artifact descriptors cannot erase delivery disclosures or a valid publication. RPC protocol 3 refuses receipt-unaware protocol-2 peers before dispatch; upgrade both peers together.

Closes #4595. 29 files, including ADR/user guides, compatibility guards and security regressions. Main now contains the proxy isolation prerequisite; temporary gate work is removed.

agent-device open Settings --save-script ./journey.ad
agent-device batch --steps '[{"command":"wait","input":{"selector":"label=\"Apps\""}},{"command":"close","input":{}}]'

Validation

Head 63c6341766d47f64bb5602db3bb6f8da4a421650; base bfb67d5cce.

  • pnpm check:affected --run --head HEAD: 42 passed, 25 owned skips, receipt run-SbopvC, exactCommit=true, checkoutChanged=false.
  • Unit: 20,395 passed / 10 skipped. Provider integration: 306 passed. Format, lint, typecheck, layering, Fallow, packaging, Node integration, wire compatibility and docs guards passed.
  • Security regressions: cf0442c 2 failed / 63 skipped at the disclosure/publication assertions; fixed candidate 214e481 2 passed / 63 skipped. Retained at final head. Focused receipt/download/wire suites: 71 passed.
  • Initial independent review at cd68b20 accepts the contract and smaller design. Later maintainer findings are fixed and covered by regression proof and the final gate.

Out of draft. Current-head hosted checks and review remain pending. Native execution is unchanged; no live-device claim.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.37 MB 6.38 MB +6.3 kB
Package (unpacked) 6.37 MB 6.38 MB +6.3 kB
Package (download) 1.93 MB 1.94 MB +1.7 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 21.1 ms 21.8 ms +0.7 ms
CLI --help 44.3 ms 45.2 ms +0.9 ms

@apex-sentinel-staging

apex-sentinel-staging Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve

Since the last review: 0 new · 0 still open · 0 no longer raised

No open findings.

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (bfb67d5cce37).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

Earlier reviews

Review of cf0442cd · 17.11.2026 13:17 UTC

Apex Sentinel · ✅ Approve

Since the last review: 0 new · 0 still open · 0 no longer raised

No open findings.

Reviewed with this repository's own Sentinel configuration (fdf595127a75).

Review of d222cd6e · 17.11.2026 11:29 UTC

Apex Sentinel · ✅ Approve

Since the last review: 0 new · 0 still open · 0 no longer raised

No open findings.

2 findings below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (fce2fa6247c5).

Review of af2fdd57 · 17.11.2026 11:12 UTC

Apex Sentinel · ✅ Approve

Since the last review: 0 new · 0 still open · 1 no longer raised (1 marked fixed)

No open findings.

2 new findings away from what changed since f029c66 not shown. Comment @apex-sentinel-staging review for a full review.

Reviewed with this repository's own Sentinel configuration (fce2fa6247c5).

Review of f029c66c · 17.11.2026 10:40 UTC

Apex Sentinel · ✅ Approve

1 finding(s): 1 minor.

🟡 Minor (1)

Where Finding
packages/remote/src/session-script-destination.ts:114 Receipt failures are not disclosed when the client's record is gone

2 findings below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (e0ab0c255c3d).

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on f029c66. The verdict and the full list are in the summary comment.

@thymikee
thymikee force-pushed the t3/batch-delivery-receipts branch from af2fdd5 to d222cd6 Compare November 17, 2026 11:20
@thymikee

Copy link
Copy Markdown
Member Author

CI lint failed on the synthetic merge with newer main: its new capture-kit export pushed package-boundaries.test.ts to 1,001 lines. Rebased at d222cd6 and moved the runtime Node-resolution case verbatim into package-boundaries-runtime.test.ts. All 16 checks and focused lint pass; every assertion and the 1,000-line limit are retained. Range-diff shows all six feature commits unchanged.

The new full affected gate is blocked by another live validation owner (run-Jgae6B); I cancelled only our waiter. The draft stays pending current-head CI and the independent design review. The previous af2fdd5 exact gate passed all 42 runnable checks.

@thymikee

Copy link
Copy Markdown
Member Author

I reviewed d222cd6. The code change looks right, but the remote-proxy guide still describes the behavior this PR removes.

remote-proxy.md:124-126 still says a batch that closes a remote recording is refused before any step runs, that users must run close separately, and that a batch delivers no script versions. The direct RPC paragraph at :128-130 tells callers to download the script artifacts and keep the newest. It does not say that a batch reply now carries one scriptDeliveryReceipt in data on success and in error.details on failure. A gateway that follows this text would read step entries, which #4582 rejected. The health example at :363 also still shows rpcProtocolVersion: 2, which the client now refuses. Agents and integrators act on this page, so they will split close out of batches for no reason or build delivery from step results. Every user doc that describes remote batch script delivery should state the receipt behavior; grep website/docs for #4595 and for batch next to save-script to find them all. Use the replay-e2e.md:79 wording for :124-126, add one sentence to the direct RPC paragraph naming the receipt (publicationId, newest version, 1-based close step, failures), and show protocol 3 in the :363 example.

Not blocking, take or leave: normalizeBatchCommandName now lives in contracts/input-validation, but batch-policy.ts:6 re-exports it, so the daemon, ledger and remote package use three spellings of one symbol; deleting the re-export and importing from the contracts facade the ledger already uses would fix that. In session-script-destination.ts:275, a batch that fails without a step position (a request deadline, or a step that throws into runBatch's catch) returns the error unchanged, so the completed steps' version is dropped without a script_delivery_failed or warning; could the client disclose that, or deliver the version without honoring the close? ScriptDeliveryLedger.nested (request-script-delivery-ledger.ts:29) looks unable to change any outcome, because the ledger exists only for batch and a receipt has content only after a step already set it; could it be dropped? The test 'a batch with $name runs its steps' at session-batch.test.ts:27 does not arm remote recording state, so it also passes on the old code; the provider scenarios are the real coverage. Two unrelated rationale strings in test/wire-compat/ledger.json (:236 and :306) had their em dashes re-serialized as \u2014 escapes, which you can restore.

CI is green at d222cd6, with 21 checks reported and none failing. There are no conflicts. No native device run is needed, since native execution is unchanged and the provider scenarios exercise the real daemon and proxy route.

The open thread on receipt failures when the client record is gone no longer applies, because settleScriptReceipt now discloses them before the record lookup (session-script-destination.ts:115-116), so you can resolve it.

Before merge, update remote-proxy.md:124-130 and the :363 example to describe batch delivery through scriptDeliveryReceipt instead of the removed refusal.

@thymikee

Copy link
Copy Markdown
Member Author

Fixed the required docs in ce3ba44: batch delivery, direct-RPC scriptDeliveryReceipt in success/error replies with its fields, and protocol 3 in the health example. The docs guards pass. The independent review accepts the contract and smaller design; its protocol, wire-ledger and capability-inventory findings were already fixed, and both stale user guides are now corrected.

The optional import consolidation would reintroduce eager facade loading. Missing failed-step evidence remains fail-closed under the approved acceptance cases; I have not expanded delivery authorization. The nested flag and JSON escapes are left as optional cleanup. The provider scenarios, rather than the admission-only test, prove the removed refusal end to end.

Validation remains Base-blocked: run-ROiJWi at3610f78 had20,314 passed/1 failed/10 skipped; a fresh isolated fce2fa6 full unit run reproduced the identical proxy cap case and socket hang up. This is already tracked by #4629 and owned by #4631, so I have not changed that campaign. The final docs-only head's affected gate waited behind live owner46088; only our waiter was cancelled. Draft retained until the baseline fix and fresh validation. No failing gate is counted as passed.

@thymikee

Copy link
Copy Markdown
Member Author

Pushed 30cece8.

Blocker — already addressed at ce3ba44: remote-proxy.md:124-130 describes delivery through scriptDeliveryReceipt (publicationId, newest version, 1-based close.step, failures; data on success, error.details on failure) and the health example shows protocol 3. Grepped website/docs for the other mentions: replay-e2e.md:78-79 already carries the receipt behavior; no other page describes remote batch script delivery.

No-position failure (session-script-destination.ts:275) — fixed. The client now splits the two effects. A batch error whose step/command reconciles with the submitted plan and sits at or before the receipt's close proves the close never ran; an error naming no position (deadline, or a step throwing into runBatch's catch) proves nothing. Both now settle the receipt's version and failures, so the caller file moves and scriptDeliveryFailure plus the warning ride the error, and only the retirement is dropped. An answer naming a position the plan cannot reconcile still authorizes nothing at all. New regressions cover both shapes; in a disposable checkout at ce3ba44 they report 2 failed, 36 passed before the fix and 23 passed after.

normalizeBatchCommandName re-export — removed; batch.ts, daemon-policy.ts and macos-app-lease.ts import the contracts owner directly.

ScriptDeliveryLedger.nested — kept, with a test that proves it changes an outcome: without it the outer collector attaches a receipt to a single command's own reply naming script artifacts, changing every recorded action's shape. Mutation check at ce3ba44: dropping the flag and its guard gives 2 failed, 13 passed; unmodified gives 15 passed.

Escapes — the two — escapes in ledger.json:236 and :306 are restored. JSON parses them identically, so no digest moves.

Validation at 30cece8: typecheck, oxlint, pnpm format, wire-compat closure, adr-citations, 1288 unit tests across the touched packages, and the provider suite (12 passed: real daemon, proxy and emulator, including the batch receipt, partial-failure delivery, bounded downloads, and CLI/MCP disclosure).

@thymikee
thymikee marked this pull request as ready for review November 17, 2026 12:41
@thymikee

Copy link
Copy Markdown
Member Author

The code in 30cece8 is ready. Both problems from the earlier review are fixed, and I found no new problems in the delta. The no-position failure path passes the error through daemon-client-rpc.ts and daemon-artifacts.ts unchanged. Not blocking, and you can take or leave these: the new ADR sentence at docs/adr/0016-active-session-script-publication.md:212 covers both an absent step position and an unreconcilable one, but the code only settles the version and failures for an absent position (session-script-destination.ts:314) and returns the error unchanged for an unreconcilable one (:277), so the wording could say that. The test 'a failed batch that names no position delivers the version and discloses' in daemon-artifacts-script-receipt.test.ts:588 has no failures in its receipt, so it would still pass if that path dropped them. Adding a typed failure and asserting scriptDeliveryFailure and warnings, as the record-gone test does at :667-668, would close that.

The Coverage check fails at 30cece8. You tie it to the daemon-proxy-transfer socket hang-up in #4629, which this delta does not touch; please confirm from the log that it is not a coverage threshold on the new files, or rerun it. A security cross-check of this head is running before the label.

The open inline thread on disclosing failures when the record is missing no longer applies, because failures are disclosed before the record lookup at session-script-destination.ts:114-115 and the record-gone test covers both outcomes: #4627 (comment)

@thymikee
thymikee force-pushed the t3/batch-delivery-receipts branch from 30cece8 to cf0442c Compare November 17, 2026 12:58
@thymikee

Copy link
Copy Markdown
Member Author

Pushed cf0442c and completed validation. The PR is out of draft.

Included #4631's exact test-isolation prerequisite for #4629, preserving all 21 cases, the cap and assertions. Rebased onto main fdf5951; all 11 existing commits are unchanged by range-diff. Removed our temporary boundary-test split because #4630 fixed that upstream.

The exact final affected gate passed all 42 runnable checks (25 owned skips), with exactCommit=true and no checkout changes: 20,317 unit tests passed/10 skipped; all 303 provider tests passed. The prior baseline blocker is no longer blocking this branch. Current-head hosted checks and reviews are still pending and will be monitored.

@thymikee

Copy link
Copy Markdown
Member Author

Correction to my note above: 30cece8 is not ready yet. An independent security cross-check of this head found one blocker, and the rebase to cf0442c does not change that code.

A daemon or proxy can hide a failed batch delivery. In downloadResponseArtifacts, each script artifact is published with an unconditional delete data[artifact.field], and the field name comes from the response. A malicious daemon can return a valid receipt for a batch that ends in close, plus two extra artifacts with artifactType: 'session-script' and field set to warnings and scriptDeliveryFailure. If the receipt version download then fails (for example HTTP 503), settleScriptReceipt first records the typed failure and the warning, and the artifact loop then deletes both. The client returns ok: true with no warning, the local file keeps the old version, and settleAfter retires the record. A run of the exact-head receipt reader, sessionScriptDelivery and downloadResponseArtifacts in memory, with a failing download and an in-memory filesystem, reproduced this.

The rule to satisfy: a response artifact can never remove a field it did not create. Restrict script-field cleanup to the reserved savedScript field, validate field and artifactType before an artifact is retained, and keep the receipt's scriptDeliveryFailure and warnings through the artifact loop. Please add a regression with a failed receipt download plus malformed script artifacts that target both disclosure fields.

Not blocking, and worth a look: a successful batch close that fails its download still gets the hint that the next action or close will deliver again (session-script-destination.ts:393 checks only req.command === 'close'), although the record is retired; and the receipt contract (packages/kernel/src/contracts.ts:275-336) caps the failure count but sets no length bound on publicationId, artifactId, message, hint or cause, and a malformed receipt gets no typed disclosure.

A batch that fails with no step position the plan can reconcile, or whose
close sits at or past the failure, proves no close. Its receipt's version
and typed failures are still facts the daemon answered about this client's
own publication, so they settle and disclose instead of being dropped:
silently losing them left the caller file stale with no warning. Only the
retirement is dropped. An answer that cannot be reconciled with the plan
authorizes nothing at all.

Drop the batch-policy re-export of normalizeBatchCommandName so both peers
read the contracts facade, prove the ledger's nested flag is load-bearing,
and restore the ledger rationale escapes.
An answer that names no failing step, or a close the plan confirms was
never reached, proves no close and still settles the receipt's version and
failures. An answer naming a step or command the submitted plan does not
carry is malformed and authorizes nothing. The ADR said both cases prove no
close; the code already rejected only the malformed one.
@thymikee
thymikee force-pushed the t3/batch-delivery-receipts branch from cf0442c to 63c6341 Compare November 17, 2026 14:44
@thymikee

Copy link
Copy Markdown
Member Author

Fixed the disclosure-erasure blocker at 63c6341. Rejected script artifacts no longer delete response fields or enter the retained artifact list. Peer-supplied savedScript is cleared once at the response boundary, including empty artifact lists; later invalid entries cannot erase a valid publication. Client-owned warnings and typed failures survive the artifact loop.

The two security regressions fail at the intended assertions on cf0442c and pass with the fix. Also addressed the follow-ups: no-position errors explicitly assert the daemon failure and warning; batch-close download failures give closed-session recovery hints; receipt strings have tested 4,096-character bounds; malformed receipts disclose typed failure on success and error paths. The existing normalization re-export stays, with one implementation in contracts.

The exact final affected gate passed all 42 runnable checks (25 owned skips): 20,395 unit tests passed/10 skipped and 306 provider tests passed. Source remained unchanged. Coverage passed at cf0442c; the new head will run its own hosted Coverage and reviews. The PR remains out of draft and watched.

@thymikee

Copy link
Copy Markdown
Member Author

The PR is ready at 63c6341: the earlier findings from cf0442c (#4627 (comment)) are fixed, and I found nothing new that needs a code change. Receipt failures are now disclosed before the record lookup, in https://github.com/callstack/agent-device/blob/63c6341/packages/daemon/src/session-script-destination.ts#L114-L118. Not blocking: the disclosure fix re-adds the normalizeBatchCommandName re-export in packages/command-registry/src/batch-policy.ts that an earlier commit removed, so the symbol again has two import spellings (@agent-device/contracts/command and @agent-device/command-registry/batch-policy); you can drop it and keep the contracts import, or take it or leave it.

The open inline thread on receipt-failure ordering (#4627 (comment)) no longer applies at this head, so you can resolve it.

Hosted CI for this head is still running, including Numeric Ranges. The new SCRIPT_DELIVERY_RECEIPT_MAX_STRING_LENGTH = 4096 constant in packages/kernel/src/contracts.ts is the kind of literal the numeric-ranges job scans, so check that job first if it fails. Before merge, hosted CI needs to finish green on 63c6341. An independent security cross-check of this head is running before the label.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remote script recordings: deliver batch step scripts through one daemon-side delivery receipt

1 participant