Skip to content

fix(attachments): send a file marker wrapped in markdown emphasis - #41

Merged
pandudpn merged 2 commits into
mainfrom
fix/file-marker-emphasis
Nov 13, 2026
Merged

pandudpn merged 2 commits into
mainfrom
fix/file-marker-emphasis

Conversation

@pandudpn

Copy link
Copy Markdown
Owner

The failure

Chat 749994884, 2026-11-12 23:08. The agent generated a pairing QR and wrote the marker like this:

**<<file: /home/pandu/tmp/orca-mobile-pair.png>>**

**Pairing code (bisa dipaste manual):**

attachments.FILE_RE required the line to start with <<:

FILE_RE = re.compile(r"^[ \t]*<<\s*files?\s*:\s*(?P<body>[^>\n]+?)\s*>>", ...)

The line starts with **, so nothing matched. Three things failed from that one cause:

  • the QR was never sent (file sent never appears in the log for that turn)
  • the raw marker stayed in the chat, so the reply looked broken
  • nothing was reported: files rejected was also empty, because a marker the regex never sees is a marker that cannot be rejected

The file itself was fine. /home/pandu/tmp/orca-mobile-pair.png exists, 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:

EMPHASIS = r"(?:\*\*|__|\*|_|`)?"
FILE_RE = re.compile(
    rf"^[ \t]*{EMPHASIS}[ \t]*(?P<marker><<\s*files?\s*:[^>\n]*?>>)[ \t]*{EMPHASIS}",
    re.IGNORECASE | re.MULTILINE)

The path is then pulled from the captured marker group, 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:

test_a_marker_wrapped_in_emphasis_still_sends   FAILED
    assert [] == ['qr.png']
1 failed, 22 passed
  • bold, italic, underscore, and backtick wrapping all send the file and leave no residue in the text
  • a plain marker still works
  • a path mentioned inside a sentence is still not sent, and still produces no rejection

Full suite 776 passed, ruff check src tests clean.

@pandudpn pandudpn Bot added bug Something isn't working labels Nov 12, 2026
@pandudpn
pandudpn force-pushed the fix/file-marker-emphasis branch from 940fbdb to 5f148b4 Compare November 12, 2026 23:20
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.
@pandudpn
pandudpn force-pushed the fix/file-marker-emphasis branch from 5f148b4 to 565d531 Compare November 12, 2026 23:25
@pandudpn pandudpn Bot added the area:gateway Gateways and their systemd units label Nov 12, 2026
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.
@pandudpn

Copy link
Copy Markdown
Owner Author

Correction: the first fix was too narrow

My first push to this branch covered emphasis only (**, __, *, _, backtick). Measuring every real markdown wrapper against it showed the gap:

Wrapper Before this commit Now
plain, **bold**, __bold__, *italic*, _italic_, `code` sent sent
***bold-italic*** not sent sent
~~strike~~ not sent sent
# heading, ### heading not sent sent
> quote, > - quote+bullet not sent sent
- bullet, * bullet, 1. ordered not sent sent

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 >, - or 1. counts as decoration only when the line ends after the marker, so prose that mentions the syntax still uploads nothing:

here is <<file: p>>          -> no file
<<file: p>> is the path      -> no file
- <<file: p>> is the path    -> no file

Tests

tests/test_attachments.py now parametrises over all fifteen wrappers, plus four prose cases that must stay unsent.

Red-proof, new tests against the old source: 9 failed, all of them wrapper cases.

Full suite 794 passed, ruff check src tests clean.

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

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: Bold- and backtick-wrapped file markers send the file, no raw marker in chat

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.
#

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/ompwire/attachments.py Resolved

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

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: Bullet-list file markers send both files

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+[.)]|[-*+])?"""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pandudpn
pandudpn merged commit b2b6168 into main Nov 13, 2026
6 checks passed
@pandudpn
pandudpn deleted the fix/file-marker-emphasis branch November 13, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gateway Gateways and their systemd units bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant