Skip to content

fix(editor): Shift Audio survives save/reopen — persist audio_shift through save, load, and build - #262

Merged
byrongamatos merged 3 commits into
mainfrom
fix/editor-audio-shift-persist
Jul 14, 2026
Merged

fix(editor): Shift Audio survives save/reopen — persist audio_shift through save, load, and build#262
byrongamatos merged 3 commits into
mainfrom
fix/editor-audio-shift-persist

Conversation

@ChrisBeWithYou

@ChrisBeWithYou ChrisBeWithYou commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What

A data-loss fix: the frontend has shipped audio_shift in every save body — and read data.audio_shift back on load — since Shift Audio landed (#236), but the backend silently dropped it. A user who carefully aligned a recording got it back misaligned on every reopen. (This was #236's explicitly deferred follow-up.)

  • New module-level _parse_audio_shift boundary helper with the repo's absent-vs-explicit contract: absent (older client) = leave the persisted value alone; zero = explicitly unshifted, REMOVES the manifest key (a shift slid back to 0 must not leave residue); garbage coerces to 0 rather than 400ing — the field is supplementary alignment state and must never cost the user their note edits.
  • _save_sloppak (in-place sloppak save) writes/removes audio_shift as a manifest extension key (feedpak §4 ignored-but-preserved — same pattern as origin); _write_sloppak_pak carries it via meta so Save As and create-mode builds persist it too; _load_sloppak surfaces it in the load payload with the same defensive coercion as the existing offset passthrough.
  • One frontend line: the create-mode /build body now ships audio_shift (the regular save body already did).
  • Scope note: persistence is sloppak-format (the ecosystem's format); an archive-format session picks it up when saved as a sloppak. Host-side consumption of the key (playing a shifted pack outside the editor) remains the core-repo follow-up flagged in feat(editor): Shift Audio — slide the recording in time (chart fixed, non-destructive) #236.

Tests

tests/test_audio_shift_persist.py (6, fail on main — the helper doesn't exist there): the absent-sentinel identity, explicit-zero spellings, negative shifts, string coercion, garbage-never-fails, and microsecond rounding. Full pytest 245+6 passed, JS suite green, lint 0 errors.

Live-verified end-to-end

On a real library pak (:8001 preview, new backend): Shift Audio +120 ms → Save → full page reload + reopen → S.audioShift = 0.12 restored; then shift back to 0 → Save → the manifest key is gone again (checked inside the zip). Zero page errors.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EBQCHCNA81E9tHmSDHSe2Q

Summary by CodeRabbit

  • Bug Fixes
    • Audio shift is now persisted into saved packs and restored on reopen, including plain saves, Save As, and first builds.
    • Setting audio shift back to zero removes the stored value, keeping songs byte-identical when unshifted.
    • Safer handling of missing/explicit values ensures old packs and older clients don’t wipe previously saved shifts.
  • Tests
    • Added end-to-end and unit coverage for audio-shift persistence, parsing, rounding, and non-finite/invalid input behavior.
  • Documentation
    • Updated the Unreleased changelog entry for the audio-shift persistence fix.
  • Chores
    • Repository node_modules entry updated to a symlink.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@byrongamatos, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b9b1a3dc-f9ce-4c3e-8b67-69de1eff531d

📥 Commits

Reviewing files that changed from the base of the PR and between 8f0ff49 and 88bef7a.

📒 Files selected for processing (3)
  • .gitignore
  • routes.py
  • tests/test_audio_shift_persist.py
📝 Walkthrough

Walkthrough

Audio shift state is parsed from requests, restored from sloppak manifests, sent by editor builds, and persisted across regular saves, Save As, and builds. Explicit zero removes the manifest value, while numeric values are rounded to six decimals.

Changes

Audio shift persistence

Layer / File(s) Summary
Parse and restore audio shift
routes.py, tests/test_audio_shift_persist.py
Request and manifest values distinguish absent fields from explicit zero, coerce invalid or non-finite values to 0.0, round to six decimals, and restore nonzero values on load.
Carry audio shift through editor builds
src/create.js, routes.py, tests/test_audio_shift_persist.py
Editor build requests include S.audioShift, and create-mode builds pass nonzero values into sloppak metadata.
Persist audio shift in sloppak saves
routes.py, tests/test_audio_shift_persist.py, CHANGELOG.md, node_modules
Regular saves, Save As, and sloppak writing add, update, or remove the manifest extension key; round-trip tests and changelog documentation cover the behavior, alongside the node_modules symlink update.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Editor
  participant routes.py
  participant _write_sloppak_pak
  participant SloppakManifest
  Editor->>routes.py: send audio_shift during save or build
  routes.py->>_write_sloppak_pak: pass parsed value in metadata
  _write_sloppak_pak->>SloppakManifest: write or remove audio_shift
  SloppakManifest-->>routes.py: provide audio_shift on load
  routes.py-->>Editor: restore audio_shift
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: persisting Shift Audio across save, load, and build flows.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/editor-audio-shift-persist

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@routes.py`:
- Around line 88-93: Preserve invalid audio-shift values instead of converting
them to zero: in routes.py:88-93, return the existing absent/invalid sentinel
for parse failures and non-finite values; in routes.py:4256-4266, remove the
manifest only for a genuine zero; in routes.py:3675-3685, validate, sanitize,
and round persisted manifest values before returning them; in
routes.py:7421-7430, reject non-finite metadata before writing; update
tests/test_audio_shift_persist.py:47-52 to verify malformed, NaN, and Infinity
inputs preserve existing state.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e4610cf7-748c-4121-a6d0-4e9964a1893a

📥 Commits

Reviewing files that changed from the base of the PR and between a866705 and 6e80809.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • routes.py
  • src/create.js
  • tests/test_audio_shift_persist.py

Comment thread routes.py Outdated
@byrongamatos
byrongamatos force-pushed the fix/editor-audio-shift-persist branch from 6e80809 to 8f0ff49 Compare July 14, 2026 17:44

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/test_audio_shift_persist.py (1)

77-84: 🗄️ Data Integrity & Integration | 🔵 Trivial | 🏗️ Heavy lift

Exercise the real persistence boundaries.

These tests round-trip a local dictionary and call _coerce_audio_shift/_apply_audio_shift directly; they do not invoke the production save, Save As, load, or /api/plugins/editor/build paths. A regression in that wiring could therefore pass the suite. Add request-level coverage that saves/reopens (including absent vs. zero) and builds a fresh sloppak, then asserts the actual manifest and loaded response.

Also applies to: 118-124, 127-136

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_audio_shift_persist.py` around lines 77 - 84, Extend the
audio-shift tests beyond the local _round_trip helper and direct
_coerce_audio_shift/_apply_audio_shift calls by exercising the production save,
Save As, reopen/load, and /api/plugins/editor/build request paths. Cover both
absent and zero audio_shift values, then verify the persisted manifest, loaded
response, and freshly built sloppak contain the expected values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@node_modules`:
- Line 1: Remove the tracked machine-local node_modules symlink, ensure
node_modules remains ignored, and rely on the project’s package manager and
lockfile to restore dependencies in other environments.

---

Nitpick comments:
In `@tests/test_audio_shift_persist.py`:
- Around line 77-84: Extend the audio-shift tests beyond the local _round_trip
helper and direct _coerce_audio_shift/_apply_audio_shift calls by exercising the
production save, Save As, reopen/load, and /api/plugins/editor/build request
paths. Cover both absent and zero audio_shift values, then verify the persisted
manifest, loaded response, and freshly built sloppak contain the expected
values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: eea26025-9881-422b-b083-a0443cb3fe19

📥 Commits

Reviewing files that changed from the base of the PR and between 6e80809 and 8f0ff49.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • node_modules
  • routes.py
  • src/create.js
  • tests/test_audio_shift_persist.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • CHANGELOG.md
  • src/create.js
  • routes.py

Comment thread node_modules Outdated
byrongamatos added a commit that referenced this pull request Jul 14, 2026
…k node_modules

Drains the CodeRabbit findings on #262.

The real one: at the request boundary a malformed `audio_shift` coerced to 0.0,
and zero is a COMMAND — _apply_audio_shift REMOVES the manifest key on zero. So
one garbage save body silently wiped alignment the charter had actually saved,
while an ABSENT field was safely preserved. Garbage was given more destructive
authority than silence, which is backwards.

_coerce_audio_shift now takes the invalid-value fallback as a parameter, keeping
the single shared coercion this branch deliberately consolidated:
  - sanitize paths (sloppak load, pack writer) keep the 0.0 default — a corrupt
    or absent STORED value is just an unshifted song; there is nothing to save.
  - _parse_audio_shift passes _FIELD_ABSENT — unusable INPUT touches nothing.
An explicitly falsy spelling (0/None/"") is still a genuine zero on every path,
so "slid back to 0 removes the key" is untouched.

The old test pinned the bug (it asserted garbage == 0.0); replaced with the
absent-shaped contract plus a regression test that fails with a KeyError on the
old code — the popped key IS the data loss.

Also: the tracked absolute node_modules symlink. The symptom is the committed
blob; the cause is that `node_modules/` (trailing slash) matches only
directories, so the worktree symlink was never ignored and `git add -A` swept it
in. Slash dropped, blob untracked.

Stale on this head, verified already fixed by 8f0ff49 and skipped: "sanitize
persisted manifest values on read" (load path already coerces) and "reject
non-finite before writing" (writer already coerces).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@byrongamatos

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

ChrisBeWithYou and others added 3 commits July 14, 2026 21:00
The frontend has shipped audio_shift on every save (and read it back on
load) since Shift Audio landed, but the backend dropped it — a shifted
recording reopened misaligned. New _parse_audio_shift boundary helper
(absent = leave persisted value; zero = remove the key; garbage coerces
to 0 rather than failing the save); _save_sloppak and _write_sloppak_pak
write the manifest extension key (feedpak §4), _load_sloppak surfaces it;
create-mode build body now ships the field too.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EBQCHCNA81E9tHmSDHSe2Q
…pies

The audio_shift float coercion was pasted three times (request body, sloppak
load, pack writer) and none of the copies guarded non-finite values.
`float("nan")` and `float("inf")` both SUCCEED and are truthy, so a garbage
value sailed past the nonzero write check and landed in manifest.yaml as
`.nan` / `.inf`, poisoning the pack for every reader. Reachable via a string
("nan") and via json.loads, which accepts bare NaN/Infinity.

Collapse all three into one `_coerce_audio_shift` (float + isfinite, 0.0 for
anything unusable) plus `_apply_audio_shift` for the write/remove/no-op
manifest rule, matching the isfinite guard the drum-hit save path already
uses. Net deletion, and the readers and writers can no longer drift apart.

Tests: the suite only exercised the parse helper in isolation, never the
write -> disk -> read path that actually broke. Add the save/load/build round
trip through yaml (the real disk boundary): a saved shift comes back
identical, zero removes the key, an older client omitting the field does not
wipe a persisted shift, and an old pack with no key loads as a clean 0.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…k node_modules

Drains the CodeRabbit findings on #262.

The real one: at the request boundary a malformed `audio_shift` coerced to 0.0,
and zero is a COMMAND — _apply_audio_shift REMOVES the manifest key on zero. So
one garbage save body silently wiped alignment the charter had actually saved,
while an ABSENT field was safely preserved. Garbage was given more destructive
authority than silence, which is backwards.

_coerce_audio_shift now takes the invalid-value fallback as a parameter, keeping
the single shared coercion this branch deliberately consolidated:
  - sanitize paths (sloppak load, pack writer) keep the 0.0 default — a corrupt
    or absent STORED value is just an unshifted song; there is nothing to save.
  - _parse_audio_shift passes _FIELD_ABSENT — unusable INPUT touches nothing.
An explicitly falsy spelling (0/None/"") is still a genuine zero on every path,
so "slid back to 0 removes the key" is untouched.

The old test pinned the bug (it asserted garbage == 0.0); replaced with the
absent-shaped contract plus a regression test that fails with a KeyError on the
old code — the popped key IS the data loss.

Also: the tracked absolute node_modules symlink. The symptom is the committed
blob; the cause is that `node_modules/` (trailing slash) matches only
directories, so the worktree symlink was never ignored and `git add -A` swept it
in. Slash dropped, blob untracked.

Stale on this head, verified already fixed by 8f0ff49 and skipped: "sanitize
persisted manifest values on read" (load path already coerces) and "reject
non-finite before writing" (writer already coerces).

Co-Authored-By: Claude Opus 4.8 (1M context) <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