fix(remote): bind client artifact destinations to capture identity

Closed
TH
19h ago
+2137-226

Closed as superseded by #5338 on the 0.22 remediation line. Continue review and implementation there. Historical validation below remains attributed to its original commits; closure does not claim the replacements are merge-ready.

Summary

Bind remote trace and native perf destinations to the caller's capture ID. Daemon confirmation orders overlapping starts. A confirmed stop retires its capture under the record lock, even if the start reply is still pending. Tenant isolation uses the daemon's session naming rule. This client artifact layer was split from #5246 and is stacked on #5245.

Before / after

  • When a stop completed before its start reply, the late reply could restore the stopped capture. A matching stop confirmation now retires that generation before artifact download.
  • Under tenant isolation, capture and tenant-a:capture used separate records. Start, stop, and close now share a record.
  • Unnamed downloads receive unique filenames. Reusing a saved destination requires a matching capture ID.

Validation

f3f5575200 passed merge-tree and the changed declaration digests matched. Hosted checks pending.

At 55c76abacb, the build and all 54 focused tests passed. The reordered-start regression failed at 1082b8b351. Auth-hook aliases, the protocol-3 decision, and final-head live receipts remain open.

The previous guard job failed Fallow after passing wire compatibility. At 908766ae0b, all 11 perf runtime tests passed. All 20 hosted checks passed at that SHA.

Live HTTP at 27edb93b1c670ca2dec5f1d79595567244e52ea7 passed all four cases on iPhone Duo, iOS 27.1. Built CLI and XCTest runner, loopback proxy with isolated daemon state, and separate client-a and client-b state directories and working directories. Snapshots supplied fixture activity. The first xctrace stop failed. A fresh daemon and a recording interval produced the verified archive.

A: trace start ./saved.adtrace → trace stop
   {"trace":"stopped","outPath":"cwd-a/saved.adtrace"} 174463 bytes
A: trace start → trace stop (twice)
   {"trace":"stopped","outPath":"cwd-a/<unique>.log"} 5143 and 5144 bytes, distinct files
A: perf cpu profile start --kind xctrace --template "Time Profiler" --out ./native.trace
   perf cpu profile stop --kind xctrace
   {"perf":"stopped","outPath":"cwd-a/native.trace"} 1429171 bytes, valid gzip tar
A: trace start ./a.adtrace
B: trace stop ./first.adtrace → trace start ./b.adtrace
A: trace stop → exit 1, {"code":"INVALID_ARGS","details":{"reason":"capture-identity-mismatch"}}
B: trace stop → {"trace":"stopped","outPath":"cwd-b/b.adtrace"} 5386 bytes
Successful capture pairs returned matching clientCaptureId values.