Skip to content

fix(notetaker): match the partial jobs index in enqueueJob's upsert - #185

Merged
shockalotti merged 1 commit into
Calnode:mainfrom
MohammadHadi2031:fix/notetaker-enqueue
Oct 29, 2026
Merged

shockalotti merged 1 commit into
Calnode:mainfrom
MohammadHadi2031:fix/notetaker-enqueue

Conversation

@MohammadHadi2031

Copy link
Copy Markdown
Contributor

Fixes #184

  • ON CONFLICT(type, payload) WHERE status IN ('pending','running'), matching the index.
  • DO UPDATE … WHERE jobs.status = 'pending': a pending duplicate is pulled forward, a running one is left alone. Finished jobs no longer conflict, so a regenerate inserts a fresh run, which is what the old full-index behaviour amounted to.

Tests: TestEnqueueJob_upsertsLiveJobsAndRequeuesFinishedOnes covers first enqueue, pending duplicate, re-run after done, and duplicate while running. It fails on main with the error above.

Migration 00065 replaced UNIQUE(type, payload) on jobs with a partial index
over live jobs (status IN ('pending','running')). SQLite only accepts a
partial index as an ON CONFLICT target when the clause repeats its WHERE, so
enqueueJob's bare ON CONFLICT(type, payload) has failed to prepare since then:
"ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint".
Every notetaker transcribe/summarize enqueue errored.

Repeat the predicate, and only refresh a *pending* duplicate: the old DO
UPDATE would also have reset a running job to pending and run it twice.
Finished jobs no longer conflict, so a regenerate inserts a fresh run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 19:34

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.

🟢 Approval recommended

No active review issues remain for the change aligning notetaker job enqueueing with the partial unique index.

No open issues 🎉

What changed in this PR

Fixes #184 by aligning notetaker job enqueueing with the partial unique index introduced in migration 00065, restoring transcription and summarization scheduling.

Changes:

  • Matches the upsert conflict target to the index’s pending/running predicate.
  • Pulls pending duplicates forward, leaves running jobs unchanged, and inserts fresh jobs after completion.
  • Adds regression coverage for initial enqueue, pending duplicates, completed-job requeueing, and running duplicates.
File Description
internal/​handler/​notetaker.go Corrects the upsert and documents job deduplication behavior.
internal/​handler/​notetaker_enqueue_internal_test.go Adds regression tests for enqueueing across job states.

Review effort: Balanced

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

✅ No new issues found.

Reviewed changes

  • enqueueJob conflict target — repeats the partial index predicate (WHERE status IN ('pending','running')) so SQLite actually uses ux_jobs_type_payload_live; the bare target failed to prepare from migration 00065 onward.
  • Live duplicate semantics — DO UPDATE … WHERE jobs.status = 'pending' pulls a pending duplicate forward while leaving a running one untouched, closing the double-run the old status = 'pending' reset caused.
  • Finished-job re-enqueue — done/failed rows no longer conflict, so a regenerate inserts a fresh run instead of resurrecting history.
  • Regression test — TestEnqueueJob_upsertsLiveJobsAndRequeuesFinishedOnes covers first enqueue, pending duplicate, re-run after done, and duplicate-while-running.

Verified: the new test and the full ./internal/handler/ suite pass, go vet and gofmt are clean. Other job producers are unaffected (reminders use INSERT OR IGNORE, webhook jobs carry a unique delivery id), and no query assumes cross-status uniqueness on (type, payload).

One non-blocking observation: because a running duplicate is now a silent no-op, a second recording finalizing for the same booking while a notetaker.summarize is already running would not queue another summarize. That matches the PR's stated tradeoff and needs two recordings on one booking within a tight window; the manual regenerate path calls summarizeBooking directly and is unaffected.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash | 𝕏

@shockalotti
shockalotti merged commit 0ec5711 into Calnode:main Oct 29, 2026
9 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.

Every notetaker transcribe/summarize enqueue fails: "ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint"

3 participants