probe_connection_slot never consulted the slot assignment table, so the
same profile could be activated into both runtime slots at once. That
bypasses the ProfileAlreadyAssigned policy the database enforces, and
both slots then race to overwrite the same sticky_session_id.
Enforce it in three places. The runtime invariant lives inside
activate_slot's claim phase, so it also covers startup auto-connect,
which calls activate_slot directly and would bypass a command-layer
check. The command adds a cross-check against connection_slots. And the
operations switch guard now covers probe and disconnect, not just slot
assignment.
Both rules are deliberately negative — they ask whether the profile is
bound to the *other* slot, never whether it is bound to this one.
auto_connect_configured_slots activates from profile.auto_connect_slot
and never writes connection_slots, so a positive rule would break
reconnect for every auto-connected profile. For the same reason the
probe guard only refuses a change of profile, so reconnecting the
profile the operations slot already holds still works during a task.
The operations guard has no production writer yet (F-74, audit P3-7),
so it is inert at runtime. It ships with a test that flips the guard
directly rather than as an unexercised branch.
Refs: F-19 (audit P2-4).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
switch_slot_session released the slot lock while set_session_id ran and
then re-acquired it to write active_session_id, with no check that the
slot still belonged to the same activation. A deactivation or
re-activation in that window put the old session id onto the new
occupant's snapshot, and persist_session_identity then copied it into
that profile's sticky session.
Capture the generation alongside the client in the first critical
section and compare before writing. The write-back is extracted into
commit_session_id so the invariant can be tested directly rather than
raced.
Refs: F-17 (audit P2-1).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
activate_slot held the single mutex that covers both slots across
health() and probe(). Those go through the REST client, whose total
timeout is 120s, so one unreachable address froze every runtime command
on both slots for that long: status polling, sending, cancelling and
disconnecting all blocked on the same lock. The cancellation token was
also only created after a successful probe, so the activation itself
could not be interrupted.
Split the function into three phases. Validation and client
construction happen first with no lock held; a short critical section
then bumps the generation, installs the cancellation token up front and
publishes the Connecting snapshot; the probe runs outside the lock
inside a biased select against that token; and a final critical section
writes the result back only if the slot still belongs to this
activation.
The listener receives the same token that phase one installed. Creating
a second one there would leave deactivate_slot cancelling a token no
listener observes, so the desktop-v1 reconnect loop would outlive the
disconnect.
This also fixes a stuck-slot bug the queue did not name. Validation used
to run after the Connecting snapshot had been written, so a rejected
request tore down a working connection and left the slot in Connecting
forever, with no client and no last_error to explain it.
The three new tests were checked against a mutation that re-acquires
the lock across the probe; the two concurrency tests fail under it.
Refs: F-14 (audit P1-4).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The R1 and R2 batches were recorded as gate-verified, but the Tauri
release build and the Playwright suite had never been run against them.
Both were executed here and pass, together with the rest of the stage
gate. Record the measured numbers rather than the previously estimated
ones, and name every step that still needs a live AstrBot container.
F-04 is now verified at the packaging level: the production CSP
containing blob: is present in the release binary. Dev builds do not
inject the CSP, so this was the only automated evidence available for
it; rendering an actual attachment remains a manual step.
Also record two things this run surfaced. Prettier reports 25 files
repo-wide, not the 20 previously written down, and the Playwright 680px
case passes only because that viewport sits exactly on the second CSS
breakpoint, leaving the 681px to 900px icon-only band untested and
without accessible nav labels. The latter is tracked as F-62.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The 2026-07-26 audit records 68 findings, but five of them never
received an F-id and belonged to no batch: P2-6 (download_attachment
buffers the whole body before checking the 16 MiB cap), P2-7 (health()
omits the bearer that SSE sends), P2-8 (the reconnect backoff resets to
100ms on a graceful close, giving a hot loop), P2-29 (JWT exp is
checked with no clock skew margin), and P3-7 (the operations switch
guard has no production writer).
Assign F-70 to F-73 into R5, which already owns gateway_client.rs and
astrbot_client.rs through F-26 and F-30, so the queue's own
same-file-same-batch rule holds and R4 and R5 do not contend for one
file. Assign F-74 into R8 with a note that R3's F-19 extends only the
guard's read side. F-69 stays permanently unassigned because it was
retracted.
Also correct the Rust test count. The queue said 67 to 73 and the
status summary said 67 to 76; a real cargo test --workspace run gives
76 unit tests in astrbot-desktop and 96 passed with 2 ignored across
the workspace, so 73 was stale.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Commit 3d1d962 inserted an unreleased heading between the H1 and the
preamble without a blank line, so Markdown absorbed the "all notable
changes" preamble as a lazy continuation of a list item, and it also
prepended a UTF-8 BOM. Commit ceb7512 then inserted the 0.1.0-alpha.2
section directly under the H1, which is why the file began
mid-document, and indented the preamble to cement it inside the
bullet.
Restore the canonical order (title, preamble, single [Unreleased] with
one Added/Changed/Fixed/Security group, then the released section),
strip the BOM, and move the duplicate-optimistic-messages entry from
Changed to Fixed. Entry text is otherwise unchanged; the R1 and R2
Fixed groups were verified to be disjoint before merging. The file now
passes prettier --check.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`.claude/settings.local.json` is untracked but still scanned by
`prettier --check .`, so `check:frontend` fails for any developer who
has local Claude Code settings.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Commit 41592e2 shortened the localized fallback string but left the
ternary wrapped across three lines, which prettier now collapses. This
file passed `prettier --check` at 785f125 and failed afterwards, so it
is the only formatting regression introduced by the R1/R2 batch.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Records what was completed, what was not, and how far verification actually
got, so the next session does not have to reconstruct it from the queue and the
commit log.
Notably it separates the local gate (which passed) from the batch acceptance
criteria that were not run: the Tauri release build, Playwright, and every
real-device check. F-04 in particular cannot be considered verified until a
release build is exercised, because development does not inject a CSP.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Adds the 2026-07-26 full-source audit and the execution-ordered fix queue, and
records what actually happened when R1 and R2 were verified:
- R1 had never been compiled. The gate found a type error introduced by its own
`.nullish()` widening and a lint failure from a non-component export, plus one
acceptance test that was specified but never written.
- R2 landed F-10 through F-13, and an adversarial review of it surfaced three
defects the batch had itself introduced, all fixed in the same batch.
- The review subagents ran against the live working tree and left mutations
behind, including a deliberate duplicate POST inside the stream error path.
That injected code was briefly mistaken for a real HTTP-stack defect. It has
been removed and the process note recorded so review runs are isolated next
time.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`should_retry_astrbot` treated every `reqwest::Error` as retryable, but that
class covers both "the POST never left" and "the response body broke". `POST
/api/v1/chat` carries no idempotency key, so retrying the second case appended
the user's message to the remote conversation a second time, produced a second
answer, and interleaved the two attempts' deltas into one garbled bubble.
Retries are now limited to connect-phase failures, the one case where the
request provably never reached the server. Anything after that surfaces a
`streamInterrupted` code so the UI can offer a manual retry instead.
Also stops a send from checking the client out of its slot. The other five slot
commands read the client and report "not connected" when it is absent, so a
send disabled sessions, capabilities, upload, download, and session switching
for its whole duration. That window used to be bounded by the client's 120s
total timeout; now that streaming has no total deadline it would last as long
as the reply, so an ordinary long answer would disable the rest of the slot.
The client is cloned instead and concurrent sends are rejected with `slotBusy`.
(P2-13 / F-49, pulled forward from batch R7 because this batch is what made it
user-visible.)
Refs P1-2 / F-12.
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>
Historical UTF-8 corruption left question-mark runs in user-visible copy and in
one accessible name: the sprite load failure message, the canvas context
failure message, the pet window's `aria-label`, and the page loading state.
A separate spot had the "desktop floating" option label hard-coded as numeric
HTML entities.
Refs P1-17 / F-09.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Rust serializes `Option<String>` without `skip_serializing_if`, so absent
fields arrive as `null`. Zod's `.optional()` accepts only `undefined`, so
`safeParse` failed and three chains silently died:
- `boundRuntimeEventSchema.sessionId/messageId`: desktop-v1 and mock events
carry no session id, so every one of them was discarded; AstrBot error and
heartbeat frames were discarded too.
- `remoteChatSessionSchema.displayName/updatedAt`: one null field threw for
the whole array, leaving the remote session list permanently empty.
- `astrbotModelOptionSchema.name`: a null name failed capability parsing,
which permanently disabled the file upload button.
The sibling `slotRuntimeSnapshotSchema` in the same file already used
`.nullish()` throughout, which is what makes this look like a miss during the
de-enveloping change rather than a deliberate choice.
`formatSessionTime` widens with it: `updatedAt` is now `string | null` and the
existing falsy guard already handled null.
Refs P1-7a / F-06.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Tauri rejects `invoke` with the deserialized Rust error value, which for
`RuntimeCommandError { code, message }` is a plain object rather than an
`Error`. Nine call sites used `reason instanceof Error ? reason.message :
String(reason)`, so every send, reconnect, stop, and settings failure showed
the user `[object Object]`.
`ProfileManager` already had a correct implementation; this lifts it into
`src/lib/errorMessage.ts` and routes the other call sites through it. The
module also exports `isCancelledError`, which a later batch needs to tell a
deliberate stop apart from a real failure.
Refs P1-16 / F-08.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Assistant messages come from a remote AstrBot instance and are untrusted, but
the markdown renderer passed the href through verbatim, so `javascript:` and
`data:` URLs reached an anchor. Inside this webview, script execution has
access to the full Tauri IPC surface.
Links are now resolved with `new URL()` and only http/https/mailto survive;
anything else renders as the original plain text. Relative hrefs are rejected
too rather than being presented as absolute links against the placeholder base.
`rel` gains `noopener`.
The helper lives in `src/lib/` rather than beside the component because a
non-component export in a component module fails `react-refresh` under the
repository's `--max-warnings 0` lint gate.
Refs P1-15 / F-05.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Attachment images are rendered from `URL.createObjectURL`, but the production
CSP `img-src` list had no `blob:` entry. Development does not inject a CSP, so
this only broke release builds.
Refs P1-14 / F-04.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The `desktop-pet` window is created at startup but was absent from the
capability window list, so every IPC call and event listener it made was
rejected by the Tauri ACL. Because those calls are issued as `void invoke(...)`
the rejections were swallowed, and the pet silently lost its runtime status
link, dragging, context menu, and preference handling.
Refs P1-13 / F-03.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The manifest filename pattern used `\.` inside a regex literal, which matches
a literal backslash followed by any character, while the surrounding character
class already excludes backslashes. Every valid pack was rejected, including
the one bundled in this repository, so pack import was entirely unusable.
Adds a test that parses the bundled manifest so the pattern cannot regress.
Refs P1-12 / F-02.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>