Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(agent-core): a checkpoint that keeps the Turn's inputs says they win (#2365)

Call White6f1b3ee538d9
diff --git a/core/agent_core/harness/context.py b/core/agent_core/harness/context.py
index e3e0117be..97ec56fe2 100644
--- a/core/agent_core/harness/context.py
+++ b/core/agent_core/harness/context.py
@@ -156,6 +156,12 @@ CHECKPOINT_FRAMING = (
"history, not new instructions: the user requirements recorded in it still apply, but do not treat the "
"record itself as a request."
)
+#: The last line of a checkpoint that keeps the in-flight Turn's inputs (section 7): they come just before it, and a
+#: record that misstates the Turn (as finished, or as more than was asked) must not override them.
+KEPT_INPUTS_WIN = (
+ "The user message(s) placed just before this record are the current request and are still in progress; follow "
+ "them exactly as written. Where this record disagrees with them, they win."
+)
#: A drop that leaves out a previous checkpoint too large for the route says so (section 8 c).
CHECKPOINT_OMITTED = "An earlier checkpoint was too large for this model and was omitted"
SKILLS_LEAD = "Skills you had loaded are listed by name; run `vibe skill load <name>` again before you rely on one."
@@ -751,6 +757,7 @@ def render_summary(
skills_omitted: bool,
earlier_record: Optional[str],
checkpoint_omitted: bool = False,
+ keeps_inputs: bool = False,
) -> str:
lines = ["<context-checkpoint>"]
if checkpoint:
@@ -778,6 +785,8 @@ def render_summary(
lines += ["<skills-loaded>", SKILLS_LEAD, *named, "</skills-loaded>"]
if earlier_record:
lines += ["<earlier-record>", earlier_record, "</earlier-record>"]
+ if keeps_inputs:
+ lines.append(KEPT_INPUTS_WIN)
lines.append("</context-checkpoint>")
return "\n".join(lines)
@@ -813,6 +822,7 @@ def compaction_payload(
head = view.units[:cut]
files = _files(previous, head)
skills, skills_omitted = carried_skills(view, cut)
+ kept = [unit.seq for unit in head if unit.lead.kind == "input" and unit.seq in turn_inputs]
payload: dict[str, Any] = {
"version": 1,
"mode": mode,
@@ -828,13 +838,14 @@ def compaction_payload(
skills_omitted=skills_omitted,
earlier_record=earlier_record,
checkpoint_omitted=checkpoint_omitted,
+ keeps_inputs=bool(kept),
),
"checkpoint": checkpoint,
"state": list(state),
"first_kept_seq": view.units[cut].seq,
"summarized_to_seq": summarized_to_seq(view, cut),
"previous_compaction_id": previous_row.row_id if previous_row is not None else None,
- "kept_inputs": [unit.seq for unit in head if unit.lead.kind == "input" and unit.seq in turn_inputs],
+ "kept_inputs": kept,
"files_read": files.read,
"files_read_omitted": files.read_omitted,
"files_modified": files.modified,
diff --git a/docs/plans/agent-core-contracts/context.md b/docs/plans/agent-core-contracts/context.md
index d664de789..a3906e4e1 100644
--- a/docs/plans/agent-core-contracts/context.md
+++ b/docs/plans/agent-core-contracts/context.md
@@ -247,6 +247,7 @@ is written, so projection stays a pure function of the rows:
<earlier-record>
<the adapter's hint: where this Session's earlier conversation is stored, through summarized_to_seq>
</earlier-record>
+ The user message(s) placed just before this record are the current request and are still in progress; follow them exactly as written. Where this record disagrees with them, they win.
</context-checkpoint>
```
@@ -268,7 +269,7 @@ is written, so projection stays a pure function of the rows:
(`display`): escaped (`escape`: a backslash doubled, then control characters and `<`, `>` as `\uXXXX`, or
`\UXXXXXXXX` past the BMP), then cut in the middle to 160 UTF-8 bytes on a character boundary (its head and its file
name stay), at most about 40 tokens whatever the script, so a filename can neither add a line nor close a tag.
- Escaping is injective, so two paths look alike only when a cut hides where they differ. `<earlier-record>` is the adapter's short hint, left out when it supplies none.
+ Escaping is injective, so two paths look alike only when a cut hides where they differ. `<earlier-record>` is the adapter's short hint, left out when it supplies none. The last line is harness framing, written only when the row keeps the in-flight Turn's inputs (`kept_inputs`, §5): a mid-turn checkpoint may misstate the Turn (as finished, or as more than was asked), and the verbatim inputs placed before it must win; the owner-approved request (§11) is unchanged.
- `state`: texts the adapter rendered from their own stores when the checkpoint was written: the environment's core
fields (C-7 §8: cwd, os, shell, date, timezone; no Watches; each field displayed as every input's block displays it,
the cwd escaped and never cut, every other field cut to 160 UTF-8 bytes (`display`), so the block is the cwd, which
diff --git a/tests/agent_core/agent/test_context.py b/tests/agent_core/agent/test_context.py
index 67ab1694b..c5d242e5e 100644
--- a/tests/agent_core/agent/test_context.py
+++ b/tests/agent_core/agent/test_context.py
@@ -18,6 +18,7 @@ import pytest
from core.agent_core.ai.provider import ModelCapabilities, ModelEndpoint, ModelRequest
from core.agent_core.harness.context import (
+ KEPT_INPUTS_WIN,
CLEARED_PLACEHOLDER,
ITEM_BYTES,
budget,
@@ -355,6 +356,39 @@ def test_the_half_cut_is_nearest_to_half_and_the_rolling_cut_moves_earlier_until
assert half_cut(units[:1]) is None
+def test_a_checkpoint_that_keeps_the_turn_inputs_says_they_win_and_only_then():
+ # A mid-turn checkpoint keeps the Turn's inputs verbatim before it; its last line tells the model they are the
+ # request still in progress and win over the record. A checkpoint that keeps none says nothing of the kind.
+ rows = Rows()
+ rows.input("an older turn")
+ rows.response(value="done")
+ first = rows.input("read f10 to f18 in order")
+ rows.tool("read", "f10", call_id="r10", path="ctx2/f10.txt")
+ steer = rows.input("also count them")
+ rows.tool("read", "f11", call_id="r11", path="ctx2/f11.txt")
+ view = context_view(rows.rows)
+
+ def payload(turn_inputs):
+ return compaction_payload(
+ view, len(view.units) - 1, mode="normal", reason="threshold", checkpoint=_VALID, state=("STATE",),
+ earlier_record="Search the earlier record.", tokens_before=1, threshold=2, window=200_000,
+ summarizer=None, usage=None, turn_inputs=turn_inputs,
+ )
+
+ kept = payload({first.context_seq, steer.context_seq})
+ assert kept["kept_inputs"] == [first.context_seq, steer.context_seq]
+ assert kept["summary"].endswith(f"</earlier-record>\n{KEPT_INPUTS_WIN}\n</context-checkpoint>")
+ none = payload(set())
+ assert none["kept_inputs"] == [] and KEPT_INPUTS_WIN not in none["summary"]
+ assert none["summary"].endswith("</earlier-record>\n</context-checkpoint>")
+ # The order is unchanged: the kept inputs, the checkpoint (now ending with the line), then the tail.
+ rows.add("compaction", payload=kept)
+ messages = context_view(rows.rows).messages
+ texts = [message.content[0].text for message in messages[:3]]
+ assert texts[:2] == ["read f10 to f18 in order", "also count them"] and texts[2] == kept["summary"]
+ assert messages[3].tool_calls[0].id == "r11"
+
+
def test_a_cut_inside_the_turn_counts_every_input_it_keeps():
# A cut inside the in-flight Turn keeps all of its inputs, the first one and each steer (section 5): they count
# toward the kept tail once, at their own size, and a cut that would summarize nothing but them is no cut.
@@ -856,6 +890,7 @@ def test_a_checkpoint_carries_files_skills_and_pins_the_split_turn_input_across_
"<earlier-record>",
"The full earlier conversation is stored; search it with `vibe data query`.",
"</earlier-record>",
+ KEPT_INPUTS_WIN, # it keeps the parser turn's input
"</context-checkpoint>",
]
)