fix: fix: vault_request RETURN trap fires prematurely when vault-env.sh is sourced (#773) #904
No reviewers
Labels
No labels
action
backlog
blocked
bug-report
cannot-reproduce
in-progress
in-triage
needs-triage
prediction/actioned
prediction/dismissed
prediction/unreviewed
priority
rejected
reproduced
tech-debt
underspecified
vision
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: disinto-admin/disinto#904
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/issue-773"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #773
Changes
AI Review
Analysis
The PR correctly identifies the root cause: the RETURN trap set before
source "$vault_env"fires prematurely when the source triggers a return in the enclosing function. The two explicitrm -f "$tmp_toml"calls added for the early-exit paths (file-not-found and source-failure, lines 138–149) are correct.Blocker
critical
lib/action-vault.sh:155: The replacement trap leaks$tmp_tomlon every path except the low-tier branch.tmp_tomlis alocalvariable (declared at line 129). EXIT fires when the shell exits — long aftervault_request()has returned and its locals are gone. At EXIT time$tmp_tomlexpands to empty string, sorm -f ""is a no-op. The temp file is never removed.Paths where
$tmp_tomlis now leaked (none of these have an explicitrm -fand all reach the EXIT-trap zone):return 1)return 1)return 1)return 1)return 1)return 0)The low-tier path (line 183–187) is OK because it sets a RETURN trap after the source call; RETURN fires while locals are still in scope.
Required fix
Two equivalent options:
Option A — move the RETURN trap to after the source call (same semantics as before, no premature firing):
Option B — expand
$tmp_tomlat trap-set time using double quotes (EXIT remains valid):Either approach also removes the need for explicit
rm -fon the early-error paths (lines 138 and 149), though keeping them is harmless.Verdict
REQUEST_CHANGES — EXIT trap with single-quoted local variable leaks temp files on all non-early-return paths
Reviewed at
24d6441| AGENTS.mdAI Review: REQUEST_CHANGES — EXIT trap with single-quoted local variable leaks temp files on all non-early-return paths
24d6441e14tof1f60e555cAI Re-review (round 2)
Previous Findings
New Issue Introduced by Fix
critical
lib/action-vault.sh:138,147: Both early-exitreturn 1paths now leak$tmp_toml.The RETURN trap at line 153 is only active for returns that happen after it is registered. The two pre-source early-exit paths execute before the trap is set:
vault_envfile not found →return 1(no trap installed, norm -f)source "$vault_env"fails →return 1(no trap installed, norm -f)The previous review's Option A description said the explicit
rm -fcalls on those paths were no longer needed — that was incorrect. The RETURN trap covers only returns occurring aftertrap ... RETURNexecutes; it does not retroactively cover earlier returns. Removing both explicitrm -fcalls while leaving the trap after those code paths creates exactly the leak the fix was meant to prevent, just on different paths.Required fix: restore the explicit
rm -f "$tmp_toml"before each pre-trapreturn 1:The RETURN trap at line 153 then correctly covers all remaining return paths (validation failure, SHA lookup failure, branch creation failure, file upload failure, PR creation failure, success).
Verdict
REQUEST_CHANGES — early-exit paths at lines 138 and 147 leak $tmp_toml — RETURN trap is set after them, and explicit rms were removed
Reviewed at
f1f60e5| Previous:24d6441| AGENTS.mdAI Re-review (round 2): REQUEST_CHANGES — early-exit paths at lines 138 and 147 leak $tmp_toml — RETURN trap is set after them, and explicit rms were removed
f1f60e555cto96870d9f30AI Re-review (round 3)
Previous Findings\n- Early-exit paths at lines 138 and 147 leak
$tmp_toml(RETURN trap set after them, explicit rms removed) → FIXED:rm -f "$tmp_toml"added before each pre-trapreturn 1(file-not-found at :138, source-failure at :148). RETURN trap at line 155 now correctly covers all post-source return paths.\n\n### New Issues\n\nNone.Verdict
APPROVE — Both early-exit paths now have explicit rm -f before return 1; RETURN trap at line 155 covers all remaining paths.
Reviewed at
96870d9| Previous:f1f60e5| AGENTS.mdAI Re-review (round 3): APPROVE — Both early-exit paths now have explicit rm -f before return 1; RETURN trap at line 155 covers all remaining paths.