Skip to content

fix(daemon): compare every supplied lease label with one typed session lease - #4942

Merged
thymikee merged 8 commits into
0.22from
refactor/0.22-session-lease-claims
Nov 22, 2026
Merged

thymikee merged 8 commits into
0.22from
refactor/0.22-session-lease-claims

Conversation

@thymikee

@thymikee thymikee commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

A leased session requires its lease ID and compares every supplied label with the admitted lease (ADR 0007). HTTP, RPC aliases and nested commands can displace labels before admission.

  • Store one typed SessionLease from the admitted lease. Compare meta, flags, aliases and displaced claims with one canonical form per field. Carry displaced claims into nested requests.
  • Preserve the tenant flag for unattested HTTP routing. Give original tenant errors priority during session scope and address resolution, before device pin, policy, or device wait. Stamp session activity only after the admitted task starts.
  • Remove the inline lease type, request-derived lease construction, session expiry copy and inventory-only tenant guard.

Breaking for clients that send a conflicting label or a non-string label on a leased request.

Before / after

snapshot with the owner lease ID and a conflicting tenant replaced by attestation
  base: ok
  head: UNAUTHORIZED LEASE_SESSION_MISMATCH field=tenantId

poll snapshot with a malformed tenant on an unleased session
  base and head: INVALID_ARGS, original idle deadline preserved
  earlier PR head: INVALID_ARGS, idle deadline extended

Validation

At bd4e032e1f, focused Vitest (including eager-closure budgets), typecheck, lint and Fallow against origin/0.22 pass. Removing the falsy-tenant refusal makes fresh open check device contention. The complete local affected gate passed at 116f6dc98d. Hosted CI covers the current head.

Closes #4910
Closes #4935

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.08 MB 6.08 MB +847 B
Package (unpacked) 6.08 MB 6.08 MB +847 B
Package (download) 1.86 MB 1.86 MB -159 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 27.3 ms 28.1 ms +0.8 ms
CLI --help 54.4 ms 53.8 ms -0.6 ms

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

At 3a16b47 the change has two high-priority defects: nested batch steps drop a declared lease claim, and the session lease now stores canonical values that some readers still compare with the raw request value. A leased session then admits or hides requests depending on how the caller spells or batches them.

The one failing check, Coverage, fails on session-shutdown.test.ts ('shutdown names the leased session in its DEVICE_IN_USE refusal'). The same test fails with the same error on the base 0.22 push (run 44996420221), so it looks like merge skew from #4911/#4917 and not this PR. The two cancelled Body rules runs were replaced by a passing run. No conflicts.

handDownRequestLeaseScope hands down a parent's displaced claim only when the child scope leaves that field undefined. runBatch builds each step with batchStepMeta(req.meta, …) (batch.ts:350), so every step already names the attested tenant, and runBatchCommands does not copy req.internal. Take an attested tenant e2b, a caller that declares tenant-other, and a batch of [open with the owner lease id, snapshot] on a fresh session. The open leases the session. The snapshot then compares only tenantId=[e2b], so it is admitted, while the same snapshot sent alone is refused with LEASE_SESSION_MISMATCH field=tenantId. The outcome depends on whether the caller batches, which #4935 rules out. The rule: a nested request carries every displaced claim of the request it acts for. Please merge parentDisplaced unconditionally in handDownRequestLeaseScope (a child that names another lease is still refused), so every nested producer gets it from one place. A real-daemon test for an attested batch [open, snapshot] with a declared other tenant, refused at step 2, would prove it. Replay and test steps only look fine because replayInvokeOverDispatch reattaches the whole internal.

On base, session.lease held the raw request values. At head it holds the registry values: lease id lowercased and trimmed, and run id, client id, device key and provider trimmed. Two readers still compare the raw request value. createSessionVisibilityPredicate compares requestLeaseId === session.lease.leaseId, so a client that allocated with an upper-case lease id opens fine but session_list then hides its own session. leaseClaimNamesLease compares claim === lease[field], so a whitespace-padded run id or client id is admitted at open and refused on every later request. The rule: the session lease stores canonical values, so every comparison against it canonicalizes the request side with the registry normalizer for that field. Please normalize the request lease id in the visibility predicate, and give run id, provider, client id and device key the same treatment as lease id and tenant id in leaseClaimNamesLease, from one per-field normalizer table. The shutdown refusal path uses the same lease id comparison, so it loses its recovery details for an upper-case id too.

A second independent pass found that the batch gap is wider than one field. An attested batch on a fresh session, with the right lease and run and a declared tenant that differs from the attested one, passes the collapsed registry check (request-admission.ts:88, :138). The hand-down wrapper at lease-context.ts:170 treats the tenant copied by batchStepMeta as a step claim and drops the declared one. A parent flag masked by parent meta disappears the same way, and replay actions copy parent meta with limited flag inheritance (session-replay-action-runtime.ts:149). The rule: carry the parent's displaced and masked claims to nested admission independently of which scope fields the child inherits, and compare both those and the step's own claims when a leased session exists.

A second independent pass found that non-string lease values vanish before comparison. The generic RPC schema accepts any object for meta and flags (contracts.ts:571). A snapshot with the right lease id and a numeric meta.runId is refused on base, but at head the number is filtered out in lease-context.ts:243 and the request passes. The intake filters at lease-context.ts:143 and http-rpc-methods.ts:69 do the same for malformed flags, batch step flags, displaced tenants and install aliases, and the active provider-artifact read at lease.ts:609 shares the comparison. The rule: a present lease value is kept through collection and displacement, and at leased-session and active-provider admission a present non-string value is a field mismatch, refused without echoing the value.

A second independent pass found that the padded run id case also affects the leased-session check at lease-context.ts:258. A backend-only lease opened with a space-padded run id stores the trimmed run id, and the identical caller value on snapshot is then refused, while base accepted it. Provider, client and device-key labels differ the same way between registry normalization and session comparison. Please compare these labels with the registry's canonicalization and keep invalid and empty labels as mismatches.

A second independent pass found that the session list and shutdown cases fail on lease id case. After an open with an upper-case lease id, session_list omits the owner's session and the shutdown refusal omits its recovery details (inventory.ts:121, session-shutdown.ts:66), although lease admission accepts the upper-case id. The shared visibility predicate should normalize the presented id before comparing it with the canonical one.

