Check that Assistant replies stream on Claude and on Codex
Base showed no streamed text for a Codex Assistant reply. The runner and the instance were not dropping it: both adapters emit text deltas for assist turns (Codex on item/agentMessage/delta, checked against the pinned 0.165.0 app-server; Claude with --include-partial-messages), the link sends pending deltas before the reply, and the instance relays them on /api/v1/assistant/events. On staging the reply's text began only after the look round trip and lasted about 0.5 s before the reply (first text 8.8 s, reply 9.4 s on a cold turn), so there was almost nothing to show. The two earlier commits move the first text forward. The new headless scenario TestHeadlessAssistant/streamed holds this on Claude and on Codex, with a real runner in bubblewrap: the turn's first delta must reach the Assistant's event stream at least a second before the reply message. Breaking either adapter's emit fails its subtest.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+58
−0
internal/headless/assistant_test.go+58 −0
Intent
diff --git a/internal/headless/assistant_test.go b/internal/headless/assistant_test.go| index 1a46f4a6..424d6af6 100644 |
| --- a/internal/headless/assistant_test.go |
| +++ b/internal/headless/assistant_test.go |
| @@ -347,6 +347,64 @@ func TestHeadlessAssistant(t *testing.T) { |
| // first team_update nudges it once with the person's own words, which |
| // the thread gets again with the Assistant's context; the work starts |
| // and the person hears nothing of the stop. |
| + // The Assistant's reply streams on either provider: its first text |
| + // reaches /api/v1/assistant/events as a delta while the turn is still |
| + // running, well before the reply message that replaces the draft. |
| + t.Run("streamed", func(t *testing.T) { |
| + for _, provider := range []string{"claude", "codex"} { |
| + t.Run(provider, func(t *testing.T) { |
| + env, _, r := localEnv(t) |
| + r.opts.NoMoveIn = true |
| + if provider == "codex" { |
| + r.addAccount(t, "codex", "codex-1", thintest.Owner) |
| + r.only(t, "codex-1") |
| + } |
| + r.start(t) |
| + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) |
| + defer cancel() |
| + a := env.Client.Assistant() |
| + snap, err := a.Snapshot(ctx) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + s, err := a.Open(ctx, snap.Cursor) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer s.Close() |
| + // The fake pauses two seconds after its first words. |
| + sent, err := a.Send(ctx, "Hello there. sleep:2000", key()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var delta, reply time.Time |
| + for reply.IsZero() { |
| + select { |
| + case e, ok := <-s.Events: |
| + if !ok { |
| + t.Fatal("the Assistant's stream ended") |
| + } |
| + var m wire.Message |
| + switch { |
| + case e.Type == wire.EventDelta && e.TurnID == sent.Turn.ID && delta.IsZero(): |
| + delta = time.Now() |
| + case e.Type == wire.EventMessage && json.Unmarshal(e.Data, &m) == nil && m.TurnID == sent.Turn.ID && m.Role == wire.RoleAssistant: |
| + reply = time.Now() |
| + } |
| + case <-ctx.Done(): |
| + t.Fatal("no reply") |
| + } |
| + } |
| + if delta.IsZero() { |
| + t.Fatalf("on %s no delta came before the reply", provider) |
| + } |
| + if gap := reply.Sub(delta); gap < time.Second { |
| + t.Fatalf("on %s the first delta came only %v before the reply", provider, gap) |
| + } |
| + }) |
| + } |
| + }) |
| + |
| t.Run("nudged_through", func(t *testing.T) { |
| env, inst, r := localEnv(t) |
| r.opts.NoMoveIn = true |