Skip to content

fix(remote): write record stop output only to request-named destinations - #4724

Merged
thymikee merged 66 commits into
mainfrom
t3/record-capture-grants-main
Nov 20, 2026
Merged

thymikee merged 66 commits into
mainfrom
t3/record-capture-grants-main

Conversation

@thymikee

@thymikee thymikee commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

For #4518, the remote client ignores the daemon's destination paths when it saves a record stop video, its chunks, and telemetry. Each file uses a path from the current request, or one plain file name in the working directory. The client generates a name when it cannot use the response name. It stages the download privately and publishes it by rename, which replaces a destination symlink without writing through it.

A remote record stop without a destination now saves the recording in the working directory and adds recordingDestinationWarnings and a human-readable warning. This changes where a recording lands when the only path was supplied to record start.

Deferred hardening: #4834.

Validation

  • Tested d915f7b5a544399cedd9fba4117179ef743159e5. The 11 recording regression cases fail with the two production files restored to origin/main and pass with the fix.
  • Passed 923 unit tests across remote, daemon-client, wire compatibility, and MCP, plus 13 provider tests.
  • Passed frozen install, build, format, typecheck, lint, production exports, Fallow, layering (including R89), agent guidance, and released-wire compatibility.
  • Serialized affected validation is queued behind the host validation lock. Hosted checks started after the push.

thymikee and others added 4 commits November 19, 2026 01:45
… grant ID per start attempt (#4518)

Corrected record slice of the reviewed defensive candidate (shared object
1685076dd5cb8c02c2151664991ad48fedc085c3, preserved untouched on
t3/defensive-capture-grants).

A remote response no longer establishes a local write destination on a finishing
capture action. The client mints one distinct grant ID per record start attempt and
persists the caller-named destination under the existing remote-connections state
owner BEFORE the request is dispatched — keyed by the immutable ID, never a
latest-slot overwrite and never created from the response. The daemon admits the
optional meta.captureGrantId on public record starts only (record-only scope; trace
and perf keep their existing paths), binds it to the accepted capture in the producer
lifecycle envelope metadata, and the matching stop echoes it from that capture's
durable record; the internal fencing token never leaves the envelope.

A persisted start destination is authorized EXCLUSIVELY by the producer-echoed grant
ID matched against the persisted record with the full scope (endpoint/tenant/run/
lease/session/slot). There is no scope-open fallback for a missing echo (older
daemon) or a nonmatching ID, and no generation is ever inferred from an unbound
response: in those cases only the current request's own registered paths win and
everything else keeps the pre-grant contained cwd-local name with a disclosed
diagnostic. A stop accepts a response localPath only as an allowlisted derivation of
the matched grant (exact, extension-appended, derived telemetry, part-NNN chunk).

Aggregate admission runs before dispatch under one shared state admission lock
(#4050 process lock): at most 64 grant records AND 8 MiB of TOTAL serialized
metadata, reserving room for the incoming record within that budget — never 8 MiB
per record. An uncertain census (store directory unreadable or unsizable) DENIES
admission instead of counting as zero. The bounded sweep removes only stale
KNOWN-FINISHED records: retained known-open and pending-recovery evidence is
preserved even when old, and unparseable records stay and still count (fail-closed).

An error answer to a finishing capture marks every known-open grant of the scope
pending-recovery — never one guessed grant — and nothing is authorized from response
text. An error answer to a capture start settles only the grant the request's own
evidence named (its meta.captureGrantId) as finished, a bounded cleanup; uncertain
records are never cleared. A matched stop settles its grant finished.

Wire shape is additive only (ledger acks recorded): optional meta.captureGrantId on
record starts, optional captureGrantId echo on capture responses/artifacts. Older
daemons echo no ID and behave exactly as before on the wire; older clients ignore
the new optional fields. Source and docs state this older-peer behavior honestly.

Adds a true two-process CLI fixture proof (test/integration, existing
runSourceCliJson owner): a withheld accepted start in one process/cwd still
authorizes the exact stop run as a separate CLI process in a different cwd over the
same state dir; an unmatched echo is refused to the contained cwd-local name; an
error stop answer leaves the grant pending-recovery. Benign loopback fixture only —
no exploit, no hostile payload, no real user paths or devices.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.47 MB 6.47 MB +1.9 kB
Package (unpacked) 6.47 MB 6.47 MB +1.9 kB
Package (download) 1.97 MB 1.97 MB +622 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 27.8 ms 35.2 ms +7.4 ms
CLI --help 64.9 ms 62.6 ms -2.4 ms

@apex-sentinel-staging

This comment has been minimized.

@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: 2 new findings on d4a4056. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@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 finding moved to a new line on 86adcdb. The verdict and the full list are in the summary comment.

Comment thread packages/remote/src/capture-grant.ts Resolved
@thymikee

Copy link
Copy Markdown
Member Author

Reviewed 86adcdb. CI is green (18 checks, none failing) and there are no conflicts, but I found two lockouts in the new grant store and one docs gap that need fixes before merge.

A successful remote record stop settles its grant to "finished", but sweepGrants removes finished records only after 7 days. censusGrants counts every record, and admission refuses at 64. The store lives in the shared state dir, so after 64 successful remote recordings in a week, every remote record start fails with capture_grant_admission_refused before dispatch. The PR's own cap test frees room only by rewriting updatedAtMs to 0. Main has no such cap. Rule: a grant record must not outlive the capture it covers. Delete it on a matched stop, so the cap bounds only unresolved records. The store owns this, so callers need no change.

Open and pending-recovery records are never swept at all (capture-grant.ts:391). Several normal routes finish a recording without a stop echo: session close or lease release (retainLeasedSessionRecording), daemon restart, a start whose answer was lost, a stop under a different lease scope, and any stop against an older daemon. Each leaks a permanent slot, so 64 runs of record start then close lock out remote record start until someone deletes files under remote-connections/capture-grants by hand. Rule: every grant record has a bounded lifetime owned by the store. Sweep unresolved records on the same horizon as the session-script store (STALE_RECORD_MS), and retire a session's grants on close the way that store does.

commands.md:170 says remote recordings download to the path given to record start. After this PR that holds only when the daemon echoes the grant. A daemon without the echo (every daemon older than this PR) or an unmatched grant writes to / and warns (daemon-artifacts.ts:800). Only docs/agents/security.md changed. Please add one sentence to commands.md and the remote-proxy "Download captures" section: a remote record stop writes to the record start path only when the daemon confirms that capture, and otherwise writes the file name to the current directory and warns with capture_artifact_local_path_refused.

Would a client-only design work? On remote record start, persist {destination, scope, createdAt} under remote-connections/capture-grants with a random ID and the session-script store's lifecycle: retire on matched stop and on close, sweep anything older than STALE_RECORD_MS, no census or state machine. On record stop, accept a response localPath only when it is an allowlisted derivation (the existing authorizedCaptureLocalPath) of a destination this client persisted for the same scope, then delete the record. That drops the kernel contract fields, daemon echo, input-policy narrowing, router field, wire-ledger churn, pending-recovery, census and byte reservation (roughly 400-500 production lines). It keeps the invariant that only client-owned capture state authorizes a destination, because every candidate is a path this client chose. It also keeps older daemons working and removes both lockouts. What would have to change first is #4518's generation-identity requirement: a client-minted ID echoed by the same daemon it was sent to gives no authority against that daemon. Is per-start identity needed beyond picking among the client's own paths?

Not blocking, take or leave: "pending-recovery" behaves exactly like "open" (both authorize, neither is swept), so that state, listOpenCaptureGrantsInScope, noteUncertainFinishingCapture and the transition-byte reservation could go; isRemoteCaptureStart in remote-host-input-policy.ts restates isCaptureStartRequest, and the record checks in daemon-artifacts.ts repeat one fact, so one predicate next to readCaptureGrantId in @agent-device/kernel/contracts could serve both sides, and the single-member CaptureSlot could go; no test sends a matched grant ID with a non-derived localPath, so a case in daemon-artifacts-capture-grant.test.ts would pin authorizedCaptureLocalPath; readCaptureGrantId is re-exported from capture-grant.ts and could be imported from the kernel contracts directly, with the long comments trimmed to the constraint; the PR adds about 894 net production lines, which the smaller design above would cut.

Of the open inline threads, the one on unswept open and pending-recovery records still stands, and the lockout is worse than it says because finished records also count for 7 days. The thread on unawaited settles no longer applies, since settles are now awaited (daemon-client-rpc.ts:42, daemon-artifacts.ts:766), so you can resolve it.

The lockout follows from the code and the PR's own cap test. Only the CLI transport path was traced; please confirm Node and MCP routes and teardown-retained recordings behave the same. The integration test uses a fake daemon that echoes the ID itself, so a run against a real daemon would help. Before merge, please bound the grant store lifecycle and document the older-daemon fallback.

…-script store

Review of #4724 found two lockouts in the new grant store and one docs gap:

- A successful matching record stop settled its grant to "finished", which the
  sweep removed only after 7 days while still counting toward the 64-record
  admission cap, so 64 successful remote recordings in a week refused every
  later remote record start. The grant is now deleted after a successful
  matching stop delivery — including a matching echo that carried no
  artifacts — so the cap bounds only unresolved records. A stop whose
  materialization failed retains the grant, because the daemon answered and
  a retried stop can still deliver to the granted destination.
- Open and pending-recovery records were never swept at all, so closes, lease
  releases, daemon restarts, lost start answers and stops under another lease
  scope each leaked a permanent slot. The admission sweep now removes every
  record untouched for the shared STALE_RECORD_MS horizon (the session-script
  store's clock, now exported from remote-state-record-lock), touching only
  stale .json entries of the capture-grants directory, and a successful close
  retires its own authenticated scope's grants — never another scope's.
- The finished/open/pending-recovery state machine, the transition byte
  reservation, listOpenCaptureGrantsInScope and noteUncertainFinishingCapture
  are gone: with delete-on-matched-stop, sweep-on-horizon and retire-on-close
  no record is ever mutated after admission, so the states distinguished
  nothing and the reservation had no transition to reserve for. The count and
  aggregate-byte bounds and the strict producer-echo/full-scope matching are
  unchanged, as is the cwd-local fallback for daemons that echo no grant ID.

All mutations run under the existing store lock (withRemoteStateLock).
commands.md and the remote-proxy "Download captures" section now state the
older-daemon fallback: a remote record stop writes to the record start path
only when the daemon confirms that capture, otherwise the file name lands in
the current directory with a capture_artifact_local_path_refused warning.

Tests cover the lockout (64 matched stops free the cap; stale unresolved
records are swept, fresh and unrelated entries are not), successful matching
stop deletion (with and without artifacts), retention on failed delivery,
successful and failed close, and cross-scope isolation, at both the store
level and through two CLI processes against a loopback fixture daemon.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@thymikee

Copy link
Copy Markdown
Member Author

Pushed 96f579afed. A matched stop now deletes its grant after delivery, including a stop with no artifacts. A failed delivery preserves the grant for retry. A confirmed close retires only its own scope. Admission sweeps unresolved grants at the same seven-day horizon as session scripts. The commands and remote-proxy docs now explain the older-daemon fallback and its warning.

A client-only store would satisfy the narrower rule that the client chose every eligible destination. It cannot identify which retained start produced a stop when starts overlap in local state because an answer was lost or reordered. For example, if A and B chose different paths in the same scope, a stop for A could be matched to B’s path by path membership alone. The echoed ID binds the normal daemon producer’s reply to A. It carries no independent proof against a daemon fabricating that ID, so the client still checks the full scope and allows only derivations of the matched client path. The proposed 400–500-line reduction would require dropping that generation requirement from #4518. This patch removes the grant state machine, recovery transitions and growth reservation while retaining the producer echo and admission caps.

The CLI, Node SDK and MCP remote routes all reach the same HTTP grant admission and delivery code. The daemon still owns teardown-retained recordings, and a confirmed close retires the client grants for that scope. Four spawned-CLI tests passed against a loopback fixture, and 22 real daemon handler, authorization and teardown tests passed. I did not run a live recording against a real daemon.

@thymikee

Copy link
Copy Markdown
Member Author

Pushed d9f564fd81 to address Fallow. The loopback fixture now handles stop responses separately from request routing. All four two-process tests and the Fallow audit passed locally. The change touches only the fixture.

The previous Android smoke job read ada@example where the form expected ada@example.test. The same assertion failed earlier on #4721. The new head will run smoke again with the assertions unchanged.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Thanks for the update. At d9f564f the permanent lockout is fixed: stale grants are swept after 7 days, close now retires them, and the releases are awaited. One problem remains, so this needs one more change before merge.

A grant is released only by a matched producer echo (daemon-artifacts.ts:630), by a top-level close (:554), or by the 7-day sweep (capture-grant.ts:374). Every remote record start with a baseUrl admits a grant, because prepareRemoteRecording always fills outPath. A daemon without the echo (every daemon before this PR, which the release-tag wire check still supports) releases nothing on a successful record stop, and the test at daemon-artifacts-capture-grant.test.ts:400 pins that. The same happens on a new daemon when the echo does not match. admitCaptureGrant refuses at 64 records (capture-grant.ts:156). So one session against an older daemon that records each test with start/stop and closes once at the end fails the 65th record start within a week with COMMAND_FAILED capture_grant_admission_refused, before dispatch. On main, record start has no such cap. This is the earlier lockout, now narrowed to echo-less stops.

The rule the code must satisfy: admission never refuses because of grants whose captures already ended, so every terminal event the client observes for a scope's recording removes that scope's grants. The daemon admits one live recording per session (record-runtime.ts:250), so any ok record stop ends every capture that scope's grants can cover. After a successful record stop, could you call retireCaptureGrantsInScope (record slot only) instead of the single-ID releaseCaptureGrant, whether or not the echo matched? Alternatively, let the cap evict the oldest record by mtime instead of refusing. That bounds the store on every route (echo-less stop, batch close, idle expiry, daemon restart) without a per-route hook, and an evicted grant only falls back to the disclosed cwd basename. Then update the test at :400.

Not blocking, take or leave: retireClosedScopeCaptureGrants acts only when req.command is close, so a batch with a close step ends the recording but retires no grants; eviction at the cap covers this, otherwise derive close from the batch receipt the way session-script-destination.ts:135 does.

On the open threads: the thread on the 64-record cap still applies for echo-less stops within the 7-day window, which is the finding above. The thread on awaited releases is fixed at this head (daemon-client-rpc.ts:41 and :125, daemon-artifacts.ts:631), so you can resolve it.

The two-process tests use a loopback fixture that echoes the ID itself, so the real producer echo is covered only at handler level. Please confirm that the Node SDK and MCP routes build the same transport (daemon-client-transport.ts:561), and that record start and close fill req.session and the lease scope the same way on every surface. A mismatch would make close retirement miss its grants.

The earlier Android smoke failure (ada@example vs ada@example.test) is on a form-typing path this diff does not touch, and the same assertion failed on #4721. No conflicts are known.

@thymikee

Copy link
Copy Markdown
Member Author

Pushed 70ff1e34c0. Admission now sweeps stale grants and evicts the oldest by modification time until the new grant fits under both caps. A delayed stop therefore cannot delete a newer grant in the same scope. An evicted grant falls back to the disclosed current-directory filename, just like a missing or unmatched echo. The updated older-daemon test admits a 65th start in the same scope, verifies eviction, and confirms the store still contains 64 records. The byte-cap test verifies that a grant that cannot fit on its own is refused without eviction.

I traced session and lease scope on all three built-in surfaces. CLI flags and saved connection defaults feed createAgentDeviceClient. MCP's common command inputs and Node SDK options enter the same client's execute, which resolves the session and builds lease metadata. The daemon transport normalizes tenantId, runId, and leaseId from metadata or flags and uses the same HTTP path for remote calls. record start and close use the same scope when given the same session and lease options. CLI-only saved defaults are not implicitly loaded by SDK or MCP calls.

Both threads are resolved. The 63 focused tests, four two-process CLI tests, and release-tag wire check passed.

@apex-sentinel-staging

This comment has been minimized.

@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 70ff1e3. The verdict and the full list are in the summary comment.

Comment thread packages/remote/src/capture-grant.ts Resolved
@thymikee

Copy link
Copy Markdown
Member Author

At 70ff1e3 the 64-record lockout refusal and the unawaited grant settle from the earlier review (#4724 (comment)) are both fixed. CI is green, with 19 checks and none failing, and there are no conflicts. No code defect remains.

One question from the earlier review is still unanswered, and it decides readiness: the PR is 870 net production lines, over the 700-line threshold. Would the client-only design work? On record start it persists {destination, scope, createdAt}. On stop it accepts a localPath only when that path is an allowlisted derivation of a destination this client persisted for the same scope. It retires records on stop, on close, or by age. That drops the kernel contract fields, the daemon echo, the router field, the wire-ledger churn and most of capture-grant.ts, and older daemons keep working. If #4518 requires per-start identity beyond choosing among the client's own paths, please say what that identity protects against. Otherwise, please shrink to that design.

Not blocking, and fine to take or leave: one record can still be up to the 8 MiB aggregate cap (https://github.com/callstack/agent-device/blob/70ff1e3/packages/remote/src/capture-grant.ts#L144), and then pruneGrantsForAdmission evicts every other grant, including other sessions. Only an SDK caller with a multi-megabyte path or scope can reach it, and the result is the disclosed cwd fallback. A small per-record cap (for example 64 KiB) would make the aggregate byte cap and its eviction branch unreachable, so you could delete them. The module doc at lines 34-37 and the SWEEP_SCAN_LIMIT doc at line 62 are now stale, because admission evicts past the caps instead of relying on them, and only close retirement uses the sweep limit.

The one lower-priority open thread, on the per-record size cap, still applies (#4724 (comment)). Two threads no longer apply and can be resolved: the 64-record lockout is deleted and the test admits 64 echo-less starts after a full store (#4724 (comment)), and grant settle is now awaited on the start and error paths (#4724 (comment)).

Every remote call goes through the single sendRequestWithTransport and withCaptureStartGrant path, and scope comes only from the wire request. The two-process tests use a loopback fixture that echoes the grant ID itself, so the real daemon echo is covered only at handler level.

…nations only

Per-start grant IDs add no protection: the daemon sees every ID it is sent,
so it can name the same set of client-chosen destinations either way. Drop
the kernel contract field, the daemon bind and echo, the router field and
the wire-ledger churn. The client saves each record start destination per
scope and accepts a stop localPath only when it derives from one of them.
Older daemons keep working.
@thymikee

Copy link
Copy Markdown
Member Author

Design answer: the client-only design works. Per-start identity gives no extra protection.

  • The daemon sees every grant ID that the client sends on record start. A hostile daemon can echo any of them. It can therefore choose among the same client-chosen destinations for the same scope. The client-only design allows exactly that set, and no more.
  • Verify and enforce client-owned destinations for remote capture stop and report #4518 asks only that a response cannot choose a path that the client did not choose. The scope check gives that. The grant ID only helps an honest daemon pick between starts, which is not a security property.

Changes at 1db0cad:

  • Removed the kernel captureGrantId fields, the daemon bind and echo, the router field, the input-policy change, and their tests. No compatibility shim.
  • Reverted the wire-ledger churn. Only 3 digests, 1 rationale, and 1 closure waiver change, because daemon-artifacts.ts is gated.
  • packages/remote/src/capture-destination.ts saves {destination, createdAtMs} per scope before dispatch. A stop accepts a localPath only when it derives from a saved destination for the same scope.
  • Records retire on a delivered stop (only the used ones), on a confirmed close (the whole scope), or by age.
  • Each record is capped at 64 KiB. Each scope keeps 16 records, and it evicts its own oldest record. The aggregate byte cap, its eviction branch, the sweep limit, and the stale docs are deleted.
  • Regression: a daemon localPath outside the saved derivations for the scope goes to cwd. This covers unit tests (outside path, non-chunk sibling, another session's destination) and the two-process loopback test.
  • Older daemons work again. The provider fixture runs without changes from main.

Line counts (non-test packages/ source, net, from git diff --numstat origin/main...HEAD):

  • Before, at 70ff1e3: 834.
  • After, at 1db0cad: 339.

pnpm check:affected --run passed at 1db0cad. Thread r4626666709 is resolved, because the aggregate cap is gone.

@thymikee thymikee closed this Nov 19, 2026
@thymikee thymikee reopened this Nov 19, 2026
@thymikee

Copy link
Copy Markdown
Member Author

Shape decision for the review at 373bac1: the wire change. I will not patch the inference again.

Chosen shape

  • The daemon states an explicit role and, for a chunk, an explicit chunkIndex on every recording artifact it registers in buildRecordingStopResponse. Roles are a closed set: the recording, its telemetry, and a chunk.
  • The client validates the artifact set once, before any download: known roles only; the role agrees with artifactType; one artifact per role and index; ids are non-empty opaque segments and the built URL addresses exactly that id under the artifact route; resolved destinations are distinct by parent identity and entry name.
  • The client then downloads and builds outPath, telemetryPath and chunks[] only from its own completed downloads, keyed by role and index.
  • The path-matching code is deleted: chunkOf, the first-chunk rule, and matching by peer path or position.

Why

  • This is the fifth round of guards around one inference. The honest Android route numbers chunks from 1 and the client guessed 0, so the guess also broke the ordinary case.
  • With a declared role and index, the first-chunk rule, the role contradiction and the id checks live in one validator. Production code should go down from 698 lines.
  • The change to the wire is additive: two new fields on an existing artifact entry. It needs a compatible-change entry in the ledger, and no protocol bump (ADR 0006).

Older daemons

  • An artifact with no role is not a recording file the client can place. The client delivers no recording path for it and reports that in the response as a typed warning. It does not fall back to matching by path. I add no compatibility path unless the maintainer asks for one.

Also in the same push

  • The retry on remote_instance_mismatch uses transport-owned provenance (the HTTP precondition rejection), never a peer details.reason.
  • Fixtures are generated from buildRecordingStopResponse, so the client tests use shapes that production sends.
  • A test proves that a two-chunk Android answer prints both paths in JSON and in CLI output.
  • The non-blocking notes: one shared helper for the destination check in the publisher module, the destination in the EEXIST details, a finite-number check, the stop result schema for a missing outPath, the destinationMode nit, and a refreshed Validation section.

…nts-main

* origin/main:
  feat(platform-apple): admit screen recording on watchOS simulators (#4819)
  feat(audit): run Apple's native accessibility checks on iOS (#4776)
  fix(test-app): make the reorder handle a labelled native hold-then-drag (#4811)

# Conflicts:
#	packages/command-surface/src/recording/index.ts
@thymikee

Copy link
Copy Markdown
Member Author

The daemon adds role and chunkIndex to recording artifacts. RPC protocol stays at version 3. Android starts at chunk 1.

The client validates the set before the first download. Tests cover unknown roles, role and type conflicts, duplicate roles, chunk indexes and IDs, empty and dot IDs, separators, and two destinations that resolve to one file. The two-chunk test uses the registered daemon response. It checks the artifact URL and both local paths in JSON and human output.

I removed chunkOf, the first-chunk rule, and matching by peer path or array order. The client reports paths from completed downloads. When an artifact has no role, the client skips it and reports recording_artifact_role_missing.

Only an HTTP instance precondition refusal permits a retry. The test with a peer error reason sends one stop.

Net production source lines fell from 698 to 673.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The maintainer cut this PR back to the #4518 invariant. The client uses a destination from the current request or saves the file in the working directory with a warning. It validates the file name, stages the download privately, and uses a rename to publish it. This covers the video, chunks, and telemetry.

#4834 tracks response filtering, explicit artifact roles, result classification, diagnostics, cancellation, fallback name collisions, and retry checks. The wire ledger records the client changes. The daemon uses the same wire format.

Production code fell from about 690 net lines (687 at the previous PR head) to 96. The diff against origin/main is:

 docs/agents/security.md                            |   2 +-
 .../src/__tests__/daemon-artifacts-capture.test.ts |   7 -
 .../daemon-artifacts-record-download.test.ts       | 174 +++++++++++++++++++++
 packages/remote/src/artifact-download.ts           |  29 ++++
 packages/remote/src/daemon-artifacts.ts            |  97 ++++++++++--
 .../remote-daemon-client.test.ts                   |  23 ++-
 test/wire-compat/ledger.json                       |  25 +--
 website/docs/docs/commands.md                      |   2 +-
 8 files changed, 321 insertions(+), 38 deletions(-)

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

094b8c3 holds the #4518 invariant: a remote response no longer chooses where the client writes. The video, chunks and telemetry go to a path from the current request or to one validated file name in the working directory, staged privately and published by rename. An independent second pass tried peer-supplied paths, names, ids and chunk rows against it and found no way out, and confirmed that Android's one-based chunks are all saved and reported. All checks pass and there are no conflicts.

One thing to fix before merge, because this PR changes the behavior the text describes: record start <path> no longer chooses the download location for a remote recording, but two texts still say it does. The proxy CLI help says "Screenshot, recording, performance, and trace paths select downloads on the client" (command-overrides.ts:163), and website/docs/docs/remote-proxy.md lines 93-95 say an output path "selects the download destination on your machine". A caller who follows either runs record start clips/demo.mp4, then record stop, and finds ./demo.mp4 instead. Please say in both that a remote recording downloads to a path named by the record stop request, or otherwise to the working directory with a warning. commands.md:179 is already right.

Notes for #4834, not for this PR:

  • If a later chunk or telemetry download fails after the video was already saved in the working directory, the error carries no warning or path for that saved file (daemon-artifacts.ts:573).
  • The record usage still reads record stop with no path, although a positional path on stop is the only way to name a remote destination.
  • localFileName repeats naming rules host-kit owns in windowsEntryName and scriptEntryName (entry-name.ts:96-131).
  • recordingDestinationWarnings is not declared on the stopped record result type or the output schema; the integration test needs a cast to read it.
  • Remote recordings now publish with mode 0600 instead of the usual 0644.

The code-scanning thread on the test-only loopback server does not apply and can be resolved: it echoes a basename as application/octet-stream to a test client that never renders it (thread).

Not verified here: the code was read and no tests were run. Windows behavior (rename over an existing file, device-name refusal) was checked by reading only.

@thymikee

Copy link
Copy Markdown
Member Author

Fixed in 5fb6548. Docs only.

  • proxy help: recording is no longer in the list of paths that select a client download. It now says that a remote recording downloads to the path named by the record stop request, or otherwise to the working directory with a warning.
  • website/docs/docs/remote-proxy.md: the same statement, plus that a path on record start does not select the download destination.

The five notes are in #4834 as items 8 to 12. The code-scanning thread is resolved.

Validation: pnpm check:command-docs, typecheck and format pass locally. Hosted CI is the validation for this head.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

At 5fb6548 the two texts from the last review are updated, and the #4518 invariant holds as reviewed at 094b8c3. All checks pass and there are no conflicts. Review has nothing blocking left.

One precision note, take or leave: remote-proxy.md#L97 says the path on record start has no effect on the fallback download. The directory does not carry over, but the file name does: after record start clips/demo.mp4, a record stop without a path saves ./demo.mp4. Saying "the start directory does not carry over; the fallback uses the file name" would be exact.

For #4834, not for this PR: recordingDelivery could reuse readResponseWarnings from packages/kernel/src/success-text.ts when it appends fallback warnings, as session-script-destination.ts does.

Not verified here: only the change since 094b8c3 (help and docs text) was re-checked; check:command-docs was not run locally.

@thymikee

Copy link
Copy Markdown
Member Author

Applied the optional precision in 76beca6. One sentence in website/docs/docs/remote-proxy.md: the directory of a record start path does not carry over; the working-directory fallback keeps only its file name. Nothing else changed.

…nts-main

* origin/main:
  refactor(contracts): bind only the interactor families an owner implements (#4821)
  refactor(gestures): move gesture algorithms out of contracts into @agent-device/gestures (#4823)
  docs(command-docs): add the shared option table and per-action option tables (#4824)
  docs(agents): hold a review to the PR's invariant and stop at a third round (#4835)
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of bdf2555

Since the review of 5fb6548: 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 (faa3c82ec103).

💬 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.

@thymikee

Copy link
Copy Markdown
Member Author

This PR is ready at bdf2555, and the doc and code changes since 5fb6548 look correct. All 20 checks pass, and the delta is two doc sentences that no job route covers. There are no conflicts, and nothing else needs to happen before merge. Not blocking, take or leave: remote-proxy.md:97 says the fallback keeps the record start filename unconditionally, but daemon-artifacts.ts:692 and :706-711 generate a filename when the reported basename fails local validation, so the text could say the fallback uses the reported basename when valid and generates one otherwise. Not verified here: that artifact.fileName on the daemon side is the record start file name.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 20, 2026
@thymikee
thymikee merged commit 64d7fc7 into main Nov 20, 2026
20 checks passed
@thymikee
thymikee deleted the t3/record-capture-grants-main branch November 20, 2026 20:14
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