(t *testing.T)
| 794 | func (p *errorProvider) MaxTokens() int { return 0 } |
| 795 | |
| 796 | func TestCompactionOverflowDoesNotLoop(t *testing.T) { |
| 797 | t.Parallel() |
| 798 | |
| 799 | // The model always returns a ContextOverflowError. Without the |
| 800 | // max-retry guard this would loop forever because compaction |
| 801 | // cannot fix the problem. |
| 802 | overflowErr := modelerrors.NewContextOverflowError(errors.New("prompt is too long")) |
| 803 | prov := &errorProvider{id: "test/overflow-model", err: overflowErr} |
| 804 | |
| 805 | root := agent.New("root", "You are a test agent", agent.WithModel(prov)) |
| 806 | tm := team.New(team.WithAgents(root)) |
| 807 | |
| 808 | rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(true), WithModelStore(mockModelStoreWithLimit{limit: 100})) |
| 809 | require.NoError(t, err) |
| 810 | |
| 811 | sess := session.New(session.WithUserMessage("Hello")) |
| 812 | events := rt.RunStream(t.Context(), sess) |
| 813 | |
| 814 | var compactionCount int |
| 815 | var sawError bool |
| 816 | for ev := range events { |
| 817 | if e, ok := ev.(*SessionCompactionEvent); ok && e.Status == "started" { |
| 818 | compactionCount++ |
| 819 | } |
| 820 | if _, ok := ev.(*ErrorEvent); ok { |
| 821 | sawError = true |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | // Compaction should have been attempted at most once, then the loop |
| 826 | // must give up and surface an error instead of retrying indefinitely. |
| 827 | require.LessOrEqual(t, compactionCount, 1, "expected at most 1 compaction attempt, got %d", compactionCount) |
| 828 | require.True(t, sawError, "expected an ErrorEvent after exhausting compaction retries") |
| 829 | } |
| 830 | |
| 831 | func TestSessionWithoutUserMessage(t *testing.T) { |
| 832 | t.Parallel() |
nothing calls this directly
no test coverage detected