Skip to content

fix: preserve scoped notification routing - #2469

Merged
yohamta0 merged 9 commits into
mainfrom
fix/notification-scoped-routing
Aug 1, 2026
Merged

yohamta0 merged 9 commits into
mainfrom
fix/notification-scoped-routing

Conversation

@yohamta0

@yohamta0 yohamta0 commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Summary

  • preserve the DAG filename and labels in persisted lifecycle events, including reopened and distributed attempts
  • use the filename only to find DAG-scoped notification and incident configuration
  • keep DAG runs, events, incident state, and incident deduplication keyed by the runtime DAG name
  • fail closed when workspace labels are malformed or ambiguous
  • carry source-file and label metadata through missing distributed sub-attempt recovery

Root cause

Notification and incident configuration is stored under the DAG file identifier, while DAG runs and lifecycle events use the runtime DAG name. Those values usually match, but YAML can declare a different name. Events did not retain the file identifier needed for scoped configuration lookup. Reconstructed attempts also lost their DAG metadata, and early distributed failures could replace persisted workspace labels with an empty set.

Impact

DAG-scoped settings now continue to apply when a YAML file declares a different runtime name. Workspace-scoped failures retain their routing boundary across coordinator recovery and cannot fall through to global routing because metadata was lost or invalid. Existing open incidents remain compatible because runtime-name state and dagu:v1 deduplication semantics are unchanged.

CI hardening

An earlier Windows run exposed two test-only lifecycle problems while the same PR commit passed on rerun. Scheduler lifecycle tests were waiting on an unrelated file-backed service registry before observing startup, and conformance cleanup could stop the parent Dagu process without owning its child process tree. The follow-up commit removes the registry dependency from those focused scheduler tests and uses the existing managed-process abstraction for conformance commands. No production behavior changed, and no timeouts or retries were added.

Validation

  • make test
  • make lint
  • focused incident, coordinator, worker, notification, event-store, and persistence package tests
  • repeated scheduler lifecycle tests
  • repeated human-task cleanup regression
  • complete human-task conformance package

Closes #2467

Summary by CodeRabbit

  • Improvements
    • DAG labels and source-file metadata are preserved across task execution, status updates, event snapshots, and queued notifications.
    • Notifications and incident policies route more accurately using DAG file and runtime name information.
    • Status reporting provides more complete task metadata.
  • Bug Fixes
    • Invalid or ambiguous workspace labels are rejected to prevent misrouted notifications and incidents.
    • Reopened and reconstructed DAG runs retain associated metadata.
    • Existing incident policies are preserved when resolving events without a policy ID.

Copilot AI review requested due to automatic review settings July 31, 2026 17:09

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6bd33177-5d9f-4e1a-adf3-3050d8cb9bb8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

DAG files and workspace labels now persist from task and attempt status through event snapshots and notification events. Notification and incident services use DAGKey() for scoped matching and state updates. The conformance harness uses managed process shutdown.

Changes

Event metadata and routing

Layer / File(s) Summary
Status metadata propagation
proto/coordinator/..., internal/service/coordinator/..., internal/service/worker/...
Coordinator and worker status reports preserve DAG source files and labels. Missing sub-attempts retain this metadata.
Persisted run metadata
internal/persis/file/dagrun/..., internal/service/eventstore/...
Reopened attempts recover DAG definitions. Status snapshots preserve workspace labels through serialization and restoration.
Notification event metadata
internal/service/chatbridge/...
NotificationEvent stores DAGFile, exposes DAGKey(), and preserves complete cloned events during queueing and restart delivery.
Notification routing by DAG key
internal/service/notification/...
Notification matching uses DAGKey() and validated workspace labels for DAG, workspace, subscription, and route settings.
Incident identity and validation
internal/service/incident/...
Incident policy lookup, resolution, and deduplication use DAG keys. Invalid workspace labels are rejected.

Managed process lifecycle

Layer / File(s) Summary
Managed process startup and shutdown
conformance/harness/runner.go
The harness starts commands through cmdutil.ManagedProcess, waits for completion, releases processes, and performs one-time forced shutdown.

Scheduler test isolation

Layer / File(s) Summary
Clear scheduler services
internal/service/scheduler/scheduler_test.go
Scheduler setup clears the service registry for tests without registered DAG services.

Filesystem identity validation

Layer / File(s) Summary
Source-file identity assertions
internal/intg/reschedule_source_file_api_test.go
Reschedule tests compare source files by filesystem identity instead of path-string equality.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Worker
  participant Coordinator
  participant EventStore
  participant NotificationEvent
  participant NotificationService
  Worker->>Coordinator: reports source file and labels
  Coordinator->>EventStore: persists status metadata
  EventStore->>NotificationEvent: supplies DAG file and labels
  NotificationEvent->>NotificationService: provides DAGKey()
  NotificationService-->>NotificationEvent: returns matching scoped destinations
Loading

Possibly related PRs

  • dagucloud/dagu#2346: Both changes modify missing sub-attempt bootstrap and coordinator status reporting.
  • dagucloud/dagu#2380: Both changes modify coordinator status reporting and worker status pushers.
🚥 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
Title check ✅ Passed The title clearly describes the primary change: preserving scoped notification routing.
Description check ✅ Passed The description clearly explains the changes, root cause, impact, linked issue, and validation performed.
Linked Issues check ✅ Passed The changes preserve DAG metadata and use it for scoped notification matching, addressing issue #2467.
Out of Scope Changes check ✅ Passed The CI hardening changes are explicitly documented and remain limited to test lifecycle and process cleanup.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/notification-scoped-routing

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.

@yohamta0
yohamta0 marked this pull request as ready for review July 31, 2026 17:09
@yohamta0

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

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.

Copilot AI review requested due to automatic review settings July 31, 2026 17:40

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@yohamta0

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

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.

Copilot AI review requested due to automatic review settings August 1, 2026 01:31
@yohamta0

yohamta0 commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

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.

Copilot AI 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.

Pull request overview

Copilot reviewed 20 out of 22 changed files in this pull request and generated no new comments.

Files not reviewed (2)
  • proto/coordinator/v1/coordinator.pb.go: Generated file
  • proto/coordinator/v1/coordinator_protoopaque.pb.go: Generated file

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

🧹 Nitpick comments (1)
internal/service/incident/service_test.go (1)

238-283: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert PolicyID preservation to directly cover the fix.

This test correctly validates that resolution keys off event.Status.Name ("daily") rather than event.DAGFile ("daily-file"). Since internal/service/incident/service.go Line 625 to Line 627 now preserves the existing PolicyID instead of always overwriting it, add an assertion that state.PolicyID still equals "existing-policy" after Line 282. This directly verifies the behavior that motivated that change.

✅ Proposed assertion addition
 	state, err = store.GetState(context.Background(), provider.ID, "existing-dedup-key")
 	require.NoError(t, err)
 	assert.Equal(t, incidentmodel.IncidentStatusResolved, state.Status)
+	assert.Equal(t, "existing-policy", state.PolicyID)
 }
🤖 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 `@internal/service/incident/service_test.go` around lines 238 - 283, Extend
TestServiceResolvesRuntimeNameIncidentWithDAGFileRouting to assert that the
resolved state retains the existing PolicyID value "existing-policy" after
retrieving it with GetState. Keep the assertion alongside the existing status
verification.
🤖 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.

Nitpick comments:
In `@internal/service/incident/service_test.go`:
- Around line 238-283: Extend
TestServiceResolvesRuntimeNameIncidentWithDAGFileRouting to assert that the
resolved state retains the existing PolicyID value "existing-policy" after
retrieving it with GetState. Keep the assertion alongside the existing status
verification.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cff73517-beb8-419a-aae8-178bfe6f4c30

📥 Commits

Reviewing files that changed from the base of the PR and between 9cd2f4f and c9671e2.

