Skip to content

Summoning heavenly logging to smite mismatches on priority assignment - #3046

Merged
jimleroyer merged 9 commits into
mainfrom
debug/high-priority-not-honored
Sep 10, 2026
Merged

jimleroyer merged 9 commits into
mainfrom
debug/high-priority-not-honored

Conversation

@jimleroyer

@jimleroyer jimleroyer commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Summary | Résumé

  • Code linter forced me to remove a dead conditional branch. Need 👀 on that one.
  • Added logging prior to get_delivery_queue_for_template function calls, to clear out if the template content is proper.
  • Added logging to choose_queue when the process_type wasn't present and the logic make an override decision.
  • Refactored the choose_queue function a bit.

Related Issues | Cartes liées

Test instructions | Instructions pour tester la modification

No regression with the unit-tests.

Release Instructions | Instructions pour le déploiement

None.

Reviewer checklist | Liste de vérification du réviseur

  • This PR does not break existing functionality.
  • This PR does not violate GCNotify's privacy policies.
  • This PR does not raise new security concerns. Refer to our GC Notify Risk Register document on our Google drive.
  • This PR does not significantly alter performance.
  • Additional required documentation resulting of these changes is covered (such as the README, setup instructions, a related ADR or the technical documentation).

⚠ If boxes cannot be checked off before merging the PR, they should be moved to the "Release Instructions" section with appropriate steps required to verify before release. For example, changes to celery code may require tests on staging to verify that performance has not been affected.

Comment thread app/notifications/process_notifications.py Fixed
Comment thread app/v2/notifications/post_notifications.py Fixed

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.

🟡 Changes recommended

Logging added in the cached-template code path dereferences relationships/hybrid properties that may not be safely available, and one new log is currently on an unreachable execution path.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds additional runtime logging around template routing/priority decisions and slightly refactors choose_queue’s fallback logic to make “no priority queue provided” behavior more explicit, in support of investigating queue/priority mismatches.

Changes:

  • Added info-level logs before queue selection / sending to capture template process-type and category-related routing inputs.
  • Refactored choose_queue to return priority_queue early and use a match fallback when it’s missing.
  • Added an additional log when choose_queue falls back due to a missing priority_queue.
File summaries
File Description
app/v2/notifications/post_notifications.py Adds a routing log (but currently placed on an unreachable path for simulated flow).
app/service/send_notification.py Adds routing log before get_delivery_queue_for_template for one-off notifications.
app/notifications/rest.py Adds routing log before sending to queue in the v1 notification endpoint.
app/notifications/process_notifications.py Adds routing logs in persistence paths and refactors choose_queue fallback logic.
Review details

Suppressed comments (1)

app/notifications/process_notifications.py:422

  • Same issue as persist_notification: this template is loaded with use_cache=True, but the log message dereferences template.template_category and template.process_type. That can trigger detached/lazy-load errors (or at least extra DB work) and make the debug output misleading when the relationship isn’t available from cached JSON.
        # TODO: Remove this logging statement once debugging is complete. It is useful for understanding how templates are routed to queues.
        current_app.logger.info(
            "persist_notifications: Routing template %s version %s: process_type_column=%r, "
            "effective_process_type=%r, category_id=%s, category_email_process_type=%r, category_sms_process_type=%r",
            template.id,
  • Files reviewed: 4/4 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread app/notifications/process_notifications.py
Comment thread app/notifications/process_notifications.py
Comment on lines +285 to +298
override_queue: str
match notification.notification_type:
case models.SMS_TYPE:
override_queue = QueueNames.SEND_SMS_MEDIUM
case models.EMAIL_TYPE:
override_queue = QueueNames.SEND_EMAIL_MEDIUM
case models.LETTER_TYPE:
override_queue = QueueNames.CREATE_LETTERS_PDF
case _:
raise ValueError(f"Could not determine queue for notification type {notification.notification_type!r}")

if override_queue is None:
raise ValueError(f"Could not determine queue for notification type {notification.notification_type!r}")
return override_queue
current_app.logger.info(
f"Notification {notification.id} had no priority queue; determined queue based on notification type and attributes to {override_queue}."
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That does not work, otherwise the variable in the match statement is considered like a capture variable for pattern matching.

Comment on lines +499 to +510
# TODO: Remove this logging statement once debugging is complete. It is useful for understanding how templates are routed to queues.
current_app.logger.info(
"process_sms_or_email_notification: Routing template %s version %s: process_type_column=%r, "
"effective_process_type=%r, category_id=%s, category_email_process_type=%r, category_sms_process_type=%r",
template.id,
template.version,
template.process_type_column,
template.process_type,
template.template_category_id,
template.template_category.email_process_type if template.template_category else None,
template.template_category.sms_process_type if template.template_category else None,
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes that seems right. I didn't add new logic here myself, but it wouldn't reach. I need a bit more clarity of mind and get back on this next week to know how to refactor, if we need to.

Comment thread app/v2/notifications/post_notifications.py Fixed
current_app.logger.info(
f"Batch saving: {notification_type}/{template.process_type} {notification['id']} sent to buffer queue."
)
else:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This would be a dead branch that isn't used. The first else could be activated, but not the inner condition if not simulated containing the business logic. Hence the whole parent condition is rendered useless.

@jimleroyer
jimleroyer enabled auto-merge (squash) September 10, 2026 19:56

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

OK! let's get those logs and see how it looks :)

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.

4 participants