From 161fdeba7afe5d3bc71572bf70204c13645ae1a6 Mon Sep 17 00:00:00 2001 From: nesquena-hermes Date: Wed, 1 Jul 2026 07:48:34 +0000 Subject: [PATCH] fix(#5307): gate the 3rd/final import_cli_session write path (archive fallback) Codex round 4 found POST /api/session/archive's missing-sidecar fallback also calls import_cli_session(). grep confirms exactly 3 import_cli_session() call sites in routes.py; all 3 now refuse source='subagent' children: - 4792 _get_or_materialize_session (chat-start) -> PermissionError - 22382 import_cli endpoint -> read-only view payload - 13885 archive fallback -> 400 'Subagent sessions cannot be archived' So no path can materialize a delegated child as a writable WebUI sidecar. Fixes #5307 --- api/routes.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/routes.py b/api/routes.py index df669ca6..70c90e82 100644 --- a/api/routes.py +++ b/api/routes.py @@ -13856,6 +13856,13 @@ def handle_post(handler, parsed) -> bool: return bad(handler, "Session not found", 404) if cli_meta.get("read_only"): return bad(handler, "Read-only imported sessions cannot be archived from WebUI", 400) + # Delegated subagent children (#5307) are view-only and owned by the + # delegate runner — never materialize one into a writable WebUI + # sidecar via the archive fallback (the 3rd of the shared + # import_cli_session write paths). + _arch_source_tag = (cli_meta.get("source_tag") or cli_meta.get("raw_source") or "").strip().lower() + if _arch_source_tag == "subagent" or _is_subagent_child_session_id(sid): + return bad(handler, "Subagent sessions cannot be archived from WebUI", 400) if _is_messaging_session_record(cli_meta): s = Session( session_id=sid,