Skip to content

Remove hook registrations that run a retired memory script - #306

Merged
yourconscience merged 1 commit into
mainfrom
fix/memory-hook-leftovers
Nov 19, 2026
Merged

yourconscience merged 1 commit into
mainfrom
fix/memory-hook-leftovers

Conversation

@yourconscience

@yourconscience yourconscience commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

3.0 removes the unedited memory scripts under memory/hooks/ when no hook in tackroom.yaml runs 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 from tackroom.yaml outright (for example, replaced by rem-session-start) left its Pi and OMP modules and its Factory hooks.json entries 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-run reads the starter plan before inspecting harnesses, so the plan lists these removals.

Checked against a real config (m1), dry-run:

  • before: planned none, 8 starter files removed;
  • after: -2 hooks (droid) · -1 hooks (omp, pi), i.e. session-end.sh and session-start.sh for droid and session-start.sh for omp and pi.

Real sync in a sandbox HOME with copies of those files:

  • removes the three leftovers and backs each one up under ~/.local/state/tackroom/backups/;
  • leaves droid's hooks.json as valid JSON;
  • a second sync plans nothing;
  • with session-start.sh edited, the edited file and its registrations stay, and session-end.sh still goes.

The upgrade notes for 3.0 and docs/memory.md describe the cleanup.

Summary by Sourcery

Clean up harness registrations left behind when retired memory hooks and their scripts are removed.

Bug Fixes:

  • Remove stale harness hook registrations that still invoke retired or missing memory scripts, while preserving user-edited scripts and their registrations.

Enhancements:

  • Align sync dry-run planning with real sync so memory-script removals and dependent hook registrations are reported together and backed up consistently.

Documentation:

  • Document cleanup of leftover memory hook registrations during the 3.0 upgrade.

@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add an internal config field for detecting retired memory scripts in native hook registrations.

  • internal/app/app.go L43-47

Implementation

Identify memory scripts referenced by commands and treat native registrations as stale when their script was removed or is already missing.

  • internal/app/hooks.go L8, L61, L85-98
  • internal/app/starter_manifest.go L417-469

Compute retired scripts from the real and dry-run starter plans before hook inspection, so stale registrations are removed and previewed consistently.

  • internal/app/sync.go L272-279, L491-501, L521 (removed lines)

Documentation

Explain that obsolete harness registrations are backed up and removed alongside retired memory scripts, while registrations for edited scripts remain.

  • docs/memory.md L110
  • docs/upgrading.md L10

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f02e7731-6e63-4755-bbdb-ba6d55008cc4
Commits

Reviewing files that changed from the base of the PR and between 7e8ba28 and ff22056.

Files selected for processing: 6

  • docs/memory.md
  • docs/upgrading.md
  • internal/app/app.go
  • internal/app/hooks.go
  • internal/app/starter_manifest.go
  • internal/app/sync.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@sourcery-ai sourcery-ai 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.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread internal/app/sync.go Resolved
Comment thread internal/app/starter_manifest.go Resolved
Comment thread docs/upgrading.md Resolved
Comment thread internal/app/hooks.go Resolved
@yourconscience
yourconscience merged commit 6a193df into main Nov 19, 2026
11 checks passed
@yourconscience yourconscience mentioned this pull request Nov 19, 2026
2 tasks done
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