TestRunAgentPersistsSubSessionOnError covers the background-agent path (runCollecting) when the sub-agent's model stream fails. Before the fix, runCollecting returned early on ErrorEvent without calling parent.AddSubSession, so the sub-session was silently dropped from the parent's in-memory record
(t *testing.T)
| 4133 | // parent.AddSubSession, so the sub-session was silently dropped from the |
| 4134 | // parent's in-memory record — invisible to any code that walks session.Messages. |
| 4135 | func TestRunAgentPersistsSubSessionOnError(t *testing.T) { |
| 4136 | t.Parallel() |
| 4137 | |
| 4138 | parentProv := &mockProvider{id: "test/mock-model", stream: &mockStream{}} |
| 4139 | failingProv := &mockProviderWithError{id: "test/mock-model"} |
| 4140 | |
| 4141 | worker := agent.New("worker", "Worker agent", agent.WithModel(failingProv)) |
| 4142 | root := agent.New("root", "Root agent", agent.WithModel(parentProv)) |
| 4143 | agent.WithSubAgents(worker)(root) |
| 4144 | |
| 4145 | tm := team.New(team.WithAgents(root, worker)) |
| 4146 | rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{})) |
| 4147 | require.NoError(t, err) |
| 4148 | |
| 4149 | sess := session.New(session.WithUserMessage("Test"), session.WithToolsApproved(true)) |
| 4150 | |
| 4151 | result := rt.RunAgent(t.Context(), agenttool.RunParams{ |
| 4152 | AgentName: "worker", |
| 4153 | Task: "do something", |
| 4154 | ParentSession: sess, |
| 4155 | }) |
| 4156 | |
| 4157 | require.NotEmpty(t, result.ErrMsg, "RunAgent should surface the sub-session error") |
| 4158 | |
| 4159 | // The parent session must hold a sub-session record even though the |
| 4160 | // sub-agent errored — without the fix AddSubSession was skipped and |
| 4161 | // the entire partial transcript was lost. |
| 4162 | var subSessionItems int |
| 4163 | for _, item := range sess.Messages { |
| 4164 | if item.SubSession != nil { |
| 4165 | subSessionItems++ |
| 4166 | } |
| 4167 | } |
| 4168 | assert.Equal(t, 1, subSessionItems, |
| 4169 | "parent session must record the sub-session even when the background agent errored") |
| 4170 | } |
| 4171 | |
| 4172 | // TestReasoningOnlyTurnEmitsWarning is a regression test for |
| 4173 | // https://github.com/docker/docker-agent/issues/3145. A thinking-mode model |
nothing calls this directly
no test coverage detected