fix(skills): persist skill files with atomic replace - #77
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
skill_update opened the live .md with fopen("w"), truncating before
fwrite. Under ENOSPC/EFBIG the original skill was wiped (and stdio could
even report success after a partial flush). Write via temp+fsync+rename
so a failed PUT /api/skills/:name leaves the prior skill intact.
Co-authored-by: esadrianno <esadrianno@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug and impact
skill_update(authenticatedPUT /api/skills/:name) opened the live skill.mdwithfopen("w"), which truncates before any bytes are written. OnENOSPC/EFBIG/crash after truncate, the existing skill was wiped. With stdio buffering,fwritecould even report a full write whilefcloseflushed only a partial file — returning success after destroying the skill.Trigger: Dashboard or API updates an existing skill while the filesystem cannot complete the new write (disk full, or
RLIMIT_FSIZEin the regression test). The prior skill body is gone; agents that depend on that skill lose behavior.Distinct from open PR #71 (
auth_pairtoken store) — same truncate-then-write class, different file (skills/*.mdvia gateway skills CRUD).Root cause
In-place truncate-then-write with unchecked
fclose, same anti-pattern as #71 / config save (which already use temp+rename).Fix
Write skill content to
path.tmp,fsync, thenrenameover the live file. Used by bothskill_updateandskill_create.Validation
./build/test_skill— all tests passed, includingtest_skill_update_write_failure_preserves_existing(RLIMIT_FSIZE=8)As with return success