Skip to content

dedup_siblings: SKU-match routing is dead code (split separator mismatch) #2

Description

@bitmosh

Surfaced while running mypy across the whole tree for the first time. Two related issues at the same call site, one purely cosmetic (now fixed) and one substantive (left for a follow-up).

Where

cerebra/retrieval/lattice_dedup.py_pick_winner_scored() and its caller dedup_siblings(), invoked from cerebra/cli/main.py:524 and :755.

Issue 1: type mismatch (resolved in PR #1)

dedup_siblings(scored, query_d1, ...) declared query_d1: str | None, but every call site passes plan.query_d1 which is int | None (D1 categories are integer hex codes 0x0–0xF, see cerebra/cognition/sku_categories.py).

Resolved in PR #1 by changing the parameter type to int | None on both dedup_siblings and _pick_winner_scored. This is the smaller of the two issues.

Issue 2: the comparison never matches (this issue)

Inside _pick_winner_scored:

d1_matches = [
    c for c in group
    if c.sku_address and c.sku_address.split("::")[0] == query_d1
]

The intent is "find candidates whose SKU's D1 category matches the query's D1." Two problems combine to make this dead code:

  1. sku_address strings are produced by SKUAddress.to_hex_string() (cerebra/cognition/sku.py:90), which formats them as D1D2D3D4D5D6.D7D8.D9D10 — period-separated, not ::-separated. So sku_address.split("::") is a no-op that returns [sku_address], and split("::")[0] returns the full address string.
  2. Even after Issue 1's type fix, the comparison is str == int, which is always False.

Net effect: d1_matches is always []. _pick_winner_scored always falls through to the return _best_composite(group, "composite_score") branch. The SKU-aware routing — which the D2 routing rules docstring describes as the function's purpose — has never fired.

Impact

Behavior-wise: dedup_siblings still works correctly, it just always uses composite-score routing instead of preferring SKU-match candidates. No exception, no data corruption. Quality of retrieval ranking in SKU-classified scenarios is degraded vs. what the design intended.

Possible fixes (not done in this PR)

Some combination of:

  • Change the split character to match the actual format: c.sku_address.split(".")[0] — but then [0] would be the full D1–D6 location string D1D2D3D4D5D6, not just D1. Need to extract the first hex char: c.sku_address[0].
  • Coerce query_d1 (int) into a single hex character for comparison: f"{query_d1:X}" == c.sku_address[0].
  • Or restructure _pick_winner_scored to take an already-resolved D1 hex character rather than the int.

Whichever approach, add a unit test that exercises the SKU-match path and confirms a winner gets returned with routing_basis="sku_match" — the lack of such a test is part of why this never got caught.

Why this surfaced now

This archive repo had broken CI installs from day one, so type-check and tests have never run end-to-end against the whole tree. Pre-commit's mypy hook only checks staged files, not the whole package. PR #1's CI cleanup made these full-tree checks possible for the first time and surfaced ~50 mypy errors of accumulated debt; this is the only one of those errors that points at a real-but-silent logic bug rather than an annotation issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions