Repository navigation
fix(napcat): keep a message whose image declares a non-numeric file_size - #5914
Conversation
|
CI note for reviewers: the only red check on this head is The failure is not in the napcat suite. On that job the full-suite step finished 7856 passed, 82 skipped (both new napcat tests included); the red comes from the next step, The foreground-webui CLI tests shell out to that install, so they inherit it. The diff itself touches only |
|
Follow-up on my previous note: attempt 2 (started 13:14:49Z, finished 13:24:49Z) failed the same step the same way, so a plain re-run on the same host does not clear it. Exact evidence, from the Reading it again, the detail that matters is the path: the rename that fails is inside I am not going to push a churn commit for this. Separately: if a build that shells out to npm from a CLI test is worth pinning down, that looks like its own issue rather than something to fold in here — happy to file it if you want, or to re-run on request. |
|
The
This PR only touches Re-running the failed job should confirm it. If you would rather I push a rebase onto current |
88db989 to
4e5d9e2
Compare
Napcat reports an image segment's file_size as a string that is not always numeric, so int() raises ValueError. The upfront size guard only caught TypeError and KeyError, the ValueError escaped _download_image into _on_message, and the whole inbound message was dropped — text included — with only a background-handler warning left behind. Handle ValueError as the guard already handles a missing size: skip the upfront check and let the streamed download enforce max_image_bytes. Log it, since a declared size we cannot read is worth knowing about.
4e5d9e2 to
e5b492b
Compare
Re-bin
left a comment
There was a problem hiding this comment.
An unusable declared image size no longer causes Napcat to drop the enclosing message. Only metadata parsing changes: URL validation, streamed-byte limits and existing media filters remain enforced. Regressions cover the inbound message boundary and the download cap with malformed size metadata. No configuration, stored-data, model-prefix or tool-schema changes; no breaking change found. This is isolated channel coverage, not a live QQ delivery test.
Exact-head CI passed. The base passed one Windows-only retry for an unchanged process-timing test; the intermittent timing cause is not claimed fixed.
What
_download_imagerejects an image upfront when Napcat declares a size abovemax_image_bytes:_parse_segmentsalready documents that Napcat sendsfile_sizeas a string ("bytes, sometimes a string",runtime.py:331-333). A string that is not a number —"","unknown","12KB"— makesint()raiseValueError, and that is the one exception this guard does not catch.Why it matters
The
ValueErrorescapes_download_imageinto its caller_on_message(runtime.py:254-256), which has no surroundingtry, so the loop aborts before_handle_messageruns. The whole inbound message is dropped — the image and the text the user sent with it — and the only trace is anapcat: message handler failed: ...warning from the background-task callback.Skipping the upfront check is also what the code already intends for a size it cannot read: the check is only an optimization, and the streamed download below still caps the body at
max_image_bytesand returnsNonewhen it is exceeded, so nothing unbounded reaches disk. The new branch logs the unusable declaration instead of swallowing it silently.Tests
Two regression tests in
nanobot/channels/napcat/tests/test_napcat_channel.py:test_download_image_ignores_unparsable_declared_size— declared sizes"","unknown","12KB"now download the image instead of raising.test_message_with_unparsable_image_size_still_routes— a private message carrying text plus such an image still reaches the bus with its text and its media path.Before the fix both fail on
origin/main:After it:
basedpyright nanobot/channels/napcatreports the same unknown-type class as pristinemain(69 errors before, 70 after — the extra one is the newlogger.warningcall, a class every existing log line in this file already belongs to locally).