Repository navigation
Conversation
Size Report
Startup median (7 runs, lower is better):
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on dbcd132. The verdict and the full list are in the summary comment.
| function findTrackedArtifactId( | ||
| artifactPath: string, | ||
| tenantId: string | undefined, | ||
| owner: Pick<DownloadableArtifactRegistration, 'artifactPath' | 'tenantId' | 'leaseId'>, | ||
| ): string | undefined { | ||
| for (const [artifactId, entry] of pendingArtifacts()) { | ||
| if ( | ||
| !entry.cleanupRequested && | ||
| entry.artifactPath === artifactPath && | ||
| entry.tenantId === tenantId | ||
| ) | ||
| return artifactId; | ||
| if (entry.cleanupRequested || entry.artifactPath !== owner.artifactPath) continue; | ||
| if (entry.leaseId !== undefined) return artifactId; | ||
| if (entry.tenantId === owner.tenantId && owner.leaseId === undefined) return artifactId; | ||
| } | ||
| return undefined; | ||
| } |
There was a problem hiding this comment.
No longer raised on 8d56500.
🟡 Minor · A file registered without a lease gets a second artifact id when later registered with one
Register path P for tenant T with no leaseId, then register P again with leaseId L: findTrackedArtifactId returns undefined and trackDownloadableArtifact mints a second id, so each id deletes the file after its own download. The second call's owner.leaseId short-circuits the tenant match (entry.tenantId === owner.tenantId && owner.leaseId === undefined), so the pre-existing unleased entry is never matched. The reverse order is also lease-blind: if (entry.leaseId !== undefined) return artifactId; returns an entry owned by lease A to a registration under lease B, so B names an artifact id it then cannot download (401 LEASE_OUTPUT_MISMATCH).
| function findTrackedArtifactId( | |
| artifactPath: string, | |
| tenantId: string | undefined, | |
| owner: Pick<DownloadableArtifactRegistration, 'artifactPath' | 'tenantId' | 'leaseId'>, | |
| ): string | undefined { | |
| for (const [artifactId, entry] of pendingArtifacts()) { | |
| if ( | |
| !entry.cleanupRequested && | |
| entry.artifactPath === artifactPath && | |
| entry.tenantId === tenantId | |
| ) | |
| return artifactId; | |
| if (entry.cleanupRequested || entry.artifactPath !== owner.artifactPath) continue; | |
| if (entry.leaseId !== undefined) return artifactId; | |
| if (entry.tenantId === owner.tenantId && owner.leaseId === undefined) return artifactId; | |
| } | |
| return undefined; | |
| } | |
| function findTrackedArtifactId( | |
| owner: Pick<DownloadableArtifactRegistration, 'artifactPath' | 'tenantId' | 'leaseId'>, | |
| ): string | undefined { | |
| for (const [artifactId, entry] of pendingArtifacts()) { | |
| if (entry.cleanupRequested || entry.artifactPath !== owner.artifactPath) continue; | |
| if (entry.tenantId !== owner.tenantId) continue; | |
| if (entry.leaseId !== undefined || owner.leaseId !== undefined) { | |
| if (entry.leaseId === owner.leaseId) return artifactId; | |
| continue; | |
| } | |
| return artifactId; | |
| } | |
| return undefined; | |
| } |
Details
Also raised here
Also raised at this location by persona maintainability: findTrackedArtifactId's owner-first lookup has no reader for a leased tenant mismatch — Now that the loop takes the whole owner object, the leased branch (if (entry.leaseId !== undefined) return artifactId;) short-circuits before any tenant comparison, so a leased entry and its tenant rule coexist in one loop with no hint of which wins. A one-line comment naming that precedence — the lease outranks the tenant for an already-leased file — keeps the next change to this loop from "fixing" the missing check.
persona: maintainability, javascript, 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.
| const leaseId = | ||
| activeLease?.leaseId ?? assertRequestHoldsSessionLease(params.req, existingSession)?.leaseId; | ||
| if (leaseId) { | ||
| emitDiagnostic({ level: 'info', phase: REQUEST_LEASE_DIAGNOSTIC_PHASE, data: { leaseId } }); | ||
| } | ||
| if (!activeLease) return params.req; |
There was a problem hiding this comment.
No longer raised on 8d56500, with the code it pointed at unchanged: withdrawn, not fixed.
🟡 Minor · Exempt commands stamp the session lease into diagnostics but register artifacts unleased
On a leased session, a lease-admission-exempt command that presents the session lease id gets activeLease === undefined from assertRequestLeaseAdmission, so admitRequestLeaseForLockedScope never sets internal.admittedLease, yet the stamp still emits request_lease with the session lease id. Artifact registration reads only internal.admittedLease?.leaseId, so that same request's files are registered with no lease—callers carrying the tenant label list and download them while the diagnostics record refuses them.
Suggested change
Carry the lease id the request may act under (activeLease ?? session lease) on the request as one value, and use that single value both for the request_lease diagnostics stamp and for the artifact leaseId.
Details
persona: senior-developer, javascript
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.
dbcd132 to
8d56500
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 8d56500. The verdict and the full list are in the summary comment.
| if (logPath === scope.logPath && scope.logOwners?.length && !scope.logOwnersPublished) { | ||
| const owners = scope.logOwners.map((owner) => `${owner}\n`).join(''); | ||
| fs.appendFileSync(diagnosticsRecordOwnersPath(logPath), owners, 'utf8'); | ||
| scope.logOwnersPublished = true; | ||
| } |
There was a problem hiding this comment.
No longer raised on 400ff5d: the code it pointed at changed.
🆕 🟡 Minor · Nested batch/replay step records get no owners file, so anyone can read them
A nested replay/test/batch step on a leased session writes its diagnostics record with no owners file, so GET /sessions/<tenant:session>/requests/<stepRequestId>/diagnostics answers 200 to any caller holding the shared proxy token while the outer request's own record correctly answers 401. Cause: logOwnersPublished is a single boolean on the request's ALS scope; the nested step reuses that scope, so the flag is already true and appendDiagnosticLine skips the .owners write for the step's new logPath. readRecordOwners then maps the missing file to [], making the access check vacuously true.
| if (logPath === scope.logPath && scope.logOwners?.length && !scope.logOwnersPublished) { | |
| const owners = scope.logOwners.map((owner) => `${owner}\n`).join(''); | |
| fs.appendFileSync(diagnosticsRecordOwnersPath(logPath), owners, 'utf8'); | |
| scope.logOwnersPublished = true; | |
| } | |
| if (logPath === scope.logPath && scope.logOwners?.length && !scope.ownersPublishedFor?.has(logPath)) { | |
| const owners = scope.logOwners.map((owner) => `${owner}\n`).join(''); | |
| fs.appendFileSync(diagnosticsRecordOwnersPath(logPath), owners, 'utf8'); | |
| (scope.ownersPublishedFor ??= new Set()).add(logPath); | |
| } |
Suggested change
Track owners publication per log path (e.g. a Set on the scope) instead of one boolean per scope, so a nested step that re-points the scope still publishes owners before its first byte. Add a regression test where a batch/replay step on a leased session reads the step record without the lease id and expects 401.
Details
persona: javascript
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.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 400ff5d. The verdict and the full list are in the summary comment.
| const owners = await readRecordOwners(recordPath); | ||
| const presentedLeaseId = req.headers[DAEMON_HTTP_LEASE_HEADER]; | ||
| const presented = typeof presentedLeaseId === 'string' ? presentedLeaseId : undefined; | ||
| if (!owners.every((owner) => requestHoldsOutputLease(owner, presented))) { | ||
| sendRestJsonError(res, normalizeError(leasedOutputRefusal('Diagnostics record'))); | ||
| return; | ||
| } |
There was a problem hiding this comment.
No longer raised on ac4f9b2: the code it pointed at changed.
🆕 🟡 Minor · A diagnostics record with two lease owners becomes unreadable by every reader
A record whose owners file holds two distinct verifiers is refused to all readers because owners.every(owner => requestHoldsOutputLease(owner, presented)) can never be satisfied by the single lease a request presents. Two owners land on one file because appendDiagnosticLine guards on !scope.logOwnerPublished (per scope, not per path), and nested batch/replay steps inheriting the same meta.requestId resolve the same record path while claimRequestDiagnosticsRecord assigns their scopes different owners.
Suggested change
Key the owners-file publish by record path (a Set of paths already written) rather than by scope, and confirm no two scopes that can carry different owners resolve the same request record path; if they can, split the record per owner so a reader needs to hold only one lease.
Details
persona: javascript, 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.
@apex-sentinel-staging note Fail-closed by design, no change. Nested steps inherit the parent lease through handDownRequestLeaseScope, so a normal batch, replay or test writes one owner value per line and the parent reads its record. A second distinct owner appears only when a step names another lease id. Admission refuses that step, and the record then serves nobody rather than serving another lease's lines. Splitting records per owner would add a path scheme for a request that is already refused.
There was a problem hiding this comment.
Withdrawing this finding
Your explanation checks out against the code: handDownRequestLeaseScope only fills lease fields the child leaves unset (lease-context.ts:126-140), so a nested batch/replay/test step that inherits meta.requestId also inherits the parent's leaseId and gets the same leaseVerifier owner — and a step that names a different lease id trips assertRequestPresentsLease/assertSuppliedLeaseLabels before it can append anything, so the second owners line never lands. The remaining window (one scope appending under owner A, another under owner B for the same path) is exactly the scenario you intend to fail closed on, and refusing every reader is the safer outcome than serving another lease's lines. The line-162 every(...) over a list is fine for the single-entry case the normal path produces; no change requested.
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
|
Commit 400ff5d has five problems with leased artifacts and diagnostics. Each one lets a record or capture reach the wrong lease, or locks out the right one. They need fixes before merge. A second independent pass found that reusing a capture path lets older artifact IDs serve a new lease's bytes. A direct static-token daemon that accepts host output paths can register a screenshot of an unleased session, then write a leased screenshot to the same path while the first ID is pending (artifact-tracking.ts:232, screenshot adapter, request-finalization.ts:161). Registration keeps the earlier entry, so both entries point at that path. A second independent pass found that diagnostics written before an upgrade stay readable by the whole tenant (request-diagnostics-http.ts:194). With the same state directory, a leased request record written by the base keeps its original path and has no owners file. The head resolves that path without a live session (daemon-runtime.ts:656). It reads the missing sidecar as an empty owner list and streams the record to a caller with the shared token and tenant but no lease ID. A base debug close that kept its lease also wrote the raw lease ID into that record. The rule: a record that is explicitly unleased and a legacy record of unknown ownership must be told apart. Legacy records should be served only after trustworthy lease provenance is recovered and credentials are redacted, and ambiguous ones should stay off the remote route. A second independent pass found that sequential reuse of a request ID makes existing diagnostics unreadable (request-diagnostics-http.ts:162). HTTP keeps caller-supplied tracking IDs and frees them on completion (http-server.ts:532), and the record name comes from that ID and the session (request-execution-scope.ts:271). Two completed requests with different lease IDs can therefore share one record, and the second can be a request the router refused, since the router writes diagnostics before lease admission. Both digests are appended (diagnostics.ts:395), and every digest must match the same credential. The base returned the record to its tenant. At head even the first request's legitimate owner gets 401, and an earlier unleased record at that address loses tenant-only readability. The rule: each independent request gets a server-unique diagnostics locator that carries its own ownership, while the client tracking ID stays for request tracking only. A second independent pass found that legacy recording manifests can republish a leased export without its producing lease (record-runtime.ts:504). The base manifest recorded the remote-output flag and tenant but no lease verifier. When a stop-recovery request reaches the head handler for such a manifest, the missing verifier bypasses ownership and the completed export is returned (record-runtime.ts:539). A same-tenant request for an unheld named session with no tenant isolation can reach this path without a lease (request-admission.ts:116). Finalization then registers the export with no verifier (request-finalization.ts:107). The rule: the remote stop-recovery path republishes a completed recording only when its provenance is known. Explicitly unleased manifests keep recovery, and legacy exports of unknown ownership stay out of remote delivery. A second independent pass found that the producing caller cannot replay its retained recording through Not blocking, and each can be taken or left: the lease-ownership code (leaseVerifier, requestHoldsOutputLease, leasedOutputRefusal, claimRequestDiagnosticsRecord) sits in artifact-tracking.ts although diagnostics, recording and the router import it, while lease ID canonicalization already lives beside lease-context.ts; the SHA-256 digest comparison at artifact-tracking.ts:52 could use the existing timingSafeStringEqual; the doc and PR text say the daemon log names the lease ID, but request-scoped lines written before the request record are fingerprinted, so the sentence should cover only daemon-scope events or those writes should be marked operator-only; the test "record stop after a daemon restart serves the export only under the lease that started it" retires a session in memory and never reaches the ok:true branch after a real restart, so it could be renamed to the refusal it proves; the sentence "each caller reads only its own records" in remote-device-lease-contracts.md:93 holds only for callers that sent a lease ID; and http-server-proxy-leased-output.test.ts:200 does not send the artifacts RPC with an ended lease ID, so one assertion after endLeasedSession would cover the documented CLI route. Could the ownership code be simpler and better owned with the same behavior? One lease-output module next to lease-context.ts could export the verifier (via canonicalLeaseId), a constant-time holds(), the refusal and the diagnostics claim. The HTTP authorizer could return {tenantId, leaseId} so both REST routes share one reader. The router could set one request-lease value read for artifacts, manifests and diagnostics owner. TenantOwnedEntry could take an optional leaseVerifier, so requireTenantOwnedEntry enforces both rules for artifacts. Production size (+266/-56) is under the 700-line threshold, and no deletion was found that would shrink it. The three open inline threads from earlier review do not apply, so they can be resolved. Shared path cleanup: two IDs for one path share one refcounted cleanup, and leased-entry precedence is the documented rule. Lease-exempt commands: none of the lease-exempt commands returns downloadable artifacts. In-scope steps: they keep the outer request ID and append to the record the outer request already owns, and other steps get a fresh scope and claim. No lower-priority threads still apply. CI is still running: Smoke Tests (android, ios, macos) and one other check are in progress, and the smoke jobs run every request through the new diagnostics claim, so the diff overlaps their route. Body rules has two cancelled runs superseded by a rerun in progress, with no code overlap. No conflicts are known. Not verified here: the test suite, the seeded mutations and check:affected were not run, and regression validity was judged by reading the base code path. Not verified here: the 0.21.28 client cut-off against release history, whether local macos-app leased sessions use the artifacts command or Before merge, the five problems above need fixes, and the checks that are still running need to finish green. |
400ff5d to
ac4f9b2
Compare
|
Reply to #4945 (comment). Head is now ac4f9b2, rebased on 0.22. The five problems
Taken from the optional list: Not taken: a separate lease-output module. A new module in the daemon's eager import closure fails the closure budget, so the code stays in Side effect: files under Tests: seven seeded mutations each fail a test. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on ac4f9b2. The verdict and the full list are in the summary comment.
| export function claimRequestDiagnosticsRecord(req: Pick<DaemonRequest, 'flags' | 'meta'>): void { | ||
| const leaseId = resolveLeaseScope(req).leaseId; | ||
| // A lease id that reaches a message, and not a lease field, is removed from the record too. | ||
| const canonical = normalizeLeaseId(leaseId); | ||
| if (leaseId !== undefined && canonical) { | ||
| registerDiagnosticSensitiveValue(canonical); | ||
| registerDiagnosticSensitiveValue(leaseId.trim()); | ||
| } | ||
| if (getDiagnosticsMeta().recordId) return; | ||
| const owner = leaseId === undefined ? UNLEASED_RECORD : leaseVerifier(leaseId); | ||
| updateDiagnosticsScope({ recordId: `${crypto.randomBytes(16).toString('hex')}-${owner}` }); | ||
| } |
There was a problem hiding this comment.
No longer raised on 639973d: marked fixed in 93c51bb by thymikee in this comment; the code it pointed at changed.
🆕 🟡 Minor · A non-hex lease id is registered as no sensitive value, so it stays in the record
A lease id that is not 16–128 hex digits — or whose text leaks into a field key the fingerprinter does not recognise, such as a releaseId-style key or free-form message text — is written to the diagnostics record verbatim because claimRequestDiagnosticsRecord only calls registerDiagnosticSensitiveValue when normalizeLeaseId accepts the id. The owner still comes from the raw id, so the record exists and is served with the sensitive text intact.
Suggested change
Register the raw and trimmed lease id as a sensitive value whenever leaseId !== undefined, independently of whether normalizeLeaseId accepts it, so a non-canonical lease id is still redacted from the record it owns.
Details
persona: javascript, 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 93c51bb: the record now registers the trimmed lease id as sensitive whenever one is sent, and the canonical form too when it is valid. No test: a malformed id never reaches a record field on the paths a test can drive, so a test passes with or without the fix.
| const owner = diagnosticsRecordOwner(ref.requestId); | ||
| const presentedLeaseId = req.headers[DAEMON_HTTP_LEASE_HEADER]; | ||
| const presented = typeof presentedLeaseId === 'string' ? presentedLeaseId : undefined; | ||
| if (owner !== null && !requestHoldsOutputLease(owner, presented)) { | ||
| sendRestJsonError(res, normalizeError(leasedOutputRefusal('Diagnostics record'))); | ||
| return; | ||
| } | ||
|
|
||
| const recordPath = resolveRecordPath(ref); | ||
| const stats = await statRecord(recordPath); | ||
| // A record of unknown ownership, such as one that an earlier release wrote, is not served. | ||
| const stats = owner === null ? null : await statRecord(recordPath); |
There was a problem hiding this comment.
No longer raised on 639973d: marked fixed in 93c51bb and ac4f9b2 by thymikee in this comment; the code it pointed at changed.
🆕 🟡 Minor · A record an earlier release wrote is answered 401, not 404, when any lease id is sent
A legacy locator (e.g. /sessions/s/requests/abc123/diagnostics) sent with the x-agent-device-lease-id header returns 401 LEASE_OUTPUT_MISMATCH instead of 404. requestHoldsOutputLease returns true for an undefined ownerVerifier, so the owner !== null guard that would yield 404 is never reached when a lease id is present.
Suggested change
Check owner === null before the lease verification so that every record whose owner the daemon cannot name returns 404 regardless of whether a lease id is sent.
Details
Also raised here
Also raised at this location by persona maintainability: Unknown diagnostics owner decides its 404 in two places — A diagnostics record id the daemon did not choose is refused in two steps: diagnosticsRecordOwner returning null suppresses the stat in a null-as-sentinel ternary, and the shared !stats branch then produces the not-found error. The lease guard above already treats null specially, so the next reader has to check both places to learn what an unknown name does. Fold the null case into the guard above and keep the existing not-found error it sends, so one branch decides that outcome.
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.
There was a problem hiding this comment.
Fixed in 93c51bb. On ac4f9b2 a legacy locator already answered 404: diagnosticsRecordOwner returns null for it, which skipped the lease check. The maintainability point holds, so an unknown owner now returns the not-found error in one early branch. The legacy-record test now sends the request with and without a lease header.
This comment has been minimized.
This comment has been minimized.
|
Several findings from the earlier review (#4945 (comment)) are fixed at 639973d: the lease-blind artifact lookup, the owners file, the Two user-doc sentences now name the diagnostics file by the request id, but the daemon names it by the record id (request-execution-scope.ts#L276, session-artifact-paths.ts#L50-L57). sessions.md#L49 tells the reader to look in A second independent pass found that an earlier screenshot ID can serve a later lease's bytes (artifact-tracking.ts#L339). A direct static-token daemon without an auth hook accepts explicit screenshot destinations. An unleased screenshot registered through A second independent pass found the same problem for xctrace directories (artifact-tracking.ts#L285). A stop under another lease can target an existing published directory (session-perf-runtime.ts#L296-L299). The rename falls back to a recursive copy into it (perf-xctrace.ts#L171-L175), so the inode stays the same and the earlier ID still passes the check. Its GET then packages the new contents. The rule: an ID is bound at publication to a distinct daemon-owned directory or a sealed archive, so later writes to the caller-visible directory cannot change what the ID serves. A second independent pass found that looking up a stale artifact can delete a newer caller-owned screenshot (artifact-tracking.ts#L396). Register an unleased screenshot at an explicit path, then write a replacement to the same path without A second independent pass found that an old leased diagnostics record can pass as a new unleased one (request-diagnostics-http.ts#L143). The base accepted caller-chosen tracking IDs as filenames, so a legacy leased record can have a name that matches the new unleased format. After an upgrade with the same state directory, the head treats that name as explicitly unleased (artifact-tracking.ts#L100-L103) and streams the record to an authorized reader without its lease ID. The rule: new records resolve only in a daemon-owned namespace separate from legacy files, or carry persisted provenance that the legacy writer could not have supplied. A second independent pass found the opposite upgrade gap in the same file (request-diagnostics-http.ts#L145). An unleased failure record written before the upgrade was fetchable through its locator on the base. At the head the same request gets 404, because the filename has no owner suffix. Legacy records with trusted evidence of unleased production should stay readable, through migration or a provenance-aware read. Records with ambiguous ownership should stay closed. A second independent pass found that a routed batch step can append leased diagnostics to an unleased record (artifact-tracking.ts#L84). Send a batch without a lease to a fresh named session, and give its open step an active lease. Step flags are kept (batch.ts#L268-L278), and the step inherits the batch record ID (diagnostics.ts#L88-L102). The claim returns early, so the step writes into the batch's unleased file. The rule: a child reuses its parent's record only when their effective lease owners match; otherwise it claims its own record. A second independent pass found that completed direct-HTTP recordings from the base can be republished without their lease (record-runtime.ts#L515). On the base, a leased recording with a client destination and no daemon path used the downloadable remote temp path, and its manifest had neither A second independent pass found that an unleased recording can take the session's later lease at publication (request-finalization.ts#L102). Start an unleased remote recording in a named session, then open the same session and device under an active lease. Open keeps the recording and attaches the lease (session-open-state.ts#L52-L62). On record stop, the explicit unleased marker becomes undefined (record-runtime.ts#L511-L512), so finalization uses the stop request's lease. Close and release do the same through leased-recording-retention.ts#L28-L41. The explicit-unleased owner should survive response finalization, teardown should register with the recording's stored owner, and the request's lease should apply only when the producer made no ownership decision. A second independent pass found a replay gap for recordings that finished before the upgrade (record-runtime.ts#L515). The base manifest stored Not blocking, and these can be taken or left: when an identity mismatch cleans up a registered output, the entry should be dropped without unlinking the path, or the source removed only if it still matches None of the open inline threads from other reviewers still applies. These can be resolved: the lease-blind reverse lookup is gone because the lookup now matches tenant, verifier and output (#4945 (comment)); the record owner now comes from the lease id the request sent (#4945 (comment)); the owners file was deleted (#4945 (comment)); Not verified here: tests, seeded mutations and check:affected were not run. Regression validity was judged by reading the earlier test commit against the new tests. A batch step carrying a lease id different from its parent's was judged from the fill-unset rule only. The timing window between a capture write and its registration was judged from code, with no live attempt. Parts outside this delta were not re-traced. Before merge, fix the request-id wording in sessions.md:49 and debugging-profiling.md:149-150 so every record file mention names the record id. Then address the diagnostics, artifact and recording findings above, and re-run CI. |
|
Addressed the six findings in
The final head passed 280 focused tests, 950 eager-closure tests, 52 wire tests, the released wire compatibility check, typecheck, lint, and Fallow. The full affected rerun was queued behind the shared validation lock at push. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The smoke-test failures from the earlier review are fixed, but 9a83b71 still lets unleased output leak or be misowned in three places, and a second independent pass found six more. There are no conflicts. The only check not passing is Body rules, which was cancelled rather than failed and looks unrelated to the diff. Before merge, the three findings below need fixes, and the later ones need an answer. Every remote screenshot against a direct static-token daemon leaves a PNG in the host's /tmp. The client sends a generated remote-temp The recording producer marker now owns the whole response. In request-finalization.ts:117, Unleased recording exports lose the base tenant fallback. At request-finalization.ts:105, an unleased producer with no stored tenant registers the export with an undefined tenant, and artifact-tracking.ts:577 serves such an entry to every reader. On base, the stop request's tenant was used. A recording that a tenant-labelled stop finalizes is now downloadable for every tenant and for callers with none. leased-recording-retention.ts:34 dropped its fallback to A second independent pass found that request-diagnostics-http.ts:146 cannot serve verified legacy records with reserved-format names. Base accepts caller request IDs that match the new generated format. An operator who moves a verified record to requests-unleased under its original name, as the lease-contracts doc says, cannot restore access when the ID ends in the unleased marker or a 64-hex verifier. The first looks only in request-records and returns 404, and the second can return a lease refusal before any file is checked. Honor the verifier of an existing current record, and otherwise look for the exact name in the host-verified legacy directory regardless of its format. A second independent pass found that record-runtime.ts:464 can register replacement bytes under the original owner. Two sessions on different devices can share an explicit remote-temp recording destination over direct static-token HTTP. Complete an unleased recording, then a leased one to the same destination. Android copies the new export over the path, and a repeat stop of the unleased session validates only the original manifest and that the path exists. It then registers the replacement under an unleased ID. Give direct-HTTP downloadable recordings a daemon-owned per-capture export path before the video, chunks and telemetry are written, and require verified byte provenance for older exports on reusable paths. A second independent pass found that artifact-tracking.ts:344 validates a pathname before it opens the file. The identity check at lines 435-446 can pass while the original export is present, then another session's leased recording can replace the output before the stream opens. The handler can send the replacement's bytes under the original artifact ID. For replaceable producer paths, serve a daemon-owned per-capture copy. For file downloads, validate the identity of the opened file and stream from that same handle. A second independent pass found that trace-runtime.ts:85 can publish leased diagnostics to an unleased reader. On a static-token daemon, an unleased named session can run a public-network command under a valid scoped lease without attaching it to the session. A trace started under that lease collects leased events, and a same-tenant stop without a lease registers the trace with no verifier. Starting the trace unleased also lets a later leased request append before an unleased stop. Keep the trace's producer owner from start through registration, refuse a stop under the wrong lease, and attach diagnostics only when the request and trace owners match. A second independent pass found that session-perf-runtime.ts:331 assigns a perf capture to whoever stops it. Start a native perf capture under a valid scoped lease in an unleased named session. Start persists the path and tenant with no producer verifier, so a same-tenant request can stop it without the lease, and the artifact takes that stop request's owner in request-finalization.ts:100-117. The route is shared by xctrace, Perfetto and simpleperf, and the inverse case registers an unleased capture under a later stop lease. Persist the producer verifier or explicit unleased owner with the capture, check it before stopping, and pass it to artifact registration. A second independent pass found that session-perf-runtime.ts:174 lets a report read a leased profile without the lease. Start and stop a CPU profile under the same scoped lease in an unleased named session. The profile stays in Would it be simpler to let Not blocking: the plugin-host managed-process test fix in plugin-host.test.ts:69 (try/finally and Of the other open threads, none are high-priority and all six no longer apply, so they can be resolved. Same-path registration: the tracker matches tenant, verifier and output, so a leased registration of the same path gets its own id by design. Record owner: it comes from the lease id the request sent, not the session lease (artifact-tracking.ts:76). Owners file: the file is gone, and nested steps reuse the parent record only on an owner match. owners.every(): it is deleted, and a record has one owner encoded in its id. Sensitive lease id: the trimmed canonical id is registered as a sensitive value. Unminted ids: an id the daemon did not mint is read only from requests-unleased, and an absent file returns 404. Not verified here: no tests, seeded mutations or check:affected were run. Every finding comes from reading the code against base and the earlier head. |
|
Addressed the findings in
I kept publication in the producers because a registration-time copy runs after the producer can lose control of a reusable path. A hard link also shares the source inode. Finalization selects the admitted owner for delivered artifacts and the stored producer for capture output. Unit-core, focused tests, eager closure, wire compatibility, typecheck, lint, Fallow, and package verification passed. The affected run was still queued at push after 15 minutes of cumulative lock wait. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 34b6b2c. The verdict and the full list are in the summary comment.
| ): DaemonResponse { | ||
| const session = sessionStore.requireCurrent(ref); | ||
| if (!session.trace) return errorResponse('INVALID_ARGS', 'no active trace'); | ||
| const owner = session.trace.leaseVerifier ?? null; | ||
| if (owner !== admittedOutputLeaseVerifier(req)) throw leasedOutputRefusal('Trace'); | ||
| updateDiagnosticsScope({ traceLogPath: undefined }); |
There was a problem hiding this comment.
No longer raised on f307a48: marked fixed in f307a48 by thymikee in this comment; the code it pointed at changed.
🆕 🟡 Minor · trace stop compares verifiers exactly, so an unleased trace can never be stopped under a lease
A trace started with no lease stores no verifier, so once the session holds a lease every stop request presents one and the exact comparison refuses it with LEASE_OUTPUT_MISMATCH. The throw happens before session.trace is cleared, so the session keeps a trace that blocks every later trace start. The strict check contradicts the rule artifact-tracking documents and perf runtime applies, namely that output with no lease has no lease rule.
| ): DaemonResponse { | |
| const session = sessionStore.requireCurrent(ref); | |
| if (!session.trace) return errorResponse('INVALID_ARGS', 'no active trace'); | |
| const owner = session.trace.leaseVerifier ?? null; | |
| if (owner !== admittedOutputLeaseVerifier(req)) throw leasedOutputRefusal('Trace'); | |
| updateDiagnosticsScope({ traceLogPath: undefined }); | |
| const owner = session.trace.leaseVerifier; | |
| if (owner && owner !== admittedOutputLeaseVerifier(req)) throw leasedOutputRefusal('Trace'); |
Details
Also raised here
Also raised at this location by persona senior-developer: trace stop on pre-upgrade session state refuses a leased reader with LEASE_OUTPUT_MISMATCH — A session that already holds a trace written by an earlier release has no leaseVerifier field, so stopTrace compares null (the absent-owner side of the new check) against the verifier of the stop request's admitted lease and throws LEASE_OUTPUT_MISMATCH: an upgraded daemon refuses trace stop for exactly the leased caller that started the trace before the upgrade, and the trace file stays open with no way to close it under that lease. The record-based paths in this PR (recording, perf) treat an unknown stored owner as "no lease rule" or fall back; here an absent field is read as an unleased producer. Consider treating leaseVerifier === undefined as unknown ownership that only an unleased or matching-lease request may stop, or documenting the upgrade requirement in remote-device-lease-contracts.md.
persona: javascript, 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 f307a48ef7. The producing lease is required when the trace was leased. A session caller can stop a trace that began unleased, and the download keeps its unleased owner. The loopback regression failed at stop before the fix and now passes.
| @@ -197,7 +205,8 @@ async function executeAdmittedPerfPlan( | |||
| data: withCaptureOutputOwnership( | |||
There was a problem hiding this comment.
No longer raised on f307a48: marked fixed in f307a48 by thymikee in this comment; the code it pointed at changed.
🆕 🟡 Minor · perf report's download is registered under the retained capture's tenant, not the requester's
When a second tenant runs perf cpu profile report over another tenant's stopped capture, the report registers under the capture's retained?.tenantId, so the caller who produced it cannot download its own artifactId while the other tenant can. Passing retained?.tenantId alone drops the request-tenant fallback that request-finalization relied on. Captures that recorded no tenant are unaffected: the value stays undefined and finalization still falls back to the request tenant.
Suggested change
data: withCaptureOutputOwnership(
{ perf: 'reported', ...data },
params.req.internal?.publicNetworkOnly ? 'daemon' : 'caller',
retained?.tenantId ?? params.req.meta?.tenantId,
retained?.leaseVerifier,
),
Details
Also raised here
Also raised at this location by persona senior-developer: profile-report no longer carries the requesting tenant for an unleased capture — profile-report now passes retained?.tenantId (the tenant stored at stop time) to withCaptureOutputOwnership, where the predecessor used session.lease?.tenantId ?? params.req.meta?.tenantId. For a profile stopped before this change, or one stopped with no tenant in metadata, the report artifact is registered with no tenant at all and becomes readable by any tenant that can reach the download route rather than by the tenant that ran the request. Keeping the request-tenant fallback when retained?.tenantId is undefined preserves the old scoping.
persona: javascript, 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 f307a48ef7. The retained profile keeps its lease check for source access. The new report is registered for the requester’s tenant and admitted lease. The loopback regression now downloads successfully with that lease and refuses the same tenant without it.
This comment has been minimized.
This comment has been minimized.
|
At f307a48, the two earlier trace-stop and perf-report findings from the 9a83b71 review are fixed, but four defects remain. All 17 checks pass at this commit. Not verified here: any behavior by running it, because no tests, mutations or A second independent pass found that an ID-only stop loses the session tenant for an unleased recording (record-runtime.ts:498). On a static-token daemon, start a downloadable recording in an unleased named session with no tenant label, then reopen that session under tenant A's lease. The reopen keeps the recording (session-open-state.ts:52-62). A stop with only the lease id now stores no tenant, and request-finalization.ts:103 falls back to the absent request tenant. The base used A second independent pass found that direct HTTP recordings change an explicitly extensionless client filename (record-runtime.ts:386). Against a static-token direct HTTP daemon without a network marker, start an unleased Android recording with the client destination A second independent pass found that unleased downloadable traces lose replay timing events and Apple runner output (trace-runtime.ts:58). In an unleased session reached through a public-network HTTP request, start a downloadable trace and run an A second independent pass found that a retained leased profile blocks an xctrace report on an unrelated explicit source (session-perf-runtime.ts:178). In a named Apple session without a bound lease, start and stop xctrace under a scoped lease so Not blocking, and these can be taken or left: a remote trace now has no Could one No high-priority threads from other reviewers still apply, and no lower-priority threads still apply. These eight threads do not apply and can be resolved. The tracker reuses an id only for the same tenant, verifier and output identity, so a leased registration gets its own id by design (#4945 (comment)). The record owner comes from the lease id the request sent, not from the session lease (#4945 (comment)). The owners file is gone, and the owner is encoded in the record id (#4945 (comment)). Before merge, the four findings above need fixes, and the checks need to pass again on the new head. Live validation should reach each route named above and show the tenant, filename, trace events and report source it describes. |
|
Addressed the four findings in the review at
All six regression cases failed with the relevant fixes disabled. The amended head passed 322 focused tests, wire compatibility, 1,002 wire and eager-import tests, typecheck, lint, and Fallow. The packed-core checks passed before the final test-only amendment, and clean-install snapshot-bridge verification passed. The final affected run is queued behind the shared validation lock. |
This comment has been minimized.
This comment has been minimized.
…eir lease id Output of a request that acted under a lease keeps that lease as its owner. Artifact inventory and download (HTTP and the artifacts RPC) and the request diagnostics route give it only to a request that sends the lease id, for as long as the daemon keeps the output, also after the lease ends. The proxy forwards the lease header, REST errors carry details.field, and the CLI sends the ended proxy lease id on artifacts. Closes #4912
…dings to their lease A request diagnostics record gets its owners before its first byte: the lease id that the request sends and the lease of the session at its address. They are kept beside the record as SHA-256 verifiers and never served. Diagnostics name a lease by a fingerprint, except in the host-only daemon log. A recording manifest keeps the verifier of the lease that started it, and record stop checks it. The request_lease line and its parser are gone.
…iagnostics record The lease of the session at the request's address is no longer an owner. A request without the session lease id never acts on a leased session, and a record never holds a raw lease id, so each caller reads only its own records. The record claim moves to the request router; request-execution-scope.ts is unchanged from the base.
- An artifact id serves only the output that it registered. Another capture written to the same path gets its own id, and the earlier id expires. - The daemon names each request diagnostics record. The name carries the owner, so a record has one owner or none, and the owners file is gone. The caller's request id names no record. A record that an earlier release named is not served. - A recording manifest names its lease, or that it has none. A completed export replays to a request that sends that lease id, with no active lease, and stays with that lease when it is registered. A remote export of unknown ownership is not replayed.
…own records 404 in one place
…e's wire acknowledgment
a141e04 to
b2e982f
Compare
|
Rebased on |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on b2e982f. The verdict and the full list are in the summary comment.
| case 'profile-report': { | ||
| const runtime = await bindDevice(device, plan.use); | ||
| const last = session.lastPerfProfile; | ||
| const tracePath = plan.request.tracePath ?? last?.outPath; | ||
| const cwd = requestCwd(params.req, params.host); | ||
| const explicitPath = plan.request.tracePath && expandSessionPath(plan.request.tracePath, cwd); | ||
| const saved = session.lastPerfProfile; | ||
| const retained = | ||
| plan.request.kind === 'xctrace' && | ||
| explicitPath && | ||
| saved && | ||
| !samePerfSource(explicitPath, saved.profile.outPath) | ||
| ? undefined | ||
| : saved; | ||
| const tracePath = explicitPath || retained?.profile.outPath; | ||
| assertPerfOutputOwner(params.req, retained?.leaseVerifier); | ||
| const last = retained?.profile; | ||
| if (!tracePath) { | ||
| throw new AppError( | ||
| 'INVALID_ARGS', |
There was a problem hiding this comment.
No longer raised on ce3c247: marked fixed in ce3c247 by thymikee in this comment; the code it pointed at changed.
🆕 🟡 Minor · A caller-chosen tracePath skips every lease check in perf report and reads any host path
A request that sends no lease id (or another lease's id) with an explicit tracePath on a session whose retained profile is owned by lease A gets the report: retained becomes undefined because the explicit path differs, so assertPerfOutputOwner(req, undefined) never refuses and the handler reads any directory. When the retained outPath equals the explicit path or they symlink each other (accepted by samePerfSource via dev/ino), retained is kept, making only that capture's lease owner the gate on a caller-chosen path. samePerfSource throws because statSync(path, { throwIfNoEntry: false }) still rejects ENOTDIR when a parent segment is a file and ENOENT for a dangling symlink, escaping as COMMAND_FAILED instead of INVALID_ARGS.
Suggested change
Gate the report on the source: when the explicit tracePath is not the retained capture, check the request against the lease that produced that path (or refuse an explicit path outside the session's own artifacts) before invoking the runtime. Pass a null-ish entry to statSync or wrap samePerfSource so an unreadable path yields the existing INVALID_ARGS.
Details
Also raised here
Also raised at this location by persona maintainability: samePerfSource lets a stat failure abort perf report with a raw fs error — perf report cpu <path> out.json where <path> cannot be stat'ed for a reason other than a missing entry — permission denied on a parent directory, or a symlink cycle — now fails with the raw EACCES/ELOOP filesystem error instead of the command's typed error. The new samePerfSource calls statSync(explicitPath, { throwIfNoEntry: false }), and that option only swallows a missing entry; every other stat failure propagates out of executeAdmittedPerfPlan. The comparison is a heuristic for "is this the retained capture", so a stat failure should fall back to "not the same source" rather than abort the report; wrap both stats (or the whole helper) so only a successful pair compares.
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.
There was a problem hiding this comment.
Fixed in ce3c247f0b. Public-network and tenant-scoped requests that supply tracePath receive REMOTE_HOST_INPUT_DENIED before runtime admission. Local reports check retained xctrace sources by canonical path and file identity, including older sources whose session handoff has since changed. The loopback regressions cover requests with no lease and with a different lease.
| @@ -197,7 +215,7 @@ async function executeAdmittedPerfPlan( | |||
| data: withCaptureOutputOwnership( | |||
There was a problem hiding this comment.
No longer raised on ce3c247: marked fixed in ce3c247 by thymikee in this comment; the code it pointed at changed.
🆕 🟡 Minor · Perf report of a retained capture registered with no tenant, so only a tenant-less reader can get it
A capture taken and stopped under no lease, then reported under no lease, is registered with no tenantId because withCaptureOutputOwnership reads params.req.internal?.admittedLease?.tenantId (undefined), so any tenant can download the report. The reverse case fails closed: an unleased capture stopped under tenant-a's lease is registered with tenant-a, blocking a tenant-less report request with 401.
Suggested change
Register the report under the producer's tenant (req.meta?.tenantId) as other capture paths do, and use the lease verifier of the retained profile.
Details
persona: javascript
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 ce3c247f0b. The report registers under the requester’s tenant and admitted lease. For a request without a lease, the daemon also reads the tenant from the request’s lease scope. The regression verifies that the requester can download the report and that a different tenant or a tenant-less reader receives 401.
|
The four earlier findings from the f307a48 review are fixed at b2e982f, but a second independent pass found six remaining defects, so this needs another change before merge. 17 of 18 checks pass. The one other check is still running and covers no test route, so no failure here comes from this diff. A second independent pass found that a scoped lease produces a daemon-owned xctrace CPU capture, and stop keeps its source for later reports (session-perf-runtime.ts:180). On direct HTTP with the static credential, a report from a different unleased Apple session can name that source through tracePath, and the verifier comes only from the current session's latest handoff. The Apple backend then returns the leased trace's sample summary without the producing lease. The rule: every retained daemon-owned source records the verifier that produced it, and an explicit xctrace report checks the resolved source and its file identity against that verifier, whatever the session's latest handoff is. A second independent pass found that perf stop drops the base tenant fallback for an unleased capture (session-perf-runtime.ts:318). Start a downloadable native perf capture with no tenant on a named unleased session, reopen that session under tenant A's lease (which keeps perfCapture), then stop with only the lease id. Base bdf5096 used the session lease tenant. At this head the capture registers with no tenant and no lease verifier, so readers outside tenant A can list and download it. The rule: finalization falls back from the stored capture tenant to the session lease tenant before it applies the request tenant, and keeps the explicit unleased verifier. A second independent pass found that closing a session changes the tenant of a retained unleased recording (leased-recording-retention.ts:34). Tenant A starts an unleased downloadable recording on a named session, tenant B reopens it on the same device under B's lease, and B closes the session before record stop. The base teardown registered the export for B. The head registers it for A, so B's inventory after close loses a recording it received before. The rule: an explicitly unleased producer keeps the session lease tenant that the base teardown route used, and leased recordings use the producing verifier and stored tenant. A second independent pass found that unleased caller-owned traces lose Apple runner output while the trace is still active (diagnostics.ts:107). The runner writer now captures the launch request's scope, and that scope closes when the interaction returns. Later runner output reaches runner.log but not the open trace, where the base kept appending until the runner ended. The rule: a caller-owned unleased trace keeps its runner writer for the life of the same active trace and stops it when the trace or session ownership changes. The request-scoped limit stays for downloadable traces. A second independent pass found that an unleased explicit xctrace report loses the template field (session-perf-runtime.ts:181). Stop an unleased CPU capture, then report on another explicit trace in the same session without a template. The base returned the saved capture's template. The head discards the unleased handoff and passes no template, so the returned and written report omits it. The rule: an unleased saved xctrace handoff keeps the base template fallback, and only a leased handoff and its template are discarded when an independent source is chosen. A second independent pass found that a non-string RPC lease claim escapes the typed lease refusal (artifact-tracking.ts:102). The RPC schema only checks that meta is an object, so a numeric meta.leaseId reaches the new diagnostics code, which calls trim before admission and outside the router's error handler. HTTP then returns a generic exception where the base returned UNAUTHORIZED with LEASE_SESSION_MISMATCH. The rule: only string lease claims name and redact the diagnostics record, and the existing admission check handles the original malformed value. No open inline thread from other reviewers still applies. These eight do not apply and can be resolved: #4945 (comment) (an id is reused only for the same tenant, verifier and output, so a leased registration gets its own id by design), #4945 (comment) (the lifecycle stamp is gone at head), #4945 (comment) (the owners file is gone and the owner is in the record id), #4945 (comment) (owners.every() is deleted and a record has one owner), #4945 (comment) (both the trimmed and canonical lease id are registered as sensitive), #4945 (comment) (an unminted name is read only from unleased requests and a missing file returns 404), #4945 (comment) (trace stop under a lease was fixed at f307a48), #4945 (comment) (the perf report uses the requester's lease and tenant). Not verified here: any test, mutation or check:affected run, and whether each new test fails at f307a48. Every finding above comes from reading b2e982f against f307a48 and base bdf5096. Before merge, fix the six findings and wait for the one other check to finish. |
|
Addressed the four requested findings from the maintainer review in
The regressions failed against the earlier behavior. All 216 focused tests, 1,000 wire and eager-closure tests, wire compatibility, typecheck, lint, and Fallow passed. The earlier affected run passed with packaging. The final affected run is queued behind the shared validation lock. |
Apex Sentinel · ✅ Approve · review of
|
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
Summary
Bind downloadable captures and diagnostics to their producing lease through retention (#4912). Screenshots, xctrace results, remote recordings, and remote traces use daemon-owned paths. Downloads validate the opened file descriptor. Stale cleanup preserves replacements.
Recording stop and teardown preserve the producing lease and recover a missing tenant from the session. Direct HTTP keeps the supplied recording filename. Delivered scripts use the admitted lease. Remote perf reports use the retained capture. Local xctrace reports check source ownership by path and file identity. Reports belong to the requester. Perf stop falls back to the session lease tenant. Unleased recording teardown uses the session lease tenant. Apple runner output follows the trace lifetime for active unleased caller-owned traces.
Diagnostics use daemon-generated record IDs. A current record takes precedence over a verified legacy file with the same name. Verified unleased recordings in session storage can replay. Legacy exports on reusable remote temp paths are refused.
Breaking for callers that omit the producing lease ID and for clients older than 0.21.28.
Before / after
GET /artifacts/<id>without the producing lease returns 401 instead of 200.record stoprefuses ambiguous remote exports.Validation
At
ce3c247f0b, 216 focused tests, 1,000 wire and eager-closure tests, wire compatibility, typecheck, lint, and Fallow passed. All 43 runnable affected checks passed, including packed-core verification.Closes #4912