Skip to content

fix(cli): the audio caches never write or read through links in .hyperframes - #7825

Merged
michaelwang11394 merged 4 commits into
mainfrom
fix/cli-audio-cache-no-link-writes
Nov 15, 2026
Merged

michaelwang11394 merged 4 commits into
mainfrom
fix/cli-audio-cache-no-link-writes

Conversation

@michaelwang11394

Copy link
Copy Markdown
Contributor

What

The audio caches in a project's .hyperframes/ no longer write or read through links. This covers hyperframes audio --read (its entries, stems, voice-free mix and descriptions in .hyperframes/read-audio) and the film queries' kind cache in .hyperframes/audio-kind.

Why

A project can hold links that someone else planted, for example in a cloned repo or in files a tool wrote. Before this change, the cache writes followed them:

  • The cache entry and its text were written to <entry>.<pid>.tmp and then renamed, so a link at that temp name had its target overwritten.
  • ffmpeg wrote the voice-free mix with -y to no-vocals.wav.<pid>.tmp.wav, which had the same problem.
  • A downloaded stem was written to the file that a link at <name>.audio points to, and stems.json was written through a link at its name.
  • A described answer was written to <id>.txt.tmp, and a link at <id>.txt was read back as the answer.
  • mkdir -p accepted a link in place of .hyperframes, read-audio, stems/<hash>, describe or audio-kind, so every cache file landed in the folder the link points to.

So running the audio reader on such a project could overwrite or create files outside it.

Related work

None open. This follows the same rule as the history lock records in #7821: a link is replaced, never written through.

How

  • Each cache folder must be a real folder. A missing one is created. A link or a file in its place stops the write with "… is a link or a file, not a folder; remove it and run again". For stems and descriptions this becomes a warning, and the read goes on without them, as it does for any other stems or description failure.
  • Every cache file is written with replaceFileAtomically: an exclusive temp file with a random name, renamed into place. A link at the final name is replaced, not written through.
  • ffmpeg writes the mix into a fresh private folder from createStagingDir, and the result is renamed into place.
  • downloadToFile takes a new replaceLink: true option, which the stem downloads use. Without it, cloud get still writes through a link the user names, as before.
  • Cached entries, stem lists, stems and answers are used only when they are plain files, read with readPlainFile. A stem list may only name files in its own folder.

Nothing changes for a project without links. The cache stays where it was, and cached results are still reused.

Test plan

  • 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

New tests plant links before a read and check that every link target is unchanged:

  • read.test.ts: links at the entry's temp and final names; a link in place of .hyperframes and of read-audio; links at vocals.audio and stems.json during a stem download; a linked stems folder, and a stem list that names ../ paths; a link at the mix's old temp name.
  • describe.test.ts: cached answers replaced by links to an outside file, and a link in place of describe.
  • kindCache.test.ts: a link at an entry, and a link in place of audio-kind.
  • download.test.ts: replaceLink replaces an output link and does not copy the target's mode.

All 9 new tests fail on main and pass here. They are skipped on Windows, where making a link needs extra rights. npx vitest run src/audio src/cloud/download.test.ts in packages/cli passes (205 tests), and tsc --noEmit, oxlint, oxfmt, fallow and the comment ratchet are clean.

…rframes

The read-audio cache, its stems, mix and descriptions, and the audio-kind cache
now use only real folders under the project's .hyperframes. A link or a file in
place of a cache folder stops the write with a clear message. Every cache file is
written to an exclusive temp file with a random name and renamed into place, so a
link at a temp or final name is replaced, never written through. ffmpeg writes the
voice-free mix into a private staging folder. Stem downloads use the new
downloadToFile replaceLink option. Cached files are read only when they are plain
files, and a stem list may only name files in its own folder.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 5cd975b772450b2debf92b031a3c48c52280f166.

The writes reuse the shared atomic-file helpers, and the new planted-link regression tests exercise the real reader/download paths.

Important — incomplete cache-directory validation on reads: packages/cli/src/audio/analysis/kindCache.ts:75 validates the entry itself but does not validate its parent cache directories. A pre-existing directory link is still accepted on this read path, contrary to this change's stated scope. Apply the real-directory check to the complete cache directory chain before reading, and add regression coverage for .hyperframes and audio-kind. This is part of the targeted fix, despite also being present on the base.

Pre-existing follow-up: packages/cli/src/audio/read/describe.ts:170–186 does not anchor directory identity across awaited work. Stronger containment needs a separate design, such as private cache storage. The blocker above concerns static directory validation; concurrent directory replacement is a separate follow-up.

Validation: bun run build passed; gated CLI audio/download suite: 204 passed, 1 skipped. Restoring the five changed production files from the merge base made all nine new link cases fail. Separate local probes confirm the directory-read gap and the pre-existing asynchronous containment limitation. Windows junction behavior was inspected, not executed. Desktop release/pin and launcher validation remain outside this CLI patch.

Need: yes · Size: ok · Reuse: shared atomic-file and readPlainFile helpers · Simpler: already focused · Structure: fine (checked projectRecords and atomicFile; no split)
Risk: medium — filesystem writes run outside the agent sandbox.

— Rames Jusso (pr-review)

Verdict: REQUEST CHANGES
Reasoning: The static directory-link read path is still open in the cache this PR explicitly hardens. Validate those ancestors on reads and pin the behavior with a regression test.

readKindCache now checks that .hyperframes and audio-kind are real folders before
it reads an entry, as writeKindCache already does before it writes one.
The replaceLink test now reads the file's bytes and lstat result once each, so
no read follows a check on the same path.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 6945818d702e7e8c49499cb90f897cb62ec6c09f, delta from 5cd975b772450b2debf92b031a3c48c52280f166.

My earlier blocker is fixed: readKindCache checks both cache-directory levels before reading. The added regression has valid cached data behind each directory link and a successful ordinary-file control. The last commit changes only the download test's read/stat assertions; runtime code is unchanged by that commit.

Validation: full build passed; gated audio/download tests: 205 passed, 1 skipped, plus both original reviewer ancestor-link probes passed. Reverting the read guard makes the new committed case and both probes fail; restoring it passes all three. The previously noted concurrent-directory replacement limitation and Desktop release/pin/launcher integration remain separate follow-ups. No Windows host or packaged Desktop run was performed.

Need: yes · Size: ok · Reuse: existing isRealFolder helper · Simpler: already minimal · Structure: fine (checked makeRealFolder/readPlainFile; no split)
Risk: medium — filesystem access outside the agent sandbox.

— Rames Jusso (pr-review)

Verdict: APPROVE
Reasoning: Both static ancestor-link read cases from my change request are now refused, with effective regression coverage and a focused test-only final commit.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving at 24f23d7. The only change since my approval at 6945818d is a merge of main at bcf3d177 (the #7829 merge commit). All 10 PR files have byte-identical blobs and the same +/- counts against their merge bases before and after, so the PR's own code is unchanged, and main touched none of these files in between.

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 9701f06 Nov 15, 2026
71 checks passed
@michaelwang11394
michaelwang11394 deleted the fix/cli-audio-cache-no-link-writes branch November 15, 2026 17:49
daedal-ping Bot pushed a commit to DaedalGames/hyperframes that referenced this pull request Nov 15, 2026
* chore: release v0.9.54

* chore: release v0.9.54 notes include heygen-com#7827, heygen-com#7825, heygen-com#7845, heygen-com#7848 and heygen-com#7849

* chore: release v0.9.54 notes include heygen-com#7853

* chore: release v0.9.54 notes include heygen-com#7851 and heygen-com#7855
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