mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #266] serve: a request finalized after the next one starts clears its status (KeyError: 'tail', client sees RemoteDisconnected) #137
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#137
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tonykee on GitHub (Sep 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/266
Summary
A request whose generator is finalized only after the next request has already started clears the new request's
status: it pops
status["tail"], clears itsbusy, and records its status as its own history entry. The new requestthen raises
KeyError: 'tail'inService._noteand the client gets no response (connection closed). This looks likea regression from the #212 fix (the
self.status.pop("tail", None)added torun()'s outerfinally).Environment
serve/server.pyatd6708a4), engine 0.1.29 sm_75 build.venv)--layer-split auto,--max-context 262144,--kv int8 --kv-resident 32768,--spec 4Actual behavior
The client sees
RemoteDisconnected(no HTTP response). It happened right after a long agent request, and once so farin a few hours of use — it is timing dependent, not deterministic.
Root cause
Service.run()is a generator:with self.fifo:releases the lock as soon as the generation loop ends.self.status["busy"] = False,self.status.pop("tail"),self.status.pop("tool")) is in theouter
finally, which only runs when the consumer closes or GCs the generator — which can be after the nextrequest has already acquired the fifo and set
tail="".finallyruns against request B's status: it removes B'stail, sets B'sbusy = False, and (viaif self.status.get("busy")) appends a history entry and totals built from B's status._noteraisesKeyError: 'tail'.The window opens when a client aborts/disconnects mid-stream and immediately re-sends (common for agents). Switching
the client to non-streaming does not avoid it: the race is server-side, and both the streaming and the non-streaming
path leave the generator suspended after
doneuntil it is finalized.Expected behavior
A finished request must not touch the status of a request that has already replaced it.
Suggested fix
Tag each request and let it clean up only its own status:
A defensive
s["tail"] = ((s.get("tail") or "") + (ev.text or ""))[-600:]in_noteis worth keeping as a second lineof defence. The
my_id = 0default plus thereqequality check means a request that fails before the status isinitialized never cleans up a status it never owned.
Verification (local)
With that change, 5 rounds of "abort a streaming request after 3 chunks, then immediately send another request" give
0 exceptions and 0
KeyErrors, every follow-up request returns 200, and/statusstill omitstailafter acompleted request (the #212 behavior is preserved).
@Niko1221 commented on GitHub (Sep 30, 2026):
Confirmed:
run()releases the queue lock before itsfinallycleans the status, so the next request can start in that gap and the old one clears its status. 0.1.31 gives each request its own id so a request only cleans its own status, and the note code no longer assumes the key. Thanks for the precise report!@Niko1221 commented on GitHub (Oct 1, 2026):
Fixed in 0.1.31: the status and history are now recorded while the request still holds the queue, so a late request can't clear the next one's status. Thanks!