Skip to content

Budget cumulative Gemini and Anthropic request history - #185

Open
Anteriousis wants to merge 1 commit into
10-X-eng:mainfrom
Anteriousis:fix/provider-history-budget
Open

Budget cumulative Gemini and Anthropic request history#185
Anteriousis wants to merge 1 commit into
10-X-eng:mainfrom
Anteriousis:fix/provider-history-budget

Conversation

@Anteriousis

Copy link
Copy Markdown
Contributor

Bound cumulative Gemini and Anthropic requests before generation. The default serialized input limit is 512 KiB; above 75%, older bulky successful tool observations become explicit references with original call IDs, sizes and hashes. The latest two tool batches and current live state stay available.

Original user instructions, tool arguments and thought/signature blocks remain intact. Exact source/API reads, failures, pending operations and critical revision/state fields are protected. If protected content still exceeds the limit, return an actionable stop before generation and preserve completed CAD work. This adds no summarization API calls.

README documents context options for the byte budget, optional model context window and Gemini output reserve. Diagnostics distinguish byte-based token estimates from provider-reported usage. Anthropic retains its existing usage reporting; Gemini now records usage if its stream supplies it.

Verification

  • Tests fail against the audited baseline and pass with the implementation.
  • Exact test/build commands and results follow.

With local test dependencies on PYTHONPATH, $python denotes the bundled Python executable:

# Against audited main (7289751459ceace471ac771f3a0ec39b972d1949):
& $python -m pytest -q src/Mod/VibeCAD/vibecad_tests/test_provider_history_budget.py -k 'productive_history or available_usage' --tb=short
# Red: 3 failed, 2 passed, 19 deselected.

# With this implementation:
& $python -m pytest -q src/Mod/VibeCAD/vibecad_tests/test_provider_history_budget.py src/Mod/VibeCAD/vibecad_tests/test_provider_subprocess.py src/Mod/VibeCAD/vibecad_tests/test_gemini_provider.py src/Mod/VibeCAD/vibecad_tests/test_provider_research_review.py --tb=short
# Green: 93 passed, 1 skipped (platform-specific).
& $python -m pytest -q src/Mod/VibeCAD/vibecad_tests/test_provider_history_budget.py -k productive_history -s --tb=short
& $python -m py_compile src/Mod/VibeCAD/VibeCADProvider.py src/Mod/VibeCAD/vibecad_tests/test_provider_history_budget.py
git diff --cached --check

Synthetic comparison: 12 distinct successful calls returning 20,000-character payloads; configured 100,000-byte budget versus disabled budget. Both versions make exactly 13 model requests.

Provider Cumulative bytes before Cumulative bytes after Largest request before Largest request after
Gemini 1,600,863 727,277 245,166 70,250
Anthropic 1,599,076 725,715 244,834 69,963

About 55% fewer cumulative serialized bytes in this fixture, without additional model requests. These are mocked byte measurements, not billed-token savings. No paid API calls or full FreeCAD GUI/C++ build were run.

Coverage includes valid call/result pairing, thought signatures, live revisions, failures, pending jobs, source/API reads, image/system/tool payload accounting, output reserve, configuration surviving context refreshes, and stopping before generation for irreducible oversized input.

Compatibility

  • Existing public APIs remain available; no parameters removed or renamed.
  • No preference keys, tool names or tool schemas renamed/removed.
  • Unlimited history is preserved by default: intentionally changed under the request to fix Budget cumulative tool history before sending long Gemini and Anthropic requests #179.
  • Opt-out/rollback: set history_budget_bytes=0 and leave context_window_tokens unset. Raising the budget permits larger exact reads.
  • No deprecations. Generation output caps are unchanged.

Limits: serialized bytes divided by four are an estimate, especially for images, not a tokenizer or a guaranteed context-window fit. Unknown model context limits are not guessed. The optional context-window check requires an integrator-supplied limit. Protected content can cause an early stop; omitted observations must be re-read when needed.

Issues

Closes #179.

Before and After Images

Not applicable; no GUI layout changes.

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.

Budget cumulative tool history before sending long Gemini and Anthropic requests

1 participant