Skip to content

follow-up: multi-attribution entrypoint targets can lose their flag on unrelated file's rebuild #2419

Closed as not planned

Description

@carlos-alm

Deferred from PR #2411 review (Greptile finding on src/domain/graph/builder/stages/build-edges.ts / mirrored crates/codegraph-core/src/domain/graph/builder/pipeline.rs, mark_entrypoint_targets / markEntrypointTargets).

Context: #2411 fixes a real staleness bug where a program-entrypoint flag (nodes.entrypoint, #2392) survived after its attributing call was deleted or renamed across files, because the clear query re-derived the target from live calls edges that were already purged by the time it ran. The fix adds a single-owner nodes.entrypoint_source_file column: the flag is cleared by matching this column instead of re-querying edges, which is correct and lifecycle-independent for the common case.

Residual gap: attribution is single-owner — one entrypoint_source_file per target row. If two different files both legitimately call the same target as their own program entrypoint (e.g. two __main__.py stubs in a monorepo both calling a shared cli.main()), only the file that most recently ran the mark step "owns" the attribution. If that owning file is later rebuilt and no longer calls the target (guard removed/renamed), the target's flag is correctly cleared — but the other file that still legitimately calls it as an entrypoint gets no chance to re-assert ownership until IT is independently rebuilt, so the target incorrectly loses its entry role / live-root status in the interim.

Fix sketch: replace the single scalar column with a many-to-many attribution table, e.g. entrypoint_marks(source_file TEXT, target_id INTEGER, PRIMARY KEY(source_file, target_id)). On rebuild of file X: delete entrypoint_marks WHERE source_file = X, recompute nodes.entrypoint for any target whose row count in entrypoint_marks dropped to zero (clear) or rose above zero (mark), then insert X's fresh attributions. Needs the equivalent change in both engines (crates/codegraph-core/ and src/) to preserve parity.

This is worth its own PR — it is a materially larger schema/logic change than the staleness fix in #2411, and the failure mode (two files intentionally sharing one entrypoint target) is narrow enough not to block that fix.

Activity

  1. added
    follow-upDeferred work from PR reviews that needs tracking
    on Aug 10, 2026
  2. carlos-alm commented on Aug 16, 2026

    @carlos-alm
    ContributorAuthor

    Verified against current `main`: this is already fixed.

    Reproduced the exact scenario described — two files (`app_a.py`, `app_b.py`) each with an `if name == "main":` guard calling the same shared target (`shared_main` in `lib.py`), then removing `app_a`'s guard and rebuilding only `app_a` incrementally:

    ```
    BEFORE: {"entrypoint":1,"entrypoint_source_file":"app_a.py","role":"entry"}
    AFTER removing app_a's guard: {"entrypoint":1,"entrypoint_source_file":"app_b.py","role":"entry"}
    ```

    `shared_main` correctly stays flagged as an entrypoint — attribution transfers to `app_b.py`, the remaining valid owner, rather than clearing. Confirmed on both engines (wasm/native).

    This works because the single-owner `entrypoint_source_file` column approach this issue was filed against (#2411's fix) was superseded by a different mechanism in PR #2434 ("fix(roles): persist Python entrypoint evidence so attribution survives rebuilds", #2428/#2433): per-file guard-call evidence is now persisted in an `entrypoint_calls(file, name)` table, and `nodes.entrypoint`/`entrypoint_source_file` are re-projected from that evidence (joined against live `calls` edges) at the end of every build — see `projectEntrypointAttribution` / `project_entrypoint_attribution`. Rebuilding `app_a` only deletes `app_a`'s own evidence row; `app_b`'s evidence is untouched, so the projection still finds it and re-marks the target. This is effectively the same "don't lose attribution while any legitimate owner survives" property this issue's fix sketch (a many-to-many `entrypoint_marks` table) asked for, achieved by a different but equivalent design that landed for an unrelated reason (rebuild-lifecycle staleness, not multi-attribution) before this issue was ever picked up.

    Closing as already resolved — no code change needed.

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

    follow-upDeferred work from PR reviews that needs tracking

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions