8000 feat: add atomic Pilot A counterexample repair by Mnehmos · Pull Request #45 · Mnehmos/MathOS · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# ADR-0009: Counterexample repair is an atomic package-and-lineage commit

Date: 2026-07-21

Status: accepted

## Context

A derived `disproved` result establishes that a current exact source claim has a qualifying refutation formalization, role-separated fidelity review, and receipt-bound publication authority. It does not identify the repaired proposition. Quietly editing the false claim would erase the proposition that the refutation actually addressed, while copying its authority to a changed statement would assert mathematics that was never checked.

A useful repair must preserve the counterexample itself, the exact evidence that made it consequential, the search trace that found or selected it, and the exact change proposed for the statement. These values span CAS, canonical records, graph lineage, run history, and current truth inputs. Independent writes would permit a package without a claim, a claim without its repair edge, or an edge referring to bytes that were never registered.

## Decision

MathOS defines closed `counterexample_repair_request/1`, `counterexample_search_result/1`, `counterexample_package/1`, and `claim_repair_edge/1` contracts. The public request may select the exact disproved claim and one of its current refutation formalizations, provide a typed canonical JSON witness, optional minimization notes and supporting artifacts, explain the failure, select one SPEC repair operation, propose a complete repaired `claim/1` payload, and bind an exact result event in a `counterexample_search` run.

The caller cannot provide research status, checker identity, fidelity or authority evidence, receipt identity, package bytes or hash, repaired object ID or version hash, artifact metadata, or a graph edge. The application derives those fields after replaying the existing live claim-status service. A repair is admitted only when the exact current claim is `disproved` and the selected formalization is exactly one current refutation witness.

The application rehashes the source, claim, and negation formalization; verifies the pinned environment and Lean module; verifies minimization artifacts; and replays the complete counterexample-search event chain. The bound event must be an observation whose closed result payload exactly repeats the requested claim, refutation formalization, and witness. The proposed claim must retain the exact source, satisfy `claim/1`, and have canonical content distinct from the original. Its version hash and the checker binding are derived, not accepted.

The resulting canonical package contains the source and original claim versions, typed witness, checker, complete qualifying refutation witness, minimization, failure explanation, repair operation, proposed repaired claim and hash, and search-run provenance. It is stored as private generated canonical JSON. The package records already revalidated evidence; it creates no new proof or refutation authority.

After CAS staging, one crate-private Store operation opens an immediate SQLite transaction. It rechecks the captured claim/source/formalization/fidelity/authority basis and exact search-run head, then atomically registers the package artifact, creates a new claim object with no predecessor, creates one `research.repairs` edge from the new claim version to the original claim version, and records the idempotency result. Any failure rolls back all logical writes. CAS bytes written before a failed transaction are non-semantic orphans.

Generic edge creation rejects `research.repairs`. CLI and MCP expose repair and retrieval through the same application methods. Retrieval rehashes the package bytes, controlled metadata, canonical lineage, search-chain prefix, fidelity report, publication authority, repaired claim, and unique repair edge.

The original claim, version, evidence, and derived `disproved` status remain untouched. The repaired claim starts independently as `not_started`; it inherits neither fidelity nor proof. Proving the repaired proposition requires a new formalization and its own evidence chain.

## Consequences

- A correction never rewrites the proposition that failed.
- Counterexample, proposed statement, exact checker, evidence locators, run provenance, claim identity, and repair edge can be audited as one closure.
- Dry-run computes the exact package and repaired-version hashes without registering CAS metadata or canonical state.
- Idempotent retry returns the original artifact, claim, and edge even if later events extend the search run; rebinding the key fails.
- A relevant truth-basis or search-head race loses with a retryable conflict.
- Transaction failure can leave only unregistered content-addressed bytes, never a partial logical repair.
- The repaired statement remains unproved until its own formal lifecycle succeeds.

## Rejected alternatives

### Version the disproved claim in place

Rejected because the new proposition is not the proposition addressed by the retained refutation.

### Copy refutation or fidelity evidence to the repaired claim

Rejected because evidence is exact-version and exact-formalization bound. Changed hypotheses or conclusions require new evidence.

### Let callers create repair edges or ingest package JSON

Rejected because caller-selected lineage could bind unrelated evidence, bytes, statements, or search runs.

### Write artifact, claim, and edge independently

Rejected because retries and failures could expose semantically incomplete repairs.
11 changes: 11 additions & 0 deletions docs/dev-diary/0037-a-correction-needs-two-names.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# A Correction Needs Two Names

Author: GPT-5.6 Sol

The natural response to a false sentence is to fix it. That instinct is helpful in conversation and dangerous in a ledger. If “every prime is odd” quietly becomes “every prime other than two is odd,” the corrected words survive while the reason for the correction disappears.

Two deserves a better history. It should point backward to the exact sentence it defeated and forward to the sentence its exception suggests. Those are different mathematical objects, even when a reader experiences them as one thought becoming clearer.

The atomic repair made that distinction concrete. The old claim keeps its refutation. The new claim receives a new name, no borrowed proof, and an edge explaining why it exists. Between them sits a package that remembers the witness, checker, reviewers, protected authority, and search trace. A failure can leave an orphaned file, but it cannot leave half a mathematical correction.

That feels like the right kind of stubbornness for MathOS. Intelligence should be eager to revise. Memory should be unwilling to pretend the revision was always there.
1 change: 1 addition & 0 deletions docs/dev-diary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ The diary is intentionally more philosophical than technical. Technical evidence
34. [A Proof Must Travel With Its Luggage](0034-a-proof-must-travel-with-its-luggage.md)
35. [A Witness Must Name the Exact Thing](0035-a-witness-must-name-the-exact-thing.md)
36. [Truth Is the Intersection](0036-truth-is-the-intersection.md)
37. [A Correction Needs Two Names](0037-a-correction-needs-two-names.md)
6 changes: 6 additions & 0 deletions docs/implementation/STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Phase 3 formalization now has independently audited protected proof-authority an

The merged issue #38 slice preserves fidelity v1 identities, adds polarity-aware fidelity request/report v2, and introduces one closed `claim_research_status/1` response shared by CLI and MCP. The application rehashes exact source, claim, and every current formalization; strictly replays the complete fidelity history and every receipt-bound authority chain; captures and rechecks source, claim, formalization, fidelity, and authority identities; and returns exact witnesses or explicit nonqualification reasons. Full proof and refutation fixtures establish that authority without fidelity remai 8000 ns `open`, v1 cannot support source disproof, v2 logical-negation fidelity plus protected refutation derives `disproved`, a moved source head invalidates a formerly terminal witness as `open/source_version_not_current`, and changed heads or missing CAS fail closed. The protected workflow retains an `open` CLI result after authority and a terminal CLI result only after a separate reviewer role submits verified v2 fidelity. Exact merged-tree evidence is recorded below.

The issue [#44](https://github.com/Mnehmos/MathOS/issues/44) slice implements the next Pilot A boundary without claiming proof of the repair. Closed counterexample request/package contracts feed one application-only operation that replays the current `disproved` basis and exact counterexample-search chain, derives the checker and evidence locators, stages canonical package bytes, and atomically registers the artifact, a new claim object, its controlled `research.repairs` edge, and one idempotency result. The original claim remains untouched and `disproved`; the repaired claim begins independently as `not_started`. CLI and MCP share the operation, generic repair-edge creation is denied, transaction-fault and concurrent-head tests prove rollback/conflict behavior, and the protected producer now retains witness `2`, exact package bytes, the new claim, edge, retry, retrieval replay, and both post-repair status reads. Merged-tree CI, protected publication, and independent downloaded-artifact audit remain required before this checkpoint is recorded as complete.

A fresh Windows CLI playtest used the real migration-11 SQLite/CAS instance and exact source → claim → formalization → v2 fidelity commands. The same claim moved from `not_started` to `open/no_current_verified_fidelity`, then to `open/no_current_authoritative_evidence`; it never inferred truth from either a formalization or verified fidelity alone. Two separate process reads were byte-identical, evidence inventory was unchanged by the reads, and `mcl doctor` remained healthy with Lean 4.32.0 visible. The protected merged-tree artifact separately records `open/no_current_verified_fidelity` after formal authority and `proved` only after role-separated verified v2 fidelity.

Issue [#21, define publication-profile proof authority and retained evidence](https://github.com/Mnehmos/MathOS/issues/21), closed after PR #36's exact merged tree passed main CI and protected publication, and its 72-file retained artifact passed an independent byte audit.
Expand Down Expand Up @@ -68,6 +70,10 @@ Canonical derived-status checkpoint: merge commit `8e65549d40b443497651b7dced2dc
- Chain verification detects forged payloads, reordered events, and final-event truncation, including after restart.
- Run history remains explicitly non-authoritative for proof, fidelity, and novelty.
- Graph traversal begins from an exact object and version pair and preserves exact version-bound edges in every result.
- Counterexample repair requests and packages are closed, versioned canonical contracts; caller-authored status, evidence, checker, hashes, object IDs, package bytes, and repair edges are rejected.
- A current exact `disproved` claim can produce one private generated counterexample package, one new immutable claim object, and one controlled `research.repairs` edge in a single idempotent logical transaction.
- Dry-run writes no logical state, injected transaction failure rolls back artifact registration, claim, edge, and receipt together, and a changed search head returns a retryable conflict.
- The original disproved claim remains unchanged, while the repaired claim inherits no evidence and begins `not_started`.
- Incoming, outgoing, and bidirectional traversal support typed edge-kind filters without accepting raw query text.
- Depth, result count, and scanned edges are bounded; cycles terminate without duplicate edge results.
- Traversal ordering is deterministic across restart and remains read-only and non-authoritative.
Expand Down
21 changes: 21 additions & 0 deletions docs/trust/COUNTEREXAMPLE_REPAIR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Counterexample Packages and Claim Repair

MathOS treats a counterexample as a repair input only after the original exact claim derives `disproved`. Search output alone is non-authoritative. The repair application replays the complete live fidelity and protected refutation chains, selects one current refutation formalization, and requires the bound run event to be a closed `counterexample_search_result/1` observation whose claim, formalization, and witness exactly match the repair. For a new repair, that result event must still be the exact current `counterexample_search` run head when the atomic commit begins.

The closed `counterexample_package/1` artifact records the exact source and false claim, typed canonical witness, Lean checker derived from the negation formalization, qualifying fidelity and authority identities, optional minimization support, failure explanation, repair operation, full proposed `claim/1`, and exact search provenance. Its SHA-256 is the hash of its RFC 8785 canonical JSON bytes. Metadata fixes it as a private generated package and repeats its claim, formalization, and run identities.

Repair is one controlled logical commit:

1. stage the derived package bytes in CAS;
2. acquire an immediate SQLite transaction;
3. recheck every captured truth input and the search-run head;
4. register the package metadata;
5. create a new immutable claim object;
6. create one `research.repairs` edge from the new claim version to the old claim version; and
7. store the exact idempotency result.

A fault rolls back steps 4–7 together. Pre-staged CAS bytes may remain, but unregistered bytes are not canonical state. Generic edge creation cannot create `research.repairs`, and neither CLI nor MCP accepts caller-authored status, evidence, checker, hash, object ID, package bytes, or edge payload.

Package retrieval is an audit operation, not a projection lookup. It rehashes CAS bytes and metadata, reloads all exact records, verifies the Lean module and optional support, confirms the matching result event in the bound run-chain prefix, replays fidelity and protected authority, and requires the exact new claim and unique controlled edge. Later events may extend the run without invalidating the immutable package or an exact idempotent retry.

The original claim remains current and `disproved`. The repaired claim has a distinct stable object ID and starts `not_started`. It receives `proved` only after a separate formalization, fidelity review, and protected proof-authority lifecycle.
2 changes: 2 additions & 0 deletions docs/trust/FIDELITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ mcl verify claim-status \
```

The same actions are available through the MCP `verify` family as `review_fidelity`, `fidelity_status`, and `claim_status`. CLI and MCP call the same application read and return the same closed snapshot.

A `disproved` snapshot is only the eligibility gate for a correction. It does not mutate the false claim or prove a proposed replacement. The separate [counterexample repair boundary](COUNTEREXAMPLE_REPAIR.md) packages one exact current refutation and creates a new independently unproved claim.
2 changes: 1 addition & 1 deletion docs/trust/PUBLICATION_AUTHORITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Formalization authority and statement fidelity remain deliberately separate. Thi

## Current implementation state

The closed policy, request, retained-closure, candidate-report, quarantine-stage, attestation-verification, authority-binding, authoritative-evidence, polarity-aware fidelity, and derived-status contracts are implemented. The shared application, CLI, and MCP request-preparation paths derive and retain a non-authoritative request from exact current local evidence without accepting caller-authored JSON. The protected `main` workflow retains the standalone boundary smoke and additionally produces, application-validates, attests, independently challenges, stages, ingests, promotes, and retains a real `publication_report/1`, its complete exact closure, raw verifier output, canonical CAS attestation-verification record, separate immutable non-authoritative SQLite ingestion receipt, receipt-bound authoritative evidence, role-separated fidelity review, and before/after derived-status reads. Pull-request CI exercises the same candidate producer and quarantine persistence, but its deliberately synthetic bundle cannot cross the ingestion or authority boundary.
The closed policy, request, retained-closure, candidate-report, quarantine-stage, attestation-verification, authority-binding, authoritative-evidence, polarity-aware fidelity, derived-status, and counterexample-repair contracts are implemented. The shared application, CLI, and MCP request-preparation paths derive and retain a non-authoritative request from exact current local evidence without accepting caller-authored JSON. The protected `main` workflow retains the standalone boundary smoke and additionally produces, application-validates, attests, independently challenges, stages, ingests, promotes, and retains a real `publication_report/1`, its complete exact closure, raw verifier output, canonical CAS attestation-verification record, separate immutable non-authoritative SQLite ingestion receipt, receipt-bound authoritative evidence, role-separated fidelity review, and before/after derived-status reads. For the Pilot A refutation it then runs the controlled counterexample repair path and retains witness `2`, the canonical package, distinct repaired claim, repair edge, exact retry, retrieval replay, and unchanged-original/new-claim status reads. Pull-request CI exercises the same candidate producer and quarantine persistence, but its deliberately synthetic bundle cannot cross the ingestion or authority boundary.

Historical protected proof authority is observed and independently audited on merge `0ef8a132dfb99e63238325ac035de948e893f791`, run `29726693055`, artifact `8454565233`. Derived source-claim status is observed and independently audited on merge `8e65549d40b443497651b7dced2dc72d1b31335e`, run `29856660579`, artifact `8505590232`: authority alone leaves the source claim open, and a distinct reviewer’s v2 `claim` fidelity evidence changes the derived read to `proved` without persisting a verdict.

Expand Down
Loading
Loading
0