Skip to content

fix(devtools): topology projection avoids __init__.py target collisions - #456

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/topology-projection-conflicts
Apr 26, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/topology-projection-conflicts

Conversation

@Sinity

@Sinity Sinity commented Apr 26, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes a projection-rule defect surfaced by the topology-status dashboard (PR #455). The rule was emitting __init__.py for any module whose name equaled the subpackage prefix exactly, which caused multiple modules to claim the same destination — 12 false-conflict rows in the dashboard.

Problem

build_topology_projection.py:lib_target() and storage_target() use a strip-prefix-then-stem rule. When the stem strips empty (e.g. module session_payload matches prefix session_payload), the rule defaulted to __init__.py. Two such modules in the same cluster collide:

  • lib/session/__init__.py claimed by session_payload, session_summaries, session_profile
  • storage/runtime/__init__.py claimed by store_runtime (the catch-all prefix)

devtools verify-topology reports conflicts: 12 and the dashboard shows them in its conflicts column.

Solution

New resolver:

def _resolve_target(name: str, sub: str, prefix: str) -> str:
    stem = name[len(prefix):]
    if not stem:
        # Module name == prefix; preserve full name to avoid colliding at __init__.py.
        return f"polylogue/{sub}{name}"
    if not stem.endswith(".py"):
        stem = stem + ".py"
    stem = stem.lstrip("_")
    if not stem or stem == ".py":
        return f"polylogue/{sub}{name}"
    return f"polylogue/{sub}{stem}"

After regen: verify-topology --json reports conflicts: 0. Dashboard column will read 0 once this and #455 are both merged.

Verification

$ devtools build-topology-projection
$ devtools verify-topology --json | jq '.counts'
{"orphans": 0, "missing": 0, "conflicts": 0, "kernel_rule": 0, "tbd": 39}

$ devtools verify --quick
verify: all checks passed (incl. all 8 lints)

Related

🤖 Generated with Claude Code

Closes the projection-rule defect surfaced by the topology-status
dashboard (PR #455). Previously, when a module's name equaled its
subpackage prefix exactly (e.g. ``session_payload``, ``store_runtime``),
the rule emitted a target of ``polylogue/<sub>/__init__.py`` — causing
multiple modules to claim the same destination and producing 12
"conflicts" in the dashboard.

The new resolver:

- preserves the full module name as the target stem when stem-stripping
  would empty out (``session_payload`` -> ``lib/session/session_payload.py``,
  not ``lib/session/__init__.py``);
- otherwise strips the trailing-underscore variant of the prefix
  (``query_runtime`` -> ``lib/query/runtime.py``).

After regen: ``devtools verify-topology --json`` reports zero conflicts.
Dashboard table will show 0 in the conflicts column once both this fix
and #455 land.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Apr 26, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 6 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 17 minutes and 6 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 03380c4a-5389-4cc5-9193-5063140d3bfe

📥 Commits

Reviewing files that changed from the base of the PR and between 2f8cd57 and 9002818.

📒 Files selected for processing (2)
  • devtools/build_topology_projection.py
  • docs/plans/topology-target.yaml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/topology-projection-conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity
Sinity merged commit 8a43a42 into master Apr 26, 2026
13 checks passed
@Sinity
Sinity deleted the feature/fix/topology-projection-conflicts branch April 26, 2026 12:51
@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a defect in the topology projection generation that previously mapped some prefix-matched modules to __init__.py, creating false target-collision “conflicts” in the topology-status dashboard and related tooling.

Changes:

  • Introduces a shared _resolve_target() helper to compute deterministic, non-colliding target paths for lib_target() and storage_target().
  • Regenerates docs/plans/topology-target.yaml to replace several erroneous .../.py targets with concrete module targets and updates some loc counts accordingly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
docs/plans/topology-target.yaml Updates projection targets (and some LOC metadata) to reflect the new target resolution logic.
devtools/build_topology_projection.py Adds _resolve_target() and routes lib/storage target computation through it to avoid __init__.py collisions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +243 to +253
stem = name[len(prefix) :]
if not stem:
# Module name == prefix; preserve the full name to avoid colliding
# at the subpackage __init__.py.
return f"polylogue/{sub}{name}"
if not stem.endswith(".py"):
stem = stem + ".py"
stem = stem.lstrip("_")
if not stem or stem == ".py":
return f"polylogue/{sub}{name}"
return f"polylogue/{sub}{stem}"

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This resolver assumes sub is a directory prefix (ends with /). For exact-match rules where sub is a full file path (e.g. storage/repository/__init__.py for repository.py), returning f"polylogue/{sub}{name}" produces concatenated filenames like .../__init__.pyrepository.py (also visible in the regenerated topology-target.yaml). Consider special-casing sub values that already end with .py (treat as a complete target) or handling exact filename rewrites before calling _resolve_target.

Copilot uses AI. Check for mistakes.
Comment on lines +233 to +241
"""Build a unique target path for a module that matches a given subpackage prefix.

When the module name equals the prefix exactly, keep the full name as the
target stem (so e.g. ``session_payload`` lands at
``lib/session/session_payload.py``, not at the cluster's ``__init__.py``
where it would collide with sibling modules).

When the prefix has a trailing underscore (``query_``, ``store_runtime_``),
strip it from the stem so ``query_runtime`` becomes ``runtime.py``.

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring examples here talk about module names without the .py suffix (e.g. session_payload), but _resolve_target is passed path.name values like session_payload.py. Clarifying the docstring to match the actual inputs would make the edge-case behavior (the .py stem) easier to reason about.

Suggested change
"""Build a unique target path for a module that matches a given subpackage prefix.
When the module name equals the prefix exactly, keep the full name as the
target stem (so e.g. ``session_payload`` lands at
``lib/session/session_payload.py``, not at the cluster's ``__init__.py``
where it would collide with sibling modules).
When the prefix has a trailing underscore (``query_``, ``store_runtime_``),
strip it from the stem so ``query_runtime`` becomes ``runtime.py``.
"""Build a unique target path for a filename matching a subpackage prefix.
``name`` is the source filename as returned by ``path.name`` (for example,
``session_payload.py``), not a module stem without the suffix.
When the filename equals the prefix plus ``.py`` exactly, keep the full
filename as the target stem (so e.g. ``session_payload.py`` lands at
``lib/session/session_payload.py``, not at the cluster's ``__init__.py``
where it would collide with sibling modules).
When the prefix has a trailing underscore (``query_``, ``store_runtime_``),
strip it from the remainder so ``query_runtime.py`` becomes ``runtime.py``.

Copilot uses AI. Check for mistakes.
- path: polylogue/storage/repository.py
loc: 102
target: polylogue/storage/repository/__init__.pyinit__.py
target: polylogue/storage/repository/__init__.pyrepository.py

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This target path looks like an accidental concatenation of two filenames (__init__.py + repository.py). If the intent is to move polylogue/storage/repository.py into the storage/repository/ package, the target should likely be polylogue/storage/repository/__init__.py (or polylogue/storage/repository/repository.py), not a combined name.

Suggested change
target: polylogue/storage/repository/__init__.pyrepository.py
target: polylogue/storage/repository/__init__.py

Copilot uses AI. Check for mistakes.
- path: polylogue/storage/search.py
loc: 50
target: polylogue/storage/search/__init__.pyinit__.py
target: polylogue/storage/search/__init__.pysearch.py

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This target path looks like an accidental concatenation (__init__.py + search.py). If polylogue/storage/search.py is intended to become the package entrypoint, the target should likely be polylogue/storage/search/__init__.py (or polylogue/storage/search/search.py), not __init__.pysearch.py.

Suggested change
target: polylogue/storage/search/__init__.pysearch.py
target: polylogue/storage/search/__init__.py

Copilot uses AI. Check for mistakes.
- path: polylogue/storage/store.py
loc: 86
target: polylogue/storage/runtime/__init__.pyinit__.py
target: polylogue/storage/runtime/__init__.pystore.py

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This target path looks like an accidental concatenation (__init__.py + store.py). If polylogue/storage/store.py is intended to become the package entrypoint for storage/runtime/, the target should likely be polylogue/storage/runtime/__init__.py (or polylogue/storage/runtime/store.py), not __init__.pystore.py.

Suggested change
target: polylogue/storage/runtime/__init__.pystore.py
target: polylogue/storage/runtime/store.py

Copilot uses AI. Check for mistakes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a43a42f70

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread devtools/build_topology_projection.py Resolved
Sinity added a commit that referenced this pull request May 7, 2026
…ns (#456)

## Summary

Fixes a projection-rule defect surfaced by the topology-status dashboard
(PR #455). The rule was emitting `__init__.py` for any module whose name
equaled the subpackage prefix exactly, which caused multiple modules to
claim the same destination — 12 false-conflict rows in the dashboard.

## Problem

`build_topology_projection.py:lib_target()` and `storage_target()` use a
strip-prefix-then-stem rule. When the stem strips empty (e.g. module
`session_payload` matches prefix `session_payload`), the rule defaulted
to `__init__.py`. Two such modules in the same cluster collide:

- `lib/session/__init__.py` claimed by `session_payload`,
`session_summaries`, `session_profile`
- `storage/runtime/__init__.py` claimed by `store_runtime` (the
catch-all prefix)

`devtools verify-topology` reports `conflicts: 12` and the dashboard
shows them in its conflicts column.

## Solution

New resolver:

```python
def _resolve_target(name: str, sub: str, prefix: str) -> str:
    stem = name[len(prefix):]
    if not stem:
        # Module name == prefix; preserve full name to avoid colliding at __init__.py.
        return f"polylogue/{sub}{name}"
    if not stem.endswith(".py"):
        stem = stem + ".py"
    stem = stem.lstrip("_")
    if not stem or stem == ".py":
        return f"polylogue/{sub}{name}"
    return f"polylogue/{sub}{stem}"
```

After regen: `verify-topology --json` reports `conflicts: 0`. Dashboard
column will read 0 once this and #455 are both merged.

## Verification

```
$ devtools build-topology-projection
$ devtools verify-topology --json | jq '.counts'
{"orphans": 0, "missing": 0, "conflicts": 0, "kernel_rule": 0, "tbd": 39}

$ devtools verify --quick
verify: all checks passed (incl. all 8 lints)
```

## Related

- #429 — projection lint pattern.
- #455 — topology drift dashboard (sibling PR; conflicts column will
read 0 after both merge).
- #424 / #425 — refactors that consume the projection.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants