MCPcopy Index your code
hub / github.com/docker/docker-agent / TestRuntime_MultiAgent_SessionReload

Function TestRuntime_MultiAgent_SessionReload

e2e/runtime_test.go:54–101  ·  view source on GitHub ↗

TestRuntime_MultiAgent_SessionReload verifies that a multi-agent task transfer does not corrupt the parent session's persisted history. Before the fix (PR #2058), sub-agent streaming events (AgentChoiceEvent, AgentChoiceReasoningEvent) were processed by the PersistentRuntime against the parent sessi

(t *testing.T)

Source from the content-addressed store, hash-verified

52// 4. Runs a second turn (follow-up) on the reloaded session
53// 5. Asserts the follow-up succeeds without errors
54func TestRuntime_MultiAgent_SessionReload(t *testing.T) {
55 t.Parallel()
56
57 ctx := t.Context()
58 agentSource, err := config.Resolve("testdata/multi_transfer.yaml", nil)
59 require.NoError(t, err)
60
61 _, runConfig := startRecordingAIProxy(t)
62 team, err := teamloader.Load(ctx, agentSource, runConfig, loaderdefaults.Opts()...)
63 require.NoError(t, err)
64
65 // Use a SQLite store so we test real persistence and reload.
66 dbPath := filepath.Join(t.TempDir(), "session.db")
67 store, err := session.NewSQLiteSessionStore(t.Context(), dbPath)
68 require.NoError(t, err)
69 t.Cleanup(func() { store.Close() })
70
71 rt, err := runtime.New(t.Context(), team, runtime.WithSessionStore(store))
72 require.NoError(t, err)
73
74 // --- Turn 1: trigger a task transfer ---
75 sess := session.New(session.WithUserMessage("What's the weather in Paris? Delegate to the weather agent."))
76 _, err = rt.Run(ctx, sess)
77 require.NoError(t, err)
78
79 response := sess.GetLastAssistantMessageContent()
80 require.NotEmpty(t, response, "first turn should produce a response")
81
82 // --- Reload the session from the store ---
83 reloaded, err := store.GetSession(ctx, sess.ID)
84 require.NoError(t, err)
85 require.NotNil(t, reloaded)
86
87 // --- Turn 2: follow-up on the reloaded session ---
88 // Before the fix, this would fail because the reloaded session contained
89 // orphan streaming messages from the sub-agent that corrupt the message
90 // sequence sent to the model.
91 reloaded.AddMessage(session.UserMessage("Can you summarize what you found?"))
92 reloaded.SendUserMessage = true
93
94 _, err = rt.Run(ctx, reloaded)
95 require.NoError(t, err, "follow-up on reloaded session should not fail; "+
96 "orphan sub-agent messages in the persisted parent session would cause "+
97 "model API errors due to corrupted message sequence")
98
99 response2 := reloaded.GetLastAssistantMessageContent()
100 assert.NotEmpty(t, response2, "second turn should produce a response")
101}
102
103func TestRuntime_Mistral_Basic(t *testing.T) {
104 t.Parallel()

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
GetSessionMethod · 0.95
ResolveFunction · 0.92
LoadFunction · 0.92
NewSQLiteSessionStoreFunction · 0.92
NewFunction · 0.92
WithSessionStoreFunction · 0.92
NewFunction · 0.92
WithUserMessageFunction · 0.92
UserMessageFunction · 0.92
startRecordingAIProxyFunction · 0.85
ContextMethod · 0.80

Tested by

no test coverage detected