Skip to content

refactor: unify Braid around one ProgramGraph with CFG/DAG projections - #98

Merged
srinji-kaggss merged 6 commits into
mainfrom
refactor/unified-program-graph
Sep 3, 2026
Merged

srinji-kaggss merged 6 commits into
mainfrom
refactor/unified-program-graph

Conversation

@srinji-kaggss

Copy link
Copy Markdown
Owner

Summary

This PR begins a major architectural reset for Braid around one semantic graph kernel instead of maintaining separate intra-capsule and inter-capsule graph authorities.

Today Braid has:

  • braid-ir::Braid / Strand for intra-capsule DAGs;
  • braid-flow-ir::FlowSpec / FlowNode / FlowEdge for orchestration;
  • planner code that reconstructs predecessor topology from Flow edges + Choice arms;
  • runtime code that independently walks Strand indices;
  • separate verifier families around the sibling models.

That duplication is the core source of architectural drift.

Candidate architecture

This PR introduces braid-ir::ProgramGraph as the migration kernel:

  • stable NodeId identity;
  • explicit GraphNode / GraphNodeKind;
  • explicit typed GraphEdge::{Data, Control};
  • deterministic cfg() projection;
  • deterministic dag() projection;
  • fail-closed checks for duplicate nodes/edges, missing endpoints, self edges, CFG cycles, and data cycles.

CFG answers where control may flow.
DAG answers which data dependencies constrain execution.

Resource/effect conflict edges are deliberately deferred until the shared access vocabulary is ratified; this PR does not pretend parallel execution is safe yet.

Documents added

  • spec/braid/CANDIDATE-ARCHITECTURE.md
  • spec/braid/PRD-UNIFIED-GRAPH.md
  • spec/braid/PLAN-UNIFIED-GRAPH.md

These are one architecture, one PRD, and one migration plan—not parallel proposals.

Code added

  • crates/braid-ir/src/graph.rs
  • exports from braid-ir/src/lib.rs

The graph kernel is intentionally in braid-ir so planners, verifiers, runtimes, renderers, and adapters converge toward one semantic owner.

Explicitly not done in this PR

This is M0+M1 only.

Not claimed:

  • no conversion of existing Braid or FlowSpec yet;
  • no verifier convergence yet;
  • no planner/runtime migration yet;
  • no resource-access scheduling yet;
  • no new ProgramGraph canonical wire;
  • no change to existing Capsule/Flow bytes or CIDs;
  • no parallel execution claim;
  • no deletion of legacy graph types.

Next migration order

  1. Braid → ProgramGraph adapter + differential tests.
  2. FlowSpec → ProgramGraph adapter with Choice targets emitted as explicit CFG edges.
  3. Converge verifier structural checks onto ProgramGraph.
  4. Delete planner predecessor reconstruction and consume CFG/DAG directly.
  5. Move runtime ordering to DAG projection.
  6. Add resource-qualified read/write/append contracts + effect receipts.
  7. Only then define a versioned ProgramGraph wire and retire duplicate graph authorities.

Evidence state

  • Planned: full convergence described in PLAN-UNIFIED-GRAPH.md.
  • Present in code: ProgramGraph kernel + deterministic CFG/DAG projections + local unit tests in the new module.
  • Exercised on exact commit: not independently exercised by this review session; GitHub-side source edits only.
  • Independent evidence: none yet.
  • Safe to merge: requires CI/build/test review before merge; this PR should remain reviewable as an architectural seam, not be treated as completed convergence.

Scope budget

This PR intentionally avoids vocabulary changes, serializer changes, new dependencies, database work, ECS runtimes, and unrelated lgwks_std/bot work.

srinji-kaggss and others added 6 commits September 3, 2026 15:31
TypeTag now derives Ord so GraphEdge::Data (which contains TypeTag)
can derive Ord for deterministic sorting. Fixes build on 1.98.0
across all CI jobs (Build, lgwks-std stable, contract probe).

Also applies rustfmt normalization to graph.rs tests to satisfy
cargo fmt --check.
@srinji-kaggss
srinji-kaggss merged commit 59e9656 into main Sep 3, 2026
15 checks passed
@srinji-kaggss
srinji-kaggss deleted the refactor/unified-program-graph branch September 3, 2026 21:12
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