From 15e3836f16262a78bfa3a2116da2fc1a4e9ded07 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 26 Sep 2026 21:21:46 +0530 Subject: [PATCH] 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. --- gateway/slash_commands_session.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/gateway/slash_commands_session.py b/gateway/slash_commands_session.py index 17dbcda6b4..e64d9dd118 100644 --- a/gateway/slash_commands_session.py +++ b/gateway/slash_commands_session.py @@ -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)