Skip to content

fix: keep indirect consumers in dead-code analysis - #183376

Merged
shakkernerd merged 2 commits into
mainfrom
analyzer-consumer-model-359
Oct 25, 2026
Merged

shakkernerd merged 2 commits into
mainfrom
analyzer-consumer-model-359

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The unused-export checks misclassify live functions when their consumers enter the source graph through MCP namespace selection, Python-emitted imports, a typed CLI shim, or maintained tests outside the script scan's existing roots. That makes the checks recommend deleting behavior that is still exercised while obscuring whether a finding represents a genuinely unused export.

User Impact

There is no runtime or user-visible behavior change. Maintainers can rely on the production, full-tree, and script export scans to retain these real consumers while continuing to report unrelated unused exports; MCP, Python instrumentation, docs tooling, CI routing, Docker pruning, and reliability behavior are unchanged.

Why This Change Was Made

The existing analyzer already owns source-derived projections for generated and dynamically selected imports. This change extends that owner instead of changing producers or adding exceptions:

  • MCP edges come from the namespaces actually loaded by agent-bundle-mcp-runtime-modules.ts and the members actually selected by agent-bundle-mcp-runtime.ts.
  • Python edges come only from active edit(...) transformations and the import declarations emitted by session-row-churn-instrument.py; the instrumenter and benchmark are not executed.
  • Literal runNodeCliShim and runTsxCliShim implementations become side-effect imports, so their internal imports are reachable without treating every implementation export as a public entry.
  • The script scan includes the exact maintained source tests that consume these helpers, without a broad src glob or a new ignore.

The compiler contract removes each projected edge when its real source consumer disappears and verifies that typed implementations remain auditable.

Evidence

Remote validation ran on the exact final tree 0a78cf68105a9254f7eb72b9f7e0cd4d9143f316:

  • Changed-file formatting and selected lint passed.
  • The canonical production and test type graphs passed for core, UI, extensions, scripts, and root tests.
  • 225 assertions passed across the analyzer contract and the maintained docs, CI-scope, Docker-prune, and reliability consumers; after independent review identified the sibling Node shim, the invalidated analyzer contract passed all 20 focused assertions again.
  • The final production/full-tree/script export-scan run removed all assigned MCP, Python, docs, CI-scope, prune, and reliability rows. Its aggregate remained truthfully nonzero for unrelated findings outside this PR, confirming that unused-export detection was not weakened.

Hosted CI, independent review, and the repository's exact-head automated review remain pending on the published head. No runtime MCP session or Python benchmark was run because this PR changes only analyzer modeling and its contract tests.

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@shakkernerd shakkernerd self-assigned this Oct 25, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR models indirect MCP, Python-generated, CLI-shim, and maintained-test consumers in unused-export analysis.

Example: The MCP runtime selects projectBundleMcpServerCatalog through its lazy module loader.

  • Before: The analyzer lacks an explicit named consumer edge and can report the live export as unused.
  • After: The compiler derives that named import from the loader and runtime selection.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful, scoped repair supported by source inspection and green exact-head CI; supplied behavioral evidence is primarily narrative and configuration-level tests.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; it reports production/full-tree/script scans on the verified tree removing the targeted findings while retaining unrelated findings, without attached terminal output.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Maintainers receive unused-export findings for functions that still have real consumers.
Reason: The maintainer-authored direction preserves the established hard-zero audit contract and adds no runtime policy or public configuration.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it repairs concrete analyzer blind spots using the existing owner, and no introduced correctness or security defect was found.

Priority: P2
Reviewed head: dd454ffb2ffdf09112ac8abd22dd7778f6be8bbb

Before merge

None.

Findings

None.

Tests

  • Low-value test test/scripts/check-deadcode-exports.test.ts: Remove the copied ten-path configuration inventory and incidental synthetic-alias numbering assertions; retain the consumer-removal controls and shim reachability/export-audit checks.
  • Missing end-to-end proof: Canonical analyzer scans are reported on the matching tree, but their output and a base-red/head-green transcript are not attached.
Agent review details

How this fits together

Repository dead-code commands feed source files and configuration through Knip compilers, which project otherwise invisible imports into the graph used to report unused files and exports.

flowchart LR
  A[Source consumers] --> B[Dynamic consumer compiler]
  C[CLI shims] --> D[MJS compiler]
  E[Maintained tests] --> F[Script scan roots]
  B --> G[Knip analysis]
  D --> G
  F --> G
  G --> H[Unused export findings]
Loading

Technical review

Best possible solution:

Keep exact source-derived edges in the existing compilers while preserving independent production, full-tree, and script export audits.

Do we have a high-confidence way to reproduce the issue?

Source inspection confirms live indirect consumers and missing current-main projections; the PR reports their findings disappearing in canonical scans, but this review ran no target code.

Is this the best way to solve the issue?

The patch uses the existing projection owner and narrowly adds real test roots, preserving typed-export auditing without broad ignores or changes to runtime producers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against de55ea305cbd.

Provenance checked

  • Dynamic consumer projections keeps the original intent (3940719: Model exact imports hidden behind generated source and module hooks while restoring findings when consumers disappear.)
  • Script scan roots keeps the original intent (7e1d93d: Audit real executable and test consumers across the repository without grandfathering unused exports.)
  • Typed CLI implementations keeps the original intent (c70aee2: Keep stable JavaScript entrypoints while making typed implementations the source of truth and auditing their exports separately.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Shakker: Raw commit 3940719 adds config/knip-dynamic-consumers.mjs:11 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3940719bedc7; files: config/knip-dynamic-consumers.mjs)

PR surface

Tests +95, Other +142. Total +237 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 95 0 +95
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 142 0 +142
Total 4 237 0 +237

Labels

Label changes:

  • add P2: Incorrect unused-export findings weaken maintainer cleanup and CI diagnostics, with no demonstrated end-user runtime regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Incorrect unused-export findings weaken maintainer cleanup and CI diagnostics, with no demonstrated end-user runtime regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 25, 2026, 3:31 AM ET / 07:31 UTC.

@shakkernerd
shakkernerd merged commit 3db36fc into main Oct 25, 2026
105 of 106 checks passed
@shakkernerd
shakkernerd deleted the analyzer-consumer-model-359 branch October 25, 2026 07:43
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Fixed: Dead-code analysis now follows indirect live consumers while preserving genuine unused-export findings.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
Dead-code analysis now follows source-derived MCP, generated Python, typed CLI shim, and maintained test consumers while preserving genuine unused-export findings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant