Repository navigation
fix(daemon): refuse an allocate that repeats lease labels without the lease id - #4947
Conversation
Size Report
Startup median (7 runs, lower is better):
|
This comment has been minimized.
This comment has been minimized.
|
The daemon change in a395cce matches the invariant from #4909, but it changes CLI behavior and the CLI test no longer shows that. The CLI derives a leased session's run and client labels from the session name and profile (https://github.com/callstack/agent-device/blob/a395cce/packages/remote/src/remote-connection-state.ts#L424). When it has no saved lease id, it allocates with a fresh random id (https://github.com/callstack/agent-device/blob/a395cce/src/cli/commands/connection-lease-transaction.ts#L396). Two cases reach that allocate: re-opening the same session from a fresh or lost state dir, and A second independent pass found the same CLI gap from the other side. Resuming a live CLI lease should need the saved connection record, or an explicitly transferred lease id, with a matching scope (https://github.com/callstack/agent-device/blob/a395cce/src/cli/commands/connection-runtime.ts#L72). Keep a separate test that reopens with the saved credential. A second independent pass found that the scope-mismatch refusal changed for device-less bindings (https://github.com/callstack/agent-device/blob/a395cce/packages/daemon/src/resources/lease-registry.ts#L217). With a live device-less lease that has a client id, an allocate with the same tenant, run, backend and provider but a different explicit client id was rejected on base with UNAUTHORIZED / LEASE_SCOPE_MISMATCH. At head it gets DEVICE_IN_USE / DEVICE_LEASE_BUSY, so a caller that branches on the typed scope error now sees device contention. Keep the base scope-mismatch refusal for every request the base refused, and use DEVICE_LEASE_BUSY only for requests that passed that check and would have reused the binding without the credential. A second independent pass found that the Not blocking, and these can be taken or left: The only failing check is Body rules, which looks unrelated to the code: the PR body lacks the required Summary, Before / after and Validation sections. There are no conflicts. Not verified here: the new tests and the CLI regression were judged by reading base and head code, and no tests were run. Not verified here: daemons older than the caller-chosen Before merge, replay the CLI allocations as sent, assert the fresh-state refusal, and name the CLI case in Breaking. Then add the missing PR body sections so Body rules passes. |
… lease id refreshExistingRunBinding returned a live lease, with its id, to any lease_allocate that repeated the tenant, run, backend, provider, device key, and client id. The lease id is the bearer credential for a leased session (ADR 0007), and those labels are guessable, so a direct RPC or SDK caller could receive another caller's lease id. An allocation that repeats a live run binding's labels without that binding's lease id is now refused as contention, with DEVICE_IN_USE and reason DEVICE_LEASE_BUSY, and no lease id in the reply. This applies to device-less leases too. An owner refresh that sends the lease id still gets its lease back through refreshRequestedLease. The CLI already sends the lease id it holds, so no caller changed.
…n contract A device-less run binding that a request contradicts with an explicit label stays UNAUTHORIZED / LEASE_SCOPE_MISMATCH, as the base refused it; DEVICE_LEASE_BUSY names only the repeat that matched the binding without the lease id. The CLI replays prove both halves: a re-open from fresh state has lost the lease id, so it is refused as contention and gets no lease id, and a re-open that sends the id the allocation named gets that lease back.
a395cce to
4cd3345
Compare
|
Addressed in 4cd3345 (rebased on 0.22):
Declined the optional cleanups: |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 4cd3345. The verdict and the full list are in the summary comment.
| The daemon never fills a missing lease id from the session. | ||
| Tenant, run id, lease backend, client id, device key, and lease provider are labels. | ||
| The daemon refuses a label that differs from the session lease. A missing label is not a refusal and grants nothing. | ||
| An allocate that repeats the labels of a live lease without that lease's id is refused as contention, with `DEVICE_IN_USE` and reason `DEVICE_LEASE_BUSY`. It returns no lease id. A label that contradicts the live lease stays a scope mismatch, with `UNAUTHORIZED` and reason `LEASE_SCOPE_MISMATCH`. Only an allocate that sends the id of its live lease gets that lease back. |
There was a problem hiding this comment.
No longer raised on 5b413c5: marked fixed in 5b413c5 by thymikee in this comment; the code it pointed at changed.
🆕 🟡 Minor · Contract doc claims any contradicting label is a scope mismatch; device-keyed leases say busy
A repeat allocate against a live device-keyed lease with a contradicting clientId (same tenant, run, backend, provider, deviceKey) returns DEVICE_IN_USE / DEVICE_LEASE_BUSY, not UNAUTHORIZED / LEASE_SCOPE_MISMATCH. Cause: assertNoRunBindingLease only calls assertLeaseScopeMatch when the live lease has no deviceKey; the same over-claim appears in the method's docstring, whose own device-keyed test asserts the busy error.
Suggested change
Scope the new sentence (and the assertNoRunBindingLease docstring) to device-less leases: a label that contradicts a device-less live lease is LEASE_SCOPE_MISMATCH, while a repeat of a live device-keyed binding is DEVICE_LEASE_BUSY whatever else its clientId says.
Details
Also raised here
Also raised at this location by persona maintainability: New doc comment claims label disagreements always stay LEASE_SCOPE_MISMATCH — An allocate that repeats a live device-KEYED lease's tenant, run, backend, provider and device but names a different clientId is refused with DEVICE_LEASE_BUSY, not the LEASE_SCOPE_MISMATCH the new comment and the new contracts-doc sentence promise: assertLeaseScopeMatch runs only under if (!existingLease.deviceKey), and deviceLeaseBusyError is thrown unconditionally after it. The same contradicting label on a device-less lease does produce LEASE_SCOPE_MISMATCH, which the new registry test pins, so the two paths answer one condition with two different reason codes. Scope the comment (and the added sentence in packages/daemon/docs/remote-device-lease-contracts.md) to device-less leases, or run the scope check for device-keyed leases too so the taxonomy matches the documentation.
persona: javascript, senior-developer, maintainability
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.
There was a problem hiding this comment.
Fixed in 5b413c5: the contract doc sentence and the assertNoRunBindingLease docstring now say the scope mismatch applies to a device-less live lease, and a repeat of a device-keyed binding is DEVICE_LEASE_BUSY whatever its client id says.
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.
|
This PR is ready at 5b413c5. The earlier findings from a395cce (#4947 (comment)) are fixed: the test helper now exercises the real refresh path, the device-less LEASE_SCOPE_MISMATCH refusal is kept, and retainOnClose is documented. All 16 checks pass at 5b413c5, and there are no conflicts. Nothing else must happen before merge. Not blocking, and fine to take or leave: the test 'a re-open that sends the lease id it saved gets its live lease back' in src/tests/cli-leased-session.test.ts replays the first open's captured allocation twice (https://github.com/callstack/agent-device/blob/5b413c5/src/__tests__/cli-leased-session.test.ts#L556). No second CLI The open inline thread on the contract doc (#4947 (comment)) no longer applies. Line 80 of remote-device-lease-contracts.md now scopes the scope-mismatch wording to device-less leases and says device-keyed repeats are DEVICE_LEASE_BUSY, which matches lease-registry.ts:219-220. It can be resolved. Not verified here: tests were not run locally, and regression validity was judged by reading the base and a395cce code against the new assertions. The older-daemon sentences in client-api.md and remote-proxy.md were checked against base code only, and no older daemon build was run. |
… lease id (#4947) * fix(daemon): refuse an allocate that repeats lease labels without the lease id refreshExistingRunBinding returned a live lease, with its id, to any lease_allocate that repeated the tenant, run, backend, provider, device key, and client id. The lease id is the bearer credential for a leased session (ADR 0007), and those labels are guessable, so a direct RPC or SDK caller could receive another caller's lease id. An allocation that repeats a live run binding's labels without that binding's lease id is now refused as contention, with DEVICE_IN_USE and reason DEVICE_LEASE_BUSY, and no lease id in the reply. This applies to device-less leases too. An owner refresh that sends the lease id still gets its lease back through refreshRequestedLease. The CLI already sends the lease id it holds, so no caller changed. * fix(daemon): keep the scope-mismatch refusal and prove the CLI re-open contract A device-less run binding that a request contradicts with an explicit label stays UNAUTHORIZED / LEASE_SCOPE_MISMATCH, as the base refused it; DEVICE_LEASE_BUSY names only the repeat that matched the binding without the lease id. The CLI replays prove both halves: a re-open from fresh state has lost the lease id, so it is refused as contention and gets no lease id, and a re-open that sends the id the allocation named gets that lease back. * docs(daemon): scope the lease scope-mismatch sentence to device-less leases
… lease id (callstack#4947) * fix(daemon): refuse an allocate that repeats lease labels without the lease id refreshExistingRunBinding returned a live lease, with its id, to any lease_allocate that repeated the tenant, run, backend, provider, device key, and client id. The lease id is the bearer credential for a leased session (ADR 0007), and those labels are guessable, so a direct RPC or SDK caller could receive another caller's lease id. An allocation that repeats a live run binding's labels without that binding's lease id is now refused as contention, with DEVICE_IN_USE and reason DEVICE_LEASE_BUSY, and no lease id in the reply. This applies to device-less leases too. An owner refresh that sends the lease id still gets its lease back through refreshRequestedLease. The CLI already sends the lease id it holds, so no caller changed. * fix(daemon): keep the scope-mismatch refusal and prove the CLI re-open contract A device-less run binding that a request contradicts with an explicit label stays UNAUTHORIZED / LEASE_SCOPE_MISMATCH, as the base refused it; DEVICE_LEASE_BUSY names only the repeat that matched the binding without the lease id. The CLI replays prove both halves: a re-open from fresh state has lost the lease id, so it is refused as contention and gets no lease id, and a re-open that sends the id the allocation named gets that lease back. * docs(daemon): scope the lease scope-mismatch sentence to device-less leases
… lease id (#4947) * fix(daemon): refuse an allocate that repeats lease labels without the lease id refreshExistingRunBinding returned a live lease, with its id, to any lease_allocate that repeated the tenant, run, backend, provider, device key, and client id. The lease id is the bearer credential for a leased session (ADR 0007), and those labels are guessable, so a direct RPC or SDK caller could receive another caller's lease id. An allocation that repeats a live run binding's labels without that binding's lease id is now refused as contention, with DEVICE_IN_USE and reason DEVICE_LEASE_BUSY, and no lease id in the reply. This applies to device-less leases too. An owner refresh that sends the lease id still gets its lease back through refreshRequestedLease. The CLI already sends the lease id it holds, so no caller changed. * fix(daemon): keep the scope-mismatch refusal and prove the CLI re-open contract A device-less run binding that a request contradicts with an explicit label stays UNAUTHORIZED / LEASE_SCOPE_MISMATCH, as the base refused it; DEVICE_LEASE_BUSY names only the repeat that matched the binding without the lease id. The CLI replays prove both halves: a re-open from fresh state has lost the lease id, so it is refused as contention and gets no lease id, and a re-open that sends the id the allocation named gets that lease back. * docs(daemon): scope the lease scope-mismatch sentence to device-less leases
Summary
lease_allocaterefreshed a live run binding from its labels alone: repeating the tenant, run, backend, provider, device key, and client id returned that lease with its lease id, though the caller held nothing. The lease id is the credential (ADR 0007); the labels are guessable (#4909). An allocate that repeats a live binding's labels without that binding's lease id is now refused as contention,DEVICE_IN_USE/DEVICE_LEASE_BUSY, with no lease id in the reply. A label that contradicts the live lease staysUNAUTHORIZED/LEASE_SCOPE_MISMATCH. A refresh that sends the lease id still gets that lease.Before / after
Breaking
DEVICE_IN_USE/DEVICE_LEASE_BUSYuntil that lease expires or the saved lease id is sent; the base handed the live lease back.connect --forceafter a failed release hits the same refusal.Validation
Head 4cd3345: real-daemon RPC and CLI-replay tests assert the refusal leaks no lease id and the id-based refresh and re-open still recover; registry tests keep the scope-mismatch refusal.
pnpm typecheck,lint,format, targeted vitest, andpnpm check:affected --run --base origin/0.22pass. Risk: daemons older than caller-chosenleaseIdignore it; the docs say so.Closes #4909