Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
64a2d31
fix(agent): keep waiting for the reply past a subagent's report
robstolarz Nov 15, 2026
370b5de
chore(proto): sync depot agent proto for GetSessionMessage
robstolarz Nov 15, 2026
b9a57ac
fix(agent): read the whole reply and keep watching past a GOAWAY
robstolarz Nov 15, 2026
fdf9369
fix(agent): find the reply above a late subagent report, read it with…
robstolarz Nov 15, 2026
a21f987
test(agent): assert only what a cut connection fixes in the GOAWAY test
robstolarz Nov 15, 2026
bc5b4aa
Merge branch 'rob/dep-8506-dispatch-cli' into rob/dep-8516-dispatch-c…
robstolarz Nov 15, 2026
2f7e27a
agent logs: read a long reply whole (DEP-8516)
robstolarz Nov 15, 2026
f9762f9
agent: read a cut reply again on a later frame, forget replies that l…
robstolarz Nov 15, 2026
0486960
agent: print a recovered reply without restarting the next turn's str…
robstolarz Nov 15, 2026
bcd8934
Merge branch 'rob/dep-8506-dispatch-cli' into rob/dep-8516-dispatch-c…
robstolarz Nov 15, 2026
5b98304
fix(agent): a whole-reply read that outlasts the wait times out
robstolarz Nov 15, 2026
86a9bc6
fix(agent): give each whole-reply try its own time, read again before…
robstolarz Nov 15, 2026
e229d06
fix(agent): read a cut reply again only where the wait ends (DEP-8516)
robstolarz Nov 15, 2026
1f1443a
fix(agent): read the awaited reply again by its id (DEP-8516)
robstolarz Nov 15, 2026
f99519b
Merge branch 'rob/dep-8506-dispatch-cli' into rob/dep-8516-dispatch-c…
robstolarz Nov 15, 2026
8eda9ad
Merge branch 'main' into rob/dep-8516-dispatch-cli-waits
robstolarz Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 91 additions & 3 deletions pkg/cmd/agent/render.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package agent

import (
"context"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -38,6 +39,8 @@ type viewMessage struct {
Summary string `json:"summary"`
IsError bool `json:"isError"`
ToolCalls []viewToolCall `json:"toolCalls"`
// TruncatedBytes is how much of the message the view left out of Text, which then ends in a note saying so.
TruncatedBytes int64 `json:"truncatedBytes"`
}

// outside reports whether a person or another system sent the message, rather than the session's own subagent.
Expand Down Expand Up @@ -90,6 +93,11 @@ type Renderer struct {
broken bool
// from is the input the transcript starts at; everything older is skipped until it shows up.
from string
// whole reads a message's full text by id, and full keeps each one read while the view still holds it.
// unread counts the frames left to read again a message whose read failed in a way that may pass.
whole func(messageID string) (string, error)
full map[string]string
unread map[string]int
}

func NewRenderer(w io.Writer) *Renderer {
Expand Down Expand Up @@ -128,12 +136,18 @@ func (r *Renderer) Render(session *agentv1.DepotAgentSession, viewJSON string) (
if err != nil {
return nil, err
}
for i := range viewMessages(view) {
if text, ok := r.full[view.Messages[i].ID]; ok {
view.Messages[i].Text = text
}
}
// A snapshot older than one already printed, as a stream frame behind a direct read is, has nothing to add.
if n := len(viewMessages(view)); n > 0 {
if view.Messages[n-1].Seq < r.newest {
return view, nil
}
r.newest = view.Messages[n-1].Seq
r.keep(view)
}
status := session.GetStatus()
if status == "running" {
Expand Down Expand Up @@ -178,9 +192,16 @@ func (r *Renderer) renderView(view *agentView) {
// Everything in this view belongs to turns before the awaited input.
return
}
for _, msg := range view.Messages {
if msg.ID != "" && r.once("message:"+msg.ID) {
r.renderMessage(msg)
for i := range view.Messages {
if msg := &view.Messages[i]; msg.ID != "" && r.once("message:"+msg.ID) {
err := r.fill(msg)
r.renderMessage(*msg)
if err != nil {
r.line("(the rest of this reply could not be read: %s)", truncate(oneLine(err.Error())))
if retryable(err) {
r.unread[msg.ID] = wholeMessageTries
}
}
}
}
for _, tool := range view.Tools {
Expand All @@ -201,6 +222,73 @@ func (r *Renderer) renderView(view *agentView) {
}
}

// Whole makes the renderer read the full text of a reply the view cut short, for the transcript and for the
// view Render returns. A reply is an assistant message that calls no tool; nothing else is read.
func (r *Renderer) Whole(read func(messageID string) (string, error)) *Renderer {
r.whole, r.full, r.unread = read, map[string]string{}, map[string]int{}
return r
}

// keep forgets the messages the view no longer holds, so a long watch does not keep every reply it read,
// and reads again a reply that an earlier frame could not.
func (r *Renderer) keep(view *agentView) {
held := make(map[string]bool, len(view.Messages))
for i := range view.Messages {
msg := &view.Messages[i]
held[msg.ID] = true
if r.unread[msg.ID] == 0 {
continue
}
if r.unread[msg.ID]--; r.fill(msg) == nil {
delete(r.unread, msg.ID)
// Printed as plain lines: a response streaming now is another turn's, and keeps its place.
r.line("(the whole reply, read on a later try)")
r.line("%s", strings.TrimSpace(msg.Text))
}
}
for id := range r.full {
if !held[id] {
delete(r.full, id)
}
}
for id, left := range r.unread {
if !held[id] || left <= 0 {
delete(r.unread, id)
}
}
}

// Recover reads again the reply with this id if a failed read left it cut, with the tries it has left, and returns its text.
func (r *Renderer) Recover(ctx context.Context, view *agentView, id, reply string) string {
for i := range viewMessages(view) {
msg := &view.Messages[i]
if msg.ID != id {
continue
}
for r.unread[id] > 0 && ctx.Err() == nil {
select {
case <-ctx.Done():
case <-time.After(retryDelay):
r.keep(view)
}
}
return msg.Text
}
return reply
}

func (r *Renderer) fill(msg *viewMessage) error {
if r.whole == nil || msg.TruncatedBytes <= 0 || msg.Role != "assistant" || msg.IsError || len(msg.ToolCalls) > 0 {
return nil
}
text, err := r.whole(msg.ID)
if err != nil {
return err
}
r.full[msg.ID], msg.Text = text, text
return nil
}

// From starts the transcript at the message of this input, leaving out the session's earlier turns.
func (r *Renderer) From(inputID string) *Renderer {
r.from = inputID
Expand Down
8 changes: 6 additions & 2 deletions pkg/cmd/agent/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ func newLogs() *cobra.Command {
Short: "Print an agent session's transcript",
Long: `Print the session's recent messages and tool calls, then its status.

The transcript is the API's bounded view of the session: long messages and old history are cut.`,
The transcript is the API's bounded view of the session: old history is cut, and so are long tool results. A long
reply of the agent is read whole; -o json prints the view as the API returns it.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
c, err := f.caller(cmd)
Expand All @@ -234,7 +235,10 @@ The transcript is the API's bounded view of the session: long messages and old h
return err
}
if f.output == "text" {
_, err := NewRenderer(cmd.OutOrStdout()).Render(resp.Msg.GetSession(), resp.Msg.GetViewJson())
r := NewRenderer(cmd.OutOrStdout()).Whole(func(messageID string) (string, error) {
return wholeMessage(cmd.Context(), c, args[0], messageID)
})
_, err := r.Render(resp.Msg.GetSession(), resp.Msg.GetViewJson())
return err
}
session, err := protojson.Marshal(resp.Msg.GetSession())
Expand Down
Loading
Loading