Skip to content

The agent that grows with you

fix(desktop): a committed turn renders once when the provider reuses tool-call ids (#128003)

Siddharth Balyanb5f606f16174
diff --git a/apps/desktop/src/lib/chat-messages/tool-parts.ts b/apps/desktop/src/lib/chat-messages/tool-parts.ts
index 9ff115368da..a3192f28f56 100644
--- a/apps/desktop/src/lib/chat-messages/tool-parts.ts
+++ b/apps/desktop/src/lib/chat-messages/tool-parts.ts
@@ -895,9 +895,8 @@ export function storedToolMessagePart(toolMessage: SessionMessage, fallbackIndex
}
export function withUniqueToolCallIds(messages: ChatMessage[]): ChatMessage[] {
- const seen = new Set<string>()
-
return messages.map(message => {
+ const seen = new Set<string>()
let changed = false
const parts = message.parts.map((part, index) => {
diff --git a/tui_gateway/methods_session.py b/tui_gateway/methods_session.py
index a9a73514e51..584f435f51a 100644
--- a/tui_gateway/methods_session.py
+++ b/tui_gateway/methods_session.py
@@ -243,6 +243,7 @@ def _persist_branch(db, new_key: str, parent_key: str, title: str, history: list
IGNORE first-prompt seed) — except on disk-full, where the delete cannot land. ``user_id`` is the creating
login: the child is a Desktop session too, and the row only records identity at insert."""
from agent.message_metadata import message_identity
+ from agent.transcript_repair import sync_flushed_message_markers
# The child sends the parent's exact system prompt: a row without one makes the branch's first
# turn rebuild (re-probing the workspace) and forfeits the warm cache the copied transcript buys.
@@ -262,14 +263,14 @@ def _persist_branch(db, new_key: str, parent_key: str, title: str, history: list
# path can retry cleanly on first submit.
# Copy the whole parent history in bounded-chunk transactions — a branch seed can be hundreds of
# rows, and per-row transactions were the write-amplification pattern removed in #23254.
- db.append_messages_batch(
- new_key, [{"role": msg.get("role", "user"), "content": msg.get("content"),
- **{field: msg.get(field) for field in copy_fields}, **message_identity(msg)}
- for msg in history], chunk_rows=500)
+ rows = [{"role": msg.get("role", "user"), "content": msg.get("content"),
+ **{field: msg.get(field) for field in copy_fields}, **message_identity(msg)} for msg in history]
+ db.append_messages_batch(new_key, rows, chunk_rows=500)
if title_source == "user":
db.set_session_title(new_key, title)
else:
db.set_auto_title(new_key, title, source=title_source)
+ sync_flushed_message_markers(history, rows)
except Exception as exc:
from hermes_state_errors import is_disk_full_error
if compensate and not is_disk_full_error(exc):
diff --git a/tui_gateway/session_workdir.py b/tui_gateway/session_workdir.py
index b53a9b836fb..fa44fbb6eb5 100644
--- a/tui_gateway/session_workdir.py
+++ b/tui_gateway/session_workdir.py
@@ -511,9 +511,11 @@ def _persist_branch_seed(session: dict) -> None:
if not (key := session.get("session_key")) or not session.get("seeded") or session.get("_branch_seed_persisted"):
return
from agent.message_metadata import message_identity
+ from agent.transcript_repair import sync_flushed_message_markers
with session["history_lock"]: # message_identity stamps the live dicts
+ live = list(session.get("history") or [])
seed = [{"role": msg.get("role", "user"), **{f: msg.get(f) for f in _WORKDIR_SEED_FIELDS},
- **message_identity(msg)} for msg in (session.get("history") or [])]
+ **message_identity(msg)} for msg in live]
if not seed:
return
with _session_db(session) as db:
@@ -525,6 +527,8 @@ def _persist_branch_seed(session: dict) -> None:
# Bounded-chunk transactions (see #23254): a branch seed can be hundreds of rows; chunking keeps
# each BEGIN IMMEDIATE short so concurrent writers aren't starved.
db.append_messages_batch(key, seed, chunk_rows=500)
+ with session["history_lock"]:
+ sync_flushed_message_markers(live, seed)
session["_branch_seed_persisted"] = True
except Exception as exc:
_workdir_reraise_disk_full(exc, "branch seed persist failed")