Skip to content

fix(media-use): audio scripts replace the file at a name and leave a link's target alone - #8830

Open
jrusso1020 wants to merge 7 commits into
mainfrom
fix/media-use-audio-link-safe-writes
Open

jrusso1020 wants to merge 7 commits into
mainfrom
fix/media-use-audio-link-safe-writes

Conversation

@jrusso1020

@jrusso1020 jrusso1020 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What

  • carve.mjs reads the composition only when it is a regular file, reached with no link below the folder the command runs in. A --comp that is a link, or sits behind a linked folder, stops with a message and nothing is read or written.
  • carve.mjs saves the composition as a new file renamed over the name. The file keeps its permissions, and a read-only composition is still not written.
  • lyria-recipe.py writes its WAV to a new temp file beside the output and renames it over the output name.
  • A save that fails now ends with a one-line message, not a stack trace.

Why

Both scripts opened the name they were given and followed whatever was there. With a link at that name, the link's target was read and changed, not the file in the project. The other writers in media-use already replace the file at the name (scripts/lib/link-safe-write.mjs); these two did not.

Fails without the fix: nine of the new tests fail when the read and the save follow links again, for example "saving the composition replaces a symbolic link at its name, never the target" and "lyria-recipe replaces a dangling symbolic link at the output name, never its target".

Related work

No issue. Same pattern as the existing link-safe-write.mjs users and extract-audio-data.py. A follow-up covers the MusicGen fallback writer.

How

  • Read: readRegularFile (one no-follow open, then the opened file is compared with the name) plus isPlainProjectPath for the folders between the working folder and the file. A composition outside the working folder is checked at its own name only.
  • Save: replaceFileWith, so the temp file gets the old file's mode before the rename. accessSync(W_OK) first, because a rename would otherwise replace a file the user made read-only.
  • Python: exclusive create (xb) of a temp file with the same name shape the other writers use, os.replace, retried on Windows while the file is held, and the temp file is removed on any failure.
  • skills-manifest.json regenerated; docs/reference/audio-effects.mdx says what --comp must be.

Behaviour changes to know about:

  • A project whose composition is itself a link, or sits behind a linked folder inside the project, is now refused by carve.mjs.
  • A hard link at the composition or WAV name is replaced by a separate file; the other name keeps the old content.

Test plan

  • node --test carve.test.mjs lyria-recipe.test.mjs media-input.test.mjs: 43 pass.

  • The nine link tests fail against the old read and save.

  • After review: a folder inside the project whose name begins with two dots (..drafts) is checked like any other project folder. The new case "a linked folder whose name begins with two dots stops the carve like any other" fails against the previous commit; carve.test.mjs is 35 pass.

  • After the second review: the save creates its new file readable by its owner only, fills it through the handle that created it, and gives it the composition's permissions before the rename. The new case "while the new file holds the composition and is not yet in place, only its owner can read it" fails against the previous commit; carve.test.mjs is 36 pass. The real carve.mjs run was not repeated for this change.

  • One real run: carve.mjs --comp index.html on two generated WAV files wrote the composition and kept its mode (640).

  • oxfmt --check, oxlint, gen-skills-manifest.ts --check, check-core-skills, check-skill-mirror: clean.

  • Not exercised: Windows (the permission test is skipped there; the link tests use a junction for the folder case), and a live Lyria call (the WAV writer is tested on its own).

  • Unit tests added/updated

  • Manual testing performed

  • Documentation updated (if applicable)

  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

Self-review: read the full diff after the last change; the six files are the only ones touched. Rollout: ships with the next skills release. Rollback: revert this commit.

Signed: Rames

🤖 Generated with Claude Code

…link's target alone

carve.mjs reads the composition only when it is a regular file reached
with no link below the working folder, and saves it as a new file renamed
over the name, keeping its permissions. A read-only composition is still
not written. lyria-recipe.py writes its WAV to a new temp file and renames
it over the output name.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mintlify

mintlify Bot commented Nov 25, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
hyperframes 🟢 Ready View Preview Nov 25, 2026, 8:29 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

@mintlify

mintlify Bot commented Nov 25, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
hyperframes 🟡 Building – Nov 25, 2026, 8:26 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

jrusso1020 and others added 2 commits November 25, 2026 08:40
…ne handle

The permissions test looked the file up by path twice. It now opens it once
and reads both from that handle.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed: Rames

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jrusso1020 jrusso1020 added the needs-jerrai-review Request a review from Jerrai. Removed after the review posts; re-add to request another. label Nov 25, 2026

@jerry-heygen jerry-heygen 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.

Changes requested at 6b8d2151. In readComposition, the containment check treats every relative path beginning with two dots as outside the project. A valid in-project directory whose name begins that way therefore skips the parent-link check entirely. Checking only the final file does not establish that its parent directories are confined to the project.

Use a path-component-aware containment check, distinguishing a parent-directory component from an ordinary name, and extend the regression to cover those names. The exact-head hosted lint and skills test jobs ran and passed. This is a static source finding, not a filesystem race reproduction or a Windows validation.

— Jerrai (pr-review)

@jerry-heygen jerry-heygen removed the needs-jerrai-review Request a review from Jerrai. Removed after the review posts; re-add to request another. label Nov 25, 2026
… as a project folder

readComposition decided whether a composition sits under the working
folder from the first two characters of its relative path. It now looks
at the first path part, so a folder named "..drafts" is checked for
links on the way like every other project folder.

Signed: Rames

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@jerry-heygen jerry-heygen 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.

Changes requested at 206dc039. The component-aware path check fixes the previous finding. The save still writes the composition to the temporary file before applying the original mode. For a private composition, the temporary copy can be more broadly readable than the original during the write, and an interruption before chmod can leave that copy behind.

Create the temporary file with owner-only permissions, write through the descriptor used to create it, and apply the final permissions before publishing. Add coverage that the temporary copy is private while it contains the composition. This is a source review; no filesystem race or live Windows test was run.

— Jerrai (pr-review)

… it has its permissions

The save wrote the composition into its temp file under default permissions
and set the composition's own permissions afterwards. The temp file is now
created readable by its owner only, filled through the handle that created it,
and given the final permissions before it is renamed into place. A save that
stops before the rename leaves no temp file behind.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@jerry-heygen jerry-heygen 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.

Changes requested at fd96b389. Carve now creates its temporary composition file privately and writes through the descriptor that created it. The WAV writer still regresses permissions: replacing an existing WAV publishes the temporary file’s default mode rather than preserving the original mode. On POSIX this can make a private WAV readable by other users, and it can replace a read-only WAV that the previous writer would have refused.

Create the WAV temporary file with owner-only access, preserve the mode of an existing regular output before publication, and retain the read-only refusal without following links at the output name. Add coverage for private and read-only regular outputs. This is a source review; I did not run Lyria or test Windows.

— Jerrai (pr-review)

…nd refuses one that may not be written

The new WAV is created readable by its owner only and gets its permissions
before it takes the output name: those of the file it replaces, or the
default for a new file. A WAV that may not be written is refused, as the
write in place refused it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jrusso1020

Copy link
Copy Markdown
Collaborator Author

Pushed b95d14ab for the review at fd96b389.

The music recipe's WAV write now:

  • creates its temporary file exclusively and readable by its owner only, until the file has its final permissions;
  • gives the new WAV the permissions of the regular file it replaces, or the default for a new file;
  • refuses a regular WAV that may not be written, before anything is created, as the write in place did. The check does not follow a link at the output name; a link there is still replaced, not followed.

Tests added for a private output (0600 stays 0600), a read-only output (refused, content and mode unchanged, nothing left beside it), and the temporary file's permissions before it gets its final ones. All three fail on the writer at fd96b389.

Writers in this diff: two. The carve's composition save has had these properties since fd96b389; the WAV write was the other. No other writers in the diff.

Not exercised: no real Lyria session, and Windows was not run.

Signed: Rames

@jerry-heygen jerry-heygen 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.

Approved at b95d14ab. The WAV writer now creates its temporary output exclusively with owner-only permissions, restores an existing regular output’s mode before publishing, and refuses a non-writable regular output. The new regressions cover private outputs, read-only refusal, and permissions during the write. A link at the final output name is still replaced rather than written through.

Hosted CI was still running at this cut. The mode tests are POSIX-specific; I did not independently run Windows or a live Lyria generation.

— Jerrai (pr-review)

@jrusso1020
jrusso1020 enabled auto-merge November 25, 2026 10:00
…h one handle

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch was successfully deployed

1 active (outdated) deployment
staging - docs — 79bc6d65 Deployed Nov 25, 2026 by mintlify[bot]
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.

3 participants