Skip to content

feat(grammar-diffusion): topology solver capsule fallback + unit test (SLM-71 follow-up)#371

Merged
Tyler-R-Kendrick merged 3 commits into
mainfrom
slm-71-follow-up-topology-solver
Jul 18, 2026
Merged

feat(grammar-diffusion): topology solver capsule fallback + unit test (SLM-71 follow-up)#371
Tyler-R-Kendrick merged 3 commits into
mainfrom
slm-71-follow-up-topology-solver

Conversation

@Tyler-R-Kendrick

@Tyler-R-Kendrick Tyler-R-Kendrick commented Jul 18, 2026

Copy link
Copy Markdown
Owner

"Follow-up to #356 (SLM-71).\n\n## What changed\n- Added test_topology_solver_prune_runs_and_is_monotone — direct unit test that topology_solver_prune runs exact closure over a small SolverTopologyNode tree and survivors are a subset of the original complete edit domain.\n- Added a synthetic joint-capsule coordinator in topology_solver.py:\n - _derive_synthetic_capsule_graph builds one joint CapsuleGraph over all active topology nodes.\n - TopologyCapsuleProblemBuilder, TopologyCapsuleSummaryExtractor, TopologyCapsuleMaterializer, TopologyCapsuleTerminalChecker, and TopologyCapsuleGlobalVerifier wire the capsule solver protocol.\n - topology_capsule_solver_solve exposes the coordinator and returns (assembled_source, CapsuleSolveResult).\n- Wired the capsule solver into GrammarDiffusionModel._topology_solver_survivors when topology_capsule_solver=True and the active DSL pack exposes the required capsule slots. If the coordinator does not return a solved result with non-empty survivors, or if it raises, the model falls back to whole-tree topology_solver_prune with an honest capsule_fallback trace entry. If the pack slots are missing, the existing pack_capsule_slots_unimplemented fallback remains.\n- Added test_topology_capsule_solver_runs_without_error and kept test_capsule_mode_falls_back_when_pack_slots_missing to document the honest gap.\n\n## Verification\n- python -m pytest tests/test_dsl tests/test_harnesses/model_build tests/test_models -q — 838 passed, 5 skipped, 15 deselected\n- .githooks/check-changed — passed\n- python -m scripts.repo_policy — ok\n- git diff --check — clean\n\n## Caveats\nThe synthetic capsule graph is a wiring fixture: it exercises solve_capsule_graph and SCC-joint plumbing but does not yet derive capsules from a real ProgramSpec. Full pack capsule slots, reversible backtracking, and model/energy ranker ordering remain future work.\n"

- Verify closure runs over a tiny ProductionCodec tree and survivors are a
  subset of the original complete edit domain.
…lver

- Detect topology_capsule_solver=True and probe the active DSL pack for
  capsule slots (builder, summary extractor, materializer, global oracle).
- When slots are unavailable, fall back to whole-tree exact closure and
  record a capsule_fallback trace entry instead of silently weakening.
- Add regression test for the fallback behavior.
@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
slm-training Ready Ready Preview, Comment Jul 18, 2026 3:48pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The topology solver now probes optional capsule pack slots and records capsule availability or fallback state in its trace. New regression tests verify monotone topology pruning and fallback behavior when capsule slots are unavailable.

Changes

Topology solver updates

Layer / File(s) Summary
Capsule fallback trace
src/slm_training/models/grammar_diffusion.py, tests/test_models/test_grammar_diffusion_solver.py
The solver checks capsule pack slots when enabled, records capsule mode and availability, and reports pack_capsule_slots_unimplemented when slots are unavailable.
Pruning monotonicity regression
tests/test_dsl/test_topology_solver.py
A fake topology verifies that pruning survivors remain a subset of the original edit-domain candidates and that support-query counts are non-negative.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: capsule fallback behavior in the topology solver plus a regression test.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch slm-71-follow-up-topology-solver

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Tyler-R-Kendrick

Copy link
Copy Markdown
Owner Author

Follow-up to #356 (SLM-71).

What changed

  • Added tests/test_dsl/test_topology_solver.py — direct unit test that topology_solver_prune runs exact closure over a small ProductionCodec tree and survivors are a subset of the original complete edit domain.
  • GrammarDiffusionModel._topology_solver_survivors now probes the active DSL pack for capsule_problem_builder / capsule_summary_extractor / capsule_materializer / capsule_global_oracle slots when topology_capsule_solver=True. Since the current openui pack does not implement those slots, it falls back to whole-tree exact closure and records an honest capsule_fallback: pack_capsule_slots_unimplemented trace entry.
  • Added regression test for the capsule-mode fallback.

Verification

  • python -m pytest tests/test_dsl tests/test_harnesses/model_build tests/test_models -q — 577 passed, 5 skipped
  • .githooks/check-changed — clean
  • python -m scripts.repo_policy — ok

Caveats

Full capsule-plan/SCC integration, reversible backtracking, and model/energy ranker ordering remain future work.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/slm_training/models/grammar_diffusion.py (1)

1637-1676: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Fix dead code and lost fallback telemetry.

The trace dictionary assigned here is unconditionally overwritten by the assignment on line 1663. As a result, the "honest gap" telemetry is lost when capsules are available but not yet implemented in the model. Additionally, the comment implies the model hooks are missing, not the pack slots (since capsule_available is true).

Consolidate the assignments to preserve the capsule_fallback field.

💡 Proposed fix
             if use_capsules and capsule_available:
                 # VSS3-03 future work: drive solve_capsule_graph with topology
-                # capsule hooks.  Until those pack slots are implemented, fall
+                # capsule hooks.  Until those hooks are implemented, fall
                 # back to whole-tree exact closure and record the honest gap.
-                trace = {
-                    "enabled": True,
-                    "capsule_mode": True,
-                    "capsule_fallback": "pack_capsule_slots_unimplemented",
-                }
                 # Fall through to the whole-tree prune below.
 
             survivors, result = topology_solver_prune(
                 root,
                 self.codec,
                 adapter_config,
                 slot_inventory,
                 output_kind,
                 bounds,
                 max_queries=max(
                     1,
                     min(
                         self.config.topology_max_active * 4,
                         self.config.topology_solver_max_verifier_calls or 64,
                     ),
                 ),
             )
             trace = {
                 "enabled": True,
                 "capsule_mode": use_capsules,
                 "capsule_available": capsule_available,
                 "reached_fixed_point": result.reached_fixed_point,
                 "stop_reason": result.stop_reason,
                 "candidates_removed": result.counters.candidates_removed,
                 "support_queries": result.counters.support_queries,
                 "verifier_calls": result.counters.verifier_calls,
                 "survivor_count": len(survivors),
             }
             if use_capsules and not capsule_available:
                 trace["capsule_fallback"] = "pack_capsule_slots_unimplemented"
+            elif use_capsules and capsule_available:
+                trace["capsule_fallback"] = "model_capsule_hooks_unimplemented"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/slm_training/models/grammar_diffusion.py` around lines 1637 - 1676,
Consolidate the trace construction in the topology-pruning flow so the initial
capsule fallback telemetry is not overwritten by the later assignment. Update
the fallback condition and message to reflect missing model hooks when
use_capsules and capsule_available are true, while retaining the existing
unavailable-capsule fallback behavior and all solver metrics.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/slm_training/models/grammar_diffusion.py`:
- Around line 1637-1676: Consolidate the trace construction in the
topology-pruning flow so the initial capsule fallback telemetry is not
overwritten by the later assignment. Update the fallback condition and message
to reflect missing model hooks when use_capsules and capsule_available are true,
while retaining the existing unavailable-capsule fallback behavior and all
solver metrics.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 388ba0d3-5101-4e86-b10a-8f1d201a7327

📥 Commits

Reviewing files that changed from the base of the PR and between c6a7d14 and 28fc8eb.

📒 Files selected for processing (3)
  • src/slm_training/models/grammar_diffusion.py
  • tests/test_dsl/test_topology_solver.py
  • tests/test_models/test_grammar_diffusion_solver.py

…llback

When topology_capsule_solver=True and the DSL pack exposes capsule slots, call topology_capsule_solver_solve and convert solved capsule decisions into survivor edits. If the coordinator returns non-solved, empty survivors, or raises, fall back to whole-tree topology_solver_prune with an honest trace entry. Keeps the existing pack-slot-missing fallback unchanged.
@Tyler-R-Kendrick
Tyler-R-Kendrick merged commit 1339790 into main Jul 18, 2026
4 checks passed
@Tyler-R-Kendrick
Tyler-R-Kendrick deleted the slm-71-follow-up-topology-solver branch July 18, 2026 15:53
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