Repository navigation
refactor(daemon): bind session authority to one lifetime - #4983
Conversation
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 cd1b5cb. The verdict and the full list are in the summary comment.
This comment has been minimized.
This comment has been minimized.
|
Review of cf99785: the session lifetime change has five cancellation problems, and hosted checks are green with no conflicts. The first four listed below are in the replay and timeout paths, and the fifth is in snapshot. A second independent pass found that a direct suite attempt can be canceled while it waits in the session lock queue, and still enter (session-replay-command.ts:166). A request ahead in the queue can publish a same-owner lifetime at the attempt address. The attempt's finally block then pins it at line 177, and the late cleanup scheduled at session-test-runtime.ts:137 closes a session the attempt never ran on. The rule: lock acquisition must observe the attempt signal before the first pin, and cleanup may only close a lifetime that was acquired or published while the attempt was active. A second independent pass found that with video enabled, an attempt that times out while recording start awaits its runtime binding can still start native recording (record-runtime.ts:282). The attempt check in session-replay-video-owner.ts:68 only reaches adoption at line 307, after A second independent pass found that a suite can return before a requested video is exported when an attempt times out during recording (session-replay-command.ts:186). On base 9c40d42 the video finalizer sees the active recording and holds the response through the three-second tail, so a late close can export it. At this head the finalize reader sees no completed ref yet, and session-replay-video-recording.ts:98 skips the tail and the stop. The rule: the original recording lifetime must keep finalization pending through the existing tail window, and the stop and late close must run under that lifetime's lock. An export that settles inside the window must then be ready before the suite returns. A second independent pass found that a replay capture can write session state after cancellation (internal-observation.ts:41). The WebDriver XCTest path can await a module load after its last abort check at webdriver-interactor.ts:306. The capture helper then records timing and clears freshness at snapshot-capture.ts:140 and line 97 without a cancellation check. Standalone replay passes no A second independent pass found that an existing-session snapshot can publish a new ref frame after the owner cancels it (snapshot-command-runtime.ts:170). The command runtime still calls Simplicity question: could Not blocking, and these can be taken or left: the replay test handler at session-replay-command.ts:122 rebuilds lifetime state beside Both open inline threads no longer apply and can be resolved: the lease-field comparison thread is covered at this head by All 23 checks at cf99785 pass or skip by design. The cancelled Body rules job came from the body-edit concurrency rule, and the later run 45066420187 passes. There are no conflicts. Not verified here: tests were not run locally, and regression validity was judged from the diff and the base code, where the leased-reopen, snapshot-only-binding, and record-only-binding tests would fail. The iOS, macOS, and Android smoke jobs run Before merge, the five cancellation problems above need fixes, plus a live run of a timed-out |
|
Live
Observation: recording start on this simulator took between 1.7 s and 8.3 s across runs, so a short attempt timeout can land in either case. Both now settle cleanly. |
This comment has been minimized.
This comment has been minimized.
|
The earlier findings from cf99785 (#4983 (comment)) are fixed in the code at 5eb2f4c. One required live run is still missing. All hosted checks at 5eb2f4c pass or skip by design, and the smoke jobs do not use The delta changes the device-facing timeout path of Not blocking, take or leave: the new No open inline thread still applies. These two no longer apply, so they can be resolved: #4983 (comment) (fixed, Not verified here: tests were not run locally, and the nested-request paths that keep |
|
The live run in the PR body covers what the review at 5eb2f4c asked for: on Android 16 at 5eb2f4c, Optional, for clarity: the sentence "The initial stop returned |
… rules out #4945 tests attached a lease to an open session. A session lifetime now keeps its lease from creation, so trace writability no longer checks for a gained lease, and tests of an unleased producer on a later-leased session go away.
5eb2f4c to
739a315
Compare
Apex Sentinel · ✅ Approve · review of
|
| Where | Finding |
|---|---|
packages/daemon/src/core/deferred-interaction-outcome.ts:452 |
🆕 assertCurrent in finally masks the real capture error and skips stabilization clear |
scripts/layering/session-store-reads.ts:29 |
🆕 session-store-reads gate aborts with a raw git stack when the base ref is absent |
packages/daemon/src/execution/internal-observation.ts:41 |
🆕 New authority-ended refusal throws a bare Error matched only by its text |
Reviewed with this repository's own Sentinel configuration (a6642f37da2e).
💬 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.
There was a problem hiding this comment.
Apex Sentinel: 3 new findings on 83af5b0. The verdict and the full list are in the summary comment.
| } finally { | ||
| params.assertCurrent?.(); | ||
| clearSurfaceStabilization(session); | ||
| } |
There was a problem hiding this comment.
🆕 🟡 Minor · assertCurrent in finally masks the real capture error and skips stabilization clear
A device or backend AppError from capture() that coincides with the session authority having ended will have the thrown cancellation from assertCurrent replace the real error (request_canceled / NO_ACTIVE_SESSION), discarding the device-side cause; clearSurfaceStabilization(session) is also skipped on that path. The assertCurrent call sits first in the finally block, so it throws regardless of whether the try block succeeded or failed. Run the assert only when the try block settled normally, or capture the pending error and prefer it.
Details
persona: javascript, maintainability
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.
There was a problem hiding this comment.
Kept as is. The order is deliberate: when the session authority ended during a capture, the request is canceled, and a canceled request must not change session state. Clearing stabilization first would let a stale request mutate the next lifetime. snapshot-capture.test.ts ("a late canceled capture leaves timing and deferred stabilization unchanged") pins this; it fails with the clear moved first. The cancellation replacing a device error is intended too: the device error is a result of the teardown, not its cause.
|
|
||
| const base = execFileSync( | ||
| 'git', | ||
| ['merge-base', process.env['SESSION_STORE_READ_BASE'] || 'origin/main', 'HEAD'], | ||
| { encoding: 'utf8' }, | ||
| ).trim(); | ||
| const before = countReads(base); | ||
| const after = countReads(); |
There was a problem hiding this comment.
🆕 🟡 Minor · session-store-reads gate aborts with a raw git stack when the base ref is absent
Running pnpm check:layering in a fresh clone or worktree — or in CI when SESSION_STORE_READ_BASE names a base commit that the checkout does not contain — makes the new gate die with an uncaught execFileSync failure from git merge-base instead of a message, so the whole check:layering script fails for reasons unrelated to raw session reads. The script calls execFileSync('git', ['merge-base', env.SESSION_STORE_READ_BASE || 'origin/main', 'HEAD']) with no fallback: if origin/main (or the PR base sha) is not in the repository's object store, merge-base exits non-zero and the throw propagates. The repository instructions tell workers to run pnpm check in a new worktree, where origin/main and the PR base sha are not guaranteed to be fetched. Catch the failure (or fall back to counting only the HEAD side and reporting the base as unknown) so the ratchet degrades to a report instead of a crash.
Details
Also raised here
Also raised at this location by persona javascript: session-store-reads.ts aborts the whole layering gate when origin/main is absent — countReads handles git grep's "no matches" exit 1, but the git merge-base call in the same script has no such handling, so in a shallow clone or CI checkout without origin/main the script throws and check:layering fails on the gate script rather than on an invariant. Resolve the base defensively (the env var the workflow now sets) or wrap the merge-base in the same status check.
persona: javascript, senior-developer
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.
There was a problem hiding this comment.
Fixed in 634e131. A missing merge base now prints No merge base with <ref>. Fetch it, or set SESSION_STORE_READ_BASE to a fetched base. and exits 1. It still fails rather than degrading to a report, because a ratchet without a base cannot check anything.
| store: (snapshot) => { | ||
| params.signal?.throwIfAborted(); | ||
| if (params.isActive?.() === false) | ||
| throw new Error('Internal observation authority has ended.'); | ||
| return storeInternalObservation(params, snapshot); | ||
| }, |
There was a problem hiding this comment.
🆕 🟡 Minor · New authority-ended refusal throws a bare Error matched only by its text
The new store guard in bindInternalObservationAuthority throws new Error('Internal observation authority has ended.') when isActive returns false; the only way for a caller, log reader, or test to distinguish this refusal from any other generic failure is the message string. Every other refusal on the same path uses a typed error (AppError with a reason, or createRequestCanceledError() via assertSessionAuthorityActive). Same shape in session-store.ts: TypeError('Session slot has already published') and TypeError('Session authority is no longer active') use TypeError for runtime lifetime state rather than a typed reason.
| store: (snapshot) => { | |
| params.signal?.throwIfAborted(); | |
| if (params.isActive?.() === false) | |
| throw new Error('Internal observation authority has ended.'); | |
| return storeInternalObservation(params, snapshot); | |
| }, | |
| if (params.isActive?.() === false) | |
| throw new AppError('UNAUTHORIZED', 'Internal observation authority has ended.', { | |
| reason: 'session_authority_ended', | |
| }); |
Suggested change
Throw an AppError with a typed code and a reason detail (for example reason 'session_authority_ended') instead of a bare Error/TypeError, so the replay cleanup and tests branch on the reason rather than the text.
Details
persona: maintainability
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.
There was a problem hiding this comment.
Fixed in 634e131. The observation guard and the two runtime-reachable SessionCoordinator checks (slot and authority no longer active) now throw createRequestCanceledError(), the same as assertSessionAuthorityActive. Session slot has already published stays a TypeError: it signals a programming error, not runtime state.
|
The PR is ready from the code side at 83af5b0. The earlier review at 5eb2f4c (#4983 (comment)) found nothing to fix, and the new commits keep that result. Not blocking: in request-execution-scope.ts, the new The two earlier inline threads do not apply at this head, so they can be resolved: the session-store.ts one was fixed at cf99785 (#4983 (comment)), and the session-replay-command.ts one is outdated and was fixed at cf99785 (#4983 (comment)). All 6 CI jobs that are not yet passing are still running at this head, not failed. They cover the changed code: Lint, Typecheck & Package checks the deleted There are no conflicts. Merge once the running CI jobs pass at 83af5b0. |
Name a missing merge base in the raw-read ratchet instead of a git stack.
* refactor(daemon): bind session authority to one lifetime * chore(gates): ratchet raw session store reads * fix(daemon): verify reopen lease claims and retry pinned cleanup * fix(daemon): fence replay and snapshot cancellation by lifetime * refactor(daemon): drop lease-change paths that a fixed lifetime lease rules out its lease from creation, so trace writability no longer checks for a gained lease, and tests of an unleased producer on a later-leased session go away. * docs(help): keep the remote first screen within 30 lines * fix(daemon): refuse ended session authority as a canceled request Name a missing merge base in the raw-read ratchet instead of a git stack.
) * refactor(daemon): bind session authority to one lifetime * chore(gates): ratchet raw session store reads * fix(daemon): verify reopen lease claims and retry pinned cleanup * fix(daemon): fence replay and snapshot cancellation by lifetime * refactor(daemon): drop lease-change paths that a fixed lifetime lease rules out its lease from creation, so trace writability no longer checks for a gained lease, and tests of an unleased producer on a later-leased session go away. * docs(help): keep the remote first screen within 30 lines * fix(daemon): refuse ended session authority as a canceled request Name a missing merge base in the raw-read ratchet instead of a git stack.
* refactor(daemon): bind session authority to one lifetime * chore(gates): ratchet raw session store reads * fix(daemon): verify reopen lease claims and retry pinned cleanup * fix(daemon): fence replay and snapshot cancellation by lifetime * refactor(daemon): drop lease-change paths that a fixed lifetime lease rules out its lease from creation, so trace writability no longer checks for a gained lease, and tests of an unleased producer on a later-leased session go away. * docs(help): keep the remote first screen within 30 lines * fix(daemon): refuse ended session authority as a canceled request Name a missing merge base in the raw-read ratchet instead of a git stack.
Summary
Implements ADR 0040 step 1. App open, record, and snapshot bind the admitted lease when they create a lifetime, removing in-place lease attachment. Script revisions commit under the lifetime lock, removing the late address reread. Their receipt carries forward to #4970. Replay checks attempt authority at lock acquisition, recording start, capture, snapshot publication, and cleanup.
Before / after
opencould adopt a live unleased session. It now returnsLEASE_SESSION_MISMATCHbefore launch. Conflicting lease labels also refuse before launch.Value
Raw
sessionStorereads outside owners fell from 197 to 195. CI rejects increases. Direct store publishers fell from 3 to 1. The 459 net runtime and tooling lines cover three creation paths, replay locking and cancellation, and the CI ratchet.Validation
At
5eb2f4c719, all 22 hosted checks passed or skipped by design. Targeted Vitest, eager closure, and the full local affected gate passed.On Android 16, the branch CLI ran
test recording-timeout.ad --record-video --jsonwithtimeout=15000andwait 30000. Two runs stopped and exported before return. The initial stop returnedUNKNOWNand cleanup exported a playable MP4 that the suite omitted. Suite JSON excerpt with relative artifact paths and the file check follows.{ "sha": "5eb2f4c719910b0e86ea30e0483acbae0f9066de", "cliExitCode": 1, "data": { "failed": 1, "tests": [ { "status": "failed", "attempts": 1, "error": { "code": "COMMAND_FAILED", "message": "TIMEOUT after 15000ms", "details": { "reason": "timeout", "timeoutMs": 15000, "timeoutMode": "cooperative", "artifactPaths": [ "attempt-1/replay-timing.ndjson", "attempt-1/recording.mp4", "attempt-1/recording.gesture-telemetry.json" ] } } } ] }, "fileCheck": { "path": "attempt-1/recording.mp4", "bytes": 712717, "existedAtReturn": true } }Closes #4965
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.