Skip to content

Feat/148 adaptive polling intervals - #262

Merged
AbdulmalikAlayande merged 3 commits into
TegoLabs:mainfrom
nazteeemba:feat/148-adaptive-polling-intervals
Jun 29, 2026
Merged

AbdulmalikAlayande merged 3 commits into
TegoLabs:mainfrom
nazteeemba:feat/148-adaptive-polling-intervals

Conversation

@nazteeemba

Copy link
Copy Markdown
Contributor

closes #148

Add requirements spec for the adaptive polling intervals feature.

- Defines 6 requirements covering interval tier calculation, dynamic
  rescheduling, backward-compatible configuration, a pure
  computeEffectiveInterval function, observability logging, and
  re-entrance safety
- TTL tiers expressed in ledgers (720 / 17,280 / 120,960) mapping to
  1 min / 5 min / 1 hour polling intervals
- IntervalPolicy type allows custom tier boundaries; intervalMs
  override pins a fixed interval (disabling adaptive mode)
- Invalid policies throw before daemon starts
- Pure computeEffectiveInterval function enables isolated unit testing

Closes TegoLabs#148
Add design document and implementation tasks for the adaptive polling
intervals feature.

- Design covers interval.ts pure module, loop.ts refactor from
  setInterval to chained setTimeout, IntervalPolicy type, and
  MonitorCycleResult.remainingTTLs extension
- Tasks cover 9 steps: fast-check install, interval.ts creation,
  monitor.ts extension, loop.ts wiring, build checkpoint, unit tests,
  property-based tests, integration tests, and final checkpoint

Closes TegoLabs#148
@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@nazteeemba Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jun 27, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@AbdulmalikAlayande, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 68644b4d-5512-4313-8fe6-4c8f0422badf

📥 Commits

Reviewing files that changed from the base of the PR and between 403829e and 48bf6b1.

📒 Files selected for processing (2)
  • .kiro/specs/adaptive-polling-intervals/design.md
  • .kiro/specs/adaptive-polling-intervals/tasks.md
📝 Walkthrough

Walkthrough

Added a Kiro feature spec set for adaptive daemon polling, covering requirements, design, and task planning for tier-based interval calculation, chained rescheduling, configuration rules, logging, and test coverage.

Changes

Adaptive Polling Interval Specification

Layer / File(s) Summary
Feature framing and terminology
.kiro/specs/adaptive-polling-intervals/.config.kiro, .kiro/specs/adaptive-polling-intervals/requirements.md, .kiro/specs/adaptive-polling-intervals/tasks.md
Adds the feature metadata plus the introductory requirements, glossary, and implementation-plan framing for adaptive daemon polling.
Adaptive interval contract
.kiro/specs/adaptive-polling-intervals/requirements.md, .kiro/specs/adaptive-polling-intervals/design.md
Defines the tier-based interval rules, rescheduling semantics, interval-policy validation, daemon option/state changes, and adaptive interval module contracts.
Testing and rollout plan
.kiro/specs/adaptive-polling-intervals/design.md, .kiro/specs/adaptive-polling-intervals/tasks.md
Lists the interval invariants, logging/error behavior, testing strategy, task sequencing, and dependency graph for the feature.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Possibly related PRs

  • AbdulmalikAlayande/sorokeep#221: This also focuses on daemon-cycle timing behavior, which is the same area covered by the adaptive polling specification.

Poem

I’m a rabbit with a timer’s tune,
Hopping by TTL beneath the moon.
Tiny waits for tiny tasks,
Gentle pauses when safety asks.
🐇⏱️ Hop, reschedule, bloom!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds only spec/doc files; it does not implement adaptive polling in src/daemon/loop.ts or the required tests. Implement the adaptive scheduler and supporting tests in the daemon code, including the TTL-based interval tiers and rescheduling logic.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the adaptive polling interval feature.
Description check ✅ Passed The description is related to issue #148 and correctly references closing it.
Out of Scope Changes check ✅ Passed Changes are confined to the adaptive polling spec docs; no unrelated code changes are shown.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
.kiro/specs/adaptive-polling-intervals/requirements.md (2)

193-201: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Add missing validation rules for IntervalPolicy boundary ordering and maxIntervalMs constraints.

The current validation rules (3.4, 3.5) only check tier intervals ≥ 10,000 ms and minIntervalMs against tier intervals. Missing validations that could cause incorrect clamping behavior:

  • maxIntervalMs should be ≥ minIntervalMs (design mentions this but no validation rule)
  • Tier boundaries should be strictly ordered: criticalTtlLedgers < dayTtlLedgers < weekTtlLedgers

Add these to validateIntervalPolicy in task 2.4 and document in requirements/design to prevent misconfiguration where clamping produces nonsensical results.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.kiro/specs/adaptive-polling-intervals/requirements.md around lines 193 -
201, `validateIntervalPolicy` is missing two configuration checks: enforce that
`maxIntervalMs` is greater than or equal to `minIntervalMs`, and that the tier
boundaries are strictly ordered (`criticalTtlLedgers` < `dayTtlLedgers` <
`weekTtlLedgers`). Update the validation logic in the interval policy
requirements/design so these rules are documented alongside the existing
interval minimum checks, and make sure the new constraints are applied wherever
`IntervalPolicy` is validated.

188-188: 📐 Maintainability & Code Quality | 🟠 Major | ⚖️ Poor tradeoff

Remove optional marking from tests — property and integration tests are required per PR objectives.

Tasks marked with * (6.2, 6.3, 7.1–7.4, 8.1–8.6) are labeled optional, but the PR objectives explicitly require a "test-driven approach, with tests written before implementation, and coverage for edge cases and failure modes." Property-based tests (7.1–7.4) and integration tests (8.1–8.6) are essential for verifying correctness properties and end-to-end behavior. Remove the * marking and optional designation from these tasks.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.kiro/specs/adaptive-polling-intervals/requirements.md at line 188, The
requirements spec still marks several test tasks as optional, but the PR
objectives require them to be mandatory. Update the task list in the
adaptive-polling-intervals requirements so the property-based tests (7.1–7.4)
and integration tests (8.1–8.6), along with the other listed test tasks (6.2,
6.3), are no longer marked with “*” or described as optional; keep the task
names and structure, only remove the optional designation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.kiro/specs/adaptive-polling-intervals/requirements.md:
- Around line 70-72: Add an explicit precedence requirement to the adaptive
polling intervals section so the behavior is unambiguous when both
DaemonOptions.intervalMs and DaemonOptions.intervalPolicy are provided. Update
the requirement set near the existing intervalMs / IntervalPolicy clauses to
state that intervalMs takes precedence and intervalPolicy is ignored in that
case, while keeping the current fixed-interval and default-behavior requirements
intact.
- Around line 46-49: The `MonitorCycleResult` shape is currently inconsistent
with the design claim of a non-breaking addition: `remainingTTLs` is required,
so every constructor, mock, and test creating `MonitorCycleResult` must be
updated unless the field is made optional. Decide whether `remainingTTLs` in
`MonitorCycleResult` should be `remainingTTLs?: number[]` with default handling
in `computeEffectiveInterval`, or explicitly treat it as a breaking change and
update all call sites and fixtures that build `MonitorCycleResult` accordingly.
- Around line 74-76: Clarify the backward-compatibility notes for fixed
intervalMs mode: the scheduler implementation uses chained setTimeout behavior,
which changes timing semantics for slow cycles compared with setInterval. Update
the design/spec section that describes intervalMs so it explicitly states that
wall-clock regularity is not preserved when a cycle runs longer than the
interval, and reference the Scheduler behavior and intervalMs mode so
implementers and testers understand the drift/skipping difference.

In @.kiro/specs/adaptive-polling-intervals/tasks.md:
- Around line 186-192: The note about `vi.advanceTimersByTimeAsync` in the task
list is too absolute for chained `setTimeout` behavior. Rephrase the note to
clarify that while Vitest supports advancing chained timers, the total elapsed
time in `loop.test.ts` includes both the cycle execution time and the timeout
delay, so tests may need timing expectations adjusted accordingly. Keep the
guidance tied to the timer-related tasks and the `setInterval` → `setTimeout`
chain change.
- Around line 197-209: The dependency graph is missing Task 5 and Task 9, so
update the waves structure in the adaptive-polling-intervals task list to
include them. Add Task 5 alongside or immediately after the wave containing 4.4
and 4.5, and add Task 9 as a final wave after the current last wave; keep the
existing wave ordering and task IDs consistent.
- Around line 87-91: The build checkpoint task in the adaptive-polling-intervals
spec should be approved and included in the dependency graph. Update the task
entry for the build/test verification step so it is marked as an approved
checkpoint, and make sure its dependencies are represented consistently with the
surrounding tasks in the spec.

---

Outside diff comments:
In @.kiro/specs/adaptive-polling-intervals/requirements.md:
- Around line 193-201: `validateIntervalPolicy` is missing two configuration
checks: enforce that `maxIntervalMs` is greater than or equal to
`minIntervalMs`, and that the tier boundaries are strictly ordered
(`criticalTtlLedgers` < `dayTtlLedgers` < `weekTtlLedgers`). Update the
validation logic in the interval policy requirements/design so these rules are
documented alongside the existing interval minimum checks, and make sure the new
constraints are applied wherever `IntervalPolicy` is validated.
- Line 188: The requirements spec still marks several test tasks as optional,
but the PR objectives require them to be mandatory. Update the task list in the
adaptive-polling-intervals requirements so the property-based tests (7.1–7.4)
and integration tests (8.1–8.6), along with the other listed test tasks (6.2,
6.3), are no longer marked with “*” or described as optional; keep the task
names and structure, only remove the optional designation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ff206202-b659-4dbf-a04e-0ba8cc68e584

📥 Commits

Reviewing files that changed from the base of the PR and between d4f7b90 and 403829e.

📒 Files selected for processing (4)
  • .kiro/specs/adaptive-polling-intervals/.config.kiro
  • .kiro/specs/adaptive-polling-intervals/design.md
  • .kiro/specs/adaptive-polling-intervals/requirements.md
  • .kiro/specs/adaptive-polling-intervals/tasks.md
📜 Review details
🧰 Additional context used
🪛 LanguageTool
.kiro/specs/adaptive-polling-intervals/design.md

[style] ~13-~13: ‘exactly the same’ might be wordy. Consider a shorter alternative.
Context: ...xisting users who pass intervalMs get exactly the same behaviour as today. ### Key design goa...

(EN_WORDINESS_PREMIUM_EXACTLY_THE_SAME)


[style] ~363-~363: To form a complete sentence, be sure to include a subject or ‘there’.
Context: ...tive or zero TTL values remainingTTL can be zero or negative when a ledger entry...

(MISSING_IT_THERE)

.kiro/specs/adaptive-polling-intervals/requirements.md

[style] ~60-~60: This phrase is redundant. Consider writing “point” or “time”.
Context: ...at most one pending cycle exists at any point in time. 4. WHEN startDaemon is called, THE S...

(MOMENT_IN_TIME)


[style] ~72-~72: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...y in place of the built-in defaults. 3. WHERE neither intervalMs nor `IntervalPolic...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~96-~96: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...terval values in the same log entry. 3. WHEN no TTL data is available (empty watch l...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🪛 markdownlint-cli2 (0.22.1)
.kiro/specs/adaptive-polling-intervals/tasks.md

[warning] 83-83: Spaces inside code span elements

(MD038, no-space-in-code)

.kiro/specs/adaptive-polling-intervals/design.md

[warning] 32-32: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


[warning] 178-178: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


[warning] 256-256: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


[warning] 376-376: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


[warning] 382-382: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


[warning] 388-388: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


[warning] 412-412: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


[warning] 412-412: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


[warning] 417-417: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


[warning] 417-417: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


[warning] 439-439: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (15)
.kiro/specs/adaptive-polling-intervals/design.md (8)

279-290: 🗄️ Data Integrity & Integration

Reiterate: remainingTTLs should be optional or explicitly marked breaking.

As noted in the requirements review, claiming this is "non-breaking" is inaccurate if the field is required. The design should either add ? to the type or remove the "non-breaking" claim.


400-479: 📐 Maintainability & Code Quality

Flag: Property tests marked optional in tasks contradict this testing strategy.

The design describes a comprehensive testing strategy with property tests, but the tasks.md marks these as optional. Ensure the testing strategy is fully implemented per PR objectives.


96-109: Verify tier interval constants match requirements exactly.

The default constants are consistent with requirements. No issue here — approving this section.


118-139: Approve IntervalPolicy interface design.

The interface is well-structured with clear JSDoc comments. Optional fields with sensible defaults allow gradual adoption. No issues.


154-174: Approve public API design for pure functions.

The computeEffectiveInterval, validateIntervalPolicy, and ttlToIntervalMs signatures are clean, testable, and correctly typed. No issues.


176-191: Approve computeEffectiveInterval algorithm.

The four-tier classification with min/max clamping is correct and matches requirements. Edge cases (empty array, negative TTL) are handled appropriately.


302-331: Approve correctness properties.

The four properties (tier mapping, range invariant, purity, uniform-array) directly validate requirements and provide good coverage for property-based testing.


370-398: Approve observability design.

Log formats are informative and include the required fields (effectiveMs, minTTL, errorCount, intervalChanged). Debug level for empty watch list is appropriate.

.kiro/specs/adaptive-polling-intervals/tasks.md (7)

93-119: 📐 Maintainability & Code Quality

Reiterate: Remove optional marking from unit tests 6.2 and 6.3.

Edge case and validation tests are essential for a test-driven approach. The * marking should be removed.


121-148: 📐 Maintainability & Code Quality

Reiterate: Remove optional marking from property tests 7.1–7.4.

Property tests validate universal invariants and are core to the testing strategy. Must not be optional.


150-179: 📐 Maintainability & Code Quality

Reiterate: Remove optional marking from integration tests 8.1–8.6.

Integration tests verify end-to-end scheduler behavior and are required for confidence in the setTimeout chaining implementation. Must not be optional.


13-16: Approve fast-check installation task.

Standard dev dependency addition. Version specification is reasonable.


18-44: Approve interval.ts implementation tasks.

Tasks 2.1–2.4 cover the pure computation module with clear requirements traceability. No issues.


46-49: Approve MonitorCycleResult extension task.

Task 3 correctly identifies the needed change. As noted previously, the "non-breaking" claim should be verified.


51-85: Approve loop.ts refactoring tasks.

Tasks 4.1–4.5 cover the scheduler wiring comprehensively. The setTimeout chaining approach is correctly described. No issues.

Comment thread .kiro/specs/adaptive-polling-intervals/requirements.md
Comment thread .kiro/specs/adaptive-polling-intervals/requirements.md
Comment thread .kiro/specs/adaptive-polling-intervals/requirements.md
Comment thread .kiro/specs/adaptive-polling-intervals/tasks.md
Comment thread .kiro/specs/adaptive-polling-intervals/tasks.md
Comment thread .kiro/specs/adaptive-polling-intervals/tasks.md
@gitguardian

gitguardian Bot commented Jun 27, 2026 •

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@AbdulmalikAlayande

Copy link
Copy Markdown
Collaborator

@coderabbitai resolve

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
✅ Action performed

Comments resolved and changes approved.

@AbdulmalikAlayande
AbdulmalikAlayande merged commit 193a784 into TegoLabs:main Jun 29, 2026
3 checks passed
AbdulmalikAlayande added a commit that referenced this pull request Aug 2, 2026
* feat(daemon): add spec for adaptive polling intervals (#148)

Add requirements spec for the adaptive polling intervals feature.

- Defines 6 requirements covering interval tier calculation, dynamic
  rescheduling, backward-compatible configuration, a pure
  computeEffectiveInterval function, observability logging, and
  re-entrance safety
- TTL tiers expressed in ledgers (720 / 17,280 / 120,960) mapping to
  1 min / 5 min / 1 hour polling intervals
- IntervalPolicy type allows custom tier boundaries; intervalMs
  override pins a fixed interval (disabling adaptive mode)
- Invalid policies throw before daemon starts
- Pure computeEffectiveInterval function enables isolated unit testing

Closes #148

* feat(daemon): add design and tasks for adaptive polling intervals

Add design document and implementation tasks for the adaptive polling
intervals feature.

- Design covers interval.ts pure module, loop.ts refactor from
  setInterval to chained setTimeout, IntervalPolicy type, and
  MonitorCycleResult.remainingTTLs extension
- Tasks cover 9 steps: fast-check install, interval.ts creation,
  monitor.ts extension, loop.ts wiring, build checkpoint, unit tests,
  property-based tests, integration tests, and final checkpoint

Closes #148

* fix(docs): address CodeRabbit review feedback

---------

Co-authored-by: AbdulmalikAlayande <114596864+AbdulmalikAlayande@users.noreply.github.com>
AbdulmalikAlayande added a commit that referenced this pull request Aug 2, 2026
* feat(daemon): add spec for adaptive polling intervals (#148)

Add requirements spec for the adaptive polling intervals feature.

- Defines 6 requirements covering interval tier calculation, dynamic
  rescheduling, backward-compatible configuration, a pure
  computeEffectiveInterval function, observability logging, and
  re-entrance safety
- TTL tiers expressed in ledgers (720 / 17,280 / 120,960) mapping to
  1 min / 5 min / 1 hour polling intervals
- IntervalPolicy type allows custom tier boundaries; intervalMs
  override pins a fixed interval (disabling adaptive mode)
- Invalid policies throw before daemon starts
- Pure computeEffectiveInterval function enables isolated unit testing

Closes #148

* feat(daemon): add design and tasks for adaptive polling intervals

Add design document and implementation tasks for the adaptive polling
intervals feature.

- Design covers interval.ts pure module, loop.ts refactor from
  setInterval to chained setTimeout, IntervalPolicy type, and
  MonitorCycleResult.remainingTTLs extension
- Tasks cover 9 steps: fast-check install, interval.ts creation,
  monitor.ts extension, loop.ts wiring, build checkpoint, unit tests,
  property-based tests, integration tests, and final checkpoint

Closes #148

* fix(docs): address CodeRabbit review feedback

---------

Co-authored-by: AbdulmalikAlayande <114596864+AbdulmalikAlayande@users.noreply.github.com>
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.

feat(daemon): implement adaptive polling intervals

2 participants