Repository navigation
fix(remote): write record stop output only to request-named destinations - #4724
Conversation
… 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>
Size Report
Startup median (7 runs, lower is better):
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on d4a4056. The verdict and the full list are in the summary comment.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 finding moved to a new line on 86adcdb. The verdict and the full list are in the summary comment.
|
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 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 commands.md:170 says remote recordings download to the path given to Would a client-only design work? On remote 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>
|
Pushed 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. |
|
Pushed The previous Android smoke job read |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the update. At d9f564f the permanent lockout is fixed: stale grants are swept after 7 days, A grant is released only by a matched producer echo (daemon-artifacts.ts:630), by a top-level 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 Not blocking, take or leave: retireClosedScopeCaptureGrants acts only when req.command is 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 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. |
|
Pushed I traced session and lease scope on all three built-in surfaces. CLI flags and saved connection defaults feed Both threads are resolved. The 63 focused tests, four two-process CLI tests, and release-tag wire check passed. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 70ff1e3. The verdict and the full list are in the summary comment.
|
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 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.
|
Design answer: the client-only design works. Per-start identity gives no extra protection.
Changes at
Line counts (non-test
|
|
Shape decision for the review at 373bac1: the wire change. I will not patch the inference again. Chosen shape
Why
Older daemons
Also in the same push
|
…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
|
The daemon adds 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 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. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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: Notes for #4834, not for this PR:
The code-scanning thread on the test-only loopback server does not apply and can be resolved: it echoes a basename as 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. |
|
Fixed in 5fb6548. Docs only.
The five notes are in #4834 as items 8 to 12. The code-scanning thread is resolved. Validation: |
This comment has been minimized.
This comment has been minimized.
|
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 For #4834, not for this PR: Not verified here: only the change since 094b8c3 (help and docs text) was re-checked; |
|
Applied the optional precision in 76beca6. One sentence in |
…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 · ✅ Approve · review of
|
| 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.
|
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. |
Summary
For #4518, the remote client ignores the daemon's destination paths when it saves a
record stopvideo, 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 stopwithout a destination now saves the recording in the working directory and addsrecordingDestinationWarningsand a human-readable warning. This changes where a recording lands when the only path was supplied torecord start.Deferred hardening: #4834.
Validation
d915f7b5a544399cedd9fba4117179ef743159e5. The 11 recording regression cases fail with the two production files restored toorigin/mainand pass with the fix.