Skip to content

feat(totlib): activate eq->tr BPSD verify rule on mono (#208 Phase 2c PR-B)#214

Merged
k-yoshimi merged 5 commits into
developfrom
l7b-ii-phase-2c-prb
May 26, 2026
Merged

feat(totlib): activate eq->tr BPSD verify rule on mono (#208 Phase 2c PR-B)#214
k-yoshimi merged 5 commits into
developfrom
l7b-ii-phase-2c-prb

Conversation

@k-yoshimi
Copy link
Copy Markdown
Owner

@k-yoshimi k-yoshimi commented May 26, 2026

Summary

Closes #208 (Phase 2c umbrella) and #201 (Phase 2 umbrella).

Activates the (\"eq\",\"tr\") BPSD coupling rule in
TotPipeline._MONO_ONLY_RULES — now possible after PR-A's
MONO_LIB_PATH plumbing landed (#212). Adds a Layer-D
integration test that drives TotPipeline.run_pipeline([(eq, ...), (tr, ...)]) on the mono image AND asserts the rule stays
dormant on the default per-module image.

What's in this PR (5 commits)

  1. feat(totlib): activate (\"eq\",\"tr\") BPSD verify rule on mono — populates _MONO_ONLY_RULES with the verify rule; named module-level callable (_eq_to_tr_bpsd_check) so error-message __qualname__ is meaningful; Layer-D happy-path test.
  2. test(totlib): negative path — rule dormant on default per-module — adds the inverse contract test pinning Codex MED-6.
  3. ci(python-tests): mono pipeline coupling step — extends mono-build job to run the new test with both env vars set.
  4. docs(totlib): note (\"eq\",\"tr\") rule activation in README — 1-paragraph note appended to PR-A's mono routing section.
  5. test(totlib): isolate env vars + _MONO_ONLY_RULES — Codex cumulative review LOW fixups (defensive env-var popping in negative test + monkeypatch isolation in test_pipeline_verify).

Acceptance (spec §11)

  • _MONO_ONLY_RULES[(\"eq\",\"tr\")] populated per §6.
  • test_mono_pipeline_coupling.py with 2 cases per §7.
  • Both tests pass locally with pytest --forked.
  • CI step extends mono-build job per §8.
  • 1e-10 equivalence preserved (test_equivalence.py untouched).
  • PR-A test_mono_routing.py stays green (9 tests).
  • _build_active_rules() / _detect_mono() untouched — verified by diff.
  • Pre-push reviews HIGH/MED-free.

Tests

  • New python/totlib/tests/test_mono_pipeline_coupling.py: 2 tests, both pass locally + via pytest --forked (mono happy + dormant on default).
  • Existing totlib tests unaffected (the 1 pre-existing Python 3.10 ExceptionGroup failure in test_close_raises_exception_group_when_multiple_modules_fail is the same as develop baseline since PR fix(tot): cascade eq_api_init in tot_init (#209) #211, unrelated).
  • test_pipeline_verify.py two tests received minimal _MONO_ONLY_RULES = {} monkeypatch isolation since the populated mono rule would otherwise pollute their controlled coupling_applied lists when MONO_LIB_PATH is set.

Out of scope

  • Other module-pair rules (e.g. ("tr","fp")) — deferred to future PRs.
  • Restructuring _MONO_ONLY_RULES for per-rule activation conditions.
  • Fortran source changes.

Spec + Plan

  • Spec: `docs/superpowers/specs/2026-05-26-l7b-ii-phase-2c-prb-rule-activation-design.md` (Codex 5-round SHIP IT).
  • Plan: `docs/superpowers/plans/2026-05-26-l7b-ii-phase-2c-prb-implementation.md`.

Process notes

Subagent-driven implementation per superpowers:subagent-driven-development. Plan tasks 1-4 dispatched as fresh implementer subagents with two-stage review (spec + code quality) per task. Task 1 implementer flagged a non-plan modification to test_pipeline_verify.py to isolate it from the new global rule state — accepted by spec compliance review as minimal+necessary. Cumulative review by Codex surfaced 2 LOW (env-var isolation + sister-test pollution) — both addressed in commit 5.

Every plan command used `git -C ` or explicit `cd` per feedback_codex_worktree_sharing.md to defuse the recurring 'subagent commits on main checkout' failure class (incidents: 2026-04-23 Codex, 2026-05-26 PR-A Task 5). Controller-side tripwire confirmed main checkout develop = origin/develop pre-push.

Test plan

🤖 Generated with Claude Code


Note

Medium Risk
Changes multi-module pipeline coupling behavior when MONO_LIB_PATH is set (verify can fail pipelines if BPSD round-trip breaks); default per-module path is explicitly tested to stay unchanged.

Overview
Phase 2c PR-B turns on the ("eq","tr") verify coupling in TotPipeline._MONO_ONLY_RULES, gated by the existing mono overlay (_detect_mono() / _build_active_rules() unchanged). The check delegates to Trlib.check_bpsd_pull() via a named _eq_to_tr_bpsd_check so failures surface a clear __qualname__.

On the mono image (with MONO_LIB_PATH from PR-A), run_pipeline([("eq", …), ("tr", …)]) records eq → tr BPSD broker round-trip in PipelineResult.last("tr").coupling_applied. On the default per-module .so layout the same rule stays dormant so pipelines do not fail on private, non-shared BPSD storage.

New Layer-D tests in test_mono_pipeline_coupling.py cover both behaviors (pytest.mark.forked). The mono-build CI job runs them alongside existing mono routing/smoke steps. test_pipeline_verify.py clears _MONO_ONLY_RULES under monkeypatch so unit tests stay isolated when MONO_LIB_PATH is set. README notes the behavioral change.

Reviewed by Cursor Bugbot for commit 65c354d. Bugbot is set up for automated code reviews on this repo. Configure here.

k-yoshimi and others added 5 commits May 26, 2026 10:11
Populates TotPipeline._MONO_ONLY_RULES with a single verify-kind
CouplingRule that wraps Trlib.check_bpsd_pull(). The rule fires
when TotPipeline.run_pipeline([("eq",...),("tr",...)]) is invoked
against the mono image (_detect_mono() == True after PR-A's
MONO_LIB_PATH routing); it stays dormant on the default per-module
image via the existing _build_active_rules() overlay.

The rule body is a named module-level callable
(_eq_to_tr_bpsd_check) per spec §4 D-2 so pipeline error messages
show a meaningful __qualname__ instead of `<lambda>`.

Spec §4 D-4 empirical resolution: `eq_init -> eq_run(1) -> tr_init
-> tr_check_bpsd_pull` returns ok=1 on the mono image; tr_init
does NOT clear the bpsd broker slots that eq just pushed. This is
the ordering TotPipeline.run_pipeline exercises with no prior
tr-side set_param.

First Layer-D test
(test_mono_pipeline_coupling.py::TestEqToTrPipelineCoupling) drives
the full pipeline through eq -> tr on mono and asserts the rule
appears in result.last("tr").coupling_applied. Negative test
follows in the next commit.

Also adds monkeypatch.setattr("totlib.pipeline._MONO_ONLY_RULES", {})
to test_pipeline_verify.py::test_verify_true_records_rule_in_applied
so that unit test is not affected by MONO_LIB_PATH presence; the
mono overlay behaviour is now covered by the new Layer-D test.

Spec: docs/superpowers/specs/2026-05-26-l7b-ii-phase-2c-prb-rule-activation-design.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…PR-B)

Adds TestEqToTrRuleDormantOnDefault to
python/totlib/tests/test_mono_pipeline_coupling.py. Asserts the
inverse contract to the happy-path test in the prior commit:
when MONO_LIB_PATH is unset, TotPipeline.run_pipeline([("eq",..),
("tr",..)]) completes without the ("eq","tr") verify rule firing.
Pipeline succeeds because the rule stays dormant via the Phase 2b
overlay mechanism (_detect_mono() returns False on the default
per-module image).

Skip-gate is _default_per_module_so_present() — checks the actual
.so paths eqlib/trlib/totlib will load via priority-2 repo
defaults. Per Codex 2026-05-26 spec round-3 review, TOTLIB_PATH
env var is NOT in the gate (eqlib/trlib don't honor it).

Pin for Codex 2026-05-26 design review MED-6: if a future refactor
of _detect_mono() / _build_active_rules() silently activates the
overlay on non-mono, this test catches it at the user-facing
TotPipeline entry point.

Spec: docs/superpowers/specs/2026-05-26-l7b-ii-phase-2c-prb-rule-activation-design.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extends the mono build (Linux libtotapi_mono.so) job to run
python/totlib/tests/test_mono_pipeline_coupling.py with both
MONO_LIB_PATH and TOTLIB_PATH set so both test classes execute.
The default libtotapi.so and per-module .so files are already
built earlier in this job; PR-B reuses them.

Step is added directly after PR #212's "Mono routing sanity"
step in the same job.

Spec: docs/superpowers/specs/2026-05-26-l7b-ii-phase-2c-prb-rule-activation-design.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Appends a one-paragraph note to the existing Mono routing section
that PR #212 added. Documents that the eq -> tr BPSD coupling rule
now fires through TotPipeline.run_pipeline when MONO_LIB_PATH is
set, and stays dormant on the default per-module image.

No code or behavior changes — pure documentation.

Spec: docs/superpowers/specs/2026-05-26-l7b-ii-phase-2c-prb-rule-activation-design.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses Codex 2026-05-26 cumulative PR-B review:

LOW-1: TestEqToTrRuleDormantOnDefault.test_eq_to_tr_rule_dormant_on_default
       only popped MONO_LIB_PATH. Inherited EQLIB_PATH / TRLIB_PATH
       could route the wrappers away from the repo-default per-module
       .so files the test asserted exist. Now pop+restore all three.

LOW-2: test_pipeline_verify.test_mixed_transfer_then_verify_fires_in_order
       patched COUPLING_RULES but not _MONO_ONLY_RULES. Under
       MONO_LIB_PATH it would silently fire the real ("eq","tr") mono
       rule alongside the mock rules and break the exact-order
       assertion. Apply the same _MONO_ONLY_RULES = {} isolation
       that test_verify_true_records_rule_in_applied got in Task 1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@k-yoshimi
Copy link
Copy Markdown
Owner Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 65c354d. Configure here.

@k-yoshimi k-yoshimi merged commit 5a59b96 into develop May 26, 2026
4 checks passed
@k-yoshimi k-yoshimi deleted the l7b-ii-phase-2c-prb branch May 27, 2026 22:04
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