Skip to content

test: cover StructuredDiscussion.flatten context truncation and cache breakpoints - #34

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1789677972-test-structured-discussion-flatten
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1789677972-test-structured-discussion-flatten

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Closes a code-scan coverage gap: StructuredDiscussion.flatten builds the exact message list sent to the model on every ToolUseAgent step, and had no test anywhere. A regression there silently changes model context (dropped observations) or prompt caching (cost/correctness), with no failing test.

New file tests/agents/test_tool_use_agent.py, pure objects, no LLM and no network. It pins both halves of the index-sensitive logic:

  • tail selection by keep_last_n_obs — non-tail groups collapse to group.summary, the last n groups stay verbatim, and a non-tail group without a summary falls back to its messages:
    groups = [(2 msgs, summary), (1 msg, summary), (1 msg, no summary)]
    keep_last_n_obs=1  -> [g0_summary, g1_summary, g2_m0]
    keep_last_n_obs=None -> every message verbatim
    
  • cache-breakpoint rewrite at the boundary — earlier _cache_breakpoint flags (including a stale one pre-set on an earlier message) are cleared and exactly one breakpoint is set at the tail boundary; when keep_last_n_obs exceeds the group count the boundary index is negative and no breakpoint is set at all.

Tests use the real AnthropicAPIMessageBuilder (the only builder that actually implements mark_all_previous_msg_for_caching via _cache_breakpoint) rather than stubs, so the assertions track real message objects.

Note for reviewers: flatten marks messages[i] where i is the group index, which coincides with the first message of the boundary group only when every collapsed group contributes exactly one message. The tests document current behavior; changing that indexing is out of scope here.

Devin-Org: engineering

Link to Devin session: https://app.devin.ai/sessions/5a670129ef3840b1ad2fd78b2267b90c
Open in Devin Desktop: https://app.devin.ai/desktop/session/5a670129ef3840b1ad2fd78b2267b90c?variant=devin

…ints (bug risk in untested index-sensitive logic)
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants