refactor(gateway): read the /branch parent prompt inline

The try/except around the parent get_session() only added a silent path
that reproduces the bug (a child row with no system prompt). Read it inline
like the handler's other DB calls, per AGENTS.md no-defensive-wrappers.
This commit is contained in:
kshitijk4poor
2026-09-26 21:21:46 +05:30
committed by kshitij
parent e1b483a6ed
commit 15e3836f16

View File

@@ -1042,11 +1042,7 @@ class GatewaySessionCommandsMixin:
# 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.
parent_prompt = None
try:
parent_prompt = ((await self._session_db.get_session(parent_session_id)) or {}).get("system_prompt")
except Exception:
logger.debug("branch: parent system prompt read failed for %s", parent_session_id, exc_info=True)
parent = await self._session_db.get_session(parent_session_id)
try:
await self._session_db.create_session(
session_id=new_session_id,
@@ -1056,7 +1052,7 @@ class GatewaySessionCommandsMixin:
parent_session_id=parent_session_id, user_id=dest_source.user_id,
session_key=dest_key, chat_id=dest_source.chat_id, chat_type=dest_source.chat_type,
thread_id=dest_source.thread_id, origin_json=_branch_origin_json,
display_name=current_entry.display_name, system_prompt=parent_prompt or None)
display_name=current_entry.display_name, system_prompt=(parent or {}).get("system_prompt") or None)
except Exception as e:
logger.error("Failed to create branch session: %s", e)
return t("gateway.branch.create_failed", error=e)