feat(7836): lessons and rules are no longer paired by arriving together
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Failing after 1m40s
CI & Build / integration (push) Successful in 2m7s
CI & Build / Build & push image (push) Skipped

The co-arrival recorder counted a lesson and a rule shown in one response
as evidence that the lesson is an instance of the rule, and asked the
reader to judge the pair once three situations had gathered. Two records
that resemble the same prompts arrive together whether or not one is an
instance of the other, and the outcome bore that out (2,317 pairs
suggested, 23 confirmed). It no longer runs:

- neither the prompt door nor the write path records co-arrivals or
  carries a proposal line;
- a rule read lists the lessons judged against it, confirmed first, and a
  lesson read the rules it was judged against: suggested rows stay in the
  table and no read shows them;
- the lesson page and the rule editor drop the suggested section.

The situation-counting helpers stay; rule moment judgments use them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 06:02:10 -05:00
co-authored by Claude Opus 5.5
parent 2f93a4f7b5
commit 1a8c02bfe5
13 changed files with 69 additions and 358 deletions
-1
View File
@@ -221,7 +221,6 @@ def _no_lesson_rule_links(request):
with patch("grimoire.services.lesson_rules.attach_lesson_rules", AsyncMock()), \
patch("grimoire.services.lesson_rules.attach_rule_lessons", AsyncMock()), \
patch("grimoire.services.lesson_rules.rule_candidates", AsyncMock(return_value=[])), \
patch("grimoire.services.lesson_rules.co_surfaced", AsyncMock(return_value="")), \
patch("grimoire.services.plugin_context._rules_via_lessons",
AsyncMock(return_value=([], []))), \
patch("grimoire.services.lesson_rules.convergence_for", AsyncMock(return_value=None)):
+18 -63
View File
@@ -259,87 +259,42 @@ async def test_deleting_the_lesson_takes_its_answer_with_it(world):
assert left == []
# ── soft links from co-surfacing ────────────────────────────────────────────
# ── suggested links: inert, and absent from every read ──────────────────────
async def _link(lesson_id: int, rule_id: int):
async def _suggest(lesson_id: int, rule_id: int) -> None:
"""A suggested row, as the retired co-arrival recorder left them."""
async with async_session() as s:
return (await s.execute(
select(LessonRuleLink).where(
LessonRuleLink.lesson_id == lesson_id, LessonRuleLink.rule_id == rule_id,
)
)).scalar_one_or_none()
s.add(LessonRuleLink(lesson_id=lesson_id, rule_id=rule_id, state="suggested",
evidence={"situations": ["p:1", "p:2", "p:3"]}))
await s.commit()
async def _arrive(world, prompt: str, project: int | None = None, rules=None) -> str:
return await links_svc.co_surfaced(
world["owner"], [world["lesson"]], rules or [world["r1"]],
arm="p", situation=prompt, project_id=project,
)
async def test_distinct_situations_reach_the_bar_and_the_proposal_fires_once(world):
assert await _arrive(world, "the CI run is still going after twenty minutes") == ""
assert await _arrive(world, "deploy job hanging on the image build step") == ""
line = await _arrive(world, "integration lane overran its usual duration", world["mine"])
assert f"judge_lesson_link({world['lesson']}, {world['r1']}" in line
link = await _link(world["lesson"], world["r1"])
assert link.state == "suggested"
assert links_svc.evidence_summary(link.evidence)["situations"] == 3
# Within the cooldown a fourth situation is counted but not asked again.
assert await _arrive(world, "pipeline stuck waiting on a runner for ages") == ""
link = await _link(world["lesson"], world["r1"])
assert links_svc.evidence_summary(link.evidence)["situations"] == 4
async def test_the_same_prompt_repeated_never_reaches_the_bar(world):
for _ in range(5):
assert await _arrive(world, "is the CI run still going") == ""
ev = links_svc.evidence_summary((await _link(world["lesson"], world["r1"])).evidence)
assert ev == {"situations": 1, "projects": 0, "co_surfaced": 5}
async def test_a_judged_pair_gathers_nothing_and_is_never_proposed(world):
owner = world["owner"]
await links_svc.judge_link(owner, world["lesson"], world["r1"], "reject", "different failure")
await links_svc.judge_link(owner, world["lesson"], world["r2"], "confirm")
for prompt in ("first situation here", "second situation there", "third situation elsewhere"):
assert await _arrive(world, prompt, rules=[world["r1"], world["r2"]]) == ""
assert (await _link(world["lesson"], world["r1"])).evidence is None
assert (await _link(world["lesson"], world["r2"])).evidence is None
async def test_a_rule_the_reader_does_not_own_is_not_paired(world):
for prompt in ("first situation here", "second situation there", "third situation elsewhere"):
assert await _arrive(world, prompt, rules=[world["foreign"]]) == ""
assert await _link(world["lesson"], world["foreign"]) is None
async def test_a_suggestion_shows_its_evidence_and_leaves_the_lesson_unjudged(world):
await _arrive(world, "the CI run is still going after twenty minutes", world["mine"])
async def test_a_suggested_link_is_in_no_read_and_leaves_the_lesson_unjudged(world):
await _suggest(world["lesson"], world["r1"])
await links_svc.judge_link(world["owner"], world["lesson"], world["r2"], "reject", "not this")
rules = (await links_svc.rules_for_lessons(world["owner"], [world["lesson"]]))[world["lesson"]]
assert rules[0]["state"] == "suggested"
assert rules[0]["evidence"] == {"situations": 1, "projects": 1, "co_surfaced": 1}
assert [(r["id"], r["state"]) for r in rules] == [(world["r2"], "rejected")]
assert [x["id"] for x in await links_svc.lessons_for_rule(world["owner"], world["r1"])] == []
assert (await _judgment(world["lesson"]))["rule_judgment"] == "unjudged"
async def test_confirming_a_suggestion_keeps_what_it_rested_on(world):
for prompt in ("first situation here", "second situation there", "third situation elsewhere"):
await _arrive(world, prompt)
async def test_confirming_a_suggested_pair_puts_it_in_the_rules_read(world):
await _suggest(world["lesson"], world["r1"])
out = await links_svc.judge_link(world["owner"], world["lesson"], world["r1"], "confirm", "same failure class")
assert out["state"] == "confirmed"
assert len(out["evidence"]["situations"]) == 3
lessons = await links_svc.lessons_for_rule(world["owner"], world["r1"])
assert [(x["id"], x["state"]) for x in lessons] == [(world["lesson"], "confirmed")]
# ── which links can carry a rule ────────────────────────────────────────────
async def test_only_a_confirmed_link_can_carry_its_rule(world):
"""A suggested link never expands: it would manufacture the co-arrival
that co-surfacing counts, and prove itself. A rejected one obviously not."""
"""A suggested link never carries its rule: nothing judged it. A rejected
one obviously not."""
owner, lesson = world["owner"], world["lesson"]
await links_svc.co_surfaced(owner, [lesson], [world["r1"]], arm="p", situation="one ask here")
await _suggest(lesson, world["r1"])
await links_svc.judge_link(owner, lesson, world["r2"], "reject", "not this")
assert await links_svc.confirmed_lessons(owner) == set()
assert await links_svc.confirmed_rules_in_scope(owner, [lesson], world["mine"]) == {}
-24
View File
@@ -9,7 +9,6 @@ is tested against Postgres in tests/test_integration_lesson_rule_links.py.
"""
from __future__ import annotations
import inspect
from datetime import datetime, timedelta, timezone
from grimoire.services import lesson_rules as links_svc
@@ -76,28 +75,5 @@ def test_a_passed_over_proposal_waits_out_the_cooldown():
assert links_svc.proposal_due(ev, NOW + links_svc.PROPOSE_COOLDOWN)
def test_the_proposal_names_the_call_that_answers_it():
line = links_svc._proposal_line(
41, "An overrun run usually failed early", 7, "Read the job log first",
"rule", {"situations": ["p:1", "p:2", "p:3"], "projects": [2, 5]},
)
assert 'judge_lesson_link(41, 7, "confirm"' in line
assert '"reject"' in line
assert "3 distinct situations across 2 projects" in line
def test_evidence_summary_reads_nothing_as_zero_not_an_error():
assert links_svc.evidence_summary(None) == {"situations": 0, "projects": 0, "co_surfaced": 0}
def test_both_hook_doors_count_the_pair_on_their_own_arm():
"""The two responses that carry lessons and rules together. A door that
renders both and does not record the pair is the miss this step exists
to close, and it would produce no error anywhere — only an empty table."""
from grimoire.routes import plugin as plugin_routes
from grimoire.services import plugin_context
prompt_door = inspect.getsource(plugin_routes.autoinject_retrieve)
assert "co_surfaced(" in prompt_door and 'arm="p"' in prompt_door
write_door = inspect.getsource(plugin_context.build_write_path_hint)
assert "co_surfaced(" in write_door and 'arm="w"' in write_door
-1
View File
@@ -43,7 +43,6 @@ async def _retrieve(query_string, turn_context="CORE SHAPE"):
"shown_rule_ids": [11]})), \
patch.object(routes.plugin_ctx_svc, "build_autoinject_hint",
AsyncMock(return_value={"context": "NOTES MENU", "note_ids": []})), \
patch.object(routes.lesson_rules_svc, "co_surfaced", AsyncMock(return_value="")), \
patch.object(routes.moment_delivery_svc, "deliver_for_turn", turn):
resp = await inspect.unwrap(routes.autoinject_retrieve)()
return await resp.get_json(), turn