Repository navigation
Remove hook registrations that run a retired memory script - #306
Conversation
Reviewer's GuideData structuresAdd an internal config field for detecting retired memory scripts in native hook registrations.
ImplementationIdentify memory scripts referenced by commands and treat native registrations as stale when their script was removed or is already missing.
Compute retired scripts from the real and dry-run starter plans before hook inspection, so stale registrations are removed and previewed consistently.
DocumentationExplain that obsolete harness registrations are backed up and removed alongside retired memory scripts, while registrations for edited scripts remain.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 53 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="internal/app/sync.go" line_range="273" />
<code_context>
}
- starterChanges, err := reconcileStarterFiles(repoRoot, streams, opts.ConfirmRemovals, memoryHooksInUse(cfg, repoRoot, home))
+ keepMemory := memoryHooksInUse(cfg, repoRoot, home)
+ starterChanges, err := reconcileStarterFiles(repoRoot, streams, opts.ConfirmRemovals, keepMemory)
if err != nil {
return err
</code_context>
<issue_to_address>
**Retired scripts leave active hooks behind**
When a harness has a blocking conflict, an unreadable config, or hook backup fails during sync, `reconcileStarterFiles` removes the scripts before `inspectAgents` and `applyAgentHookSync` can remove and back up their registrations; `runSync` skips or returns on those failures, leaving registrations pointed at missing scripts.
Defer removing retired scripts until the related harness registrations have been successfully reconciled, and keep the scripts when reconciliation cannot proceed.
</issue_to_address>
### Comment 2
<location path="internal/app/starter_manifest.go" line_range="428" />
<code_context>
+// in ~/.agents) that command runs, or "".
+func memoryScript(command string, root string, home string) string {
+ dirs := []string{filepath.Join(root, "memory", "hooks"), filepath.Join(home, ".agents", "memory", "hooks")}
+ for _, field := range strings.Fields(command) {
+ field = strings.Trim(field, `"'`)
+ for _, prefix := range []string{"$HOME/", "${HOME}/"} {
</code_context>
<issue_to_address>
**Hook registrations are misclassified**
When a command invokes a retired script through a shell payload containing spaces or merely mentions a memory-script path as an argument, `memoryScript` splits commands with `strings.Fields`, so it misses script paths inside quoted shell payloads and treats unrelated argument paths as executed scripts; `retiredMemoryScripts` then leaves stale registrations or removes unrelated hooks.
Parse commands to identify the script actually executed while preserving shell payloads and ignoring paths that appear only as arguments.
Also at `internal/app/starter_manifest.go:461`.
</issue_to_address>
### Comment 3
<location path="docs/upgrading.md" line_range="10" />
<code_context>
+- What an existing config keeps: its memory hooks stay in `tackroom.yaml` and sync as ordinary hooks. While a hook entry points at a script under `memory/hooks/`, enabled or not, every file under `memory/` stays, and the first sync stops tracking them in `.tackroom-starter.json` with one note; after that they are yours to delete. With no such hook entry at that first sync, it removes the scripts you never edited and lists the ones you did once. Any sync then also removes a hook registration in a harness's own config that still runs a removed or missing memory script, such as a Pi or OMP module or a Factory `hooks.json` entry left from a memory hook you deleted from `tackroom.yaml`; it backs each one up first, as for any removed hook. `memory/tools/`, built `rem` and `knowledge-sync` binaries and `memsearch.conf` are left alone. Details are in [memory.md](memory.md#coming-from-the-bundled-memory).
</code_context>
<issue_to_address>
**Setup removal is understated**
When a user relies on the setup description while setup retires memory scripts, the upgrade note says setup does not remove memory hooks from harness configs, but setup follows the sync path, which now removes stale registrations for memory scripts retired by that run. Users are told setup preserves registrations that it can delete.
Clarify the setup statement that setup can remove stale harness registrations when it retires memory scripts.
</issue_to_address>
### Comment 4
<location path="internal/app/hooks.go" line_range="58" />
<code_context>
off = append(off, hook)
}
}
</code_context>
<issue_to_address>
**Stale-hook comment omits new removals**
`staleHooksForAgent` now also returns undeclared registrations that run retired memory scripts, but its comment says every command the config does not declare stays. The comment therefore misstates the function’s behavior for callers and maintainers.
Update the function comment to describe both disabled configured hooks and retired memory-script registrations.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and if a registration is mistakenly classified as stale, sync removes it from the harness config, so that hook stops running; the registration is backed up and can be restored, but reverting the code alone will not put it back.
Blocking findings: internal/app/sync.go:273, internal/app/starter_manifest.go:428
3.0 removes the unedited memory scripts under
memory/hooks/when no hook intackroom.yamlruns one. Registrations in a harness's own config that still run those scripts stayed behind, because sync only removes registrations of hooks the config still declares and has turned off. A memory hook deleted fromtackroom.yamloutright (for example, replaced byrem-session-start) left its Pi and OMP modules and its Factoryhooks.jsonentries pointing at scripts that no longer exist.Now, when no configured hook runs a memory script, sync treats a registration as stale if it runs a memory script that this sync removes or that is already missing. It removes the registration the same way as any stale hook, backup first. A script the user edited stays, and the registrations that run it stay too.
sync --dry-runreads the starter plan before inspecting harnesses, so the plan lists these removals.Checked against a real config (m1), dry-run:
planned none, 8 starter files removed;-2 hooks (droid) · -1 hooks (omp, pi), i.e.session-end.shandsession-start.shfor droid andsession-start.shfor omp and pi.Real sync in a sandbox HOME with copies of those files:
~/.local/state/tackroom/backups/;hooks.jsonas valid JSON;session-start.shedited, the edited file and its registrations stay, andsession-end.shstill goes.The upgrade notes for 3.0 and
docs/memory.mddescribe the cleanup.Summary by Sourcery
Clean up harness registrations left behind when retired memory hooks and their scripts are removed.
Bug Fixes:
Enhancements:
Documentation: