Skip to content

fix: brief timing double-send + DB deadlocks; add minute/day scheduling#16

Merged
Aarav261 merged 1 commit into
mainfrom
fix/brief-timing-minute-day-deadlock
Jun 29, 2026
Merged

fix: brief timing double-send + DB deadlocks; add minute/day scheduling#16
Aarav261 merged 1 commit into
mainfrom
fix/brief-timing-minute-day-deadlock

Conversation

@Aarav261

Copy link
Copy Markdown
Owner

Brief send-time was unreliable and could fire at two times a day.

Root causes:

  • The popup auto re-link on every open sent brief_hour (defaulting to 8), silently overwriting a custom hour in the DB.
  • schedule_brief used reschedule_job against the persistent jobstore, so a stale trigger left by an overlapping scheduler could survive alongside the new one — firing the brief at both the old and new time.

Fixes:

  • Stop the clobber: brief send-time fields are optional in /link-ontrack and preserved from the DB when absent; the auto re-link no longer sends them.
  • Make scheduling idempotent (remove-then-add → exactly one job per user) and reconcile orphan brief_* jobs on startup.

Feature — fully customizable send time:

  • New brief_minute + brief_dow columns (migrated on both PG and SQLite).
  • Settings UI: native HH:MM time picker + Mon-Sun day checkboxes.
  • schedule_brief honours hour, minute and day_of_week.

Deadlock fix:

  • The contended user row was updated by several separate transactions per request under concurrent extension traffic. Fold the Settings-panel writes into a single update_brief_prefs UPDATE, and add a retry-on-deadlock wrapper (Postgres 40P01/40001, SQLite "database is locked") on the write helpers.

Summary

Related issue

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation
  • Other:

Checklist

  • My branch is based on the latest main
  • ruff check . passes
  • pytest passes (if backend changes)
  • npm run lint passes in extension/ (if extension changes)
  • I added/updated tests where it makes sense
  • I did not commit secrets, .env files, tokens, or database files

Notes for reviewers

Brief send-time was unreliable and could fire at two times a day.

Root causes:
- The popup auto re-link on every open sent brief_hour (defaulting to 8),
  silently overwriting a custom hour in the DB.
- schedule_brief used reschedule_job against the persistent jobstore, so a
  stale trigger left by an overlapping scheduler could survive alongside the
  new one — firing the brief at both the old and new time.

Fixes:
- Stop the clobber: brief send-time fields are optional in /link-ontrack and
  preserved from the DB when absent; the auto re-link no longer sends them.
- Make scheduling idempotent (remove-then-add → exactly one job per user) and
  reconcile orphan brief_* jobs on startup.

Feature — fully customizable send time:
- New brief_minute + brief_dow columns (migrated on both PG and SQLite).
- Settings UI: native HH:MM time picker + Mon-Sun day checkboxes.
- schedule_brief honours hour, minute and day_of_week.

Deadlock fix:
- The contended user row was updated by several separate transactions per
  request under concurrent extension traffic. Fold the Settings-panel writes
  into a single update_brief_prefs UPDATE, and add a retry-on-deadlock wrapper
  (Postgres 40P01/40001, SQLite "database is locked") on the write helpers.
Copilot AI review requested due to automatic review settings June 29, 2026 10:19

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

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

@Aarav261 Aarav261 merged commit 6114a10 into main Jun 29, 2026
2 checks passed
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