fix: reload config fresh to prevent stale-snapshot profile loss#24
Merged
Conversation
In two places a config snapshot loaded at function start was being written back after a saveProfile() call had already done a fresh load+write in between, meaning the intervening write was clobbered. - buddies.ts (isDefault case): saveProfile(outgoing) writes fresh data, but savePetConfigV2(config) then overwrote it with the stale snapshot captured at the top of runBuddies. Fixed by reloading before the activeProfile→null update. - interactive.ts: the final profile identity update read configV2.profiles[result.salt] from a snapshot taken before the patch step; if that snapshot missed the newly saved profile the activate:true save was silently skipped. Fixed by reloading fresh. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Owner
|
@Co-Messi thank you for PR merged |
Co-Messi
added a commit
to Co-Messi/any-buddy
that referenced
this pull request
Apr 4, 2026
Hook install gaps (from code review of PR cpaczek#31): - apply.ts: hook was only installed in the ORIGINAL_SALT fallthrough path; the previousSalt and ORIGINAL_SALT early-return branches inside !oldSalt both returned before reaching it. Extract autoInstallHook() helper and call it before every successful-patch return. - apply.ts: --no-hook flag was silently dropped — runApply() had no noHook param so the flag was ignored. Add noHook param and pass it from cli.ts. - buddies.ts: runBuddies() patched the binary but never installed the hook. Stale-snapshot write (missed in PR cpaczek#24): - buddies.ts isDefault branch: config was the snapshot from the top of runBuddies(), read before saveProfile(outgoing) wrote to disk. Reload fresh immediately before savePetConfigV2 to avoid clobbering that write. - buddies.ts incoming profile read: after switchToProfile() writes to disk, reload fresh config to read the incoming profile rather than the stale pre-switch snapshot. preview.ts edge case (from code review of PR cpaczek#26): - cols - 4 can be negative when stdout.columns < 4 (piped output, very narrow TTY). String.repeat throws RangeError on negative values. Wrap with Math.max(0, cols - 4).
Co-Messi
added a commit
to Co-Messi/any-buddy
that referenced
this pull request
Apr 4, 2026
Hook install gaps (from code review of PR cpaczek#31): - apply.ts: hook was only installed in the ORIGINAL_SALT fallthrough path; the previousSalt and ORIGINAL_SALT early-return branches inside !oldSalt both returned before reaching it. Extract autoInstallHook() helper and call it before every successful-patch return. - apply.ts: --no-hook flag was silently dropped — runApply() had no noHook param so the flag was ignored. Add noHook param and pass it from cli.ts. - buddies.ts: runBuddies() patched the binary but never installed the hook. Stale-snapshot write (missed in PR cpaczek#24): - buddies.ts isDefault branch: config was the snapshot from the top of runBuddies(), read before saveProfile(outgoing) wrote to disk. Reload fresh immediately before savePetConfigV2 to avoid clobbering that write. - buddies.ts incoming profile read: after switchToProfile() writes to disk, reload fresh config to read the incoming profile rather than the stale pre-switch snapshot. preview.ts edge case (from code review of PR cpaczek#26): - cols - 4 can be negative when stdout.columns < 4 (piped output, very narrow TTY). String.repeat throws RangeError on negative values. Wrap with Math.max(0, cols - 4).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When generating multiple buddies, profiles created earlier could go missing from the saved-buddies gallery.
Two stale-snapshot writes were clobbering data that had already been written by a fresh
saveProfile()call:runBuddies—isDefaultcasesaveProfile(outgoing)performs a fresh load → write to snapshot the outgoing buddy's current name/personality.Then
savePetConfigV2(config)overwrites the file with the staleconfigcaptured at the very top ofrunBuddies(). Any profile data written by the interveningsaveProfilecall is silently lost.applyDesiredTraitsSequential— final identity updateThe code read
configV2.profiles[result.salt]from a snapshot loaded before the patch step. IfloadPetConfigV2()returnednullat that point (e.g. a transient read error) the fallback usedprofiles: {}, which then got saved, wiping all existing profiles. Even without the null case, the snapshot could be stale relative to whatsaveProfile()had just written.Fix
Both sites now reload the config fresh immediately before writing:
Test plan
any-buddy buddiespnpm test— all 203 tests pass