Skip to content

fix(daemon): publish direct recordings with producer proof - #5099

Open
thymikee wants to merge 5 commits into
0.22from
fix/recording-producer-proof
Open

thymikee wants to merge 5 commits into
0.22from
fix/recording-producer-proof

Conversation

@thymikee

@thymikee thymikee commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Refs #4970. Supersedes the direct recording work in #5059. The live producer captures file identities before committing the export checkpoint and retains that proof after the checkpoint lands. The daemon writes the proof with completion and serves verified outputs under the producing lifetime, tenant, and lease. Suite delivery follows in #5100.

Before / after

  • Remote start returns a basename. Remote stop verifies the whole file set before publishing IDs. Named tenants cannot stop or retry recordings made without a tenant. A successor session cannot replay an earlier lifetime's manifest.
  • If the export checkpoint fails, the retry can produce new files and capture fresh proof. Checkpoint replays and memoized completions keep their original proof.
  • Missing or replaced files return path-free RESOURCE_EXPIRED. Unverified recovered or legacy exports stay on the host.

Validation

  • At 118d16f4a7, the new HTTP test reproduced the old expiry and then downloaded the re-produced video with the fix. All 40 focused tests, typecheck, and Fallow passed. All 11 runnable affected checks passed with exactCommit: true.
  • At 0f387473f8, all 11 runnable affected checks passed with exactCommit: true. The Android 16 run on fix(replay): publish recordings after suite archive copy #5100 included that commit and verified a decodable MP4 and telemetry from direct stop over HTTP.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.07 MB 5.08 MB +4.7 kB
Package (unpacked) 5.07 MB 5.07 MB +4.7 kB
Package (download) 1.55 MB 1.55 MB +1.6 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 14.9 ms 16.5 ms +1.6 ms
CLI --help 25.2 ms 27.8 ms +2.7 ms

@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 30 files

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

View guided diff | Turn on auto-fix | Re-trigger cubic

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

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

At bb6328c, six likely defects need fixes before merge. They can let another tenant or a later session reach a recording, certify a replaced file, return unusable IDs, or expose a host path. Each fix needs a test that reaches the described state and shows the expected refusal.

A second independent pass found a likely tenant gap at record-runtime.ts:554. On a shared-token daemon without an auth hook, an unnamed remote caller can start an unleased recording in a named session. A named tenant can address that session, because declared tenants do not partition it (tenant-trust.ts:21, session-routing.ts:49). The stop guard checks only string owners, so that tenant can stop the live recording, or retry a stopped one, and learn its artifact IDs (an expired-artifact error also prints the ID). The 401 on download prevents neither. Could every remote recording compare the canonical request tenant with the manifest tenant, with explicit null as unnamed and absent ownership as unknown, on both live stop and retry, before anything publishes or returns an ID?

A second independent pass found a likely lifetime gap at record-runtime.ts:606. A tenant stops a recording, closes the session with a retained lease, and reopens the same address on the same device. The new session has a fresh journal ID, but the address still resolves to the old completed manifest (session-store.ts:201 and :623). Recovery checks only session name and device (screen-recording-stop-recovery.ts:104), and the handler only tenant and lease, so a stop returns the previous IDs. When a session is bound, can its journal ID be required to match the producing lifetime before the manifest is served? Detached retry and download by ID should still work for the producing tenant and lease while the output is retained.

A second independent pass found a likely proof gap at screen-recording-session-resource.ts:108. The backend finishes a playable file, then the terminal manifest write fails once. The live binding stays open (transitions.ts:55) and the handle reuses the successful result (screen-recording-live-handle.ts:41). If the file is replaced before the next stop or teardown, the proof records the replacement, and the registry serves bytes the producer never finished. Android likely reaches this too when the native marker write fails after the finalization checkpoint (finalize.ts:101 and :228, stop-sequence.ts:95). Can identities be captured when the producer first finishes the files, before any fallible step that leaves a reusable completion, and carried through retries into the manifest? Changed identities, and replayed completions without that proof, should be refused.

A second independent pass found a likely first-publish gap at artifact-tracking.ts:344. A video or sidecar is removed or replaced after its identity is committed, while the live stop is still importing the publisher (record-runtime.ts:462). The identity check runs only on replay, so the stop succeeds with an unusable ID and installs a stale entry. Teardown uses the same branch (recording-outputs.ts:58). Can initial publication check every file against its committed identity before inserting any entry? A mismatch should return RESOURCE_EXPIRED, and teardown should leave the whole set unpublished.

A second independent pass found a likely error leak at artifact-tracking.ts:690. If a published file is removed and its ID is requested before a scan or timer retires it, the response carries the full daemon path, has no RESOURCE_EXPIRED reason, and maps to HTTP 500 (http-errors.ts:23 and :32). Can a missing committed recording return the same path-free expiry error as an identity mismatch, and retire its entry?

A second independent pass found a likely race at artifact-tracking.ts:580. A file passes the first lstat, then disappears or becomes a symlink during the yield at line 554. The O_NOFOLLOW open rejects it before the descriptor error handler, so the raw filesystem error, possibly with the host path, reaches the response (downloadable-artifact-http.ts:158). Can both failures of the verified open become the path-free expiry error and retire the entry, with the descriptor identity check kept before streaming?

Not blocking: take or leave these: use the registry's matchesTenantOwnedEntry rule for stop authorization too (record-runtime.ts:554); treat a missing registered file as expiry at the single registry read (artifact-tracking.ts:690); give capture-kit a typed owner for the reserved path and proof (screen-recording-session-resource.ts:85); mention in the PR body that record start now returns a basename outPath without sessionStateDir, and confirm no shipped surface requires that field (record-runtime-response.ts:36); store a null owner for unnamed screenshots too, since named tenants can still list and download them (artifact-tracking.ts:306); and derive remote on stop without clientArtifactPaths, which only record start sets (record-runtime.ts:494).

