Skip to content

feat: new risk jobs#344

Open
gusfcarvalho wants to merge 16 commits intomainfrom
codex/plan-bch1183-risk-jobs
Open

feat: new risk jobs#344
gusfcarvalho wants to merge 16 commits intomainfrom
codex/plan-bch1183-risk-jobs

Conversation

@gusfcarvalho
Copy link
Contributor

@gusfcarvalho gusfcarvalho commented Mar 10, 2026

Summary

  • introduce RiskConfig/risk.yaml and load it separately so risk scheduling stays outside workflow config
  • add the risk scanners, workers, and notifications (including new riskNotificationsSubscribed preference) outlined in BCH-1183
  • update templates, docs, and tests to cover the new config, jobs, and subscription behavior

Testing

  • make reviewable passes successfully

Copilot AI review requested due to automatic review settings March 10, 2026 10:41
@gusfcarvalho gusfcarvalho changed the title Add dedicated risk config and wire new risk jobs feat: new risk jobs Mar 10, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a dedicated RiskConfig/risk.yaml configuration file and wires up a set of new risk lifecycle periodic jobs (scanner workers and notification workers). It also adds a new riskNotificationsSubscribed user preference with opt-out semantics for risk emails.

Changes:

  • Add RiskConfig with LoadRiskConfig/Validate, loaded separately from workflow config, with support for env vars and a risk.yaml file
  • Add four scanner workers (RiskReviewDeadlineReminderScanner, RiskReviewOverdueEscalationScanner, RiskStaleRiskScanner, RiskEvidenceReconciliationScanner) and their corresponding notification/action workers
  • Add RiskNotificationsSubscribed boolean field (default true) to the User model and propagate it through the API handler and subscription endpoint

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
risk.yaml Default sample config file for risk job scheduling, all jobs disabled by default
internal/config/risk.go New RiskConfig type with LoadRiskConfig, DefaultRiskConfig, and Validate
internal/config/config.go Loads RiskConfig from risk.yaml and attaches to Config.Risk
internal/config/risk_test.go Tests for default values, env override, file loading, and validation
internal/service/worker/risk_workers.go All new scanner and notification worker implementations
internal/service/worker/risk_job_types.go River job arg types, Kind()/Timeout() implementations, and insert option helpers
internal/service/worker/risk_workers_test.go Tests for scanner enqueue behavior, duplicate closing, reopen logic, and subscription gating
internal/service/worker/service.go Registers scanner workers and periodic jobs driven by RiskConfig
internal/service/worker/service_test.go Test that risk periodic jobs are created from dedicated RiskConfig
internal/service/worker/jobs.go Registers new notification/reopen workers, adds RiskNotificationsSubscribed to NotificationUser
internal/service/worker/user_repository.go Maps RiskNotificationsSubscribed from DB user to NotificationUser
internal/service/relational/ccf_internal.go Adds RiskNotificationsSubscribed bool with gorm:"default:true" to User
internal/api/handler/users.go Adds RiskNotificationsSubscribed to subscription get/update endpoints
internal/api/handler/users_integration_test.go Integration tests for the new subscription field
internal/service/email/templates/templates/*.html/txt Three new email templates for risk notifications
internal/service/email/templates/service_test.go Tests that all three new templates render without errors
docs/swagger.json, docs/swagger.yaml, docs/docs.go Updated API docs for the new subscription field
.env.example Documents the CCF_RISK_CONFIG env var

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

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 26 out of 26 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

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 28 out of 28 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

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 28 out of 28 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

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 28 out of 28 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

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 28 out of 28 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

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 28 out of 28 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

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 28 out of 28 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

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 28 out of 28 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

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 28 out of 28 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 10, 2026 15:52
Copy link
Contributor

Copilot AI left a comment

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 28 out of 28 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gusfcarvalho gusfcarvalho requested review from Copilot and removed request for Copilot March 10, 2026 16:50
Copy link
Contributor

Copilot AI left a comment

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 28 out of 28 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

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 28 out of 28 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

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 29 out of 29 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

riskIDs := make([]uuid.UUID, 0, len(risks))
for i := range risks {
risk := &risks[i]
if risk == nil || risk.ID == nil {
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The risk == nil guard on line 549 is dead code. The function receives risks []riskrel.Risk (a slice of value types, not pointer types), so elements retrieved via &risks[i] can never be nil. While this doesn't cause a bug, it is misleading since it implies a condition that can never occur.

Suggested change
if risk == nil || risk.ID == nil {
if risk.ID == nil {

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +66
&riskrel.RiskSubjectLink{},
&riskrel.RiskEvent{},
&riskrel.RiskReview{},
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

Lines 64–66 use extra indentation (\t\t\t) compared to the preceding lines 53–63 (\t\t), making the argument list of db.AutoMigrate(...) inconsistently formatted. All arguments should be at the same indentation level.

Suggested change
&riskrel.RiskSubjectLink{},
&riskrel.RiskEvent{},
&riskrel.RiskReview{},
&riskrel.RiskSubjectLink{},
&riskrel.RiskEvent{},
&riskrel.RiskReview{},

Copilot uses AI. Check for mistakes.
continue
}
ownerIDs := ownersByRiskID[*risk.ID]
overdueWindow := now.Format("2006-01-02")
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The overdueWindow variable is declared inside the for i := range risks loop on line 141, but it always evaluates to the same value — now.Format("2006-01-02") — regardless of which risk is being processed. Since now is defined at the start of the outer Work function and never changes, this can be computed once before the loop (or even before the batch callback) to avoid the redundant formatting call on every iteration.

Copilot uses AI. Check for mistakes.
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