Skip to content

Key project memory by repository identity, not folder name - #1724

Open
michael-wojcik wants to merge 377 commits into
mainfrom
issue-1677-repository-identity-memory
Open

michael-wojcik wants to merge 377 commits into
mainfrom
issue-1677-repository-identity-memory

Conversation

@michael-wojcik

@michael-wojcik michael-wojcik commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

What this changes

pact-memory used to file a project's memories under the folder name the repository was cloned into. That split one repository across machines when the folder was named differently, and merged unrelated repositories that shared a name. It now files them under the repository itself.

  • The id is host/owner/repo from the origin remote. ssh, scp and https spellings of one remote give one id. The host is lower-cased; the login, a trailing .git and a scheme's default port are dropped; any other port is kept.
  • A pin at <git-common-dir>/pact-project-id, shared by every worktree, outranks the remote. An in-tree .pact/project-id is ignored, because a clone can plant one.
  • Resolution order: supplied > repository pin > CLAUDE_PROJECT_DIR > session record > worktree-identity fallback > git root > decline > user-scope setting > cwd.
  • Refusals instead of guesses. A remote whose host is in the reserved .invalid namespace declines; a bracketed IPv6 host is accepted and an IPv4-mapped one declines; an empty port means the default port. A remote that cannot be represented, a .git git cannot answer for, a .git pointing into another repository, or a submodule with no usable remote refuses with the cause and the fix. project-id show and status carry it as decline_reason.
  • Old memories. Reads also cover this checkout's old folder-name bucket when there is evidence it belongs here (file rows under this repository or its linked worktrees, or sessions recorded here) and none that it belongs to another checkout. In a long-lived store most pre-upgrade buckets have no placing file row and no session still on disk or in the new ledger (sessions older than the 30-day cleanup left no ledger line), so they are reported unproven and are not read until the user approves a project-id rekey. project-id rekey --from <id> [--to <id>] [--apply] moves a bucket in one transaction; a dry run is the default.
  • Reads leave an existing store's schema alone. list, search, search_by_file, sync, get_status and id lookups no longer create, migrate or switch the journal mode of an existing store. The first read of an absent store creates its schema and answers empty.
  • Session evidence. hooks/session_end.py keeps a size-capped ledger of reaped session folders, so the evidence for an old bucket outlives the folder.
  • Exit codes. Every store fault, failed setup and internal error on any verb now exits 3 (it was 2). 2 is bad input only.

Where this departs from the plan

  • github.com paths are lower-cased. The plan said path case is preserved. GitHub treats owner and repository names case-insensitively, so folding there cannot merge two repositories and prevents a split. Every other host, GitHub Enterprise included, keeps path case.
  • Unproven buckets are not read. An old bucket with no evidence either way is reported as unproven with a runnable rekey command, not read.
  • The id grammar is wider. Percent-encoded and non-ASCII path segments are kept as uppercase %XX, and the Azure DevOps spellings of one repository share one id.
  • The pin must be a canonical id. A folder-name value in the pin is ignored and reported as override_ignored.
  • A live declaration that declines ends resolution rather than falling through to a folder name.
  • Exit 3 is reused for every operational fault on every verb, as above.
  • One ownership rule for old buckets. For a repository-identity session, one decision drives every read, defaulted rekey, warning and refusal. Foreign evidence is an existing row inside another checkout that could have written the bucket and is not a clone of this repository (its name before this change, or its folder-name id, is the bucket's, or the name is unknown; a checkout whose .git is a directory and whose usable pin is this repository's id or, with no usable pin, whose config's first origin url is this repository's url exactly as written, in a config with no include, no dotted section header and no empty origin url anywhere, is the same owner; an ssh/https or .git spelling difference stays a rival), an existing row under another project folder of the bucket's name (a directory marked by .git, .claude or a recorded session), or sessions recorded at another existing folder. Rows in no checkout and no marked project folder, and vanished, unreadable or relative rows, count for nothing either way. A session reads a bucket only with evidence it is its own and none that it is someone else's; a bucket with only foreign evidence is excluded and gets no rekey command. A rekey with no --to is accepted only for a bucket whose rows are placed here.

Accepted residuals

  1. A delivered .git directory chooses its id. An archive or vendored copy that ships a .git/config origin or a .git/pact-project-id binds whatever canonical id it names, and so reads and writes that bucket. Trusting a checkout's .git is the trust git itself already asks for. The status and show census lists every bucket id and count (no memory content) to any checkout, which such a checkout could already reach.
  2. A .git file naming an external git directory (a bare clone or a --separate-git-dir store) binds that repository's id, because refusing it would break the legitimate separate-git-dir setup. It adds reach beyond residual 1 only for a victim whose id is unguessable and whose separate git dir path is known.
  3. A checkout whose own path sits under a .git/modules directory declines rather than binding.
  4. Projects with no portable remote are not judged. A repository with no portable origin or with a remote-helper transport origin (codecommit, sso, keybase, persistent-https, or any <helper>::<address>; project-id show reports source remote helper and names the pin remedy), a non-git project folder, the home-directory landing and a user-scope project_id setting keep their folder-name (or configured) id and read and save that bucket as before this change, so it is shared with any same-name folder. That includes a repository with an origin whose pre-upgrade folder-name bucket has not yet been moved with project-id rekey: any same-name folder-name session can still read and write that bucket. A project that wants its own bucket sets an origin remote or writes a canonical id to <git-common-dir>/pact-project-id. An ssh host alias stays in the id (git@gh_work:o/r gives gh_work/o/r), so only clones whose origin uses that same alias share its bucket, usually those on machines whose ssh config defines it; a pin holding the canonical id joins an alias clone to the others.
  5. A vanished folder, or a bucket with only relative rows, is no evidence either way. A relative-only bucket stays shared by every folder of that name, as before this change. A session from a removed linked worktree counts as unattributed, and a row whose path no longer exists counts for nothing. So a bucket whose only evidence is such a session drops out of reads until a rekey; and once another repository's checkout is deleted, its rows stop keeping a bucket out of a repository session's reads.
  6. The first read of an absent store in the default location creates it with its schema; otherwise reads leave an existing store's schema, migrations and journal mode alone.

Measured

  • Combined gate on the final tree: lint green on both Ruff legs (ruff 0.17.3); 302 test modules that change or import a changed module: 22,895 passed, 16 skipped, 0 failed, 0 errors, rc 0.
  • The ownership rule's cases (the original 22 plus the amendment's rows for home and user-setting sessions, project-folder markers, a planted repository inside a linked worktree, and elsewhere-only buckets) run through list, project-id show, the defaulted rekey and save against real git checkouts; each was shown to fail under a targeted mutation.
  • Every other new test was shown to fail under a mutant of the code it pins; the ASCII-digit sweep's 38 cases give 14 failures against the unfixed code, one per fixed site.
  • The two whole-tree census modules were the bulk of a fast-suite slowdown (18.7 min vs 12-13 min on recent main-based PRs). Walking each tree once cut their paired local wall time from 118s to 89s (-25%).
  • The legacy-bucket session check cost about 0.5 s per command on the largest real sessions folder here (3,665 folders); it now takes about 75-80 ms.

Reviewer notes

  • Version 4.8.38 in all five release files with a CHANGELOG section; main is 4.8.37.
  • Moving the rest of identity resolution out of memory_api.py into project_identity.py is tracked in Move identity resolution out of memory_api into project_identity #1732.
  • database.py no longer imports project_identity; an AST test pins that boundary and project_identity not importing memory_api.

Refs #1677

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

The read-scope cache is keyed on the store's stamp, taken before the read,
and that stamp includes the `-wal` journal. A read-only open of a store with
no journal creates an empty one, so the key changed across the very read it
keyed: the second read in every process missed and decided the scope again,
re-running the bucket census and listing the session folder a second time.

An empty journal now stamps the same as an absent one. It holds no frames, so
in both states the rows are the main file's alone, and the main file's stamp
is already in the key. Measured across separate processes (SQLite 3.45.1):
a read-only open of a store with no journal leaves an empty one, and later
read-only opens leave it byte- and mtime-identical; a dead writer's journal
is left as it is. A TRUNCATE checkpoint after a full backfill empties the
journal without moving the main file's stamp, but the backfill already moved
it, and the emptied journal moves the key, so the next read misses.

The key is still taken before the read, so a write landing during a read is
never filed under a stamp that includes it. The stamp's limit, a main-file
write that keeps its (mtime_ns, size), is unchanged and is now stated in
`_store_stat_key`.

Three arms beside the WAL-only arm: repeated reads decide the scope once; a
read after a truncating checkpoint decides again and returns the backfilled
rows; a commit landing after the read counted the buckets is seen by the next
read.
The test class for the session-evidence check is named for listing each
root's session folder once, but no arm counted a listing: a change that
checked each session on its own instead of listing the folder passed it.

A new arm spies on the folder listing across three instances with three
reads each in one process and requires exactly one listing of the root's
session folder. It fails with two listings on the code before the
read-scope cache fix, and with none when the listing is replaced by a
per-session check.
The read-scope cache arm for a TRUNCATE checkpoint asserted, as a
precondition, that the checkpoint left the main file's (mtime_ns, size)
unchanged. On a CI Linux runner the checkpoint moved the main file's
mtime by 3 ms with its size unchanged, so the arm failed before reaching
its subject. The claim in c280f0b's message, that a TRUNCATE checkpoint
after a full backfill empties the journal "without moving the main file's
stamp", holds on some runners and not others: whether the main file's
mtime moves is SQLite's and the filesystem's choice.

The arm's subject is the -wal leg of the key, so it now holds the main
leg constant: after the truncate it checks the main file's size did not
change and restores its mtime to the pre-truncate value. The checkpoint
and the stat key the code reads stay real; only the main leg is pinned,
and the arm's docstring says so. Dropping the -wal leg from the key
still reds the arm, and a forced main-mtime bump after the checkpoint,
which reproduces the CI failure on the old arm, leaves the new one
green.

The repeated-reads arm relied on the first read's read-only connection
creating an empty -wal (measured with SQLite 3.45.1). It now creates the
empty -wal itself when SQLite did not, so it crosses the absent-to-empty
transition on any SQLite; stamping an empty -wal apart from an absent one
still reds it.
The census of inputs that select a resolver route recognised only
os.environ.get, os.getenv and a subscript with a constant key. A new
variable read through `"X" in os.environ`, os.environ.setdefault,
dict(os.environ).get or an os.environ.items() scan left it green, and a
read inside a helper module the detection path calls (config.py reads
PACT_TEST_MEMORY_DIR) was never seen.

