Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 40 additions & 13 deletions scripts/check-memory-rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
uv run --no-sync python3 scripts/check-memory-rotation.py --bookmark <PATH> --all
uv run --no-sync python3 scripts/check-memory-rotation.py --bookmark <PATH> --json

# the defaults both point at the paths this host uses
# The two defaults name this repository's own layout. An installation that keeps
# its bookmark under the other name is still read - the fallback covers that - and
# the run says which file it opened; any other layout is reached by naming both.
uv run --no-sync python3 scripts/check-memory-rotation.py

Why this exists
Expand Down Expand Up @@ -210,19 +212,24 @@ def now() -> datetime:
MEMORY_SUBDIR = (".emrg", "memory")
SESSIONS_SUBDIR = (".emrg", "sessions")

#: Both defaults are this host's paths. They are defaults rather than required
#: arguments because step 0 runs every cycle on this installation; any other
#: layout is reached by naming the two paths, and the report says which it read.
#: The defaults name **this repository's** layout, which is not every installation's:
#: measured 2026-11-18, the host that filed issue #2951 keeps its bookmark under the other
#: name and has never written the one below, and a review of that issue reported the
#: reverse pairing on a second host. They are defaults rather than required arguments
#: because step 0 runs every cycle; another layout is reached by naming the two paths -
#: and, for the bookmark, by `BOOKMARK_FALLBACK` when the default's name is absent - and
#: the report says which file it read either way.
DEFAULT_AGENTS = "~/.emrg/agents.yml"
#: The bookmark keeps its **pre-rename basename**, and the difference from the
#: register above is the whole point: the register's move is a migration
#: (`emrg.config` performs it), so naming the new file and falling back over the
#: window is right. The bookmark is moved by **nothing** — no code in this tree
#: renames it, it is a file this installation writes and this tool reads — so a
#: renamed constant renames no file and answers `not measurable` on every cycle
#: from then on. A name whose value is host state is preserved verbatim, which is
#: the same rule the register already obeys one line down: its fallback still
#: spells the **old** name (`projects.yml`) rather than translating it.
#: The basename is **host state and stays verbatim**: a test in
#: `tests/test_check_memory_rotation.py` pins it, because renaming the constant renames no
#: file, and step 0 then answers `not measurable` on every cycle from the merge onwards.
#:
#: Which of the two bookmark names an installation keeps is **its own state**, not a
#: property of this file: measured 2026-11-18 on the host that filed issue #2951 this
#: name is absent and `BOOKMARK_FALLBACK`'s is present, and a review of that issue
#: reported the reverse on another host. So neither name is universal, and the value
#: below stays the one this repository has always carried - a test pins it - while the
#: other is reached by the fallback and the run says which file it read.
DEFAULT_BOOKMARK = "~/.emrg/evolution/emrg/.emrg/memory/project-memory-rotation-bookmark.md"

#: The register's name before an Agent became the record of the directory a
Expand All @@ -241,6 +248,15 @@ def now() -> datetime:
#: reading never claims a subject it did not open.
LEGACY_AGENTS = "~/.emrg/projects.yml"

#: The other name a bookmark is kept under, reached only when the default is absent
#: (issue #2951). On the host that filed that issue the default's name is absent and this
#: one is present, which is why the no-argument form could not be run there at all; a
#: review reported the opposite pairing on a second host. Both are therefore live
#: possibilities, neither is a replacement for the other, and the fallback fires only from
#: the default - never on a path a caller named - so the reading is always about the file
#: it opened.
BOOKMARK_FALLBACK = "~/.emrg/evolution/emrg/.emrg/memory/project-memory-bookmark.md"


class Unmeasurable(Exception):
"""A reading could not be taken. Reported as exit 2, never as a pass."""
Expand Down Expand Up @@ -950,6 +966,17 @@ def main(argv: list[str] | None = None) -> int:
file=sys.stderr,
)
agents_path = legacy_path
# The bookmark's one window, on the same terms: only the default may fall back, and the
# run says which file it read rather than presenting one name's answer as another's.
if args.bookmark == DEFAULT_BOOKMARK and not bookmark_path.exists():
fallback_bookmark = Path(os.path.expanduser(BOOKMARK_FALLBACK))
if fallback_bookmark.exists():
print(
f"note: {bookmark_path} does not exist - reading {fallback_bookmark}, "
f"the bookmark's other name",
file=sys.stderr,
)
bookmark_path = fallback_bookmark
try:
reading = read(agents_path, bookmark_path)
except Unmeasurable as exc:
Expand Down
65 changes: 65 additions & 0 deletions tests/test_check_memory_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,3 +1247,68 @@ def test_a_moved_note_belongs_to_the_file_it_was_moved_to(mod, tmp_path):
assert len(mod.narration_blocks(archive)) == 3, (
"the moved notes are still notes, of the archive file - if they read as zero there, "
"moving them out of the bookmark lost them instead of storing them")


# ── the default's own name, and the other spelling it falls back to ───────────


def test_the_default_bookmark_falls_back_to_the_name_this_host_writes(
mod, tmp_path, monkeypatch, capsys
) -> None:
"""Issue #2951: the default's file is not one this host writes, so `main([])` never ran.

Measured 2026-11-18: this checkout keeps its bookmark at `project-memory-bookmark.md`
- the name §1.5 and the memory index both use - and has never written the default's
name, so the no-argument form answered `not measurable: no bookmark at <that path>`
on every cycle. The tool built to end the hand-written step-0 probe could not replace
it on the host that ran it.

The default keeps its value - the basename is host state, and the test above pins that
- so the reading is reached by a fallback instead, on the register's own terms. Both
directions, because a fallback that never fires and one that always fires look
identical from a single arm. The constants are redirected at the module, so no host
path is opened.
"""
assert mod.DEFAULT_BOOKMARK.endswith(
"/.emrg/memory/project-memory-rotation-bookmark.md"), (
"the default's basename is host state; this change must not rename it")
assert Path(mod.BOOKMARK_FALLBACK).name == "project-memory-bookmark.md", (
"the fallback must name the other spelling of the bookmark: §1.5 and the memory "
"index both use this one, and which an installation keeps is its own state")

root = tmp_path
register = root / "agents.yml"
register.write_text(f"- name: alpha\n path: {root / 'alpha'}\n", encoding="utf-8")
row = (
"| project | stamp | read by |\n"
"| --- | --- | --- |\n"
f"| `alpha` | {BASE} | `cyc20261118-000000` |\n"
)
preferred = root / "preferred.md"
preferred.write_text(row, encoding="utf-8")
fallback = root / "fallback.md"
fallback.write_text(row, encoding="utf-8")

monkeypatch.setattr(mod, "DEFAULT_AGENTS", str(register))
monkeypatch.setattr(mod, "LEGACY_AGENTS", str(root / "absent-register.yml"))
monkeypatch.setattr(mod, "DEFAULT_BOOKMARK", str(preferred))
monkeypatch.setattr(mod, "BOOKMARK_FALLBACK", str(fallback))

assert mod.main([]) in (0, 1)
captured = capsys.readouterr()
assert str(preferred) in captured.out, (
"the run must say which bookmark it read, and with the default present that is "
f"the default: {captured.out}")
assert "does not exist - reading" not in captured.err, (
"the default is present, so nothing was fallen back to - a note here would say "
f"the run read a file it did not: {captured.err}")

preferred.unlink()
assert mod.main([]) in (0, 1)
captured = capsys.readouterr()
assert str(fallback) in captured.out, (
"with the default absent the reading must come from the fallback, and say so: "
f"{captured.out}")
assert "does not exist - reading" in captured.err, captured.err
assert str(fallback) in captured.err, (
f"the note must name the file it read instead: {captured.err}")
Loading