fix(notes): the save guard keeps properties-only notes byte-exact #983

Closed
kayg wants to merge 0 commits from fix/properties-only-byte-exact into dev
Owner

The save guard treated a closing properties fence at EOF as broken and inserted a trailing newline. This caused #980's deterministic save/history fuzz failure at seed 21 step 76. Accept EOF as a closed fence, so properties-only notes keep their exact bytes with or without a final newline. A fence joined to body text still takes the existing repair path; unwrapped properties still refuse the save.

Scope and plan: one predicate change in frontmatter_guard.rs, with boundary tests and documentation. The 64 KiB accepted-block limit remains unchanged. Scanning is linear in the inspected text with O(1) scanning space, as before. No parser, editor, save ordering, repair edit, or refusal mutation changes.

condition effect detection recovery test
Valid EOF fence or empty body No guard edit Closed fence including EOF Save exact bytes LF/CRLF, BOM via file decoder, final newline/none, fence whitespace
Fence joined to body Insert only separator Existing saved-block prefix Existing small edit Full repaired text equals expected, including Unicode body
Unwrapped properties Refuse save Existing property-content check Retain last saved file Refusal and file-style bytes, existing room save test

Failing first on dev-01 via Nix and slot: EOF unit tests fail with None instead of a closed block; file-style regression returns Repair instead of Fine; existing review_fuzz_old_new_bytes_history_versions_and_restarts fails at seed 21 step 76 with one extra trailing newline. After the fix all 8 guard tests pass.

All requested gates passed on this head and its hotfix cherry-pick on dev-01 through Nix and slot: fmt check; full notes crate (dev 568 passed, hotfix 565 passed; each 6 ignored, zero failures; all 24 fuzz seeds included); workspace/all-targets clippy with warnings denied; editor vitest (526 passed on each). Exact commands, exit statuses, and full logs: #983 (comment).

The same source commit 40e64fcfe1d07121845fd8b37fdc6b38c86f978f was cherry-picked with -x and pushed to release/2026-11-06-hotfix as 71827028ca380248019edd2ddcc84fa1ecb33d05. Identical patch-id verified. No merge or deployment. Relates to #980 and follows merged #982.

The save guard treated a closing properties fence at EOF as broken and inserted a trailing newline. This caused #980's deterministic save/history fuzz failure at seed 21 step 76. Accept EOF as a closed fence, so properties-only notes keep their exact bytes with or without a final newline. A fence joined to body text still takes the existing repair path; unwrapped properties still refuse the save. Scope and plan: one predicate change in `frontmatter_guard.rs`, with boundary tests and documentation. The 64 KiB accepted-block limit remains unchanged. Scanning is linear in the inspected text with O(1) scanning space, as before. No parser, editor, save ordering, repair edit, or refusal mutation changes. | condition | effect | detection | recovery | test | | --- | --- | --- | --- | --- | | Valid EOF fence or empty body | No guard edit | Closed fence including EOF | Save exact bytes | LF/CRLF, BOM via file decoder, final newline/none, fence whitespace | | Fence joined to body | Insert only separator | Existing saved-block prefix | Existing small edit | Full repaired text equals expected, including Unicode body | | Unwrapped properties | Refuse save | Existing property-content check | Retain last saved file | Refusal and file-style bytes, existing room save test | Failing first on dev-01 via Nix and slot: EOF unit tests fail with None instead of a closed block; file-style regression returns Repair instead of Fine; existing `review_fuzz_old_new_bytes_history_versions_and_restarts` fails at seed 21 step 76 with one extra trailing newline. After the fix all 8 guard tests pass. All requested gates passed on this head and its hotfix cherry-pick on dev-01 through Nix and slot: fmt check; full notes crate (dev 568 passed, hotfix 565 passed; each 6 ignored, zero failures; all 24 fuzz seeds included); workspace/all-targets clippy with warnings denied; editor vitest (526 passed on each). Exact commands, exit statuses, and full logs: https://git.kayg.org/kayg/calternal/pulls/983#issuecomment-82009. The same source commit `40e64fcfe1d07121845fd8b37fdc6b38c86f978f` was cherry-picked with `-x` and pushed to `release/2026-11-06-hotfix` as `71827028ca380248019edd2ddcc84fa1ecb33d05`. Identical patch-id verified. No merge or deployment. Relates to #980 and follows merged #982.
fix(notes): keep properties-only saves byte-exact
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled
40e64fcfe1
Author
Owner

Regression fix is ready for gates: PR #983 (40e64fcfe1d07121845fd8b37fdc6b38c86f978f, based on dev db15794ac), cherry-picked with -x and pushed to release/2026-11-06-hotfix as 71827028ca380248019edd2ddcc84fa1ecb33d05. Both commits have identical patch-id b8965802d57c7701f9ed035ac86ed201490daadc. No merge or deployment.

Cause: the save guard copied the editor's requirement for a final line break. A valid closing fence at EOF failed that predicate, entered Repair, and gained a newline. The save guard now accepts EOF as a closed fence. Its existing repair/refusal paths remain unchanged.

Failing first on dev-01 with Nix and slot:

  • cargo test -j4 -p calternal-notes frontmatter_guard: EOF recognition tests failed (None instead of closed block).
  • cargo test -j4 -p calternal-notes file_styles_round_trip_through_the_guard: failed (Repair(Edit { at: 38, delete: 0, insert: "\n" }) instead of Fine).
  • cargo test -j4 -p calternal-notes review_fuzz_old_new_bytes_history_versions_and_restarts: reproduced seed 21 step 76, exactly one extra trailing newline.

After the fix, all 8 guard unit tests pass. The full four gates are running sequentially on both exact heads on dev-01; results will follow here and on #983. Editor runner found: cd packages/editor && bun run test (vitest run, config includes test/**/*.test.ts).

Regression fix is ready for gates: PR #983 (`40e64fcfe1d07121845fd8b37fdc6b38c86f978f`, based on dev `db15794ac`), cherry-picked with `-x` and pushed to `release/2026-11-06-hotfix` as `71827028ca380248019edd2ddcc84fa1ecb33d05`. Both commits have identical patch-id `b8965802d57c7701f9ed035ac86ed201490daadc`. No merge or deployment. Cause: the save guard copied the editor's requirement for a final line break. A valid closing fence at EOF failed that predicate, entered Repair, and gained a newline. The save guard now accepts EOF as a closed fence. Its existing repair/refusal paths remain unchanged. Failing first on dev-01 with Nix and slot: - `cargo test -j4 -p calternal-notes frontmatter_guard`: EOF recognition tests failed (`None` instead of closed block). - `cargo test -j4 -p calternal-notes file_styles_round_trip_through_the_guard`: failed (`Repair(Edit { at: 38, delete: 0, insert: "\n" })` instead of `Fine`). - `cargo test -j4 -p calternal-notes review_fuzz_old_new_bytes_history_versions_and_restarts`: reproduced seed 21 step 76, exactly one extra trailing newline. After the fix, all 8 guard unit tests pass. The full four gates are running sequentially on both exact heads on dev-01; results will follow here and on #983. Editor runner found: `cd packages/editor && bun run test` (`vitest run`, config includes `test/**/*.test.ts`).
Author
Owner

Both exact heads: all requested gates passed

  • Dev PR head: 40e64fcfe1d07121845fd8b37fdc6b38c86f978f (base db15794ac).
  • Pushed hotfix head: 71827028ca380248019edd2ddcc84fa1ecb33d05 (parent 3915d1518), cherry-picked with -x from the dev fix. Identical patch-id: b8965802d57c7701f9ed035ac86ed201490daadc.
gate dev PR head hotfix head
cargo fmt --check pass, exit 0 pass, exit 0
cargo test -j4 -p calternal-notes 568 passed, 6 ignored, 0 failed 565 passed, 6 ignored, 0 failed
cargo clippy -j4 --workspace --all-targets -- -D warnings pass, exit 0 pass, exit 0
editor bun run test 526 passed, 41 files, 0 failed 526 passed, 41 files, 0 failed

Both full notes runs include the unchanged review_fuzz_old_new_bytes_history_versions_and_restarts loop over all seeds 1–24. It passes on both heads. No test was weakened, filtered out of the full crate run, or newly ignored. The eight guard unit tests cover EOF with/without a final newline, an empty/blank body, CRLF, accepted BOM via file decode/encode, closing-fence whitespace, exact repair text, and refusal. The existing room save test also verifies that refusal leaves the disk file unchanged.

Commands ran on claude@calternal-dev-01-compute02.vpn.kayg.org, reached only through netbird ssh, in my own worktrees ~/Developer/Worktrees/guard-byte-exact-dev and ~/Developer/Worktrees/guard-byte-exact-hotfix. Each log starts with the exact tested SHA. After exporting PATH=/nix/var/nix/profiles/default/bin:$PATH and CARGO_TARGET_DIR=$HOME/Developer/Worktrees/guard-byte-exact-dev/target, each head ran:

