Repository navigation
fix(daemon): recover provider rental fences after restart - #5052
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: 1 new finding on ac19dde. The verdict and the full list are in the summary comment.
|
Review of ac19dde found one regression in lease-registry.ts:141 runs The real Limrun create request now carries a new A second independent pass found that Revyl can clear a rental using a 404 from a different backend. Start an embedded daemon with A second independent pass found a second Revyl gap at runtime.ts:304. A second independent pass found that a failed exact-id write does not stop allocation (provider-rental-journal.ts:145). The scope and key writes succeed and the provider returns an exact id. Then the journal rewrite fails with ENOSPC, and A second independent pass found that existing recovery is lost for providers that implement only A second independent pass found that a transient journal write error can turn a confirmed release into a permanent fence (provider-rental-journal.ts:155). A WebDriver provider without restart recovery confirms session deletion, but removing the rental record fails. Not blocking, and they can be taken or left: key-only entries are fenced forever when the crash lands between reserve and Could the journal be smaller? One option is to make Not verified here: the real Limrun API's handling of the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@apex-sentinel-staging review |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 5d8393b. The verdict and the full list are in the summary comment.
|
All six code problems from the earlier review are fixed at 5d8393b. Three problems remain, and one needs a live run. Every Limrun create now carries a A second independent pass found a stuck fence in lease-registry.ts:903. Close a session on a journaled provider lease and pause the provider stop after close moves the lease to Ending. Send a concurrent authenticated A second independent pass found that recovery proof can come from a different account in daemon-composition.ts:203. Register a third-party recovering provider with the stable module owner instance Not blocking, and these can be taken or left: no test covers the production The two earlier inline threads no longer apply and can be resolved. The legacy-only recovery thread is fixed: the rental now carries The only failing check is Body rules, which lints the PR description and not code. No file in the diff is on that route. The second run was cancelled by a later run, so the check still fails until the body passes. One possible cause is that the Not verified here: the real Limrun API's handling of the label and selector for create, list and delete; whether Revyl |
This comment has been minimized.
This comment has been minimized.
|
Both code blockers from the earlier review (5d8393b) are fixed at 9a4aef3, but the live Limrun check is still missing, and a second pass found three new problems. The earlier request is unchanged: restart recovery and cleanup of a lost create depend on the real Limrun list API selecting A second independent pass found that provider-lease-expiry.ts:582 can lose a retirement on shutdown. Let a journaled lease expire and hold its provider stop in flight until shutdown enters A second independent pass found that plugin.ts:74 can make instance attachment fail. Start with valid iOS or Android instance access plus A second independent pass found that runtime.ts:234 can retire a live rental fence. Run Limrun through a gateway set by The two resolved-benign inline threads (#5052 (comment) on identity-free journal restore, #5052 (comment) on fail-closed startup) do not apply, so the author can resolve them: the first is an intentional release-unknown fence, and the second is deliberate to avoid overlapping allocations of rentals that may still bill. The remaining check is 'Body rules', which was cancelled as superseded. It lints the PR description, not code, and no file in the diff is on that route, so it looks unrelated. It still blocks merge until a run on the current body passes. No conflicts. Hosted unit and integration checks are green at 9a4aef3. Not verified here: tests were not run locally, the new daemon and composition tests were read but not executed, and real Limrun behavior for the label, list selection and exact DELETE needs credentials. The next step before merge is the live Limrun run above, plus fixes for the three new findings. |
This comment has been minimized.
This comment has been minimized.
|
@apex-sentinel-staging review |
This comment has been minimized.
This comment has been minimized.
|
Review of 798a059: one regression in the restart principal needs a fix, and the live Limrun run is still missing. The earlier request at 9a4aef3 for a live run is not met yet. The only check not passing is "Body rules", which was cancelled as superseded after a body edit; no file in the diff is on that route, but a run on the current body must pass before merge. Not verified here: tests were not run locally, and the SDK header behavior was read from the @limrun/api 0.69.1 package source, not observed in a running process. The principal now hashes every header the SDK builds, not just the account and origin (runtime.ts:236). Those headers include User-Agent (agent-device version and SDK version), X-Stainless-Package-Version, X-Stainless-Runtime-Version (process.version), X-Stainless-OS/Arch and X-Stainless-Timeout. They change with the agent-device, SDK or Node version, not with the account. A journaled rental survives a crash or a version-mismatch takeover whose provider stop does not confirm in the 2 s drain. The next daemon then runs on a new version, and provider-rental-journal.ts:117-118 sees a different principal. canRecover returns false, the rental is marked release-unknown, and it is never retried. The Limrun instance keeps billing, and overlapping lease_allocate stays refused until the exact old versions run again or someone edits provider-rentals.json. This is a regression from the base and from 9a4aef3. The rule: the principal changes only when the account or origin that the DELETE reaches can change. Derive it from baseURL, the built Authorization header and the effective custom headers (the parsed LIMRUN_CUSTOM_HEADERS), and nothing generated by the SDK. The principal test should also change clientVersion and a stubbed User-Agent or SDK version header, and expect the same principal. The current test always uses clientVersion "test-version" on one Node version, so it cannot catch this. A second independent pass found the same problem from the Node side (runtime.ts:237). With identical API key, API URL and custom headers, the lockfile SDK and this digest gave different principals under Node v26.11.1 and v26.13.1. The journal then rejects the match, and provider-lease-expiry.ts:267-275 skips the exact-ID recovery. The same fix covers it: exclude generated SDK headers unless the operator configured them explicitly, so routing overrides stay bound. Restart recovery and lost-create cleanup depend on the real Limrun API: listing by the rentalKey label, exact-instance DELETE, and the SDK-built principal at plugin setup (runtime.ts:231). Every test mocks @limrun/api, and hosted CI cannot detect a rejected label or an unstable principal. Before merge, after the fix above, attach a run on real Limrun credentials. (1) Allocate a lease, and show provider-rentals.json with reconciliationKey and a principal- rentalRecoveryPrincipal before the create, and with instanceId after it. (2) SIGKILL the daemon once instanceId is recorded, restart with the same credentials, and show the DELETE of that exact instance and an empty rentals array. (3) Allocate again, SIGKILL, remove instanceId from the entry, and restart. Show the list call with provider=limrun,rentalKey= finding one instance, the id being recorded, the DELETE, and an empty array. Attach the journal snapshots and the provider_rental diagnostics. The two open inline threads (identity-free journal entry fence, fail-closed startup on an invalid journal) no longer apply: both behaviors are deliberate and unchanged by this delta, so they can be resolved. #5052 (comment) #5052 (comment) Next, make the principal ignore SDK version, Node and User-Agent headers, then attach the live SIGKILL and restart run. |
This comment has been minimized.
This comment has been minimized.
|
@apex-sentinel-staging review |
This comment has been minimized.
This comment has been minimized.
|
The principal problem from 798a059 (#5052 (comment)) is fixed at b235a02, but the new principal derivation has header-source gaps, and the live Limrun run is still missing. Hosted unit and integration checks are green. The only check not passing is "Body rules", which lints the PR description. No file in this diff is on its route, so it looks unrelated, but the body must pass it before merge. There are no conflicts. Restart recovery and lost-create cleanup depend on real Limrun behavior that every test mocks: listing by the A second independent pass found that the principal takes header names from A second independent pass found that host-only header names also reach the digest (runtime-instance.ts:56). With the same embedded host and no ambient A second independent pass found that a host-only malformed header can stop Limrun from registering (runtime.ts:241). Start an embedded daemon with a valid host API key and The two open inline threads on provider-lease-expiry.ts (#5052 (comment)) and on fail-closed startup (#5052 (comment)) were resolved without a change and need no further work. Both are intentional: the identity-free journal entry is a release-unknown fence, and an invalid journal stops startup to avoid overlapping allocations while rentals may still bill. Not blocking, and these can be taken or left: the first header-source gap above could also be closed by passing the parsed Not verified here: tests were not run, and the SDK header-merge order and env parsing were read from a locally installed @limrun/api 0.49.3 rather than the pinned 0.69.1. Real Limrun label selection, exact DELETE and principal stability across a restart were not observed. |
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 three code problems from the earlier review (#5052 (comment)) are fixed at 65166c0. One problem remains: the restart recovery has no live proof yet. Restart recovery and lost-create cleanup depend on real Limrun behavior that every test mocks (https://github.com/callstack/agent-device/blob/65166c0/packages/provider-limrun/src/runtime.ts#L230). The rule: a restarted daemon must find and delete every rental it created, using only the journal. That needs three things from Limrun: the The two open inline threads (#5052 (comment) and #5052 (comment)) do not need more work. Both were resolved before the earlier review and describe intended behavior: the identity-free journal entry is a release-unknown fence, and startup fails closed on an invalid journal so allocations cannot overlap while rentals may still bill. This update does not touch either one, so they can stay resolved. Not verified here: the tests were not run locally, and real Limrun label selection, exact DELETE, and principal stability across a real restart. The SDK constructor and header merge were read from the local @limrun/api 0.68.1 source, not the pinned 0.69.1. CI runs the principal tests against the pinned SDK and they pass. They would fail if The only check not passing is Body rules, which was cancelled. It lints the PR description and runs no code, and no file in the diff is on its route, so it looks unrelated. A run on the current body must still pass before merge. The next step is the live run above. After that, Body rules must pass on the current body. |
|
Live Limrun restart recovery passed at The table shows the
The trace recorded a valid |
|
The live Limrun run at 65166c0 covers the evidence the review asked for: the journal holds the reconciliation key and principal before create, the same principal is used after a SIGKILL restart, the exact-ID case deletes the recorded instance without a list call, the rental-key case recovers the instance through the |
* fix(daemon): recover provider rental fences after restart * fix(daemon): keep provider release fences through reconciliation * docs(daemon): explain pending rental retirement * fix(daemon): retry exact rental writes before legacy recovery * fix(limrun): reconcile live cleanup by rental key * refactor(limrun): move heartbeat API probe to client helpers * refactor(limrun): separate recovery identity and deletion * fix(daemon): retire confirmed rentals independently and verify recovery principals * test(limrun): supply recovery request identity in daemon fixtures * fix(daemon): settle rental retirement and bind Limrun routing headers * fix(limrun): keep recovery identity stable across SDK upgrades * fix(limrun): read routing settings from the plugin host * fix(limrun): derive recovery proof from the SDK client configuration * fix(limrun): defer rental proof validation import
Summary
Fixes #4972. Record rental scope before create and exact identity before allocation succeeds. Restore reservations before admitting overlapping work. Require matching recovery proof before either recovery hook runs.
Before / after
Validation
65166c0695, 996 focused tests passed, including the eager-import guard and Limrun recovery. Format, lint, and typecheck passed. All 12 runnable affected checks passed. Local receiptrun-Sj7pZm. Hosted Coverage was rerun after a fake-daemon timeout.42ed83d00a, formatting, lint, typecheck, layering, and 55 focused tests passed. Two regression cases failed atb235a0239f. Coverage caught the eager import fixed above.65166c0695, live Limrun exact-ID and rental-key recovery passed after SIGKILL. The keyed lookup returned one match. Both exact-instance DELETE requests returned HTTP 200, and both journals ended empty. The PR evidence comment includes the journal snapshots.