@@ -529,14 +529,49 @@ func TestMysisContextCompaction(t *testing.T) {
529529 t.Errorf("expected first memory to be system prompt, got %s", memories[0].Role)
530530 }
531531
532+ // Count get_ship tool results - should only have 1 (the latest)
533+ shipResults := 0
532534 for _, m := range memories {
533- if m.Role == store.MemoryRoleTool {
534- t.Fatalf("expected no tool memories in context, found: %s", m.Content)
535+ if m.Role == store.MemoryRoleTool && strings.Contains(m.Content, `"ship_id"`) {
536+ shipResults++
535537 }
536- if m.Role == store.MemoryRoleAssistant && strings.HasPrefix(m.Content, constants.ToolCallStoragePrefix) {
537- t.Fatalf("expected no assistant tool-call memories in context, found: %s", m.Content)
538+ }
539+ if shipResults != 1 {
540+ t.Errorf("expected 1 get_ship result after compaction, got %d", shipResults)
541+ }
542+
543+ // Count get_system tool results - should only have 1 (the latest)
544+ systemResults := 0
545+ for _, m := range memories {
546+ if m.Role == store.MemoryRoleTool && strings.Contains(m.Content, `"system_id"`) {
547+ systemResults++
538548 }
539549 }
550+ if systemResults != 1 {
551+ t.Errorf("expected 1 get_system result after compaction, got %d", systemResults)
552+ }
553+
554+ // Non-snapshot tool result should be kept
555+ mineResults := 0
556+ for _, m := range memories {
557+ if m.Role == store.MemoryRoleTool && strings.Contains(m.Content, `"result":"mining"`) {
558+ mineResults++
559+ }
560+ }
561+ if mineResults != 1 {
562+ t.Errorf("expected 1 mine result (non-snapshot), got %d", mineResults)
563+ }
564+
565+ // Verify the latest get_ship result is kept (ship_4, not ship_0)
566+ foundLatestShip := false
567+ for _, m := range memories {
568+ if m.Role == store.MemoryRoleTool && strings.Contains(m.Content, `"ship_id":"ship_4"`) {
569+ foundLatestShip = true
570+ }
571+ }
572+ if !foundLatestShip {
573+ t.Error("expected latest get_ship result (ship_4) to be kept")
574+ }
540575 }
541576
542577 func TestSystemPromptContainsSearchGuidance(t *testing.T) {
@@ -607,14 +642,28 @@ func TestZoeaListMysesCompaction(t *testing.T) {
607642 if err != nil {
608643 t.Fatalf("getContextMemories() error: %v", err)
609644 }
645+
646+ // Count zoea_list_myses tool results - should only have 1 (the latest)
647+ listResults := 0
610648 for _, m := range memories {
611- if m.Role == store.MemoryRoleTool {
612- t.Fatalf("expected no tool memories in context, found: %s", m.Content)
649+ if m.Role == store.MemoryRoleTool && strings.Contains(m.Content, `"id":"mysis-`) {
650+ listResults++
613651 }
614- if m.Role == store.MemoryRoleAssistant && strings.HasPrefix(m.Content, constants.ToolCallStoragePrefix) {
615- t.Fatalf("expected no assistant tool-call memories in context, found: %s", m.Content)
652+ }
653+ if listResults != 1 {
654+ t.Errorf("expected 1 zoea_list_myses result after compaction, got %d", listResults)
655+ }
656+
657+ // Verify the latest result is kept (mysis-4, not mysis-0)
658+ foundLatest := false
659+ for _, m := range memories {
660+ if m.Role == store.MemoryRoleTool && strings.Contains(m.Content, `"id":"mysis-4"`) {
661+ foundLatest = true
616662 }
617663 }
664+ if !foundLatest {
665+ t.Error("expected latest zoea_list_myses result (mysis-4) to be kept")
666+ }
618667 }
619668
620669 func TestMysisContextCompactionNonSnapshot(t *testing.T) {
@@ -637,14 +686,17 @@ func TestMysisContextCompactionNonSnapshot(t *testing.T) {
637686 if err != nil {
638687 t.Fatalf("getContextMemories() error: %v", err)
639688 }
689+
690+ shipResults := 0
640691 for _, m := range memories {
641- if m.Role == store.MemoryRoleTool {
642- t.Fatalf("expected no tool memories in context, found: %s", m.Content)
643- }
644- if m.Role == store.MemoryRoleAssistant && strings.HasPrefix(m.Content, constants.ToolCallStoragePrefix) {
645- t.Fatalf("expected no assistant tool-call memories in context, found: %s", m.Content)
692+ if m.Role == store.MemoryRoleTool && strings.Contains(m.Content, `"ship_id"`) {
693+ shipResults++
646694 }
647695 }
696+
697+ if shipResults != 2 {
698+ t.Fatalf("expected 2 travel results to be kept, got %d", shipResults)
699+ }
648700 }
649701
650702 func TestComputeMemoryStats(t *testing.T) {