Repository navigation
fix(studio-server): opening a project no longer waits on its drive to answer a write - #8833
miguel-heygen wants to merge 6 commits into
Conversation
… answer a write The hf-id stamp pass and a project's first history id wrote the project with blocking calls on the host's own thread, so a drive that answered reads but not writes held that thread for as long as it stayed silent. The stamp pass now has one owner of its rules and two drivers; stampProjectHfIdsAsync makes every file call on fs/promises, and projectHistoryId makes its folder and id file on fs/promises.
|
On the pool-thread note: right, each write the drive never answers keeps one libuv pool thread (4 by default) for as long as the drive stays silent. A timeout on our side would only stop the caller waiting, which the async path already doesn't do; the thread stays inside the system call until the drive answers, so it would not free the pool. What would cap it is one stamp pass per project at a time, so reopening a project on a stuck drive joins the pass already waiting instead of starting another stuck write. I'll make that a follow-up if a stack shows other file work queueing behind stuck writes; this PR keeps the host's window answering, which is the freeze people hit. Head is now e6cd27f: the only change since fa6efcb removes two doc comments, because the comment-share check refused the added lines. |
Edit accuracy: accurate 273 (base branch 271), smooth 55 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) Unstable (1)
|
|
Size budget (6c09256): |
jrusso1020
left a comment
There was a problem hiding this comment.
Review at 6c092565: APPROVE. Since fa6efcb1 there are two changes and no code changes. Two doc-comment lines are removed. The @hyperframes/inspector packed budget goes from 933,584 to 952,400 bytes: Build measured 942,944 at e6cd27f0, because the inspector bundles core and now carries the async folder-write helpers. The reason is in the commit message ("fit the inspector size budget to core's async project folder writes"). A line in the PR body would satisfy the check's wording too. What follows was reviewed at fa6efcb1.
- Fails without the fix: I put the five changed source files back as they are on main, and both tests in
projectDriveWrites.test.tsfail. The timer fired 12,013 ms late during the stamp pass and 4,509 ms late during the first history id, which matches the body. At head, the stamp, history and safe-path tests pass: 452 tests, 3 runs in a row. - One rule owner: the stamp rules now live once in generator passes (
stampPass,hashAfterStamp,stampFile). The sync and async drivers only answer file steps. A driver error goes back in throughpass.throw, so each existingtry/catchstill decides the outcome: a bad record parses everything, an unreadable file returns null, and a failed replace warns and returns null. That matches main'sstampFileHfIds.stampProjectHfIdsandstampFileHfIdskeep their sync behavior. - Async path: every project write in
stampProjectHfIdsAsyncandprojectHistoryIdnow goes throughfs/promises: the no-follow open, the stat and read, the unchanged check, the temp-and-rename replace, and the mkdir. The read-only refusal,foldersToMakeandmadeOrThroware shared with the sync versions, not copied. historyId: this function already awaited its reads, so moving its two writes to async adds no new interleave. The history-root records stay synchronous, as the body says.
Not blockers:
- A drive that never answers a write now holds a libuv pool thread for each stuck call (4 threads by default). The stamp pass makes one call at a time, but after a few opens of projects on such a drive, the host's other
fs/promisesand crypto work would queue behind the stuck calls. The window still stays responsive, which is the fix. A later timeout or abort on these writes would bound it. walkDirandisLinkFreeWithinProjectstay synchronous. They only read, and this drive still answers reads, as the body says.
Need · Size · Reuse · Simpler · Structure: stops a project open from freezing the host's window · +396/−97, of which 120 are a new test · one set of rules with two drivers instead of duplicated sync and async stampers · the generator is the smallest way to keep one copy of the rules · fits the existing helpers.
Risk: low to medium. The sync path is unchanged in behavior. The async path is new and has only been tested against the stand-in drive, not a real network drive.
— Rames
|
Merged main and shortened one comment:
Against main, the diff is still the same eight files. |
jrusso1020
left a comment
There was a problem hiding this comment.
Review at a6c05362: request changes. The code is unchanged and still approve-ready. After the main merge, one required check is red because of the combined size.
Buildfailsverify:packed-manifests: "@hyperframes/cli unpacked size 26091227 bytes is over its budget of 25830000 by more than 1%." Main passesBuild(it is green at47e6307e, the main this merge brought in), and so did6c092565before the merge. The CLI bundlescoreandstudio-server, so this PR's async folder-write code plus main's growth since the last base takes it over. The fix is the same as for the inspector: raise@hyperframes/cli.unpackedinscripts/package-size-budgets.jsonwith the reason in the body.Test (runtime)also failed, on an unhandledReferenceError: window is not definedfromwebAudioTransport.test.ts(mediaProxy.ts:406isRenderMode) after teardown. This PR does not touch that path, and it is the same late-callback teardown problem as hf#8834. I'm treating it as a flake: a rerun should clear it, and it does not block.
I'll approve the next head once required CI is green.
Need · Size · Reuse · Simpler · Structure: unchanged.
Risk: low. Build budget only.
— Rames
|
Why: the CLI bundles studio-server, so this PR's async stamp pass and folder writes grow the CLI's chunks by about 3.7 KB (the largest, 453.40 → 456.07 KB). Main already sat just under the 1% line: built on main (22f268e), the CLI unpacks to 26,087,457 bytes against a 26,088,300 limit, 843 bytes of room. At this PR's head, CI measured 26,091,227, past it. The new value follows The size check on this branch, run locally: red ("@hyperframes/cli unpacked size 26091227 bytes is over its budget of 25830000 by more than 1%") with main's budget, green ("Verified 15 packages are within their size budgets.") with this one.
|
What
Opening a project no longer holds the host's thread when the project's drive answers reads but not writes. The hf-id stamp pass (
stampProjectHfIdsAsync) and a project's first history id (projectHistoryId) now write the project only throughfs/promises. A drive that stays silent holds a libuv pool thread, not the host's event loop.Why
Both wrote the project with blocking calls on the caller's thread.
replaceFileAtomicallyrunsaccessSync(W_OK), thenwriteFileSync,renameSyncand their siblings;mkdirWithinProjectrunsmkdirSync. A host that embeds Studio's server in its own main process (a desktop app) runs these during a project open. Its main thread then waited for as long as a network or cloud folder left a write unanswered, while the window stayed frozen. The stamp pass rewrites.hyperframes/hf-ids-stamped.jsonon every run, so every open reached this, not only the first.stampProjectHfIdsAsyncalready yielded to the event loop between files, but each file's open, read and write ran synchronously, so a silent drive still froze the host inside one file.Related work
None open on this path. A host that calls the synchronous
stampProjectHfIdson its main thread needs to move tostampProjectHfIdsAsyncto get this.How
helpers/hfIdPersist.ts: the stamping rules are written once, as a pass that yields the file work it needs (read, open for stamping, replace if unchanged, write the record, pause). A synchronous and an asynchronous driver answer those steps.stampProjectHfIdsandstampFileHfIdskeep the synchronous driver and behave as before.stampProjectHfIdsAsyncuses the asynchronous one, so every file call it makes is onfs/promises.core/atomicFile.ts:replaceFileAtomicallyAsync(already there) takes its read-only refusal from the same rule as the synchronous writer (readOnlyOrMissing), not from a copy.core/safePath.ts:mkdirWithinProjectAsync, thefs/promisestwin ofmkdirWithinProject. Both get their folder list and error rule from one place (foldersToMake,madeOrThrow).studio-server/helpers/safePath.ts:mkdirOwnedWithinProjectAsync; the link check stays synchronous (lstat, a read).history/historyId.ts:projectHistoryIdmakes.hyperframesand writeshistory-idwith the async twins.Not changed: the directory walk (
walkDir) and reads stay as they were;lstatandreaddirare reads, which the drive in question still answers. History records under the history root (the tool's own cache folder, not the project) keep their synchronous writes.One order to know about: a pass that is waiting on the drive can see a check (file unchanged) and its write separated by other work of the same process. The pass runs before a host serves or watches the project, as its doc says, so no in-process writer edits that project's files meanwhile. Writers in other processes could interleave before this change too.
Test plan
helpers/projectDriveWrites.test.tsstands in for a drive under the project that answers reads but never a write. It is patched onnode:fsitself and synced to every module's import. A blocking write call holds the calling thread for 1.5 s. Anfs/promiseswrite never settles. A 20 ms timer is set, then the call starts:stampProjectHfIdsAsyncon two compositions without ids.projectHistoryIdon a project with no.hyperframes.Each expects the timer on time (under 500 ms late) and the call still waiting on the drive.
fails without the fix: with the five changed source files as on main, both fail. The timer fired 11,987 ms late during the stamp pass and 4,487 ms late during the first history id. With the change, both pass (45 ms for the file).
hfIdPersist.yield.test.ts"lets the event loop run between files" asserted that at least one file was stamped by the firstsetImmediate. That held only while each file was stamped synchronously. It now reads "lets the event loop run before the pass is done": the timer must fire before all 40 files are stamped. A pass that ran synchronously still fails it.atomicFile,atomicFile.win32Pathsand the foursafePathtest files, 260 passed, 3 runs in a row.tsc --noEmitclean for core and studio-server; oxlint and oxfmt clean on the changed files.