F-33. A voice reply produced nothing at all: no marker, no event, no
error. Four independent gates each dropped it, and fixing any one alone
would have changed nothing observable.
The mapper reached `map_media` for image, record, file and video alike,
but its only emitting branch was gated on the frame being an image, and
the `attachment_saved` fallback rejected every other type outright. Both
now carry whatever type arrived, with the frame type as the marker's alt
text so the renderer knows what to expect before any bytes exist.
`pending_media` was also a single slot, so a second attachment in one
reply overwrote the first before it was paired; it is a bounded queue
now, and an `attachment_saved` with no id no longer consumes the media
frame still waiting for one.
The download judged a candidate path successful only if the bytes sniffed
as an image — this server answers unknown paths with its own text under
HTTP 200, so sniffing is load-bearing and cannot simply be dropped.
Audio and video signatures are recognised now, and a declared
Content-Type is trusted when it names media rather than only images.
SILK is included deliberately: it is what AstrBot relays for QQ and
WeChat voice, no browser decodes it, and recognising it is what lets the
UI say so instead of rendering a player whose play button does nothing.
The CSP had no `media-src`, so it fell back to `default-src 'self'` and
an `<audio src="blob:">` was refused — in release builds only, since the
dev server serves no CSP at all. That is the same divergence as F-04 and
the inline-script trap in pet.html, so the policy now has a test of its
own that pins each directive the app depends on, including that
script-src still refuses inline.
The renderer chose `<img>` unconditionally. The element now follows the
media type of the bytes that actually arrived, falling back to the
marker's declared kind for the placeholder and the failure message.
`map_media` also kept a private copy of the message-id handling that
included the reopen-suffix overwrite fixed earlier in `adopt_message_id`;
it shares the one implementation now.
Protocol tests 22 -> 26, Rust client 99 -> 101, frontend 35 -> 43. All
six mutations of the new assertions were confirmed to fail.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Attachments went out under a top-level `attachments` key holding
camelCase objects. AstrBot's `OpenApiChatRequest` has no such field —
its properties are message, session_id, conversation_id, username,
config_id, config_name, platform_id, enable_streaming and flags,
read from the live server's own /api/v1/openapi.json — and FastAPI
ignores unknown keys instead of rejecting them. So every attachment this
client ever sent was discarded in silence while the request reported
success. The same is true of `nickname`, now removed.
Attachments belong inside `message`, which AstrBot accepts either as a
bare string or as a list of segments: {"type":"plain","text":...} and
{"type":"image"|"record"|"file"|"video","attachment_id":...}, per the
documented format at docs.astrbot.app/en/dev/openapi.html. Segment type
now follows the uploaded media type, with `file` as the fallback so an
unrecognised type still travels rather than being dropped.
This closes the outbound half of P1-9, which the queue had recorded as
externally blocked on a real container. It did not need one: the schema
is public and the server serves it unauthenticated.
It also settles how voice input will be sent — an audio upload is a
`record` segment — so B4 no longer has to guess at the contract.
Text-only requests keep the bare-string shape they always had. A test
now asserts the serialized request carries no key outside the nine the
server declares, since anything else fails by being ignored rather than
by erroring.
Protocol tests 19 -> 22. All three new assertions confirmed to fail
under a deliberate regression.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Repairs two commits that I pushed with a failing gate.
64dab45 treated every `streaming: false` plain frame as a new segment.
That is wrong half the time: AstrBot sends both a block that restates
what the delta stream already carried and a block carrying text the
deltas never delivered, sometimes in the same reply — which is exactly
what the frame-trace fixtures in astrbot_client.rs were built to tell
apart, and I had written those fixtures myself. Treating a restatement as
new content would have shown it twice, and completing each block on
arrival left the two R2 sentinels with no open message to finalize, so a
truncated body and a cancellation both reported "stop".
Both the non-streaming plain frames and the complete frame now go through
one `reconcile`: emit only the byte-exact tail beyond what was shown, or
nothing if the text has already been shown allowing for different
whitespace, or open a message of its own if it diverges. Fixes a real
defect this exposed in `adopt_message_id`, which assigned the server's
bare id back over an active id that carried a reopen suffix, merging
blocks that had just been separated.
9b2ec64 added petEntry.test.ts importing node:fs. tsconfig.app.json sets
an explicit `types` array so Node globals are absent, and typecheck and
build both failed. Now imported as raw text through vite, rather than
adding Node's types to the compilation that covers the browser code.
Protocol tests 12 -> 19. Every new assertion was checked against a
deliberate regression, and the two that survived their first check —
dropping the byte-exact prefix case and dropping the whitespace-only
guard — now have tests that fail without them.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A `streaming: false` plain frame carries a whole segment, not a fragment
of one, but the mapper appended it to the open accumulation and then
`complete` assigned its own text over the top. A reply that arrived in
three parts was shown as one bubble holding only whichever part
`complete` restated; the rest was never displayed and never stored.
Non-streaming frames now become messages of their own, and `complete`
reconciles instead of overwriting. Three ordered cases, none of which can
lose text the client has seen: the frame extends what was shown byte for
byte, so only the tail is emitted (the streaming case the existing
reconcile test pins); the frame restates text already shown, compared
with whitespace squeezed, so nothing is emitted; or the frame diverges
from what was shown, so both are kept and the frame's text opens its own
message. Tracking that needs the whole stream's delivered text, since
`accumulated` empties as each message closes.
Also stops emitting deltas with no message id. Metadata without one makes
the client fall back to `event_id`, which is unique per event, so each
such delta became a message of its own — and AstrBot does not always put
an id on the opening frames of a stream. The stream id is stable across
exactly the span that needs one name. This is the mapper half of N-4; the
duplicate-bubble report is not yet confirmed to be this, and the client's
own `messageId || eventId` fallback is untouched.
Protocol tests 12 -> 17. All five new assertions were confirmed to fail
under a deliberate regression.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Exact containment cannot separate "the same text formatted differently"
from "content the stream never carried". A capture had a 278-character
block against 286 streamed characters and reported no containment either
way, which is the reading the segmentation fix depends on.
Report containment with whitespace removed alongside the exact result.
Both are logged: a block that matches only once whitespace is dropped is
the same content, while a block that matches under neither is genuinely
separate.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Reading the dashboard's own bundle settled where the file endpoints
are. It exposes upload as POST /api/v1/files, fetch-by-name as
GET /api/v1/files/content?filename=, and fetch-by-id as
GET /api/v1/files/{id}/content, and it fetches a chat image by name.
Both of our endpoints were wrong in different ways. Upload posted to
/api/v1/file, singular. Download used the by-id form with the id from
the attachment_saved frame, which does not address the file — asking for
it returned the dashboard's HTML shell with HTTP 200, which is what
surfaced as a broken image.
The name was there all along: the media frame carries [IMAGE]{uuid}.jpg
and the mapper discarded it, waiting for the id in the frame after.
Emit the marker from the media frame instead, naming the file, and keep
the saved id as a fallback for a media frame that names nothing usable.
A reference carrying a path or a scheme is refused rather than guessed
at, since the by-name fetch cannot express either.
Refs: N-6.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A captured stream ended complete(272 chars) → image → attachment_saved
→ end, all under one message id. complete emptied the accumulation, the
attachment marker re-accumulated onto it, and end emitted a second
completion for the same message whose body was the marker alone. The
client assigns completed content over the existing message, so 272
characters of reply were replaced by an image tag — the reply visibly
vanished behind a broken image placeholder.
Mark a message as completed when its completion is emitted, and open a
new message on the next delta rather than reusing the finished id. The
reopened id carries a #part- suffix so the client reads it as a separate
message; frame comparisons use the base id so a later frame bearing the
server's original id is not treated as a different message.
The regression test replays the captured frame order and was checked
against a mutation that drops the completed flag, where it fails with
the attachment reusing the finished id.
Refs: F-32 (audit P2-17), which predicted this as "content arriving
after complete overwrites the full text".
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Combines the P0 event-id fix with the three transport fixes that rewrite the
same stream loop; they are not separable in these two files.
fix(astrbot): scope stream event ids per request (P0-1 / F-01)
`AstrBotStreamMapper` restarts its sequence at zero for every stream, but
`seen_event_ids` lives on the client and outlives a request. Event ids were
built from `server_instance_id + sequence` alone, so the second message on a
connection replayed the first message's ids and every one of its events was
discarded as a duplicate: the assistant's reply never reached the UI or the
database. Ids now carry a per-request `stream_id`.
fix(protocol): serialize model options in camelCase (P1-7b / F-07)
`AstrBotModelOption` had no `rename_all`, so the frontend's `isDefault` was
always undefined and no model was preselected.
fix(net): stop total timeouts from killing streams (P1-1 / F-10)
`Client::timeout` runs from the start of the request until the body is
finished and keeps counting while `bytes_stream()` is consumed. The 30s
desktop-v1 budget therefore tore the long-lived SSE connection down every 30
seconds no matter how healthy it was — heartbeats could not keep it alive —
and the 120s AstrBot budget cut off any generation longer than two minutes.
Streaming now uses a separate client with no total deadline, detecting a
stalled peer with `read_timeout` (which resets on every successful read) plus
a TCP keepalive. REST endpoints keep their total deadline.
fix(astrbot): decode sse bytes on line boundaries (P1-3 / F-11)
Decoding each network chunk with `String::from_utf8_lossy` corrupted any
character straddling a chunk boundary. For CJK text that is one replacement
character per unlucky chunk, persisted into the message. The stream is now
split into lines at the byte level and only complete lines are decoded.
fix(astrbot): finalize streams on cancel and error (P2-2 / F-13)
Cancellation and every error path returned without a `MessageCompleted`
event, leaving the row `streaming = 1` so it rendered as "generating" again
after a restart. All exit paths now finalize with `Cancelled` or `Error` and
keep the text received so far. Cancelling also no longer flips the connection
to Disconnected and back, which was a visible flicker (P3-4 / F-56).
Hardening found while reviewing the above: a 64 MiB per-response ceiling
(removing the total timeout removed the only bound on a response, and
`read_timeout` cannot replace it), and a cursor-based line buffer instead of
draining from the front, which was quadratic in the chunk size.
Tests drive a real `AstrBotClient` against a hand-rolled HTTP/1.1 chunked-SSE
server on a raw `TcpListener`: byte-exact control over chunk boundaries and
dropping a socket mid-body without the terminal chunk are not expressible
through an HTTP framework, and both are needed here.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>