提交图

18 提交

作者 SHA1 备注 提交日期
02ac2046d6 fix(chat): validate slot sends before writing history
send_connection_slot_message wrote the optimistic user row from the
runtime snapshot alone, then called send_slot_message, which can still
refuse the send for an empty message, a busy slot or a disconnected
slot. The rejected question stayed in history with no failure marker,
and because each attempt minted a fresh local- id, retrying appended a
second copy rather than replacing the first.

Add a read-only pre-flight, ensure_slot_can_send, and run it before any
database write. The conditions it checks are extracted into
slot_send_precondition, which send_slot_message now uses inside its own
critical section, so the two cannot drift. Mint the message id once so
the failure path can address the row it wrote.

A send that fails after AstrBot accepted it must keep its question:
cancelled and streamInterrupted both mean the message is already in the
remote conversation and a partial reply may already be stored. Those
two keep the row; every other code marks it failed. server_received
encodes that rule and is covered by a test that walks every
AstrBotClientError variant through astrbot_send_error, so a future
rename of an R2 error code cannot silently change the classification.

Marking rather than deleting keeps chat_sessions.last_message_id valid,
re-uses the idempotent upsert, and leaves unread counts alone since they
already ignore user rows. The queue sanctions either choice.

The R2 retry loop and its error mapping are untouched; all five R2
transport sentinels still pass.

Refs: F-18 (audit P2-3).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 00:20:09 +08:00
0fadc699e2 fix(net): reject one profile occupying both runtime slots
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>
2026-07-27 00:16:33 +08:00
06312447aa fix(net): reject stale session switches by generation
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>
2026-07-27 00:12:32 +08:00
b2ecd1f3a4 fix(net): probe connection slots outside the runtime lock
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>
2026-07-27 00:11:19 +08:00
c4c40bd561 fix(astrbot): do not resend messages after the response starts
`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>
2026-07-26 23:12:57 +08:00
6e81a3a7ae fix(astrbot): scope stream event ids and fix the transport layer
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>
2026-07-26 23:12:56 +08:00
d100da324d fix(chat): prevent duplicate history on session switch
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
2026-07-22 02:52:31 +08:00
5de8bfab03 fix(chat): flatten runtime event payloads
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
2026-07-21 14:55:49 +08:00
ceb7512bf2 feat(desktop): complete Q9 chat and stability increment
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
2026-07-21 14:43:14 +08:00
74fe19f7e4 feat(auth): handle jwt expiry and relogin state
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
2026-07-20 16:52:29 +08:00
7dae4898cb feat(pet): separate remote identity and add paper pet window
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
2026-07-20 16:28:42 +08:00
06e0b411ea feat(chat): add remote session navigation
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
2026-07-20 14:32:07 +08:00
bcaebee6f3 feat(chat): add model and attachment interfaces
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
2026-07-20 13:30:29 +08:00
e0b48c0a5c feat(chat): persist sessions and unread state
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
2026-07-20 12:25:08 +08:00
5dfac5960f fix(sse): add bounded chat retry and cancellation
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
2026-07-20 12:08:06 +08:00
2e84ea52e9 feat(connection): auto-connect configured slots
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
2026-07-20 12:01:18 +08:00
3d1d962461 feat(chat): add AstrBot dual-slot chat foundation
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
2026-07-20 11:31:41 +08:00
01607c69ff feat(p00): add Tauri desktop spike foundation 2026-07-18 20:34:47 +08:00