Skip to content

fix(gateway): tighten MEDIA extraction regex + silent skip on file-not-found (#28249)#28350

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-3ad7d98a
May 19, 2026
Merged

fix(gateway): tighten MEDIA extraction regex + silent skip on file-not-found (#28249)#28350
teknium1 merged 1 commit into
mainfrom
hermes/hermes-3ad7d98a

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #28249 by @colin-chang.

What: Two issues in MEDIA delivery:

  1. The MEDIA path regex in gateway/platforms/base.py and the tool-result MEDIA scanner in gateway/run.py matched overly broad paths, sometimes capturing trailing junk.
  2. Mattermost's _send_local_file() surfaced (file not found: ...) as a user-visible reply when the file was missing. The agent had already moved on; the gateway should just log and skip.

How:

  • Tighten the MEDIA regex so it stops at the first trailing punctuation/whitespace boundary cleanly (drops the fallback |\\S+ clause that produced false-positive captures).
  • Replace the Mattermost user-visible "file not found" message with a logger.warning + silent skip (returns SendResult(success=True)).
  • Centralize the tool-result MEDIA regex compile in gateway/run.py so it's not rebuilt every iteration.

Original PR: #28249

…t-found

Three related fixes for the MEDIA:<path> extraction pipeline that
caused 'file not found' noise in platform channels:

1. run.py — tighten tool-result MEDIA regex from \S+ (any non-
   whitespace) to require a path pattern with known extensions.
   Prevents LLM-generated placeholder paths like
   'MEDIA:/path/to/example.mp4' from being captured as real media.

2. base.py — remove the |\S+ fallback in extract_media() that
   catches anything non-whitespace as a potential MEDIA path.
   This was the primary cause of false positives — strings like
   '' in tool output were captured as MEDIA: paths.

3. mattermost.py — replace the file-not-found error message sent
   to the channel with a silent logger.warning() skip. When a
   path extracted by MEDIA doesn't exist on disk, the channel
   no longer gets a noisy '(file not found: ...)' message.

Impact: eliminates the persistent 'file not found' spam in
Mattermost channels caused by over-broad MEDIA regex patterns
matching non-path text in tool output.
@teknium1 teknium1 merged commit ea49b38 into main May 19, 2026
6 checks passed
@teknium1 teknium1 deleted the hermes/hermes-3ad7d98a branch May 19, 2026 03:07
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-3ad7d98a vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8791 on HEAD, 8791 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4626 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

briandevans added a commit to briandevans/hermes-agent that referenced this pull request May 29, 2026
…o main room

`_send_local_file` previously surfaced `(file not found: ...)` via
`self.send(room_id, ...)` without propagating `metadata` — which carries
`thread_id` for threaded sends. The error message therefore landed in the
main room even when the original MEDIA send was thread-targeted, on top of
being a confusing user-visible reply for a problem the agent has already
moved past.

Mirror the mattermost adapter pattern landed in NousResearch#28350: log a warning and
return `SendResult(success=True, message_id=None)`. The agent's turn is
done by the time the missing file is detected, so treating it as a silent
skip avoids both the wrong-room leak and pointless delivery retries.

Fixes NousResearch#32503
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.

2 participants