A second independent pass found that the moved lease id normalizer throws on non-string input. On an ordinary unleased session with no required lease policy, a snapshot with a false or 0 meta.leaseId is treated as absent by unleased admission (request-admission.ts:129). Response handling then asks whether that id belongs to a macos-app lease (request-router.ts:328), and the new normalizer in lease-scope.ts:538 calls trim on the boolean or number, so a successful snapshot becomes an RPC error. The previous normalizer returned undefined for falsy values. normalizeLeaseId should return undefined for non-string input before it calls trim.

Not blocking, and fine to take or leave: LEASE_CLAIM_FLAGS restates the flag-to-field mapping that leaseScopeFromRequest already owns, so one exported table could drive both; an empty meta.leaseId is now a string claim and loses the 'send its lease id' hint, which a blank-string filter before the missing check would restore; and LeaseClaims is daemon-internal but lives in the public contracts package, so a follow-up could declare it beside daemon-request.ts.

Not verified here: tests and mutations were not run, the attested batch of [open, snapshot] was traced by reading and not run against a real daemon, which shipped clients send a non-lowercase lease id was not checked, and the other nested producers (selector capture, wait-current-surface, snapshot runtime binding) were not audited for cross-session targets. They appear to act on the parent session, which parent admission already compared.

Before merge, hand down every parent displaced claim in handDownRequestLeaseScope so batch steps compare the declared tenant, and canonicalize the request side wherever it meets the canonical session lease.

@thymikee
thymikee force-pushed the refactor/0.22-session-lease-claims branch from 3a16b47 to 60fbd62 Compare November 22, 2026 08:37
@thymikee

Copy link
Copy Markdown
Member Author

Reply to #4942 (comment). Fixed at 60fbd62, rebased on 0.22 at 64f963a (#4941).

Fixed

  1. Nested steps drop a declared claim. handDownRequestLeaseScope now hands down every value that the parent sent and that is not the parent scope value: displaced claims, and flags or aliases that the parent meta hides. It does not depend on which fields the step names. Test: an attested batch [open, snapshot] with a declared tenant-other against a real daemon. The open leases the session, and step 2 is refused with LEASE_SESSION_MISMATCH field=tenantId.
  2. Canonical lease, raw request. LEASE_FIELD_NORMALIZERS is one table for leaseId, tenantId, leaseBackend, runId, leaseProvider, clientId and deviceKey. leaseClaimNamesLease reads it (the switch is gone). The request side of createSessionVisibilityPredicate reads it. The registry normalizers for run id, provider, client id and device key read it too, so there is one rule per field. Test: an owner with an upper-case padded lease id and padded run id and client id is listed by session_list and admitted on snapshot.
  3. Non-string values. A present value of any type stays a claim through readLeaseClaims, withDisplacedLeaseClaims and the install_from_source params. It is a field mismatch at the leased-session check and at the active provider-artifact check. The error names the field only. Test: a numeric runId in meta, in flags, and as an install param.
  4. normalizeLeaseId returns undefined for non-string input before trim.

Each new test fails when its fix is removed (5 mutations).

Optional notes

  • Taken: a blank leaseId gets the "send its lease id" hint again.
  • Not taken: one flag-to-field table shared with leaseScopeFromRequest, and LeaseClaims beside daemon-request.ts. Both are follow-ups.

One placement note

The table is in packages/daemon/src/core/lease-context.ts, not in contracts/lease-scope.ts. In contracts it added kernel/contracts and daemon-http to the client import closures, and eager-closure-budgets.test.ts refused that.

Not verified

The other nested producers (selector capture, wait-current-surface, snapshot runtime binding) were not audited. They get the claims from the same wrapper when they use the handed-down invoke.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

This follow-up on the earlier review covers 60fbd62. The earlier findings from 3a16b47 are fixed, but a second independent pass found four gaps that still let a conflicting or null lease label reach the session.

A second independent pass found that a batch step can drop the parent's lease claim (lease-context.ts:185). On a daemon without required lease policy or tenant isolation, submit a batch for a fresh named session with a conflicting runId in the parent flags and no lease id at the batch level. Give both open and snapshot the correct lease scope in their step flags. The outer batch can run without a lease (request-admission.ts:108,129), and the open binds the admitted lease. The step builder copies parent meta but not lease flags (batch.ts:268,333,348,350, batch-policy.ts:45). The wrapper excludes the parent runId from hidden claims because it equals parentScope.runId, then skips inheriting it because the child has its own runId at line 192. The snapshot then passes on the leased session despite the conflicting parent claim, which remote-device-lease-contracts.md:82 forbids. The rule to satisfy: every claim the parent supplied must be compared, even when the step supplies its own value. Carry the parent's collected claims into the child's displaced claims whenever they are absent from the outgoing child request, and keep the existing effective-scope merge for routing.

A second independent pass found that explicit null claims disappear from admission (lease-context.ts:288). A snapshot of a leased session with the owner lease id and an explicit null runId in meta or flags passes the lease check. The generic RPC schema keeps the nested value (contracts.ts:571), but readLeaseClaims removes it at line 271. The same filter drops a null step flag in a batch, and mergeLeaseClaims at line 164 drops a null parent claim or a null tenant displaced by HTTP attestation (http-server.ts:690,694). An active provider-artifact lookup with the owner lease id and a null optional label also passes the shared guard (lease.ts:607-610). The documented rule requires a field mismatch for any supplied non-string. The shared claim collector and merger should exclude only undefined, and the existing field normalizer should turn an explicit null into a mismatch.

A second independent pass found that the source-install adapter drops null before the shared guard (http-rpc-methods.ts:238). An install_from_source call on a leased session can supply its owner lease id and a null runId, or a matching tenantId and an explicit null tenant alias. The adapter removes null before saving displaced claims at line 240, so admission reaches install handling instead of returning LEASE_SESSION_MISMATCH for that field. Fixing the shared collector alone leaves this route open. Displaced claims should keep every supplied value except undefined and the string chosen for the effective metadata field.

A second independent pass found that alias selection changed for unleased requests (http-rpc-methods.ts:239). On an unleased named session with no auth hook, an install_from_source call with retainPaths enabled, a numeric tenantId and tenant set to a valid string used that string on base 64f963a (lines 206-219 select the first string). Head selects the first supplied value and then leaves meta.tenantId unset. A successful install then records the retained paths without their tenant owner (session-app-source-deployment.ts:220-225, materialized-path-registry.ts:79-85), and the release ownership check skips the tenant restriction (tenant-owned-entry.ts:33). The same change applies to leaseProvider/provider and leaseBackend/backend. Effective metadata should come from the first string in the original alias order, and every other supplied value should be kept for leased admission.

Not blocking, and these can be taken or left: the alias case above also covers the numeric-first form (leaseProvider: 5, provider: 'proxy'), where base 0.22 routed by the string alias, so the same fix and a note in the follow-up issue that shares the alias tables would close it.

Required evidence is satisfied, and there are no conflicts. The only check not passing is Body rules (one failure, one later cancelled run). That gate reads only the PR title and body, so it does not overlap this diff, and the current body passes the gate script locally. The failure most likely belongs to an earlier body revision, so it needs a re-run, not a code change.

Not verified here: the tests and the author's five mutations were run, and the regression checks were traced by reading the 3a16b47 code paths. Not verified here: the Body rules job log was read. Not verified here: nested producers other than batch and replay (selector capture, wait-current-surface, snapshot runtime binding) were audited for requests built without the handed-down invoke. Not verified here: the eager-closure budget reason for placing LEASE_FIELD_NORMALIZERS in daemon core was reproduced.

Before merge, the four findings above need fixes, and Body rules needs a re-run on the current body.

@thymikee
thymikee force-pushed the refactor/0.22-session-lease-claims branch from 60fbd62 to 1e3d990 Compare November 22, 2026 09:15
@thymikee

Copy link
Copy Markdown
Member Author

Reply to #4942 (comment). Fixed at 1e3d990. The base is 0.22 at 64f963a.

  1. A step drops the parent claim (lease-context.ts:185). handDownRequestLeaseScope now compares the parent claims with the claims of the outgoing child request. Each parent value that the child does not carry goes into the child's displaced claims. This includes the parent scope value when the step names its own value. The effective-scope merge for routing did not change. Test: your scenario against a real daemon without tenant isolation. A batch on a fresh session has runId=run-other in its flags and no lease id. Open and snapshot have the correct scope in their step flags. Step 2 is refused with LEASE_SESSION_MISMATCH field=runId.
  2. Null claims (lease-context.ts:288). readLeaseClaims and mergeLeaseClaims exclude only undefined. The field normalizer gives a mismatch for null. Test: a null run id in meta and in flags on a leased session.
  3. Null in the install adapter (http-rpc-methods.ts:238). The displaced claims keep each supplied value except undefined and the string chosen for the label. Test: tenantId with a null tenant alias, and a null runId param, on a leased session.
  4. Alias selection (http-rpc-methods.ts:239). The label is the first string in the alias order. Each other supplied value is a claim. Test: tenantId: 5, tenant: 'tenant-a' and leaseProvider: null, provider: 'proxy' give meta.tenantId='tenant-a', meta.leaseProvider='proxy' and the displaced claims [5], [null]. On a leased session the numeric tenantId is refused.

Each new test fails when its fix is removed (4 mutations). typecheck, lint, check:layering and check:daemon-wire-compat pass. The unit lane for daemon, contracts, scripts and wire-compat has 6860 passes.

The PR body passes scripts/check-pr-body.ts locally after the validation lines changed to this head.

Not done: the other nested producers were not audited, and the follow-up issue for the shared alias table was not filed.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The earlier findings at 60fbd62 are fixed on the code paths read at 1e3d990, but a second independent pass found two lease-label cases that still bypass the new check, so this needs two more fixes.

A second independent pass found that request-admission.ts:61 drops an explicit null tenant. On the local socket, an owner can send a snapshot to an active tenant-scoped leased session with the correct lease id, tenant isolation, meta.tenantId: null and flags.tenant set to the lease tenant. Socket intake keeps the null (transport.ts:199-223), tenant scoping replaces it in both routing branches, and admission then sees only the matching tenant and admits the request. A socket batch loses the parent claim the same way before the nested invoker can collect it (request-router.ts:422-425). The rule: every supplied tenant claim must be compared with the session lease before routing replaces it. Please record the original meta tenant as a displaced claim in both tenant-scoping branches by reusing withDisplacedLeaseClaims, so direct and nested requests share one check.

A second independent pass found that request-admission.ts:38 throws on a non-string tenant before the lease check runs. On a daemon without an HTTP auth hook, an owner can request a snapshot of an explicitly named, non-isolated leased session with the correct lease id and meta.tenantId: 5. HTTP writes the value back to meta (http-server.ts:612, 625-629, 683), a numeric flags.tenant alone does the same, and the raw socket passes either carrier through. scopeRequestSession then sends the number to normalizeTenantId, whose trim call throws (daemon-http.ts:97-100). The router returns UNKNOWN instead of UNAUTHORIZED with LEASE_SESSION_MISMATCH and field=tenantId (request-execution-scope.ts:241, 484-492). A nested step with a numeric tenant flag takes the same path, and the failure also precedes the active provider-artifact guard. The rule: the lease check must see the raw claim whatever its type. Please make tenant routing type-aware and keep the raw claim. When the session name resolves without a tenant, run the target lease check before the existing malformed-tenant handling.

Not blocking: the 'a null claim' row in lease-context.test.ts:63 uses a null as never cast, and it can be dropped or typed as a LeaseClaimRequest with an unknown-valued meta record, or left as is.

Not verified here: tests, mutations and the author's local gates were not run, and regression validity was judged by reading the 60fbd62 code paths. Nested request producers other than batch, replay and find, which use request-router.ts:422, were not audited.

The only check not passing is Body rules (cancelled). That job reads the PR title and body, and this delta touches none of that, so it looks unrelated. There are no conflicts. After the two fixes above, Body rules needs a re-run on the current body before merge.

@thymikee
thymikee force-pushed the refactor/0.22-session-lease-claims branch from 1e3d990 to 0106304 Compare November 22, 2026 10:13
@thymikee

Copy link
Copy Markdown
Member Author

