Skip to content

fix(#757): a repo-committed config is no longer trusted after migration; strip model/reject_pattern from a tracked project config - #765

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/757
Sep 25, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/757

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #757.

Problem

Fix

Tests (red first)

  • tests/test_migration_trust_757.py:
    • tracked legacy config: left behind, and its haiku token never reaches the merged config
    • repo root two levels above the project dir: still seen as tracked
    • broken-git shim (exit 128): fails closed
    • control: untracked config still migrates and is honoured
  • tests/test_untrusted_project_haiku_config_726.py: tracked project config has model and reject_pattern stripped. Paired controls: the same keys untracked are honoured, and so are the keys with no repo at all. The broken-git shim strips.
  • test_config_key_injection_539.py and test_jq_free_config.py are back to their original .model fixtures (untracked config), and still pass.

Full suite on macOS: 2631 passed, 59 skipped. Both changelog checks pass. shellcheck is clean.

Known limits

  • No case-insensitive fallback for .remember/Config.json: it would cost another spawn. Documented in docs/external-storage-mode.md.
  • A machine with no git binary inside a legacy project reads as could-not-tell, so its project model/reject_pattern are stripped. This fails closed and is rare for Claude Code users.

Platform

Observed: macOS. Reasoned: Linux and Windows Git Bash (same git -C conventions as the rest of the repo).

🤖 Generated with Claude Code

[AI-generated]

fdaviddpt and others added 2 commits September 25, 2026 13:33
…xternal-storage migration

In external-storage mode, the one-shot migration in bootstrap-dirs.sh moved
a project's whole legacy .remember/, config.json included, into the new
external REMEMBER_DIR -- where lib-memory-dir.sh trusts it unconditionally
from then on. A repository that committed .remember/config.json before a
clone ever switched to external storage could pick the summarizer's OAuth
credential/model, force ANTHROPIC_API_KEY to be stripped, or turn the
refusal gate off (reject_pattern: "none") or into a ReDoS surface.

A config.json that is git-tracked in the legacy dir is now left behind
during migration -- still tracked, doing nothing for the new external
store -- logged in both MIGRATED-TO.txt and hook-errors.log rather than
silently. An untracked legacy config (the user's own) still migrates and
is still trusted, as before.

Also extends the #726/#740 untrusted-project-layer strip (jq del(...) and
its Python fallback) to cover `model` and `reject_pattern`, not just
`haiku`, in the ordinary (non-migrated) legacy layout.

Two existing config-key tests picked `.model` as their incidental "some
real key reads through" example; updated to `.timezone`, which the #757
strip does not touch.

Closes #757

Co-Authored-By: Claude Sonnet 5 <[email protected]>
… git-tracked; fix migration's tracked check for subdirectories and git failures

Review of 43827e7 found two problems, both fixed here:

1. model/reject_pattern were stripped from EVERY legacy-layout per-project
   config.json, tracked or not -- #726's "untrusted by LAYOUT alone" rule is
   right for haiku (a credential), but broke every single-user project's own
   untracked model/reject_pattern override, since #726 already distrusts
   every legacy per-project config regardless of authorship. Neither key can
   redirect where transcripts go, only which model is billed or whether the
   refusal gate runs at all -- severe enough to strip from a file the
   REPOSITORY committed, not severe enough to break an ordinary untracked
   override. Now gated on _remember_config_tracked_status(): stripped only
   when the project config.json is git-tracked (or its tracked status could
   not be determined -- fail CLOSED); an untracked in-project config keeps
   both, same as before #757. haiku's own unconditional-in-legacy-layout
   strip is unchanged. Kept to one jq call and one Python argv shape either
   way -- only the filter/drop-set varies.

2. The migration's tracked check, `[ -e "$_mem_proj/.git" ]` + a same-shape
   ls-files call, missed a project started from a repo SUBDIRECTORY (#754:
   no .git in the project dir itself, even though the enclosing repo can
   have committed the file two levels up) and read ANY git failure as
   "untracked", letting the file migrate as trusted by default on a broken
   git (#760). Both call sites now share one helper,
   _remember_config_tracked_status() in lib-memory-dir.sh: `git rev-parse
   --is-inside-work-tree` walks up to any enclosing work tree (fixes #754),
   and distinguishes three states -- tracked / untracked / could-not-tell --
   rather than two. could-not-tell fails CLOSED in both callers: the
   migration leaves the file behind, the strip treats it as tracked. The
   common "no git at all" case still costs exactly one spawn (rev-parse's
   own exit status, matched against its own untranslated fatal text via
   LC_ALL=C/LANGUAGE=C rather than trusting the ambient locale); a second
   spawn (ls-files) is paid only inside a real work tree.

Spawn budget measured, not assumed: the post-tool-hook spawn count goes
18 -> 19 (one rev-parse, gated on the same "project config exists in the
untrusted layout" condition the existing haiku sanitize spawn already
pays for) -- documented and pinned in
tests/test_post_tool_hook_spawns.py rather than absorbed silently into
its existing +2 slack.

Case-insensitive-filesystem fallback (a differently-cased Config.json
escaping the tracked check) intentionally not added -- it would cost a
second git spawn on every check and was left for a follow-up rather than
paid on this path; noted in docs/external-storage-mode.md.

tests/test_config_key_injection_539.py and tests/test_jq_free_config.py
are reverted back to their original `.model`/"sonnet" fixtures (an
untracked per-project config, so model still takes effect under the
tracked-only rule) -- the #757-vs-review-round-1 key swap to `.timezone`
papered over the very regression this round fixes rather than fixing it.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit 7c6a3a9 into main Sep 25, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/757 branch September 25, 2026 12:41
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.

External storage: first-session migration makes a repo-tracked .remember/config.json haiku block trusted

1 participant