TMPDIR="$PWD/.nix-tmp" nix develop -c bash -c '
  ~/bin/slot cargo fmt --check
  ~/bin/slot cargo test -j4 -p calternal-notes
  ~/bin/slot cargo clippy -j4 --workspace --all-targets -- -D warnings
  ~/bin/slot bun install --frozen-lockfile
  cd packages/editor
  ~/bin/slot bun run test
'

Each command's exit status was recorded separately and verified as 0, including frozen dependency installation. Editor's package script is vitest run, using packages/editor/vitest.config.ts and all test/**/*.test.ts.

Cause and decision: the save guard had inherited the editor's final-newline requirement. On a valid properties-only EOF fence, that incorrectly chose Repair and appended a newline. EOF now closes the fence for saving. A fence joined to body text still uses the existing single-separator repair; unwrapped properties still refuse the save. The parser's accepted-block byte limit remains unchanged. No merge or deployment was performed. Review remains pending.

Full logs are attached below (ANSI colour codes removed for readability).

## Both exact heads: all requested gates passed - Dev PR head: `40e64fcfe1d07121845fd8b37fdc6b38c86f978f` (base `db15794ac`). - Pushed hotfix head: `71827028ca380248019edd2ddcc84fa1ecb33d05` (parent `3915d1518`), cherry-picked with `-x` from the dev fix. Identical patch-id: `b8965802d57c7701f9ed035ac86ed201490daadc`. | gate | dev PR head | hotfix head | | --- | --- | --- | | `cargo fmt --check` | pass, exit 0 | pass, exit 0 | | `cargo test -j4 -p calternal-notes` | 568 passed, 6 ignored, 0 failed | 565 passed, 6 ignored, 0 failed | | `cargo clippy -j4 --workspace --all-targets -- -D warnings` | pass, exit 0 | pass, exit 0 | | editor `bun run test` | 526 passed, 41 files, 0 failed | 526 passed, 41 files, 0 failed | Both full notes runs include the unchanged `review_fuzz_old_new_bytes_history_versions_and_restarts` loop over all seeds 1–24. It passes on both heads. No test was weakened, filtered out of the full crate run, or newly ignored. The eight guard unit tests cover EOF with/without a final newline, an empty/blank body, CRLF, accepted BOM via file decode/encode, closing-fence whitespace, exact repair text, and refusal. The existing room save test also verifies that refusal leaves the disk file unchanged. Commands ran on `claude@calternal-dev-01-compute02.vpn.kayg.org`, reached only through `netbird ssh`, in my own worktrees `~/Developer/Worktrees/guard-byte-exact-dev` and `~/Developer/Worktrees/guard-byte-exact-hotfix`. Each log starts with the exact tested SHA. After exporting `PATH=/nix/var/nix/profiles/default/bin:$PATH` and `CARGO_TARGET_DIR=$HOME/Developer/Worktrees/guard-byte-exact-dev/target`, each head ran: ```bash TMPDIR="$PWD/.nix-tmp" nix develop -c bash -c ' ~/bin/slot cargo fmt --check ~/bin/slot cargo test -j4 -p calternal-notes ~/bin/slot cargo clippy -j4 --workspace --all-targets -- -D warnings ~/bin/slot bun install --frozen-lockfile cd packages/editor ~/bin/slot bun run test ' ``` Each command's exit status was recorded separately and verified as 0, including frozen dependency installation. Editor's package script is `vitest run`, using `packages/editor/vitest.config.ts` and all `test/**/*.test.ts`. Cause and decision: the save guard had inherited the editor's final-newline requirement. On a valid properties-only EOF fence, that incorrectly chose Repair and appended a newline. EOF now closes the fence for saving. A fence joined to body text still uses the existing single-separator repair; unwrapped properties still refuse the save. The parser's accepted-block byte limit remains unchanged. No merge or deployment was performed. Review remains pending. Full logs are attached below (ANSI colour codes removed for readability). - [guard-byte-exact-red.log](https://git.kayg.org/attachments/94b0c90a-5009-4211-bcfb-491d13169b8a) - [guard-byte-exact-dev-gates.log](https://git.kayg.org/attachments/81d04925-a5f5-48a5-be81-af8d9b3e8f7c) - [guard-byte-exact-hotfix-gates.log](https://git.kayg.org/attachments/920be2a9-c6ca-4d2b-9084-1507791b4748)
Author
Owner

Merged into dev by the orchestrator; same patch is on release/2026-11-06-hotfix.

Merged into dev by the orchestrator; same patch is on release/2026-11-06-hotfix.
kayg closed this pull request 2026-11-06 09:50:54 +00:00
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!983
No description provided.