Skip to content

Persist learned role-pitch maps; add singleton guard for re-launches#2

Open
wretcher207 wants to merge 1 commit into
mainfrom
fix/persist-rolemap-singleton-guard
Open

Persist learned role-pitch maps; add singleton guard for re-launches#2
wretcher207 wants to merge 1 commit into
mainfrom
fix/persist-rolemap-singleton-guard

Conversation

@wretcher207

Copy link
Copy Markdown
Owner

Summary

Two lifecycle fixes from internal review. Independent of #1 — both branch from main and can land in either order.

C3 — Learn from Selection now persists

Old code did table.insert(ROLE_MAP[active_role], pitch) in memory and never wrote it anywhere. Restart Reaper → the learned mapping is gone.

Fix:

  • save_settings now writes rolemap_<role> ExtState entries (comma-separated pitch list).
  • load_settings reads them and mutates the module-level ROLE_MAP as a documented side effect. Roles with no stored entry keep their built-in defaults, so future versions adding new roles aren't broken by old persisted state.
  • Learn from Selection auto-saves the moment a new pitch is added. The user does not have to remember to click Save Settings afterward.

C9 — Singleton guard against duplicate launches

run() called reaper.ImGui_CreateContext unconditionally. Re-firing the toolbar action while a previous instance was still running opened a second window with its own context.

Fix:

  • Heartbeat stamp via SetExtState(SCRIPT_ID, "instance_heartbeat", time_precise) at the top of every frame.
  • New launches check singleton_can_start() — if the last stamp is < 2s old, show a message and bail. If the previous run died (no heartbeat for 2s+), proceed.
  • reaper.atexit(singleton_release) clears the flag on normal script exit.
  • Added cached _ctx with ValidatePtr so a stale ref is replaced rather than appended to. Useful when the Lua state persists across script reloads; harmless when it doesn't.

Test plan

  • Open the script, click Learn from Selection on a role you haven't customized, then quit Reaper and reopen. The learned pitch should still be in the role.
  • Verify defaults: delete the ExtState rolemap_Kicks entry, launch the script. Kicks should be {35, 36} again.
  • Launch the script. While the window is open, fire the toolbar action a second time. A modal should say "DeHumanizer Pro is already running." instead of opening a duplicate.
  • Close the window. Wait 2 seconds. Launch again. It should open normally.
  • Force-kill the script mid-defer (no heartbeat). After 2 seconds, a fresh launch should succeed.
  • luac -p already verified on both file copies.

🤖 Generated with Claude Code

Two lifecycle fixes from internal review:

- Learn from Selection now sticks. Pitches added to ROLE_MAP were stored
  in-memory only, so any new mapping was lost on Reaper restart. ROLE_MAP
  is now persisted alongside the other settings, restored on load (side
  effect of load_settings), and auto-saved the moment Learn from Selection
  adds a new pitch — the user doesn't have to remember Save Settings.

- Singleton guard against duplicate launches. Each run() created a fresh
  ReaImGui context. Re-firing the toolbar action while the previous
  instance was still running opened a second window with its own context.
  A heartbeat ExtState is stamped each frame; a new launch only proceeds
  if the previous stamp is older than 2 seconds (i.e. the previous run
  died). atexit clears the flag on normal exit. Also added a cached _ctx
  with ValidatePtr so a stale ref is replaced rather than appended to.

Mirrored to Scripts/dehumanizer-pro.lua (ReaPack install target).
Syntax verified with luac.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@wretcher207, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 26 minutes and 21 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2d5e59e7-c3b7-4b4f-90e8-73cb169ca7ce

📥 Commits

Reviewing files that changed from the base of the PR and between 0f8aa62 and 6543b2c.

📒 Files selected for processing (2)
  • Scripts/dehumanizer-pro.lua
  • dehumanizer-pro.lua
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/persist-rolemap-singleton-guard

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

Comment @coderabbitai help to get the list of available commands and usage tips.

wretcher207 pushed a commit that referenced this pull request Jun 17, 2026
- MEMORY.md: repo conventions (dual-path ReaPack mirroring) + 2026-06-16
  session summary covering the three open fix PRs (#1 velocity parity,
  #2 lifecycle persistence, #3 per-note tempo).
- HANDOFF.md: next-chat resume point with verification checklist for the
  three PRs and gotchas (script mirrored at /dehumanizer-pro.lua and
  /Scripts/dehumanizer-pro.lua per ReaPack packaging).

No code changes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

2 participants