The census now follows the detection path into every function it calls in
the plugin's own modules, re-exports included, and classifies every use of
the environment there. A lookup, subscript or `in` test whose variable is a
constant, a module constant or a parameter resolved at its call sites names
that variable; any other use (a copy, an iteration, the mapping passed on)
becomes a condition no route drives, so the census reds until a route
drives it or NOT_A_ROUTE names it with a reason. A call into a helper counts
as driven when a route replaces it or sets an input read inside it. The
inputs this reaches today, the session id and test-process guard read by the
session-record readers, the user-scope setting's directory, and the git
subprocess environment copy, are named with their reasons.

GIT_DISCOVERY_ACROSS_FILESYSTEM stays excluded with a corrected reason. It
selects the cwd-marker rung exactly as the driven GIT_CEILING_DIRECTORIES
does: both marker walks stop at a parent on another filesystem as they stop
at a ceiling entry there, and walk on when the variable is true, measured by
faking a device boundary at each cwd-marker route's ceiling for every
fixture shape. A real filesystem boundary cannot be built in a test, so the
cwd-marker routes measure that rung.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

… absent

The read-scope cache stamped an empty `-wal` the same as an absent one, so
that the empty journal a read-only open creates would not move the key
across the read it keyed. That merged two states the key used to tell
apart. A writer's last close checkpoints its commit and deletes the
journal, so when the main file's mtime and size come out unchanged (a
write inside one timestamp tick that kept the size), the journal going
from empty to absent was the only change signal, and the next read served
the scope decided without the new row.

The `-wal` leg is now its mtime and size whenever the file exists. When it
is absent, the key first opens and closes a read-only connection so SQLite
creates it, then stamps, so the read that follows finds it already there
and leaves the key unchanged. The missing-store check still runs first and
the probe is read-only, so it never creates a store; where SQLite cannot
create the journal the read cannot either, and the leg stays empty.

A test commits and closes a writer while holding the main file's stamp: it
reads the new row now and was served from the cache before. Skipping the
probe fails the repeated-reads test, the same-tick test and the
session-folder listing test; dropping the `-wal` leg fails the truncate,
WAL-only, same-tick and write-during-read tests.
The evidence rule admits a session only when the repository's
description was created strictly before the session's started_at.
seed_session_evidence defaulted started_at to datetime.now(), and two
ledger lines did the same, so every positive-evidence arm passed only
because the filesystem clock did not lead the process clock by more
than the gap between git init and the seed. Measured in the suite, that
gap is 3.7 ms to 264 ms. With a simulated filesystem clock leading by
5 ms nothing fails; by 50 ms, 14 tests in the eight modules that seed
sessions fail with no defect in the code; by 300 ms, 27 fail.

The fixture gains start_after_description(project_dir): the
description's own ctime plus 1 ms, read through the git common dir, so
a linked worktree dates against the shared description. It is the
seed's default and replaces the wall-clock start of the two ledger
lines (test_remediation_identity_resolver.py, whose datetime_now_iso
helper is removed, and test_remediation_session_evidence_listing.py).
The comparison no longer involves the wall clock: all eight modules
pass at leads of 5 ms, 50 ms, 300 ms and one hour. A project with no
description keeps the wall-clock start; three negative arms reach that
path and none depends on ordering. Explicit started_at values are
unchanged: ignoring them fails the five arms they carry.

The margin is 1 ms. A zero margin fails 17 tests, because the start is
written to the microsecond. A 1 s margin made a seed followed by a
re-clone date after the new description too, so both re-clone arms read
evidence that is not there.
When git cannot see the checkout from the working directory (a
GIT_CEILING_DIRECTORIES entry above it, or a mount inside the checkout),
the resolver reaches the cwd-marker walk. The user-scope `project_id` was
read before that walk, so on these routes a user setting bound the user's
chosen id even inside a repository with a canonical pin, and an unusable
pin was never reported. The memory skill says a repository pin always
outranks the setting.

The cwd-marker walk now asks first: a repository it finds binds its pin or
its origin, or declines, exactly as on the git-root rung, and the user
setting is read only where the walk finds no repository. The home-directory
landing keeps its place before that question, so on this route a home that
is itself a repository still binds the user setting when one is set; the
skill and the resolver docstrings now say so. Nothing else changes order.

A forced route drives the user setting over a cwd marker in the shared
route matrix, so the parity test and the skill's override matrices measure
it. A new arm plants a canonical pin in every own layout and requires every
route to bind it; on the old order the user-setting route bound the user's
id on every layout, and the parity arm, which now names the route that
answers differently, flagged 19 shapes.

The route-input census no longer excludes get_user_memory_dir, which the
new route now drives; either change alone fails that census, so both land
here.
The constructor's git-call table counts detection with no override pin,
and said nothing about that assumption. A canonical pin answers before the
origin is read, so a pinned checkout, linked worktree, separate-git-dir
checkout and linked worktree of a submodule each run one call fewer, and a
submodule or a submodule of a superproject worktree runs two fewer (all
measured on every real route). A checkout made with
`git init --separate-git-dir=<dir>/.git` declines without a pin and binds
only through one, so the table had no row for it.

