Skip to content

feat(remote): write the --save-script recording to the caller during the session and at close - #4511

Open
bradenbiz wants to merge 19 commits into
callstack:mainfrom
bradenbiz:feat/remote-active-script-publication
Open

bradenbiz wants to merge 19 commits into
callstack:mainfrom
bradenbiz:feat/remote-active-script-publication

Conversation

@bradenbiz

@bradenbiz bradenbiz commented Nov 13, 2026 •

Copy link
Copy Markdown

Summary

A remote open --save-script=<path> now works like a local one, with no new command or flag:

agent-device open Settings --platform ios --session journey --save-script=journey.ad
agent-device wait 'label="General"' --session journey   # journey.ad holds open + wait
agent-device close --session journey                    # journey.ad gets the final script
  • The client mints a publication ID and records the destination before the open leaves; the request carries only the ID.
  • The daemon stamps that ID and a growing revision on each version, written 0600 in a private directory, registered for the opening tenant.
  • The client writes only its own record's newer versions: capped at 8 MiB, staged privately, settled crash-safely, first version exclusive unless --force.
  • A failed script write or download keeps the action's success; the daemon RPC response carries scriptDeliveryFailure and a warning. The script-artifacts health capability gates older daemons.
  • A batch that would close an armed remote recording is refused (remote_script_batch_close_unsupported).

Known limitations: #4564 (SDK, CLI and MCP disclosure; batch delivery) and #4565 (writable ancestor directories, shared with local sessions). Local sessions are unchanged. ADR 0016, help and docs updated.

Validation

Head 837f1a477c: typecheck, lint, Fallow, production exports, layering, doc prose, ADR citations, check:daemon-wire-compat and the eager-closure budget (no growth) passed, with daemon, daemon-client and remote unit tests and the remote provider scenarios. Each new test fails when its code is broken. No device run; CI owns the full gate.

🤖 Generated with Claude Code

@thymikee

Copy link
Copy Markdown
Member

Reviewed 79ff421. Remote script publication can lose a recording when the caller's target file already exists, and the proxy help and docs still say remote publication is refused.

When session save-script <path> names an existing caller file without --force, the no-clobber precheck does not run, because it only covers open (daemon-artifacts.ts:120). The daemon writes to a fresh temp path and succeeds, and markActivePublicationDone sets the status to published (session-script-publication.ts:70). The client then fails with script_target_exists in materializeScriptArtifact (artifact-download.ts:237). A retry with --force is refused because a published session is not eligible (session-script-publication.ts:123-126). Locally the refusal happens before markActivePublicationDone, so the session stays armed and --force works. A remote agent that follows the usual "file exists, retry with --force" recovery cannot republish through the CLI. The rule should be: every caller-side refusal that local publication would raise happens before the daemon consumes the one-shot publication, or the published remote target stays re-downloadable through the CLI. The smallest fix is to apply the open-time existence check to the active branch too, and/or let session save-script on a published session with a clientPath re-emit its retained artifact instead of refusing. Please cover it with a test that publishes to an existing file, then retries with --force and gets the script.

The proxy command help still says remote requests refuse script publication (command-overrides.ts:163), and remote-proxy.md:106-112 says the same and points to a local daemon. This PR removes that refusal for open --save-script and session save-script (remote-host-input-policy.ts:59-74), so agents reading the help are told the opposite of what works. Please update both to say remote callers can arm with a fresh open --save-script and publish with session save-script, which downloads a session-script artifact, while other script publication (close/replay --save-script, batch steps) stays refused.

Not blocking, take or leave: remote versus local publication is inferred from the client's clientArtifactPaths.savedScript hint (session-script-writer.ts:128) rather than from internal.publicNetworkOnly at arm time, so a direct HTTP RPC caller without that hint gets no artifact and leaves an orphan script in daemon temp; retention after download matches artifactType === 'session-script' in artifact-tracking.ts:328 where a retainAfterDownload on the registration would match deleteAfterDownload; the client and the HTTP boundary each allocate a script path (http-authorization.ts:77); bare remote open --save-script defaults to recording-<Date.now()>.ad in the caller cwd, which replay-e2e.md does not document (daemon-artifacts.ts:117); ledger.json replaces existing rationale entries instead of amending them and re-escapes an unrelated #2198 entry; and the literal 'session_save_script' in daemon-client-rpc.ts:216 and daemon-artifacts.ts should be INTERNAL_COMMANDS.sessionSaveScript.

Could remote support be a DAEMON_CAPABILITIES entry on /health, read by readDaemonCapabilities, instead of the activeScriptArtifacts boolean? That would drop the bespoke field from contracts, transport, lifecycle, metadata and about seven ledger entries, and ADR 0006 already says an absent capability means "cannot". The same simplification would mark the target as remote-delivered from publicNetworkOnly at the HTTP boundary, with one allocator for the daemon path, and declare retention on the artifact registration. Making a published remote target re-downloadable through session save-script would also make the first problem recoverable without raw HTTP. Nothing needs to change first beyond adding the capability name and a health capabilities field.

No checks have reported on this draft head. The description says check:affected fails one test, remote-proxy-artifact-fetch-tenant.test.ts (500 instead of 401), and that it also fails on b68ed4b. That test covers the artifact download and tenant path this PR changes, so please show it failing on base in CI before calling it unrelated. I did not run any tests or a live remote proxy run. The next step is to fix the two problems above and get CI green on this head.

@bradenbiz

Copy link
Copy Markdown
Author

Note

🤖 gpt-6.1-sol responding on behalf of bradenbiz

Good point that consuming publication before a caller-file collision breaks normal recovery; 081d14b makes session save-script re-download the same retained script, with regression coverage for collision/--force, immutable bytes, original action count, and destination-specific overwrite permission.

The docs fix and simplification also use the shared capability parser, daemon-side allocation, explicit remote delivery, and registration-owned retention while preserving local HTTP behavior.

The controlled Linux CI comparison ran the tenant-upload test on both unchanged base b68ed4bf2 and revised head 2be928f10: both passed, so the local failure remains unexplained and I am not treating it as a proven upstream failure.

The exact-head local gate passed its code checks but stopped at Android SDK configuration during packaging, reproduced with the same command on clean base; will you please approve the PR’s CI workflow runs so the full upstream CI can run?

@thymikee

Copy link
Copy Markdown
Member

This PR is ready at 2be928f. It fixes the problems in the earlier review of 79ff421, and I found no remaining problems in the diff. Not blocking, and you can take or leave these: /health hand-writes capabilities:['active-script-artifacts'] while daemon.json publishes DAEMON_CAPABILITIES, so it could name the HTTP subset once next to DAEMON_CAPABILITIES and use it there; also, daemon-client-transport.ts loses about fifteen blank lines between unrelated functions, which you could restore unless a gate needs the line count.

No conflicts. I judged this from the diff and did not run tests or a live remote proxy run. Upstream CI has not reported on 2be928f yet. You report remote-proxy-artifact-fetch-tenant passing on base and head in your fork CI, and I did not open that run. That test covers the artifact download route this PR changes, so it must pass upstream on this head before merge.

The PR is still a draft. Please mark it ready for review when you consider it done, so the upstream checks can run.

@bradenbiz
bradenbiz marked this pull request as ready for review November 13, 2026 20:55
@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 13, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 43 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

Comment thread packages/remote/src/daemon-artifacts.ts Resolved
Comment thread packages/remote/src/daemon-artifacts.ts Resolved
Comment thread packages/remote/src/daemon-artifacts.ts Resolved
@thymikee

Copy link
Copy Markdown
Member

Pushed e60f95f to fix the Coverage failures, using maintainer edits:

  1. daemon-runtime-quiesce.test.ts: this PR adds the active-script-artifacts capability on purpose, so the test now expects ['quiesce', 'active-script-artifacts'].
  2. daemon-client-transport-health-compat.test.ts: changed the code, not the test. The health reader now omits capabilities when a link doesn't report it, the same way it handles instanceId and hostArch. Older daemon payloads parse exactly as before.
  3. Eager closure budget: remote/src/daemon-artifacts.ts checks 'session_save_script' satisfies InternalCommandName with a type-only import instead of reading the runtime INTERNAL_COMMANDS catalog. Its closure is back within budget (no budget change). The command-registry dependency stays, now for types only.

@thymikee thymikee changed the title feat(remote): download ordinary recordings without closing the session feat(remote): write the --save-script recording to the caller during the session and at close Nov 15, 2026
@thymikee

Copy link
Copy Markdown
Member

@bradenbiz I pushed 2c6bbe0 to reshape this PR. Your use case keeps working through default behavior, with no new command or flag:

  • open --save-script=journey.ad against a remote daemon writes journey.ad on your machine. Each later action in the session refreshes it with the recording so far. An externally owned session that you never close therefore still leaves the journey in the file.
  • close writes the final script there, as a local close does.
  • The server parts are reused: the daemon-allocated output, the session-script artifacts on the authenticated download route, atomic client writes, and the health capability. Remote session save-script, --force, and the retained re-download protocol are removed.

Local sessions behave exactly as before. ADR 0016 and the docs are updated. Please check that this covers your flow.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 45 files (changes from recent commits).

You’re at about 93% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Requires human review: Auto-approval blocked because this review re-detected 3 unresolved issues already reported by Cubic.

View guided diff | Re-trigger cubic

Comment thread src/commands/schema/cli-help.ts Resolved
Comment thread website/docs/docs/remote-proxy.md Resolved
Comment thread packages/remote/src/daemon-artifacts.ts Resolved
Comment thread website/docs/docs/replay-e2e.md Resolved
@thymikee thymikee removed the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 15, 2026
@thymikee

Copy link
Copy Markdown
Member

Hardened remote script delivery in 70e9f8b..14ca828:

  • Write authority stays on the client. The daemon no longer stores or echoes the caller path. The client records the open --save-script destination in its state directory, bound to endpoint, tenant and session, and writes session-script artifacts only there. Unsolicited artifacts, artifacts naming another path, and artifacts for a joining client are dropped.
  • Ordering. Each version carries a per-session scriptRevision. The client stages the download and renames it under a cross-process lock only when it is newer than the last published revision; close removes the record, so a late older version never replaces the final script.
  • Daemon write failures. The action keeps its success and the response carries a typed scriptDeliveryFailure (script_delivery_failed) with a recovery warning.

New tests cover the unsolicited, changed-destination and joining-client cases, reversed completion (action vs action and action vs close), a routed daemon write failure, and a client refresh-download failure that runs exactly one device action and keeps its dispatch disclosure.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 20 files (changes from recent commits).

You’re at about 93% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

View guided diff | Re-trigger cubic

Comment thread website/docs/docs/remote-proxy.md Resolved
Comment thread packages/remote/src/daemon-artifacts.ts Resolved
@thymikee

Copy link
Copy Markdown
Member

Updated in 4f0e163:

  • The savedScript field now always goes through the session-script owner. An artifact of another type is dropped, so it never reaches the generic writer or follows a symbolic link.
  • The daemon mints a recording ID at open. Every script artifact and delivery failure carries it, and revisions are scoped to that recording. The client publishes only for the recording it recorded, and close removes only that recording's record. A late response, a late close, or a record left after a crash cannot write into a later recording.
  • The client record keeps the --force grant. The first version is created exclusively unless force was granted, so a file that appears while open is pending is kept.
  • A remote close that cannot write the final script keeps its outcome and returns scriptDeliveryFailure with a warning. The client then removes its record. A local close still fails as before.

ADR 0016, the remote-proxy and replay docs, and the wire ledger are updated.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 14 files (changes from recent commits).

You’re at about 93% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

View guided diff | Re-trigger cubic

Comment thread website/docs/docs/replay-e2e.md Resolved
@thymikee

Copy link
Copy Markdown
Member

Pushed 5be37a6b2e with the remaining fixes:

  • Script versions now register for download whatever network marker or capture filter the request carries. A direct daemon without an auth hook, and recorded trace, record and perf requests, now refresh the caller file. Covered by new direct-daemon and capture provider scenarios.
  • The client claims the destination before it sends the open. A delayed open answer can no longer replace a newer recording or bring back a closed one.
  • A successful close retires the record in every case: a failed final download, a failed destination write, and an aborted recording (close now always names the recording in scriptRecordingId).
  • The ownership map now names remoteCloseScriptDelivery.
  • Version checks return a typed result. The revision cursor is per recording. A version over 8 MiB is refused before the client reads it into memory.

ADR 0016 and the PR body are updated.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 13 files (changes from recent commits).

You’re at about 94% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@thymikee

Copy link
Copy Markdown
Member

Pushed 6edba17bc6:

  • Close after a capture. Close now takes the final version from the close-time write, so stopping an app log, audio probe, screen recording or perf capture first no longer drops it. Covered by routed app-log and audio-probe scenarios.
  • Crash between publish and cursor. The record names the version and the staged file's identity before the rename. The next version settles that entry from the destination, so an older version never replaces newer bytes and the first-write case never sticks on EEXIST. Tests inject crashes before and after the rename.
  • Overlapping opens. A successful open binds its own claim and drops older ones; a refused open drops only its own claim. An earlier recording is no longer stranded.
  • Limits and staging. The 8 MiB cap is enforced while the download streams. Versions stage in a private 0700 directory beside the destination and are renamed or linked into place, with no in-memory copy or second temporary file.
  • Security pass. Script versions now register for the tenant that opened the recording, so a request without a tenant cannot expose a tenant's recording. A failed daemon write no longer returns the daemon-host path.
  • Delivery closures folded into materialization; the remote version write shares the ordinary writer. ADR 0016 and the remote proxy doc updated.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 23 files (changes from recent commits).

You’re at about 94% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

View guided diff | Re-trigger cubic

@thymikee

Copy link
Copy Markdown
Member

Pushed 6d6a4280a8 with the remaining fixes:

  • Private destinations. A remote --save-script destination is refused before the claim (script_destination_not_private) unless every directory and link on the way belongs to the user or root and no directory is writable by group or others without the sticky bit. Versions download into a 0600 file opened with O_CREAT|O_EXCL|O_NOFOLLOW; a missing parent is created 0700. Local publication was checked and left unchanged: it writes through a descriptor to an unpredictable sibling name, so it cannot be redirected into another file, though it gives no integrity guarantee in a directory others can write.
  • Inode reuse. A failed rename settles the pending version under the lock before the staged file is removed; after a crash the staged file stays, so its inode cannot pass as a published version.
  • Claims. The claim waits within the request deadline and cancellation, every settled request removes its own claim, and claims carry their owner and time so dead or hour-old claims and tombstones are reclaimed. The caller path is no longer serialized.
  • Tests and docs. Byte equality, forced overwrite, aborted-close bytes, typed rejections and type-selected artifacts in the routed scenarios; help, proxy and replay docs, and ADR 0016 updated. The audio-probe close case was removed: on non-macOS hosts it cannot start, and a web-backed variant did not exercise the close path. The app-log case covers it on every host.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 20 files (changes from recent commits).

You’re at about 94% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread website/docs/docs/remote-proxy.md Resolved
Comment thread website/docs/docs/remote-proxy.md Resolved
@thymikee
thymikee force-pushed the feat/remote-active-script-publication branch from 6d6a428 to a06b7ab Compare November 15, 2026 16:32
@thymikee

Copy link
Copy Markdown
Member

Redesign round: a remote open --save-script now uses a client-minted publication ID recorded before the open is sent, in place of claims, binding and tombstones. The destination-folder policy is removed (local semantics), daemon script versions are written 0600 in a 0700 directory, and the remote script code loads lazily, so the eager closure does not grow. Both download leaks are fixed. A follow-up keeps an armed recording when only its first download fails, reclaims interrupted staging, and drops script artifacts under other fields. Production change is about 1,050 lines, down from about 1,500.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files (changes from recent commits).

You’re at about 94% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread test/wire-compat/surface.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files (changes from recent commits).

You’re at about 94% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread test/wire-compat/surface.ts Resolved
@thymikee

Copy link
Copy Markdown
Member

This PR is ready at 6e9e016. The redesigned recording delivery looks correct, and the fixes since the earlier review (2be928f, #4511 (comment)) hold: force comes only from the client's own record, a bare --save-script cannot overwrite, close takes the final version from the close-time write, and a lost open answer or failed first save keeps the record. CI is green at this commit (16 checks, none failing) and there are no conflicts. Nothing else must happen before merge.

Not blocking, and you can take or leave these: (1) a client-side download or save failure for a script version, in https://github.com/callstack/agent-device/blob/6e9e016/packages/remote/src/session-script-destination.ts#L205, throws out of materializeRemoteArtifacts, so an action that succeeded on the device reaches the caller as a failure, while the same failure on the daemon side keeps success and adds scriptDeliveryFailure. A script delivery failure should never change the outcome of the action that recorded it, so converting the client-side error into the same scriptDeliveryFailure plus warning in SessionScriptDelivery.publish (and updating the remote-proxy.md sentence) would match the daemon side. (2) sendRemoteScriptOpen at https://github.com/callstack/agent-device/blob/6e9e016/packages/remote/src/session-script-destination.ts#L83 decides whether a recording is armed by matching two client reasons, but the record is inert and the weekly sweep collects it, so removing it only when the daemon answered without naming the id would let you drop that reason list.

The open inline threads from the earlier round are arbitrated: all of them are fixed at this commit or no longer apply, so you can resolve them.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 15, 2026
thymikee and others added 3 commits November 15, 2026 20:48
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A record that a publish refreshed after the age check is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a script version

A client-side download or save failure for a script version now returns
the same scriptDeliveryFailure and warning as a daemon-side one, so it
never changes the outcome of the action that recorded it. A failed open
keeps its inert record, and only a daemon answer that does not name the
publication ID removes it, so the save-failure reason list goes away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the feat/remote-active-script-publication branch from 6e9e016 to 80eacfa Compare November 15, 2026 19:50
@thymikee

Copy link
Copy Markdown
Member

Rebased onto main 89485f9 as 80eacfa. The conflicts were in the remote health probe and its retry, where main moved the health cache and recovery; the capabilities assignment now sits after the new recovery path. The non-blocking notes are applied: a download or save failure on this machine keeps the action's success and returns the same scriptDeliveryFailure and warning as a daemon-side failure, and a failed open keeps its inert record, so only a daemon answer that does not name the publication ID removes it. Docs and ADR 0016 follow.

…tries

A close whose record cannot be retired keeps its outcome; the inert record
is swept later. A retry after the remote daemon instance changed checks the
script-artifacts capability again before it resends a remote recording.
The save-failure hint no longer promises an unchanged file, and a close
names that no later version follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member

Follow-up at c54d00a: a close whose record cannot be retired keeps its success (the inert record is swept later), a retry after the remote daemon instance changes checks the script-artifacts capability again before resending a remote recording, and the save-failure hint no longer promises an unchanged file.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files (changes from recent commits).

You’re at about 94% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

thymikee and others added 2 commits November 15, 2026 21:06
…rite

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A digest response view narrows a command's own result but now keeps
scriptPublicationId and scriptDeliveryFailure, so a snapshot or screenshot
at responseLevel digest still reports a failed script delivery. The client
record lists each staging directory before a download writes to it, so
retiring or sweeping the record removes the staging a crashed download
left behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member

Follow-up at 95bfc9a: a digest response view (snapshot, screenshot, and the other leveled commands) now keeps scriptPublicationId and scriptDeliveryFailure, and the client record lists each staging directory before a download writes to it, so retirement or the stale sweep removes staging a crashed download left behind.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files (changes from recent commits).

You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

thymikee and others added 2 commits November 15, 2026 21:21
A staging directory that cannot be removed now stays listed, so
retirement or the stale sweep still finds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ate it

Retiring or sweeping a record removes its listed staging directories
before the record, and a private-file download requires the staging
directory its caller allocated instead of recreating a retired one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files (changes from recent commits).

You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

A batch delivers no script versions from its steps, so a close inside it
would lose the final script. The batch is refused before any step runs
with remote_script_batch_close_unsupported. ADR 0016 and the remote docs
record the refusal and link the follow-ups for SDK, CLI and MCP
disclosure and batch delivery (callstack#4564) and for writable ancestor
directories (callstack#4565).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member

Following the maintainer decision: a batch whose steps would close an armed remote recording is now refused before any step runs (remote_script_batch_close_unsupported); run close on its own after the batch. SDK, CLI and MCP disclosure of scriptDeliveryFailure and batch delivery are tracked in #4564, and the writable-ancestor exposure shared with local sessions in #4565. Also in 0444b83: staging stays listed until it is removed, and a private download never recreates a retired staging directory.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 8 files (changes from recent commits).

You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

thymikee and others added 3 commits November 15, 2026 21:39
The refusal reads the steps as the batch runs them, so a close spelled
with other case or spacing is refused too, and malformed steps get the
batch's own INVALID_ARGS refusal instead of a type error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…taging

Retiring or sweeping a record first writes it without the interrupted
version it names, so a failed record removal never leaves it naming an
inode whose anchor is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stale record whose staging cannot be removed now stays for a later
sweep, and the new open goes ahead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member

Thanks for the update. At 12736b6 the conflict from the earlier review (#4511 (comment)) is fixed, and one docs problem remains.

website/docs/docs/remote-proxy.md:115 says that when this machine cannot download or save a version, "the command also succeeds with a warning and a scriptDeliveryFailure". That holds for the RPC response only. Through the CLI and SDK, a close whose final version fails to download resolves in materializeRemoteArtifacts with the warning and scriptDeliveryFailure. Then sessions.close and apps.close in packages/client/src/index.ts (https://github.com/callstack/agent-device/blob/12736b6/packages/client/src/index.ts#L266-L276 and https://github.com/callstack/agent-device/blob/12736b6/packages/client/src/index.ts#L375-L385) rebuild the result without either field. The CLI then prints a plain Closed: <session> (https://github.com/callstack/agent-device/blob/12736b6/src/command-output/result-serialization.ts#L174-L189). No CLI, SDK or MCP surface carries scriptDeliveryFailure today. Issue #4564 defers this, and ADR 0016 lists it as a known limitation. A reader of the doc will see Closed: journey and conclude the final script reached the file. The file holds the previous version, and the session is gone, so no later version can follow. Please make every user-doc sentence about remote --save-script failures say what each surface shows today: the RPC response carries scriptDeliveryFailure and a warning, CLI, SDK and MCP results do not carry the field yet, and close shows no warning (#4564). The earlier "the command still succeeds and shows a warning" sentence in the same paragraph has the same close gap. Alternatively, keep the warning on the close result surfaces, which is the #4564 work.

Not blocking, and you can take or leave these: the only production caller in packages/daemon/src/sessions/handlers/session.ts:211 passes isArmedRemoteRecording(sessionStore.get(sessionName)), but the tests pass armedRemoteRecording=true by hand or test the predicate alone, so dropping that wiring would keep every test green; one test that sends a batch with a close step through handleSessionCommands against an armed remote session, asserting remote_script_batch_close_unsupported with zero steps invoked, would cover it. In session-batch.ts:36, assertBatchKeepsRemoteRecording normalizes the steps a second time before runBatch does and swallows errors with a bare catch; checking context.remainingSteps and the current step in the first invoke callback would let you delete the second normalization. In packages/remote/src/session-script-destination.ts:109 the client builds the scriptDeliveryFailure wire shape by hand, and the daemon builds the same field in session-script-publication-capability.ts:257-265; one shared ScriptDeliveryFailure type next to the response contracts would keep them in step.

Of the open inline threads, none still apply at this head, so you can resolve all five: the 'publishes nothing' test now isolates the retirement failure (#4511 (comment)), releaseStaging now unlists the directory even when rmSync fails (#4511 (comment)), a failed stale-record sweep in createRecord no longer blocks the open (#4511 (comment)), the close check now runs after trim and lowercase normalization (#4511 (comment)), and normalization errors now defer to runBatch's typed INVALID_ARGS refusal (#4511 (comment)).

The Coverage check fails on the MCP tool input-schema size budget. This PR changes no flag or input schema, and the same job also fails on main at 82819f8, so it looks unrelated to this change.

Before merge, remote-proxy.md must describe what each surface shows today, or the close result surfaces must carry the warning.

…at the first step

The remote proxy and replay guides now say what each surface shows for
an undelivered script version today: the daemon RPC response carries
scriptDeliveryFailure and a warning, while the CLI, SDK and MCP results do
not carry the failure yet and close shows no warning (callstack#4564). The batch
refusal checks the normalized steps in the batch runner's first step
instead of normalizing them a second time, and a session-router test
covers its wiring. The client and the daemon build scriptDeliveryFailure
from one ScriptDeliveryFailure contract type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member

Addressed the review of 12736b6 in 9e61d60: the remote proxy and replay guides now say what each surface shows for an undelivered script version (the daemon RPC response carries scriptDeliveryFailure and a warning; the CLI, SDK and MCP results do not carry the failure yet, and close shows no warning, tracked in #4564). The batch refusal now checks the normalized steps in the batch runner's first step, a session-router test covers its wiring, and the client and daemon share one ScriptDeliveryFailure type.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 8 files (changes from recent commits).

You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread website/docs/docs/remote-proxy.md Resolved
…oxy page

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member

This PR is ready at 837f1a4. The docs gap from the earlier review is fixed: remote-proxy.md now states the script-artifacts /health requirement, and it matches the client and proxy resolution code. I found no new problems in the changes since 12736b6.

Not blocking, and you can take or leave these: the failure in session-script-destination.ts is typed with String(...) wrappers after an as AppError cast, which only silence the type checker today, so a future throw path without details would print a literal 'undefined'. Typing the failure at its source in scriptSaveError would let you drop the wrappers and the comment above them. The moved test 'malformed steps get the batch refusal' in session-batch.test.ts only checks INVALID_ARGS from runBatch's own validation, so deleting it or renaming it to say that would avoid confusion with the close refusal.

The three review threads no longer apply at this head, so you can resolve them: the /health docs requirement is added (thread), the close check now compares the normalized steps including the ' CLOSE ' case (thread), and malformed steps now fail in runBatch before any callback (thread).

The Coverage check is red on the MCP tool input-schema size budget. The same job has failed on main since 82819f8, and this PR adds no flag or input schema property, so it looks unrelated. Before merge, Coverage needs to be green again or accepted as the known main failure.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 15, 2026

This branch has not been deployed

No deployments
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.

2 participants