Repository navigation
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: 1 new finding on 262dfd9. The verdict and the full list are in the summary comment.
|
At 262dfd9 the lease check does not yet hold on every unlocked route, and
A second independent pass found more gaps of the same kind. Each needs its own fix and a test. A second independent pass found that a lease refusal can leave a request-start event in a session journal. A request starts while its address is empty, a lease holder publishes a session there, and the request is then refused at the locked check or the unlocked A second independent pass found that distinct store addresses can share one session journal. A second independent pass found that an unlocked recording refresh can change a recording after the session becomes leased. A second independent pass found that the second session read in A second independent pass found that remote script finalization can publish another client's session recording. A detached, unlocked A second independent pass found that lease admission can update a session the command is meant to ignore. On a daemon serving both lease backends, a A second independent pass found that suite attempt operations can outlive their lease check. A suite without a matching credential starts direct cleanup on an unleased attempt session. The close yields during runtime admission, and a concurrent open can add a lease to that same lifetime (session-open-state.ts). Close then accepts the same ref and can tear down the leased session (session-close.ts). Direct video start and stop have the same gap: they authorize once, then await recording operations (session-replay-video-owner.ts). The replay adapter also has unchecked runtime-hint reads at lines 202 and 275, and captures against a ref checked only when observation authority is bound at lines 281-291. Please hold the normal attempt session lock across authorization and each direct close, record or capture operation, and route the runtime-hint reads through the authorized attempt lookup at the point of use. A second independent pass found that the new expiry contract promises more than the code does (remote-device-lease-contracts.md:82). A lease holder sends a bounded batch, replay or bounded step after expiry and before the sweep. The contract says this request ends the session. But request-execution-scope.ts passes Not blocking, and each can be taken or left: Would one lease-checked session read on the scope handed to session handlers be simpler? For example, The open inline thread on the request-start event written from a pre-lock lookup still applies (thread). It is lower priority, because the same race shape existed on base. A follow-up issue or a contract-line qualifier is enough for it. Coverage is red. The PR author attributes it to the Before merge, |
262dfd9 to
7330ab7
Compare
|
Reply to the review of Fixed
Each fix has a test that fails when the fix is reverted. I ran those reverts. Deferred
Coverage. I could not read the failing line from that job's log. The only local unit failure at |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 7330ab7. The verdict and the full list are in the summary comment.
|
Final round, head Fixed
Deferred to a follow-up: #4949
Production code against |
This comment has been minimized.
This comment has been minimized.
|
This PR has findings at 2458eeb. The three open items from the earlier review (#4944 (comment)) at 262dfd9 are fixed, and five new issues remain. CI is green: 15 checks, 0 not passing. There are no conflicts. The findings below must be fixed before merge. A second independent pass found that an expired proxy lease can be torn down by a caller that cannot take over. A named session holds an expired proxy lease. Another client in the same tenant sends open with its own active proxy lease but omits clientId. Preflight skips the fresh-open metadata check while the old session exists (request-admission.ts:244). The successor check compares only labels the caller supplied (lease-registry-scope.ts:263). lease-lifecycle.ts:192 then tears down and retires the old session. Only afterwards does normal admission refuse the open for missing metadata (request-admission.ts:121). Run the fresh-session lease admission rules, without lease mutation, under the locks before the teardown. Reuse the normal admission rules for required metadata and owner scope. A second independent pass found that the same refusal path leaks the expired owner's lease id. Teardown adds the previous leaseId to the caller's request diagnostics (lease-lifecycle.ts:121). The redactor does not classify leaseId as sensitive (redaction.ts:1). The refusal returns the record locator (request-router.ts:762-777), and the caller can read the record through request-diagnostics-http.ts:137-162. Lease-end diagnostics emitted in a request scope must not carry the lease id. This includes the cleanup failure event at line 127. A second independent pass found that request-driven expiry can skip application finalization. The holder sends a locked command after the deadline while its iOS recording stop fails. teardownSessionResources throws the aggregated failure (session-teardown.ts:204-210). The new settle callback in daemon-runtime.ts:410 then never reaches application finalization, which releases the Apple runner (lifecycle.ts:476). endLeasedSession still clears the claim and retires the entry. At e8adbb8 the inline path attempted finalization after a resource failure (request-execution-scope.ts:656-689). Keep the daemon-owned callback, and let the lease-expiry caller attempt finalization after a resource failure with the resource failure kept as primary. A second independent pass found that local inventory no longer notices a restarted recording runner (request-execution-scope.ts:684). Run devices, capabilities, or doctor against a local unleased iOS session with an active runner-backed recording whose runner restarted. At e8adbb8 the refresh marked the recording invalid and the command returned COMMAND_FAILED (lines 722-727 and 759-771). At this head the refresh is skipped for these commands, so the handle stays valid and the request proceeds, although these commands keep the default invalid-recording refusal (daemon-command-registry.ts:95). The recording-health check must still run for unleased sessions: take the session lock around it and re-read the session under the lock. Keep lease-exempt commands detached if that read finds a lease. A second independent pass found that an expired-owner batch refusal writes journal entries and stamps activity (request-execution-scope.ts:451). A batch sends the matching lease id after the deadline and before the sweep. The outer request queues request.started before cleanup returns LEASE_NOT_FOUND (lease-lifecycle.ts:84-91). The outer batch is not a bounded step (line 433), so line 551 stamps activity before admission completes, and the finalizer can append request.finished (lines 326-337). This contradicts the refused-request guarantee in remote-device-lease-contracts.md:79. Journal and activity writes must depend on successful lease admission for this refusal. Otherwise narrow the contract to the credential mismatches it covers. Not blocking, and these can be taken or left: remote-device-lease-contracts.md:84 should say that a batch, a replay, or a bounded step that sends the expired lease id is refused with LEASE_NOT_FOUND, and with another active lease with LEASE_SESSION_MISMATCH, because resolveRequestSessionRef refuses that case before the consume callback; and settleExpiredSession at request-execution-scope.ts:170 could be required in RequestRouterDeps, as platformResourceCleanup was, so that a composition that omits it cannot retire an expired session silently (the only production composition at daemon-runtime.ts:331 supplies it). Of the earlier inline threads, three are fixed at this head and can be resolved: the orphan request.started (#4944 (comment)), the requestMayRecordSessionEvents scan (#4944 (comment), with path aliasing left to #4949), and apps inventory session resolution (#4944 (comment)). Not verified here: any test run, and a live successor takeover on a real device. Regression validity was judged by reading the 262dfd9 code path for each new test and the router order. The change was treated as daemon-only, since the request-driven expiry teardown now calls the existing settleIdleExpiredSession that the sweep already runs. The side effects of LeaseRegistry.inspectActiveLease and consumeExpiredLease were not inspected beyond their code comments. After these fixes, a rerun of the affected daemon lease tests with the new regressions must pass. |
2458eeb to
6de8d92
Compare
|
Reply to the review of Fixed
Also taken
Each of 1, 3 and 4 fails its test when reverted. Items still deferred are in #4949. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 6de8d92. The verdict and the full list are in the summary comment.
|
The findings from the earlier review are fixed at 6de8d92. A second independent pass found four remaining defects in the new successor-lease path. Each one lets a request tear down expired session A and then fail, or lets it open an unleased session. A second independent pass found that a named session in non-tenant isolation can still end A without an admitted successor. The caller sends A second independent pass found that the read-only successor check accepts leases the heartbeat would reject (request-admission.ts:204). A snapshot that presents active proxy lease B without B's A second independent pass found the same shape for PID-pinned leases (request-execution-scope.ts:540). A host-issued A second independent pass found that the lease contract is wrong for lock-exempt routes (remote-device-lease-contracts.md:81). It says the command does not refresh the recording. A Not blocking, and each can be taken or left: the unreachable Simplicity question, not a blocker: could finalize-after-resource-failure be a property of every lease-end teardown instead of the request route? Passing None of the open inline threads from other reviewers still applies, so these can be resolved. Orphan The only check not passing is Not verified here: no tests were run, and the two new route tests were judged by reading the 2458eeb code paths. The diff stat includes upstream 0.22 commits after the rebase, so only 6de8d92 and the range-diff doc rebases were reviewed as the change. Whether |
|
Addressed all four findings at
129 focused tests and 950 eager-closure cases passed. Four new daemon cases failed at the previous head with just the tests applied. The fifth failed when only the post-PID eligibility check was removed. The final affected rerun reached the 15-minute shared-lock wait limit. The first revision passed the affected gate. |
This comment has been minimized.
This comment has been minimized.
|
One problem remains at 5363624 after the earlier round (#4944 (comment)). The lease check itself now looks right, but a lock-exempt request no longer shows up in the session journal while it runs. On an existing active leased session, start a doctor request with the matching lease ID and let it wait in its local toolchain check at session-doctor.ts:91. Doctor is exempt from the session lock, so the head skips Could The open inline thread on the journal path aliasing is deferred to #4949, so please resolve #4944 (comment). These also no longer apply at this head, so please resolve them: #4944 (comment) ( The only check that did not pass is Body rules, which was cancelled. It validates the PR description and the diff changes nothing it exercises, so it needs a rerun. The other 16 checks pass. There are no conflicts. Not verified here: the new tests were not run, the |
|
Fixed at A side-effect-free human-control check belongs in 130 focused tests, 950 eager-closure cases, and all runnable affected checks passed on the code commit |
This comment has been minimized.
This comment has been minimized.
|
At 21133f1, the earlier findings (#4944 (comment)) are fixed in part. The journal start now runs only after the session ref resolves, and the inventory read goes through The start-at-resolution rule keys on lease presence ( A second independent pass found a related case. Start a local-mode A second independent pass also found that the first case holds even when the session stays unleased for the whole request. An authorized Could the lease-presence special case go? Using Of the earlier inline threads, the one on recording the start before the session is resolved (#4944 (comment)) and the one on the inventory read (#4944 (comment)) are fixed at this head and can be resolved. The journal path aliasing thread (#4944 (comment)) is deferred to #4949, which is out of scope here. The yield-to-lock-holder thread (#4944 (comment)) is deliberate, because the lock holder checks the recording itself and the contract documents it, so both can be resolved. No conflicts. The only check that did not pass is Body rules (cancelled), which validates the PR description and title and does not exercise this diff. A passing rerun is reported but was not checked against this head. All other 15 checks pass. Not verified here: the tests were not run, and no test was written to reproduce the first case, which rests on reading the code paths. Before merge, the journal start must be recorded for every lock-exempt request whose session ref resolved, unleased included as on the base, with a test for a leased and an unleased session. |
|
Fixed at The daemon test reads Independent review identified adjacent timing cases outside the requested ones. A ref that first resolves during recording-health preparation, a late inventory read such as |
This comment has been minimized.
This comment has been minimized.
|
At be4465e, the start is now recorded only after the session ref resolves under the lease check, with the finish fallback kept (request-execution-scope.ts:460-468 and :333). The inventory read also goes through resolveRequestSessionRef (inventory.ts:470). Both were open in the earlier review and are fixed. One gap remains: lock-exempt requests that first resolve a session after admission still do not write their live start. In session-doctor.ts:71 the lease-presence special case is back, now in the handler: A second independent pass found the same class of gap on three more routes. Each one is covered by the rule above. First, a lock-exempt Would it be simpler to record the start inside the scope, at the seeded read when None of the four earlier inline threads needs more work from the author. These threads no longer apply: #4944 (comment) (start now recorded after the lease-checked resolve), #4944 (comment) (inventory read now uses resolveRequestSessionRef), #4944 (comment) (case-insensitive journal path aliasing is deferred to #4949 item 2 and request-admission.ts is unchanged), and #4944 (comment) (yielding to the lock holder is deliberate, since the holder checks the recording itself and the contract documents it). No other threads still apply. On checks, the only one not passing is Body rules (cancelled). It validates the PR title and body and runs no daemon code, so it is likely unrelated to this change. The other 15 checks pass at this head. Before merge, the live start must be recorded at every lease-checked session read of a lock-exempt request that resolves a ref, leased or not. That means dropping |
|
Fixed at The new row opens an unleased session via HTTP after |
This comment has been minimized.
This comment has been minimized.
|
Commit 9df5311 fixes the problems from the earlier review (#4944 (comment)), but a second independent pass found one high-priority case that remains. When an open presents a valid successor lease B while the session still holds expired lease A, B can expire during teardown of A. The successor check at https://github.com/callstack/agent-device/blob/9df5311/packages/daemon/src/sessions/lease-lifecycle.ts#L195 only inspects admission. Then https://github.com/callstack/agent-device/blob/9df5311/packages/daemon/src/sessions/lease-lifecycle.ts#L209 awaits teardown of A. An asynchronous resource stop or application finalization at https://github.com/callstack/agent-device/blob/9df5311/packages/daemon/src/sessions/session-teardown.ts#L225 can run past B's deadline when B is close to expiry. A is retired at https://github.com/callstack/agent-device/blob/9df5311/packages/daemon/src/sessions/lease-lifecycle.ts#L145. The first normal admission and heartbeat then fail with LEASE_NOT_FOUND (https://github.com/callstack/agent-device/blob/9df5311/packages/daemon/src/server/request-execution-scope.ts#L541, https://github.com/callstack/agent-device/blob/9df5311/packages/daemon/src/sessions/request-admission.ts#L182). The request has already ended A and never admits B, so the client loses a valid successor lease. The rule to satisfy: a validated successor must be admitted, with its admitted-work protection held, before any awaited teardown of the incumbent starts. Please commit the fresh-session admission before line 209 and reuse it in the request scope. Expiry handling for the incumbent should stay with the existing teardown owner. A test that opens with a successor lease near its deadline and a teardown that outlasts it would show the fix. The code needs this change before merge. The only check that did not pass is Body rules, which was cancelled. It validates the PR title and body and runs no daemon code, and the other 15 checks pass at this head. No conflicts. Body rules needs a re-run before merge. Not verified here: the new tests were not run, and the claim that the new row fails at be4465e rests on reading request-router.ts:352-367 and the be4465e doctor condition. No test drives a late open before the capabilities or artifacts handler read, so their live start rests on reading the wiring (session.ts:34-36, request-handler-chain.ts:174) and the shared resolver. The reported 438 focused tests, 950 eager-closure cases and affected checks were not reproduced. |
|
Fixed at The deadline regression failed with |
This comment has been minimized.
This comment has been minimized.
…session A request reached a leased session before the daemon checked its lease id: it could end an expired session, inspect resources as a bounded step, write request events, and stamp session activity. `devices` refreshed the recording of a leased session. `doctor` and `events` read a session that opened after their admission. A `test` suite recorded and closed a leased session at an attempt address. The request scope now resolves the session a request acts through from the exact ref, first under the session lock, and commands that ignore the session lease get no session there. Unlocked routes and the test attempt handlers check the lease id at their read. Closes #4913
…r the lock A successor that reached the session lock before the lease sweep was refused with LEASE_SESSION_MISMATCH. A request that sends another active lease now ends the expired session for its exact lifetime, under its session and device locks, and then runs as the new owner. A request with no active lease still ends nothing. Lock-exempt commands no longer end an expired session inline: the lease-end owner ends it under its locks. capabilities checks the lease id once and reuses that session for both reads. The expired-session teardown moves to a sibling file to keep the request scope below the line cap, and the unused RequestExecutionScope.startedAtMs goes.
- doctor, events and capabilities read the session through one lease-checked reader; capabilities reuses that session for both reads. - A request writes its journal events only after its lease check: under the session lock, or with its last write. An address that maps to the session directory of a leased session neither reads nor writes that journal. - Only a request that holds the session lock refreshes the recording. - A command that ignores the session lease delivers no script of the session at its address, is admitted in its own scope, and renews no session. - A test attempt reads its runtime hints through the checked lookup.
…veto - A request that ends an expired session runs the daemon-owned settle, injected through the scope. The second teardown composition and its sibling file go. - A successor lease is checked again at the teardown boundary, after the wait for the device lock and with no await before the teardown starts. - The addressed session still decides the app-lease veto in admission. Only the session a request acts through is renewed. - apps and capabilities share one lease-checked session read. - The journal guard checks the session at the request address only; path aliasing moves to #4949.
…iry teardown no longer uses
…sion - A successor runs the lease admission rules of a new session, with no lease change, before the teardown. One that admission would refuse ends nothing. - A request record no longer names the lease id of the session that it ends; only the daemon log does. - A request that ends an expired session still finalizes the application after a resource failure, and the resource failure stays the error. - A command without the session lock checks the recording of a session under that lock again, and stays detached when the session holds a lease. - The contract states which refusals write no journal event. - The router requires the expired-session settle operation.
ac63c1d to
2c8fb90
Compare
|
Rebased on Typecheck, lint, format, the Fallow audit gate, 611 changed and lease-related tests, and 948 eager-closure cases passed. The PR body passed validation. The affected run was queued on the shared validation lock at publication. |
This comment has been minimized.
This comment has been minimized.
|
The near-deadline successor fix and the earlier blocking finding from 9df5311 are now fixed at 2c8fb90, and one new problem remains. Required evidence is satisfied. The other 16 checks pass, and the one check not passing is still queued; it is a review status that runs no daemon code, so it does not relate to this diff. No conflicts are known. A second independent pass found that a lock-exempt doctor, capabilities, or artifacts request can journal a start that the handler then refuses. The scope queues Not verified here: the new tests and the author's local suites were not run. The claim that the near-deadline successor test fails at 9df5311 rests on reading |
|
Fixed at The real-daemon regression exercises each route. A concurrent HTTP 614 changed and lease-related tests, 948 eager-closure cases, typecheck, lint, format, and the Fallow audit gate passed. The affected run was queued on the shared validation lock at publication. |
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.
Summary
Check the lease ID before a request reads or changes a leased session (#4913). Journal authorization and lease admission share one typed comparison of canonical lease claims. Use the checked session for recording refresh, inventory, scripts, and test attempts. Lock-exempt
doctor,capabilities, andartifactsrecord their starts after the handler checks the session lease. Anopencan attach a lease between preparation and that check.A successor must pass fresh lease admission, heartbeat owner-scope and TTL checks, and any macOS PID check before it can end an expired session. Recheck eligibility after the PID lookup. Admit the successor before teardown and hold its work pass through dispatch. Use the daemon's expiry teardown and remove the second teardown implementation. No wire format change. Older callers must send the lease ID to act on a leased session. Follow-ups are tracked in #4949.
Before / after
closewithout the expired session's lease ID returnsLEASE_SESSION_MISMATCHand preserves the session. Previously it ended the session and returnedSESSION_NOT_FOUND.deviceswithout a lease ID stays detached from a leased iOS session. Previously its recording could causeCOMMAND_FAILED.Validation
At
a1ed32735e, 614 changed and lease-related tests and 948 eager-closure cases passed. Three daemon regressions failed on2c8fb90because the journal exposed the refused start after a concurrent open attached a lease. Typecheck, lint, format, and the Fallow audit gate passed. All runnable affected checks passed at the same commit against0.22atbdf5096f77.Closes #4913