Chat and runs: tell a slow client to resync instead of dropping it silently; join queued deltas
A chat subscriber whose queue fills is detached and its writer ends the stream with a resync frame (the app re-attaches and re-reads history); a run subscriber gets a final runs_resync and the app subscribes again and re-reads the Runs list and open detail. Consecutive text/reasoning deltas of one part are joined in a chat subscriber's queue; joined numbered frames carry seq_from and delta_lens so the app trims exactly the prefix a history page already holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// A run subscriber that falls behind used to be dropped silently: the app's
|
||||
// run list and open detail froze until the next reconnect. Now it is detached
|
||||
// and its last frame is runs_resync, which makes the app subscribe again.
|
||||
func TestRunSubscriptionOverflowEndsWithRunsResync(t *testing.T) {
|
||||
h := newRunEventHub()
|
||||
release := make(chan struct{})
|
||||
var mu sync.Mutex
|
||||
var written []protocol.Message
|
||||
sub := h.subscribe("conn", "", nil, func(msg protocol.Message) error {
|
||||
<-release
|
||||
mu.Lock()
|
||||
written = append(written, msg)
|
||||
mu.Unlock()
|
||||
return nil
|
||||
})
|
||||
sub.ready()
|
||||
for i := range runEventSubscriberBuffer + 4 {
|
||||
sub.send(protocol.RunEventFrame{RunID: int64(i + 1), Status: protocol.RunStatusRunning})
|
||||
}
|
||||
h.mu.Lock()
|
||||
_, attached := h.subs[sub]
|
||||
h.mu.Unlock()
|
||||
if attached {
|
||||
t.Fatal("an overflowed run subscriber stayed attached")
|
||||
}
|
||||
close(release)
|
||||
select {
|
||||
case <-sub.done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the overflowed subscription never closed")
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if last := written[len(written)-1]; last.Type != protocol.RunsResync {
|
||||
t.Fatalf("the overflowed client's last frame was %q, want %q", last.Type, protocol.RunsResync)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user