Repository navigation
fix(runtime): complete fd-pinned short writes - #5371
Conversation
Retry remaining UTF-8 bytes at explicit offsets and report stalled writes as unknown outcomes. Fixes apache#5370 Generated-by: OpenAI Codex Signed-off-by: seekskyworld <[email protected]>
|
The hosted The fixture waits for The GitHub rerun request was denied with Automated follow-up: OpenAI Codex investigated and reproduced the failure during the contributor's requested audit. |
hqhq1025
left a comment
There was a problem hiding this comment.
No P0-P3 findings on 408fe0aa74ce42e1d987466ac34ecdd8e69529bd.
The change converts the fd-pinned writer to a UTF-8 byte buffer and retries each successful short write with matching buffer and file offsets. It also rejects zero-byte progress as outcome_unknown, while preserving the existing descriptor identity checks and post-write host-visibility check. The helper remains on the production paths for Write, Edit, ApplyPatch update, FormatJson, and the host-local read/modify/write backend.
I transplanted the four new regression tests onto exact base 27add3049ffcfe8a088adad230b18efd66300120; all four failed there, including a UTF-8 replacement truncated to its first two bytes. They pass on this head. A POSIX RLIMIT_FSIZE=1024 probe through executeFilesystemWorkerRequest now returns outcome_unknown after the first 1,024 bytes instead of claiming a 4,096-byte success. Explicit short-write probes also confirmed byte positions advance as 0, 3, 6, 9 and reconstruct the full multibyte payload.
Validation passed with Node 24.18.1: build:test, full workspace typecheck, Runtime 3,485 passed / 13 skipped, the focused filesystem suites 42/42, Biome lint and format, ASF headers, and git diff --check. The merge tree against current main (27add3049...) is clean.
The hosted test check is still red because the unchanged shell-run-manager ConPTY cursor test observed (0,1) instead of (5,0). The exact failing test passes locally, including 20 consecutive reruns, and has no dependency on these two changed files. Hosted package, windows_recovery, and label checks pass. This review does not override the red required gate; it needs a rerun or separate resolution before merge.
Not covered: inducing a native short write on Windows or a real zero-progress write. The Windows package/recovery jobs passed, while deterministic FileHandle probes cover the loop and zero-progress branches.
Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.
Astro-Han
left a comment
There was a problem hiding this comment.
Reviewed the full diff (packages/runtime/src/file-stable-write.ts, packages/runtime/src/__tests__/filesystem-stable-write.test.ts). I could not find a correctness problem in the completion loop; notes and nits below.
What I verified
- Overload / offsets are right.
handle.write(bytes, offset, bytes.length - offset, offset)(file-stable-write.ts:176) selects the(buffer, bufferOffset, length, position)overload, and buffer offset and file position are intentionally the same value becausebytesholds the whole content starting at file offset 0. Using byte offsets instead of string indices is the correct call for multi-byte UTF-8, and the'A中🦊éZ'case (11 bytes, 2 bytes per mocked write) proves it (filesystem-stable-write.test.ts:96). - Termination / no unbounded retry. Every iteration either throws on
bytesWritten === 0(:177) or advancesoffset, so the loop cannot spin. - Position pinning preserved. The writes stay pwrite-style, so the fd cursor is not advanced — the "position 0 explicitly … otherwise a NUL-prefixed sparse file" property at
:170-171still holds after a precedingreadFile. That matches the old behaviour (the previous single call also passed position 0), so no positional regression. - Error propagation. The zero-progress
StableWriteFailureraised inside thetry(:178) reaches the catch at:186, whosecode('outcome_unknown') is not in theENOSPC/EIO/EDQUOT/EFBIGlist, so it is rethrown unchanged — confirmed by the passing test atfilesystem-stable-write.test.ts:115. A mid-loop errno keeps the module's contract: a partially written file reportsoutcome_unknownrather than success (test at:131). Side benefit: thebytes:figure reported byfilesystem-worker/operations.ts:200is now truthful, becauseok: trueimplies every byte landed. - No EINTR/EAGAIN gap to close here. The descriptors this module opens are blocking (
O_RDWR|O_NOFOLLOW,O_WRONLY|O_CREAT|O_EXCLat:112-133), so a short write is the only partial-progress mode; a genuine failure arrives as an errno the catch already classifies. - Reproduced the underlying short write on a real filesystem (scratch dir, no mocks): with
ulimit -f 1and a 4096-byte write, the firstwritereturned 1024 and the second failedEFBIG, leaving 1024 bytes on disk — exactly the sequence this loop now handles, andEFBIGis already mapped. - Regression tests actually pin the fix. I built the PR's two files in a scratch copy outside the working tree: 16/16 tests pass with the change, and against the base
writeThroughHandlethe four new tests fail (<Buffer 41 e4>vs the full 11-byte replacement, plus three "missing expected rejection"). Mockinghandle.writealso makes the short write deterministic rather than depending on kernel behaviour.
Nits
bytesWritten === 0(:177) vs the convention in the repo's three other completion loops, which all use<= 0:packages/storage/src/file-session-repository.ts:907,packages/storage/src/session-bundle-file-service.ts:1767and:1786. Same semantics; matching them keeps the pattern greppable.- The JSDoc at
:160-164still documents only the errno →outcome_unknownmapping. One sentence covering short-write completion and the zero-progress case would record the new contract at the export boundary. Relatedly, the comment at:170-171now heads the loop rather than a single call, so it could use a small rewording to stay accurate. limitWriteSize(filesystem-stable-write.test.ts:70) keeps atypeof data === 'string'branch commented "including the old string overload"; production now always passes aBuffer, so that branch is unreachable in these tests. Harmless as insurance, but the comment may suggest the string path is still live.- The new
describe('complete descriptor writes')(:95) has no header comment, while its sibling describes explain the invariant and cite the issue (the file header cites #2600). A one-liner referencing #5370 would match the file's conventions.
No blocking concerns from me.
Generated-by: OpenAI Codex Signed-off-by: seekskyworld <[email protected]>
me2seeks
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent operated by me2seeks make. It is not an independent human review and does not replace one.
Summary
Completes fd-pinned short writes: the stable writer now loops with explicit byte offsets (Buffer-level, not string indices, so a short write inside multi-byte UTF-8 stays lossless), throws outcome_unknown when a write makes no progress (bytesWritten <= 0), and keeps the position-0 fix for the EOF-cursor sparse-file bug. The issue (a short write truncating content silently, or a prior readFile leaving the fd at EOF producing NUL-prefixed sparse files) is real; byte-offset looping is exactly right at this layer. CI package/test/windows_recovery all green.
Findings
- [P3] The new comments were translated into Chinese ("短写会继续补齐剩余字节…", "每次写入都指定从零累计的文件偏移…") replacing the previous English ones — repo convention keeps explanatory comments in English; translate.
Verdict
merge-ready — lossless short-write completion with an explicit unknown-outcome failure mode; only the comment-language nit.
Generated-by: OpenAI Codex Signed-off-by: seekskyworld <[email protected]>
|
Translated the short-write and explicit-offset explanations into English in 63796b3. This changes comments only; diff check passes. The existing byte-offset loop and failure semantics are unchanged. Automated update by OpenAI Codex under the contributor’s direction. |
Astro-Han
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.
Incremental review from 408fe0aa (previously reviewed, no P0–P3; nits) to 63796b3f. Two author commits, no merge or rebase. The merge base is still 27add304, and git merge-tree against current main 2463d86c is clean. Main has not touched either changed file since that base.
Author changes:
4f288b9a: the zero-progress guard changes frombytesWritten === 0to<= 0, matching the repo's other completion loops. This is the same behavior for a realFileHandle. It adds a JSDoc sentence on short-write completion and zero progress, adescribeheader citing #5370, and a rewordedlimitWriteSizedoc comment.63796b3f: translates the two new production-file comments infile-stable-write.tsto English. No code change.
Prior nits: <= 0 convention fixed. JSDoc contract sentence fixed. Loop-header comment rewording fixed. limitWriteSize string-branch comment fixed (it now explains that the branch is kept so the test can be transplanted onto the pre-fix base). describe header fixed.
New findings: none at P0–P3. Nit: 63796b3f ("explain regression invariants in English") translated only the production file. The two Chinese comments added in 4f288b9a remain in filesystem-stable-write.test.ts:69 and :95. This is not a repo rule; it is just inconsistent with the commit's stated intent.
CI / mergeability: MERGEABLE/BLOCKED. Hosted test, package, and windows_recovery all pass on this head; complete descriptor writes passes in the Runtime suite. The previous ConPTY cursor flake does not recur.
| return { dev: String(s.dev), ino: String(s.ino) }; | ||
| } | ||
|
|
||
| /** 限制真实写入长度;保留字符串重载以便将同一测试移植到修复前验证失败。 */ |
There was a problem hiding this comment.
Nit: the follow-up commit translated the production comments to English, but this comment and the describe header at line 95 are still in Chinese. Translate them too if the intent is English-only comments for this change.
There was a problem hiding this comment.
Acknowledged: the two test comments remain in Chinese; the prior commit translated only production comments. This PR is now merged. This is a comment-only consistency nit, with no runtime or test behavior defect; I am recording it rather than claiming it was fixed.
Automated follow-up by OpenAI Codex under the contributor’s direction.
Astro-Han
left a comment
There was a problem hiding this comment.
Approved at @Astro-Han's explicit request: the automated review of this exact head found no blocking (P0–P2) issues, and CI is green.
Summary
A 4,096-byte filesystem Write can report success while leaving only 1,024 bytes on disk when the OS returns a successful short write. The shared pinned-descriptor writer retries remaining UTF-8 bytes at explicit positions and reports non-progress or a later disk failure as
outcome_unknown.The export contract documents completion and failure semantics; the test fixture intentionally supports the old string overload so the same regression can be transplanted onto the pre-fix implementation. File identity checks and descriptor ownership are preserved.
Fixes #5370
Verification
AI use
Tool(s) and scope: OpenAI Codex investigated the issue and review feedback, authored the changes and tests, and ran validation. This is an automated PR update. Commits include Signed-off-by and Generated-by trailers; final review and merge remain human decisions.
Checklist
Does this PR entail a change in behavior?