⛔ Files ignored due to path filters (2)
  • proto/coordinator/v1/coordinator.pb.go is excluded by !**/*.pb.go
  • proto/coordinator/v1/coordinator_protoopaque.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (8)
  • internal/service/coordinator/handler.go
  • internal/service/coordinator/handler_test.go
  • internal/service/incident/service.go
  • internal/service/incident/service_test.go
  • internal/service/worker/coordreport/status_pusher.go
  • internal/service/worker/coordreport/status_pusher_test.go
  • internal/service/worker/remote_handler.go
  • proto/coordinator/v1/coordinator.proto

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 22 files

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

Re-trigger cubic

Comment thread internal/service/incident/service.go Outdated
Comment thread internal/persis/file/dagrun/attempt.go Outdated
Copilot AI review requested due to automatic review settings August 1, 2026 01:53
@yohamta0

yohamta0 commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

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.

@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

🧹 Nitpick comments (1)
internal/persis/file/dagrun/attempt.go (1)

175-182: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Add tests for successful DAG restoration.

TestAttempt_OpenRejectsCorruptDAGDefinition covers only the error path. Add tests that reopen an attempt with a valid DAGDefinition and verify that the persisted DAG metadata is restored. Also verify that a missing DAGDefinition remains non-fatal.

🤖 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 `@internal/persis/file/dagrun/attempt.go` around lines 175 - 182, Add tests
around Attempt.Open and the ReadDAG restoration branch covering a valid
persisted DAGDefinition, asserting reopened attempts restore the DAG metadata,
plus a missing DAGDefinition case that remains non-fatal. Keep the existing
corrupt-definition rejection test unchanged and use the established attempt/DAG
fixtures and assertions.
🤖 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/intg/reschedule_source_file_api_test.go`:
- Around line 81-84: Update requireSameFile to use fileutil.Stat for both
expected and actual paths instead of os.Stat, preserving the existing error
assertions and subsequent os.SameFile comparison.

---

Nitpick comments:
In `@internal/persis/file/dagrun/attempt.go`:
- Around line 175-182: Add tests around Attempt.Open and the ReadDAG restoration
branch covering a valid persisted DAGDefinition, asserting reopened attempts
restore the DAG metadata, plus a missing DAGDefinition case that remains
non-fatal. Keep the existing corrupt-definition rejection test unchanged and use
the established attempt/DAG fixtures and assertions.
🪄 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: CHILL

Plan: Pro Plus

Run ID: 6b3c1733-6d2c-46c0-8f7e-72acaea6668e

📥 Commits

Reviewing files that changed from the base of the PR and between c9671e2 and 6b3fd24.

📒 Files selected for processing (4)
  • internal/intg/reschedule_source_file_api_test.go
  • internal/persis/file/dagrun/attempt.go
  • internal/persis/file/dagrun/attempt_test.go
  • internal/service/incident/service_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/persis/file/dagrun/attempt_test.go
  • internal/service/incident/service_test.go

Comment thread internal/intg/reschedule_source_file_api_test.go Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 21 out of 23 changed files in this pull request and generated no new comments.

Files not reviewed (2)
  • proto/coordinator/v1/coordinator.pb.go: Generated file
  • proto/coordinator/v1/coordinator_protoopaque.pb.go: Generated file
Suppressed comments (1)

conformance/harness/runner.go:162

  • Process.Stop ignores the ManagedProcess.Stop error/outcome. If the stop request fails (e.g., process-tree termination issues on Windows), the test harness may leak a running dagu process and still proceed as if cleanup succeeded. Consider at least surfacing the error (and optionally logging partial outcomes) so CI flakes are diagnosable.
		_, _ = p.proc.Stop(cmdutil.StopRequest{
			Intent: cmdutil.ForceTermination(),
			Reason: cmdutil.StopReasonShutdown,
		})
	})

Copilot AI review requested due to automatic review settings August 1, 2026 02:03
@yohamta0

yohamta0 commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

Review follow-up: I did not add duplicate DAG restoration tests. TestAttempt_Open already proves a missing dag.json remains non-fatal, and TestAttempt_OpenRestoresLastEmittedLifecycleState reopens a valid persisted definition and verifies the restored DAG file in the emitted snapshot. The new corrupt-definition test covers the only previously missing branch.

@yohamta0

yohamta0 commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

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.

Copilot AI 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.

Pull request overview

Copilot reviewed 21 out of 23 changed files in this pull request and generated no new comments.

Files not reviewed (2)
  • proto/coordinator/v1/coordinator.pb.go: Generated file
  • proto/coordinator/v1/coordinator_protoopaque.pb.go: Generated file

Copilot AI review requested due to automatic review settings August 1, 2026 03:26

Copilot AI 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.

Pull request overview

Copilot reviewed 25 out of 27 changed files in this pull request and generated no new comments.

Files not reviewed (2)
  • proto/coordinator/v1/coordinator.pb.go: Generated file
  • proto/coordinator/v1/coordinator_protoopaque.pb.go: Generated file

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 6 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="internal/service/incident/service.go">

<violation number="1" location="internal/service/incident/service.go:368">
P1: A transient `ListOpenStates` failure drops canonical state destinations, so the monitor prunes pending recovery batches instead of retrying them after storage recovers. Preserve the last successfully discovered state destinations (or otherwise avoid reconciliation/removal when this lookup fails).</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

}
}
}
states, err := s.store.ListOpenStates(ctx)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: A transient ListOpenStates failure drops canonical state destinations, so the monitor prunes pending recovery batches instead of retrying them after storage recovers. Preserve the last successfully discovered state destinations (or otherwise avoid reconciliation/removal when this lookup fails).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/service/incident/service.go, line 368:

<comment>A transient `ListOpenStates` failure drops canonical state destinations, so the monitor prunes pending recovery batches instead of retrying them after storage recovers. Preserve the last successfully discovered state destinations (or otherwise avoid reconciliation/removal when this lookup fails).</comment>

<file context>
@@ -365,6 +365,16 @@ func (s *Service) NotificationDestinations() []string {
 			}
 		}
 	}
+	states, err := s.store.ListOpenStates(ctx)
+	if err != nil {
+		s.logger.Warn("Failed to list open incident destinations", slog.String("error", err.Error()))
</file context>

Copilot AI review requested due to automatic review settings August 1, 2026 03:53

Copilot AI 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.

Pull request overview

Copilot reviewed 25 out of 27 changed files in this pull request and generated no new comments.

Files not reviewed (2)
  • proto/coordinator/v1/coordinator.pb.go: Generated file
  • proto/coordinator/v1/coordinator_protoopaque.pb.go: Generated file

@yohamta0
yohamta0 merged commit ac25869 into main Aug 1, 2026
12 checks passed
@yohamta0
yohamta0 deleted the fix/notification-scoped-routing branch August 1, 2026 04:14
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.

bug: Workspace- and DAG-scoped notification rules never match real DAG run events

2 participants