The design already matches the smaller shape that #5059 asked for: one terminal write, no pending export state, no retention module, and 207 net production lines. Could ownership be tightened further, with capture-kit taking the reserved path as a typed finish input and writing and reading the proof through one exported pair such as writeRecordingExportProof and readRecordingExportProof(envelope)? The daemon would then stop parsing remoteCaptureExport. Stop and download could also share one tenant predicate, and FileOutputProducer construction could own the null-owner rule for every output family.

None of the earlier threads still applies, so these can be resolved. A retry on a missing file is refused with RESOURCE_EXPIRED at publication, so no unusable path is returned, even though recovery skips existsSync. A retry now compares file identity before returning IDs. A stale retry after replacement now expires, with a routed test. Teardown now compares session ID, fence token and generation before retaining a recording. The unnamed owner is now stored as null, and the HTTP test asserts 401 and an empty inventory. Refusing older manifests without proof is deliberate under #4970, remote-proxy.md documents the operator path, and restart replay is out of scope.

The required evidence is satisfied. The Body rules check is cancelled, likely unrelated: it checks PR body formatting, which this diff does not exercise, and a body edit usually supersedes such a run. One other check, not a test job, is still running. The other 15 checks pass at this head.

Not verified here: CI test results at this head were not rerun or inspected, and the test counts come from the PR body. The live evidence is in #5100 at 42b91eb, which contains 7031f3b; its raw logs were not inspected. The latest commit changes only in-memory tenant matching and docs. It was not checked whether a shipped 0.21.x client or MCP surface requires sessionStateDir in the record start output. The earlier threads were not re-checked line by line.

The six fixes above need to land before merge. The maintainer decides whether the typed capture-kit owner and the shared tenant predicate belong in this PR, or in follow-up issues with the missing-file and screenshot-owner notes. The tenant gap above still needs its fix here.

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

@thymikee

Copy link
Copy Markdown
Member Author

All six blocking problems from the earlier review of bb6328c are fixed at 0f38747, with routed regressions. One problem remains: a failed export checkpoint can expire a freshly produced retry.

A second independent pass found this likely defect in screen-recording-session-resource.ts#L110. Take a remote Android stop where finalization succeeds, then the manifest rename for the export checkpoint fails before it lands. The wrapper stores the file identities before it calls progress.record (screen-recording-session-resource.ts#L145-L151). The live handle resets the rejected finish (screen-recording-live-handle.ts#L41-L49). The retry reads the prior checkpoint and finalizes again from the retained collected copy (stop-sequence.ts#L90-L105). The producer then rewrites the video and telemetry (finalize.ts#L127-L149, platform-runtime-screen-recording-output-host.ts#L11-L15, telemetry.ts#L32-L38). The new guard keeps the identities from the first attempt, so the retry commits a terminal manifest with stale proof. It returns RESOURCE_EXPIRED with no IDs, even when nobody replaced a file. On the base branch, the stop sequence finalizes again and returns the successful export, and bb6328c took identities from the result of the successful retry. The new HTTP tests fail the later terminal write or native marker, after the export checkpoint has landed.

Proof must belong to the export checkpoint that actually lands. If the write fails before that checkpoint is published, only its provisional proof should be dropped, so a retry that really finalizes again can record fresh identities. Checkpoint replays and memoized completions must keep the original proof. Please add an HTTP regression that fails the export-checkpoint rename once, then expects a successful download after the producer writes the files again.

This earlier thread on refusing a remote-style stop does not apply and can be resolved: #4970 requires that refusal so no caller-owned host file becomes a download, and a local stop still succeeds.

All 18 checks pass at this commit, and the required live evidence is in place.

Not verified here: the ten new HTTP tests were not run locally, and their failure on bb6328c was established by reading the earlier code. The raw logs of the #5100 Android 16 live run at bfd9e77 were not inspected. No iOS live run covers the finishLive checkpoint interception, although that capture-kit code is platform-neutral. The "missing open" spy may fire in an earlier openSync during payload preparation instead of in openRegisteredFile; the path-free 404 seen by the caller is asserted either way.

This retry problem needs a fix and its regression before merge.

@thymikee
thymikee added this pull request to stack #5106 November 25, 2026 12:07
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 118d16f

Since the review of 0f38747: 0 new · 0 still open · 1 no longer raised

No open findings.

2 findings below minor hidden (user_settings.min_severity).

2 new findings away from what changed since 0f38747 not shown. Comment @apex-sentinel-staging review for a full review.

Reviewed with this repository's own Sentinel configuration (36d95cc1d0cc).

💬 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

The remaining problem from the earlier review of 0f38747 is fixed at 118d16f, with a routed regression, and no new code problem was found. A failed export checkpoint no longer leaves stale file proof that expires a freshly produced retry.

This earlier thread on refusing a remote-style stop does not apply and can be resolved: #4970 requires that refusal, a local stop still succeeds, and the new change does not touch that code.

The required live evidence is in place. The Android 16 run from #5100 accepted in the previous round is enough, because the new change is a platform-neutral reorder in capture-kit.

Not verified here: the new HTTP regression was not run locally, and its failure on 0f38747 was established by reading the code, which identifies files by device and inode and replaces them through a temp-file rename on each finalize. A store write that throws after the rename lands, such as in a later fsync, is not handled: the checkpoint persists without cached proof, and the retry returns RESOURCE_EXPIRED. That fails closed, and no route to it was found in the current write path.

The other 17 checks pass at this commit. Body rules was cancelled, not failed. It lints the PR description and runs no code that this change touches, so the cancellation is likely unrelated.

Before merge, Body rules only needs to run again and pass.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 25, 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.

1 participant