Skip to content

Fix per-notifier error/warning count drift in dispatch chain#213

Merged
tis24dev merged 3 commits into
tis24dev:devfrom
paolostivanin:dev
May 16, 2026
Merged

Fix per-notifier error/warning count drift in dispatch chain#213
tis24dev merged 3 commits into
tis24dev:devfrom
paolostivanin:dev

Conversation

@paolostivanin
Copy link
Copy Markdown
Contributor

@paolostivanin paolostivanin commented May 16, 2026

Snapshot ErrorCount, WarningCount and LogCategories into BackupStats once at backup completion (finalizeBackupStats / parseFailedBackupLogCounts) and have convertBackupStatsToNotificationData read them as-is. Re-parsing the log file per-notifier was over-counting warnings emitted by earlier notifiers in the dispatch chain, so e.g. Pushover reported 5 warnings while Email reported 0 on the same run.

Summary by CodeRabbit

  • Bug Fixes & Improvements

    • Notifications now capture consistent pre-send snapshots of backup stats (error/warning counts and log categories), preventing timing-related mismatches.
    • Backup reporting includes categorized log information and no longer re-reads log files during notification dispatch.
    • Dry-run behavior now centralizes how issue counts affect exit codes.
  • Tests

    • Added behavioral tests to verify snapshot timing, warning propagation, and early-error log preservation.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c30ba678-3c6f-4290-9975-256ec350ab9d

📥 Commits

Reviewing files that changed from the base of the PR and between 49737f0 and 3038fc1.

📒 Files selected for processing (4)
  • internal/orchestrator/additional_helpers_test.go
  • internal/orchestrator/backup_run_phases.go
  • internal/orchestrator/extensions.go
  • internal/orchestrator/extensions_additional_test.go

📝 Walkthrough

Walkthrough

This PR refactors the backup orchestrator's notification dispatch to introduce a snapshot boundary that captures pre-notification state before issuing channel notifications, centralizes log-count parsing through a shared refresh helper, and simplifies notification conversion to trust precomputed snapshots rather than re-reading logs.

Changes

Pre-Notification Issue Snapshot Boundary

Layer / File(s) Summary
BackupStats Schema Extension and Import
internal/orchestrator/orchestrator.go
BackupStats struct now carries LogCategories []notify.LogCategory field alongside existing error/warning counts, and imports the notify package.
Notification Snapshot Boundary Implementation
internal/orchestrator/extensions.go
New startNotificationGroup() wrapper and snapshotPreNotificationIssues() helper refresh BackupStats from log files (populating error/warning counts and optionally log categories) before dispatching notifications.
Integrate Boundary into Dispatch Call Sites
internal/orchestrator/extensions.go
DispatchEarlyErrorNotification and dispatchNotificationsAndLogs now route through the new notification boundary, ensuring pre-notification snapshots occur in both success and error paths.
Centralize Log Parsing via Snapshot Refresh
internal/orchestrator/backup_run_helpers.go, internal/orchestrator/backup_run_phases.go
parseFailedBackupLogCounts and finalizeBackupStats now call refreshLogIssuesFromFile() instead of directly invoking ParseLogCounts(), consolidating log-count derivation and modifying dry-run behavior.
Simplify Notification Conversion to Use Snapshots
internal/orchestrator/notification_adapter.go
convertBackupStatsToNotificationData now consumes precomputed error/warning counts and log categories from BackupStats snapshots via defensive copy, removing prior log re-parsing fallback logic.
Test Stubs and Behavioral Test for Snapshot Timing
internal/orchestrator/additional_helpers_test.go
Extended stubNotifierChannel to record snapshot values, introduced warningStorageTarget stub, and added TestDispatchPostBackupSnapshotsIssuesImmediatelyBeforeNotifications to validate snapshot capture and warning preservation across the boundary.
Adapter Conversion Test Updates
internal/orchestrator/notification_adapter_test.go
Replaced and added tests to verify convertBackupStatsToNotificationData propagates snapshot data without re-reading logs, validates defensive LogCategories copying, and confirms zero counts are preserved when logs are not re-parsed.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🐰 A snapshot's taken, swift and true,
Before the notifiers get their cue,
No re-reads in the flow—one state held fast,
Counts and categories bound at last! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly and clearly summarizes the main change: fixing a bug where error/warning counts drift across notifiers in the dispatch chain by snapshotting counts at backup completion rather than re-parsing per notifier.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

Snapshot ErrorCount, WarningCount and LogCategories into BackupStats once
at backup completion (finalizeBackupStats / parseFailedBackupLogCounts)
and have convertBackupStatsToNotificationData read them as-is. Re-parsing
the log file per-notifier was over-counting warnings emitted by earlier
notifiers in the dispatch chain, so e.g. Pushover reported 5 warnings
while Email reported 0 on the same run.
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 16, 2026

Not up to standards ⛔

🔴 Issues 2 medium

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
Complexity 2 medium

View in Codacy

🟢 Metrics 58 complexity · 5 duplication

Metric Results
Complexity 58
Duplication 5

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

❌ Patch coverage is 78.72340% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/orchestrator/extensions.go 81.25% 4 Missing and 2 partials ⚠️
internal/orchestrator/backup_run_phases.go 63.63% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@tis24dev
Copy link
Copy Markdown
Owner

@paolostivanin I made a change and moved the snapshot to a later time.
Let me know what you think.

@tis24dev
Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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 `@internal/orchestrator/extensions.go`:
- Around line 129-145: In refreshLogIssuesFromFile, ParseLogCounts currently
unconditionally overwrites BackupStats.ErrorCount and WarningCount; change this
so parsed counts only replace the existing stats if they are > 0 (or if the
existing value is 0 and parsed >0), e.g. use the returned
errorCount/warningCount to update stats.ErrorCount and stats.WarningCount only
when those parsed values are positive (preserving pre-seeded counts such as
ErrorCount=1); keep the existing behavior for LogCategories controlled by
includeCategories and the ParseLogCounts call.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 74144e62-32ac-4364-9d10-b3c7b4d475f5

📥 Commits

Reviewing files that changed from the base of the PR and between 467cd96 and 49737f0.

📒 Files selected for processing (7)
  • internal/orchestrator/additional_helpers_test.go
  • internal/orchestrator/backup_run_helpers.go
  • internal/orchestrator/backup_run_phases.go
  • internal/orchestrator/extensions.go
  • internal/orchestrator/notification_adapter.go
  • internal/orchestrator/notification_adapter_test.go
  • internal/orchestrator/orchestrator.go

Comment thread internal/orchestrator/extensions.go
@tis24dev
Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tis24dev tis24dev merged commit 51d48f3 into tis24dev:dev May 16, 2026
8 of 9 checks passed
@paolostivanin paolostivanin deleted the dev branch May 17, 2026 13:23
@paolostivanin
Copy link
Copy Markdown
Contributor Author

sorry I could answer only now! Thanks again for the fast feedback and merge 😄

tis24dev added a commit that referenced this pull request May 18, 2026
* deps: update Go modules and GitHub Actions

Updates golang.org/x/crypto, x/term, x/text and the dependency-review/setup-node Actions with regenerated checksums

* Simplify archiver drain receive

Use a plain channel receive when draining the tar writer goroutine after compressor start failure

* Update CONFIGURATION.md

* Avoid copying exec info once in tests

Store exec info cache state behind pointers so tests can override and restore it without copying sync.Once

* Remove misleading mount guard status wrapper

Call isMounted directly from guardMountPoint and remove the pass-through helper with misleading unmount wording

* Remove duplicate install template sanitization

Keep runtime-derived env key removal only at the final write point in the install config flow

* Fix per-notifier error/warning count drift in dispatch chain (#213)

* Fix per-notifier error/warning count drift in dispatch chain

Snapshot ErrorCount, WarningCount and LogCategories into BackupStats once
at backup completion (finalizeBackupStats / parseFailedBackupLogCounts)
and have convertBackupStatsToNotificationData read them as-is. Re-parsing
the log file per-notifier was over-counting warnings emitted by earlier
notifiers in the dispatch chain, so e.g. Pushover reported 5 warnings
while Email reported 0 on the same run.

* Place issue snapshot at notification boundary

* Align exit code with notification snapshot

---------

Co-authored-by: tis24dev <github@tis24.it>

* Fix golangci-lint findings

* Format PBS API apply tests

* ci: bump github/codeql-action from 4.35.4 to 4.35.5 in the actions-updates group (#214)

ci: bump github/codeql-action in the actions-updates group

Bumps the actions-updates group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 4.35.4 to 4.35.5
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@68bde55...9e0d7b8)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.35.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions-updates
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Clarify dry-run stats finalization

Keep common backup finalization separate from dry-run issue parsing.

* Clarify issue exit code policy

Remove dead success handling and cover issue promotion rules.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Paolo Stivanin <paolostivanin@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@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.

2 participants