fix(8376): a repo that leaves a project takes its shape rows out of that project's accounting
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 2m19s
CI & Build / integration (push) Successful in 2m19s
CI & Build / Build & push image (push) Successful in 20s

A coverage refresh walks only the repos bound to a project, but its readout
counts every live row, so the rows of a repo unbound or re-bound to another
project were never synced again and kept counting: in the total, the gap
list, and every reader of live rows (proposer, divergence, stamp review).
Re-binding a repo to another project and unbinding it now stamp its rows on
the project it left as vanished, and each refresh sweeps any rows still left
under a repo nobody binds to the project. A bound repo the forge did not
serve this time stays live. Each stamped row gets an `unbound` event and
keeps its judgment, so binding the repo back revives it like any vanished
row. Plugin version bumped for the shape-accounting skill's event list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 23:15:24 -05:00
co-authored by Claude Opus 5.5
parent af5edd5c3f
commit f55e263d7e
9 changed files with 211 additions and 10 deletions
+33
View File
@@ -34,6 +34,7 @@ from grimoire.models import async_session
from grimoire.models.code_shape import (
REASON_CODES, CodeShape, CodeShapeConsumer, CodeShapeEvent, CodeShapeUse,
)
from grimoire.models.repo_binding import RepoBinding
from grimoire.models.base import iso
logger = logging.getLogger(__name__)
@@ -171,6 +172,38 @@ async def sync_repo_shapes(
await session.commit()
async def vanish_unbound(project_id: int) -> int:
"""Stamp vanished every live row of a repo no longer bound to the project.
A sync only reaches the repos a project is bound to, so the rows of a repo
that was unbound, or re-bound to another project, are never matched
against a tree again: no sync can vanish them, and they kept counting in
the accounting, the gap list and every reader of live rows. Bound by
anyone counts (a collaborator's binding is as much the project's as the
owner's), and a bound repo the forge cannot reach this time is still
bound, so its rows stand. Each row gets an `unbound` event, its
judgment is kept, and binding the repo again lets the next sync revive
it like any vanished row. Returns how many rows were stamped.
"""
now = datetime.now(timezone.utc)
async with async_session() as session:
bound = select(RepoBinding.repo_key).where(RepoBinding.project_id == project_id)
rows = (
await session.execute(
select(CodeShape).where(
CodeShape.project_id == project_id,
CodeShape.vanished_at.is_(None),
CodeShape.repo_key.not_in(bound),
)
)
).scalars().all()
for row in rows:
row.vanished_at = now
session.add(_event(row, "unbound", now, commit=row.last_seen_commit))
await session.commit()
return len(rows)
async def move_shapes(
user_id: int, project_id: int, from_path: str, to_path: str,
) -> dict: