-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(semantic): add budget guard to overview generation with batched summarization #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
qin-ctx
merged 5 commits into
volcengine:main
from
deepakdevp:feature/overview-budget-guard
Mar 17, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bb1fd3a
feat(config): add SemanticConfig for overview/abstract generation limits
deepakdevp c2be248
fix(semantic): add budget guard to overview generation with batching
deepakdevp 15caec4
test(semantic): add tests for SemanticConfig and budget estimation
deepakdevp 43fa1d0
style(semantic): fix lint and formatting
deepakdevp f2acd87
fix(semantic): address review feedback from @qin-ctx
deepakdevp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Tests for SemanticConfig and overview budget estimation.""" | ||
|
|
||
| from openviking_cli.utils.config.parser_config import SemanticConfig | ||
|
|
||
|
|
||
| def test_semantic_config_defaults(): | ||
| """Test default values match previously hardcoded constants.""" | ||
| config = SemanticConfig() | ||
| assert config.max_file_content_chars == 30000 | ||
| assert config.max_overview_prompt_chars == 60000 | ||
| assert config.overview_batch_size == 50 | ||
| assert config.abstract_max_chars == 256 | ||
| assert config.overview_max_chars == 4000 | ||
|
|
||
|
|
||
| def test_semantic_config_custom_values(): | ||
| """Test custom values override defaults.""" | ||
| config = SemanticConfig( | ||
| max_overview_prompt_chars=100000, | ||
| overview_batch_size=100, | ||
| ) | ||
| assert config.max_overview_prompt_chars == 100000 | ||
| assert config.overview_batch_size == 100 | ||
| # Unchanged defaults | ||
| assert config.max_file_content_chars == 30000 | ||
| assert config.abstract_max_chars == 256 | ||
|
|
||
|
|
||
| def test_budget_under_limit_no_batching(): | ||
| """Small directories should not trigger batching.""" | ||
| config = SemanticConfig() | ||
| # 10 file summaries, each ~100 chars = ~1000 chars total | ||
| summaries = [{"name": f"file_{i}.py", "summary": "x" * 100} for i in range(10)] | ||
| total = sum(len(f"[{i}] {s['name']}: {s['summary']}") for i, s in enumerate(summaries, 1)) | ||
| assert total < config.max_overview_prompt_chars | ||
| assert len(summaries) <= config.overview_batch_size | ||
|
|
||
|
|
||
| def test_budget_over_limit_triggers_batching(): | ||
| """Large directories should exceed budget and require batching.""" | ||
| config = SemanticConfig() | ||
| # 200 file summaries, each ~500 chars = ~100000+ chars total | ||
| summaries = [{"name": f"file_{i}.py", "summary": "x" * 500} for i in range(200)] | ||
| total = sum(len(f"[{i}] {s['name']}: {s['summary']}") for i, s in enumerate(summaries, 1)) | ||
| assert total > config.max_overview_prompt_chars | ||
| assert len(summaries) > config.overview_batch_size | ||
|
|
||
|
|
||
| def test_abstract_truncation(): | ||
| """Test abstract is truncated to abstract_max_chars.""" | ||
| config = SemanticConfig(abstract_max_chars=100) | ||
| abstract = "x" * 200 | ||
| if len(abstract) > config.abstract_max_chars: | ||
| abstract = abstract[: config.abstract_max_chars - 3] + "..." | ||
| assert len(abstract) == 100 | ||
| assert abstract.endswith("...") | ||
|
|
||
|
|
||
| def test_overview_truncation(): | ||
| """Test overview is truncated to overview_max_chars.""" | ||
| config = SemanticConfig(overview_max_chars=500) | ||
| overview = "x" * 1000 | ||
| if len(overview) > config.overview_max_chars: | ||
| overview = overview[: config.overview_max_chars] | ||
| assert len(overview) == 500 | ||
|
|
||
|
|
||
| def test_batch_splitting(): | ||
| """Test batch splitting logic produces correct batch count.""" | ||
| config = SemanticConfig(overview_batch_size=50) | ||
| summaries = [{"name": f"f{i}.py", "summary": "s"} for i in range(120)] | ||
| batches = [ | ||
| summaries[i : i + config.overview_batch_size] | ||
| for i in range(0, len(summaries), config.overview_batch_size) | ||
| ] | ||
| assert len(batches) == 3 # 50 + 50 + 20 | ||
| assert len(batches[0]) == 50 | ||
| assert len(batches[1]) == 50 | ||
| assert len(batches[2]) == 20 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] (non-blocking) The tests here thoroughly validate
SemanticConfigdefaults and budget arithmetic, which is good. However, there are no tests for the core behavioral changes:_batched_generate_overviewindex mapping, the merge step, or the truncation enforcement insemantic_dag.py/semantic_processor.py.Consider adding at least one test with a mocked VLM that verifies:
[number]→ file name replacement is correct across batchesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acknowledged — will add behavioral tests with mocked VLM in a follow-up if needed. The current tests validate the config, budget logic, and batch splitting which are the core pure-function components.