The docstring now says the table assumes no pin and states a second,
pinned table for every own layout plus that dot-git store checkout (3, 3
and 4 calls). A test measures the pinned table on every own layout and
real route, checks every pinned layout binds its pin and that the dot-git
store checkout declines without one, and reads the expected counts from
the docstring, so a changed count or a dropped assumption fails it.

Three of the layout-completeness exclusions understated who reaches them:
the predicate for a `.git` naming a directory called `.git` is also
reached by the user's own dot-git store checkout, and the submodule
admin-dir check is also true for an unset core.worktree, the state
`git submodule deinit` leaves, and the foreign-redirect check is reached
the same way. Their reasons now say so.
The rung-parity module derives five sets from the code and requires the
route matrix to cover each: the guard's decline reasons, the identity
layer's marker predicates, the rung call sites, the identity callers, and
the layout predicates. Each scanner counted only the shapes it recognised
and skipped the rest, so an unrecognised form passed silently. A guard arm
declining with a reason held in a variable, and a never-true predicate
called through a variable, both passed the current arms; measured.

Each scanner now also lists every form it cannot read, and its arm
asserts that list is empty before checking coverage:
- the guard census: a `_decline` reason that is not a string literal, a
  `_decline` used as a value, and a return that is neither None nor a
  `_decline` call;
- the marker-predicate census: any read of the asked root other than a
  direct argument of a named project_identity function, a None test, or a
  NOT_A_PREDICATE call (`Path`, with its reason, checked for staleness);
- the rung call-site census: a rung referenced other than as a call;
- the identity-caller census: an identity function referenced other than
  as a call target or a plain assignment's value;
- the layout-predicate walk: a reached function with no return
  annotation, or a project_identity function used as a value.

Twelve mutants, one per form, each fail their arm at the new assertion;
the variable-reason and variable-call mutants pass the arms as they were.
Five source scanners in this change claim a whole axis (every git call,
every decline dict, every identity construction, every route input,
every printed command), and each passed a form a normal author could
write: a subprocess runner held in a variable or a dict, os.system, git
named by its path, a subscript store inside a tuple target, a key held
in a class attribute, OrderedDict(reason=...), the identity class passed
to map or chosen by a conditional expression, a helper called through a
dotted module path or passed as a value, and a "pact-memory <verb>"
command assembled from an f-string or a +.

Each scanner now reads the form or returns it: the reason-dict census
reads a class-attribute key and reports every other reason key it cannot
classify; the construction census reports the class used as a value; the
git guard counts os and asyncio runners, reads git by its path and
reports a runner used as a value; the route census follows dotted calls
and counts a function used as a value as a call; the executable scan
flags a string piece whose verb comes from another piece. Each arm
asserts the reported list is empty, and each new helper has a fixture
control marking every line read or unread.

The route census keys the process and home directories as one input
each, so a new reader of either is absorbed by the input already there;
its docstrings now say so instead of claiming every new reader reds.
Three existing guards gain entries in this change, and each passed a
form a normal author could write. The session-context name census
missed a file name assembled from pieces ("pact-session-" + "context.json"
or an f-string). The store-scope decorator contract read only `def`
statements, so a public method bound as an alias of an undecorated
function was invisible. The path-setup pin missed a mutation through a
name assigned sys.path.

The name census now counts a piece that names the file or the piece of
an assembled name, which also counts the context writer's own temp-file
prefix; the contract requires every public callable or descriptor of
the class to be a `def` it reads; the pin follows names assigned
sys.path to a fixed point. Each has a control.
The census loaded a helper module by the dotted name its import alias
recorded, as a top-level file under the memory scripts or hooks/. A
relative import drops its dots in that record, so `from .paths import
get_claude_config_dir` inside hooks/shared/project_scope.py named a
`paths` module that does not exist there. The call was skipped, and
every input read inside the helper stayed out of the census: a new
environment read added to get_claude_config_dir left it green.

The graph now resolves a relative import against the importing
module's own package, and finds a package's __init__.py. A relative
import naming a module it cannot find, or climbing above its package,
is recorded as unresolved, and a use of it in a reached function
becomes a call condition no exclusion names, so the census fails
closed. One input became visible: the whole-environment use in
get_claude_config_dir, behind which CLAUDE_CONFIG_DIR locates the
session records. It is named as not a route: it is reached only
through the two session-record readers, which return nothing in a test
process before reading it, and whose records the session-record and
worktree identity record routes replace whole. A fixture package
controls the resolution and both unresolved shapes.
A call through a relatively imported name that reaches no function -
a class, a package re-export the graph cannot follow, or a class
reached as an attribute of a relatively imported module - was skipped,
so whatever it reads stayed out of the census.

Such a call now becomes a condition no exclusion names. A method of a
module-level object of the imported module (a compiled pattern's .sub)
is not one, because the object holds data rather than a route input.
The fixture package's control marks each form.
The git-call floor's layout-completeness arm excludes three `.git`-layout
predicates with a stated reason. Each reason listed fewer cases than its
predicate's code returns true for, and the comment above them said only a
hostile `.git` reaches them.

The submodule admin-dir check is true whenever the recorded checkout
cannot be proven: another checkout (a forgery), git cannot run,
`git config core.worktree` exits non-zero or prints nothing, a path cannot
be resolved, or the recorded path does not exist. The redirect check is
true for a target named `.git` and also whenever it hands a submodule
admin dir to that check, and the `.git`-file check is true only through
the redirect check. All three are reached only through detect_id_for_root's
redirect check, which declines.

Each reason now names every truthy return with its line, and says how it
ends: the matrix shapes that reach it and decline, or, where no fixture
shape reaches it, the code path that declines it. The user's own
`--separate-git-dir=<dir>/.git` store is named as the one own layout that
binds, through a pin read before the check.
The identity-caller census reads a plain alias (`_resolve =
main_repo_common_dir`, then `_resolve(...)`) through the scope's bindings
and counts the call as a site, as its docstring says. Its fail-closed rule
for unreadable references still flagged that alias, because it also
visited the assignment's target: a name being bound, which the bindings
resolve back to the identity function.

The rule now considers only names and attributes read in Load context, so
an assignment target is not a reference. Measured on an archive copy: the
plain alias passes and its call is counted as a site; an annotated alias,
a `partial` wrapper and a function stored in a list are still flagged; the
twelve per-form mutants from the fail-closed change still fail their arms.

The other four censuses in the module do not read aliases, so a binding of
the name they track is a form they cannot follow, and flagging it is
correct; the marker-predicate census already reads only loads.
… call it cannot read

The census recognised the forms reviewers had named and passed the rest:
os.environb, os.path.expandvars, a second key read through a name bound
to the environment, os.getenvb, a module-level alias of os.environ, a
method on a module-level reader instance, a function pulled from a
module-level table, and a class method reached through an absolute
import. It also credited a helper as driven whenever a route drove any
input read inside it, so a new record reader that happened to read a
driven variable passed.

The census now anchors on every reference to the environment (each
os.environ*, os.getenv*, os.putenv, os.unsetenv and os.path.expandvars,
read from the os module, and every name bound to one in the module, a
function or a parameter default) and reads each occurrence as a constant
key or reports it. It anchors on every call made through one of the
project's own names, reads it when it resolves to a function, and
reports it otherwise; a method called directly on a literal table, a
compiled pattern or a logger, and building a class of the calling module
that runs no project code, are the recognised exceptions. A helper counts
as driven only when a route replaces it, and the per-helper read map
that served the old rule is removed.

Ten calls on the detection path are now named with a reason (the
per-pass memo and store-scope context variables, a NamedTuple _replace,
and the git environment copy's items), and the config-root read is now
the CLAUDE_CONFIG_DIR key, the only key read there. A fixture control
marks every environment form read, accepted or reported.
The git-call floor's completeness arm walks from the identity layer's
marker predicates to every project_identity function they call, and keeps
the ones that are predicates. It kept a function only when its return
annotation was the bare name `bool` and reported only a missing
annotation, so a predicate written `-> "bool"`, `-> Optional[bool]`,
`-> builtins.bool` or `-> bool | None` dropped out of the census and its
layout outcomes went unchecked, with the arm still green.

Every reached function is now classified by two forms the walk reads and
no others: a predicate (the bare `bool` annotation), or not a predicate
(an annotation naming no `bool`, `Any` or `object` and holding no string or
`Literal`, with no bool-shaped return in its body). Anything else is
reported with its line, and the arm fails. The twelve functions reached
today classify cleanly. Each of the four annotation spellings above, and a
non-predicate that returns a bool, now fails the arm; a docstring mentioning
`-> bool`, an unrelated `bool` variable and a non-predicate returning
`x or None` do not.
The route census treats a method call on a module-level literal table,
compiled pattern or logger as data, and it classified the name by its
last top-level assignment. A name bound twice at top level - a call and
then a literal, or a literal that a function later rebinds under
`global`, or one extended with `|=` - could therefore read as data while
another binding put a callable or an instance there.

Every binding of a module-level name is now collected: plain
assignments in module code (inside if, try, with, match and loop
bodies), and as non-data bindings, tuple, subscript and attribute
targets, augmented assignments, loop and with targets, walrus targets,
imports, defs and classes, and any assignment under `global` in a
function. The name is data only when every binding is a recognised data
value; otherwise a call through it is reported. A control marks each
binding shape.
Four statements said a repository pin always outranks the user-scope
project_id, or does so on every route. A home directory that is itself a
repository is the exception: no rung reads a pin there. The git-root and
declared rungs land on the folder name, and the cwd-marker rung, whose
home landing never asks git, binds the user setting when one is set. Measured with a
home repository holding a canonical pin and a user setting: the git-root
and CLAUDE_PROJECT_DIR routes give the folder name, the cwd-marker route
gives the user setting, and without a setting the folder name.

The memory skill, the resolver's two docstrings and the user-setting
reader's docstring now say the pin outranks the setting wherever one is
read, and name the home directory case. The rung-parity test's docstring
for the pin arm now says its every-route claim covers the own layouts,
none of which is a home directory.
Both scans counted only the forms they recognised and skipped the rest,
so each reviewer found a new form that passed: the executable name as
the head of a list joined by shlex.join (the printed rekey remedy's own
shape), and a context-file name built with %, .format or a join.

Each scan now anchors on the token itself and either reads every
occurrence or reports it, with no third outcome:
- the executable scan: every whole-word `pact-memory` in a str or bytes
  constant, f-string pieces and docstrings included. A path segment, a
  word or punctuation after it, or a whole stand-alone string ending on
  it is read; a CLI verb after it is an offence; any other occurrence (a
  list or dict element, a join, format, % or + piece) is unreadable.
- the context-file name census: `pact-session` (not `pact-sessions`),
  `session-context`, and the `context.json` tail, in any string or
  f-string piece outside a docstring. A counted name site or a complete
  other session-file name is read; any other occurrence (a template, a
  piece a join or replace completes) is unreadable.
A new arm asserts each unreadable list is empty, and a live control pins
the verdict of each form.

The tree reads clean under both rules. Mutants in the named forms (the
argv head, a join, %, .format) and in forms no finding named
(.format argument, a dict value, string.Template, str.replace) each fail
at the unreadable assertion; a comment, a docstring, another word, a
path segment, another session file and the sessions root stay green.
The git scanner accepted the location-free environment helper only by its
bare name, so importing it under another name, or calling it as an
attribute of its module, failed the scan although the environment was
right. It now resolves the helper through the module's imports; a name
bound by importing another function, a call with no environment and an
environment copied from os.environ still fail.

The path-setup pin read every string constant as possible generated
code, so a docstring mentioning sys.path.insert failed it. It now skips
docstrings; a string assigned for a child process to run, a real
insert and every other mutation form still fail.

Each has an arm that fails when its fix is reverted.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

The two re-clone arms seeded a session 60 s before the original
description, so it never counted, re-clone or not: deleting the re-clone
left both green. They now seed with the default start, just after the
description, so the session counts until the re-clone replaces the
description; deleting the re-clone fails each arm.

The ledger arm dated its would-pass line from the wall clock, so under a
filesystem clock leading by an hour the line no longer passed and the arm
went vacuous. It now dates the line from the description, and reading
the ledger while the folder is live fails it under a one-hour lead too.

The fixture docstring now cites what was measured after this change:
with no margin, 15 to 21 of the seeding tests failed across five runs,
and with a 1 s margin both re-clone arms fail.
Every round of review since the folder-name gate was added found a new way
it either hid a project's own memories or let a same-name folder through,
the last one introduced by the previous fix. Folder-name ids (a repository
with no portable origin, a non-git project folder, the home landing, a
user setting) are no longer judged: they read and save their same-name
bucket as before this change, which the release notes and the skill now
state plainly. The folder-name refusal, its error arm and the pin remedies
that served it are removed.

Repository-identity sessions keep the ownership rule, with two fixes:
- a nearest checkout is a rival when its pre-change name or its folder-name
  id is the bucket's, so a --separate-git-dir checkout is recognised; and
- a .git file naming a git directory that does not exist has an unknown
  name, so a dangling pointer fails closed.

Also: an empty port in a remote (ssh://host:/o/r) means the default port,
as git reads it; hosts and ids with empty labels are refused; the
core.worktree docstring, comments and release notes say what the code
accepts; and a test stub matches the production signature.

Refs #1677

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 473395b. Configure here.

if nearest is not None and not any(_within(nearest, root) for root in roots):
name = pre_change_name(nearest, walk.names)
if name is UNKNOWN_NAME or bucket in (name, os.path.basename(nearest)):
return "checkout"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worktree basename treated as rival owner

Medium Severity

The new nearest-checkout check treats os.path.basename(nearest) as that checkout's folder-name id. For a linked worktree the folder name is not the id: the old and new resolvers both key on the main checkout (via commondir). A worktree directory that merely shares the bucket name is then counted as a rival, so a cross-linked file there can mark this repository's legacy bucket excluded or unproven and drop it from reads.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 473395b. Configure here.

…e cost plainly

- The location-divergence warning resolved the identity root directly and
  skipped the home-landing guard, so under a home dotfiles repository it
  could name an id the resolver would never bind. It now applies the same
  guard as the resolver.
- The release notes and SKILL.md state that in a long-lived store most
  pre-upgrade buckets are reported unproven and stay out of reads until a
  user approves a rekey, and that a repository's un-rekeyed old bucket is
  still shared with same-name folder-name sessions.
- Stale wording is corrected: a rekey target that is not canonical is only
  ever explicit, the reserved-host docstring no longer cites a removed
  remedy, a fail-closed git branch no longer claims a submodule always
  records core.worktree, and _unproven_cause lists its real callers.

Refs #1677
main released v4.8.37 for the in-process idle hold. This change's release
notes become the v4.8.38 section above it, and the five release files move
to 4.8.38.

Refs #1677
@cursor

cursor Bot commented Nov 24, 2026

Copy link
Copy Markdown

This PR is too large for Bugbot to review. It changes 56,955 lines and 3,038,507 characters. Split the change into smaller pull requests to get a review.

… the store

- The submodule-admin path test and the pre-change-name reader existed as
  two copies each, one in the store layer and one in the identity layer,
  so an edit to one could silently move the ownership verdict away from
  the resolver. Each pair is now one helper both layers call, and the
  store layer still does not import the identity module.
- The rekey dry run wrote inside a savepoint on a normal locking
  connection, which could leave -wal and -shm files beside a settled
  store; it now leaves the store's files untouched, and a test checks it.
- The skill says what a dry run leaves, the secretary's calibration step
  states its not-determined rule once, and the release notes give the
  ledger writer's real wait bound.

Refs #1677
…last unguarded reads

- Two clones of one repository (a/proj and b/proj, same origin) each saw
  the other's rows as a rival owner, so the old bucket was unproven from
  both. A checkout whose identity matches the session's (the same origin
  url in its own config, or the same pin) is now the same owner; a
  different-origin checkout named like the bucket is still foreign, and
  an unreadable identity still fails closed.
- The user-scope config.json is read as a bounded regular file like every
  other identity input, so a FIFO there cannot block resolution.
- The session-folder listing cache also keys on size, so a coarse-mtime
  filesystem cannot serve a stale listing.
- Two more inline copies of the parent-name derivation now call the
  shared helper, and a worktree-admin docstring states the real trimming.

Refs #1677
… endpoint one id

- The clone check compared a pin file's raw first line, so a pin with a
  CRLF ending, a leading comment or a leading space counted a clone of this
  repository as a rival. It now parses the pin the way the resolver does.
- A pin that was present but rejected switched off url matching for
  sibling clones; only an accepted pin does now.
- ssh://git@ssh.github.com:443/O/N, GitHub's SSH-over-443 endpoint, now
  resolves to github.com/o/n like every other GitHub spelling, matching the
  backlog's parser.
- The prune-ledger index cache also keys on inode and ctime, so a
  same-size compaction is not served stale, and the ledger is opened with
  O_CLOEXEC like its sibling readers.
- The skill and release notes state the clone rule exactly as the code
  applies it.

Refs #1677
read_session_record now passes O_CLOEXEC, through getattr, like its
sibling readers of the prune ledger, the user setting and git files.

Refs #1677
…ath rule

- The sibling-clone check read only the first origin url of the other
  clone's config. It now reads every line and refuses the config where
  the resolver declines: an empty or valueless origin url anywhere, an
  unreadable url, or an include anywhere. A parity test compares it with
  the resolver's own read on real repositories.
- Docstrings, the skill and the release notes now say the url is
  compared exactly as written, so ssh/https or .git spellings of one
  repository stay rivals.
- The skill's decline remedies again say that when override_path is
  null because .git points at an outside git directory, a pin there may
  remedy the decline and only the user writes it, and its test binds
  that sentence. repo_root again names its role in the legacy gate.

Refs #1677
git reads a deprecated [remote.origin] header as remote.origin, but the
sibling-clone config reader skipped it, so a config holding such a
section before a [remote "origin"] one bound another url in git while
the reader returned this repository's. The reader now refuses any
dotted section header, and a parity arm compares it with read_origin.
The release note drops a parenthesis that was wrong for includes.

Refs #1677
- An ssh or scp host alias may contain an underscore (git@gh_work:o/r
  gives gh_work/o/r); https hosts and a leading or trailing underscore
  still decline.
- A remote-helper origin (<helper>::<address>, codecommit, sso,
  keybase, persistent-https) has no portable id, so it uses the folder
  name as a repository with no remote does; project-id show reports
  source "remote helper" with an identity_detail naming the pin remedy,
  and one warning per repository says so without printing the url.
  Other unknown schemes still decline.
- www.github.com maps to github.com, in the backlog's parser too; the
  ssh.github.com fold applies to ssh and scp only; a github.com path
  with one segment declines.
- The skill and release notes state each rule, and list a dotted
  section header among the configs that keep a sibling clone a rival.

The parser hunks interleave in project_identity.py, so these land as
one commit.

Refs #1677
An alias stays in the id, so a clone made by url gets the canonical id
and another bucket. The skill and release notes now say so, with the
pin as the way to join them.

Refs #1677
The identity code folds ssh.github.com into github.com only for ssh and
scp remotes, but the backlog's remote parser read an https remote on
that host as owner/repo too. It now returns no slug there, so the two
parsers agree.

Refs #1677
Warnings and the legacy-write refusal printed a project-id rekey
command and said running it moves the rows, but the command is a dry
run: it exits 0, reports the count, and moves nothing. Each message now
says "preview the move with" the command and that adding --apply, with
the user's approval, performs it; the printed command still never
carries --apply. The skill and release notes say the same, and the
release note for the backlog's ssh.github.com parser, which landed
without its line, is added.

Refs #1677
The backlog parser read ssh://git@ssh.github.com:2222/O/R as O/R while
the identity code keeps that port in the id. It now reads ssh.github.com
only with no port, 22 or 443, so the release note's "the backlog reads
them the same way" holds.

Refs #1677
The sync --help epilog said the template moves the bucket; it previews
the move, and --apply, only with the user's explicit approval, performs
it.

Refs #1677
…e id does

The backlog read github.com and www.github.com on any port as GitHub's
owner/repo, while the identity code keeps a non-default port in the id
as a separate server. The backlog now reads them only with no port or
the scheme's default (https 443, http 80, ssh 22, git 9418); a ported
remote gives no slug. www.github.com on a port was new in this branch;
github.com on a port was main's behaviour.

Refs #1677
… as the id does

- A pin could hold a github.com id no remote derives, such as
  github.com/Acme/Widget, which split the repository from its clones
  with no warning. The one pin rule now folds a port-less github.com or
  www.github.com pin as a remote is folded (www to github.com, path
  lower-cased outside %XX escapes) and refuses a one-segment github.com
  pin; ported and other hosts stay as written. Pins and remotes share
  one copy of the GitHub rules in database.
- The backlog strips a github.com .git in any case, and the repo/.git
  form, as the id does.
- The skill and release notes state both rules.

These share the release-note and route-census hunks, so they land as
one commit.

Refs #1677
… github pin

- The backlog's own remote parser disagreed with the memory id on 1,398
  of 7,215 generated spellings (leading-zero ports, ?/# tails, escapes,
  user-less scp, ~/ paths, ports). It now reads owner/repo from the id
  itself, lower-cased, and gives none where the id declines; the hand
  parser is removed and a parity test over that corpus pins agreement.
- A ported github.com pin's path is lower-cased as its remote's id is,
  so a pin copied from https://github.com:8443/O/N names the remote's
  bucket; www.github.com and other hosts on a port keep their case.
- The release notes no longer fuse two bullets on one line, and a
  release-notes test fails on any bullet glued mid-line.

The release-note and test hunks interleave, so these land as one
commit.

Refs #1677
The backlog now reads its slug from the memory id, so the agreement test
compared one parser with itself and with a hand copy of its last steps,
which already differed on all-dots names. It now asserts end-to-end
slugs against 51 fixed expectations, including all-dots names, and
says there is one parser.

Refs #1677
The pin docstring said a mixed-case pin names the same id its remote
would; the fold applies only GitHub's case and www rules and keeps a
trailing .git, since github.com/o/r.git is itself derivable.

Refs #1677
…Hub does not serve

- The backlog held back every memory-skill warning on success, including
  the store's own (a legacy bucket that could not be checked) while show
  opens the store. Identity warnings now carry a mark and only those
  are held; store warnings print.
- git sends git@github.com:~/o/r as ~/o/r and .../o/r/.git as /o/r/.git,
  and GitHub serves neither, but both gave github.com/o/r. A github.com
  id now declines them, and the backlog follows; a plain ssh server
  keeps both forms.

The release-note hunks for both sit in one section, so they land
together.

Refs #1677
…Hub reads them

The not-served rule read the path as written, so https://github.com/O/R/%2Egit
still bound github.com/o/r and .../O/R/.GIT gave a three-segment id.
It now decodes escapes and matches .git in any case, and a github.com
id must be exactly owner/repo; ported github.com, other hosts and a
plain ssh server are unchanged, and the backlog follows.

Refs #1677
…wner/repo

A port-less github.com remote or pin bound an id GitHub cannot serve:
an escaped slash (O/R%2Fx), a name with ~ or + or a non-ASCII letter, or
more than owner/repo. One rule in database (is_github_name,
is_github_repo_path) now decides it on the decoded names for the
remote id, the pin and the backlog slug, so the three always agree;
ported pins and remotes, which check no names, are unchanged. The skill
and release notes state the rule.

Refs #1677
…thout file proof, and read the backlog's first origin url

- A pin is decoded and folded by the same github_repo_path step as its
  remote, on any host and port, so github.com/o/%41b and
  github.com:8443/o/%41b name the ids their remotes give. An https
  github.com remote whose .git suffix is escaped declines: GitHub
  decodes ordinary escapes but strips only a literal .git (measured
  with git ls-remote).
- The "no recorded session" warning fires only for a bucket read on
  session evidence alone; a bucket verified by its file rows reads
  quietly, as its defaulted rekey already treats it.
- The backlog read the last remote.origin.url through git config --get;
  it now reads the first url of the repository's own config, as the id
  does.
- The skill states when legacy_scope is null and when its candidate is
  null, and the skill and release notes state the pin and warning rules.

The release-note, skill and census hunks for these interleave, so they
land as one commit.

Refs #1677
Main took 4.8.38 for the structural wait watcher. This PR's release
section moves to v4.8.39 above it, and the five release files carry
4.8.39.

Refs #1677
…nattributed rows, and say how to write a pin

- The backlog's origin read used rev-parse --path-format, which git
  before 2.31 echoes back, so the slug was silently None there while
  the id resolved. It now finds the common dir with the id's own reader
  (relative answers resolved, paths decoded with os.fsdecode), on every
  git the id supports and on a non-UTF-8 path.
- A verified legacy bucket with rows from no recorded session is read
  with one informational line per process that gives their count and
  says its file rows place it here; a bucket read on session evidence
  alone keeps its warning.
- The skill tells the user to write a pin as the id project-id show
  reports, with no .git, since a pin keeps a .git that a remote drops.

The release-note, skill and test hunks for these interleave, so they
land as one commit.

Refs #1677
The verified-bucket line and the unverified warning shared one
once-per-process key, so a bucket that turned verified within a process
logged only the first message. Each now has its own key. The docstring
says the line asks nothing and is logged at WARNING only because no
pact-memory script installs a handler, so lastResort shows WARNING and
above.

Refs #1677
…git-ending github pin

- rekey --apply reads the scope first because its verdict gates the
  move, and that read printed "NOT in this read scope ... preview the
  move" just before the applied move's own result. The pre-move read now
  runs with the legacy notices held for that call only; a dry run still
  prints them, and a later read still discloses.
- A port-less github.com pin whose repository ends in .git is honoured
  as written, but its remote drops the .git and gives another id.
  project-id show now names that in identity_detail, and one warning
  per root names the remote's id.
- The skill and release notes state both.

The census and release-note hunks for these share one table and one
section, so they land as one commit.

Refs #1677

This branch has not been deployed

No deployments
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.

1 participant