Repository navigation
fix(remote): download trace and perf captures only to client-chosen or generated paths - #5338
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 8b5a62d. The verdict and the full list are in the summary comment.
- 🟡 Minor · readCaptureToken hard-codes the token prefix instead of CAPTURE_TOKEN_PREFIX ·
packages/remote/src/capture-destination.ts:17 - 🟡 Minor · Unique-name suffix keys on the command, not the artifact field, so other trace/perf artifacts are renamed ·
packages/remote/src/daemon-artifacts.ts:781
This comment has been minimized.
This comment has been minimized.
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: 1 new finding on 3648ee2. The verdict and the full list are in the summary comment.
- 🟡 Minor · captureAction lets parsePerfRuntimeRequest's INVALID_ARGS escape before a remote perf request is sent ·
packages/remote/src/capture-destination.ts:51
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 7c8f377. The verdict and the full list are in the summary comment.
- 🟡 Minor · trace/perf unique fallback sets fallback:true but no warning is ever emitted ·
packages/remote/src/daemon-artifacts.ts:773
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Review of 4b69a38: the change holds its main invariant, but six defects in how capture intents are scoped, retired and delivered need fixes before merge. CI is green, with 24 checks and none failing at this head, and there are no conflicts. A second independent pass found that two sessions or leases with the same local state, endpoint, credential and capture family can share a token. A pathless stop in the second session accepts the token learned by a named start in the first session, so it writes to the first capture's destination. Bind each intent to the local request scope as well as the token: tenant and lease identity for leased traffic, the caller's session identity for unleased traffic. Use the existing session and lease routing rules for aliases. A second independent pass found that a named start followed by a stop with a different explicit destination leaves the start intent alive. The unchanged daemon echoes the explicit stop path (trace-runtime.ts:89–107, session-perf-runtime.ts:379–390), so the client delivers it and returns without retiring the saved intent. A later pathless stop in the same scope can then write to the earlier capture's original destination. After a successful explicit stop, retire the pending start for that local request scope under the record lock. Keep a newer start if its generation already replaced the stopped capture. A second independent pass found that a daemon can turn a capture file destination into a directory. If the daemon describes the outPath artifact of a trace or native perf stop as test-artifacts, the token handler skips the intent, but the generic downloader still trusts the artifact type (artifact-download.ts:63–72 and :353–362). It then publishes an archive-named child under the selected file path. Allow directory delivery only for requests that expect a suite directory. For trace and perf outPath fields, require file delivery or reject a directory-shaped response. A second independent pass found that the cwd fallback can fail for a valid legacy basename. A legacy client that starts a trace with a 240-byte basename on a filesystem with a 255-byte component limit gets that basename echoed back (trace-runtime.ts:107). The 37-byte suffix then makes a 277-byte component, so the pathless stop fails with ENAMETOOLONG instead of writing the documented cwd file. The fallback also keeps the first dot-delimited stem from the response, which can retain a reserved device name on Windows. Generate the fallback basename locally from a fixed stem and a UUID. Keep only a validated, bounded suffix where the format needs one. A second independent pass found that a failed transfer renews a seven-day-old intent. A stop that claims an intent shortly before the limit rewrites the record through writeIntent, which refreshes its mtime. After the original seven days pass, readIntent (line 145) still authorizes the saved path, although remote-proxy.md:116 says it has expired. Record an immutable creation time and use it for both the expiry check and the eviction order. Store the claimed artifact ID separately. A second independent pass found that a v0.21.46 client treats a new client's token as a literal path. Start a named remote trace with a client at this head, then stop it without a path using v0.21.46 against the same daemon. The daemon returns the token in localPath, the released resolver (daemon-artifacts.ts:766) uses it directly, and a token-named file lands in cwd. The base preserves the chosen start destination for the same pair. The compatibility fixture (http-server-capture-destination-compat.test.ts:148–176) pairs each client's start with its own stop, so it does not cover this switch. Document the version boundary in the user-facing workflow, and require a token-aware stop or an explicit stop path when switching versions mid-capture. Transparent pathless compatibility would need a carrier that legacy clients do not interpret as a path. Not blocking, and these can be taken or left: intentPath, writeIntent, readIntent and the TTL sweep re-implement the destination-record store that script-publication-record.ts already owns, so one generalized store with a namespace parameter and optional max-count eviction would serve both; perf native-capture stop JSON now reports the token as Not verified here: no tests were run, and CI is the evidence for this head. Regression validity was judged from the diff, and the changed daemon-artifacts-capture case would fail on base. Not verified here: that client.stateDir equals settings.paths.baseDir on every transport path, that the layering parser output is byte-identical, or whether cloud-issued credentials rotate during a session. No live remote run exists at this head. The change is client-side delivery, so live evidence was not treated as required. After the fixes, a push with matching tests for the scope binding, the explicit-stop retirement and the directory-delivery check is needed before merge. |
4b69a38 to
9286c42
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 3 new findings on 9286c42. The verdict and the full list are in the summary comment.
- 🟠 Major · Wire-compat ledger digest and ack for resolveMaterializedArtifactPath are left stale ·
packages/remote/src/daemon-artifacts.ts:758 - 🟡 Minor · Generated trace/perf name is keyed on the command, so non-outPath artifacts are renamed ·
packages/remote/src/daemon-artifacts.ts:758 - 🟡 Minor · trace/perf generated destination discards the response file name, losing its extension ·
packages/remote/src/daemon-artifacts.ts:758
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 41591ee. The verdict and the full list are in the summary comment.
- 🟡 Minor · perf trace/perf stop --kind perfetto or simpleperf downloads to an extensionless perf- ·
packages/remote/src/daemon-artifacts.ts:771(moved)
41591ee to
d5737ba
Compare
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 d5737ba. The verdict and the full list are in the summary comment.
- 🟡 Minor · cpu-profile and memory capture downloads can land on an extensionless perf- ·
packages/remote/src/daemon-artifacts.ts:772(moved)
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 6a9ff24. The verdict and the full list are in the summary comment.
- 🟡 Minor · trace/perf outPath branch ignores the artifact it is naming, unlike every sibling branch ·
packages/remote/src/daemon-artifacts.ts:749
|
Three problems remain at 6a9ff24, and the earlier findings (#5338 (comment)) are otherwise addressed: the ledger digests, the A second independent pass found that the earlier directory-delivery problem still holds at daemon-artifacts.ts:619. For a trace or perf A second independent pass found that remote-proxy.md:103 tells CLI users to run A second independent pass found that the Android profiling examples at cli-help-workflows.ts:165 set Not blocking, and fine to take or leave: after a remote None of the open inline threads from other reviewers still apply. These can be resolved: the ledger digests are updated at head (#5338 (comment)); the generated-name branch is limited to The only check not passing is Body rules, which was cancelled. It validates PR body text and does not exercise the changed routes, so it is likely unrelated; it needs a re-run to show green. No conflicts are known. Before merge, the three changes above are needed and the cancelled check must pass. |
6a9ff24 to
8442c27
Compare
|
Fixed in 8442c27 (rebased onto current 0.22). A trace or perf |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The three problems from the earlier review (#5338 (comment)) are fixed at 17408d5, but a second independent pass found one new problem: a failed trace or perf download can delete an existing local output file. CI is green at this head: 19 checks, none failing, and the Body rules check that was cancelled at 6a9ff24 has passed. No conflicts. When a trace or perf stop names an existing local output file, the remote daemon describes the outPath artifact as test-artifacts, and the download returns an error before writing any bytes. The base takes the directory branch, fails while preparing the existing file as a directory, and leaves the file alone. The new code sends that same response down the ordinary file branch. Its HTTP failure handler then calls rm on the caller's existing file, although the transfer never opened it (https://github.com/callstack/agent-device/blob/17408d5/packages/remote/src/artifact-download.ts#L63, L79, L184, L217; entry point https://github.com/callstack/agent-device/blob/17408d5/packages/remote/src/daemon-artifacts.ts#L623). The caller gets a download error and loses the previous file. The rule to satisfy: a test-artifacts response for a trace or perf outPath is rejected before the destination is prepared, so no failure path can remove a file the transfer did not create. Keep the existing suite directory delivery. A test for an existing output file plus a test-artifacts response should show the file is still there after the error. The four earlier inline threads on the ledger digest and the generated-name, suffix and --kind handling are fixed at this head and can be resolved (#5338 (comment), #5338 (comment), #5338 (comment), #5338 (comment)). The docs thread is also fixed (#5338 (comment)). The thread on generatedCapturePath ignoring the artifact does not apply, because that is the invariant itself: no daemon-supplied string reaches the local filename (#5338 (comment)). Not verified here: the changes were read, not run, so the new directory-shaped test case was judged valid from the harness and the old isDirectory expression. Not verified here: the full remote CLI to HTTP daemon to download route was traced in code but not run against a live daemon. After the fix above and green checks, nothing else stops the merge. |
|
Fixed at 458b9d5. A trace or perf outPath answered as |
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.
|
The code at 458b9d5 looks good. The earlier problem is fixed: a failed directory-shaped trace or perf download no longer deletes an existing output file. CI is green, with 19 checks and none failing. No conflicts are known, and nothing else blocks merge. The docs thread on perf download suffixes (#5338 (comment)) is fixed at this head, so it can be resolved. Not verified here: the new test was read, not run, and the full remote CLI to daemon download route was traced in code, not run against a live remote daemon. |
Summary
The client never writes a downloaded trace or perf artifact to a path the daemon echoes in
artifact.localPath. A remote daemon controls that value. Output goes to the command's own--out, else to a locally namedtrace-<uuid>orperf-<uuid>in cwd. A daemon-supplied name never sets the suffix:.log,.json,.tar.gz,.perfetto-trace,.perf.data,.hprofor.memgraphcomes from the local command and capture kind.start --out Xno longer carries over to astopin another process. Docs:website/docs/docs/remote-proxy.md. The wire ledger digest forresolveMaterializedArtifactPathand its compatibility acknowledgement are updated (client-only change).Before / after
Before:
trace stopandperf ... stopwrote to the daemon-echoedlocalPath, so../../etc/xor an absolute path worked.After: that branch is gone.
stoptakes its own--out.Validation
Head 8442c27; CI pending.
pnpm exec vitest run --project unit-core packages/remote/src/__tests__/daemon-artifacts-capture.test.ts: 27 passed. With the production file reverted to 0.22, 2 hostile-localPathtests fail. The suffix trace case fails without the suffix.wire-compat.test.tscovers the ledger.Production delta versus 0.22: +41 / -28 (69 lines) in
packages/remote/src/daemon-artifacts.ts.No unresolved risk known.