Skip to content

feat(daemon): fix #112 by integrating alert delivery into the daemon loop - #279

Merged
AbdulmalikAlayande merged 2 commits into
TegoLabs:mainfrom
Gezziy:integrate-alert
Jun 29, 2026
Merged

AbdulmalikAlayande merged 2 commits into
TegoLabs:mainfrom
Gezziy:integrate-alert

Conversation

@Gezziy

@Gezziy Gezziy commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

closes #112

##summary:
This PR closes issue #112 by wiring alert delivery into the daemon’s polling cycle. Before this change, a monitoring pass could finish without immediately dispatching any alerts that had been fired during that pass. The daemon now runs the delivery step right after runMonitorCycle, which keeps alert propagation inside the same execution flow instead of deferring it to a later interval.

The updated flow is straightforward: the daemon completes its monitoring work, invokes deliverPendingAlerts(db, network), logs the delivery summary, and then continues with the rest of the maintenance steps. That matters because alert delivery is part of the daemon’s operational contract, and it needs to happen as soon as the polling cycle has produced actionable alerts. The implementation also keeps the same database handle flowing through the loop and the dispatcher so delivered alerts are marked in the shared database state.

The test coverage verifies that daemon cycles trigger alert dispatch and that the loop stays resilient if delivery throws unexpectedly. That gives us confidence that issue #112 is addressed without changing the daemon’s failure behavior.

Changes Made

  • src/daemon/loop.ts
    • Calls deliverPendingAlerts(db, network) immediately after each runMonitorCycle completion.
    • Logs delivery report summaries so dispatch activity is visible in daemon output.
    • Keeps delivery errors isolated so a bad dispatcher call does not stop the daemon loop.
  • tests/daemon/loop.test.ts
    • Verifies alert dispatch is triggered during daemon cycles.
    • Verifies the daemon continues running if delivery throws.
  • Issue reference: #112

Testing

Executed:

npm test -- tests/daemon/loop.test.ts

Result:

  • Passed: 31 tests
  • Failed: 0 tests

@coderabbitai

coderabbitai Bot commented Jun 28, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c84cabad-a204-45cf-9548-8d1164cbe959

📥 Commits

Reviewing files that changed from the base of the PR and between bac00ec and ae10ec3.

📒 Files selected for processing (1)
  • tests/daemon/loop.test.ts
📜 Recent review details
🔇 Additional comments (2)
tests/daemon/loop.test.ts (2)

12-23: LGTM!

Also applies to: 49-52


557-570: LGTM!

Also applies to: 585-588


📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Added coverage to verify alert delivery runs during the daemon’s initial cycle and subsequent scheduled intervals, including the expected delivery behavior and logging.
    • Ensured the daemon remains responsive even if alert delivery fails unexpectedly, logs the error, and retries on the next scheduled cycle.

Walkthrough

Adds daemon-loop tests in tests/daemon/loop.test.ts that mock the logger, verify deliverPendingAlerts(db, network) runs on startup and later intervals, and confirm daemon execution continues after a delivery rejection.

Changes

Alert Dispatch Tests

Layer / File(s) Summary
Alert dispatch test suite
tests/daemon/loop.test.ts
Adds a hoisted mock logger, routes getLogger() to it, and introduces fake-timer tests for repeated alert delivery calls, delivery-count logging, and continued daemon cycles after an unexpected rejection.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related issues

  • #112 (feat(daemon): integrate alert delivery into daemon loop): The added tests cover the daemon-loop alert dispatch integration and the acceptance criteria for triggering alert dispatch during a running cycle.
  • AbdulmalikAlayande/sorokeep#12: The new daemon-loop tests directly exercise the alert delivery behavior described in this issue.

Possibly related PRs

  • AbdulmalikAlayande/sorokeep#221: Both PRs assert that deliverPendingAlerts is invoked with (db, network) during daemon execution and that delivery failures do not stop subsequent cycles.

Poem

🐇 I hop through ticks and timer light,
Alert tests gleam in fuzzy sight.
If one delivery stumbles, the loop stays bright,
Then hops again on the next clock bite.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The changes shown are test-only; they don't demonstrate the required src/daemon/loop.ts integration of deliverPendingAlerts. Add the daemon-loop implementation that imports and calls deliverPendingAlerts after runMonitorCycle, then keep the current tests validating it.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the daemon loop alert-delivery integration for issue #112.
Description check ✅ Passed The description directly matches the daemon alert-delivery work and related tests.
Out of Scope Changes check ✅ Passed The added daemon loop tests and logging assertions are directly related to issue #112.
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.

@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@Gezziy 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 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: 1

🤖 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 `@tests/daemon/loop.test.ts`:
- Around line 539-565: Add logging assertions to the daemon loop tests so the
delivery logging contract is covered. In the `startDaemon` scenarios around
`mockDeliverPendingAlerts`, assert that `logger().info(...)` is called with the
delivery summary after a successful dispatch and that `logger().error(...)` is
called when `mockDeliverPendingAlerts` rejects in the unexpected-failure path.
Use the existing `startDaemon`, `mockDeliverPendingAlerts`, and `logger()`
symbols to locate the relevant expectations in this suite.
🪄 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: 94302136-d492-4888-a540-3c3113259369

📥 Commits

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

📒 Files selected for processing (1)
  • tests/daemon/loop.test.ts
📜 Review details
🔇 Additional comments (1)
tests/daemon/loop.test.ts (1)

557-557: 🎯 Functional Correctness

resolves.not.toThrow() is fine here. startDaemon(...) returns a promise, so this assertion is a valid way to check the async path completes without error; no change needed.

			> Likely an incorrect or invalid review comment.

Comment thread tests/daemon/loop.test.ts
@AbdulmalikAlayande

Copy link
Copy Markdown
Collaborator

Actionable comments posted: 1

🤖 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 `@tests/daemon/loop.test.ts`:
- Around line 539-565: Add logging assertions to the daemon loop tests so the
delivery logging contract is covered. In the `startDaemon` scenarios around
`mockDeliverPendingAlerts`, assert that `logger().info(...)` is called with the
delivery summary after a successful dispatch and that `logger().error(...)` is
called when `mockDeliverPendingAlerts` rejects in the unexpected-failure path.
Use the existing `startDaemon`, `mockDeliverPendingAlerts`, and `logger()`
symbols to locate the relevant expectations in this suite.

🪄 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: 94302136-d492-4888-a540-3c3113259369

📥 Commits
Reviewing files that changed from the base of the PR and between d4f7b90 and bac00ec.

📒 Files selected for processing (1)

  • tests/daemon/loop.test.ts

📜 Review details

@Gezziy please resolve this

@Gezziy

Gezziy commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

done , merge boss

@AbdulmalikAlayande
AbdulmalikAlayande merged commit fb90a6e into TegoLabs:main Jun 29, 2026
3 checks passed
AbdulmalikAlayande pushed a commit that referenced this pull request Aug 2, 2026
…loop (#279)

* fix(daemon): fix #112 daemon alert delivery

* fix(daemon): cover delivery logging in tests

---------

Co-authored-by: Justice <ezejustice112@gmail.com>
AbdulmalikAlayande pushed a commit that referenced this pull request Aug 2, 2026
…loop (#279)

* fix(daemon): fix #112 daemon alert delivery

* fix(daemon): cover delivery logging in tests

---------

Co-authored-by: Justice <ezejustice112@gmail.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): integrate alert delivery into daemon loop

3 participants