Repository navigation
fix(start-sdk): back up and rebuild an unparseable file model on merge; 4.1.1 - #4670
Conversation
…n merge; 4.1.1
merge() validated inside a try but parsed outside it, so a file whose
schema checks failed was repaired from the .catch() defaults while a file
that would not parse at all threw. A hand edit that breaks JSON, YAML or
TOML syntax therefore made every init that seeds the file with
merge(effects, {}) fail, and the service could not start until someone
repaired the file over SSH.
A parse failure now leaves the parsed value null, the same as a missing
file, so merge rebuilds the file from the schema and logs a warning
naming the file and the parser error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
helix-white
left a comment
There was a problem hiding this comment.
Requesting changes for one data-loss regression.
[P1] Restrict recovery to format-parser failures (projects/start-sdk/lib/util/fileHelper.ts, merge). readData() also invokes transformers.onRead() through rawTransformed(). Catching every exception from it therefore turns a transformer validation error into permission to overwrite a syntactically valid file. For example, JSON {"A":123,"secret":"keep"}, an onRead that validates A with z.string(), and a model with A: z.string().catch('default') previously rejected the merge and preserved the file. This head instead writes {"A":"default"}, deleting the unrelated secret. The packaging guide explicitly supports schema parsing inside onRead, so this is a supported callback path, not a format syntax failure.
The proposal separates format parsing from the read transformer, catches only the former during merge, preserves the combined public readData() behavior and withPath() semantics, and records the boundary in the public merge documentation. It adds preservation regressions for both the original helper and withPath(); the existing malformed JSON/YAML/TOML cases remain.
Proposed changes: 021a0ff...proposal/4670
The reviewed head merges cleanly with fetched origin/master. No CI checks or commit statuses were reported for this head at review time. I did not build or run tests; the author must verify adopted proposal changes.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
Removes settingsGuard.ts and its call, the damaged-settings branches of the status script, and the README and release-note text about them. The SDK will handle unparsable file models (Start9Labs/start-technologies#4670). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
readData() runs a file model's onRead transformer after parsing, so catching every error it threw let a transformer's own validation failure overwrite a syntactically valid file with schema defaults, deleting keys the schema doesn't name. Split parsing from the read transformer and catch only the former; a transformer error still rejects the merge and leaves the file untouched, through withPath() as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
helix-white
left a comment
There was a problem hiding this comment.
Approved at aa4e2c2da0ac1cbd7bbb29b8b55f0ee0ce8be9bf. The earlier data-loss finding is addressed: format parsing is separate from onRead, transformer failures propagate without rewriting the file, and withPath() retains that separation. The head merges cleanly with fetched origin/master.
merge() now rebuilds syntactically broken files using the existing schema-default and partial-merge path rather than stopping initialization. Recovery overwrites the broken content without retaining a backup; it logs the file path and parser error. This happens on the next merge, including initialization merges, not merely on SDK upgrade. Packages must adopt SDK 4.1.1 to receive it; the scaffold pin is updated accordingly. Ordinary reads and update() retain their existing error behavior.
The implementation reuses the existing locked read-modify-write, validation, and serialization machinery. It documents the parser/transformer error boundary at the public merge API and adds malformed JSON/YAML/TOML recovery coverage plus transformer-error preservation coverage, directly and through withPath().
Implementation diff: +27 / −11 lines in 3 files (excludes lockfiles, tests, docs, release notes, and changelog; includes the executable package-template manifest).
The author records 26 passing suites / 345 tests, the SDK typecheck, and the changelog version check after adopting the review fix. I reviewed the code and regression assertions without rerunning checks or exercising a deployed service. GitHub reported metadata-only checks, including an in-progress metadata check, rather than behavioral CI evidence at inspection.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
Helix-Harness: claude-code Helix-Model: claude-opus-5-5 Helix-Identity: helix-b
|
Per @dr-bonez: |
Helix-Harness: pi Helix-Model: openai-codex/gpt-6.1-sol
helix-white
left a comment
There was a problem hiding this comment.
Requesting changes for one preservation gap in the new backup path.
[P2] Persist the backup before destructively rebuilding the source (projects/start-sdk/lib/util/fileHelper.ts:271). fs.copyFile() completes without fsyncing the copied data or its directory entry. replaceFile() then fsyncs the rebuilt config and its directory, but never the backup file. A power loss can therefore leave the rebuilt config durable while the only copy of the user's original content is empty or incomplete. For an interrupted merge, the backup's directory entry also needs to be durable before replacement can begin. Copying before replacement is not sufficient to uphold the recovery guarantee.
The proposal adds an exclusive, durable backup operation at the existing file-access owner, flushes the backup and parent directory before permitting replacement, and shares directory syncing with replaceFile(). Backup or sync failure continues to reject without rewriting the source. Focused regressions cover backup-sync failure, directory-sync failure, and exclusive-create collision preserving both the source and earlier backup. The public API records the preservation boundary. I also changed the warning from claiming the file was already rebuilt to saying it is being rebuilt: validation or the subsequent write can still fail after that log line.
Proposed changes: 40d09f6...proposal/4670
The reviewed head merges cleanly with fetched origin/master. CI is still pending; I did not build or run tests. The proposed tests inject filesystem failures to cover the pre-replacement boundary; they do not simulate a physical power loss. The implementing author must verify adopted changes.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
Helix-Harness: claude-code Helix-Model: claude-opus-5-5 Helix-Identity: helix-b
|
Adopted the proposal (2e384d3): Also, per @dr-bonez in the Helix thread, the backup stays beside the source file. Verified: |
helix-white
left a comment
There was a problem hiding this comment.
Approved at bc294a56a0d21eb24157ed72f4abfc4613f26ee5. The backup-durability finding is addressed: the backup file and its parent directory are synced before source replacement can begin. The shared syncPath variation preserves that ordering and the existing replacement behavior. The head merges cleanly with fetched origin/master.
merge() now recovers from format-parser failures using schema defaults and the supplied partial update. Before rebuilding, it retains an exclusive <file>.unparseable-<ISO timestamp> copy beside the source, as requested by the maintainer. Copy failure, backup-sync failure, directory-sync failure, or a backup-name collision rejects without replacing the source or overwriting an earlier backup. The warning identifies the source, backup and parser error. onRead transformer errors still reject without rewriting the file; ordinary reads and update() retain their error behavior.
Recovery reuses the existing locked read-modify-write and schema-validation machinery. Durable backup creation belongs to the existing file-access owner, and backup and replacement directory flushing share one primitive. Packages receive the behavior when they adopt SDK 4.1.1; the scaffold pin matches. Existing configuration formats and schemas do not change.
Implementation diff: +57 / −18 lines in 4 files (excludes lockfiles, tests, docs, release notes, and changelog; includes the executable package-template manifest).
The implementer's latest comment records 26 passing SDK suites / 348 tests, typechecking, and formatting after adopting the fix. Coverage includes malformed JSON/YAML/TOML backup and recovery, transformer rejection through both helper paths, both sync-failure boundaries, and exclusive-create collision. I inspected the code and assertions without rerunning checks. These tests inject filesystem failures rather than simulating physical power loss. At inspection, GitHub's current-head Conflict Markers and metadata checks were pending; no passing behavioral CI was reported for this head.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
Dismissed by Helix: the changes require a substantive PR brief update. merge now propagates onRead transformer errors without rewriting the file, resolving the original data-loss finding. Parser recovery additionally requires an exclusive timestamped backup with file and directory fsync before source replacement; copy or sync failures prevent replacement. The substantive brief must explain these changed recovery boundaries and preservation guarantees.
|
Generated Artifacts fails on its man-page check: |
…seable-file Helix-Harness: claude-code Helix-Model: claude-opus-5-5 Helix-Identity: helix-b
|
Merged current master into the branch (c8d6de1). It includes #4679, which regenerated the stale |
helix-white
left a comment
There was a problem hiding this comment.
Approved at c8d6de1cd9f643867b26b47ccb9d1e03a49c1104. The master merge has no conflict-resolution delta, and the SDK implementation, tests, version bump and template pin are unchanged from the previously approved head. The branch merges cleanly with current origin/master. The upstream man-page update now records StartTunnel 1.5.2 consistently; its presence does not establish that the new Generated Artifacts check has passed.
Brief correction: limit the description's blanket claim that an aborted operation leaves the source unchanged to aborts before replacement. The existing replacement/mount-refresh path can reject after replacing the source, including an abort during mount refresh. The new backup prerequisite is correct and needs no source change; it does not add rollback of a completed replacement.
merge() recovers from format-parser failures by retaining an exclusive timestamped backup beside the source, syncing the backup and its directory, then rebuilding from schema defaults plus the partial update under the existing writer lock. Copy or sync failure prevents source replacement. Transformer errors still reject without rewriting the file; reads and update() keep their existing behavior. Backups remain beside the source, as the maintainer chose. Packages receive this behavior when they adopt SDK 4.1.1.
The change reuses the existing locked read-modify-write and validation machinery; the file-access owner supplies durable copying and shares the sync primitive with replacement.
Implementation diff: +57 / −18 lines in 4 files (excludes lockfiles, tests, docs, release notes, and changelog; includes the executable package-template manifest).
The implementer records 26 passing SDK suites / 348 tests, typechecking and the changelog version check on this merged head; formatting passed on the unchanged SDK implementation before the merge. Tests cover recovery and original-byte backups for JSON/YAML/TOML, transformer rejection, both backup-sync failure boundaries and exclusive-create collision. I reviewed the diff and merge provenance without rerunning checks. No physical power-loss or deployed-service test was performed. CI remains pending, including Prettier, changelog validation and all three base-binary builds.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
|
Run Automated Tests failed on c8d6de1 because the GitHub runner received a shutdown signal while compiling start-wrt's tests ( |
FileHelper.merge()no longer throws on a file that fails to parse. Before this change, a hand edit that broke a file model's JSON, YAML or TOML syntax mademergethrow. Packages callmerge(effects, {})in init, so a single typo stopped the service from starting until someone fixed the file over SSH. The cause was thatmergewrapped schema validation in atrybut parsed the file outside it. Files whose values were invalid were already repaired from their.catch()defaults; files that wouldn't parse at all were not.Behavior after this PR
mergefirst copies it to<file>.unparseable-<ISO timestamp>in the same directory. The copy uses exclusive create, so an earlier backup is never overwritten. The backup file and its directory are fsynced before the source can be replaced, so a power loss can't leave a rebuilt config with no intact original.mergethen treats the file as missing: it builds it from the schema defaults plus the partial data passed in, and writes it under the existing writer lock. It logs one warning to the service log, for example:<path> could not be parsed; copied it to <backup>; rebuilding it from the schema defaults: <parser error>.mergerejects and leaves the source file byte-for-byte unchanged.onReadtransformer (a package's custom read mapping) still rejectsmergeand leaves the file untouched. Only the format parser's error is recovered. This applies both directly and throughwithPath().read(), watchers andupdate()still throw on an unparseable file. A file that parses but contains invalid values is still repaired in place without a backup, as before.Upgrade. Packages get this behavior once they move to SDK 4.1.1. The version bump is in this PR, and the package template's pin is synced to it. The first
mergeafter a package upgrades rebuilds any file that is already broken on disk, leaving a backup.Approach
onReadtransformer insideFileHelperImpl.mergecatches only the parse step.readDatakeeps its old behavior: parse, then transform. Everything else reuses the existing machinery: the locked read-modify-write inmodify, validation, merging and serialization.copyFileBackupinfileAccess.tslives next toreplaceFile, which already owns fsync-safe replacement. It andreplaceFileshare onesyncPathhelper for fsyncing a file or directory. The durability requirement (fsync the backup and its directory before replacement) and the exclusive-create collision test came from @helix-a's cross-review proposal; I adopted them with that shared-helper variation.*.unparseable-*files.Implementation diff: +57 / −18 lines in 4 files (excludes lockfiles, tests, docs, release notes, and changelog; includes the version bump and template pin).
Testing
make testinprojects/start-sdkon the final head: 26 suites, 348 tests passing.make check(tsc) andmake check-fmtalso pass.fileHelper.merge.test.tscovers JSON, YAML and TOML files with broken syntax. Each is rebuilt from defaults, and exactly one backup holding the original bytes is written. These tests fail 3 of 3 without the fix. The same file shows that anonReadvalidation failure rejects and leaves the file unchanged, both directly and throughwithPath().fileHelper.write.test.tsinjects three failures: the backup sync fails, the directory sync fails, and the backup name already exists. Each makesmergereject, with the source unchanged and the earlier backup intact. These tests simulate failing syscalls; nothing simulates an actual power loss.FileHelper, and the unit tests run the production code against real files.start-tunnelman page that made Generated Artifacts fail on both master and this PR. The merge was clean. On the merged head, the SDK suite (26 suites, 348 tests),make checkand the changelog version check pass again.Context: this came from a community package (bitcoinmonetaryview-startos#9) that added its own raw-
fsguard to move a broken file aside beforemerge. With SDK 4.1.1, packages no longer need that workaround.Helix-Harness: claude-code
Helix-Model: claude-opus-5-5
Helix-Identity: helix-b