Skip to content

fix(#750,#751,#776): refuse tracked handoff targets; widen Codex child-env allowlist; route subdirectory-project handoffs correctly - #789

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/750-751-776
Sep 26, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/750-751-776

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

What each fix does

Closes #750, Closes #751, Closes #776

TDD evidence (red then green, separately, for each issue)

#750 (tests/test_write_handoff_tracked_target_750.py, 2 tests): red (fix reverted via git stash) -- 1 failed, 1 passed (script exited 0 and overwrote the tracked file); green -- 2 passed.

#751 (additions to tests/test_summarizer_sandbox_724.py, 4 new tests): red -- 3 failed, 9 passed (three new positive-assertion tests failed, env.get(...) was None); green -- 12 passed.

#776 (tests/test_write_handoff_subdirectory_project_776.py, 2 tests): red -- 1 failed, 1 passed (note landed at the enclosing repo's store, not the subdirectory project's); green -- 2 passed.

Combined targeted run after all fixes restored: 53 passed.

Adjacent finding, fixed in this commit

Moving _WH_SESSION_ID's computation earlier in scripts/write-handoff.sh (for #776) shifted the line number of a pre-existing case pattern that tests/test_locale_ranges_695.py's allowlist exempts by file+line-number, going stale. Fixed by updating the allowlist entry to its new line in this same commit.

Self-review: three below-bar findings (non-blocking, fails-to-preserve)

Two reviewers (Explore, oss:auditor) were spawned against the committed diff. All three findings below are judged below the intake bar -- narrow, reachable only in edge-case compositions, and never regressing behavior below what shipped before this commit.

  1. Composite subdirectory-project + deeper mid-call cd is not disambiguated. The write-handoff.sh's git-root fallback (#743) conflicts with subdirectory-project support (#754), sending handoffs to the wrong store #776 fix only trials exactly two candidates ($PWD and the git toplevel). If a project is genuinely rooted at repo/pkg but the model then cds deeper still (e.g. repo/pkg/deeper) before running /remember, neither trial's store carries the session hint, and the code falls through to the pre-write-handoff.sh's git-root fallback (#743) conflicts with subdirectory-project support (#754), sending handoffs to the wrong store #776 default (git toplevel) -- misrouting the note one directory level deeper than write-handoff.sh's git-root fallback (#743) conflicts with subdirectory-project support (#754), sending handoffs to the wrong store #776 itself. Not a regression: pre-write-handoff.sh's git-root fallback (#743) conflicts with subdirectory-project support (#754), sending handoffs to the wrong store #776, this exact composite scenario already always went to the git toplevel, identically. Reasoned, not executed. A full fix would generalize the two-candidate trial into an ancestor walk from $PWD up to the git toplevel, meaningfully widening this diff's scope for a non-blocking gap.

  2. Trial-resolution failure is indistinguishable from "no hint" in the write-handoff.sh's git-root fallback (#743) conflicts with subdirectory-project support (#754), sending handoffs to the wrong store #776 disambiguation. _wh_trial_remember_dir exits nonzero and prints nothing both when a candidate's store genuinely lacks the session hint AND when the resolve-paths.sh/lib-memory-dir.sh chain itself fails for that candidate. The caller only tests for a non-empty result, so a transient failure on the $PWD trial silently reproduces the write-handoff.sh's git-root fallback (#743) conflicts with subdirectory-project support (#754), sending handoffs to the wrong store #776 bug with a success message, never a refusal. Reasoned via code reading. At worst reproduces the pre-fix behavior, never something worse; a real fix needs three-state signalling (present / absent / could-not-tell), which is non-blocking here.

  3. Incidental log-line side effect via resolve-paths.sh's failure path. _resolve_paths_fail can append a line to a .remember/logs/memory-*.log file when the log directory exists, reachable in principle from inside a trial subshell. The auditor could not construct a scenario where this actually fires, since both trial candidates are always real, existing directories. Effectively a non-finding, included for completeness.

Docs

README.md checked (grepped for write-handoff, codex, subdirectory): no-change-needed -- none of these three fixes changes documented, user-facing behavior described there.

[AI-generated]

…d-env allowlist; route subdirectory-project handoffs correctly

#750: write-handoff.sh now refuses to overwrite a target the repository's
own git index tracks, mirroring the read-side injection guard (#721) so a
tracked remember.md is never silently overwritten and reported as success.

#751: the nested Codex summarizer's child-env allow-list is widened to
include Windows process variables (SYSTEMROOT/USERPROFILE/APPDATA/PATHEXT)
and, on every platform, CODEX_API_KEY and the standard proxy/CA variables.

#776: write-handoff.sh disambiguates a repository-subdirectory project from
a stale-cwd `cd` using this session's own published handoff hint (#738), so
a project deliberately started from a repo subdirectory is routed to its
own store instead of the enclosing repository's root.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt

Copy link
Copy Markdown
Contributor Author

Review: this PR is currently red on pytest (windows-latest, 3.10) and pytest (windows-latest, 3.12), both on the same new assertion in tests/test_summarizer_sandbox_724.py (test_codex_child_env_keeps_proxy_and_ca_vars):

>       assert env.get("https_proxy") == "http://proxy.example:8080"
E       AssertionError: assert None == 'http://proxy.example:8080'

Root cause (reasoned from the diff, not just the log): _CODEX_CHILD_ENV_ALLOW in pipeline/haiku.py lists both cases of the proxy names (HTTPS_PROXY/https_proxy, etc.), and _codex_child_env()'s dict comprehension only keeps a name that is also a key in os.environ. On Windows, os.environ folds environment-variable names to a single case internally, so setting HTTPS_PROXY and then https_proxy in the test (or in a real Windows process) never produces two distinct keys -- only one survives in os.environ.items(), so whichever-case entry is not that one never matches the allow-list and is silently dropped. This is not flaky CI: it reproduces the same way on 3.10 and 3.12, and it is exactly the "must handle both cases of the proxy names" claim the PR adds a test for, on the one platform where that claim needs a different implementation (case-insensitive lookup, e.g. building a case-folded index of os.environ before filtering) rather than two literal allow-list entries.

Decision: needs-fix, not merged. The three below-bar self-review findings already in the PR body (composite subdirectory-project routing, trial-resolution failure signalling, incidental log-line side effect) are read and their reasoning holds -- no disagreement with any of those three.

…g a Windows-only CI failure

PR #789's own CI went red on windows-latest only: a new #751 test asserted
`env.get("https_proxy")` after also setting `HTTPS_PROXY` in the same run.
CPython's os.py folds every os.environ key to uppercase on `nt`, at
process-startup time (`_createenviron`'s encodekey = str.upper, applied
while building the initial dict from the inherited environment) -- so the
two setenv calls collapsed to one real variable there, and the plain,
case-sensitive dict `_codex_child_env()` returns never carried a literal
"https_proxy" key to begin with. Production was never broken: the
already-listed uppercase allow-list entry passed the value through
correctly regardless of which case a real Windows host set it under. Only
the test's assumption -- that a specific key casing survives a platform
that does not preserve it -- was wrong.

Fixed by:
 - matching the codex child-env allow-list case-insensitively against the
   real os.environ (pipeline/haiku.py), removing the need to enumerate
   both cases of the proxy names as separate allow-list entries
 - splitting the proxy/CA test into one that sets uppercase-only names and
   one that sets lowercase-only names, never both together, checked via a
   case-insensitive helper against the output -- and a new test that
   simulates a real Windows-folded os.environ directly, so the shape of
   the bug is pinned even without a Windows runner

Verified: reverting only the matching-logic change reproduces the failure
locally (1 failed) without needing Windows; restoring it is green. Full
targeted suite (test_summarizer_sandbox_724, test_write_handoff_*,
test_handoff_per_session_pointer_738, test_injection_guard_754_755_756,
test_locale_ranges_695, test_windows_skip_triage_497): 55 passed.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit 8bd5b7e into main Sep 26, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/750-751-776 branch September 26, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment