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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

- Installer: an identity that exists only in the installing shell (`EMAIL`, `GIT_AUTHOR_EMAIL`,
`GIT_COMMITTER_EMAIL`) is persisted into the brain's `.git/config`, so the hourly sync — which
runs under launchd with a minimal environment — can keep committing. Previously only the seed
commit worked. A configured git identity is still left alone.

## v0.7.0 (2026-09-04)

**Reliability overhaul: every memory captured, every injection honest, failures visible within a day.**
Expand Down
37 changes: 31 additions & 6 deletions agent/tools/render_pending_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,27 @@ def _health_age_hours(health: dict) -> float:
return max(0.0, (now - generated).total_seconds() / 3600.0)


def _last_run_sync_lines(tail_lines: list[str]) -> list[str]:
"""The most recent run's own `sync:` lines, newest first, down to and
INCLUDING the terminal-marker line that ends it.

Not `_in_last_run`: that helper assumes the marker is a run's last line,
and the scan_gate-missing path logs its marker and then a
`sync: reinstall …` hint, so the marker read as the PREVIOUS run's end
and the blocked classification was unreachable. Every blocked marker
sync.sh writes sits on the terminal line itself, so stopping at the
first marker seen (newest first) keeps the scan inside one run.
"""
out: list[str] = []
for ln in reversed(tail_lines):
if _is_health_line(ln) or not _is_sync_run_line(ln):
continue
out.append(ln)
if any(m in ln.lower() for m in _RUN_TERMINAL_MARKERS):
break
return out


def _check_sync_status(
brain_root: Path,
tail_lines: Optional[list[str]] = None,
Expand Down Expand Up @@ -545,13 +566,17 @@ def _check_sync_status(
if held_back is None:
held_back = _held_back_paths(tail_lines)
# A run's own lines only: `health: stderr:` can quote anything, including
# an old "sync: ... push failed" (staff delta review, M3).
sync_lines = [ln for ln in tail_lines[-100:] if _is_sync_run_line(ln)]
# an old "sync: ... push failed" (staff delta review, M3). And EVERY line
# of the last run, newest first — not just the last one: the
# scan_gate-missing path logs its marker and then a `sync: reinstall …`
# hint, which made that run read as ok (follow-up 3, M3).
sync_lines = _last_run_sync_lines(tail_lines[-100:])
if sync_lines:
last = sync_lines[-1].lower()
for marker, reason in _SYNC_BLOCKED_MARKERS:
if marker in last:
return reason
for ln in sync_lines: # newest first
low = ln.lower()
for marker, reason in _SYNC_BLOCKED_MARKERS:
if marker in low:
return reason
# Pushed, but not everything went. Never let this pass as 'ok'.
# Oversize first: a size hold-back also logs a "held back" line, so
# the quarantine check below would otherwise claim a secret hit and
Expand Down
8 changes: 6 additions & 2 deletions bin/install-recall-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ fi
# again. Cheap: deps are already satisfied, only the scripts are rewritten.
if ! grep -q "from recall.cli import main" "$VENV_RECALL"; then
log "regenerating $VENV_RECALL (console-script entry point changed)"
"$VENV_DIR/bin/pip" install --quiet -e "${REPO_DIR}[embeddings,mcp]"
if ! grep -q "from recall.cli import main" "$VENV_RECALL"; then
# pip's build isolation downloads hatchling, so this needs the network.
# Offline it fails — and under `set -e` a bare call would end the helper
# here, before the warning and before the symlink step. Fall through.
if ! "$VENV_DIR/bin/pip" install --quiet -e "${REPO_DIR}[embeddings,mcp]"; then
warn "pip could not regenerate the wrapper (offline?); $VENV_RECALL still enters through the old entry point. Run later: $VENV_DIR/bin/pip install -e '${REPO_DIR}[embeddings,mcp]'"
elif ! grep -q "from recall.cli import main" "$VENV_RECALL"; then
warn "$VENV_RECALL still enters through the old entry point; run: $VENV_DIR/bin/pip install -e '${REPO_DIR}[embeddings,mcp]'"
fi
fi
Expand Down
59 changes: 37 additions & 22 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3150,28 +3150,43 @@ if [ -n "$BRAIN_REMOTE" ]; then
else
git remote add origin "$BRAIN_REMOTE"
fi
# A fresh machine, a CI runner or a service account often has no git
# identity anywhere. Without one the seed commit dies with "Author
# identity unknown" AFTER the brain was laid out and BEFORE the hooks,
# LaunchAgents and daemon were installed — a half-install, exit 128
# (2026-09-08 full-day QA). Give the brain a REPO-LOCAL identity, where
# the hourly sync.sh commit (launchd, minimal environment) finds it too.
# A configured identity — global, local, or GIT_AUTHOR_*/GIT_COMMITTER_*
# in the environment — is left alone.
# Seed when either (a) git says the commit would fail — `git var` applies
# the same rules as `git commit` (config, EMAIL, GIT_*_IDENT variables,
# auto-detection) — or (b) nothing EXPLICIT is configured and git would
# fall back to an auto-detected `user@host.local`: a CI runner gets that
# far, but a brain's history should not be built on a guessed identity.
if ! git var GIT_AUTHOR_IDENT >/dev/null 2>&1 \
|| ! git var GIT_COMMITTER_IDENT >/dev/null 2>&1 \
|| { [ -z "$(git config user.email 2>/dev/null)" ] \
&& [ -z "${GIT_AUTHOR_EMAIL:-}${GIT_COMMITTER_EMAIL:-}${EMAIL:-}" ]; }; then
git config user.name "brainstack"
git config user.email "brainstack@localhost"
echo " No git identity configured; set a repo-local one for the brain"
echo " (brainstack <brainstack@localhost>). Change it any time with:"
echo " git -C $BRAIN_ROOT config user.email you@example.com"
# The brain's commit identity must be DURABLE. The hourly sync.sh runs
# under launchd with a minimal environment, so an identity that exists
# only in this shell (EMAIL, GIT_AUTHOR_EMAIL, GIT_COMMITTER_EMAIL) makes
# the seed commit succeed and every later auto-commit die with "Author
# identity unknown" (Codex review, pass 5). A fresh machine, CI runner or
# service account has no identity at all and used to die at the seed
# commit — after the brain was laid out and before hooks, LaunchAgents
# and daemon were installed (2026-09-08 QA).
# * git config already has an email (global or local): leave it alone.
# * only the shell has one: persist THAT into the brain's .git/config,
# so history carries the user's address rather than a placeholder.
# * nothing anywhere: brainstack <brainstack@localhost>, repo-local.
if [ -z "$(git config user.email 2>/dev/null)" ]; then
seed_email="${GIT_COMMITTER_EMAIL:-${GIT_AUTHOR_EMAIL:-${EMAIL:-}}}"
seed_name="${GIT_COMMITTER_NAME:-${GIT_AUTHOR_NAME:-}}"
if [ -n "$seed_email" ]; then
if [ -z "$seed_name" ]; then
seed_name="$(id -F 2>/dev/null || true)"
[ -n "$seed_name" ] || seed_name="$(id -un)"
fi
git config user.name "$seed_name"
git config user.email "$seed_email"
echo " Persisted your shell's git identity into the brain repo ($seed_name <$seed_email>)"
echo " so the scheduled sync (which runs with a minimal environment) can commit."
else
git config user.name "brainstack"
git config user.email "brainstack@localhost"
echo " No git identity configured; set a repo-local one for the brain"
echo " (brainstack <brainstack@localhost>). Change it any time with:"
echo " git -C $BRAIN_ROOT config user.email you@example.com"
fi
elif ! git var GIT_COMMITTER_IDENT >/dev/null 2>&1; then
# An email is configured but git still cannot build an ident (no
# name and an un-guessable host): give it a name so the seed commit
# cannot die here.
git config user.name "${GIT_COMMITTER_NAME:-${GIT_AUTHOR_NAME:-brainstack}}"
echo " git could not build a committer identity; set user.name repo-locally."
fi
# Stage + commit if there's anything to commit
git add -A
Expand Down
62 changes: 55 additions & 7 deletions tests/test_install_git_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ def _no_identity_env(tmp_path: Path) -> dict[str, str]:
return env


def _git(brain: Path, *args: str) -> str:
def _git(brain: Path, *args: str, env_extra: dict[str, str] | None = None) -> str:
env = {**os.environ, "GIT_CONFIG_NOSYSTEM": "1", "GIT_CONFIG_GLOBAL": "/dev/null"}
env.update(env_extra or {})
return subprocess.run(
["git", "-C", str(brain), *args], capture_output=True, text=True,
env={**os.environ, "GIT_CONFIG_NOSYSTEM": "1", "GIT_CONFIG_GLOBAL": "/dev/null"},
["git", "-C", str(brain), *args], capture_output=True, text=True, env=env,
).stdout.strip()


Expand Down Expand Up @@ -87,10 +88,13 @@ def test_install_without_any_git_identity_still_seeds_the_brain(tmp_path):


@pytest.mark.skipif(_find_py310() is None, reason="needs Python >= 3.10 on PATH")
def test_install_leaves_a_configured_git_identity_alone(tmp_path):
def test_install_leaves_a_git_config_identity_alone(tmp_path):
"""An identity that lives in git config (global here) is durable: the
hourly sync finds it too. Nothing is written to the brain's .git/config."""
env = _no_identity_env(tmp_path)
env["GIT_AUTHOR_NAME"] = env["GIT_COMMITTER_NAME"] = "Real Person"
env["GIT_AUTHOR_EMAIL"] = env["GIT_COMMITTER_EMAIL"] = "real@example.test"
gitconfig = tmp_path / "home" / "gitconfig"
gitconfig.write_text("[user]\n\tname = Real Person\n\temail = real@example.test\n")
env["GIT_CONFIG_GLOBAL"] = str(gitconfig)
brain = tmp_path / "home" / ".agent"
remote = tmp_path / "remote.git"
subprocess.run(["git", "init", "-q", "--bare", "-b", "main", str(remote)], check=True)
Expand All @@ -102,5 +106,49 @@ def test_install_leaves_a_configured_git_identity_alone(tmp_path):
)

assert r.returncode == 0, r.stdout[-2000:] + r.stderr[-2000:]
assert _git(brain, "log", "-1", "--format=%ae") == "real@example.test"
assert _git(brain, "log", "-1", "--format=%ae", env_extra={"GIT_CONFIG_GLOBAL": str(gitconfig)}) == "real@example.test"
assert _git(brain, "config", "--local", "user.email") == ""


@pytest.mark.parametrize(
"env_identity, expected_email",
[
({"GIT_AUTHOR_NAME": "Env Person", "GIT_AUTHOR_EMAIL": "env@example.test",
"GIT_COMMITTER_NAME": "Env Person", "GIT_COMMITTER_EMAIL": "env@example.test"},
"env@example.test"),
({"EMAIL": "only@example.test"}, "only@example.test"),
],
ids=["GIT_*_EMAIL", "EMAIL-only"],
)
@pytest.mark.skipif(_find_py310() is None, reason="needs Python >= 3.10 on PATH")
def test_environment_only_identity_is_persisted_repo_locally(tmp_path, env_identity, expected_email):
"""Codex review pass 5: an identity that exists only in the installing
shell's environment (`EMAIL`, `GIT_AUTHOR_EMAIL`, ...) makes the seed
commit succeed and then vanishes — the hourly sync runs under launchd
with a minimal environment and dies with 'Author identity unknown'.
The installer must persist THAT identity into the brain's .git/config,
so history carries the user's address rather than a placeholder."""
env = _no_identity_env(tmp_path)
env.update(env_identity)
brain = tmp_path / "home" / ".agent"
remote = tmp_path / "remote.git"
subprocess.run(["git", "init", "-q", "--bare", "-b", "main", str(remote)], check=True)

r = subprocess.run(
[str(INSTALL_SH), "--yes", "--brain-root", str(brain),
"--brain-remote", f"file://{remote}"],
capture_output=True, text=True, env=env, stdin=subprocess.DEVNULL, timeout=180,
)

assert r.returncode == 0, r.stdout[-2000:] + r.stderr[-2000:]
assert _git(brain, "config", "--local", "user.email") == expected_email
assert _git(brain, "config", "--local", "user.name") != ""
assert _git(brain, "log", "-1", "--format=%ae") == expected_email
# And a later commit from a bare environment — what launchd gives sync.sh — works.
(brain / "later.md").write_text("later\n")
bare = {"HOME": str(tmp_path / "home"), "PATH": "/usr/bin:/bin",
"GIT_CONFIG_NOSYSTEM": "1", "GIT_CONFIG_GLOBAL": str(tmp_path / "home" / "no-such-gitconfig")}
subprocess.run(["git", "-C", str(brain), "add", "later.md"], check=True, env=bare)
c = subprocess.run(["git", "-C", str(brain), "commit", "-q", "-m", "later"],
capture_output=True, text=True, env=bare)
assert c.returncode == 0, c.stderr
20 changes: 20 additions & 0 deletions tests/test_install_recall_cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,23 @@ def test_missing_wrapper_still_installs_with_extras(fake_repo):
assert r.returncode == 0, r.stdout + r.stderr
assert "[embeddings,mcp]" in _pip_calls(fake_repo), _pip_calls(fake_repo)
assert fake_repo["wrapper"].exists()


def test_failed_regeneration_warns_and_still_symlinks(fake_repo):
"""Staff review follow-up 3, M1: regeneration needs the network (pip's
build isolation downloads hatchling). Offline, the pip call fails; under
`set -e` that used to exit the helper before its own warning and before
the ~/.local/bin symlink step. The helper must warn and fall through."""
fake_repo["wrapper"].write_text(OLD_WRAPPER)
fake_repo["wrapper"].chmod(0o755)
pip = fake_repo["repo"] / ".venv" / "bin" / "pip"
pip.write_text(f"#!/bin/sh\necho \"pip $*\" >> \"{fake_repo['calls']}\"\necho 'no network' >&2\nexit 1\n")
pip.chmod(0o755)

r = _run(fake_repo)

assert r.returncode == 0, r.stdout + r.stderr
assert "install" in _pip_calls(fake_repo), "regeneration was not even attempted"
assert "old entry point" in r.stderr, r.stderr
symlink = Path(fake_repo["env"]["HOME"]) / ".local" / "bin" / "recall"
assert symlink.is_symlink(), "the symlink step was skipped after the failed pip"
30 changes: 30 additions & 0 deletions tests/test_render_pending.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,36 @@ def test_sync_status_ignores_a_quoted_sync_line_inside_health_stderr(self, tmp_p

assert status == "ok", status

def test_sync_status_sees_a_blocked_marker_behind_a_trailing_sync_line(self, tmp_path: Path):
"""Staff review follow-up 3, M3 (pre-existing): the scan_gate-missing
path logs its marker and THEN a `sync: reinstall …` hint. Reading only
the run's last `sync:` line classified that run as ok, so
blocked-scanner was unreachable for it. Every line of the last run
counts, most recent first."""
rps = self._import()
tail = [
"2026-09-08T18:20:00Z sync: starting",
"2026-09-08T18:20:01Z sync: scan_gate.py missing at /x/tools/scan_gate.py; refusing to push",
"2026-09-08T18:20:01Z sync: reinstall with ./install.sh to restore the secret gate",
"2026-09-08T18:20:03Z health: wrote runtime/health.json",
]
(tmp_path / "sync.log").write_text("\n".join(tail) + "\n")

assert rps._check_sync_status(tmp_path, tail_lines=tail) == "blocked-scanner"

def test_sync_status_does_not_pick_up_the_previous_runs_block(self, tmp_path: Path):
rps = self._import()
tail = [
"2026-09-08T17:20:01Z sync: scan_gate.py missing at /x/tools/scan_gate.py; refusing to push",
"2026-09-08T17:20:01Z sync: reinstall with ./install.sh to restore the secret gate",
"2026-09-08T18:20:00Z sync: starting",
"2026-09-08T18:20:05Z sync: pushed",
"2026-09-08T18:20:06Z health: wrote runtime/health.json",
]
(tmp_path / "sync.log").write_text("\n".join(tail) + "\n")

assert rps._check_sync_status(tmp_path, tail_lines=tail) == "ok"

def test_remote_error_parsers_agree(self):
"""`recall.health._sync_log_remote_error` and this twin are read by
the same user on the same log. Pin them on one fixture so they can
Expand Down
Loading