Skip to content

Budget cumulative tool history before sending long Gemini and Anthropic requests #179

Description

@Anteriousis

Problem

The provider loops limit individual tool results, but do not bound the accumulated conversation sent on subsequent requests. Productive sequences of distinct calls can therefore replay a growing history until requests become expensive or exceed a model's context window.

This remains an issue even after repeated-state suppression and no-progress detection: legitimate calls with unique arguments still accumulate.

Evidence and reproduction

Audited main at 7289751459ceace471ac771f3a0ec39b972d1949. Area: AI provider orchestration. Findings come from source inspection and isolated Python execution of the relevant source functions with mocked CAD/model boundaries; no paid model requests or live CAD mutations were made.

An isolated execution of the Gemini child used 65 distinct tool calls, each returning a 20,024-byte projected tool result, below the individual 40 KiB bound. The context used the native engine so repeated vibecad_state_after was absent. The final outbound request serialized to 1,317,904 bytes. Earlier tool results were all replayed; no cumulative budget intervened.

This is a synthetic byte measurement, not an exact token count or a claim that every supported model rejects that particular size. Prompt caching may reduce processing charges on cache hits but does not remove logical context length.

Proposed fix

Add provider-aware input-history accounting before each request, including tools, system instructions, image context, and output reserve. Use a configurable high-water policy to compact or replace obsolete historical observations with bounded summaries/references before a hard limit is reached. Record actual provider usage where available and clearly distinguish estimates from measured tokens.

Preserve the current user obligation, live exact CAD state/revisions, unresolved operations, required tool-call/result pairs, and provider thought/signature requirements. Keep full source/API read tools available; handle large results deliberately rather than silently truncating exact source.

Acceptance tests

  • A productive sequence of distinct results crosses the configured threshold and triggers controlled history management before another oversized request.
  • Tool-call/result pairing and Gemini thought signatures remain valid.
  • Critical revisions, pending jobs, failures, and user constraints survive compaction.
  • Source/API reads and image-heavy turns are included in the budget policy.
  • Short turns incur no additional model call.
  • Compare cumulative request bytes, request count, and measured usage where available before/after.

Suggested priority: high for long sessions. This extends #130 and is separate from no-progress loop protection. Follow the repository's additive compatibility policy for new configuration and history-management behavior.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions