Work in /Users/userc042661f/Documents/banodoco-workspace/brain-of-bndc. You are not…
- User
Work in /Users/user_c042661f/Documents/banodoco-workspace/brain-of-bndc. You are not alone in the codebase: another megaplan execution may have edited TopicEditor and tests, so do not revert unrelated changes and keep your write scope narrow. Task: fix the specific bug where the same YouTube/embed media ref can be sent three times when multiple structured blocks contain the same media_ref. First inspect current code to see whether this is already fixed. Relevant files: src/features/summarising/topic_editor.py, tests/test_topic_editor_core.py, tests/test_topic_editor_runtime.py. Desired behavior: structured publishing/rendering should not emit duplicate media units for the same resolved URL/ref across a topic; keep the first occurrence only. Also block-level validation should reject media_refs whose message_id is not in that block's source_message_ids, so a block cannot attach media from a source it did not cite. Add/update focused tests proving: (1) repeated identical embed refs across blocks render/send only once, (2) a media_ref whose message_id is not in the block source ids is rejected/removed/audited according to existing validation patterns, and (3) existing attachment/embed behavior still works. If the current code already implements this correctly, do not edit; report where. If you edit, list exact files changed and tests run.
- Assistant
I’ll inspect the topic editor and the two test files first, then only patch the smallest surface if the duplicate/ref validation behavior is missing. I’ll also check git state so I can avoid touching unrelated work.
- Assistant
There are already dirty changes in the exact files the task names, so I’m treating them as shared work and reading before editing. The first pass shows media rendering and validation both live in
topic_editor.py; I’m narrowing onto those functions now. - Assistant
The bug is not fully fixed. Rendering currently appends every block media ref that resolves, and validation only checks that the referenced message exists, not that the block cited that message. I’m going to add URL/ref dedupe in the render path and a narrow validation check in the existing
invalid_media_refpattern. - Assistant
The code changes are in place: render-time dedupe is keyed by resolved URL, and block validation now rejects a resolved media ref if its message is not cited by that same block. I added one core render/send test and one runtime validation test, leaving the existing attachment/embed tests intact.
- Assistant
The full two-file run hit one unrelated existing failure in
test_acquire_topic_editor_run_expires_stale_running_lease: it expectsfailed, but the current storage code returnsexpired. I’m running the focused topic-editor tests for this change now so the verification is cleanly scoped. - Assistant
Fixed. The current code had both gaps: structured rendering emitted every duplicate resolved media URL, and block media validation did not require the media ref’s
message_idto be in that block’ssource_message_ids.Changed:
- topic_editor.py: reject resolved media refs whose is not cited by the same block, using existing rejection/audit flow.