Skip to content

fix(reader): hold the lease for the budget plus the read timeout - #82

Merged
somethingwithproof merged 2 commits into
mainfrom
fix/reader-lease-length
Nov 20, 2026
Merged

somethingwithproof merged 2 commits into
mainfrom
fix/reader-lease-length

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Fixes #79.

The budget only stops new reads from starting, so a read started near the deadline can run for the whole read timeout. The lease covered only budget + 60, so such a run could lose its lease and discard every result.

Change: Reader::run() takes the read timeout and leases for budget + read timeout + 60, matching the process registration in poller_pfs.php. Test callers pass Settings::DEFAULT_TIMEOUT. New lifecycle scenario reader_overrun: a read runs from the budget's end to a 120 s timeout, and its results and run counts are written.

Verification (local, PHP 8.3 + Cacti 1.2.31 + MariaDB 11.8): Pest unit 273 passed, lifecycle 26 passed (the new test fails with the old lease length), PHPStan no errors, page and device permission scripts all PASS, PHP 8.0 lint clean.

Risk: low. A reader that has actually died holds its poller's lease longer, by the read timeout (30 s by default).

Summary by CodeRabbit

  • Bug Fixes
    • Reads that start near the end of a processing budget can now continue for their configured timeout.
    • The reader’s lease now remains active through the read timeout, giving an in-progress read time to finish and save its result.
    • Reader operations now require an explicit timeout setting.

The reader took its lease for the budget plus 60 seconds, but the budget
only stops new reads from starting. A read started near the deadline may
run for the whole read timeout, so a run could outlive its lease and
have every result discarded, possibly on every cycle.

Reader::run() now takes the read timeout and holds the lease for
budget + read timeout + 60, in line with the process registration in
poller_pfs.php. A lifecycle scenario runs a read from the budget's end
to a 120 second timeout and checks that its results are written.

Fixes #79

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The reader lease now covers the configured read timeout in addition to the reader budget and margin. The poller passes the timeout to the reader. Test calls now provide a timeout, and lifecycle tests cover reads that continue past the budget.

Changes: Reader Lease Duration

Layer / File(s) Summary
Lease duration and poller wiring
lib/Reader.php, poller_pfs.php
Reader::run now requires readTimeout and adds it to the lease duration. The poller passes its configured timeout.
Timeout call sites and overrun coverage
tests/Integration/LifecycleTest.php, tests/bin/lifecycle.php, tests/bin/reader-restart.php, tests/bin/alert-flow.php, tests/bin/device-flow.php, tests/bin/device-permissions.php, tests/bin/reader-flow.php, tests/bin/restore-flow.php, tests/bin/scale-flow.php, tests/bin/target-flow.php
Reader test calls pass an explicit timeout. The restart test adds an overrun scenario, and the integration test checks a read that continues through its timeout.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 8a55d

This change lengthens the reader lease so a read that starts near the end of the budget can finish and have its results written instead of being discarded. The only cost is that a dead reader holds its poller's lease longer, by the read timeout (30 seconds by default). No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Reader::run() now holds the poller lease for the budget plus the read timeout. The raw summary and objectives confirm this is the primary change, and the lease formula…
Description check Passed The description covers the summary, the issue link (Fixes #79), verification steps with versions, and a risk note. It does not fill the Requirements affected section, which it should mark as 'none' if…
Linked Issues check Passed [#79] The issue asks for a lease of at least budget + readTimeout + margin, or renewal before applying results. At head, Reader::run() takes $readTimeout and calls runs->acquire() with $budgetSeconds …
Out of Scope Changes check Passed All changes relate to #79. The Reader::run() signature change and lease formula are the fix. poller_pfs.php passes the new argument. The tests/bin/*.php files pass Settings::DEFAULT_TIMEOUT to run() b…
Full details: Title check

Explanation

The title names the main change: Reader::run() now holds the poller lease for the budget plus the read timeout. The raw summary and objectives confirm this is the primary change, and the lease formula matches the summary.

Full details: Description check

Explanation

The description covers the summary, the issue link (Fixes #79), verification steps with versions, and a risk note. It does not fill the Requirements affected section, which it should mark as 'none' if not applicable. It also omits the signed-off and documentation checklist items. The core content is complete, so the check passes. The missing template sections are non-critical.

Resolution

Optionally add a Requirements affected entry (or 'none'), and confirm the checklist items: signed-off commits, docs/PLAN.md and docs/REQUIREMENTS.md updates if applicable, and a decision record if one applies.

Full details: Linked Issues check

Explanation

[#79] The issue asks for a lease of at least budget + readTimeout + margin, or renewal before applying results. At head, Reader::run() takes $readTimeout and calls runs->acquire() with $budgetSeconds + $readTimeout + 60 (lib/Reader.php). The margin of 60 matches the issue's stated lease shortfall. The docblock states that a read started before the budget deadline may run for the full read timeout. poller_pfs.php passes $pfs_settings->readTimeout, so production callers supply the value the lease uses. The new lifecycle scenario reader_overrun (tests/bin/reader-restart.php, tests/Integration/LifecycleTest.php) covers a read that ends after budget + 60, as the issue requests. The lease is now shorter than the process registration (budget + readTimeout + 120), which keeps the poller registration as the outer bound. The issue's other references (ProcRunner deadline handling, CacheRepository and ReaderRepository expiry checks) are unchanged, which the chosen fix does not require. Limit: the lifecycle and unit test results are author-reported and were not re-run here.

Full details: Out of Scope Changes check

Explanation

All changes relate to #79. The Reader::run() signature change and lease formula are the fix. poller_pfs.php passes the new argument. The tests/bin/*.php files pass Settings::DEFAULT_TIMEOUT to run() because the new required parameter needs a value at every call site. reader-restart.php adds the reader_overrun scenario and an optional timeout on restart_reader, which the issue's requested test requires. LifecycleTest.php and tests/bin/lifecycle.php register that scenario. No unrelated behavior change appears in the reviewed hunks. Limit: I did not search the whole repository for other run() callers outside the files listed in the summary; the summary lists none beyond these.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the lease at dawn,
And sees the timeout safely drawn.
A read may pass the budget’s end,
Its results still reach their proper end.
The tests hop through the overrun,
Then rest beneath the setting sun.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ff4bc1a9-694e-4655-8254-dc1bce9b9428
Commits

Reviewing files that changed from the base of the PR and between 19dbbfa and 8a55db5.

Files selected for processing: 12

  • lib/Reader.php
  • poller_pfs.php
  • tests/Integration/LifecycleTest.php
  • tests/bin/alert-flow.php
  • tests/bin/device-flow.php
  • tests/bin/device-permissions.php
  • tests/bin/lifecycle.php
  • tests/bin/reader-flow.php
  • tests/bin/reader-restart.php
  • tests/bin/restore-flow.php
  • tests/bin/scale-flow.php
  • tests/bin/target-flow.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@gitar-bot

gitar-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Gitar is working

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

Gitar

@sonarqubecloud

Copy link
Copy Markdown

@somethingwithproof
somethingwithproof merged commit e7313cd into main Nov 20, 2026
19 checks passed
@somethingwithproof
somethingwithproof deleted the fix/reader-lease-length branch November 20, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reader lease can expire before a run writes its results

1 participant