From 30decee2220d4366f4f87310ac3a1a6cdd3e66a7 Mon Sep 17 00:00:00 2001 From: paulbettner Date: Thu, 26 Feb 2026 21:01:48 -0500 Subject: [PATCH] fix(plan): restore pre-plan permission mode reliably (#1170) --- src/cli/App.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/cli/App.tsx b/src/cli/App.tsx index 7f35a15..f5f9aaa 100644 --- a/src/cli/App.tsx +++ b/src/cli/App.tsx @@ -1087,6 +1087,21 @@ export default function App({ const setUiPermissionMode = useCallback((mode: PermissionMode) => { uiPermissionModeRef.current = mode; _setUiPermissionMode(mode); + + // Keep the permissionMode singleton in sync *immediately*. + // + // We also have a useEffect sync (below) as a safety net, but relying on it + // introduces a render/effect window where the UI can show YOLO while the + // singleton still reports an older mode. That window is enough to break + // plan-mode restoration (plan remembers the singleton's mode-at-entry). + if (permissionMode.getMode() !== mode) { + // If entering plan mode via UI state, ensure a plan file path is set. + if (mode === "plan" && !permissionMode.getPlanFilePath()) { + const planPath = generatePlanFilePath(); + permissionMode.setPlanFilePath(planPath); + } + permissionMode.setMode(mode); + } }, []); const statusLineTriggerVersionRef = useRef(0);