Skip to content

refactor(daemon): bind find actions to the admitted session lifetime - #5072

Merged
thymikee merged 2 commits into
0.22from
feat/5064-find-dispatch-authority
Nov 24, 2026
Merged

thymikee merged 2 commits into
0.22from
feat/5064-find-dispatch-authority

Conversation

@thymikee

@thymikee thymikee commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Bind mutating find actions to the admitted session lifetime. The dispatcher passes narrow operations for reading the target, expiring its ref frame, and recording a completed action. A completed action still records after cancellation if the original lifetime is current. A stale capability cannot reach a replacement.

The read-only selector runtime and capture observation write still use a store adapter. Snapshot binding and offscreen target probing now receive the facts they read.

Issue: #5064

Before / after

Behavior matches 0.22, including recording completed actions after cancellation and one runtime bind.

Value

Measure Base Head
Raw store reads in find.ts 6 0
Mutating branches that access the store 4 0

Validation

  • Rebased onto 0.22@2062cbe182. Range-diff confirms both commits carried over without patch changes.
  • At 30d6e5dbec, all 19 focused tests passed. Exact-head affected run run-WZdaJg passed all eight runnable checks, including 397 related and 22,920 unit tests. Hosted checks passed, including Android, iOS, macOS, and Linux smoke.
  • At 9be4a46740, 4,557 daemon tests, daemon typecheck, and layering passed. The cancellation assertion failed there before the fix.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.05 MB 5.05 MB +384 B
Package (unpacked) 5.05 MB 5.05 MB +384 B
Package (download) 1.54 MB 1.54 MB +299 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 13.2 ms 13.4 ms +0.2 ms
CLI --help 22.9 ms 23.2 ms +0.3 ms

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The change at 9be4a46 has one regression: a find action can now go unrecorded when its request is canceled after the device effect. AuthorizedMutation.recordAction returns early when admitted() is false, and admitted() includes isRequestCanceled(requestId). Take a find click, fill, focus or type whose client disconnects after the tap or typing completes. The device was acted on, but the session's recorded actions and event log omit the step. A later close --save-script or repair publication then produces a script that diverges from device state on replay. The base recordSessionAction checked only resolveCurrent(ref), so this also contradicts the "no observable change" claim. Please gate recordAction on the session lifetime only, as the base did (if (!this.#store.resolveCurrent(ref)) return;). The successor protection already comes from the ref's lifetime identity. Please also make the cancellation case in the new test assert that the admitted session still receives the entry after markRequestCanceled. The current assertion checks an unpublished successor, so it cannot catch this.

Not blocking, and these can be taken or left: the dispatcher now has a third per-command branch in bindSession and a second per-command field threaded through the scope and handler chain; there is no router-path test for the stale-capability case in #5064 (the new test calls SessionCoordinator.mutate directly and the find tests use bindFindSessionForTest); and the comment saying find actions "never resolve the address again" overstates it, since click and fill re-admit through the nested request, so calling mutations.requireTargetContext() before the nested invoke would make every branch re-check.

Could AuthorizedSession, which bind() already re-checks per call, take requireTargetContext, expireRefFrame and recordAction, or could mutate() reuse the requireActive closure from bind()? Then bindSession could return that one authority for every admitted ref instead of command === 'find' and command === 'doctor' branches. Find would take a single sessionAuthority plus the existing existingRef for its capture leg, FindSessionAuthority would go away, and later #4971 slices would add no dispatcher fields. Nothing here is blocking. Deciding in ADR 0040 step 7 that the converted-command authority is generic would prevent per-command fields before the next slice.

Lint, Typecheck & Package, Numeric Ranges and Coverage fail on the captureHostEnvironment import in src/daemon-provider-rental-restart.{fixtures,test}.ts. The 0.22 base run at e9a2f43 fails the same three jobs, and this diff touches neither file, so the failures look unrelated; #5071 repairs the import. The two Body rules runs were canceled by newer runs. Not verified here: the tests and the reported layering count (190 to 180) were not run locally, and whether close and reopen can interleave between find's capture and the nested click or fill is inferred from the held session lock, not proven. Before merge, the recording gate needs the fix above with its test, and CI needs #5071 to land.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The changes at 41baa06 look good, and the findings from the earlier review (#5072 (comment)) are fixed. No new code problems were found in the delta, and nothing from that review remains open. The cancellation test now asserts the case the old recordAction gate let through. Not verified here: the tests were not run locally, so that regression claim comes from reading the old gate and the new assertion.

Lint, Typecheck & Package, Numeric Ranges and Coverage are red with TS2305 on captureHostEnvironment in src/daemon-provider-rental-restart.fixtures.ts and src/daemon-provider-rental-restart.test.ts. This PR does not touch those files, and base e9a2f43 fails the same three jobs. #5071 repairs the import. Body rules was cancelled by a newer run. Because Typecheck fails, CI has not independently confirmed the types of this head. Live device validation is not needed, because the delta only changes daemon-side recording gating. Merge waits on #5071 landing and a green re-run on the rebased head.

@thymikee
thymikee marked this pull request as ready for review November 24, 2026 13:58
The find route resolved its session from the store at the top of the handler
and again in every mutating branch, so a lifetime that ended mid-request made
those reads answer for whichever session owned the address next.

The dispatcher now hands find the effects of the one lifetime it admitted:
the target-context read, the ADR 0014 ref-frame expiry at the side-effect
seam, and the recorded action. Each operation re-checks its own lifetime and
never resolves the address again, so a revoked authority can neither observe
nor mutate a successor session. The action branches hold no store.

The read-only selector-runtime leg and find's own capture observation write
keep the store adapter, recorded as remaining debt.

Refs: #5064
@thymikee
thymikee force-pushed the feat/5064-find-dispatch-authority branch from 41baa06 to 30d6e5d Compare November 24, 2026 14:00
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 30d6e5d

Since the review of 41baa06: 0 new · 0 still open · 0 no longer raised

No open findings.

Reviewed with this repository's own Sentinel configuration (8a29aea9a820).

💬 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 code at 30d6e5d is unchanged in substance from the version reviewed earlier (#5072 (comment)), and it still looks correct. The earlier TS2305 failures came from base files this PR does not touch and are fixed in the rebased base. CI is still pending, and the only check not passing is Body rules, which was cancelled because a newer run replaced it. Before merge, the Body rules re-run must pass. Not verified here: tests were not run locally, and the conclusion that the patch is identical rests on a range-diff and diff comparison.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 24, 2026
@thymikee
thymikee merged commit dca0f19 into 0.22 Nov 24, 2026
17 of 18 checks passed
@thymikee
thymikee deleted the feat/5064-find-dispatch-authority branch November 24, 2026 15:14
thymikee added a commit that referenced this pull request Nov 24, 2026
…5072)

* refactor(daemon): bind find actions to the admitted session lifetime

The find route resolved its session from the store at the top of the handler
and again in every mutating branch, so a lifetime that ended mid-request made
those reads answer for whichever session owned the address next.

The dispatcher now hands find the effects of the one lifetime it admitted:
the target-context read, the ADR 0014 ref-frame expiry at the side-effect
seam, and the recorded action. Each operation re-checks its own lifetime and
never resolves the address again, so a revoked authority can neither observe
nor mutate a successor session. The action branches hold no store.

The read-only selector-runtime leg and find's own capture observation write
keep the store adapter, recorded as remaining debt.

Refs: #5064

* fix(daemon): record completed find actions after cancellation
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