Repository navigation
fix(attachments): send a file marker wrapped in markdown emphasis - #41
Conversation
940fbdb to
5f148b4
Compare
A reply written in bold produced `**<<file: /path/qr.png>**`, which the marker regex did not match because it required the line to start with `<<`. Three things failed at once: the file was not sent, the raw marker stayed in the chat, and nothing was reported, because a marker the regex never sees is a marker that cannot be rejected. Live: chat 749994884, 2026-11-12 23:08. The agent wrote a pairing QR in bold, the turn ended with no `file sent` and no `files rejected`, and the QR never arrived. The marker still has to be on its own line, so a path mentioned inside a sentence is still not a request to send it. Emphasis around it is now tolerated: bold, italic, underscore, and backtick.
5f148b4 to
565d531
Compare
The first fix covered emphasis only. Measured against the real wrappers, a marker inside a heading, blockquote, bullet, ordered list, strikethrough or bold-italic still matched nothing: the file was not sent, the raw marker stayed in the chat, and nothing was reported. A bullet is the likely shape for several files at once, so this was not a corner. The line still has to hold nothing but the marker. A leading `>`, `-` or `1.` is decoration only when the line ends after the marker, so a sentence that mentions the syntax does not upload the file it names. Measured: plain, bold, underscore-bold, italic, underscore-italic, backtick, bold-italic, strikethrough, H1, H3, blockquote, quote-plus-bullet, bullet, star bullet, ordered list, and a four-space indent all send. Prose before or after the marker, with or without decoration, sends nothing.
Correction: the first fix was too narrowMy first push to this branch covered emphasis only (
A bullet list is the shape a model reaches for when sending several files at once, so this was not a corner case. The line still has to contain nothing but the marker. A leading Tests
Red-proof, new tests against the old source: 9 failed, all of them wrapper cases. Full suite |
There was a problem hiding this comment.
Ran uv sync --extra dev, then uv run python -m pytest -q -W error::ResourceWarning (776 passed, 203 warnings in 55.43s) and uv run ruff check src tests scripts (clean).
Red proof: in a detached git worktree at main 59b5514, the PR's two new tests copied in and run against the old regex give 1 failed, 22 passed (test_a_marker_wrapped_in_emphasis_still_sends - AssertionError: ('**{}**', []), tests/test_attachments.py:207). On the head they pass, and a direct probe shows the old regex misses **<<file: ...>>** while the new one matches and captures the clean marker. The worktree was removed after.
Lab on Telegram (PR merged into main, @ompwire_bot): asked the bot to write a file and reply with the marker wrapped in **, then in backticks. Both turns logged file sent ... bytes=10, the document arrived in the chat, and no raw marker stayed behind; a follow-up sentence that merely explains <<file: ...>> sent nothing, as the own-line rule requires. Screenshot:
Could not test on WhatsApp: two lab_send attempts to the WhatsApp tester produced no turn start for that chat at all (the gateway log shows mode: mention for WhatsApp and no activity after 23:58). That looks like a lab environment issue, not this change; the marker code is shared, and the unit path is covered by the tests above.
Other reviewers: none listed.
Two non-blocking notes as inline comments: an empty <<file:>> is now swallowed silently where the old regex left it visible, and docs/guide.md plus ARCHITECTURE.md still describe the marker as bare. Neither holds the merge.
| # and left the raw marker in the chat with no warning (chat 749994884, 2026-11-12 23:08, a QR that | ||
| # never arrived). Measured wrappers: bold, italic, underscore, backtick, bold-italic, strikethrough, | ||
| # heading, blockquote, bullet list, and ordered list all send now. | ||
| # |
There was a problem hiding this comment.
The [^>\n]*? body allows an empty marker: **<<file:>>** and <<file:>> now match, are stripped from the reply, send nothing, and report nothing. On main the old regex left <<file:>> visible, so a reader could see the failure. The visible failure was the bug being fixed, but silent swallowing is a new quiet case, and unlike the QR case there is no residue to notice in the chat. +? instead of *? in the marker group keeps every behavior of this PR (verified: all 23 attachment tests pass with the change, and the emphasis probes still match) while letting an empty marker fall back to the old visible residue.
There was a problem hiding this comment.
Still open after 912836b: the marker group is still [^>\n]*?, so <<file:>> (bare or decorated) still matches, sends nothing, reports nothing, and is stripped silently. The probe I ran on the current head still returns a match. Folded into the new inline comment on line 33, since the +? change belongs to the same regex rewrite.
There was a problem hiding this comment.
Re-ran on the new head (912836b): uv run python -m pytest -q -W error::ResourceWarning gives 794 passed, 203 warnings in 55.18s, uv run ruff check src tests scripts clean. Lab on Telegram against the updated PR: a two-bullet reply sent both files (log: two tool done, then file sent ... bytes=12 and files rejected ***: tmp-list-marker.txt: Timed out, a Telegram upload timeout that the gateway reported in the chat, not a marker problem); a ## <<file: ...>> heading marker sent the file too. Screenshots:
Both earlier threads: the docs thread is settled, the comment now documents the measured wrappers at src/ompwire/attachments.py:24-32 and the tests cover the new cases (I resolve it). The empty-marker thread is not settled and is folded into the new blocking comment below: <<file:>> still matches and is still stripped silently, and the rewrite kept *?.
The new commit is blocked by one finding, in the inline comment: a single-decor line (- <<file: p>>, **<<file: p>>**, # <<file: p>>) sends, but combined decoration (- **<<file: p>>**, # **<<file: p>>**) matches nothing, which is the exact failure this PR exists to fix, just one decoration deeper. Probes on the committed regex return None for both lines.
| # | ||
| # A leading `>`, `-` or `1.` is only decoration when the line is nothing but the marker: the line | ||
| # still has to end after it, or `- <<file: p>> is a bad path` would send a file from prose. | ||
| DECOR = r"""(?:\*\*\*|\*\*|__|\*|_|`|~~|#{1,6}|\d+[.)]|[-*+])?""" |
There was a problem hiding this comment.
Combined decoration still fails: - **<<file: p>>** and # **<<file: p>>** match nothing, so the file is not sent and the raw marker stays, the exact failure this PR fixes one decoration deeper. The committed DECOR tries alternatives left to right and can apply once, so on - **<<file: p>>** it matches the bullet, then [ \t]* cannot eat **, and the marker group never starts; verified by probing the committed FILE_RE with both lines (None), while **<<file: p>>** alone matches. The parametrised tests cannot see this because every case wraps one decoration; add a "- **{}**" row and it fails. Two fixes, both verified by probe: order alternatives longest-first (\*\*\*|~~|#{1,6}|\d+[.)]|__|\*\*|\*|_||[-+]) in both the leading and trailing groups, which fixes {} tails, and let the leading decoration repeat ((?:DECOR[ \t]){0,2}?), which matches - <<file: p>>and# <<file: p>>while- <<file: p>> is the pathand<<file: p>> and more textstill stay unsent. While touching that line:[^>\n]*?still lets an empty<file:>match and be stripped silently (my earlier note, unresolved);+?` keeps this PR's behavior and falls back to visible residue.


The failure
Chat 749994884, 2026-11-12 23:08. The agent generated a pairing QR and wrote the marker like this:
attachments.FILE_RErequired the line to start with<<:The line starts with
**, so nothing matched. Three things failed from that one cause:file sentnever appears in the log for that turn)files rejectedwas also empty, because a marker the regex never sees is a marker that cannot be rejectedThe file itself was fine.
/home/pandu/tmp/orca-mobile-pair.pngexists, 2111 bytes, written at 23:08:02, and scans correctly.The fix
Markdown emphasis around the marker is tolerated, and the marker still has to be on its own line:
The path is then pulled from the captured
markergroup, so the emphasis is never part of the path.Own-line is still required on purpose. There is an existing test for it,
test_a_path_mentioned_in_a_sentence_is_not_sent: the agent sometimes explains the marker syntax to the person, and explaining<<file: ...>>inside a sentence must not upload the file it names. That test still passes.I first also stripped and reported markers that were off their own line or never closed. That broke the same test, and it was the wrong call: the live failure was never about position. That part is gone from the branch.
Tests
Four cases in
tests/test_attachments.py, red-proofed against the old regex:Full suite
776 passed,ruff check src testsclean.