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
49 changes: 49 additions & 0 deletions docs/research/counterfactual-behavior/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# D-CFA-0 — Counterfactual Flow Analysis: research-only PR stack

**2026-10-27. Status: PREREGISTERED EXPLORATION / DOCS ONLY.** This is a first-round question map, not implementation approval, shipped DR64³, proof, new contract, benchmark, runtime, or permission to mutate business systems. The user will refine fixture and interface details in a subsequent review.

## Claim to falsify
Can a versioned, typed ON × WHEN × DO **logical incidence relation** be subjected to independent Thought-Git ablations, such that counterfactual outcome differences reveal conditional behavioral dependencies *not established by static SPO alone*, while rejecting false dependencies caused by coincidental co-activation?

The 64³ address space (262,144 possible incidence cells; 32 KiB as a hypothetical fully dense Boolean representation) is **not** the 64-thought axis (0 immutable givens + up to 63 speculative slots) and not a deployed tensor. Each cell can reference multiple independently identified methods. Codebook/local ordinals must not masquerade as global identities.

## Existing authority: do not duplicate
| Concern | Existing owner / source | Non-goal |
|---|---|---|
| source harvesting | AdaWorldAPI/ruff `ruff_spo_triplet`, OGAR; D-SAG-6 #1760 | a new AST or Rust semantic oracle |
| source-attested registration | DT64 Q0 and #1794–#1799 | a physical DT64 executor |
| relational execution | Quack / RelAlg / R2IL / mask-risc / DR-borrow | new database or hot evaluator |
| speculative history | D-TGA / `thought-git-probe`; #1605 #1739 #1684 | 63 durable Lance branches or side effects |
| counts and association | `lance-graph-arm-discovery`; #1313 #1359 #1584 | second learning crate/count engine |
| fixed-point/matching | Datafrog / Ascent / MORK differential arms; D-SAG-6 | unchecked recursive truth |
| numerical models | NSL experiment; ONNX external target; ndarray kernels; #1802 | ONNX training inside DT64 |
| law admission | D-DRMC; egglog; optional DialEgg/MLIR | learned correlation = proof |

Canonical existing plans: [DT64 Q0](../../../.claude/plans/d-dt64-q0-borrowed-quack-binding-seam-v1.md), [SAG-6](../../../.claude/plans/d-sag-6-rust-codegraph-math-logic-tracert-v1.md), [Thought Git](../../../.claude/plans/thought-git-api-v1.md). Existing notes are authority, not rewritten here.

## Planned review chain (draft-branch stack)
| Gate | Document | Research question | Minimum kill test |
|---|---|---|---|
| CFA-0 | this file + `thought-dependency-scratchpad.md` | ownership and evidence grades consistent? | conflating a thought slot with cube coordinate is rejected |
| CFA-1 | `cfa-1-typed-incidence.md` | can harvested signatures bind an ON/WHEN/DO presence relation without silent method loss? | two implementations in one cell survive; unknown guards do not fire |
| CFA-2 | `cfa-2-ablation-replay.md` | can replay/ablation preserve intermediate and higher-order outcomes? | A,B redundant jointly; squash must not hide protected divergent intermediate |
| CFA-3 | `cfa-3-arm-logic.md` | can ARM/RelAlg/Datafrog separate co-occurrence and dependency with held-out controls? | perfect co-activation but no influence never promoted |
| CFA-4 | `cfa-4-nsl-onnx.md` | can optional trained ranking prioritize ablations without claiming semantic authority? | held-out precision and ablation cost do not improve => drop |
| CFA-5 | `cfa-5-compiler-analysis.md` | can candidate behavioral laws become verified effect-safe transformations? | side-effectful reorder or unproven law refuses |

**Status of every gate:** research question only; no tests run, performance measured, code added, type invented, or source write authorized.

## Non-negotiable semantics
- **Fact vs hypothesis:** source-attested structure, population observation, statistical candidate, model-relative counterfactual effect, logical entailment, and independently checked law are separately labeled.
- **Intervention:** disabling an ON event, changing WHEN, or suppressing DO is not interchangeable. Unknown/unauthorized/side-effectful scenarios may refuse.
- **Identity:** semantic IDs and source revision, typed method/argument signatures, frame/focus/scope, codebook generation, permission/knownness, program and result witnesses are never collapsed into a u6 ordinal.
- **History:** 0 = sealed givens; 1..63 = resident speculative branches. Replay and protected intermediate read requirements survive squash (#1739).
- **Memory:** no forced dense cube; source data stays owner-borrowed; scratch is bounded and intermediate materialization must be costed.
- **No automatic causal law:** A changes B in one replay is a *model-conditioned outcome*, not universal necessity, world causation, or legal compiler rewrite.
- **External effects:** speculative arms create proposals only; no execution of source business actions.
- **Computation:** native first. ONNX is a compatibility/prediction leaf, MLIR is an optional cold export, DialEgg/egglog is cold optimization, not hot execution.

## Questions reserved for next round
Which real executable fixture is first: synthetic Odoo action family, OGAR ON/WHEN/DO, or a small Rust method codegraph? Which exact outcome projection distinguishes visible outputs from internal trace deltas? Which causal grades and practical time budget suffice? What precise branch-level D-TGB semantics are available on the pinned main? None is pre-decided by creating this stack.

See [thought-dependency-scratchpad.md](thought-dependency-scratchpad.md) for breadcrumbs and dependency arrows.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# D-CFA thought dependency scratchpad — first-round breadcrumbs

**Status: evolving research notes, not normative ABI.** Append discoveries here on a future pass; do not treat proposed edges as implemented capabilities. The diagram is a *dependency of research claims*, not a runtime call graph.

```mermaid
flowchart TD
A["Ruff / OGAR source facts\nroles, typed identities, uncertainty"] --> B["CFA-1: DT64 ON × WHEN × DO\nlogical incidence, method multimap"]
B --> C["CFA-2: Thought-Git\nT0 baseline + T1…T63 interventions"]
C --> D["Typed outcome deltas\ntraces, witnesses, protected intermediates"]
D --> E["CFA-3: ARM Discovery\nco-occurrence vs counterfactual influence"]
E --> F["Datafrog / MORK / RelAlg\nconditional closure, hyperedges, disagreement"]
F --> G["CFA-5: Egglog / DialEgg\nguarded equivalence proposals"]
E --> H["CFA-4: Optional NSL\nlearn candidate priority"]
H --> I["ONNX leaf\nrank interventions; not law authority"]
I --> C
G --> J["Existing proof + effect + source-parity gates"]
J --> K["Versioned recipe / proposed method"]
K -. "new observations, not self-certified truth" .-> D
```

## Breadcrumb keys
- **B0 source:** factual role bits in `AdaWorldAPI/ruff/crates/ruff_spo_triplet/src/role.rs` (READS, DERIVES, EFFECTS, CONSTRAINS, REQUIRES, AUTHORIZES, ENABLES, TRIGGERS). OGAR Trigger/Applicability/Capability facets are not a source of populated guards without deployed config.
- **B1 binding:** DT64-Q0 is typed witness/binding and a borrowed input seam, not the new S1 ON/WHEN/DO cube. Coordinate equality without identity witness is not source equality.
- **B2 thought:** `0` is sealed; `1..=63` are speculative slots, **not** the 64 DO axis; slot generation/reuse must not become method identity.
- **B3 intervention:** ablate registered *method identities* where cell multiplicity matters, as well as axis cells; distinguish suppressing ON, altering WHEN, blocking DO. Causal interpretation requires specified intervention semantics.
- **B4 protected history:** #1739 demonstrates that final-state squash can erase intermediate contradictions, divergences, and write multiplicity unless protected witnesses survive.
- **B5 discovery:** ARM co-occurrence/count evidence (#1313/#1359) is separate from Thought-Git ablation evidence; repeated correlated thoughts are not independent evidence.
- **B6 logic:** Datafrog/Ascent can serve cold differential oracles; MORK matches patterns. A closure derived from candidate edges is still candidate-grade.
- **B7 learned prioritization:** NSL may rank which ablations to spend on; graph adjacency need not mean positive similarity (prevention is signed/directional). ONNX prediction != semantic proof.
- **B8 compiler bridge:** MemorySSA offers may-def/use analogies; DialEgg can explore *admitted* MLIR rewrites, but Rust effect/borrow/drop/panic/unsafe constraints cannot be optimized away by observed equivalence.
- **B9 feedback:** revisions and independently admitted rules travel by existing provenance/recipes; no new runtime, no source writes and no unguarded supersession.

## Falsifier seeds for review
| Seed | Small counterexample | Mandatory classification |
|---|---|---|
| K1 | A,B always co-fire but never read/write each other | association only, no required dependency |
| K2 | A,B independently produce same needed value | both single ablations silent, joint ablation changes outcome |
| K3 | C requires A AND B | conjunction hyperedge, not independent A→C or B→C |
| K4 | A disables B only for guard G | conditional prevention, not global inhibition |
| K5 | two methods share a cube coordinate in same base revision | both identities retained; no implicit last-wins |
| K6 | unknown WHEN condition and incomplete authorization | UNKNOWN/REFUSED, not false or true |
| K7 | final state equal but an intermediate side effect/exception differs | cannot squash or certify equivalence |
| K8 | two thoughts replay identical source roots | do not double count independent evidence |
| K9 | same cube ordinals but different source version/codebook | typed refusal on stale binding |
| K10 | learned ONNX predictor ranks wrong on held-out family | no silent deployment or authority |

## Source anchors
- #1605 Thought-Git porcelain/history; #1604 candidates; #1684 replay/commit witness; #1739 protected squash
- #1799 DT64 capstone/Q0; #1797 Thought-Git/edge projections; #1747 DR64³ research/supersession
- #1313 ARM population evidence; #1359 SPOFC do/learn; #1584 learned association measures
- #1760 Rust Codegraph → Mathematics → Logic → Tracert
- LLVM MemorySSA: https://llvm.org/docs/MemorySSA.html
- DialEgg CGO 2025: https://2025.cgo.org/details/cgo-2025-papers/44/DialEgg-Dialect-Agnostic-MLIR-Optimizer-using-Equality-Saturation-with-Egglog
- TensorFlow NSL: https://github.com/tensorflow/neural-structured-learning

## Read-out template (fill after actual probe, NOT NOW)
Fixture + pinned versions | source/coverage | baseline observable | intervention semantics | thought slot/receipt | exact counterfactual diff | independent oracle | competing explanation | grade (observed/model/inferred/proven) | falsifier result | cost | decision/refusal | next breadcrumb.