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
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:
@@ -896,6 +896,9 @@ async def compute_coverage(
|
||||
logger.warning("shape proposer failed for %s", key, exc_info=True)
|
||||
if not served:
|
||||
return None
|
||||
# A repo unbound or re-bound elsewhere is outside every walk above, so
|
||||
# its rows would otherwise stay live here for good.
|
||||
await shape_ledger.vanish_unbound(project_id)
|
||||
|
||||
# Platform detection rides the same walk: the paths are in
|
||||
# hand once. It only ever ADDS membership the project has no answer for,
|
||||
|
||||
@@ -78,6 +78,10 @@ async def set_binding(
|
||||
binding: a name sets it, ``""`` clears it back to the forge's default
|
||||
branch, ``None`` leaves whatever stands (a re-bind that only moves the
|
||||
project keeps the ref it had).
|
||||
|
||||
A re-bind to another project stamps the repo's rows on the project it
|
||||
left as vanished (`shape_ledger.vanish_unbound`): the old project's
|
||||
refresh no longer walks the repo, so nothing else would.
|
||||
"""
|
||||
key = normalize_repo_key(raw_repo)
|
||||
if not key:
|
||||
@@ -89,16 +93,23 @@ async def set_binding(
|
||||
)
|
||||
)
|
||||
binding = existing.scalar_one_or_none()
|
||||
left = None
|
||||
if binding is None:
|
||||
binding = RepoBinding(user_id=user_id, repo_key=key, project_id=project_id)
|
||||
session.add(binding)
|
||||
else:
|
||||
if binding.project_id != project_id:
|
||||
left = binding.project_id
|
||||
binding.project_id = project_id
|
||||
if ref is not None:
|
||||
binding.ref = ref.strip() or None
|
||||
await session.commit()
|
||||
await session.refresh(binding)
|
||||
return binding
|
||||
if left is not None:
|
||||
from grimoire.services.shape_ledger import vanish_unbound
|
||||
|
||||
await vanish_unbound(left)
|
||||
return binding
|
||||
|
||||
|
||||
async def move_binding(
|
||||
@@ -229,7 +240,11 @@ async def bindings_for_key(raw_repo: str) -> list[RepoBinding]:
|
||||
|
||||
|
||||
async def delete_binding(user_id: int, raw_repo: str) -> bool:
|
||||
"""Remove a repo's binding. Returns True if a row was deleted."""
|
||||
"""Remove a repo's binding. Returns True if a row was deleted.
|
||||
|
||||
The repo's rows on the project it was bound to are stamped vanished in
|
||||
the same call, unless another binding still ties the repo to it.
|
||||
"""
|
||||
key = normalize_repo_key(raw_repo)
|
||||
if not key:
|
||||
return False
|
||||
@@ -242,6 +257,10 @@ async def delete_binding(user_id: int, raw_repo: str) -> bool:
|
||||
binding = row.scalar_one_or_none()
|
||||
if binding is None:
|
||||
return False
|
||||
left = binding.project_id
|
||||
await session.delete(binding)
|
||||
await session.commit()
|
||||
return True
|
||||
from grimoire.services.shape_ledger import vanish_unbound
|
||||
|
||||
await vanish_unbound(left)
|
||||
return True
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user