Skip to content

fix(#700): export _REMEMBER_PHASE so a deferred child can see it - #718

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/700
Sep 17, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
fix/700

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #700.

scripts/session-start-hook.sh assigned _REMEMBER_PHASE=deferred at three deferred-fork
sites but never exported it, so no child process forked from any of those subshells could ever
observe it -- defeating the stated purpose in the comment on _remember_deferred_phase: "a
trace cannot tell a deferred child from a command substitution by pid alone."

The issue offered three honest fixes (delete, export, or log at transitions) and called picking
between them "a design call." This PR picks export, because it is literally what the
existing comment already says it wants, and is the smallest, most mechanical fix of the three.

What changed

All three sites get the identical fix in kind:

  • scripts/session-start-hook.sh:419 (before_session_start deferred dispatch subshell):
    _REMEMBER_PHASE=deferred -> export _REMEMBER_PHASE=deferred
  • scripts/session-start-hook.sh:940 (_remember_deferred_phase(), was local):
    local _REMEMBER_PHASE=deferred -> local -x _REMEMBER_PHASE=deferred
  • scripts/session-start-hook.sh:1955 (deferred start-cache-context publish subshell):
    _REMEMBER_PHASE=deferred -> export _REMEMBER_PHASE=deferred

Each site got an inline comment citing #700.

Tests

Added tests/test_remember_phase_export_700.py, an end-to-end test of site 1 (the
before_session_start dispatch) using a full plugin copy and a stub hooks.d/before_session_start/
listener that dumps whether _REMEMBER_PHASE reached its own environment. Sites 2 and 3 got the
identical mechanical fix, verified by reading rather than a separate end-to-end harness --
building recovery-fork and cache-publish fixtures was judged not worth it for a low-severity,
no-behavior-change issue.

RED (stashing the fix, rerunning):

E   AssertionError: the before_session_start listener, dispatched as a real child process from
    the deferred subshell, did not see _REMEMBER_PHASE in its own environment -- got:
    'PHASE=UNSET\n'

GREEN (unstashing, rerunning): 1 passed in 0.58s.

Narrowed regression check: tests/test_dispatch_timeout_286.py, tests/test_git_restore_hook_253.py,
tests/test_git_restore_no_resource_when_disabled_663.py, tests/test_capture_gap_notice.py,
tests/test_hook_stdout_labelling_280.py -- 74 passed. Full suite was not run locally, per
this repo's CI-is-source-of-truth policy.

Docs / changelog

No README.md change needed -- this is a purely internal tracing detail with no user-facing
mention before or after. changelog.d/700.fixed.md added, naming #700.

Review

Two concurrent reviewers (Explore, oss:auditor) spawned against the commit, both told not to
mutate the tree; both returned NO FINDINGS. One below-bar note from the auditor, not corrected
post-hoc: the new test module's own docstring says "left at its shipped default (false, per
config.example.json)" when in fact the fixture's config_into default parameter supplies the
false value, not a read of config.example.json -- a minor imprecision in the test's own prose,
not in the production fix, and it does not affect the test's correctness.

Adjacent (not filed, not fixed, out of scope for #700)

[AI-generated]

session-start-hook.sh set _REMEMBER_PHASE=deferred at three deferred-fork
sites (before_session_start dispatch, _remember_deferred_phase, the
start-cache publish) but never exported it, so the assignment stayed
inside the subshell that made it and no child process -- a hooks.d/
listener, the recovery save-session.sh fork -- could ever observe it. That
defeated the label's own stated purpose: telling a deferred child from a
command substitution by pid alone needs the child's own environment.

Adds tests/test_remember_phase_export_700.py, pinning the
before_session_start dispatch site end to end via a full plugin copy and a
stub hooks.d listener (red before the fix, green after -- confirmed by
stashing scripts/session-start-hook.sh and re-running). The other two
sites get the identical mechanical fix, verified by reading rather than a
separate end-to-end harness.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit 9a0169a into main Sep 17, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/700 branch September 17, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_REMEMBER_PHASE is write-only: nothing reads it, and it is not exported

1 participant