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(vibey): never replay another model's thinking as text (#2904)

Call Whiteabb44248e3c3
diff --git a/core/agent_core/ai/transform.py b/core/agent_core/ai/transform.py
index 6f8dbc7fd..383519cdb 100644
--- a/core/agent_core/ai/transform.py
+++ b/core/agent_core/ai/transform.py
@@ -137,6 +137,7 @@ def transform_messages(
# The synthetic results of the current run of hosted calls, and the assistant parts they split off.
results: list[ToolResultMessage] = []
parts: list[Message] = []
+ foreign_thinking = False
def split() -> None:
nonlocal content, results
@@ -171,14 +172,13 @@ def transform_messages(
continue
split()
if isinstance(block, ThinkingBlock):
- if block.redacted:
- if same_origin:
- content.append(block)
+ # Thinking is a model's private reasoning, not something the assistant said, so it never goes to a
+ # different origin in any form: as text it would be attributed to the target model, and providers
+ # refuse requests that carry another model's reasoning as text (cross-provider.md).
+ if not same_origin:
+ foreign_thinking = True
continue
- if block.signature is None:
- if block.text:
- content.append(TextBlock(text=block.text))
- elif same_origin:
+ if block.redacted or block.signature is not None:
content.append(block)
elif block.text:
content.append(TextBlock(text=block.text))
@@ -218,7 +218,9 @@ def transform_messages(
pending_tool_ids.setdefault(source_id, []).extend(wire_ids)
split()
transformed.extend(parts)
- if content or not parts:
+ # A response whose only content was another origin's thinking is skipped, as an aborted one is, rather than
+ # sent as an empty assistant message; one that was empty as served (a refusal) still goes, as before.
+ if content or not (parts or foreign_thinking):
transformed.append(_assistant_part(message, content, stop_reason=message.stop_reason))
transformed = _insert_synthetic_results(transformed)
diff --git a/docs/plans/agent-core-contracts/cross-provider.md b/docs/plans/agent-core-contracts/cross-provider.md
index f31430551..952b3f505 100644
--- a/docs/plans/agent-core-contracts/cross-provider.md
+++ b/docs/plans/agent-core-contracts/cross-provider.md
@@ -7,9 +7,9 @@ cross-provider history tests (MIT).
| Input | Same origin as the target | Different origin |
| --- | --- | --- |
| Text block | kept | kept |
-| Thinking block with `signature` | replayed verbatim with its signature | converted to plain assistant text; the signature is dropped |
+| Thinking block with `signature` | replayed verbatim with its signature | dropped |
| Thinking block, `redacted: true` | replayed verbatim | dropped |
-| Thinking block without `signature` (unverified origin, C-2) | sent as plain assistant text | sent as plain assistant text |
+| Thinking block without `signature` (unverified origin, C-2) | sent as plain assistant text | dropped |
| Tool call | kept; `id` and `signature` as stored | kept without `signature`; `id` normalized to the target's rules (below) |
| Tool result | kept | `tool_call_id` rewritten through the same id map |
| Image in a user or tool-result message | kept | kept if the target model accepts images, else `[image: <name or mime>]` |
@@ -19,6 +19,15 @@ cross-provider history tests (MIT).
Invariants:
+- Thinking never goes to a different origin, in any form (owner decision, 2026-10-21; Pi converts it to text). It is
+ the serving model's private reasoning, not something the assistant said: sent as assistant text it is attributed to
+ the target model, and Anthropic refuses requests whose history carries another model's reasoning as text
+ (`reasoning_extraction`), the same refusal on every retry, so a Session that switched models stays stuck. The
+ stored transcript keeps it; only the request leaves it out. An assistant message whose only content was such
+ thinking is left out of the request, as an aborted one is, never sent empty; the messages around it keep their
+ order (consecutive user-role messages are already valid on every protocol).
+- Same-origin unsigned thinking stays plain assistant text: a protocol that cannot take that reasoning back gets the
+ model's own words, attributed to the model that wrote them.
- "Opaque provider payload" means any `signature` field on any block, and any redacted thinking. Every rule here
about signatures applies to all of them. A signature is never synthesized and never sent to a different origin.
- Opaque payloads are also bound to the account that issued them, the identity of the Source that served the message
diff --git a/docs/plans/agent-core-contracts/provider.md b/docs/plans/agent-core-contracts/provider.md
index 5ed230048..ae53f12d5 100644
--- a/docs/plans/agent-core-contracts/provider.md
+++ b/docs/plans/agent-core-contracts/provider.md
@@ -90,9 +90,9 @@ for xAI's). The loop answers it by rendering the request again, never by the gen
never hands it back;
- after `opaque_refused`, with each refused (identity, kind) in `opaque_refused`, so none of that identity's payloads
of that kind is sent again: its earlier search calls take their portable form (the query and sources, readable;
- no encrypted data), and its thinking goes without signatures. The loop keeps each new pair as a `replay_refusal`
- row before resending, so the Session's later turns, and its forks, start without them (`transcript.md`). Each
- pair is answered once; refused again, the error ends the run.
+ no encrypted data), and its thinking is left out, as a different origin's (`cross-provider.md`). The loop keeps
+ each new pair as a `replay_refusal` row before resending, so the Session's later turns, and its forks, start
+ without them (`transcript.md`). Each pair is answered once; refused again, the error ends the run.
A `pause_turn` continuation's `pin_unavailable` comes after output, so it is no refusal (`conversion-tables.md`).
diff --git a/docs/plans/avibe-agent-core-evaluation.md b/docs/plans/avibe-agent-core-evaluation.md
index f793bef74..eb7697d14 100644
--- a/docs/plans/avibe-agent-core-evaluation.md
+++ b/docs/plans/avibe-agent-core-evaluation.md
@@ -68,6 +68,7 @@ Switching vendors mid-session keeps the full conversation if the transcript is v
- Every assistant message records `origin{provider, api, model}`.
- Same origin: replay thinking and its signature verbatim. Different origin: thinking becomes plain assistant text;
redacted or encrypted reasoning and Gemini thought signatures are dropped; a signature is never synthesized.
+ (C-1 later drops a different origin's thinking in every form instead; see `agent-core-contracts/cross-provider.md`.)
- Tool-call ids are normalized to the target protocol's format, with the same mapping applied to their results.
- A tool call without a result gets a synthetic error result; images become a placeholder for non-vision models.
- Responses API with `store: false`, never `previous_response_id`; compaction runs on the client and produces text.
diff --git a/tests/agent_core/ai/test_transform_sse_errors.py b/tests/agent_core/ai/test_transform_sse_errors.py
index 2310d31a2..668a91627 100644
--- a/tests/agent_core/ai/test_transform_sse_errors.py
+++ b/tests/agent_core/ai/test_transform_sse_errors.py
@@ -115,7 +115,6 @@ def test_cross_provider_transform_drops_opaque_payload_and_answers_orphaned_call
assistant = result.messages[1]
assert isinstance(assistant, AssistantMessage)
assert assistant.content == (
- TextBlock(text="private"),
ToolCallBlock(
id=result.tool_call_id_map["call|foreign"],
name="read",
@@ -162,7 +161,62 @@ def test_opaque_payloads_go_back_only_to_the_source_identity_that_served_them(se
if bound:
assert sent.content == (reasoning, redacted, call)
else:
- assert sent.content == (TextBlock("plan"), ToolCallBlock("call_1", "read", {"path": "x"}))
+ assert sent.content == (ToolCallBlock("call_1", "read", {"path": "x"}),)
+
+
+_THINKER = Origin("openai", "openai_responses", "gpt-test")
+
+
+ "target",
+ [
+ Origin("anthropic", "anthropic", "claude-test"),
+ Origin("openai", "openai_chat", "gpt-test"),
+ Origin("openai", "openai_responses", "gpt-other"),
+ _THINKER,
+ ],
+ ids=["to-anthropic", "to-chat", "to-another-model", "same-origin"],
+)
+def test_thinking_goes_back_only_to_the_origin_that_thought_it(target: Origin) -> None:
+ """cross-provider.md: thinking is a model's private reasoning, not something the assistant said. Another origin
+ gets none of it, signed, unsigned or redacted, and never as assistant text (Anthropic refuses such requests as
+ reasoning extraction); everything the assistant said or did still goes. A response whose only content was that
+ thinking is left out, not sent as an empty assistant message, while one that was empty as served (a refusal) still
+ goes. Its own origin gets it back as before."""
+
+ signed = ThinkingBlock("signed plan", '{"id": "rs_1", "encrypted_content": "enc"}')
+ redacted = ThinkingBlock("", "redacted-opaque", redacted=True)
+ call = ToolCallBlock("call_1", "read", {"path": "x"})
+ result = ToolResultMessage("call_1", "read", (TextBlock("contents"),))
+ history = (
+ UserMessage((TextBlock("go"),)),
+ AssistantMessage((signed, ThinkingBlock("unsigned plan"), redacted, TextBlock("reading"), call), _THINKER, "tool_use"),
+ result,
+ AssistantMessage((ThinkingBlock("only thought", "sig-only"), ThinkingBlock("more thought")), _THINKER, "stop"),
+ UserMessage((TextBlock("and then?"),)),
+ AssistantMessage((), _THINKER, "refusal"),
+ UserMessage((TextBlock("please"),)),
+ )
+
+ sent = transform_messages(history, target).messages
+
+ if target == _THINKER:
+ assert sent == (
+ history[0],
+ AssistantMessage(
+ (signed, TextBlock("unsigned plan"), redacted, TextBlock("reading"), call), _THINKER, "tool_use"
+ ),
+ result,
+ AssistantMessage((ThinkingBlock("only thought", "sig-only"), TextBlock("more thought")), _THINKER, "stop"),
+ *history[4:],
+ )
+ return
+ assert sent == (
+ history[0],
+ AssistantMessage((TextBlock("reading"), call), _THINKER, "tool_use"),
+ result,
+ *history[4:],
+ )
def test_cross_provider_transform_drops_results_for_failed_tool_turns() -> None: