Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions core/model/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
_ "github.com/rossoctl/cortex/core/session"
_ "github.com/rossoctl/cortex/core/session/archive"
_ "github.com/rossoctl/cortex/core/session/timeline"
_ "github.com/rossoctl/cortex/core/session/toolpair"
_ "github.com/rossoctl/cortex/core/sessionexport"
)

Expand All @@ -32,6 +33,7 @@ var dataOnly = []string{
"github.com/rossoctl/cortex/core/session",
"github.com/rossoctl/cortex/core/session/archive",
"github.com/rossoctl/cortex/core/session/timeline",
"github.com/rossoctl/cortex/core/session/toolpair",
"github.com/rossoctl/cortex/core/sessionexport",
"github.com/rossoctl/cortex/core/attribution",
"github.com/rossoctl/cortex/core/parse/a2a",
Expand Down
355 changes: 87 additions & 268 deletions core/session/timeline/agents.go

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions core/session/timeline/agents_lostfor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package timeline

import (
"testing"

"github.com/rossoctl/cortex/core/session/toolpair"
)

// TestLostForFailsClosedOnAnUnknownReason is the guard on the mapping's DIRECTION.
//
// lostFor used to name the no-result reasons, so a reason added to toolpair later matched none
// of them and read as "not lost" — and a call that ended without a result then rendered as
// still running, forever, on a pane whose job is showing what finished. Deriving it from HasEnd
// inverts that: an unknown reason is lost until someone says otherwise. A future reason must
// not need an edit here, and this test fails if the derivation goes back to a list.
func TestLostForFailsClosedOnAnUnknownReason(t *testing.T) {
if !lostFor(toolpair.EndReason("some_reason_added_later")) {
t.Error("lostFor(unknown) = false, want true: an unrecognised reason must read as lost, not as open")
}
// The zero reason is the one exception: still open is not a kind of loss.
if lostFor("") {
t.Error(`lostFor("") = true, want false: an open call has no end at all`)
}
for _, r := range []toolpair.EndReason{toolpair.ReasonResult, toolpair.ReasonBackground} {
if lostFor(r) {
t.Errorf("lostFor(%q) = true, want false: it carries an end", r)
}
}
for _, r := range []toolpair.EndReason{toolpair.ReasonEndedRun, toolpair.ReasonStopped, toolpair.ReasonAbandoned} {
if !lostFor(r) {
t.Errorf("lostFor(%q) = false, want true", r)
}
}
}
11 changes: 9 additions & 2 deletions core/session/timeline/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ import (
"time"

"github.com/rossoctl/cortex/core/model"
"github.com/rossoctl/cortex/core/session/toolpair"
)

// MainAgent is the agent id of the main conversation.
const MainAgent = "main"
//
// ALIASED, NOT RESPELLED. core/session/toolpair assigns these keys and this package compares
// against them (buildAgents' resent line, and agentLabel). Two literals that must be equal and

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Good change. The comment around it is a bit off, though:

  • agentLabel doesn't exist in this package. agentLabel/agentLabelIn live in core/session (summary.go, fold.go) and have nothing to do with these keys. The comparison you mean is linkAgents' switch id { case MainAgent: … case UnseparatedAgent: … } (agents.go:253-261).
  • "every subagent turn reads as a fresh agent" is not what drift would actually do. If UnseparatedAgent drifted, the c.agent != UnseparatedAgent guard on the resent line would stop excluding the shared bucket, so its turns would start being flagged as retries. linkAgents would also miss the case, so the bucket would lose its "subagents (not separated)" label and go through spawn matching like a real subagent.

The argument for aliasing is the same either way. Only the example should match the code. Something like (buildAgents' resent guard, and linkAgents' label switch) … the shared bucket's turns read as retries and it is linked as if it were a real subagent.

// are written in two files drift in silence: the comparison simply stops matching, and every
// subagent turn reads as a fresh agent. Taking the value from the producer makes that
// impossible rather than unlikely.
const MainAgent = toolpair.MainAgent

// UnseparatedAgent holds subagent traffic recorded before the proxy captured Claude Code's
// agent id header (#1459): AgentRole says "subagent" but nothing says which one.
const UnseparatedAgent = "subagents"
const UnseparatedAgent = toolpair.UnseparatedAgent

// Kind classifies a host span.
type Kind string
Expand Down
18 changes: 0 additions & 18 deletions core/session/timeline/timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,24 +552,6 @@ func TestOnlyNewMessagesAreScanned(t *testing.T) {
}
}

func TestCommonPrefix(t *testing.T) {
a, b, c := user("a"), user("b"), user("c")
for _, tc := range []struct {
prev, cur []pipeline.InferenceMessage
want int
}{
{nil, []pipeline.InferenceMessage{a}, 0},
{[]pipeline.InferenceMessage{a, b}, []pipeline.InferenceMessage{a, b, c}, 2},
{[]pipeline.InferenceMessage{a, b}, []pipeline.InferenceMessage{a, c}, 1}, // history rewritten
{[]pipeline.InferenceMessage{a, b, c}, []pipeline.InferenceMessage{a, b}, 2}, // compacted shorter
{[]pipeline.InferenceMessage{{Role: "system", Content: "a"}}, []pipeline.InferenceMessage{a}, 0},
} {
if got := commonPrefix(tc.prev, tc.cur); got != tc.want {
t.Errorf("commonPrefix(%v, %v) = %d, want %d", tc.prev, tc.cur, got, tc.want)
}
}
}

// A parent can resume a subagent with SendMessage after its first hand-back; the row runs to
// the last one.
func TestReturnedAtIsTheLastReturn(t *testing.T) {
Expand Down
Loading
Loading