Compaction: the model's notes replace the middle of a long run (#158)
Before each driver call, over compact_at (0.6) of the prompt budget, the same model is asked for notes over the very request it was about to get, plus one message, so the server's cache covers all but the notes. The notes, with code's list of the calls they replace, become a compaction event that renders in place of its range, keeping word for word what started the work and the last few turns. Rare, large steps keep the prompt's start unchanged between them. A later compaction folds in the earlier; one from an earlier run's view is hidden. Failed notes are logged and fitting takes over. Fitting now applies compactions before it measures, records what it cuts (Trim) and logs each cut as context.trimmed. Wired into both agents' drivers and the benchmark; nisse-dev's helper loop is a follow-up. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J5Utyfzw7gF7UhjRDEtjTk
This commit is contained in:
1 parent
fa8d93cf41
commit
cb638fe687
20 files changed
+952
-44
No files matched your search
@@ -494,6 +494,30 @@ def test_the_ci_waits_may_be_zero(tmp_path: Path) -> None:
|
||||
assert (review.ci_wait_s, review.ci_grace_s) == (0, 0)
|
||||
|
||||
|
||||
def test_compaction_is_tuned_in_the_config(tmp_path: Path) -> None:
|
||||
from nisse_core.config import ConfigError
|
||||
from nisse_review.config import ReviewConfig
|
||||
|
||||
tree: dict[str, Any] = {
|
||||
"state_db": str(tmp_path / "s.db"),
|
||||
"llm": {"base_url": "http://llm", "token": "k"},
|
||||
"roles": {"reviewer": "local", "expert": "frontier"},
|
||||
"gitea": {"url": "https://g", "token": "t", "operators": ["don"]},
|
||||
}
|
||||
assert (
|
||||
ReviewConfig.from_tree(tree, {}).tuning.context.compaction().compact_at == 0.6
|
||||
)
|
||||
tuned = {
|
||||
**tree,
|
||||
"tuning": {"context": {"compact_at": 0.7, "compact_keep_turns": 2}},
|
||||
}
|
||||
compaction = ReviewConfig.from_tree(tuned, {}).tuning.context.compaction()
|
||||
assert (compaction.compact_at, compaction.keep_turns) == (0.7, 2)
|
||||
wrong = {**tree, "tuning": {"context": {"compact_at": 0.2, "compact_to": 0.3}}}
|
||||
with pytest.raises(ConfigError, match="compact_to must be less than compact_at"):
|
||||
ReviewConfig.from_tree(wrong, {})
|
||||
|
||||
|
||||
def test_diff_lines_are_the_heads_lines_a_diff_shows() -> None:
|
||||
diff = (
|
||||
"--- a/x.py\n+++ b/x.py\n@@ -1,3 +1,4 @@\n a\n-b\n+c\n+d\n e\n"
|
||||
|
||||
@@ -163,6 +163,8 @@ def test_build_wires_a_stop_to_every_model_call(tmp_path: Path) -> None:
|
||||
try:
|
||||
driver = built.scheduler._reviewer._driver
|
||||
assert driver._client is built.model
|
||||
# Compaction's notes are a model call a stop breaks off too.
|
||||
assert driver._compactor._client is built.model
|
||||
assert built.scheduler._reviewer._expert._client is built.model
|
||||
built.stop() # no call in flight: nothing raised
|
||||
assert driver._cancel.requested and built.scheduler._stop.is_set()
|
||||
|
||||
Reference in new issue
Block a user