Repository navigation
fix(daemon): answer a busy device without naming another proxy client's session - #4953
Conversation
Size Report
Startup median (7 runs, lower is better):
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 179cee3. The verdict and the full list are in the summary comment.
| const claim = | ||
| claims.find((candidate) => candidate.deviceKey === deviceKey) ?? | ||
| claims.find((candidate) => isClaimOfHostScopedDevice(identity, candidate)); | ||
| return claim ? { claimedBy: { session: claim.session, workspace: claim.workspace } } : {}; | ||
| // A claim owned by a session of this daemon that the request may not see is listed without its | ||
| // owner: the label would be another client's session handle (#4923). `open` still refuses the | ||
| // device, and `device status` stays the host-level view of who holds a device. | ||
| if (!claim || !claimOwnerVisible(req, sessionStore, claim)) return {}; | ||
| return { claimedBy: { session: claim.session, workspace: claim.workspace } }; |
There was a problem hiding this comment.
No longer raised on 2289035: deferred by thymikee in this comment.
🟡 Minor · devices drops the claim marker entirely from a peer, so a busy device looks unclaimed
Behind a shared proxy token, claimedByProjection returns {} instead of { claimedBy: { session, workspace } }, so a device another client holds shows no claim marker in devices output and reads as free to take. The visibility rule only needs to hide the name—the fact that the device is claimed isn't secret (a peer learns it by trying open). This contradicts the help text the same PR added: "devices marks rows that are claimed, so pick an unclaimed device instead of contending."
Suggested change
Report the device as claimed (a nameless marker) rather than returning no projection at all, or amend the new shared-proxy sentence in cli-help.ts so users know an unmarked devices row does not mean the device is free behind a shared token.
Details
Also raised here
Also raised at this location by persona senior-developer: devices now marks an invisibly-claimed device as free; help still says it does not — A peer client on a shared proxy token runs devices and the row for the device another client's leased session holds comes back with no claimedBy (inventory.ts:210 returns {}), so the row reads as free — yet open on that same device is refused with DEVICE_IN_USE. The owning help text this PR edits still promises the opposite: "devices marks rows that are claimed, so pick an unclaimed device instead of contending" (cli-help.ts:331), so the new shared-proxy line at 330 sends a caller to pick exactly the device that will refuse it. Either mark the row claimed without the owner (a boolean, or claimedBy: undefined plus a claimed: true flag) or state in the same help paragraph that a row can read unclaimed behind a shared token and still refuse.
persona: javascript, maintainability, senior-developer
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.
There was a problem hiding this comment.
Fixed in bdc238c. A claim of this daemon whose label resolves to no stored session, such as transient:install, is named again to a local request, so devices and the claim-conflict refusal report it as on 0.22. A tenant-scoped request still gets no owner for such a label: on a proxy shared under one token, the tenant prefix does not tell one client's ended session from another's. That is the case the proxy test covers. New unit test: a local request keeps the owner of transient:install. It fails without the fix.
There was a problem hiding this comment.
Deferred, no change in this PR. claimedBy carries session and workspace as required fields. Showing a claim marker without its owner would change the wire shape of devices for released clients, and that is a separate ADR 0006 decision. Meanwhile a peer's open on that device still gets DEVICE_IN_USE, so a peer cannot take the device by mistake.
This comment has been minimized.
This comment has been minimized.
|
The change at bdc238c still leaks other sessions to proxy clients, so it needs one more fix before merge. All 16 checks pass at this commit, and there are no conflicts.
The new help sentence at cli-help.ts:330 says both
The open inline thread on the unmarked claimed row (#4953 (comment)) still stands. The thread on unresolved or transient claims (#4953 (comment)) is fixed at this commit, because a local request keeps that owner and only a tenant request loses it, so it can be resolved. Not blocking, and these can be taken or left: three predicates now answer 'may this reply name this holder?' ( For a follow-up issue, not for this PR: sessions.md:196 says another workspace's session keeps its named address 'everywhere', but the shutdown refusal hides it; route shutdown through Could the shape stay as it is (one predicate plus one response-level claim filter) with the rule fixed? That would be Not verified here: tests and typecheck were not run, and CI status comes from the checks report. A tenant |
|
Addressed the review of bdc238c in 2289035:
|
This comment has been minimized.
This comment has been minimized.
|
This follow-up on the earlier review (#4953 (comment)) covers 2289035. The tenant-scoped case is now fixed, but the shared-token proxy case still leaks a holder name, so the code needs one more change. Not verified here: tests and typecheck were not run. In the supported clientToken proxy setup without a daemon auth hook, a remote open with valid lease metadata can still reach contention without tenant isolation. The daemon marks it publicNetworkOnly, but resolveSessionScope still classifies an explicitly named request as named-local (session-routing.ts:378). The listing predicate then accepts the unleased named-local holder before mayNameSession reaches its tenant guard, and the claim gate at line 397 also treats the request as local. The proxy then returns a local operator's session address in the busy-device message, details and recovery hint. This breaks the privacy rule the new CLI help promises. The rule to satisfy: when the daemon has admitted a request as publicNetworkOnly, no holder name may appear in an unscoped reply. Apply that check before the local listing predicate and before the claim exceptions, so it covers every site that calls mayNameSession, claimOwnerVisible and dropInvisibleClaimOwner. A regression case through the shared-token proxy that leaves isolation unset, while keeping the peer's valid lease metadata, should prove it. The PR claim that the round-two fix stops busy-device replies from naming local operators' sessions to shared-token proxy clients did not hold in that setup. The production CLI proxy uses clientToken (src/cli/commands/proxy.ts:57-62), and it stamps tenant isolation only when an authenticate callback returns a tenant (daemon-proxy.ts:244-252). Without such a hook, HTTP intake keeps the caller's isolation metadata (http-server.ts:678-687). The new test at http-server-proxy-reply-visibility.test.ts:270-294 inserts tenant isolation in its helper at line 159, so it covers the tenant route only. Please either fix the gap above or narrow the claim to the tenant-scoped case. This is a source trace; the new test was not observed failing against bdc238c. Could session-routing own holder-name disclosure using both the admitted public request context and the tenant and lease visibility rule, so local recovery permissions depend on the daemon's admission decision and not on a caller-selected session namespace? The open inline thread on the unmarked claimed row at inventory.ts:210 (#4953 (comment)) still applies, but needs no further work here: the author deferred the wire marker and cli-help.ts:331 now documents the behavior. The thread on session-routing.ts:402 (#4953 (comment)) no longer applies, because the transient-claim handling was fixed at bdc238c and is unchanged, so it can be resolved. The only check that did not pass is Body rules, which was cancelled and not failed. It validates the PR description and the diff touches no related tooling, so a rerun should settle it. Not verified here: the shutdown widening for local callers has no dedicated test, and the other-daemon claim branch for a tenant request is covered only by a unit test. There are no conflicts. After the fix above, rerun Body rules and resolve the transient-claim thread. |
|
Addressed the review of 2289035 in b1ee621:
|
This comment has been minimized.
This comment has been minimized.
|
Reviewed b1ee621 against the earlier findings (#4953 (comment)). The remote-caller and transient-owner cases from that review are now fixed, but one shutdown regression remains. On a daemon shared by two local workspaces, an implicit shutdown from workspace B with an explicit device selector reaches the handler even if B has no session (session-shutdown.ts:66). If an unleased cwd-scoped session in workspace A holds the device, the handler finds it before binding. On db59d00, Not blocking, and these can be taken or left: for a remote non-tenant caller, session-routing.ts:379 is now stricter than the listing predicate, so the reply withholds a holder that For a follow-up issue, not for this PR: the paragraph at sessions.md:196 says a session of another local workspace keeps its named address everywhere, but a proxy client never learns an unleased non-tenant holder (session-routing.ts:379, asserted by http-server-proxy-reply-visibility.test.ts:296), so the exception should be scoped to local callers and the hidden-holder list completed. The open inline thread on the unmarked invisible claim owner (#4953 (comment)) still applies and is not blocking, since the deferral is documented in Only the Body rules check is not passing. It was cancelled, not failed, and it validates the PR description, which this diff does not touch, so a rerun should settle it. The other 16 checks pass, including the daemon unit tests that run the new proxy test. There are no conflicts. Before merge, the shutdown naming fix needs to land. Not verified here: tests were not run, the claim that the new proxy test fails at 2289035 rests on a source trace and not an observed red run, and the |
|
Addressed the shutdown finding in The real daemon HTTP regression fails on Filed #4960 to share the public-network rule between listing and reply naming. Resolved the transient-claim thread. |
This comment has been minimized.
This comment has been minimized.
|
At 3fb31b9 the shutdown naming is fixed and the transient claim label no longer leaks to proxy clients, but two items from the earlier review (#4953 (comment)) remain: one defect and one unsupported claim. A local authenticated implicit open can publish a cwd-scoped session backed by an admitted providerless logical lease (request-admission.ts lines 108-109 and 197-206 allow it, and session-open-state.ts lines 66 and 73 store the scope and the lease independently). When an implicit open from a different workspace selects that device, isImplicitSessionScopeConflict compares only the two cwd scope ids, and open-device-contention-wait.ts:157 then calls the workspace-specific builder before mayNameSession can reject the leased holder. The second workspace gets the leased holder address in the DEVICE_IN_USE message, details.session and the close hint, though it cannot list that holder. The rule: a refusal may name a holder only when mayNameSession allows it with device-recovery, and the workspace-specific builder runs only in that case. Please evaluate mayNameSession first and use the existing anonymous refusal when naming is denied. Live validation: from a second workspace, open the device held by a leased cwd session and show that the reply carries no holder address in the message, details or hint. The PR states that every open-contention refusal checks whether the caller may learn the holder address, and that the only exception is local recovery of an unleased local holder. That does not hold at head. The device-recovery check at session-routing.ts:388 gets its three production callers at open-device-contention-wait.ts:170 and :196 and session-routing.ts:416, while buildForeignWorkspaceSessionConflict has a single call at open-device-contention-wait.ts:158 that returns before the refusal at :164 reaches that check. Please fix the path above, then either state the claim so it matches the code or show the enumeration that supports it. Could session-routing.ts own the decision whether a reply can name a holder, with both contention refusal builders taking that decision, and could resources/device/device-claim-conflict.ts apply the same policy to its typed owner before it constructs an error? That would guard the workspace-specific refusal and avoid decoding the claim builder serialized details in session routing. The inline thread on inventory listing a claimed row without claimedBy still stands, but it is deferred and not required here (#4953 (comment)). The thread on an unresolved claim label returning localRequest is fixed at head and can be resolved (#4953 (comment)). Not verified here: the tests were not run. That the new HTTP regression fails at b1ee621 and passes at head comes from a source trace of mayNameSession at both commits, not from a red/green run. The doctor change for local cwd callers was checked by reading the code only, and no test drives doctor through a cwd-scoped request, since the doctor tests use a named-local request. The Body rules failure was attributed from the job purpose and its cancelled state, and its log was not read. Only Body rules is not passing, and it was cancelled rather than failed. It checks the PR description, and no daemon, test or docs code in the diff is on its route. The other 16 checks pass, including the daemon unit tests that run the new proxy and session-routing tests. Rerunning the cancelled check should settle it. No conflicts. Before merge, the leased-holder refusal needs the fix above and the cancelled check needs a rerun. |
|
Fixed the leased-holder finding in The real daemon HTTP test allocates a providerless lease, opens a cwd-scoped session, and attempts an implicit open from a second workspace. On Updated the PR body to match. The body checker, 50 targeted tests, 950 eager-closure tests, Fallow audit, and all runnable checks in the exact-commit affected gate passed. |
This comment has been minimized.
This comment has been minimized.
|
The earlier findings from 3fb31b9 are now fixed at 8b7857e, with one docs gap left. The unresolved claim label no longer falls back to naming the holder, and the real daemon HTTP test now covers the route the last review asked about. The remaining problem is in the docs. An unleased local install in a second workspace can hit a device whose live claim belongs to a cwd-scoped holder with a providerless lease. On the base, deviceClaimConflictError names that owner. At 8b7857e, dropInvisibleClaimOwner removes the name and owner details because the requester cannot see the holder. The sessions guide still says a readable claim means the error names its owner. The help text still says the error supplies the owner state directory. Callers are sent to an address the refusal now withholds. Please make the guide and help state that owner and state-directory disclosure depend on owner visibility, and point callers with an anonymous error to the recovery hint. Could resources/device/device-claim-conflict.ts apply the request owner-visibility decision to the typed claim inside deviceClaimConflictError, with the policy kept in session-routing.ts? The constructor already serves open, renewal, transient admission and bounded steps. Both router paths could then drop the code that decodes its error details, and diagnostics would carry the same message as the reply. Of the open threads, the one on inventory.ts:207-209 does not apply here: listing a claimed row without claimedBy matches the documented help, and the maintainer deferred it (#4953 (comment)). The one on session-routing.ts:415-416 is fixed at 8b7857e, so it can be resolved (#4953 (comment)). The only check not passing is Body rules, and it was cancelled, not failed. It validates the PR description, and this change touches neither of its routes, so it is likely unrelated. Rerunning it should settle that. No conflicts are known. Not verified here: the tests were not run, the red-on-3fb31b9 and green-at-head result for the leased workspace case comes from reading the code, and the Body rules log was not read. No device run is needed because only daemon reply text changed. After the docs fix, the cancelled Body rules check must be rerun before merge. |
|
Addressed the docs finding in |
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.
|
The docs and CLI help now say the owner and its state directory appear only when the caller can see the owner, and point everyone else to the recovery hint. This addresses the last finding; nothing else blocks 7876b90. |
…'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
…ility rule in session-routing
…xcept to a tenant-scoped request
…nical lease ids after #4942
7876b90 to
f4550d9
Compare
Summary
On a shared proxy, a busy-device reply could disclose another client's session address (#4923). Open contention and wait progress use the same visibility check. A public-network or tenant-scoped caller learns only listable leased or tenant-scoped holders. Local device recovery can also name an unleased local holder in another workspace. Shutdown and doctor require listing visibility. The sessions guide and CLI help explain when a claim error shows the owner and state directory. No wire schema change.
Before / after
openagainst another client's leased device returnsDEVICE_IN_USE. Base names the holder. Head omits the address. The lease owner still sees it.openagainst another workspace's providerless leased holder named it on3fb31b9. Head omits it from the message, details, and close hint.shutdownagainst another workspace's unleased holder named it onb1ee621. Head restores the base behavior and omits it.Validation
At
8b7857ebd9, 50 targeted tests and 950 eager-closure tests pass. The leased workspace open regression fails on3fb31b9and passes at head. Format, lint, typecheck, Fallow audit againstorigin/0.22, and all runnable affected checks pass. At7876b90221, 135 CLI help tests and lint pass for the documentation follow-up. Hosted CI covers the remaining checks.Closes #4923