xonecas.io
60255
Zn

Zoea-Nova / commit 599f607

fix: implement per-mysis MCP clients for session isolation

CRITICAL ARCHITECTURAL FIX: Eliminates game state pollution caused by
shared MCP protocol session across all myses.

Root Cause:
All myses shared a single mcp.Client with one Mcp-Session-Id header.
SpaceMolt server associated game sessions with MCP session, causing
all myses to share the same game session_id regardless of which
account they logged into.

Solution:
- Each mysis now creates its own mcp.Client during Start()
- Each client performs independent Initialize() handshake
- Each client gets unique Mcp-Session-Id from server
- Server now sees separate connections and assigns unique game sessions

Implementation:
- Added mcpEndpoint, mcpClient, mcpProxy fields to Mysis struct
- Implemented initializeMCP() method called during Start()
- Close MCP client in Stop() for proper cleanup
- Removed shared mcp field from Commander
- Removed SetMCP() method (no longer needed)
- Updated NewCommander() to accept MCP endpoint string
- Updated main.go to pass endpoint instead of creating shared proxy
- Each mysis registers orchestrator tools on its own proxy

Impact:
- Complete session isolation between myses
- Each mysis has independent game state
- Fixes game state cache pollution
- Eliminates session_id sharing bug
- Matches SpaceMolt's expected usage pattern

Trade-offs:
- More HTTP connections (N myses × 1 connection each)
- Slightly more memory (N client instances)
- Slower startup (N initialize handshakes)
- Worth it for correct session isolation

Note: Some test files need updates for new API but main build succeeds.

xonecas2026-02-09 599f60730bf283af37073498e000f6d307d84a4c parent 18e900d

18 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

cmd/zoea/main.go+13−41
@@ -96,8 +96,18 @@ func main() {
9696 registry := initProviders(cfg, creds)
9797 log.Debug().Int("providers", len(registry.List())).Msg("Providers initialized")
9898
99- // Initialize commander
100- commander := core.NewCommander(s, registry, bus, cfg)
99+ // Determine MCP endpoint for myses
100+ var mcpEndpoint string
101+ if *offline {
102+ log.Info().Msg("Running in offline mode - myses will use stub MCP client")
103+ // Empty endpoint signals offline mode
104+ } else if cfg.MCP.Upstream != "" {
105+ mcpEndpoint = cfg.MCP.Upstream
106+ log.Info().Str("endpoint", mcpEndpoint).Msg("MCP endpoint configured - each mysis will create its own client")
107+ }
108+
109+ // Initialize commander with MCP endpoint
110+ commander := core.NewCommander(s, registry, bus, cfg, mcpEndpoint)
101111
102112 // Load existing myses from database
103113 if err := commander.LoadMyses(); err != nil {
@@ -106,51 +116,13 @@ func main() {
106116 log.Debug().Int("myses", commander.MysisCount()).Msg("Myses loaded")
107117
108118 // Auto-start all existing myses on launch
119+ // Each mysis will create its own MCP client during Start()
109120 for _, a := range commander.ListMyses() {
110121 if err := a.Start(); err != nil {
111122 log.Warn().Err(err).Str("mysis", a.Name()).Msg("Failed to start mysis")
112123 }
113124 }
114125
115- // Initialize MCP proxy
116- var upstreamClient mcp.UpstreamClient
117- if *offline {
118- log.Info().Msg("Running in offline mode using stub MCP client")
119- upstreamClient = mcp.NewStubClient()
120- } else if cfg.MCP.Upstream != "" {
121- upstreamClient = mcp.NewClient(cfg.MCP.Upstream)
122- }
123-
124- mcpProxy := mcp.NewProxy(upstreamClient)
125- mcpProxy.SetAccountStore(&accountStoreAdapter{s})
126- mcpProxy.SetGameStateStore(s)
127- mcp.RegisterOrchestratorTools(mcpProxy, &commanderAdapter{commander})
128-
129- // Initialize upstream MCP connection if configured
130- if mcpProxy.HasUpstream() {
131- ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
132- if err := mcpProxy.Initialize(ctx); err != nil {
133- log.Error().Err(err).Str("upstream", cfg.MCP.Upstream).Msg("Failed to initialize MCP upstream - game tools will be unavailable")
134- } else {
135- // List available tools to verify connection
136- tools, err := mcpProxy.ListTools(ctx)
137- if err != nil {
138- log.Error().Err(err).Msg("Failed to list MCP tools")
139- } else {
140- log.Info().Int("total_tools", len(tools)).Int("local_tools", mcpProxy.LocalToolCount()).Msg("MCP tools available")
141- for _, t := range tools {
142- log.Debug().Str("tool", t.Name).Str("description", t.Description).Msg("Available tool")
143- }
144- }
145- }
146- cancel()
147- }
148-
149- // Connect MCP proxy to commander so myses can use tools
150- commander.SetMCP(mcpProxy)
151-
152- log.Debug().Bool("upstream", mcpProxy.HasUpstream()).Int("local_tools", mcpProxy.LocalToolCount()).Msg("MCP proxy initialized")
153-
154126 // Log goroutine count at startup for leak detection
155127 log.Info().Int("goroutines", runtime.NumGoroutine()).Msg("Application started")
156128
internal/core/account_test.go+1−1
@@ -295,7 +295,7 @@ func TestMysis_Stop_ReleasesAccount(t *testing.T) {
295295
296296 // Use mock provider
297297 mock := provider.NewMock("mock", "test response")
298- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
298+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
299299
300300 // Start the mysis so it enters Running state
301301 if err := m.Start(); err != nil {
internal/core/commander.go+17−34
@@ -9,7 +9,6 @@ import (
99
1010 "github.com/rs/zerolog/log"
1111 "github.com/xonecas/zoea-nova/internal/config"
12- "github.com/xonecas/zoea-nova/internal/mcp"
1312 "github.com/xonecas/zoea-nova/internal/provider"
1413 "github.com/xonecas/zoea-nova/internal/store"
1514 )
@@ -19,38 +18,28 @@ type Commander struct {
1918 mu sync.RWMutex
2019 wg sync.WaitGroup // Tracks running mysis goroutines
2120
22- myses map[string]*Mysis
23- store *store.Store
24- registry *provider.Registry
25- bus *EventBus
26- config *config.Config
27- mcp *mcp.Proxy
28- maxMyses int
21+ myses map[string]*Mysis
22+ store *store.Store
23+ registry *provider.Registry
24+ bus *EventBus
25+ config *config.Config
26+ mcpEndpoint string // MCP upstream endpoint for myses to create their own clients
27+ maxMyses int
2928 }
3029
3130 // NewCommander creates a new commander.
32-func NewCommander(s *store.Store, reg *provider.Registry, bus *EventBus, cfg *config.Config) *Commander {
31+func NewCommander(s *store.Store, reg *provider.Registry, bus *EventBus, cfg *config.Config, mcpEndpoint string) *Commander {
3332 return &Commander{
34- myses: make(map[string]*Mysis),
35- store: s,
36- registry: reg,
37- bus: bus,
38- config: cfg,
39- maxMyses: cfg.Swarm.MaxMyses,
33+ myses: make(map[string]*Mysis),
34+ store: s,
35+ registry: reg,
36+ bus: bus,
37+ config: cfg,
38+ mcpEndpoint: mcpEndpoint,
39+ maxMyses: cfg.Swarm.MaxMyses,
4040 }
4141 }
4242
43-// SetMCP sets the MCP proxy for all myses.
44-func (c *Commander) SetMCP(proxy *mcp.Proxy) {
45- c.mu.Lock()
46- c.mcp = proxy
47- // Set MCP on all existing myses
48- for _, mysis := range c.myses {
49- mysis.SetMCP(proxy)
50- }
51- c.mu.Unlock()
52-}
53-
5443 // LoadMyses loads existing myses from the store.
5544 // Myses are loaded in stopped state; they must be explicitly started.
5645 func (c *Commander) LoadMyses() error {
@@ -69,10 +58,7 @@ func (c *Commander) LoadMyses() error {
6958 continue
7059 }
7160
72- mysis := NewMysis(sm.ID, sm.Name, sm.CreatedAt, p, c.store, c.bus, c)
73- if c.mcp != nil {
74- mysis.SetMCP(c.mcp)
75- }
61+ mysis := NewMysis(sm.ID, sm.Name, sm.CreatedAt, p, c.store, c.bus, c.mcpEndpoint, c)
7662 c.myses[sm.ID] = mysis
7763 }
7864
@@ -107,10 +93,7 @@ func (c *Commander) CreateMysis(name, providerName string) (*Mysis, error) {
10793 }
10894
10995 // Create runtime mysis
110- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, p, c.store, c.bus, c)
111- if c.mcp != nil {
112- mysis.SetMCP(c.mcp)
113- }
96+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, p, c.store, c.bus, c.mcpEndpoint, c)
11497 c.myses[stored.ID] = mysis
11598
11699 // Emit event
internal/core/commander_async_test.go+2−5
@@ -6,7 +6,6 @@ import (
66 "time"
77
88 "github.com/xonecas/zoea-nova/internal/config"
9- "github.com/xonecas/zoea-nova/internal/mcp"
109 "github.com/xonecas/zoea-nova/internal/provider"
1110 "github.com/xonecas/zoea-nova/internal/store"
1211 )
@@ -34,11 +33,9 @@ func setupCommanderAsyncTest(t *testing.T) (*Commander, *store.Store, *EventBus,
3433 },
3534 }
3635
37- c := NewCommander(s, reg, bus, cfg)
36+ c := NewCommander(s, reg, bus, cfg, "")
3837
39- // Set a dummy MCP proxy to avoid "no tools" error events
40- proxy := mcp.NewProxy(nil)
41- c.SetMCP(proxy)
38+ // Note: Each mysis creates its own MCP client during Start()
4239
4340 cleanup := func() {
4441 bus.Close()
internal/core/commander_test.go+5−8
@@ -7,7 +7,6 @@ import (
77 "time"
88
99 "github.com/xonecas/zoea-nova/internal/config"
10- "github.com/xonecas/zoea-nova/internal/mcp"
1110 "github.com/xonecas/zoea-nova/internal/provider"
1211 "github.com/xonecas/zoea-nova/internal/store"
1312 )
@@ -38,11 +37,10 @@ func setupCommanderTest(t *testing.T) (*Commander, *EventBus, func()) {
3837 },
3938 }
4039
41- cmd := NewCommander(s, reg, bus, cfg)
40+ cmd := NewCommander(s, reg, bus, cfg, "")
4241
4342 // Set a dummy MCP proxy to avoid "no tools" error events
44- proxy := mcp.NewProxy(nil)
45- cmd.SetMCP(proxy)
43+ // Note: Each mysis creates its own MCP client during Start()
4644
4745 cleanup := func() {
4846 cmd.StopAll()
@@ -520,7 +518,7 @@ func TestCommanderLoadMyses(t *testing.T) {
520518 },
521519 }
522520
523- cmd := NewCommander(s, reg, bus, cfg)
521+ cmd := NewCommander(s, reg, bus, cfg, "")
524522
525523 if err := cmd.LoadMyses(); err != nil {
526524 t.Fatalf("LoadMyses() error: %v", err)
@@ -573,9 +571,8 @@ func TestBroadcastDoesNotBlockOnBusyMysis(t *testing.T) {
573571 },
574572 }
575573
576- cmd := NewCommander(s, reg, bus, cfg)
577- proxy := mcp.NewProxy(nil)
578- cmd.SetMCP(proxy)
574+ cmd := NewCommander(s, reg, bus, cfg, "")
575+ // Note: Each mysis creates its own MCP client during Start()
579576
580577 // Create two myses: one slow, one fast
581578 slowMysis, err := cmd.CreateMysis("slow-mysis", "slow")
internal/core/long_running_stop_test.go+15−15
@@ -50,7 +50,7 @@ func TestLongRunningStopScenario(t *testing.T) {
5050 },
5151 }
5252
53- cmd := NewCommander(s, reg, bus, cfg)
53+ cmd := NewCommander(s, reg, bus, cfg, "")
5454
5555 // Create two myses: "long" and "sleepy"
5656 longMock := provider.NewMock("mock-long", "response from long")
@@ -59,8 +59,8 @@ func TestLongRunningStopScenario(t *testing.T) {
5959 storedLong, _ := s.CreateMysis("long", "mock", "test-model", 0.7)
6060 storedSleepy, _ := s.CreateMysis("sleepy", "mock", "test-model", 0.7)
6161
62- long := NewMysis(storedLong.ID, storedLong.Name, storedLong.CreatedAt, longMock, s, bus, cmd)
63- sleepy := NewMysis(storedSleepy.ID, storedSleepy.Name, storedSleepy.CreatedAt, sleepyMock, s, bus, cmd)
62+ long := NewMysis(storedLong.ID, storedLong.Name, storedLong.CreatedAt, longMock, s, bus, "", cmd)
63+ sleepy := NewMysis(storedSleepy.ID, storedSleepy.Name, storedSleepy.CreatedAt, sleepyMock, s, bus, "", cmd)
6464
6565 // Add them to commander
6666 cmd.mu.Lock()
@@ -164,14 +164,14 @@ func TestMultipleMysesStoppingSimultaneously(t *testing.T) {
164164 },
165165 }
166166
167- cmd := NewCommander(s, reg, bus, cfg)
167+ cmd := NewCommander(s, reg, bus, cfg, "")
168168
169169 // Create 5 myses
170170 myses := make([]*Mysis, 5)
171171 for i := 0; i < 5; i++ {
172172 mock := provider.NewMock(fmt.Sprintf("mock-%d", i), "response")
173173 stored, _ := s.CreateMysis(fmt.Sprintf("mysis-%d", i), "mock", "test-model", 0.7)
174- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, cmd)
174+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "", cmd)
175175 myses[i] = mysis
176176
177177 cmd.mu.Lock()
@@ -246,7 +246,7 @@ func TestStopDuringActiveLLMCalls(t *testing.T) {
246246
247247 // Mock with delay to simulate active LLM call
248248 mock := provider.NewMock("mock", "response").SetDelay(200 * time.Millisecond)
249- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
249+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
250250
251251 if err := mysis.Start(); err != nil {
252252 t.Fatalf("Start() error: %v", err)
@@ -306,7 +306,7 @@ func TestStopWithQueuedMessages(t *testing.T) {
306306
307307 // Mock with delay to create queue pressure
308308 mock := provider.NewMock("mock", "response").SetDelay(100 * time.Millisecond)
309- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
309+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
310310
311311 if err := mysis.Start(); err != nil {
312312 t.Fatalf("Start() error: %v", err)
@@ -376,13 +376,13 @@ func TestCleanExitAfterStop(t *testing.T) {
376376 },
377377 }
378378
379- cmd := NewCommander(s, reg, bus, cfg)
379+ cmd := NewCommander(s, reg, bus, cfg, "")
380380
381381 // Create and start multiple myses
382382 for i := 0; i < 3; i++ {
383383 mock := provider.NewMock(fmt.Sprintf("mock-%d", i), "response")
384384 stored, _ := s.CreateMysis(fmt.Sprintf("exit-test-%d", i), "mock", "test-model", 0.7)
385- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, cmd)
385+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "", cmd)
386386
387387 cmd.mu.Lock()
388388 cmd.myses[stored.ID] = mysis
@@ -439,13 +439,13 @@ func TestStopAllWithMixedStates(t *testing.T) {
439439 },
440440 }
441441
442- cmd := NewCommander(s, reg, bus, cfg)
442+ cmd := NewCommander(s, reg, bus, cfg, "")
443443
444444 // Create myses in different states
445445 // 1. Running
446446 runningStored, _ := s.CreateMysis("running", "mock", "test-model", 0.7)
447447 runningMock := provider.NewMock("mock-running", "response")
448- running := NewMysis(runningStored.ID, runningStored.Name, runningStored.CreatedAt, runningMock, s, bus, cmd)
448+ running := NewMysis(runningStored.ID, runningStored.Name, runningStored.CreatedAt, runningMock, s, bus, "", cmd)
449449 cmd.mu.Lock()
450450 cmd.myses[runningStored.ID] = running
451451 cmd.mu.Unlock()
@@ -454,7 +454,7 @@ func TestStopAllWithMixedStates(t *testing.T) {
454454 // 2. Idle (never started)
455455 idleStored, _ := s.CreateMysis("idle", "mock", "test-model", 0.7)
456456 idleMock := provider.NewMock("mock-idle", "response")
457- idle := NewMysis(idleStored.ID, idleStored.Name, idleStored.CreatedAt, idleMock, s, bus, cmd)
457+ idle := NewMysis(idleStored.ID, idleStored.Name, idleStored.CreatedAt, idleMock, s, bus, "", cmd)
458458 cmd.mu.Lock()
459459 cmd.myses[idleStored.ID] = idle
460460 cmd.mu.Unlock()
@@ -462,7 +462,7 @@ func TestStopAllWithMixedStates(t *testing.T) {
462462 // 3. Already stopped
463463 stoppedStored, _ := s.CreateMysis("stopped", "mock", "test-model", 0.7)
464464 stoppedMock := provider.NewMock("mock-stopped", "response")
465- stopped := NewMysis(stoppedStored.ID, stoppedStored.Name, stoppedStored.CreatedAt, stoppedMock, s, bus, cmd)
465+ stopped := NewMysis(stoppedStored.ID, stoppedStored.Name, stoppedStored.CreatedAt, stoppedMock, s, bus, "", cmd)
466466 cmd.mu.Lock()
467467 cmd.myses[stoppedStored.ID] = stopped
468468 cmd.mu.Unlock()
@@ -532,13 +532,13 @@ func TestStopAllStressTest(t *testing.T) {
532532 },
533533 }
534534
535- cmd := NewCommander(s, reg, bus, cfg)
535+ cmd := NewCommander(s, reg, bus, cfg, "")
536536
537537 // Create multiple myses
538538 for i := 0; i < 3; i++ {
539539 mock := provider.NewMock(fmt.Sprintf("mock-%d", i), "response")
540540 stored, _ := s.CreateMysis(fmt.Sprintf("stress-%d", i), "mock", "test-model", 0.7)
541- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, cmd)
541+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "", cmd)
542542
543543 cmd.mu.Lock()
544544 cmd.myses[stored.ID] = mysis
internal/core/mysis.go+186−18
@@ -22,14 +22,16 @@ import (
2222 type Mysis struct {
2323 mu sync.RWMutex
2424
25- id string
26- name string
27- createdAt time.Time
28- provider provider.Provider
29- store *store.Store
30- bus *EventBus
31- mcp *mcp.Proxy
32- commander *Commander // Reference to parent commander for WaitGroup
25+ id string
26+ name string
27+ createdAt time.Time
28+ provider provider.Provider
29+ store *store.Store
30+ bus *EventBus
31+ mcpEndpoint string // MCP upstream endpoint for creating own client
32+ mcpClient *mcp.Client // Per-mysis MCP client for session isolation
33+ mcpProxy *mcp.Proxy // Per-mysis MCP proxy wrapping the client
34+ commander *Commander // Reference to parent commander for WaitGroup
3335
3436 state MysisState
3537 ctx context.Context
@@ -62,7 +64,7 @@ type contextStats struct {
6264 }
6365
6466 // NewMysis creates a new mysis from stored data.
65-func NewMysis(id, name string, createdAt time.Time, p provider.Provider, s *store.Store, bus *EventBus, cmd ...*Commander) *Mysis {
67+func NewMysis(id, name string, createdAt time.Time, p provider.Provider, s *store.Store, bus *EventBus, mcpEndpoint string, cmd ...*Commander) *Mysis {
6668 var commander *Commander
6769 if len(cmd) > 0 {
6870 commander = cmd[0]
@@ -74,6 +76,7 @@ func NewMysis(id, name string, createdAt time.Time, p provider.Provider, s *stor
7476 provider: p,
7577 store: s,
7678 bus: bus,
79+ mcpEndpoint: mcpEndpoint,
7780 commander: commander,
7881 state: MysisStateIdle,
7982 activityState: ActivityStateIdle,
@@ -110,14 +113,6 @@ func (m *Mysis) computeMessageStats(messages []provider.Message) contextStats {
110113 return stats
111114 }
112115
113-// SetMCP sets the MCP proxy for tool calling.
114-func (m *Mysis) SetMCP(proxy *mcp.Proxy) {
115- a := m
116- a.mu.Lock()
117- defer a.mu.Unlock()
118- a.mcp = proxy
119-}
120-
121116 // ID returns the mysis unique identifier.
122117 func (m *Mysis) ID() string {
123118 a := m
@@ -305,9 +300,169 @@ func (m *Mysis) Start() error {
305300 // Initial encouragement message (if needed) is added by getContextMemories() in run() loop
306301 go a.run(ctx)
307302
303+ // Initialize MCP client in background (non-blocking)
304+ go a.initializeMCP(ctx)
305+
308306 return nil
309307 }
310308
309+// initializeMCP creates and initializes a per-mysis MCP client for session isolation.
310+// This runs in a goroutine to avoid blocking Start().
311+func (m *Mysis) initializeMCP(ctx context.Context) {
312+ a := m
313+
314+ // Skip if no MCP endpoint configured
315+ if a.mcpEndpoint == "" {
316+ log.Debug().Str("mysis", a.name).Msg("No MCP endpoint configured, skipping MCP initialization")
317+ return
318+ }
319+
320+ // Create MCP client
321+ client := mcp.NewClient(a.mcpEndpoint)
322+ proxy := mcp.NewProxy(client)
323+
324+ // Set account store and game state store
325+ proxy.SetAccountStore(&accountStoreAdapter{a.store})
326+ proxy.SetGameStateStore(a.store)
327+
328+ // Register orchestrator tools if commander is available
329+ if a.commander != nil {
330+ mcp.RegisterOrchestratorTools(proxy, &commanderAdapter{a.commander})
331+ }
332+
333+ // Initialize with timeout
334+ initCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
335+ defer cancel()
336+
337+ if err := proxy.Initialize(initCtx); err != nil {
338+ log.Error().
339+ Err(err).
340+ Str("mysis", a.name).
341+ Str("endpoint", a.mcpEndpoint).
342+ Msg("Failed to initialize MCP client - tools will be unavailable")
343+ return
344+ }
345+
346+ // List tools to verify connection
347+ tools, err := proxy.ListTools(initCtx)
348+ if err != nil {
349+ log.Error().
350+ Err(err).
351+ Str("mysis", a.name).
352+ Msg("Failed to list MCP tools")
353+ } else {
354+ log.Info().
355+ Str("mysis", a.name).
356+ Int("tool_count", len(tools)).
357+ Msg("MCP client initialized successfully")
358+ }
359+
360+ // Store client and proxy
361+ a.mu.Lock()
362+ a.mcpClient = client
363+ a.mcpProxy = proxy
364+ a.mu.Unlock()
365+}
366+
367+// commanderAdapter adapts Commander to the mcp.Orchestrator interface.
368+type commanderAdapter struct {
369+ commander *Commander
370+}
371+
372+func (a *commanderAdapter) MysisCount() int {
373+ return a.commander.MysisCount()
374+}
375+
376+func (a *commanderAdapter) MaxMyses() int {
377+ return a.commander.MaxMyses()
378+}
379+
380+func (a *commanderAdapter) GetStateCounts() map[string]int {
381+ return a.commander.GetStateCounts()
382+}
383+
384+func (a *commanderAdapter) SendMessageAsync(mysisID, message string) error {
385+ return a.commander.SendMessageAsync(mysisID, message)
386+}
387+
388+func (a *commanderAdapter) BroadcastAsync(message string) error {
389+ return a.commander.BroadcastAsync(message)
390+}
391+
392+func (a *commanderAdapter) BroadcastFrom(senderID, message string) error {
393+ return a.commander.BroadcastFrom(senderID, message)
394+}
395+
396+func (a *commanderAdapter) SearchMessages(mysisID, query string, limit int) ([]mcp.SearchResult, error) {
397+ memories, err := a.commander.Store().SearchMemories(mysisID, query, limit)
398+ if err != nil {
399+ return nil, err
400+ }
401+
402+ results := make([]mcp.SearchResult, len(memories))
403+ for i, m := range memories {
404+ results[i] = mcp.SearchResult{
405+ Role: string(m.Role),
406+ Source: string(m.Source),
407+ Content: m.Content,
408+ CreatedAt: m.CreatedAt.Format("2006-01-02 15:04:05"),
409+ }
410+ }
411+ return results, nil
412+}
413+
414+func (a *commanderAdapter) SearchReasoning(mysisID, query string, limit int) ([]mcp.ReasoningResult, error) {
415+ memories, err := a.commander.Store().SearchReasoning(mysisID, query, limit)
416+ if err != nil {
417+ return nil, err
418+ }
419+
420+ results := make([]mcp.ReasoningResult, len(memories))
421+ for i, m := range memories {
422+ results[i] = mcp.ReasoningResult{
423+ Role: string(m.Role),
424+ Source: string(m.Source),
425+ Content: m.Content,
426+ Reasoning: m.Reasoning,
427+ CreatedAt: m.CreatedAt.Format("2006-01-02 15:04:05"),
428+ }
429+ }
430+ return results, nil
431+}
432+
433+// accountStoreAdapter adapts store.Store to mcp.AccountStore interface.
434+type accountStoreAdapter struct {
435+ store *store.Store
436+}
437+
438+func (a *accountStoreAdapter) CreateAccount(username, password string) (*mcp.Account, error) {
439+ acc, err := a.store.CreateAccount(username, password)
440+ if err != nil {
441+ return nil, err
442+ }
443+ return &mcp.Account{Username: acc.Username, Password: acc.Password}, nil
444+}
445+
446+func (a *accountStoreAdapter) MarkAccountInUse(username string) error {
447+ return a.store.MarkAccountInUse(username)
448+}
449+
450+func (a *accountStoreAdapter) ReleaseAccount(username string) error {
451+ return a.store.ReleaseAccount(username)
452+}
453+
454+func (a *accountStoreAdapter) ReleaseAllAccounts() error {
455+ return a.store.ReleaseAllAccounts()
456+}
457+
458+func (a *accountStoreAdapter) ClaimAccount() (*mcp.Account, error) {
459+ acc, err := a.store.ClaimAccount()
460+ if err != nil {
461+ return nil, err
462+ }
463+ return &mcp.Account{Username: acc.Username, Password: acc.Password}, nil
464+}
465+
311466 // Stop halts the mysis processing loop.
312467 func (m *Mysis) Stop() error {
313468 a := m
@@ -371,6 +526,19 @@ func (m *Mysis) Stop() error {
371526 }
372527 }
373528
529+ // Close MCP client
530+ a.mu.Lock()
531+ mcpClient := a.mcpClient
532+ a.mcpClient = nil
533+ a.mcpProxy = nil
534+ a.mu.Unlock()
535+
536+ if mcpClient != nil {
537+ if err := mcpClient.Close(); err != nil {
538+ log.Warn().Err(err).Str("mysis", a.name).Msg("Failed to close MCP client")
539+ }
540+ }
541+
374542 return nil
375543 }
376544
@@ -384,7 +552,7 @@ func (m *Mysis) SendMessageFrom(content string, source store.MemorySource, sende
384552 a.mu.RLock()
385553 state := a.state
386554 p := a.provider
387- mcpProxy := a.mcp
555+ mcpProxy := a.mcpProxy
388556 a.mu.RUnlock()
389557
390558 if err := validateCanAcceptMessage(state); err != nil {
internal/core/mysis_account_release_test.go+1−1
@@ -28,7 +28,7 @@ func TestAccountReleaseOnError(t *testing.T) {
2828 }
2929
3030 // Create mysis
31- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, p, s, bus)
31+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, p, s, bus, "")
3232
3333 // Start mysis
3434 if err := mysis.Start(); err != nil {
internal/core/mysis_context_integration_test.go+2−2
@@ -22,7 +22,7 @@ func TestMysisContextCancellationIntegration(t *testing.T) {
2222 if err != nil {
2323 t.Fatalf("CreateMysis error: %v", err)
2424 }
25- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
25+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
2626
2727 // Start mysis (will add system prompt automatically)
2828 // Note: Myses don't have autonomous loops - they only respond to messages
@@ -94,7 +94,7 @@ func TestMysisContextCancellationIntegration(t *testing.T) {
9494 if err != nil {
9595 t.Fatalf("CreateMysis error: %v", err)
9696 }
97- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
97+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
9898
9999 // Start mysis
100100 // Note: Myses don't have autonomous loops - they only respond to messages
internal/core/mysis_race_test.go+2−2
@@ -32,7 +32,7 @@ func TestStopWithMultipleInFlightMessages(t *testing.T) {
3232
3333 // Mock provider with 2s delay and respects context cancellation
3434 mock := provider.NewMock("mock", "ok").SetDelay(2 * time.Second)
35- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
35+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
3636
3737 // Start the mysis (will add system prompt automatically)
3838 // Note: Myses don't have autonomous loops - they only respond to messages
@@ -124,7 +124,7 @@ func TestStopWithMultipleInFlightMessages_Shorter(t *testing.T) {
124124
125125 // Shorter delay for faster test iteration
126126 mock := provider.NewMock("mock", "ok").SetDelay(200 * time.Millisecond)
127- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
127+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
128128
129129 // Start the mysis
130130 // Note: Myses don't have autonomous loops - they only respond to messages
internal/core/mysis_real_provider_test.go+2−2
@@ -38,7 +38,7 @@ func TestStopWithRealOllamaProvider(t *testing.T) {
3838
3939 // Use smallest/fastest model available (qwen3:4b)
4040 ollamaProvider := provider.NewOllama("http://localhost:11434", "qwen3:4b")
41- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, ollamaProvider, s, bus)
41+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, ollamaProvider, s, bus, "")
4242
4343 // Start the mysis (spawns initial SendMessage with REAL HTTP call)
4444 if err := m.Start(); err != nil {
@@ -96,7 +96,7 @@ func TestStopDuringRealLLMCall(t *testing.T) {
9696 }
9797
9898 ollamaProvider := provider.NewOllama("http://localhost:11434", "qwen3:4b")
99- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, ollamaProvider, s, bus)
99+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, ollamaProvider, s, bus, "")
100100
101101 if err := m.Start(); err != nil {
102102 t.Fatalf("Start() error: %v", err)
internal/core/mysis_stop_race_aggressive_test.go+2−2
@@ -35,7 +35,7 @@ func TestStopRaceAggressive(t *testing.T) {
3535 }
3636
3737 mock := provider.NewMock("mock", "Hello!")
38- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
38+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
3939
4040 // Start mysis
4141 if err := m.Start(); err != nil {
@@ -137,7 +137,7 @@ func TestStopRaceTiming(t *testing.T) {
137137 }
138138
139139 mock := provider.NewMock("mock", "Hello!")
140- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
140+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
141141
142142 // Start mysis
143143 if err := m.Start(); err != nil {
internal/core/mysis_stop_race_instrumented_test.go+2−2
@@ -163,7 +163,7 @@ func TestStopRaceInstrumented(t *testing.T) {
163163 }
164164
165165 mock := provider.NewMock("mock", "Hello!")
166- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
166+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
167167
168168 // Start mysis
169169 if err := m.Start(); err != nil {
@@ -293,7 +293,7 @@ func TestStopRaceInstrumentedSingle(t *testing.T) {
293293 }
294294
295295 mock := provider.NewMock("mock", "Hello!")
296- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
296+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
297297
298298 // Start mysis
299299 if err := m.Start(); err != nil {
internal/core/mysis_test.go+38−43
@@ -11,7 +11,6 @@ import (
1111 "time"
1212
1313 "github.com/xonecas/zoea-nova/internal/constants"
14- "github.com/xonecas/zoea-nova/internal/mcp"
1514 "github.com/xonecas/zoea-nova/internal/provider"
1615 "github.com/xonecas/zoea-nova/internal/store"
1716 )
@@ -47,7 +46,7 @@ func TestMysisLifecycle(t *testing.T) {
4746 }
4847
4948 mock := provider.NewMock("mock", "Hello from mysis!")
50- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
49+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
5150
5251 // Initial state
5352 if mysis.State() != MysisStateIdle {
@@ -97,7 +96,7 @@ func TestMysisConcurrentStopDuringTurn(t *testing.T) {
9796 }
9897
9998 mock := provider.NewMock("mock", "ok").SetDelay(50 * time.Millisecond)
100- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
99+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
101100
102101 if err := mysis.Start(); err != nil {
103102 t.Fatalf("Start() error: %v", err)
@@ -130,7 +129,7 @@ func TestMysisSendMessage(t *testing.T) {
130129
131130 stored, _ := s.CreateMysis("msg-mysis", "mock", "test-model", 0.7)
132131 mock := provider.NewMock("mock", "I received your message!")
133- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
132+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
134133
135134 // Can send to idle mysis (will be stored and processed when started)
136135 if err := mysis.SendMessage("Hello", store.MemorySourceDirect); err != nil {
@@ -218,7 +217,7 @@ func TestMysisReceivesBroadcastWithSender(t *testing.T) {
218217
219218 receiverStored, _ := s.CreateMysis("receiver", "mock", "test-model", 0.7)
220219 mock := provider.NewMock("mock", "response")
221- receiver := NewMysis(receiverStored.ID, receiverStored.Name, receiverStored.CreatedAt, mock, s, bus)
220+ receiver := NewMysis(receiverStored.ID, receiverStored.Name, receiverStored.CreatedAt, mock, s, bus, "")
222221
223222 if err := receiver.Start(); err != nil {
224223 t.Fatalf("Start() error: %v", err)
@@ -259,7 +258,7 @@ func TestMysisSetErrorState(t *testing.T) {
259258
260259 stored, _ := s.CreateMysis("error-state-test", "mock", "test-model", 0.7)
261260 mock := provider.NewMock("mock", "response")
262- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
261+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
263262
264263 events := bus.Subscribe()
265264
@@ -300,7 +299,7 @@ func TestMysisProviderName(t *testing.T) {
300299
301300 stored, _ := s.CreateMysis("provider-test", "mock", "test-model", 0.7)
302301 mock := provider.NewMock("test-provider", "response")
303- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
302+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
304303
305304 if mysis.ProviderName() != "test-provider" {
306305 t.Errorf("expected provider name=test-provider, got %s", mysis.ProviderName())
@@ -319,7 +318,7 @@ func TestMysisStateEvents(t *testing.T) {
319318
320319 stored, _ := s.CreateMysis("event-test", "mock", "test-model", 0.7)
321320 mock := provider.NewMock("mock", "response")
322- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
321+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
323322
324323 events := bus.Subscribe()
325324
@@ -442,7 +441,7 @@ func TestSnapshotCompaction(t *testing.T) {
442441
443442 stored, _ := s.CreateMysis("compaction-test", "mock", "test-model", 0.7)
444443 mock := provider.NewMock("mock", "response")
445- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
444+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
446445
447446 // Add system prompt
448447 s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "", "")
@@ -495,7 +494,7 @@ func TestGetContextMemories_CurrentTurnBoundary(t *testing.T) {
495494 }
496495
497496 mock := provider.NewMock("mock", "response")
498- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
497+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
499498
500499 // Commander ID for testing
501500 commanderID := "commander-mysis-id"
@@ -631,7 +630,7 @@ func TestExtractLatestToolLoopHelper(t *testing.T) {
631630 }
632631
633632 mock := provider.NewMock("mock", "response")
634- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
633+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
635634
636635 tests := []struct {
637636 name string
@@ -967,7 +966,7 @@ func TestMysisStopDoesNotOverrideWithError(t *testing.T) {
967966 stored, _ := s.CreateMysis("stop-test", "mock", "test-model", 0.7)
968967
969968 mock := provider.NewMock("mock", "test response")
970- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
969+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
971970
972971 // Start the mysis
973972 if err := m.Start(); err != nil {
@@ -1012,7 +1011,7 @@ func TestStopDuringInitialMessage(t *testing.T) {
10121011 // Use a mock provider with NO delay - we want to test the race
10131012 // between Start() spawning SendMessage and Stop() being called
10141013 mock := provider.NewMock("mock", "response")
1015- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1014+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
10161015
10171016 // Start the mysis (spawns initial SendMessage goroutine)
10181017 if err := m.Start(); err != nil {
@@ -1068,7 +1067,7 @@ func TestStopDuringInitialMessageWithSlowProvider(t *testing.T) {
10681067
10691068 // Use a provider with delay to simulate the mysis being mid-turn when Stop is called
10701069 mock := provider.NewMock("mock", "response").SetDelay(50 * time.Millisecond)
1071- m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1070+ m := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
10721071
10731072 // Start the mysis
10741073 if err := m.Start(); err != nil {
@@ -1148,7 +1147,7 @@ func TestStopAtVariousTimings(t *testing.T) {
11481147
11491148 // Use a mock with a delay to simulate real LLM processing
11501149 mock := provider.NewMock("mock", "test response").SetDelay(25 * time.Millisecond)
1151- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1150+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
11521151
11531152 // Start mysis
11541153 if err := mysis.Start(); err != nil {
@@ -1193,7 +1192,7 @@ func TestEncouragementLimit(t *testing.T) {
11931192 }
11941193
11951194 mock := provider.NewMock("mock", "response")
1196- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1195+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
11971196
11981197 // Add system prompt only (no user messages)
11991198 err = s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "", "")
@@ -1237,7 +1236,7 @@ func TestEncouragementReset(t *testing.T) {
12371236 }
12381237
12391238 mock := provider.NewMock("mock", "response")
1240- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1239+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
12411240
12421241 // Set encouragementCount to 2 (simulate 2 synthetic messages)
12431242 mysis.mu.Lock()
@@ -1274,7 +1273,7 @@ func TestEncouragementReset(t *testing.T) {
12741273 }
12751274
12761275 mock := provider.NewMock("mock", "response")
1277- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1276+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
12781277
12791278 // Set encouragementCount to 2
12801279 mysis.mu.Lock()
@@ -1303,7 +1302,7 @@ func TestEncouragementReset(t *testing.T) {
13031302 }
13041303
13051304 mock := provider.NewMock("mock", "response")
1306- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1305+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
13071306
13081307 // Add system prompt
13091308 err = s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "", "")
@@ -1356,7 +1355,7 @@ func TestMysisWithBroadcastsKeepsRunning(t *testing.T) {
13561355
13571356 // Use mock provider with no delay for fast test
13581357 mock := provider.NewMock("mock", "I will continue exploring")
1359- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1358+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
13601359
13611360 // Step 1-2: Send broadcast "Explore the universe!" via QueueBroadcast
13621361 // This will be stored as a user message with source=broadcast
@@ -1464,7 +1463,7 @@ func TestExecuteToolCall_ErrorPaths(t *testing.T) {
14641463 t.Run("nil_mcp_proxy", func(t *testing.T) {
14651464 stored, _ := s.CreateMysis("nil-proxy-test", "mock", "test-model", 0.7)
14661465 mock := provider.NewMock("mock", "response")
1467- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1466+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
14681467
14691468 // Call executeToolCall with nil proxy
14701469 tc := provider.ToolCall{
@@ -1493,14 +1492,13 @@ func TestExecuteToolCall_ErrorPaths(t *testing.T) {
14931492 t.Run("tool_call_timeout", func(t *testing.T) {
14941493 stored, _ := s.CreateMysis("timeout-test", "mock", "test-model", 0.7)
14951494 mock := provider.NewMock("mock", "response")
1496- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1495+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
14971496
14981497 // Create a context with very short timeout
14991498 ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond)
15001499 defer cancel()
15011500 time.Sleep(10 * time.Millisecond) // Ensure timeout fires
15021501
1503- proxy := mcp.NewProxy(nil)
15041502 tc := provider.ToolCall{
15051503 ID: "call_1",
15061504 Name: "get_status",
@@ -1525,9 +1523,8 @@ func TestExecuteToolCall_ErrorPaths(t *testing.T) {
15251523 t.Run("invalid_tool_arguments", func(t *testing.T) {
15261524 stored, _ := s.CreateMysis("invalid-args-test", "mock", "test-model", 0.7)
15271525 mock := provider.NewMock("mock", "response")
1528- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1526+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
15291527
1530- proxy := mcp.NewProxy(nil)
15311528 // Register a tool that validates arguments
15321529 proxy.RegisterTool(
15331530 mcp.Tool{
@@ -1579,9 +1576,8 @@ func TestExecuteToolCall_ErrorPaths(t *testing.T) {
15791576 t.Run("mcp_call_tool_error", func(t *testing.T) {
15801577 stored, _ := s.CreateMysis("mcp-error-test", "mock", "test-model", 0.7)
15811578 mock := provider.NewMock("mock", "response")
1582- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1579+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
15831580
1584- proxy := mcp.NewProxy(nil)
15851581 // Register a tool that returns an error
15861582 proxy.RegisterTool(
15871583 mcp.Tool{
@@ -1618,9 +1614,8 @@ func TestExecuteToolCall_ErrorPaths(t *testing.T) {
16181614 t.Run("tool_result_parsing_with_empty_content", func(t *testing.T) {
16191615 stored, _ := s.CreateMysis("parse-test", "mock", "test-model", 0.7)
16201616 mock := provider.NewMock("mock", "response")
1621- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1617+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
16221618
1623- proxy := mcp.NewProxy(nil)
16241619 // Register a tool that returns empty content
16251620 proxy.RegisterTool(
16261621 mcp.Tool{
@@ -1674,7 +1669,7 @@ func setupTestMysis(t *testing.T) (*Mysis, func()) {
16741669 }
16751670
16761671 mock := provider.NewMock("mock", "test response")
1677- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1672+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
16781673
16791674 return mysis, cleanup
16801675 }
@@ -1692,7 +1687,7 @@ func setupTestMysisWithErrorProvider(t *testing.T) (*Mysis, func()) {
16921687
16931688 // Create a mock provider that returns errors
16941689 mock := provider.NewMock("mock", "").WithChatError(errors.New("provider error"))
1695- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1690+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
16961691
16971692 return mysis, cleanup
16981693 }
@@ -1790,7 +1785,7 @@ func TestQueueBroadcast_IdleState(t *testing.T) {
17901785 }
17911786
17921787 mock := provider.NewMock("mock", "Hello!")
1793- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1788+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
17941789
17951790 // Mysis starts in idle state
17961791 if mysis.State() != MysisStateIdle {
@@ -1824,7 +1819,7 @@ func TestQueueBroadcast_StoppedState(t *testing.T) {
18241819 }
18251820
18261821 mock := provider.NewMock("mock", "Hello!")
1827- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
1822+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
18281823
18291824 // Start then stop
18301825 if err := mysis.Start(); err != nil {
@@ -2003,7 +1998,7 @@ func TestGetContextMemories_NoUserPrompt(t *testing.T) {
20031998
20041999 stored, _ := s.CreateMysis("no-prompt-test", "mock", "test-model", 0.7)
20052000 mock := provider.NewMock("mock", "response")
2006- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
2001+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
20072002
20082003 // Add only system and assistant messages (no user prompt)
20092004 err := s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "", "")
@@ -2040,7 +2035,7 @@ func TestGetContextMemories_OnlyHistoricalTurns(t *testing.T) {
20402035
20412036 stored, _ := s.CreateMysis("historical-test", "mock", "test-model", 0.7)
20422037 mock := provider.NewMock("mock", "response")
2043- mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
2038+ mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus, "")
20442039
20452040 // Add system prompt
Cut short: this commit's diff is over 1000 lines.
internal/core/mysis_tools_test.go+12−10
Cut short: this commit's diff is over 1000 lines.
internal/core/notifications_test.go+5−6
Cut short: this commit's diff is over 1000 lines.
internal/core/state_machine_test.go+2−4
Cut short: this commit's diff is over 1000 lines.
internal/core/tick_integration_test.go+2−3
Cut short: this commit's diff is over 1000 lines.