Skip to content

fix(media): split prose fused onto a MEDIA: path so the attachment still lands - #129

Merged
Willi8910 merged 3 commits into
boonfrom
eng-18014-media-directive-glue
Aug 20, 2026
Merged

Willi8910 merged 3 commits into
boonfrom
eng-18014-media-directive-glue

Conversation

@Willi8910

@Willi8910 Willi8910 commented Aug 14, 2026 •

Copy link
Copy Markdown

Linear: https://linear.app/getboon/issue/ENG-18014
Companion PR (boon-core, defense-in-depth): https://github.com/getboon/boon/pull/14026

What problem this solves

A customer asked the agent for a generated spreadsheet. The agent built it and emitted the delivery directive, but no attachment arrived and a raw server path rendered in chat.

The system prompt requires MEDIA:<path> on its own line. When the model forgets the newline the prose fuses onto the path (…Bid_Form.xlsxHere's the earthwork). MEDIA_TOKEN_RE captures greedily to end-of-line, so the fused run becomes the "path", resolves to nothing, and no attachment is produced. Worse, the existing "local path containing spaces" fallback re-joined the whitespace-split parts, rebuilding the very path that had just failed to resolve.

Confirmed in production (org 554, thread 800): a directive on its own line attached a 363 KB workbook; the fused one attached nothing.

Why this change

Re-split the first token at a known media extension via mimeTypeFromFilePath, so the extension vocabulary stays sourced from media-core rather than duplicated. All three spaced-path fallbacks are suppressed only when a split occurred, so /Users/pete/My File.png is untouched. Invalid parts are already re-emitted downstream, so the prose survives as visible text.

The boundary search takes the full alphanumeric run after a dot as the candidate extension: if that run is itself known, nothing is fused on and the dot is skipped. Testing prefixes instead truncates .xlsx → .xls (and .docx/.pptx/.html likewise) whenever punctuation or a serialized-JSON suffix follows — dropping the attachment and leaking the tail as visible text, i.e. reintroducing this exact bug on the Office formats the ticket is about. The scan runs right-to-left because the real extension is the rightmost one (report.pdf2024.xlsxHere must split at .xlsx, not .pdf).

User impact

An agent that fuses prose onto a MEDIA: path now still delivers the file, and the prose renders as normal text instead of the path leaking.

Evidence

  • node scripts/run-vitest.mjs src/media/parse.test.ts — 69 passing (+10), including .xlsx/.docx/.pptx/.html with JSON suffixes, trailing punctuation, the backtick-wrapped form, rightmost-extension ordering, and a fused URL.
  • node scripts/run-tsgo.mjs -p tsconfig.core.json — clean.
  • node --import tsx scripts/check-import-cycles.ts — 0 runtime value cycles.
  • npx oxlint src/media/parse.ts src/media/parse.test.ts — clean.
  • Independent code review; its Critical finding was the .xlsx→.xls truncation above, now fixed and covered by the four new table rows.

Known limitation

Only the first whitespace-delimited token is examined, so prose fused onto a path that itself contains spaces is still unsplit — unchanged from before this PR, stated so it isn't mistaken for broader coverage.

🤖 Generated with Claude Code


Summary by cubic

Fixes missing attachments when the model emits MEDIA:<path> fused with prose. Previously the fused run became the path and failed to resolve; now we split at a known media extension, deliver the file, and render the fused prose as normal text. Also rejects directory-name false boundaries, stops at the rightmost real extension, and allows attaching fused bare filenames. Addresses Linear ENG-18014.

  • Splits only when the first token contains a known media extension (via mimeTypeFromFilePath from @openclaw/media-core/mime), scanning right-to-left over the full alphanumeric run; if that run is itself a known extension or the remainder contains a path separator, do not split, and never walk left past a rightmost known extension; avoids prefix truncation (.xlsx/.docx/.pptx/.html).
  • After a split, validates the media half (allowing a bare filename), emits the remainder as text, and suppresses spaced-path fallbacks; quoted paths are never re-split, and existing spaced-path behavior is unchanged otherwise.
  • Adds tests for Office formats with punctuation/JSON suffixes, rightmost-extension stop, dotted directories, multi-suffix bare filenames, and fused URLs.

Written for commit 30c163b. Summary will update on new commits.

Review in cubic

…ill lands

Linear: https://linear.app/getboon/issue/ENG-18014

The system prompt requires `MEDIA:<path>` on its own line, but when the model
forgets the newline the prose fuses onto the path ("…Bid_Form.xlsxHere's the
earthwork"). MEDIA_TOKEN_RE captures greedily to end-of-line, so the fused run
becomes the "path", resolves to nothing, and NO attachment is produced — the raw
server path then reaches the user. Worse, the existing "local path containing
spaces" fallback re-joined the split parts, rebuilding the very path that had
just failed to resolve.

Re-split the first token at a known media extension (via mimeTypeFromFilePath,
so the extension vocabulary stays sourced from media-core) and suppress all
three spaced-path fallbacks when a split occurred, so "/Users/pete/My File.png"
is untouched. Invalid parts are already re-emitted downstream, so the prose
survives as visible text.

The boundary search takes the FULL alphanumeric run after a dot as the candidate
extension: if that run is itself known, nothing is fused on and the dot is
skipped. Testing prefixes instead truncates `.xlsx` to `.xls` (and
`.docx`/`.pptx`/`.html` likewise) whenever punctuation or a serialized-JSON
suffix follows — which would drop the attachment and leak the tail as visible
text, reintroducing this very bug on the Office formats the ticket is about. The
scan runs right-to-left because the real extension is the rightmost one
("report.pdf2024.xlsxHere" must split at .xlsx, not .pdf).

Evidence:
- node scripts/run-vitest.mjs src/media/parse.test.ts — 69 passing (+10), incl.
  .xlsx/.docx/.pptx/.html with JSON suffixes, trailing punctuation, the
  backtick-wrapped form, rightmost-extension ordering, and a fused URL.
- node scripts/run-tsgo.mjs -p tsconfig.core.json — clean.
- node --import tsx scripts/check-import-cycles.ts — 0 runtime value cycles.
- npx oxlint src/media/parse.ts src/media/parse.test.ts — clean.

Known limitation: only the first whitespace-delimited token is examined, so
prose fused onto a path that itself contains spaces is still unsplit (unchanged
from before this commit).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@claude

claude Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@cubic-dev-ai cubic-dev-ai 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.

cubic analysis

All reported issues were addressed across 2 files

Linked issue analysis

Linked issue: ENG-18014: Jaynes: Excel-sheet creation tool keeps failing (repeated, flagged on call)

Status Acceptance criteria Notes
✅ Split fused MEDIA:+prose so the file attachment is extracted and the trailing prose is preserved as visible text Code introduces splitGluedMediaExtension and injects a whitespace boundary; parse logic uses the split when present. New unit test specifically asserts the Bid_Form.xlsx fused case is split and parsed into mediaUrls + text.
✅ Choose the RIGHTMOST real extension as the split boundary (e.g. split at .xlsx in report.pdf2024.xlsxHere) Implementation scans right-to-left and the tests include rightmost-extension cases to validate behavior.
✅ Avoid truncating multi-letter extensions (.xlsx/.docx/.pptx/.html) to shorter prefixes during boundary detection Code explicitly avoids prefix-only matching and tests add rows for .xlsx/.docx/.pptx/.html cases to guard against the truncation regression described in ENG-18014.
✅ Do not treat dotted directory segments as an extension boundary (e.g. ".openclaw" should not split) Implementation only allows known media extensions to split; a dedicated unit test verifies dotted directory segments are ignored.
✅ Suppress whitespace-rejoin/spaced-path fallbacks only when a glued split occurred; quoted paths are not re-split PR adds guards around the existing spaced-path rejoin/fallback logic that check the split flag and preserves the prior behavior for quoted paths. Tests + CI are run and passing per PR evidence.

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread src/media/parse.ts Resolved
Comment thread src/media/parse.ts Resolved
Comment thread src/media/parse.test.ts Resolved
Comment thread src/media/parse.ts Resolved
…lenames

Addresses cubic review findings on the MEDIA: fused-prose splitter:

P1 — a directory whose name merely STARTS with a known extension was treated as
a boundary, so `MEDIA:/tmp/report.xlsxbackup/final.pdf` emitted an attachment
for `/tmp/report.xlsx` (a path that does not exist) and leaked the remainder as
text. A path separator in the remainder now disqualifies the boundary; because
every shorter candidate leaves an even longer remainder, the scan abandons that
dot rather than retrying.

P2 — a fused bare filename split correctly but the media half was then rejected,
so `MEDIA:image.pngHere` still attached nothing. The media half of a split is a
filename carved out of the token, so it may be bare; the prose half stays
invalid and is re-emitted as text.

P3 — removed ticket references from comments and test comments per the AGENTS.md
rule, keeping the rationale, and dropped a customer name from a test comment.

Evidence:
- node scripts/run-vitest.mjs src/media/parse.test.ts — 71 passing (+2).
- node scripts/run-tsgo.mjs -p tsconfig.core.json — clean.
- node --import tsx scripts/check-import-cycles.ts — 0 runtime value cycles.
- npx oxlint src/media/parse.ts src/media/parse.test.ts — clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread src/media/parse.ts Resolved
Allowing a bare filename for the media half of a split (previous commit) made a
latent case reachable: a bare name whose EARLIER segment is a known extension
and which ends in another known extension got carved up, so
`MEDIA:report.pdf2024.xlsx` attached `report.pdf` — a file that does not exist.

A known extension on the right means the filename genuinely ends there, so the
scan now abandons the token instead of walking further left; an earlier dot can
only ever carve a prefix out of a legitimate name. A dot followed by no
alphanumeric run still just advances to the next dot.

Evidence:
- node scripts/run-vitest.mjs src/media/parse.test.ts — 72 passing (+1).
- node scripts/run-tsgo.mjs -p tsconfig.core.json — clean.
- npx oxlint src/media/parse.ts src/media/parse.test.ts — clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Willi8910
Willi8910 merged commit f58644a into boon Aug 20, 2026
146 of 147 checks passed
@Willi8910
Willi8910 deleted the eng-18014-media-directive-glue branch August 20, 2026 05:35
Willi8910 added a commit that referenced this pull request Aug 20, 2026
Version-bump-only release cutting the seven commits merged to boon since
v2026.6.11-boon.19: #129 (deliver an attachment when prose is fused onto the
MEDIA: path), #131 (stop mislabeling sanctioned silent NO_REPLY finals as
delivery failures, ENG-18092), #133 (fingerprint sentry-monitor hook captures
and surface the real Python exception line), #130 (docs cross-link), and the
#36 / #77 / #113 dependency bumps.

Bumps the gateway plus @openclaw/slack, @openclaw/msteams, and
@openclaw/diagnostics-prometheus to 2026.6.11-boon.20 in lockstep across all 8
manifests, and adds the CHANGELOG entry. No code changes.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

1 participant