Skip to content

Prove the conversion safety invariant per failure mode - #43

Merged
amrali-eg merged 1 commit into
masterfrom
feat/safety-invariant
Aug 26, 2026
Merged

Prove the conversion safety invariant per failure mode#43
amrali-eg merged 1 commit into
masterfrom
feat/safety-invariant

Conversation

@amrali-eg

Copy link
Copy Markdown
Owner

The engine already enforces the invariant — verification is unconditional, there is no flag to skip it, and AtomicReplace runs only after it succeeds. What was missing is evidence that it holds for every way a conversion can fail.

That gap matters here more than usual: the corpus audit found EC reporting success on files whose text had silently changed. The lesson wasn't "fix that decoder" — it was that a safety property nothing tests is a safety property nobody knows they still have.

Eight cases, each driving a different failure mode and asserting the same pair — refused, and the source byte-for-byte unchanged:

Failure mode Asserted
Invalid byte sequence refused, unchanged
Truncated multi-byte sequence refused, unchanged
Target cannot represent content refused, unchanged
Post-write verification failure refused, unchanged
Impossible BOM request refused, unchanged
Backup creation failure aborted before converting
-WhatIf nothing modified at all
A provably preserving conversion succeeds

The pairing is deliberate. A refusal that still damaged the file would be worse than no refusal, and counting "safe refusals" means nothing unless each is verified to have left the source alone. The last row exists so the invariant cannot be satisfied by refusing everything.

This is the measurable half of the reviewer's proposed fifth metric: safe refusal becomes a property with tests rather than a number without them.

320 tests passing (was 312).

🤖 Generated with Claude Code

The engine already enforces it: verification is unconditional, there is no flag
to skip it, and AtomicReplace runs only after it succeeds. What was missing is
evidence that it holds for every way a conversion can fail.

That gap matters here more than usual. An audit across four corpora found EC
reporting success on files whose text had silently changed, and the lesson was
not "fix that decoder" but "a safety property nothing tests is a safety property
nobody knows they still have".

Eight cases, each driving a different failure mode and asserting the same pair:
the conversion is refused, and the source file is byte-for-byte what it was.

  invalid byte sequence            refused, unchanged
  truncated multi-byte sequence    refused, unchanged
  target cannot represent content  refused, unchanged
  post-write verification failure  refused, unchanged
  impossible BOM request           refused, unchanged
  backup creation failure          aborted before converting
  -WhatIf                          nothing modified at all
  a provably preserving conversion succeeds

The pairing is the point. A refusal that still damaged the file would be worse
than no refusal, and counting safe refusals means nothing unless each is
verified to have left the source alone. The last case exists so the invariant
cannot be satisfied by refusing everything.

This is the measurable half of the reviewer's proposed fifth metric: safe
refusal is a property with tests rather than a number without them.

320 tests passing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@amrali-eg
amrali-eg merged commit 089ce0b into master Aug 26, 2026
1 check passed
@amrali-eg
amrali-eg deleted the feat/safety-invariant branch August 26, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant