oficina / equipo Public

Scenario 7 counts only the replay, not what happens after it

TestStaging/7_stream_resume failed on 2301e3c1 with "replayed events
applied twice". Nothing was applied twice. The event was new: a
connection event (cursor 71434, after the reply's 71433) carrying the
Codex connection's headroom from the turn itself, stored 1.1 s after the
reply by the runner's next hello (helloConnections, at most once a
minute per connection). The suite runs on Codex since its Claude
connection reports error, so each run has a few of these, and one lands
in the 2 s window about one run in fifteen. The same events appear in
the passing runs at 55e192cf; nothing in 55e192cf..2301e3c1 changed them.

The scenario counted every event applied during those 2 s, including
ones the still-open live stream received. It now closes the live stream,
notes the conversation's cursor, and reads the replay from the old
cursor up to that cursor only: everything there must change nothing,
and the replay must reach it. A replay the edge drops is resumed.

TestHeadlessStreamResumeWhileLive connects a Codex account while the
replay is read, a new connection event like staging's. It failed with
the staging message before this change and passes after; with the
client's cursor guard broken, the new check still fails.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev ce1bc27ab61b0080c352e3a0ad695de3f0a3a91f parent 2301e3c
2 files changed, +53 −6
  • internal/headless/env_test.go +5 −1
  • internal/headless/scenarios_test.go +48 −5
diff --git a/internal/headless/env_test.go b/internal/headless/env_test.go
index 4e4fd8c5..0d989b17 100644
--- a/internal/headless/env_test.go
+++ b/internal/headless/env_test.go
@@ -127,7 +127,11 @@ type Env struct {
// Usage is every usage row of a task and of one coordinator turn, as
// role/round/turns=<known>/cached=<any>, by role and round (local only).
Usage func(t *testing.T, task, turn string) []string
- turns *int
+ // duringReplay makes something new reach the conversation while
+ // scenario 7 reads its replay, as a runner's hello with fresh headroom
+ // does on staging (local only).
+ duringReplay func(t *testing.T, s *session)
+ turns *int
}
// Turn counts model turns so staging stays inside its budget.
diff --git a/internal/headless/scenarios_test.go b/internal/headless/scenarios_test.go
index 95b4b2ac..355071ab 100644
--- a/internal/headless/scenarios_test.go
+++ b/internal/headless/scenarios_test.go
@@ -329,20 +329,47 @@ func scenarioStreamResume(t *testing.T, env *Env) {
if s.conv.Applied == before {
t.Fatal("no events replayed from the cursor")
}
- // The same events again from the old cursor change nothing.
+ // The same events again from the old cursor change nothing. Only the
+ // replay counts, up to where the conversation stood: the live stream
+ // closes first, and nothing after that point is a repeat. The
+ // conversation goes on after a reply (on staging a runner's hello
+ // stores a connection's fresh headroom at any moment), and an event
+ // newer than the conversation's cursor is news, not a replay.
+ s.close()
+ top := s.conv.Cursor
+ applied := s.conv.Applied
again, err := env.Client.Open(s.ctx, cursor)
if err != nil {
t.Fatal(err)
}
- applied := s.conv.Applied
- timeout := time.After(2 * time.Second)
+ if env.duringReplay != nil {
+ env.duringReplay(t, s)
+ }
+ timeout := time.After(30 * time.Second)
+ last := cursor
replay:
for {
select {
- case e := <-again.Events:
+ case e, ok := <-again.Events:
+ if !ok {
+ // The edge can drop a stream (a 502 on staging): resume the
+ // replay from what it brought, as a client would.
+ again.Close()
+ if again, err = env.Client.Open(s.ctx, last); err != nil {
+ t.Fatalf("reopen the replay: %v", err)
+ }
+ continue
+ }
+ if e.Cursor > top {
+ t.Fatalf("the replay passed cursor %d without it (at %d)", top, e.Cursor)
+ }
s.conv.Apply(e)
+ last = max(last, e.Cursor)
+ if e.Cursor == top {
+ break replay
+ }
case <-timeout:
- break replay
+ t.Fatalf("the replay did not reach cursor %d (at %d)", top, last)
}
}
again.Close()
@@ -574,6 +601,22 @@ func TestHeadless(t *testing.T) {
report(t)
}
+// TestHeadlessStreamResumeWhileLive is scenario 7 while something new
+// reaches the conversation as it reads the replay: on staging a runner's
+// hello stores a connection's fresh headroom at any moment after a reply.
+// Only the replay must change nothing; what is new still applies.
+func TestHeadlessStreamResumeWhileLive(t *testing.T) {
+ env, _, r := localEnv(t)
+ r.opts.NoMoveIn = true
+ r.start(t)
+ env.duringReplay = func(t *testing.T, s *session) {
+ if _, err := env.Client.Connect(s.ctx, wire.Connect{Provider: "codex"}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ scenarioStreamResume(t, env)
+}
+
// TestStaging runs the same scenarios against staging with the real CLI.
// The gate script sets the origin, the device bearer and the controls.
func TestStaging(t *testing.T) {