From 82302e47f995bca822c56ca1ecb60b47104c1c8c Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Wed, 12 Aug 2026 21:19:25 -0700 Subject: [PATCH] fix(terminal): preserve user-enabled functrace traps --- config/reliability-gates.jsonc | 4 ++-- src/main/bash-startup-exec-preservation.ts | 3 ++- src/main/providers/local-pty-shell-ready.test.ts | 12 +++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/config/reliability-gates.jsonc b/config/reliability-gates.jsonc index 6256ad20451..d1bbc9308ab 100644 --- a/config/reliability-gates.jsonc +++ b/config/reliability-gates.jsonc @@ -200,7 +200,7 @@ "command": "pnpm exec vitest run --config config/vitest.config.ts src/main/daemon/repro-13767-shell-ready-marker-lost-to-exec.test.ts src/main/providers/local-pty-shell-ready.test.ts src/relay/pty-shell-launch.test.ts", "result": "passed", "durationSeconds": 4.65, - "summary": "All 107 focused local, daemon, and relay assertions passed, including real zsh/bash exec restoration, command modifiers, ZDOTDIR expansion ordering, and DEBUG trap invocation preservation." + "summary": "All 107 focused local, daemon, and relay assertions passed, including real zsh/bash exec restoration, command modifiers, ZDOTDIR expansion ordering, and DEBUG trap invocation preservation when the user enables functrace during startup." } ], "runtimeBudget": { @@ -213,7 +213,7 @@ }, "redGreenEvidence": { "status": "complete", - "evidence": "PR head 05c0ac91dd1 failed the exact exec \"$ZDOTDIR/zsh-replacement\" oracle with status 127 after expanding the target inside Orca's wrapper directory. The just-in-time shim candidate passed that oracle plus all 107 focused assertions; the existing #13767 red/green evidence independently proves the original replacement-shell readiness failure." + "evidence": "PR head 05c0ac91dd1 failed the exact exec \"$ZDOTDIR/zsh-replacement\" oracle with status 127 after expanding the target inside Orca's wrapper directory. The just-in-time shim candidate passed that oracle plus all 107 focused assertions. The pre-fix Bash guard reported USER_DEBUG_NESTED=0 after a profile enabled functrace; the reviewed guard reports USER_DEBUG_NESTED=1 while keeping the ordinary non-functrace trap unmultiplied. The existing #13767 red/green evidence independently proves the original replacement-shell readiness failure." }, "performanceBudget": { "required": true, diff --git a/src/main/bash-startup-exec-preservation.ts b/src/main/bash-startup-exec-preservation.ts index 7d6206ffaab..8876189d266 100644 --- a/src/main/bash-startup-exec-preservation.ts +++ b/src/main/bash-startup-exec-preservation.ts @@ -156,7 +156,8 @@ _orca_exec_command_check_body="$(declare -f __orca_startup_command_is_exec)" __orca_preserve_startup_exec() { local _orca_exec_command="$BASH_COMMAND" if [[ -n "\${_orca_exec_startup_chained_debug_trap:-}" ]] && - { [[ "\${_orca_exec_functrace_was_set:-0}" == "1" ]] || (( \${#FUNCNAME[@]} <= 1 )); }; then + { [[ "\${_orca_exec_functrace_was_set:-0}" == "1" || + "\${_orca_exec_user_enabled_functrace:-0}" == "1" ]] || (( \${#FUNCNAME[@]} <= 1 )); }; then eval "$_orca_exec_startup_chained_debug_trap" || true fi case "$_orca_exec_command" in diff --git a/src/main/providers/local-pty-shell-ready.test.ts b/src/main/providers/local-pty-shell-ready.test.ts index 369f42410ef..2fb3fa92cb2 100644 --- a/src/main/providers/local-pty-shell-ready.test.ts +++ b/src/main/providers/local-pty-shell-ready.test.ts @@ -641,17 +641,23 @@ describePosix('local PTY shell-ready launch config', () => { expect(output).toContain('CHILD_TEMP_PC=unset') }) - itWithBash('preserves functrace enabled by a user profile', async () => { + itWithBash('preserves user-enabled functrace and nested DEBUG trap behavior', async () => { const { getBashShellReadyRcfileContent } = await importFreshLocalPtyShellReady() - writeFileSync(join(userDataPath, '.bash_profile'), 'set -T\n') + writeFileSync( + join(userDataPath, '.bash_profile'), + 'set -T\nprofile_nested() { :; }\nprofile_nested\nprintf "USER_DEBUG_NESTED=%s\\n" "${USER_DEBUG_NESTED:-0}"\n' + ) + const wrapper = `trap '[[ " \${FUNCNAME[*]} " != *" profile_nested "* ]] || USER_DEBUG_NESTED=1' DEBUG +${getBashShellReadyRcfileContent()}` const output = runInteractiveBashRcfile( - getBashShellReadyRcfileContent(), + wrapper, userDataPath, "shopt -qo functrace && printf 'USER_FUNCTRACE_ON\\n'\nexit 0\n" ) expect(output).toContain('USER_FUNCTRACE_ON') + expect(output).toContain('USER_DEBUG_NESTED=1') }) itWithBash('does not multiply a pre-existing DEBUG trap inside startup functions', async () => {