Skip to content

fix(daemon): retry provider lease record retirement - #5174

Merged
thymikee merged 4 commits into
mainfrom
fix/provider-lease-retirement
Nov 28, 2026
Merged

thymikee merged 4 commits into
mainfrom
fix/provider-lease-retirement

Conversation

@thymikee

@thymikee thymikee commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Track an expired lease record write independently once the provider confirms release. Retry it while the daemon owns registration and keep the provider result and drain accounting intact.

Before / after

  • Before: a failed write after provider confirmation could leave a stale record. Retrying an isolated disk failure every second would keep logging with no provider work left.
  • After: a retirement write alone gets one timer retry. Drain, shutdown, and registration handoff can still finish it when the disk recovers. Every close attempts the final write. An in-flight confirmation can still retire the record after a close that keeps registration. A confirmation after handoff leaves the inherited record for the successor.

Validation

At 35e96ce62d, 55 focused tests, lint, typecheck, Fallow, and git diff --check passed locally. The new runtime regression confirmed the record remained on disk at 389f6889da and was removed after the fix. All 21 hosted checks passed on the same head, Sentinel approved it, and both inline threads are resolved.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.68 MB 6.68 MB +441 B
Package (unpacked) 6.68 MB 6.68 MB +441 B
Package (download) 2.04 MB 2.04 MB +156 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 17.6 ms 17.6 ms -0.0 ms
CLI --help 39.5 ms 39.8 ms +0.3 ms

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding on 135e1df. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

At 389f688, one problem needs a fix: a close that keeps the daemon registration still stops all later lease record writes.

closeOnHost calls finishPersistence() even when it then keeps the registration because work is unfinished. After that, pending lease writes and journal writes do nothing. In an embedded runtime (startAgentDevice), the process stays alive and keeps the lock. A late recovery confirmation is then never written, so the next daemon repeats provider recovery. A lease that an abandoned request records late is also never journaled. If the host exits before that request releases it, no daemon recovers the billed device. A late recoverable release is also refused with durable:false. The base branch made these writes. A detached daemon exits right after close, so its window is negligible. The rule: disk writes must stop only when the close actually releases the registration. Every close should still make the final retirement retry. Please add a regression test where a close keeps the registration, a late recovery confirmation arrives, and the record is removed.

Not blocking: these can be taken or left: state in the lease contract doc that writes stop at registration handoff and describe the bounded retirement retry; cover the rollback and close calls in runtime-level tests (the close order can share the regression above); mention or move the restart recovery test, which covers unchanged behavior; and run the finishPersistence calls and the shutdown() call inside withDaemonDiagnosticsScope, so a record write failure is not dropped.

Two earlier threads no longer apply and can be resolved: late confirmation writes are fixed for shutdown with a final retry, and leaving the record after handoff is intentional (the kept-registration close is the problem above); the unbounded retry loop is gone, because retirement now retries once on a timer.

The required evidence is in place. CI checks pass, and Proof is skipped. The cancelled Body rules run was replaced by a passing run on the same commit.

Not verified here: no tests or reproduction were run, and the author's local validation was not rerun. The problem and the test gap come from reading the code. No live run shows the late event after a close with unfinished work in a process that stays alive.

Before merge, disk writes must stop only when the close releases the registration, with a regression test for the kept-registration route.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 35e96ce

Since the review of 389f688: 0 new · 0 still open · 0 no longer raised

No open findings.

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

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

This PR is ready at 35e96ce. The open points from the earlier review are fixed, and only one optional follow-up remains.

Not blocking: take this as a follow-up issue or leave it: retainRegistration states what the close asks for, so if an embedded owner's finish() keeps the lock (a failed daemon.json unlink, or an ownership read other than match or absent, here) after persistence has closed, a later recovery confirmation is not written, so either persistence should close only where the registration owner actually releases the lock (no writes after handoff), or the stated rule should be "a close that does not request retention".

Two earlier threads no longer apply and can be resolved. In this one, shutdown now retries a failed write before handoff, a late confirmation writes on a retaining close, and after handoff it is left to the successor by design. In this one, the retry-attempted state ends the retirement-only retry loop after one timer.

CI is green. One Body rules run was cancelled, but later runs of that job passed on the same commit, and it checks only the PR text. All other checks passed, and Proof was skipped.

A trial merge with the newer main reports no conflicts.

Not verified here: no tests or reproduction were run, and the author's local validation was not rerun. The regression at 389f688 and the failed-unlink route were judged from the code. The new test asserts only the expired record, so journal writes and a late release after a retaining close were checked by reading the shared persistence gate. Newer main changes daemon-runtime.ts and the lease expiry test mock path, and the merged tree was not tested.

Nothing from this review needs to change before merge.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 28, 2026
@thymikee
thymikee merged commit 9fbb4d6 into main Nov 28, 2026
22 of 23 checks passed
@thymikee
thymikee deleted the fix/provider-lease-retirement branch November 28, 2026 13:00
thymikee added a commit that referenced this pull request Nov 28, 2026
* origin/main:
  fix(cli): judge install-from-source lease admission by its daemon command (#5169)
  ci: report sizes for affected plugins (#5176)
  fix(ios): keep the zh-Hans alert vocabulary check honest about OS versions (#5177)
  Consolidate Apple tap and replacement result construction (#5161)
  fix(daemon): retry provider lease record retirement (#5174)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant