fix(8572): a reference holder whose shapes already speak is answered by the shape ledger at once, not at its next coverage refresh
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 12s
CI & Build / Plugin hooks (push) Successful in 15s
CI & Build / Python tests (push) Successful in 1m50s
CI & Build / integration (push) Successful in 2m46s
CI & Build / Build & push image (push) Successful in 24s

answer_reference_holders stepped aside whenever the project's shapes spoke for
the idea, leaving the row unassessed until the project's next coverage refresh
synced the shapes. A lift makes the reference row new, so those shapes had
never been synced onto the idea. It now asks the shape ledger to answer that
holder straight away (sync_from_shapes for the reference snippet).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-04 15:52:12 -05:00
co-authored by Claude Opus 5.5
parent 198bf110c2
commit b67e621adc
2 changed files with 49 additions and 7 deletions
+18 -7
View File
@@ -1061,10 +1061,12 @@ async def answer_reference_holders(user_id: int, idea_id: int) -> list[dict]:
"""A project whose own snippet is one of a canon idea's reference """A project whose own snippet is one of a canon idea's reference
implementations has built the idea, so its unassessed row is answered implementations has built the idea, so its unassessed row is answered
`adopted` (decided_via system, the snippet as evidence). Only an `adopted` (decided_via system, the snippet as evidence). Only an
unassessed row is answered — an answer somebody gave stands — and only unassessed row is answered — an answer somebody gave stands. Where the
where the project's shapes say nothing about the idea, because the shape project's shapes already speak for the idea (the reference's own
ledger's answer and this one must never disagree. Returns the answers `canonical` stamp, an instance, a variant), the shape ledger gives the
given: {project_id, idea_id, snippet_id, decision_id}.""" answer now, as the coverage refresh would, because the two ledgers never
disagree. Returns the answers given: {project_id, idea_id, snippet_id,
decision_id}."""
async with async_session() as session: async with async_session() as session:
idea = await session.get(FamilyIdea, idea_id) idea = await session.get(FamilyIdea, idea_id)
if idea is None or idea.status != "canon": if idea is None or idea.status != "canon":
@@ -1088,9 +1090,18 @@ async def answer_reference_holders(user_id: int, idea_id: int) -> list[dict]:
continue continue
if row is not None and row.status != "unassessed": if row is not None and row.status != "unassessed":
continue continue
if shapes_say(await _shape_evidence(session, project_id, idea_id)): spoken = shapes_say(await _shape_evidence(session, project_id, idea_id)) is not None
continue if spoken:
row = row or await _row_for_write(session, project_id, idea_id) # The reference row that made the shapes evidence may be new, so
# nothing has synced them onto this idea yet.
for moved in await sync_from_shapes(user_id, project_id, [snippet_id]):
if moved["idea_id"] == idea_id:
given.append({"project_id": project_id, "idea_id": idea_id,
"snippet_id": snippet_id, "decision_id": moved["decision_id"]})
continue
async with async_session() as session:
row = await _row(session, project_id, idea_id) \
or await _row_for_write(session, project_id, idea_id)
reason = (f"{project_title} holds a reference implementation of this idea: " reason = (f"{project_title} holds a reference implementation of this idea: "
f"#{snippet_id} \u201c{snippet_title}\u201d.") f"#{snippet_id} \u201c{snippet_title}\u201d.")
before = _row_state(row) before = _row_state(row)
@@ -238,6 +238,37 @@ async def test_a_snippet_stays_in_its_project_as_a_reference_and_its_project_is_
assert answer.decided_via == "system" and answer.evidence["source"] == "reference" assert answer.decided_via == "system" and answer.evidence["source"] == "reference"
async def test_a_reference_the_shape_ledger_already_holds_is_answered_by_the_shapes_at_promotion(family):
"""The project's own snippet is already stamped `canonical` in its shape
ledger, so the shapes answer the idea the moment promotion makes that
snippet a reference — not at the project's next coverage refresh."""
from grimoire.models.code_shape import CodeShape
from grimoire.services import family_adoption
async with async_session() as s:
snippet = Note(user_id=family["owner"], project_id=family["a"], note_type="snippet",
title="ReleaseSigner", body="fun sign(apk: File) = ...",
data={"language": "kotlin"})
s.add(snippet)
await s.flush()
s.add(CodeShape(project_id=family["a"], repo_key="git.example.com/x/y",
path="app/src/ReleaseSigner.kt", symbol="sign", kind="sym",
status="canonical", snippet_id=snippet.id, classified_by="mechanical"))
await s.commit()
await s.refresh(snippet)
out = await family_svc.promote(
family["owner"], snippet.id, applies_when="any Android app that ships its own APK",
platforms=["android-app"], criteria=CRITERIA, evidence=["CI green"], reason="proven",
)
lifted = out["idea"]["note_id"]
assert (await _ledger(lifted))[family["a"]] == "adopted"
assert [a["project_id"] for a in out["answered"]] == [family["a"]]
async with async_session() as s:
answer = (await s.execute(select(FamilyDecision).where(
FamilyDecision.idea_id == lifted, FamilyDecision.project_id == family["a"]))).scalars().one()
assert answer.decided_via == "system"
assert answer.evidence["source"] == family_adoption.SHAPE_SOURCE
async def test_an_answer_somebody_gave_is_not_overwritten_by_the_reference(family): async def test_an_answer_somebody_gave_is_not_overwritten_by_the_reference(family):
from grimoire.services import family_adoption from grimoire.services import family_adoption