Reply to #4942 (comment). Fixed at 0106304. The base is 0.22 at e8adbb8.

  1. A meta tenant that routing replaces (request-admission.ts:61, :71). The two tenant-scoping branches are now one return through withDisplacedLeaseClaims. It records the original meta.tenantId when routing replaces it, null included. The batch path at request-router.ts:422 needs no separate edit: the nested invoker reads the claims of the scoped request, and that request now holds the displaced tenant. Test, on the local socket against a real daemon: a snapshot with the owner lease id, tenant isolation, meta.tenantId: null and flags.tenant set to the lease tenant is refused with LEASE_SESSION_MISMATCH field=tenantId. A batch [open, snapshot] with the same carriers is refused at step 2. The same snapshot without the null is admitted.
  2. A tenant that routing cannot read (request-admission.ts:38). normalizeTenantId returns undefined for a value that is not a string, so it does not throw. Without tenant isolation, scopeRequestSession does no tenant check, because the session name resolves without a tenant. assertRequestLeaseAdmission runs the malformed-tenant refusal after assertRequestHoldsSessionLease. Under tenant isolation, the first string carrier routes the request, and a meta tenant of another type stays a claim. Test, over HTTP with no auth hook: meta.tenantId: 5, flags.tenant: 5 and a malformed string tenant on an explicitly named, non-isolated leased session each give UNAUTHORIZED, LEASE_SESSION_MISMATCH, field=tenantId. The same tenant on an unleased session keeps INVALID_ARGS, and the owner is admitted.

Each test fails when its fix is removed (3 mutations). typecheck, lint, check:layering and check:daemon-wire-compat pass. The unit lane for daemon, contracts, proxy, scripts and wire-compat has 6998 passes. The PR body passes scripts/check-pr-body.ts locally.

One behavior to know: under tenant isolation, a malformed string tenant is still an INVALID_ARGS routing error, because no session name resolves and there is no target lease to compare.

Not taken: the null as never cast in lease-context.test.ts. Not done: the full check:affected gate was not run on this head.

…n lease

A leased session admits a request by its lease id and compares each label the
request sends. Some labels never reached that comparison: the tenant a caller
declared before HTTP attestation replaced it, a flag hidden by meta on the
provider-artifact path, and an RPC alias that lost to its sibling.

SessionState.lease is now one SessionLease picked from the admitted DeviceLease,
and assertRequestPresentsLease(req, lease) is the one comparison for the session
check and the active provider-artifact guard. Intake adapters record the labels
they displace in DaemonRequest.internal.displacedLeaseClaims.

Closes #4910
Closes #4935
Admission no longer copies the lease expiry onto the session, so open state is
the only writer of session.lease.
@thymikee
thymikee force-pushed the refactor/0.22-session-lease-claims branch from 0106304 to 2d6a161 Compare November 22, 2026 10:16
@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 2d6a161. 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 62b3e30, both findings from the earlier review (#4942 (comment)) are fixed on the production route. A second independent pass found two remaining defects. CI is green: 15 checks, 0 not passing. There are no conflicts.

A second independent pass found that an unattested HTTP request can lose its valid tenant flag before lease admission. Send snapshot to an active tenant-isolated session with the correct lease id, meta.sessionIsolation set to tenant, meta.tenantId set to 5, and flags.tenant set to the lease tenant. HTTP picks 5 at http-server.ts#L612 and stamps it into both carriers at L683 and L691. Routing then rejects the numeric flag with INVALID_ARGS in request-admission.ts#L50-L57. The request never reaches the typed LEASE_SESSION_MISMATCH for tenantId, while the same request on the socket routes with the valid flag. The rule: on unattested HTTP, a non-string declared tenant must stay a claim for lease comparison, and the original tenant flag must stay available for routing. Attested routing stays as it is. Validation: the HTTP request above must reach lease admission and return LEASE_SESSION_MISMATCH for tenantId.

A second independent pass also found a regression in idle accounting. Enable AGENT_DEVICE_SESSION_IDLE_TIMEOUT_MS and keep a named, non-isolated, unleased session that holds a local device claim with no active capture. Send standalone snapshot requests with meta.tenantId set to 'not a tenant'. On the 0.22 base, request-admission.ts#L37-L44 returns INVALID_ARGS before the execution scope finishes. At this head the same refusal happens inside runAdmitted, so request-execution-scope.ts#L511-L516 stamps activity, and the reaper reads that stamp in session-idle-expiry.ts#L63-L64. Polling with refused requests can now keep the session and its device claim alive. The rule: once the target is resolved, a malformed tenant on an unleased request must be refused before activity accounting and admission side effects. The typed lease comparison stays first when the resolved session has a lease. Validation: the polling run above must let the session expire at the idle timeout.

Not blocking: the ignoresSessionLease guard added in 62b3e30 at request-admission.ts#L44 only refuses the same INVALID_ARGS earlier, because every routed command already reaches request-admission.ts#L96 through runAdmitted. Its comments say such commands never reach that check, which is not true of the malformed-tenant refusal, and its unit test calls the helper directly, so it would pass even if production already refused. These notes can be taken or left.

Could the guard and its comments be deleted, so that one malformed-tenant refusal remains for non-isolated requests: the call after assertRequestHoldsSessionLease in assertRequestLeaseAdmission? If the guard stays, a test through the router (session_list over the real daemon) would show it matters.

The open inline thread claiming session_list and devices skip admission does not apply: shouldLockSessionExecution only picks lock keys, and runLocked always calls runAdmitted, so the refusal at L96 covers every routed command (#4942 (comment)). Please resolve it.

Not verified here: no tests or mutations were run, and the claim that session_list and devices were already refused at 2d6a161 rests on reading the router route. Not verified here: lease RPCs built in http-rpc-methods.ts were assumed to enter the same router path. The upstream files in the rebase onto 0.22 were not reviewed.

Both defects above must be fixed and checked with the validation runs described before merge.

@thymikee

Copy link
Copy Markdown
Member Author

Fixed in 116f6dc98d. Review findings

  • Unattested HTTP preserves the tenant flag for routing when the meta tenant is a non-string. Tenant scoping retains the original value as a displaced claim, so the leased snapshot returns UNAUTHORIZED LEASE_SESSION_MISMATCH field=tenantId. The same request with only the valid flag succeeds.
  • Malformed tenant validation runs after target resolution and before activity accounting or lease admission effects. Leased requests still get the typed lease refusal. The idle test polls with malformed requests and proves the unleased session expires and releases its claim at the original deadline.
  • Removed the inventory-only routing guard and replaced its helper test with HTTP cases for session_list and devices. The inline thread is resolved.

Both regression tests fail on 62b3e3045e. All 108 focused tests and all runnable check:affected checks against origin/0.22 passed at the published SHA. The PR body passes its gate script.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Reviewed 116f6dc. The earlier findings from 62b3e30 (#4942 (comment)) are fixed, but a second independent pass found three regressions against the base tenant checks. Not verified here: any of this by running tests or mutations. The claims rest on reading the code paths.

A second independent pass found that tenant routing now masks a malformed tenant for unleased requests. On unattested HTTP or the local socket, send a tenant-isolated command with meta.tenantId set to 5 and flags.tenant set to 'team'. Base dcbf9d8 rejects the selected meta tenant at packages/daemon/src/sessions/request-admission.ts:37-44. At the head, lines 42-61 route by the flag and replace meta.tenantId, and line 82 validates only the replacement. With no session lease, session_list returns a successful response. A standalone snapshot targeting an unleased local session named team:demo reaches lease admission, fails for the missing run id, and stamps lastActivityAtMs, so repeated requests can postpone expiry of the local claim. The rule: when no session lease applies to the command, the original selected tenant must pass the base validation before activity accounting. Keep the flag fallback routing and the displaced lease comparison for leased requests.

A second independent pass found that newly refused lease-label mismatches still stamp session activity. A standalone snapshot against an active leased session sends the correct lease id and run id in meta and null in flags.runId. The head correctly refuses the null claim at lease-context.ts:248-253. But runAdmitted reaches its finally block with admissionCompleted false, and for a standalone request the guard still calls noteSessionActivity at request-execution-scope.ts:514. The refusal does not renew the remote lease heartbeat, but it does update lastActivityAtMs. The activity stamp should require admissionCompleted on standalone requests as well as bounded steps.

A second independent pass found that a malformed tenant can enter the fresh-open device wait. Send an unisolated open for a fresh local session with meta.tenantId set to 'not a tenant', a valid waitMs, and a device already held by another session. Base dcbf9d8 rejects the tenant before device resolution. At the head, device selection and waitForDeviceOutsideLocks run before tenant validation, which happens at line 402. The request can emit contention progress and spend its full budget before returning INVALID_ARGS. The selected tenant should be validated after the preflight session lookup and before the lock plan or the device wait. The locked validation should stay for requests whose session state changes while they wait.

Not blocking: the new typeof daemonRequest.meta?.tenantId === 'string' check in http-server.ts:692 repeats the routing rule that scopeRequestSession owns, while clientDeclaredTenant at line 612 still selects with ??, so tenantTrust.tenantId can hold 5 and meta and flags can diverge; one exported routing-tenant selector in request-admission.ts would fix that, and it can be taken or left.

The earlier thread claiming session_list and devices skip malformed-tenant admission does not apply: runLocked always enters runAdmitted, and at the head those commands are refused at request-execution-scope.ts:402, which the HTTP test at http-server-proxy-session-lease.test.ts:509 covers, so it can be resolved: #4942 (comment)

The only check that did not pass is Body rules, which was cancelled rather than failed; it checks the PR body and does not touch the daemon admission code, and the other 15 checks pass. There are no conflicts. Not verified here: that the proxy forwards meta.tenantId unchanged under clientToken auth, and the steps that run before runAdmitted with a malformed tenant (request_started event, diagnostics, preflight, open wait). Once the three issues above are fixed, re-run the cancelled Body rules check so CI is fully green.

@thymikee

Copy link
Copy Markdown
Member Author

Fixed in 7a092ca0e1. Review findings

  • Tenant admission reads the original request after routing resolves the target. With no applicable session lease, malformed meta returns INVALID_ARGS even when a valid flag supplied the route. Leased requests retain that route and the typed lease comparison.
  • Activity stamping requires completed admission for standalone commands. A refused lease label leaves activity unchanged. A subsequent admitted snapshot stamps activity.
  • Fresh open validates the tenant before resolving lock keys or entering the device wait. The same validation runs again inside the lock.

Each new real-daemon regression test fails with its own fix removed. All 1,064 focused tests, including eager-closure budgets, passed. Typecheck, lint, the Fallow audit against origin/0.22 and the PR body gate passed.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The delta at 7a092ca fixes the earlier findings from 116f6dc: refused standalone requests no longer renew session activity, and malformed tenants on session_list and devices are refused again. Three problems remain, so this is not ready to merge yet.

A second independent pass found that a falsy non-string tenant now bypasses validation. On the local socket or an unattested command RPC with tenant isolation, send meta.tenantId=false or 0 plus a valid flags.tenant. Base returned INVALID_ARGS because it could not name a tenant. Head routes by the flag at request-admission.ts:42-61, then skips the selected raw value because line 85 tests truthiness, and session_list succeeds. A fresh open with the same carriers and waitMs can also reach contention polling at request-execution-scope.ts:322-335 before any later refusal. The rule to satisfy: when flag fallback supplies the route, validate the original nullish-selected tenant. With no applicable session lease, keep the base missing-tenant refusal for an explicitly selected falsy non-string in tenant isolation. On a resolved leased session, keep the typed claim comparison.

A second independent pass found that routing and policy can now mask the malformed-tenant refusal. In a workspace with two implicit unleased sessions, send an implicit snapshot with meta.cwd set to that workspace, no platform, and meta.tenantId="not a tenant". Base returned INVALID_ARGS before routing. Head reaches session-routing.ts:238-246 and :294-312 first and returns AMBIGUOUS_MATCH. A named unleased request with a malformed tenant behaves the same way when a device pin or daemon policy refuses it at request-execution-scope.ts:312-313; a policy denying snapshot now returns UNAUTHORIZED before tenant validation at line 315. The rule to satisfy: a malformed tenant is refused before any routing error, device-pin check or policy check. If effective-session routing cannot resolve a target, validate the original tenant without a session before returning the routing error. If routing resolves a target, run the tenant preflight before the device-pin and policy checks.

A second independent pass found that final lease admission refusals still advance session activity. An owner sends snapshot to an existing PID-pinned macos-app session after the pinned process exits. The lease scope passes and admissionCompleted becomes true. The process check at request-execution-scope.ts:500 then returns UNAUTHORIZED (MACOS_APP_LEASE_DENIED, rule=process) before the task starts, yet line 520 advances lastActivityAtMs. The fixture in request-execution-scope-macos-app-lease.test.ts:111-160 exercises this refusal. A mutating request can take the same path when the process is alive but a host human-control hold lands while the PID check awaits, because the second gate at lease-registry.ts:489-495 refuses before it invokes the task. The rule to satisfy: only an invoked task stamps activity. Set admissionCompleted when runAdmittedLeaseWork enters the admitted task, after both the process check and the final human-control gate, and keep the existing cancellation and session-lock requirements for the stamp.

The open inline thread about malformed tenants on commands that skip lease admission no longer applies at this head, so it can be resolved: session_list and devices are refused at request-execution-scope.ts:315 and :404, and http-server-proxy-session-lease.test.ts:454 and the test.each at :555 cover it. #4942 (comment)

The head also rewrites the base test that kept the activity stamp on an ordinary failed lease admission, so no refused standalone request stamps activity now. That matches the earlier ask and the PR description. For a non-isolated malformed tenant, head also records request start and finish events and runs the device-pin and policy checks before the tenant refusal; this changes which refusal wins and the event log, not the activity invariant.

The only check that is not passing is Body rules. It was cancelled, not failed, and it validates the PR body text, so it does not exercise the daemon admission route; the other 15 checks pass. There are no conflicts. Re-run the cancelled check so CI is fully green after the fixes. Not verified here: tests and mutations were not run, and these findings rest on reading the head and 116f6dc code paths.

@thymikee

Copy link
Copy Markdown
Member Author

Fixed in 36a762ea1d. Review findings

  • When the tenant flag supplies the route, admission still validates the original nullish-selected value. Under tenant isolation, 0 and false keep the missing-tenant refusal when no session lease applies. A leased request still gets the typed tenant mismatch.
  • When routing cannot resolve a session, malformed tenant takes precedence over the routing error. When it resolves, the tenant check runs before device pin and daemon policy checks. The locked tenant check still runs.
  • Session activity records only invoked work. The activity marker moves inside the task callback, after both the PID check and the final human-control gate.

The real-daemon cases fail when their fixes are removed, including the PID-pinned process refusal. All 1,095 focused tests, including eager-closure budgets, passed. Typecheck, lint, Fallow against origin/0.22 and the PR body gate passed.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The three rules from the earlier review (#4942 (comment)) are now met at 36a762e, but one defect remains. CI is green: every check passes except Proof, which is skipping. An earlier Body rules run was cancelled, and that check only validates PR body text. There are no conflicts.

A second independent pass found that the early resolveSessionScope call can mask the original malformed-tenant refusal on the web identity route. Send snapshot to an unleased named session on the local socket with meta.sessionIsolation='none', flags.sessionIsolation='tenant' and flags.tenant='not a tenant', and no meta.tenantId. Base dcbf9d8 refuses this with INVALID_ARGS at https://github.com/callstack/agent-device/blob/36a762e/packages/daemon/src/sessions/request-admission.ts#L37-L44. At this head, scopeRequestSession returns early at https://github.com/callstack/agent-device/blob/36a762e/packages/daemon/src/sessions/request-admission.ts#L44. The web identity setup then calls resolveSessionScope before the catch in resolveRequestSessionName (https://github.com/callstack/agent-device/blob/36a762e/packages/daemon/src/server/request-execution-scope.ts#L247), so https://github.com/callstack/agent-device/blob/36a762e/packages/daemon/src/sessions/session-routing.ts#L68-L74 returns INTERNAL_ERROR. The same early call hides INVALID_ARGS on an implicit snapshot with meta.tenantId='not a tenant' and meta.cwd=1, where session-routing.ts lines 84 and 334 throw a TypeError. The socket keeps these values at https://github.com/callstack/agent-device/blob/36a762e/packages/daemon/src/server/http/transport.ts#L208-L223. The rule: the early resolveSessionScope call must give the same malformed-tenant error precedence as resolveRequestSessionName. If it throws, run assertRequestTenantAdmission on the original request without a target session before propagating the routing error. Please add a test for each of the two requests above that expects INVALID_ARGS.

The earlier thread about malformed tenants on commands that skip lease admission no longer applies, so it can be resolved: every command now reaches assertRequestTenantAdmission through resolveRequestSessionName, and the session_list test.each([5, 0, false]) covers it (#4942 (comment)).

Not verified here: tests, mutations and typecheck were not run, and the conclusions come from reading the 7a092ca and 36a762e code paths. The attested-tenant HTTP intake path for malformed originals was not exercised. It falls under the remaining labels in #4935, which are out of scope. After this fix, only maintainer judgement is needed before merge.

@thymikee

Copy link
Copy Markdown
Member Author

Fixed in 9ae2505589. Review findings

Early session scope and session address resolution now share the same error precedence. When routing throws, admission checks the original tenant without a target session. If tenant validation passes, the original routing error propagates.

Both socket regressions return INVALID_ARGS at this head. The named snapshot with a malformed tenant flag and conflicting isolation carriers returned INTERNAL_ERROR at 36a762ea1d. The implicit snapshot with a malformed meta tenant and numeric cwd returned UNKNOWN.

All 1,097 focused tests, including eager-closure budgets, passed. Typecheck, lint, Fallow against origin/0.22, and the PR body gate passed. The inline thread is resolved.

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

Comment on lines +86 to +103
export function assertRequestTenantAdmission(
unscopedReq: DaemonRequest,
session?: SessionState,
): void {
const { meta, flags } = unscopedReq;
const rawTenant = meta?.tenantId ?? flags?.tenant;
const assertLease = () => {
assertRequestHoldsSessionLease(unscopedReq, session);
};
if (
!rawTenant &&
resolveSessionIsolationMode(meta?.sessionIsolation ?? flags?.sessionIsolation) === 'tenant'
) {
assertLease();
throw missingIsolatedTenantError();
}
const requestedSession = req.session || 'default';
if (isTenantOwnedSessionName(tenant, requestedSession)) {
return {
...req,
meta: {
...req.meta,
tenantId: tenant,
sessionIsolation: isolation,
},
};
requireWellFormedTenant(rawTenant, assertLease);
}

@apex-sentinel-staging apex-sentinel-staging Bot Nov 22, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer raised on bd4e032.

🆕 🟡 Minor · Missing-tenant branch in assertRequestTenantAdmission is unreachable; scopeRequestSession throws first

A request that resolves to tenant isolation with no rawTenant gets INVALID_ARGS "session isolation mode tenant requires --tenant" from scopeRequestSession, never the session-lease refusal. createRequestExecutionScope calls scopeRequestSession(unscopedReq)—which throws missingIsolatedTenantError() under exactly the same condition—before either call site of assertRequestTenantAdmission, making the !rawTenant && isolation === 'tenant' branch unreachable. Drop that branch and its re-throw, or move the check ahead of the scoping call so the lease refusal can win.

Details

Also raised here

Also raised at this location by persona javascript: requireWellFormedTenant's beforeRefusal callback is never given one outside assertRequestTenantAdmission — scopeRequestSession (request-admission.ts:46) calls requireWellFormedTenant(...) without the beforeRefusal argument, so a request that reaches admission with tenant isolation forced but the session not yet resolved gets the INVALID_ARGS refusal with no lease-mismatch priority. The parameter and its call-site indirection earn their keep only in assertRequestTenantAdmission (line 102); in scopeRequestSession the optional argument is dead weight that reads like a missed priority hook, so drop the optional parameter and inline the malformed-tenant throw there, or state the two priorities in the helper's doc comment.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The branch is reachable. A fresh open with tenant isolation, meta.tenantId: false, and flags.tenant: "e2b" gets through scopeRequestSession: it uses the valid string flag to route to e2b:fresh. resolveRequestSessionName then calls assertRequestTenantAdmission with the original request and no existing session. Nullish selection still yields false, so the branch returns the missing-tenant refusal before device contention.

bd4e032e1f adds this real-daemon case. Removing only the branch made the fresh open check the device holder three times and made both existing inventory cases with 0 and false succeed. The branch stays.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of bd4e032

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

No open findings.

1 finding below minor hidden (user_settings.min_severity).

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

💬 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 findings from the earlier review (#4942 (comment)) are fixed at bd4e032, and no code problem remains from reading the head code and the base db59d00 code paths. Not verified here: tests, mutations and typecheck were not run, and the local socket transport was not re-checked to keep meta.cwd=1 and meta.sessionIsolation='none' (the earlier reading of transport.ts:208-223 was relied on).

Could contracts/src/lease-scope.ts own canonical lease-label normalization alongside normalizeLeaseId? Then registry allocation and session admission could share the same rules without making lease-registry-scope.ts depend on the request handling and command registry imports in core/lease-context.ts.

Neither open inline thread applies at this head, so both can be resolved: #4942 (comment) (the missing-tenant branch is reachable with meta.tenantId=false and a valid flags.tenant) and #4942 (comment) (every command reaches assertRequestTenantAdmission through resolveRequestSessionName, and the session_list test.each([5, 0, false]) covers it).

The only check that is not passing is Body rules, which was cancelled. It validates PR body text, and this change touches only daemon request admission code and tests, so it is likely unrelated. Re-run it to clear it. No conflicts are known. After that, the PR waits for maintainer judgement.

@thymikee

Copy link
Copy Markdown
Member Author

On the design question (could contracts/src/lease-scope.ts own canonical lease-label normalization next to normalizeLeaseId): not in this PR. The table was first written there. It pulled @agent-device/kernel/contracts (readLeaseBackend) and @agent-device/contracts/daemon-http (normalizeTenantId) into client import closures, and scripts/__tests__/eager-closure-budgets.test.ts refused that. So LEASE_FIELD_NORMALIZERS lives in packages/daemon/src/core/lease-context.ts, beside its only callers: admission, the visibility predicate and the registry. normalizeLeaseId has no such imports, so it stays in contracts. Moving the table there would first need those two normalizers moved into a leaf module that clients already load. That is a refactor outside the lease-id rule, not a fix.

@thymikee

Copy link
Copy Markdown
Member Author

The design answer covers the open question at bd4e032: moving the normalizer table into contracts would pull kernel and daemon-http normalizers into client import closures, which the eager-closure budget refuses, so it stays beside its only callers in lease-context.ts. No code findings remain and the second pass is clean. Nothing else blocks this head.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 22, 2026
@thymikee
thymikee merged commit 9dc3c07 into 0.22 Nov 22, 2026
16 of 17 checks passed
@thymikee
thymikee deleted the refactor/0.22-session-lease-claims branch November 22, 2026 15:58
thymikee added a commit that referenced this pull request Nov 22, 2026
thymikee added a commit that referenced this pull request Nov 22, 2026
…'s session (#4953)

* fix(daemon): answer a busy device without naming another proxy client's session

On a proxy shared under one token every client is one tenant, so a
leased session belongs to another client, and busy-device answers that
carried its address confirmed the session and handed out a handle. A
reply may name a holder unless it is another client's: a leased session,
or a tenant-scoped session the request does not already see. The open
contention refusal, its wait progress, the doctor same-device list, the
claimed-device projection, the reboot-takeover warning, and claim-
conflict refusals answer generically for that holder; a claim is
verified through its state dir. A local session of another workspace
keeps its named address: #2580's recovery stands.

Closes #4923

* refactor(daemon): keep the reply naming rule beside the session visibility rule in session-routing

* fix(daemon): name the owner of a claim that resolves to no session, except to a tenant-scoped request

* fix(daemon): name no unlistable holder to a tenant-scoped request

* fix(daemon): treat every public-network caller as remote when naming a holder

* fix(daemon): require listing visibility for shutdown replies

* fix(daemon): gate workspace contention hints on holder visibility

* docs: clarify claim owner visibility in device errors

* test(daemon): give reply-visibility lease fixtures a backend and canonical lease ids after #4942
thymikee added a commit that referenced this pull request Nov 23, 2026
…n lease (#4942)

* fix(daemon): compare every supplied lease label with one typed session lease

A leased session admits a request by its lease id and compares each label the
request sends. Some labels never reached that comparison: the tenant a caller
declared before HTTP attestation replaced it, a flag hidden by meta on the
provider-artifact path, and an RPC alias that lost to its sibling.

SessionState.lease is now one SessionLease picked from the admitted DeviceLease,
and assertRequestPresentsLease(req, lease) is the one comparison for the session
check and the active provider-artifact guard. Intake adapters record the labels
they displace in DaemonRequest.internal.displacedLeaseClaims.

Closes #4910
Closes #4935

* chore(gates): drop lease-lifecycle from the session.lease writers

Admission no longer copies the lease expiry onto the session, so open state is
the only writer of session.lease.

* fix(daemon): refuse a malformed tenant at routing for commands that ignore the session lease

* fix(daemon): preserve tenant routing and refuse malformed tenants before activity

* fix(daemon): validate original tenant before open wait and activity

* fix(daemon): preserve tenant refusal order and stamp only invoked work

* fix(daemon): preserve tenant errors during early session scope resolution

* test(daemon): cover falsy tenant refusal before open wait
thymikee added a commit that referenced this pull request Nov 23, 2026
…'s session (#4953)

* fix(daemon): answer a busy device without naming another proxy client's session

On a proxy shared under one token every client is one tenant, so a
leased session belongs to another client, and busy-device answers that
carried its address confirmed the session and handed out a handle. A
reply may name a holder unless it is another client's: a leased session,
or a tenant-scoped session the request does not already see. The open
contention refusal, its wait progress, the doctor same-device list, the
claimed-device projection, the reboot-takeover warning, and claim-
conflict refusals answer generically for that holder; a claim is
verified through its state dir. A local session of another workspace
keeps its named address: #2580's recovery stands.

Closes #4923

* refactor(daemon): keep the reply naming rule beside the session visibility rule in session-routing

* fix(daemon): name the owner of a claim that resolves to no session, except to a tenant-scoped request

* fix(daemon): name no unlistable holder to a tenant-scoped request

* fix(daemon): treat every public-network caller as remote when naming a holder

* fix(daemon): require listing visibility for shutdown replies

* fix(daemon): gate workspace contention hints on holder visibility

* docs: clarify claim owner visibility in device errors

* test(daemon): give reply-visibility lease fixtures a backend and canonical lease ids after #4942
hannojg pushed a commit to hannojg/agent-device that referenced this pull request Nov 23, 2026
…n lease (callstack#4942)

* fix(daemon): compare every supplied lease label with one typed session lease

A leased session admits a request by its lease id and compares each label the
request sends. Some labels never reached that comparison: the tenant a caller
declared before HTTP attestation replaced it, a flag hidden by meta on the
provider-artifact path, and an RPC alias that lost to its sibling.

SessionState.lease is now one SessionLease picked from the admitted DeviceLease,
and assertRequestPresentsLease(req, lease) is the one comparison for the session
check and the active provider-artifact guard. Intake adapters record the labels
they displace in DaemonRequest.internal.displacedLeaseClaims.

Closes callstack#4910
Closes callstack#4935

* chore(gates): drop lease-lifecycle from the session.lease writers

Admission no longer copies the lease expiry onto the session, so open state is
the only writer of session.lease.

* fix(daemon): refuse a malformed tenant at routing for commands that ignore the session lease

* fix(daemon): preserve tenant routing and refuse malformed tenants before activity

* fix(daemon): validate original tenant before open wait and activity

* fix(daemon): preserve tenant refusal order and stamp only invoked work

* fix(daemon): preserve tenant errors during early session scope resolution

* test(daemon): cover falsy tenant refusal before open wait
hannojg pushed a commit to hannojg/agent-device that referenced this pull request Nov 23, 2026
…'s session (callstack#4953)

* fix(daemon): answer a busy device without naming another proxy client's session

On a proxy shared under one token every client is one tenant, so a
leased session belongs to another client, and busy-device answers that
carried its address confirmed the session and handed out a handle. A
reply may name a holder unless it is another client's: a leased session,
or a tenant-scoped session the request does not already see. The open
contention refusal, its wait progress, the doctor same-device list, the
claimed-device projection, the reboot-takeover warning, and claim-
conflict refusals answer generically for that holder; a claim is
verified through its state dir. A local session of another workspace
keeps its named address: callstack#2580's recovery stands.

Closes callstack#4923

* refactor(daemon): keep the reply naming rule beside the session visibility rule in session-routing

* fix(daemon): name the owner of a claim that resolves to no session, except to a tenant-scoped request

* fix(daemon): name no unlistable holder to a tenant-scoped request

* fix(daemon): treat every public-network caller as remote when naming a holder

* fix(daemon): require listing visibility for shutdown replies

* fix(daemon): gate workspace contention hints on holder visibility

* docs: clarify claim owner visibility in device errors

* test(daemon): give reply-visibility lease fixtures a backend and canonical lease ids after callstack#4942
thymikee added a commit that referenced this pull request Nov 24, 2026
…n lease (#4942)

* fix(daemon): compare every supplied lease label with one typed session lease

A leased session admits a request by its lease id and compares each label the
request sends. Some labels never reached that comparison: the tenant a caller
declared before HTTP attestation replaced it, a flag hidden by meta on the
provider-artifact path, and an RPC alias that lost to its sibling.

SessionState.lease is now one SessionLease picked from the admitted DeviceLease,
and assertRequestPresentsLease(req, lease) is the one comparison for the session
check and the active provider-artifact guard. Intake adapters record the labels
they displace in DaemonRequest.internal.displacedLeaseClaims.

Closes #4910
Closes #4935

* chore(gates): drop lease-lifecycle from the session.lease writers

Admission no longer copies the lease expiry onto the session, so open state is
the only writer of session.lease.

* fix(daemon): refuse a malformed tenant at routing for commands that ignore the session lease

* fix(daemon): preserve tenant routing and refuse malformed tenants before activity

* fix(daemon): validate original tenant before open wait and activity

* fix(daemon): preserve tenant refusal order and stamp only invoked work

* fix(daemon): preserve tenant errors during early session scope resolution

* test(daemon): cover falsy tenant refusal before open wait
thymikee added a commit that referenced this pull request Nov 24, 2026
…'s session (#4953)

* fix(daemon): answer a busy device without naming another proxy client's session

On a proxy shared under one token every client is one tenant, so a
leased session belongs to another client, and busy-device answers that
carried its address confirmed the session and handed out a handle. A
reply may name a holder unless it is another client's: a leased session,
or a tenant-scoped session the request does not already see. The open
contention refusal, its wait progress, the doctor same-device list, the
claimed-device projection, the reboot-takeover warning, and claim-
conflict refusals answer generically for that holder; a claim is
verified through its state dir. A local session of another workspace
keeps its named address: #2580's recovery stands.

Closes #4923

* refactor(daemon): keep the reply naming rule beside the session visibility rule in session-routing

* fix(daemon): name the owner of a claim that resolves to no session, except to a tenant-scoped request

* fix(daemon): name no unlistable holder to a tenant-scoped request

* fix(daemon): treat every public-network caller as remote when naming a holder

* fix(daemon): require listing visibility for shutdown replies

* fix(daemon): gate workspace contention hints on holder visibility

* docs: clarify claim owner visibility in device errors

* test(daemon): give reply-visibility lease fixtures a backend and canonical lease ids after #4942
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