fix(2.0.24): store slug (not numeric id) on patterns created from corrections#196
Open
ttlequals0 wants to merge 2 commits intomainfrom
Open
fix(2.0.24): store slug (not numeric id) on patterns created from corrections#196ttlequals0 wants to merge 2 commits intomainfrom
ttlequals0 wants to merge 2 commits intomainfrom
Conversation
src/api/patterns.py wrote str(podcast['id']) into ad_patterns.podcast_id on the confirm and boundary_adjustment correction paths, while every other creation site and the detection-side query (get_ad_patterns(podcast_id=slug)) use the slug. Patterns created via a user correction were scoped to a value the matcher never queries with, so they were silently orphaned -- never retrieved during detection on subsequent episodes. Use the slug at both call sites, matching the ap.podcast_id = p.slug join the rest of the schema assumes. https://claude.ai/code/session_01Cqt4uejLMshs1CQyBWNbQD
- Bump version.py and openapi.yaml to 2.0.24 (CLAUDE.md requires version update for behavioral changes). - Replace [Unreleased] CHANGELOG section with [2.0.24] - 2026-05-05. - Add tests/unit/test_correction_pattern_scope.py: pins both correction paths (confirm and adjust with no existing pattern_id) so they cannot regress to writing the numeric podcasts.id into ad_patterns.podcast_id. Also pins the find_pattern_by_text dedup lookup to use the slug.
16e0c34 to
39dd329
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/api/patterns.pywritesstr(podcast['id'])intoad_patterns.podcast_idon two correction paths:submit_correctionwithcorrection_type=confirmand no existingpattern_id(src/api/patterns.py:445)submit_correctionwithcorrection_type=adjustand no existingpattern_id(src/api/patterns.py:556)Every other creation site stores the slug:
ad_detector.learn_from_detections->text_pattern_matcher.create_pattern_from_ad(podcast_id=podcast_id)where the caller inmain_app/processing.py:297passes the slugpattern_serviceverification-miss auto-create ->podcast_id=slug(src/pattern_service.py:784)And the detection-side query is
get_ad_patterns(podcast_id=podcast_slug)(src/ad_detector.py:1259), backed byap.podcast_id = p.slug(src/database/patterns.py:17, plus the comment "podcast_id stores slugs since v0.1.194").Net effect: a pattern auto-created from a user
confirmor boundary adjustment is scoped to a value the matcher never queries with. The pattern is silently orphaned -- it will never match on subsequent episodes, so the system fails to learn from exactly the corrections users put the most thought into.Fix
Both call sites now store the slug instead of the numeric id:
The
db.get_podcast_by_slug(slug)lookup is preserved so the existence guard still rejects creation when the slug doesn't resolve.Version + tests (added)
version.pyandopenapi.yamlbumped to2.0.24; CHANGELOG[Unreleased]rolled into[2.0.24] - 2026-05-05.tests/unit/test_correction_pattern_scope.py(new): three tests pinning both correction paths and thefind_pattern_by_textdedup lookup so they can't regress to writing the numeric id.Migration note for existing data
Operators with patterns already created via the corrections UI will have rows where
ad_patterns.podcast_idis a numeric string ("3","7", ...) instead of a slug. These rows are inert -- detection can't find them. They can be repaired with a one-shot UPDATE that joins back topodcasts.id:Not bundled in this PR -- the fix stops the bleeding; data repair is operator-driven and depends on whether the operator wants to keep, merge, or discard the orphaned rows.
Test plan
confirmcorrection on an episode where nopattern_idis sent, then verify the newad_patternsrow haspodcast_idequal to the slugget_ad_patterns(podcast_id=slug)and counted inlast_matched_atlearn_from_detectionsand verification-miss paths unchanged