Public report of headroomlabs-ai/headroom, published 14 November 2026. It has the same score, grades and number of
findings as the full report. The details of security findings (where they are in the code, which known
vulnerabilities and which passwords or keys were found) are left out, so nobody can use them against the project.
Public
Executive reportMeasured under the Code Assurance Index, an open standard for code quality, using its published scoring rules (rubric version 2026.11.4). Assert signed this survey and filed it in the standard's public register, where anyone can look it up by its survey ID. Check this survey →
Signed and filed in the standard's public register, 14 November 2026, 01:56 UTC · Survey ID cd_83433fbe8d504b90b3099aad42006c9c
headroomlabs-ai/headroom
Measured 14 November 2026, 01:55 UTC, at code version 0368a87
Code coverage is not measured: JavaScript/TypeScript suite (CouldNotMeasureTestRunFailed).
CAI scoreAt riskUp 2 since the last survey
The score is built from these lenses. Each lens grades one area of the code, such as how easy it is to change or how well it is protected. The weakest lens counts most, so one weak area pulls the score down instead of being averaged away.
A large codebase: 324,979 lines of product code in 12 projects, tests not counted · Estimated rebuild effort: about 4.7 person-years · Weakest lens: Domain Modelling, 10
Findings by how serious they are
60 critical2050 serious204 minor
15 dimensions are left out of the score. For each one, we either couldn't measure it in this code, or found no evidence of the safeguard we look for, such as a tested backup restore. They count neither for nor against the score, and Limitations lists each one with its reason.
This survey was produced by
Canine Code Analyzer
Producer
Canine Development
Analyzer
Canine Code Analyzer engine 1.0.0
Measured
14 November 2026, 01:55 UTC
A measurement, not a certificate. The Code Assurance Index records a number
together with the evidence it was worked out from, so anyone can recalculate it, but it doesn't certify or guarantee
the code. The standard was written by Canine Development, which also builds the Canine Code Analyzer. It is open to any tool that
implements it, and today the Canine Code Analyzer is the only one that does.
A critical security finding is open, such as a library with a known critical vulnerability or a password or key found in the code. The score itself is unchanged, but its band shows At risk until the finding is fixed. See the Security and Compliance lens.
The score is deterministic, which means the same code always gets the same score. We work it out with tools that follow published rules, and an AI model never decides it, so anyone who applies the same rules to the same code gets the same number. How it is done is explained under Methodology ▸
85of 85 dimensions measured by tools.
2286of 2314 findings point to an exact file and line, so you can open each one in the code. The other 28 concern the repository as a whole, such as missing documentation.
85dimensions across 8 lenses, read from 324,979 lines of product code in 12 projects.
headroomlabs-ai/headroom is rated At risk because critical security findings are open, most of them in the packages it uses. It scores 38 out of 100, which the At risk rating leaves unchanged. We judged it as a preview release, against a lower bar.
Domain Modelling, at 10, is the weakest lens and counts most in the score. The best first step is moving database and web code out of the business core, worth about 23 points. Raising Domain Modelling to 65 would lift the score to about 60.
Thirty known security holes in the packages the code depends on can be used by attackers. Twenty-one pipeline steps install packages that can change without warning, and two automatic updates take new releases before a bad one can be spotted. Updating the vulnerable packages, pinning what the pipeline installs and setting a waiting period for automatic updates would close these risks. Fixing the weaknesses the scanner points to would fix the security weakness in the code, and the password or key in the code needs replacing, with the old one switched off. The two uses of packages that aren't listed need adding to the project's list of dependencies.
The product code is 324,979 lines, about €680,000 to rebuild.
A lens is capped at Adequate while one of its dimensions scores below 4 out of 10, however well the rest of the lens does. That way a serious problem in one place always shows in the lens's rating.
How the score is built: what each lens counts forThe lenses don't count equally. The weakest lens counts most, the next weakest a little less, and so on, so a weak area pulls the score down instead of being averaged away. In the bar below, each part's width shows how much that lens counts and its colour shows its rating. Improving the widest part moves the score most, and as that lens improves, it counts for less, because another lens becomes the weakest.
If Domain Modelling rose from 10 to 65, the lowest score rated Strong, the score would rise from 38 to about 60.
Code composition: what the lines of code are
Product code 49%Tests 51%
New since the last survey: 433 findings
These 433 critical or serious findings weren't in the previous survey, on 25 October 2026. The first 100 are listed here, and the findings file in the download package lists them all.
God Classes · MethodTooLong: DiffCompressor.compress_with_ccr_source crates/headroom-core/src/transforms/diff_compressor.rs
God Classes · FileTooLong: src/transport.ts plugins/opencode/src/transport.ts
God Classes · TooManyMethods: AnthropicHandlerMixin REDACTED
God Classes · TooManyMethods: TrafficLearner headroom/memory/traffic_learner.py
God Classes · FileTooLong: tokenizers/base.py headroom/tokenizers/base.py
God Classes · FileTooLong: providers/proxy_routes.py headroom/providers/proxy_routes.py
Code Duplication · Near-duplicate member pair (211 shared lines) crates/headroom-proxy/src/bedrock/invoke.rs
Code Duplication · Near-duplicate member pair (105 shared lines) crates/headroom-proxy/src/compression/live_zone_openai.rs
Code Duplication · Near-duplicate member pair (52 shared lines) headroom/evals/core.py
Code Duplication · Edited copy of a member (40 corresponding lines) headroom/providers/openai.py
Code Duplication · Members sharing a duplicated core (7 members, 50+ identical tokens) headroom/cli/evals.py
Code Duplication · Members sharing a duplicated core (5 members, 50+ identical tokens) headroom/backends/anyllm.py
Code Duplication · Members sharing a duplicated core (5 members, 50+ identical tokens) headroom/proxy/handlers/batch.py
Code Duplication · Members sharing a duplicated core (4 members, 50+ identical tokens) headroom/backends/litellm.py
Code Duplication · Members sharing a duplicated core (4 members, 50+ identical tokens) REDACTED
Code Duplication · Members sharing a duplicated core (4 members, 50+ identical tokens) headroom/integrations/langchain/chat_model.py
Code Duplication · Members sharing a duplicated core (4 members, 50+ identical tokens) headroom/memory/adapters/embedders.py
Code Duplication · Members sharing a duplicated core (4 members, 50+ identical tokens) headroom/memory/writers/claude_writer.py
Code Duplication · Members sharing a duplicated core (4 members, 50+ identical tokens) REDACTED
Code Duplication · Members sharing a duplicated core (4 members, 50+ identical tokens) headroom/proxy/handlers/gemini.py
Code Duplication · Edited copy of a member (97 corresponding lines) headroom/audit/maturation.py
Code Duplication · Edited copy of a member (76 corresponding lines) headroom/learn/plugins/opencode.py
Code Duplication · Edited copy of a member (97 corresponding lines) headroom/integrations/agno/model.py
Code Duplication · Edited copy of a member (67 corresponding lines) crates/headroom-core/src/transforms/log_compressor.rs
Code Duplication · Edited copy of a member (75 corresponding lines) headroom/evals/runners/compression_only.py
Code Duplication · Edited copy of a member (66 corresponding lines) crates/headroom-proxy/src/bedrock/invoke.rs
Code Duplication · Edited copy of a member (76 corresponding lines) headroom/memory/adapters/graph.py
Code Duplication · Edited copy of a member (48 corresponding lines) crates/headroom-proxy/src/bedrock/invoke_streaming.rs
Code Duplication · Edited copy of a member (62 corresponding lines) headroom/integrations/agno/providers.py
Code Duplication · Edited copies of one member (3 members, 48+ corresponding lines) headroom/evals/batch_compression_eval.py
Code Duplication · Edited copy of a member (62 corresponding lines) headroom/memory/bridge_parsers.py
We compare every finding with the previous survey's. A finding that has only moved to another line in the same file counts as the same finding, so only new findings appear here. Advisory notes from the AI model are left out, because the model words them afresh in every survey.
Fixed since the last survey: 448 findings
These 448 critical or serious findings were in the previous survey, on 25 October 2026, and are gone from this one. The first 100 are listed here.
€230,000 to €1,100,000, for 3,769 to 11,956 hours of work, about 4.7 person-years for 2 to 9 engineers
Difficulty of the problem
Standard, judged from the kind of software and how it is built. Code that solves a harder problem, such as payments or medical bookings, costs more per line to write.
Quality factor
×0.7 at a score of 38. Better code takes more work to write, so the factor is ×1.0 at a score of 70, lower below it and higher above it.
Size
Large: 324,979 lines of product code
What it is not
Not a quotation: nobody has offered to build it for that. Not a valuation: it says nothing about what the business is worth. Not a certified figure: no professional has signed it as one.
How the estimate is made: We price the hours a team would need to write this code again, at €60 to €95 an hour. Declarations and boilerplate are priced at a fast rate and logic at a slower one, and the logic is then multiplied by the difficulty of the problem and by the quality factor. The estimate can be about 30% off either way, and it moves most with the hourly rate and the difficulty. For this code, every line is priced as straight logic, which keeps the estimate on the low side.
Top priorities
The three actions that raise the score most for the work they take. The full ranked list is in the Roadmap.
1
Keep the ORM/table mapping on a boundary data-model + mapper; leave the domain entity framework-free (map row↔domain through a repository).
Resolve the 1 Leaked secret finding(s) in Secret Scanning — start with REDACTED.
Raises the score by about 1 point · Low effort · Secret Scanning
3
Act on each finding's own remediation rather than one rule: the move depends on what recurs.
Where the copies are executable blocks, give the shared part one home and call it from each site; where they are declarations, a listing, a specialisation already delegating to its base, or one shape repeated per entity, there is no call site and the move is a shared type, a generated set or a factory — sometimes there is nothing to extract.
Raises the score by about 2 points · Medium effort · Code Duplication
Diagnosis: what the measurements show together
Each conclusion below combines several dimensions into one point that no single dimension shows, and lists the measurements it rests on.
Where the investment is most exposed · Value at risk
This code would cost about €680,000 to build again, about 4.7 person-years of work. Its weakest lens is Domain Modelling, at 10 (Critical). Domain Modelling is about whether the code protects the rules the business depends on. Because the weakest lens counts most in the score, work on Domain Modelling also moves the score most.
Based on: the rebuild estimate · the Domain Modelling grade · how much each lens counts
What to do: Start with the Domain Modelling actions in Top priorities.
If you do one thing first · First action
Keep the ORM/table mapping on a boundary data-model + mapper; leave the domain entity framework-free (map row↔domain through a repository). Of all the actions in this report, it raises the score most for the work it takes: about 23 points for medium effort. The next survey will show the change in the score.
Based on: the ranked actions in Top priorities, by score gain and effort
What hard-to-read code costs each year · Cost
Four dimensions measure how easy the code is to work in: two measure how tangled its logic is, one how much of it is copied, and one how well each part sticks to a single job. In this codebase they average 5.6 out of 10. Code at that level is slower to change than clean code, and we estimate the extra work at 6% to 13% on every change. The history of the code shows how much it changes: about 322,055 lines over the last 90 days, which is about 1,306,112 lines a year. At that pace, the extra work comes to an estimated 192 to 1152.2 engineer-days a year, and it grows as more code changes.
How this is estimated: The number of changed lines is measured from the history of the code. The rest rests on two assumptions of our own: code scoring 8 out of 10 or more adds no extra work, and each point below 8 adds 2.5% to 5.6% to every change, never less than 2% to 5% and never more than 40% to 60% in all; and an engineer changes 150 to 400 lines in a day. The result is a range for planning, not a measurement.
Based on: Cyclomatic Complexity · Cognitive Complexity · Code Duplication · Cohesion (LCOM4) · the code's change history
What to do: Start with the files listed under Churn × Complexity Hotspots, which change often and are hard to read, because that is where the extra work is paid most often.
Architecture — module dependency graph
Project dependencies, layered top-to-bottom; arrows show direction. Any dashed red edge points upward or sideways, which only happens where the projects form a dependency cycle. A graph without cycles has none.
Architecture: which parts of the code depend on which
The code is divided into modules, groups of code that each handle one part of the product, and a module depends on another when it uses code from it. The table lists the modules both down the side and across the top, in an order where each module should only use modules listed above it. A number in a cell means the module on that row uses the module in that column, and it counts the pairs of building blocks (types) that connect them. The one thing to look for is a mark above the diagonal line. It means two or more modules use each other in a loop (a dependency cycle), so none of them can be changed, tested or released on its own.
596 modules, with 544 dependencies between them. 4 loops run through 10 of the modules, marked above the diagonal.
The table shows the 40 modules with the most connections; 556 more are left out to keep it readable.
Which modules use which. The module on each row uses the module in each column, and the number counts the pairs of types that connect them. A cell above the diagonal is part of a loop.
headroom.cache.compression_store uses headroom.memory.tracker, so a change to headroom.memory.tracker can break headroom.cache.compression_store, while a change to headroom.cache.compression_store can't break headroom.memory.tracker.
Position
Below the diagonal: headroom.cache.compression_store uses a module listed above it, which is the healthy direction.
headroom.cli uses headroom.install.models, so a change to headroom.install.models can break headroom.cli, while a change to headroom.cli can't break headroom.install.models.
Position
Below the diagonal: headroom.cli uses a module listed above it, which is the healthy direction.
headroom.cli uses headroom.memory.models, so a change to headroom.memory.models can break headroom.cli, while a change to headroom.cli can't break headroom.memory.models.
Position
Below the diagonal: headroom.cli uses a module listed above it, which is the healthy direction.
headroom.learn.writer uses headroom.learn.models, so a change to headroom.learn.models can break headroom.learn.writer, while a change to headroom.learn.writer can't break headroom.learn.models.
Position
Below the diagonal: headroom.learn.writer uses a module listed above it, which is the healthy direction.
headroom.memory.ports uses headroom.memory.models, so a change to headroom.memory.models can break headroom.memory.ports, while a change to headroom.memory.ports can't break headroom.memory.models.
Position
Below the diagonal: headroom.memory.ports uses a module listed above it, which is the healthy direction.
headroom.providers uses headroom.install.models, so a change to headroom.install.models can break headroom.providers, while a change to headroom.providers can't break headroom.install.models.
Position
Below the diagonal: headroom.providers uses a module listed above it, which is the healthy direction.
headroom.proxy.server uses headroom.proxy.models, so a change to headroom.proxy.models can break headroom.proxy.server, while a change to headroom.proxy.server can't break headroom.proxy.models.
Position
Below the diagonal: headroom.proxy.server uses a module listed above it, which is the healthy direction.
headroom.tokenizer uses headroom.providers.base, so a change to headroom.providers.base can break headroom.tokenizer, while a change to headroom.tokenizer can't break headroom.providers.base.
Position
Below the diagonal: headroom.tokenizer uses a module listed above it, which is the healthy direction.
headroom_core.transforms.smart_crusher.crusher uses headroom_core.transforms.smart_crusher.config, so a change to headroom_core.transforms.smart_crusher.config can break headroom_core.transforms.smart_crusher.crusher, while a change to headroom_core.transforms.smart_crusher.crusher can't break headroom_core.transforms.smart_crusher.config.
Position
Below the diagonal: headroom_core.transforms.smart_crusher.crusher uses a module listed above it, which is the healthy direction.
headroom_proxy.proxy uses headroom_core.auth_mode, so a change to headroom_core.auth_mode can break headroom_proxy.proxy, while a change to headroom_proxy.proxy can't break headroom_core.auth_mode.
Position
Below the diagonal: headroom_proxy.proxy uses a module listed above it, which is the healthy direction.
headroom_proxy.proxy uses headroom_proxy.config, so a change to headroom_proxy.config can break headroom_proxy.proxy, while a change to headroom_proxy.proxy can't break headroom_proxy.config.
Position
Below the diagonal: headroom_proxy.proxy uses a module listed above it, which is the healthy direction.
30→36 headroom_proxy.proxy uses headroom_proxy.observability.capturepart of a loop✕
Connections
1 pair of types, where a type in headroom_proxy.proxy uses a type in headroom_proxy.observability.capture.
headroom_proxy.proxy uses headroom_proxy.observability.capture, so a change to headroom_proxy.observability.capture can break headroom_proxy.proxy, while a change to headroom_proxy.proxy can't break headroom_proxy.observability.capture.
Position
Above the diagonal, so it is part of a loop. Neither module can be changed, tested or released on its own until one of these dependencies is removed.
headroom uses headroom.providers.base, so a change to headroom.providers.base can break headroom, while a change to headroom can't break headroom.providers.base.
Position
Below the diagonal: headroom uses a module listed above it, which is the healthy direction.
headroom uses headroom.relevance.base, so a change to headroom.relevance.base can break headroom, while a change to headroom can't break headroom.relevance.base.
Position
Below the diagonal: headroom uses a module listed above it, which is the healthy direction.
headroom.learn.base uses headroom.learn.models, so a change to headroom.learn.models can break headroom.learn.base, while a change to headroom.learn.base can't break headroom.learn.models.
Position
Below the diagonal: headroom.learn.base uses a module listed above it, which is the healthy direction.
headroom.learn.base uses headroom.learn.writer, so a change to headroom.learn.writer can break headroom.learn.base, while a change to headroom.learn.base can't break headroom.learn.writer.
Position
Below the diagonal: headroom.learn.base uses a module listed above it, which is the healthy direction.
headroom.memory uses headroom.memory.ports, so a change to headroom.memory.ports can break headroom.memory, while a change to headroom.memory can't break headroom.memory.ports.
Position
Below the diagonal: headroom.memory uses a module listed above it, which is the healthy direction.
headroom.transforms.base uses headroom.config, so a change to headroom.config can break headroom.transforms.base, while a change to headroom.transforms.base can't break headroom.config.
Position
Below the diagonal: headroom.transforms.base uses a module listed above it, which is the healthy direction.
headroom.transforms.base uses headroom.tokenizer, so a change to headroom.tokenizer can break headroom.transforms.base, while a change to headroom.transforms.base can't break headroom.tokenizer.
Position
Below the diagonal: headroom.transforms.base uses a module listed above it, which is the healthy direction.
headroom_core.transforms.live_zone uses headroom_core.auth_mode, so a change to headroom_core.auth_mode can break headroom_core.transforms.live_zone, while a change to headroom_core.transforms.live_zone can't break headroom_core.auth_mode.
Position
Below the diagonal: headroom_core.transforms.live_zone uses a module listed above it, which is the healthy direction.
headroom_core.transforms.live_zone uses headroom_core.transforms.smart_crusher.crusher, so a change to headroom_core.transforms.smart_crusher.crusher can break headroom_core.transforms.live_zone, while a change to headroom_core.transforms.live_zone can't break headroom_core.transforms.smart_crusher.crusher.
Position
Below the diagonal: headroom_core.transforms.live_zone uses a module listed above it, which is the healthy direction.
headroom_proxy.observability.capture uses headroom_proxy.proxy, so a change to headroom_proxy.proxy can break headroom_proxy.observability.capture, while a change to headroom_proxy.observability.capture can't break headroom_proxy.proxy.
Position
Below the diagonal: headroom_proxy.observability.capture uses a module listed above it, which is the healthy direction.
headroom.transforms.content_router uses headroom.config, so a change to headroom.config can break headroom.transforms.content_router, while a change to headroom.transforms.content_router can't break headroom.config.
Position
Below the diagonal: headroom.transforms.content_router uses a module listed above it, which is the healthy direction.
headroom.transforms.content_router uses headroom.tokenizer, so a change to headroom.tokenizer can break headroom.transforms.content_router, while a change to headroom.transforms.content_router can't break headroom.tokenizer.
Position
Below the diagonal: headroom.transforms.content_router uses a module listed above it, which is the healthy direction.
headroom.transforms.content_router uses headroom.transforms.base, so a change to headroom.transforms.base can break headroom.transforms.content_router, while a change to headroom.transforms.content_router can't break headroom.transforms.base.
Position
Below the diagonal: headroom.transforms.content_router uses a module listed above it, which is the healthy direction.
headroom.transforms.smart_crusher uses headroom.config, so a change to headroom.config can break headroom.transforms.smart_crusher, while a change to headroom.transforms.smart_crusher can't break headroom.config.
Position
Below the diagonal: headroom.transforms.smart_crusher uses a module listed above it, which is the healthy direction.
headroom.transforms.smart_crusher uses headroom.tokenizer, so a change to headroom.tokenizer can break headroom.transforms.smart_crusher, while a change to headroom.transforms.smart_crusher can't break headroom.tokenizer.
Position
Below the diagonal: headroom.transforms.smart_crusher uses a module listed above it, which is the healthy direction.
headroom.transforms.smart_crusher uses headroom.transforms.base, so a change to headroom.transforms.base can break headroom.transforms.smart_crusher, while a change to headroom.transforms.smart_crusher can't break headroom.transforms.base.
Position
Below the diagonal: headroom.transforms.smart_crusher uses a module listed above it, which is the healthy direction.
headroom.proxy uses headroom.memory.tracker, so a change to headroom.memory.tracker can break headroom.proxy, while a change to headroom.proxy can't break headroom.memory.tracker.
Position
Below the diagonal: headroom.proxy uses a module listed above it, which is the healthy direction.
headroom.proxy uses headroom.proxy.models, so a change to headroom.proxy.models can break headroom.proxy, while a change to headroom.proxy can't break headroom.proxy.models.
Position
Below the diagonal: headroom.proxy uses a module listed above it, which is the healthy direction.
headroom.proxy uses headroom.proxy.server, so a change to headroom.proxy.server can break headroom.proxy, while a change to headroom.proxy can't break headroom.proxy.server.
Position
Below the diagonal: headroom.proxy uses a module listed above it, which is the healthy direction.
headroom.proxy uses headroom.transforms.content_router, so a change to headroom.transforms.content_router can break headroom.proxy, while a change to headroom.proxy can't break headroom.transforms.content_router.
Position
Below the diagonal: headroom.proxy uses a module listed above it, which is the healthy direction.
headroom.transforms uses headroom.relevance.base, so a change to headroom.relevance.base can break headroom.transforms, while a change to headroom.transforms can't break headroom.relevance.base.
Position
Below the diagonal: headroom.transforms uses a module listed above it, which is the healthy direction.
headroom.transforms uses headroom.tokenizer, so a change to headroom.tokenizer can break headroom.transforms, while a change to headroom.transforms can't break headroom.tokenizer.
Position
Below the diagonal: headroom.transforms uses a module listed above it, which is the healthy direction.
headroom.transforms uses headroom.transforms.content_router, so a change to headroom.transforms.content_router can break headroom.transforms, while a change to headroom.transforms can't break headroom.transforms.content_router.
Position
Below the diagonal: headroom.transforms uses a module listed above it, which is the healthy direction.
At a glance — Code Health · 53% · Adequate · gated by D1, D2, R10 ·
Findings mapped to OWASP categories; the specific CVEs/secrets are in the Security dimension cards below and findings.md (redacted only on the public version of this report).
OWASP category
Findings
Severity
A05:2025 — Injection
96
High / Critical
A03:2025 — Software Supply Chain Failures
61
High / Critical
A02:2025 — Security Misconfiguration
20
High / Critical
A07:2025 — Authentication Failures
1
High / Critical
Roadmap
Top priorities: Keep the ORM/table mapping on a boundary data-model + mapper; leave the domain entity framework-free (map row↔domain through a repository); Act on each finding's own remediation rather than one rule: the move depends on what recurs. Where the copies are executable blocks, give the shared part one home and call it from each site; where they are declarations, a listing, a specialisation already delegating to its base, or one shape repeated per entity, there is no call site and the move is a shared type, a generated set or a factory — sometimes there is nothing to extract; Resolve the 1 Leaked secret finding(s) in Secret Scanning — start with REDACTED.
Ranked by impact ÷ effort. "Helps" is the estimated gain on the 0–100 health score.
Do this
Helps
Effort
Dimension
Keep the ORM/table mapping on a boundary data-model + mapper; leave the domain entity framework-free (map row↔domain through a repository).
Act on each finding's own remediation rather than one rule: the move depends on what recurs. Where the copies are executable blocks, give the shared part one home and call it from each site; where they are declarations, a listing, a specialisation already delegating to its base, or one shape repeated per entity, there is no call site and the move is a shared type, a generated set or a factory — sometimes there is nothing to extract.
Bring the 67 bodies over 60 down to 60 or less in Cognitive Complexity — start with AnthropicHandlerMixin.handle_anthropic_messages (cognitive 650), ContentRouter.apply (cognitive 435), wrap._ensure_proxy_unlocked (cognitive 328).
Every finding carries one of four grades. Three say how serious it is. The fourth says this
survey could not settle it — and it is a grade, not a gap.
Critical — 60
A definite problem that already costs you something and drags the score down: a
missing authorisation check, a dependency with a known exploit, a build that does not reproduce. Failure here
tends to cause failures elsewhere.
Serious — 2050
Likely wrong, but not failing yet. It degrades
the codebase over a longer horizon and can cause failures elsewhere — not urgent this week, not something to
carry for two years either.
Minor — 204
Recorded, with no effect on how the codebase functions.
Present so the survey is complete, not because it needs doing.
Could not be resolved — 15
Something this survey could not settle
from the outside, and which could be critical or serious. Either a control was required and no
positive evidence of it exists in the repository — a backup job that nothing shows was ever restored from proves
nothing about restores — or our own analysis could not run over that part of the tree. This is not a clean
result. These are excluded from the score rather than awarded a pass, so the number on the cover neither
rewards nor penalises them: if you act on this survey without resolving them, you carry that risk yourself. Each
one is named under Limitations.
Methodology & how to trust this report
This survey is a deep, periodic assessment — run each sprint, monthly, or quarterly, taking the time to go wider and deeper than a quick check and surfacing in one coherent report what you'd otherwise piece together from a dozen separate tools. It scores deterministically: the same commit yields the same score, every run. All 85 evaluated dimensions are computed by tools and static analysis; no language model sets or judges any of them. Overall confidence is 0.9, the weighted average across measured dimensions.
Every figure here is one of two kinds, and we label which: ✓ Measured — a deterministic fact (LoC, complexity, coverage); ~ Modeled — an estimate from a stated model (cost, effort, value-at-risk), always a range with its assumptions, never a precise fact. We never present a modelled estimate as if it were measured. Perfect or absent scores carry their provenance too (ADR-0011): ✓ Tool-verified means the property itself was measured across the surface; ○ Nothing flagged means the probes came back clean — a claim bounded by what a repository can show; ⊘ Not evidenced means a working control (a tested restore, an automated rollback) showed no positive evidence — absence of evidence is not evidence of a control, so it's excluded from the score rather than awarded a spurious 10.
What we checked — 85 dimensions across the health lenses
Each chip is a dimension scored from real signals across architecture, testing, dependencies, security & compliance, documentation, git-history and code quality — in one coherent pass. A surface report typically covers a handful.
How to trust any code-health report — three questions
Can you open the finding? Real findings cite a repo-relative file and line you can open at the cited line — never an absolute scratch path. Here, 2286 of 2314 do; the remainder are repo-wide signals — a dimension-level measurement, not a single line. (Every path in this report is repo-relative by construction: paths are normalized at the producer and the report is rejected if any rooted path leaks through.)
Is there a tool behind the number? Every score below names the method that produced it: Roslyn, git or a scanner, not a narrative.
Does re-running give the same result? Run it again on the same commit and the score — and this report, byte for byte — is identical. A report whose numbers move between runs is describing the run, not the code.
This report answers yes to all three. That's the bar to hold any assessment to.
Tools & methods
The actual versions used this run (captured at analysis time) — re-run on the same commit for the identical score.
Method
Backs
Version
Evaluator
Roslyn static analysis
Complexity, cohesion, coupling, dead code, API surface, layering
What ran differently this time — a tool absent, degraded, or that fell back to an estimate. Named openly, not folded silently into the scores. A degraded run also records its exact cause in diagnostics.md.
D10 Test Quality — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. The 709 test(s) behind this row are the ones the JavaScript/TypeScript census could read, and this repository also carries at least 1,230 test source file(s) (.py, .rs) that it cannot: it reads JavaScript/TypeScript test declarations off disk, so a JUnit/pytest-style suite is invisible to it. Skipped tests, zero-assertion tests and the other quality signals on this row are UNMEASURED in that suite — their absence from the counts above is a gap in this analyzer's language coverage, not a finding that those tests are sound.
D11 Test Reliability — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. Test reliability NOT SCORED: this repository's production source includes .rs, and the rust executor ran against the .rs half and did not finish re-running within its tier budget — so reliability was not measured for the repository as a whole. The JavaScript/TypeScript (node:test via `npm ci --ignore-scripts` in e2e/wrap/tools/ (4 tests); vitest via `npm ci --ignore-scripts` in plugins/openclaw/ (160 tests); vitest via `npm ci --ignore-scripts` in plugins/opencode/ (96 tests); vitest via `npm ci --ignore-scripts` in sdk/typescript/ (479 tests)): measured (0 flaky); Python (2 distributions): measured (0 flaky) suite(s) did re-run, and came back with 0 flaky across 2 measured tier(s) — but that is a figure for one half of the product, and we do not publish a partial one as if it were complete. This is OUR limitation, not a defect in the repo — test reliability is excluded from the score rather than counted. The half was driven by a runner we ship, so this is not a missing-runner gap.
D14 License Compliance — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. This repository declares a Python REDACTED/requirements.txt (pip/uv/Poetry), but the licence verdict published here was taken over its crate dependencies. Nothing was read about its Python dependencies' licensing in either direction, and a clean score on this card must not be read as covering them.
D14 License Compliance — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. This repository declares package.json, but the licence verdict published here was taken over its crate dependencies. Nothing was read about its npm dependencies' licensing in either direction, and a clean score on this card must not be read as covering them.
D19 Documentation Quality — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. Each ecosystem's manifests (what makes a folder runnable or a published package) need their own proof before D19 judges its units. Until then those folders' READMEs are judged only as documents (boilerplate, structure), never counted as complete.
D21 Naming Consistency — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. D21's naming rules read C# through Roslyn and every other language through its sidecar model; these languages are left out (PHP's reading is its own change, a Roslyn-loaded VB or F# project has no population builder yet). Their declarations carry no naming verdict this run — this says nothing about whether their names are consistent.
D21 Naming Consistency — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. PREREGISTRATION version 20's fallback (adjudication D21-sample3-v3): this rule kind was adjudicated below the 95 % precision gate, so its candidates are counted here and not published, and the score covers only the acronym-spelling and awaitable-suffix rules. The kind returns as rows only after it shows a measured precision; this says nothing about whether these names are consistent.
D21 Naming Consistency — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. PREREGISTRATION version 20's fallback (adjudication D21-sample3-v3): this rule kind was adjudicated below the 95 % precision gate, so its candidates are counted here and not published, and the score covers only the acronym-spelling and awaitable-suffix rules. The kind returns as rows only after it shows a measured precision; this says nothing about whether these names are consistent.
D22 Internal API Consistency — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. D22's deterministic call-shape rules are gated on C# first (docs/plans/deterministic-engine.md, P5): each other language is switched on only after its own concept suite and A/B gate pass. This says nothing about whether that surface is consistent.
D24 Comment Value — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. Each source language's comment syntax, and the code a comment annotates in it, needs its own proof before D24 judges it. Until then those comments are left unread, not counted as clean.
D27 Navigability — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. Tracing effort is measured over resolved call sites, and all 753 sampled here came from .py files. This repository's .rs source is a material share of its production lines and contributed none, so the score above is a verdict about the part that was read. Not a finding that the unread half navigates well — it is unmeasured.
D32 Data Compliance (PII/GDPR) — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. `docs/components/mdx.tsx`, `headroom/providers/opencode/_dist/index.js` produced a parse error, so every rule in this engine's `gdpr.yml` was absent there. That absence is NOT a clean result: these rules detect personal data crossing a boundary into a log sink, a URL or browser storage, and a file that was never parsed cannot report any of the three. The rest of the tree analysed normally and its rows above stand; only these files are unaccounted for. You can widen what we reach: fix the syntax error (or exclude the file deliberately) and re-scan to cover it.
AX1 Captive dependencies — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads Microsoft.Extensions.DependencyInjection registrations in C# and Spring beans in Java/Kotlin only, and this repository defines its own container in headroom/transforms/compressor_registry.py, whose lifetimes are not modelled yet, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
AX6 Interface segregation — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check's reader does not cover most of the languages this repository's product is written in. What it read is kept, but it is too small a share to grade the product by. That is a gap in this analyzer's language reach — not a finding about this repository.
AXR1 Runtime accessibility — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. Render strategy: boot via DockerCompose (REDACTED). compose up failed (exit 15 — the compose project is invalid) — error while interpolating services.headroom-proxy.environment.[]: required variable HEADROOM_PROXY_TOKEN is missing a value: set HEADROOM_PROXY_TOKEN (see .env.example; e.g. openssl rand -hex 32); runtime evidence skipped.
C1 Data Protection — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. These personal data controls are read from declarative annotations, request middleware, entity/column names and guard methods in a C# source model, and none was loaded on this run, so there was nothing to gather. That is a gap in this analyzer's language reach — not a finding that the repository lacks personal data controls.
C2 Access Controls — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. These authorization controls are read from declarative annotations, request middleware, entity/column names and guard methods in a C# source model, and none was loaded on this run, so there was nothing to gather. That is a gap in this analyzer's language reach — not a finding that the repository lacks authorization controls.
C3 Audit Trail — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. These audit controls are read from declarative annotations, request middleware, entity/column names and guard methods in a C# source model, and none was loaded on this run, so there was nothing to gather. That is a gap in this analyzer's language reach — not a finding that the repository lacks audit controls.
C4 Data Retention — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. These retention controls are read from declarative annotations, request middleware, entity/column names and guard methods in a C# source model, and none was loaded on this run, so there was nothing to gather. That is a gap in this analyzer's language reach — not a finding that the repository lacks retention controls.
C5 Data-Subject Rights — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. These data-subject rights controls are read from declarative annotations, request middleware, entity/column names and guard methods in a C# source model, and none was loaded on this run, so there was nothing to gather. That is a gap in this analyzer's language reach — not a finding that the repository lacks data-subject rights controls.
GD1 Unfinished & placeholder code — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads C# syntax, F#, JavaScript/TypeScript, Dart, Ruby and Scala source only, and this repository's Python, Rust, c is most of its product and is not read yet, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
IC1 Incompleteness & stubs — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads C# syntax, JavaScript/TypeScript, Java, Dart, Ruby and Scala source only, and this repository's Python, Rust, c is most of its product and is not read yet, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
M4 Documentation accuracy — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. M4 checks only the claim kinds adjudicated at or above 95 % precision: links and versions (PREREGISTRATION version 9), and artefact counts an order of magnitude off. Paths, command arguments, installs, environment variables, settings, projects, packages, routes, cd targets, infrastructure products and removed modules are read but not checked, and none of them is reported or counted.
X10 Duplicated predicate — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. 84 further occurrence(s) are not listed individually; the score already reflects all 124.
X12 Unreachable branch — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. This check's reader does not cover every language in this repository. The score describes the part it read, which is most of the product; the rest is a gap in this analyzer's language reach.
X13 Undrained process stream — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. This check's reader does not cover every language in this repository. The score describes the part it read, which is most of the product; the rest is a gap in this analyzer's language reach.
X16 Unfloored truncation loop — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check's reader does not cover most of the languages this repository's product is written in. What it read is kept, but it is too small a share to grade the product by. That is a gap in this analyzer's language reach — not a finding about this repository.
X17 Uncapped recursion over a caller-supplied document — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. This check's reader does not cover every language in this repository. The score describes the part it read, which is most of the product; the rest is a gap in this analyzer's language reach.
X18 Disposal-pattern correctness — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check's reader does not cover most of the languages this repository's product is written in. What it read is kept, but it is too small a share to grade the product by. That is a gap in this analyzer's language reach — not a finding about this repository.
X19 Unrestored process-global state — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. This check's reader does not cover every language in this repository. The score describes the part it read, which is most of the product; the rest is a gap in this analyzer's language reach.
X23 Unguarded diagnostic materialisation — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. This check's reader does not cover every language in this repository. The score describes the part it read, which is most of the product; the rest is a gap in this analyzer's language reach.
X24 Document value interpolated into markup unescaped — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. This check's reader does not cover every language in this repository. The score describes the part it read, which is most of the product; the rest is a gap in this analyzer's language reach.
X25 Inert configuration knob — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. This check's reader does not cover every language in this repository. The score describes the part it read, which is most of the product; the rest is a gap in this analyzer's language reach.
X29 Per-element action decided by a fixed element — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check's reader does not cover most of the languages this repository's product is written in. What it read is kept, but it is too small a share to grade the product by. That is a gap in this analyzer's language reach — not a finding about this repository.
X3 Exception handling — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. This check's reader does not cover every language in this repository. The score describes the part it read, which is most of the product; the rest is a gap in this analyzer's language reach.
X3 Exception handling — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. 107 further occurrence(s) are not listed individually; the score already reflects all 147.
X4 Structured logging — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. 519 further occurrence(s) are not listed individually; the score already reflects all 559.
X7 Silent fallback defaults — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. 23 further occurrence(s) are not listed individually; the score already reflects all 63.
Repo exclusion declarations (.gitattributes linguist-generated/vendored, .editorconfig generated_code): none declared — every source file was scored.
Limitations & what we did not check
We assess the repository exactly as committed, and only the repository. By design we do not reach outside the source tree: the live cloud account, the running CI/CD pipeline, the host's branch-protection and approval rules, the production configuration, or a restore actually exercised against a backup are all out of scope. That boundary is a feature, not a gap — a repo-relative, deterministic scan re-runs identically on any commit and every finding opens at a real file and line, where a live audit can neither be reproduced nor traced. The visible consequence is that controls which leave no in-repo evidence are reported as "not evidenced" and excluded from the score rather than awarded a number a static scan cannot justify.
Per-dimension blind spots
For each dimension that was measured, what a static, repo-only scan structurally cannot see — the honest edge of the measurement, not a failure of it.
D1 Cyclomatic Complexity: Cyclomatic complexity counts branches statically — it cannot tell an essential decision tree from accidental tangle, nor see complexity that lives in data or configuration (large switch-case token tables, DSL lexers/parsers, data-as-code rule tables) rather than control flow: a tokenizer's many single-character cases read as high complexity though each branch is trivial.
D2 Cognitive Complexity: Cognitive-complexity heuristics approximate how hard code is to follow; genuine domain difficulty and well-named intent that eases reading are not captured.
D3 God Classes: "God class" is sized by members and responsibilities visible in the type — a deliberately broad facade over a coherent subsystem can read the same as an accidental grab-bag. For front-end JS the file-length check is cohesion-aware (a single-responsibility module — one class/IIFE — earns a 3× threshold), but cohesion is approximated from top-level declarations, not true dependency structure.
D4 Code Duplication: Duplication is token-similarity — an in-process token-stream comparison over sliding windows, with type-aware normalization — so it finds copy-paste, not semantic duplication expressed differently. Committed machine-written code (scaffolded migrations, designer/codegen output, protobuf/OpenAPI stubs, model snapshots) is EXCLUDED — its repetition is the tool's, not the team's — so the score reflects hand-written duplication only.
D5 Coupling: Coupling is measured between projects/assemblies — runtime coupling through DI, reflection, messaging or shared databases is invisible to a static reference graph.
D6 Cohesion (LCOM4): LCOM4 cohesion is syntactic — it infers connectivity from which methods touch which fields/methods by name, not from real runtime behaviour or intent.
D7 Architectural Integrity: Layering is checked against detected/declared rules — an architecture whose boundaries live in convention or in code review, not in a rule a scanner can read, is not enforced here.
D10 Test Quality: Assertion density is structural — it cannot tell a meaningful behavioural assertion from a trivial one, only that an assertion is present.
D12 Dependency Hygiene: Dependency health reads manifests and lockfiles — a vulnerability in a vendored/copied dependency, or risk from how a dependency is actually used, is outside this view.
D13 Secret Scanning: Secret detection is signature- and entropy-based on the current tree — a secret that does not match a known pattern, or one already rotated, will not be flagged (a clean scan is "nothing matched", not "no secrets exist").
D14 License Compliance: License compatibility is checked against declared package metadata and a policy — mislabelled or missing license metadata, and obligations that depend on how you distribute, are not resolved here.
D15 Churn × Complexity Hotspots: Churn hotspots come from git history — a freshly imported or squashed repository has no churn signal, and recent rewrites can mask a historically risky file.
D16 Bus Factor: Bus-factor is a time-decayed model of commit attribution (who has recently, repeatedly worked a file), not comprehension — pairing, review and reading-without-committing spread knowledge it can't see; bot commits and shared accounts still distort it.
D17 Explicit Debt: Acknowledged-debt signals (TODO/FIXME, suppressions, dead code) are textual — undocumented debt that nobody marked, and debt that lives in design rather than annotations, is invisible. Committed machine-written code (scaffolded migrations, designer/codegen output, generated stubs) is excluded — it is never the team's dead code to delete.
D19 Documentation Quality: Documentation quality publishes two things only: a runnable or packaged unit with no example, and a multi-project root README that maps none of its parts. It does not judge clarity, and its other checks (overview, licence, boilerplate, structure, empty sections, XML-doc coverage) are withheld after adjudication: their candidates are counted in the card's gaps, not shown as rows. A false statement in a document is M4's; units are .NET projects only.
D20 ADR Quality: ADR quality checks the structure of the decision records present: it cannot know about decisions made and never recorded, and it does not judge how well a record argues its case. Records in a language the section lexicon does not cover are not evaluated.
D21 Naming Consistency: Naming consistency compares each name with the convention its structural peers follow in this repository: it cannot tell whether a consistently used name is a good one, and languages other than C# and TypeScript are not measured.
D24 Comment Value: Comment value is measured as redundancy only: a comment that repeats its code's words is found, but a paraphrase in other words, a vague comment, or one the code contradicts is not, and whether a comment is valuable is not claimed. Comments in other scripts or languages, and outside C#, are not judged.
D26 Project Cohesion: Project focus is sized from members/namespaces per project — a project that is broad by deliberate design reads the same as one that has sprawled.
D27 Navigability: Indirection/navigability is structural — it measures hops to follow a call, not whether that indirection buys real flexibility or just ceremony.
D28 Secrets (history): Secret-history scanning sweeps the git log for known patterns — a secret that predates the available history, or never matched a signature, is not found (clean means "nothing matched in the history we can see").
D29 Static Analysis (SAST): SAST findings are pattern-based (semgrep) — it finds classes of bug it has rules for; logic flaws, auth/authorization gaps and issues needing runtime context are out of reach (and clean means "no rule matched").
D30 Dependency Vulnerabilities: CVE matching depends on accurate package/version metadata and on the advisory databases — a vulnerability with no published advisory, or in code not declared as a dependency, is not seen. Coverage needs a RESOLVED graph: an unpinned requirements.txt, or a pom without a resolved build, yields partial coverage rather than a clean verdict. An ecosystem the analyzer cannot scan is reported as unmeasured, never as clean.
D31 IaC & Container Security: IaC scanning checks Dockerfiles/Terraform/Kubernetes against best-practice rules — it cannot see the live cloud account, runtime configuration, or drift between the committed config and what is actually deployed.
D34 Knowledge Freshness: Freshness is decayed commit RECENCY, not comprehension — code read often but rarely committed reads as orphaned, and stable code that genuinely needs no changes is penalised the same as forgotten code; bot/squash commits distort it like the bus factor.
D35 Change Coupling: Change coupling is co-change in COMMITS — files split across separate commits, or coupled only through a shared config/build step, read as uncoupled, and a sweeping commit (rename/format) is excluded so it doesn't couple everything. It shows that files change together, not WHY: a high coupling can be a healthy cohesive pair as readily as a hidden leak.
D43 Malicious Dependencies: Only packages some vulnerability database has already NAMED as malicious are seen — a compromise published in the last hours, or never reported at all, is invisible here, and this dimension reading 10 is not evidence that a dependency is trustworthy. There is no typosquat or dependency-confusion analysis: a package nobody has reported is simply absent from the feeds. Coverage is the dependency scan's: an ecosystem that could not be scanned is disclosed as unmeasured, never as clean.
D44 Platform End-of-Life: The support table is FROZEN, so it goes out of date by losing RECALL: a release that ended support after the table was written is missed until the table is refreshed, and this dimension reading 10 is not evidence that a platform is current. Only platforms the repository DECLARES in a place this pass reads are seen — a runtime named only in a REDACTED (D31's subject), in a CI workflow (D29's), or in a file this pass does not parse (go.mod, a Gemfile ruby directive) is invisible here, which is why a repository declaring none of them abstains rather than scoring. Only frameworks with a PUBLISHED support policy are tracked: React, Flask and Express publish none, so their age cannot be judged and their absence from a report is not a statement that they are supported.
AC1 Text alternatives: Alt-text is detected structurally — the scan sees that an alternative EXISTS, not whether it meaningfully describes the image, and decorative-vs-missing is judged by attribute shape; runtime-injected images and a non-role=img decorative svg are out of scope. This is accessibility readiness, never a WCAG conformance claim.
AC2 Forms & labels: Label association is read from static markup — a label wired up at runtime (JS-set aria-labelledby, framework-injected ids) reads as missing, a present label says nothing about whether its text is correct. A known UI-library field component (e.g. a JSX <TextField>) is now checked conservatively — flagged only when it carries NO label/aria-label/aria-labelledby/id/name — but wrapper/context-labelled libraries (Chakra/Radix FormControl+FormLabel) aren't statically visible (possible false positive) and non-JSX lowercased components are still skipped. A click handler on a plain element is now asked for a name too (it is a control the author declared), but the subtree test that answers it is deliberately generous: any DYNAMIC text expression in the subtree counts as a name, so an icon chosen by a ternary ({cond ? <IconA/> : <IconB/>}) reads as named, and a glyph component from a library the icon-import list does not know still names its parent. A clean result is "no unlabelled control found", not a labelling proof.
AC3 Page structure: Page structure is read from the static markup tree — landmarks, headings and lang injected at runtime aren't seen, heading ORDER is checked structurally (not against the rendered visual hierarchy), and lang/title/main fire only on full documents, never partials, and the data-table check sees header-cell presence (a <th> exists), not whether each header correctly associates with its cells. Static readiness, not conformance.
AC4 Keyboard semantics: Keyboard semantics are inferred from markup attributes — interactivity wired purely in script, focus managed at runtime, and component-level handlers are invisible. A clean result means "no static keyboard-trap shape", not a keyboard-operability proof.
AC5 ARIA correctness: ARIA correctness is checked against the static role/attribute shape — roles/attributes set dynamically aren't seen, a valid role says nothing about whether it matches the element's real behaviour, and required-state checks are suppressed when a JSX spread could supply them. The two-branch toggle check (a control whose state is conveyed only by which of two mutually exclusive branches renders) reads CONDITIONALS THAT ARE ATTRIBUTES — Vue v-if/v-else/v-show and Alpine x-if/x-show — so the same toggle written as a Svelte {#if} block or a JSX ternary is control flow the markup model never projects as a branch and is not seen at all.
AC6 Visual & motion safety: Contrast and motion safety are PARTIAL by construction — literal colours (hex/rgb/hsl/named) in inline styles, in-repo <style> blocks, in-repo .css files, var() tokens, Tailwind neutral utilities and CSS-in-JS top-level declarations are read (same-rule/same-element colour+background pairs only); computed/runtime/theme colour, external-CDN stylesheets, CSS-in-JS dynamic (${…}) and nested-selector colours, cross-element pairs and image contrast stay out of reach, so a clean result is bounded by what the static CSS itself shows.
AX10 Code composition: Role is inferred from namespace/folder convention, not semantics — a domain concept living in a folder named "Services" reads as application, and the split is lines-of-code, not business value. The business-logic-share score is a SOFT, FLOORED signal: it contributes to the Architecture lens but is floored at the Critical gate, so an infrastructure-heavy design (a gateway, an ETL, a driver) is legitimately low without being nuked to zero.
AX9 CQS / query purity: Handlers are found by interface/name convention — a query handler using neither is not seen. Mutation is a resolved write/publish invocation (SaveChanges/repository/bus), so a write hidden behind a hand-rolled wrapper, reflection, or a string-keyed service locator resolves to a non-persistence type and isn't flagged; it detects that a query writes state, not whether the write is a legitimate read-side cache update. Clean means "no resolved write/publish in a query body", not a proof of CQS purity.
DM6 Domain ↔ infrastructure boundary: Infrastructure reached through a hand-rolled wrapper, a domain-named facade, reflection, or a string-keyed service locator resolves to a non-infra type and isn't seen; the body scan is symbol resolution over syntax, not full dataflow. A clean result means "no resolved infra reference in a domain body", not a proof of purity.
M4 Documentation accuracy: Documentation accuracy checks links, versions and artefact counts against the tree: other claims (paths, commands, settings, routes) are read but not checked, and it cannot run the onboarding or measure how long a real new joiner takes.
P4 Deployment & Rollback: Approval/branch-protection rules live in repository settings the scan cannot see — only their in-repo evidence (config files, workflows) is checked, so a control enforced purely in the host's settings reads as "not evidenced".
P5 DR & Backup: Backup/restore and disaster-recovery readiness is judged from in-repo evidence — a config that exists is not a tested restore, so the absence of positive evidence is reported as "not evidenced", never scored as present.
P6 Release Hygiene: Rollback/observability controls are inferred from repo artefacts (pipelines, dashboards-as-code) — controls configured in external tooling, with no in-repo trace, cannot be credited.
What it measures: How tangled the control flow is — methods with many branches are hard to test and change.
Method: Cyclomatic complexity per method (1 + decision points), computed exhaustively across production source; test projects separated by convention. Deterministic.
324 method(s) exceeded the cyclomatic complexity threshold of 15; the worst was AnthropicHandlerMixin.handle_anthropic_messages at 373. A further 2 method(s) were over the threshold but excluded as flat dispatchers (a long switch/match over independent cases: many branches, almost no nesting), the largest being ResponseItem::type_tag at 20 — they are counted neither in the figure above nor in this dimension's score. 2 files carry no cyclomatic complexity row at all for this reason — every one of their over-threshold functions was excluded, so the exclusion is disclosed nowhere in the file itself: crates/headroom-proxy/src/responses_items.rs (ResponseItem::type_tag at 20), crates/headroom-proxy/src/sse/openai_responses.rs (ResponseState::apply at 19). They are named here because the per-file figures other dimensions report are taken BEFORE this exclusion, so such a file can show a high maximum complexity elsewhere in this report and nothing here, with nothing to reconcile the two.
+ 290 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Bring the 1 body over 240 down to 240 or less in Cyclomatic Complexity — start with AnthropicHandlerMixin.handle_anthropic_messages (cyclomatic 373). — Refactoring it lifts Cyclomatic Complexity from 2.8 to about 3.6/10.
Detailed fixes: d1_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: How hard the code is for a person to follow, beyond raw branching.
Method: Cognitive complexity per method (Sonar-style nesting-penalized score), computed exhaustively over production code, excluding test projects. Deterministic.
+ 546 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Bring the 67 bodies over 60 down to 60 or less in Cognitive Complexity — start with AnthropicHandlerMixin.handle_anthropic_messages (cognitive 650), ContentRouter.apply (cognitive 435), wrap._ensure_proxy_unlocked (cognitive 328). — This score is capped by its worst body, so a finding fixed alone moves it by almost nothing — the next one down takes its place. Refactoring these 67 together lifts Cognitive Complexity from 2.0 to about 3.7/10, projected with the scoring formula itself and assuming each lands exactly at 60; a cleaner split scores higher.
Detailed fixes: d2_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D3 · God Classes8.8 / 10Strong✓ Tool-verified
What it measures: Over-large classes that try to do too much ("god classes").
Method: God-class detection by line and method-count thresholds per logical type (partial classes unified), filtered for generated code and registration/contract false positives. Deterministic.
+ 1 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 68 FileTooLong finding(s) in God Classes — start with lib.rs (2), REDACTED, wrap.py. — One of this dimension's main actionable groups (68 warning-level).
Resolve the 14 FunctionTooLong finding(s) in God Classes — start with proxy.rs (2), live_zone.rs (2), raw_predict.rs. — One of this dimension's main actionable groups (14 warning-level).
Resolve the 7 TooManyMethods finding(s) in God Classes — start with content_router.py, memory_handler.py, savings_tracker.py. — One of this dimension's main actionable groups (7 warning-level).
Detailed fixes: d3_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: How much of the production code is copy-pasted: the share of production lines inside a reported copy (every copy of a duplicated block or of an edited member, each line once), 10 at none and 0 at a quarter of the lines.
Method: Code duplication via token-stream sliding windows with type-aware normalization (locals masked, type names preserved), scored on the share of production lines inside a reported copy (each line once; 10 at none, 0 at a quarter). Deterministic.
397 duplicated block group(s) detected. 5.3 % of the production lines (17,328 of 324,979) are in a reported copy. A further 202 rows report members as variants of one another; the share counts each copied line once, however many rows cite it. 23 of the 599 are in trees this repository does not ship — vendored, example/demo, project-template, fixture and benchmark code — and are ranked below the shipped groups rather than excluded from them: the duplication there is real and is still counted in this dimension's score. The dimensions that publish a production-file census leave those trees out of theirs, so this count is deliberately drawn over the wider population.
+ 238 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 18 Duplicated block (14 lines × 2) finding(s) in Code Duplication — start with REDACTED (2), REDACTED, wrap.py. — One of this dimension's main actionable groups (18 warning-level).
Resolve the 18 Duplicated block (10 lines × 2) finding(s) in Code Duplication — start with REDACTED (2), REDACTED (2), memory.py. — One of this dimension's main actionable groups (18 warning-level).
Resolve the 17 Duplicated block (9 lines × 2) finding(s) in Code Duplication — start with REDACTED (2), batch_compression_eval.py, core.py. — One of this dimension's main actionable groups (17 warning-level).
Detailed fixes: d4_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D5 · Coupling9.3 / 10Stronggated by 1 serious finding✓ Tool-verified
What it measures: Whether volatile projects sit underneath others that depend on them (so their churn ripples upward), and whether project dependencies form cycles. A widely-depended-on but stable shared/kernel project is healthy, not penalised.
Method: Dependency cycles via elementary-DFS over real .csproj references, plus Martin instability (afferent/efferent) per project. Exhaustive over the reference graph, deterministic.
Coverage: Exhaustive · type-level: afferent/efferent coupling + cycles computed over every production type — the population is all types, not a name convention.
11 production modules (Cargo+npm+Python), 0 dependency cycle(s), 0 unstable depended-on module(s). Read from the build's own module declarations; 1 module(s) off the main sequence.
Off the main sequence: headroom-core
What to do
Resolve the 1 Off the main sequence finding(s) in Coupling. — One of this dimension's main actionable groups (1 warning-level).
Detailed fixes: d5_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether a class's methods are focused on a single responsibility.
Method: LCOM4 cohesion per production class with at least two methods: connected components of methods sharing state or calls, computed syntactically. Deterministic, not a proxy.
Coverage: Exhaustive · type-level: LCOM4 cohesion computed over every production class — the population is all types, not a name convention.
Resolve the 2 Low cohesion finding(s) in Cohesion (LCOM4) — start with metrics.py, REDACTED. — One of this dimension's main actionable groups (2 warning-level).
Detailed fixes: d6_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether the code respects its intended layering / architecture rules.
Method: Enforcement rung (Prevented/Verified/Documented) per checkable ADR via Roslyn, plus dependency cycles via the engine shared with D5/AX3. Deterministic, exact.
No mechanizable ADR was identified, so enforcement is not measured. Dependency cycles not checked (no project-reference graph; where this repository's language has an import-cycle lens, cycles are reported there).
Detailed fixes: d7_recommendation.md.
Do you agree with this assessment?
D10 · Test Quality10.0 / 10Stronggated by 1 serious finding✓ Tool-verified
What it measures: Whether the tests truly assert behaviour rather than just running the code.
Method: Per-test assertions, skips, and mock references analyzed via Roslyn; structured skip-reason tags (BUG:/ENV:) separate documented deferrals from debt. Deterministic.
4 skipped (4 with a documented reason), 1 zero-assertion, no mocking-framework packages referenced (hand-written doubles or no mocking) across 709 tests. Measured on the JavaScript/TypeScript suite only — at least 1,230 test source file(s) (.py, .rs) went unread, so its test quality is unmeasured and is not in these counts.
No assertions: execFile(file, null, callback) and execFile(file, callback) still call the callbackREDACTED:1430
Mock-dominated test: falls back when proxy is down · ×2sdk/typescript/test/adapters/vercel-ai.test.ts:476
Resolve the 2 Mock-dominated test finding(s) in Test Quality — start with vercel-ai.test.ts, REDACTED. — One of this dimension's main actionable groups (2 recommendation-level).
Resolve the 1 No assertions finding(s) in Test Quality — start with REDACTED. — One of this dimension's main actionable groups (1 warning-level).
Detailed fixes: d10_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether dependencies are current, not deprecated, and not bloated. Known vulnerabilities are D30's.
Method: Manifest scan via dotnet list package across all projects; worst-signal-per-package deduction (capped-linear for deprecation, prerelease and outdated) per KLoC. Known-vulnerable packages are D30's and are not charged here (rubric-2026.11.2). Exhaustive.
11 outdated, 0 yanked direct Cargo dependencies. Only DIRECT edges are graded: a transitive crate cannot be moved past what its parent's requirement admits, so reporting one would be advice its owner cannot take. A newer release is reported only where this repository's OWN requirement already admits it, so the remedy is `cargo update` and never a manifest edit — which means a release outside the declared range is deliberately NOT charged, because a written-down constraint is a decision rather than a defect. Note that a bare requirement is a CARET, and for a 0.x crate its ceiling is the minor. Whether any crate is UNMAINTAINED is not graded — crates.io publishes no maintenance status, and release age does not stand in for one. Known CVEs in this dependency graph are D30's question, read from REDACTED there.
Outdated: aws-config · ×11
✓ On the Gold path — maintain.
Detailed fixes: d12_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether any secrets (keys, tokens, passwords) have leaked into the code.
Method: In-process native secret scanner (entropy plus signature patterns) across all tracked files; no external tool. A clean result is a measured 10, not no-data zero. Deterministic.
What it measures: Whether the licenses of third-party packages are compatible with your policy.
Method: Third-party package licenses resolved from declared package metadata and checked against the configured policy (allow/deny/copyleft). Deterministic; clean = no incompatible license found at metadata depth.
0 of 504 shipped crate(s) use a banned license. Licences were resolved from crates.io over the crates a consumer compiles — this repository's REDACTED closed over its manifests' `[dependencies]` and `[build-dependencies]`. Crates it asks for ONLY under `[dev-dependencies]` are excluded: they are not compiled by anything that depends on this repository. This repository publishes itself under Apache-2.0, which is its own choice and is not judged here. ★ COVERAGE OF THIS VERDICT: it grades this repository's crate dependencies and nothing else. The repository also declares a Python REDACTED/requirements.txt (pip/uv/Poetry) and package.json, and the licences of those dependency graphs were NOT read by this pass — a gap in this engine's coverage, not a statement about them. So this result says the graded closure carries no banned licence; it does NOT say this repository's licensing is clear.
What it measures: Files that change often and are also complex — the riskiest hotspots.
Method: Per production file churn times cyclomatic complexity over a rolling window, computed from git and Roslyn/JS/Razor analysis. Exhaustive, deterministic per commit date.
Top hotspots: REDACTED (93×373=34689); REDACTED (108×205=22140); headroom/transforms/content_router.py (62×192=11904) Repeated repair below the complexity floor: headroom/config.py (15 of 18 changes were fixes); REDACTED (12 of 13 changes were fixes); headroom/proxy/models.py (11 of 16 changes were fixes)
Resolve the 74 Repeated repair finding(s) in Churn × Complexity Hotspots — start with config.py (2), models.py (2), sqlite.py (2). — One of this dimension's main actionable groups (74 warning-level).
Resolve the 62 Hotspot finding(s) in Churn × Complexity Hotspots — start with REDACTED (2), analyzer.py (2), REDACTED. — One of this dimension's main actionable groups (62 warning-level).
Detailed fixes: d15_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D16 · Bus Factor8.4 / 10Strong✓ Tool-verified
What it measures: Whether knowledge is concentrated in too few people (the "bus factor").
Method: Living knowledge per author via time-decayed commit attribution (6-month half-life, focus weighting) across largest source files. Deterministic, avoids blame's mechanical-refactor false positives.
109 source file(s) have their living knowledge concentrated in one author (≥90% of recent, decayed contribution). The largest is benchmarks/claude_session_mode_benchmark.py. Counted over 679 of the 842 production source files in this repository: the rest are under the ~2,400-byte size floor this dimension measures over.
Off-boarding risk: anonymized user #1 · ×4
Further sole-owners (lower concentration)
What to do
Resolve the 4 Off-boarding risk finding(s) in Bus Factor. — One of this dimension's main actionable groups (4 recommendation-level).
Resolve the 1 Further sole-owners (lower concentration) finding(s) in Bus Factor. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d16_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Acknowledged debt left in the code — TODOs, dead code, suppressed warnings.
Method: Roslyn syntactic debt markers (suppressions/TODO/FIXME/HACK/empty-catch/commented-code/Obsolete) plus SymbolFinder dead-code analysis; weighted-debt-per-KLoC density deducted 2.0x per unit. Deterministic, exhaustive.
11 deducted task-comment markers across 324979 LoC (0.0/KLoC) → score 10.0. Task comments only: this repository's language is read without a compiler, so D17's suppression, dead-code and commented-out-code arms did not run and this score counts fewer marker kinds than a .NET repository's would.
TodoComment · ×10tests/test_memory_bridge.py:63
FixmeCommenttests/test_search_compressor.py:317
What to do
Resolve the 10 TodoComment finding(s) in Explicit Debt — start with test_observed_wire_shapes.py (5), test_memory_bridge.py, gemini.py. — One of this dimension's main actionable groups (10 warning-level).
Resolve the 1 FixmeComment finding(s) in Explicit Debt — start with test_search_compressor.py. — One of this dimension's main actionable groups (1 warning-level).
Detailed fixes: d17_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether the project's documentation is clear, complete, and useful.
Method: Every README, docs/ document and root guide parsed by its markup and measured in Unicode letters. Published: a runnable or packaged .NET project whose README (or a document it links, or a root guide) shows no example, and a root README naming none of three or more projects. Overview, licence, boilerplate, wall-of-text, empty-section and XML-doc rows are measured and withheld (counted in gaps) after adjudication. Deterministic, exhaustive, advisory.
What it measures: Whether architecture decisions are recorded well (context, decision, consequences).
Method: Every ADR read by its section structure: nine located rules (a missing Decision, Context or Consequences section, a stale status, two records deciding the same question, a dangling supersede link, a number-only title, a single option, no named cost, no status where the log uses one, no enforcement field where the log adopted one), each a fixed deduction from 10; the score is the mean over evaluated records. Deterministic, no model. Advisory.
0 of 5 evaluated ADRs have a defect readable from the log itself (a missing or empty section, no title, a single option, consequences with no cost, no status, a missing enforcement field, a status the log contradicts, a dangling link, an unlinked second decision on one question, a date that is no calendar day). How well each record argues its case is not measured.
What it measures: Whether names — types, methods, variables — are clear and consistent.
Method: Seven vocabulary-free rules (N1-N7) mine each naming convention from the repository and flag a name that breaks a convention its structural peers in the same unit follow; production C# and TypeScript, each its own population. Deterministic, no model, no sample. Advisory.
2 naming inconsistencies among 76 declarations measured against a convention their peers follow.
`baseURL` spells `URL` where 59 names in the project spell it `Url`plugins/opencode/src/plugin.ts:179
`normalizedOpenAiProxyPath` spells `Ai` where 15 names in the project spell it `AI`plugins/opencode/src/transport.ts:516
What to do
Resolve the 1 `baseURL` spells `URL` where 59 names in the project spell it `Url` finding(s) in Naming Consistency — start with plugin.ts. — One of this dimension's main actionable groups (1 recommendation-level).
Resolve the 1 `normalizedOpenAiProxyPath` spells `Ai` where 15 names in the project… finding(s) in Naming Consistency — start with transport.ts. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d21_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether comments are worth it — explaining WHY (valuable) rather than WHAT (redundant).
Method: Every inline C# comment compared word by word with the identifiers, literals and constructs of the code it annotates (taken from the syntax); a comment whose words that code already contains is redundant, as are closing-brace labels and generator template text. Comments giving a reason or a reference are kept; other scripts and languages are not judged. Deterministic, exhaustive, advisory.
Resolve the 3 redundant comment finding(s) in Comment Value — start with index.ts, format.ts, vercel-ai-e2e.test.ts. — One of this dimension's main actionable groups (3 recommendation-level).
Detailed fixes: d24_recommendation.md · top locations in Appendix A, every location in findings.md.
3 of 12 build units (Cargo, Python, npm) flagged as possibly oversized/incoherent.
Projects may be oversized for their cohesion
What to do
Resolve the 1 Projects may be oversized for their cohesion finding(s) in Project Cohesion. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d26_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D27 · Navigability7.9 / 10Strong✓ Tool-verified
What it measures: How far you must trace to follow a call — low indirection and co-located slices read easier.
Method: Call indirection (interface hops, cross-namespace calls, slice-locality scaled) over a sampled set of method invocations, size-aware baseline. Sampled; confidence discounted by symbol-resolution gaps. C# also names each pass-through layer (a class whose every public method only forwards its own parameters to one collaborator) as a located finding; the score is not affected.
Coverage: Slice locality from the first namespace segments, SAMPLED (≤400 methods) — not exhaustive.
99 % of calls cross a namespace and 0 % go through an interface, but 58 % of collaborators are co-located — so following a call takes several hops. Baseline: small — navigation cost is tolerated. Measured over the .py source only — this repository's .rs was not sampled for call sites, so this score covers part of the tree, not all of it.
Scattered collaborators
What to do
Resolve the 1 Scattered collaborators finding(s) in Navigability. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d27_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether any secrets were ever committed — scanned across the full git history, not just now.
Method: Secret scan via TWO gitleaks detect passes in an isolated checkout — the full git history, then a second --no-git pass over the working tree as it stands — merged and de-duplicated by (rule, file, line); each match flagged High. Both invocations are recorded in the audit trail. Exhaustive; when the tool is absent, or when its output cannot be parsed into the expected shape, the dimension is WITHHELD as an explicit measurement gap on our side — unscored and excluded from the lens, never a hedged middling score.
What it measures: Real static-analysis (SAST) findings — likely security bugs in the code, any language.
Method: Polyglot static analysis via semgrep across the repo using the pinned, image-baked p/security-audit + p/owasp-top-ten rulesets (no scan-time registry fetch); severity rules (ERROR/WARNING/INFO) map to a full-band severity-weighted score. Exhaustive, deterministic; degrades on parse failure.
Coverage: semgrep pattern rules over all files — exhaustive for the rule set, blind to classes of bug without a rule (clean = no rule matched).
97 finding(s): 0 critical, 24 high, 56 medium, 17 low. semgrep hit a parse error in 9 file(s) — `REDACTED` (line 67), `docs/components/mdx.tsx` (line 28), `e2e/docker-bind-security.sh` (line 5), `e2e/init/REDACTED` (lines 51–79), `headroom/cli/proxy.py`, … (+4 more) — so no absence of findings in the named regions is evidence of anything; rows reported elsewhere in those files are real. Fix the syntax error (or exclude the file deliberately) and re-scan to cover them. Separately, one or more rules could not re-parse an embedded snippet in 11 file(s) (e.g. a workflow `run:` block read as shell). Those files WERE scanned and their other rows are unaffected; only those rules' view of those snippets is missing.
REDACTED
REDACTED
REDACTED
REDACTED
REDACTED
+ 9 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 21 REDACTED finding(s) in Static Analysis (SAST) — start with REDACTED (17), REDACTED (2), REDACTED. — One of this dimension's main actionable groups (21 issue-level).
Resolve the 1 REDACTED finding(s) in Static Analysis (SAST) — start with REDACTED. — One of this dimension's main actionable groups (1 issue-level).
Resolve the 1 REDACTED finding(s) in Static Analysis (SAST) — start with REDACTED. — One of this dimension's main actionable groups (1 issue-level).
Detailed fixes: d29_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether any dependency has a known published vulnerability (CVE), direct or transitive, in ANY ecosystem the repository declares — Dart pub, Elixir and Erlang via Hex, Go modules, Java and Kotlin via Maven/Gradle, JavaScript/npm, .NET/NuGet, PHP/Composer, Python/PyPI, RubyGems, Rust/Cargo and Swift.
Method: Dependency-CVE scan across every ecosystem the repository declares, scored ONCE. Three sources are unioned and deduplicated by advisory identity (rule id + alias closure, CVE<->GHSA) scoped to package+version, keeping the worst severity: `osv-scanner --recursive` over osv.dev for Dart pub, Elixir/Hex (and Erlang, whose `rebar.lock` syft first converts to a CycloneDX SBOM the scanner reads, with rows attributed back to the lock), Go, Java and Kotlin via Maven/Gradle (and Scala, whose sbt build's pinned direct declarations are written into a CycloneDX SBOM the scanner reads, with rows attributed back to the build file), npm, PHP/Composer, Python/PyPI, RubyGems, Rust/Cargo and Swift; `trivy fs --scanners vuln` for npm lockfiles; and `dotnet list package --vulnerable --include-transitive` for NuGet (with per-advisory collapse of the project x target-framework fan-out), plus a DECLARED-dependency arm that resolves a published gem's gemspec against rubygems.org where no Gemfile.lock is committed. `SeverityScore(c,h,m,l, normalizer 8.0)`. NotApplicable only when NO ecosystem is readable; if any applicable ecosystem could not be scanned the findings are REPORTED and the score is withheld. Supersedes the npm and OSV arms, retired 2026-09-05. Advisory since rubric-2026.11.2 (CAI decision 0006): every row is a match against a vulnerability database that changes daily, so the reading is shown and never moves a scored dimension, lens or the headline.
+ 5 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 18 High CVE finding(s) in Dependency Vulnerabilities — start with REDACTED (7), REDACTED (7), REDACTED (4). — One of this dimension's main actionable groups (18 issue-level).
Resolve the 6 Critical CVE finding(s) in Dependency Vulnerabilities — start with REDACTED (4), REDACTED (2). — One of this dimension's main actionable groups (6 issue-level).
Resolve the 4 Critical vulnerability finding(s) in Dependency Vulnerabilities — start with REDACTED, REDACTED, REDACTED. — One of this dimension's main actionable groups (4 issue-level).
Detailed fixes: d30_recommendation.md · top locations in Appendix A, every location in findings.md.
Resolve the 1 High IaC finding(s) in IaC & Container Security — start with REDACTED.runner. — One of this dimension's main actionable groups (1 issue-level).
Resolve the 14 Medium IaC finding(s) in IaC & Container Security — start with REDACTED (7), REDACTED (5), REDACTED.runner (2). — One of this dimension's main actionable groups (14 warning-level).
Resolve the 5 Low IaC finding(s) in IaC & Container Security — start with REDACTED (3), REDACTED (2). — One of this dimension's main actionable groups (5 recommendation-level).
Detailed fixes: d31_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether anyone still has living knowledge of each file, or it has been orphaned — last understood long ago by someone now gone quiet. The sibling of the bus factor: D16 asks who owns it, D34 asks whether anyone still knows it.
Method: File orphaning as total living-knowledge decay below one focused-commit's worth within a year, computed per-file from the D16 decay model. Exhaustive, deterministic over fixed history.
13 of 679 significant source file(s) are orphaned — their living knowledge has decayed to nothing, so no one currently understands them. The largest is crates/headroom-proxy/src/cache_stabilization/beta_sticky.rs. Counted over 679 of the 842 production source files in this repository: the rest are under the ~2,400-byte size floor this dimension measures over.
Resolve the 1 Orphaned knowledge finding(s) in Knowledge Freshness — start with beta_sticky.rs. — One of this dimension's main actionable groups (1 issue-level).
Resolve the 12 Orphaned file finding(s) in Knowledge Freshness — start with i18n_compression_eval.py, text_crusher_quality_eval.py, agent_savings.py. — One of this dimension's main actionable groups (12 recommendation-level).
Resolve the 1 Further orphaned files (smaller) finding(s) in Knowledge Freshness. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d34_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether files that change together actually belong together — pairs that repeatedly co-change in git history despite having no explicit code dependency, surfacing the hidden/logical coupling (and boundaries in the wrong place) a static scan can't see.
Method: Pairwise co-occurrence over the per-commit file sets in git history (production source only — tests and generated dropped): Degree-of-Coupling = shared ÷ min individual revisions, reported above noise floors (each file ≥10 revisions, ≥5 shared commits, ≥50% strength); sweeping commits excluded. Deterministic over fixed history.
Coverage: Population: PRODUCTION source files only — test and generated files are dropped before pairing, so a class co-changing with its own test (trivially ~100%) can't drown the real production↔production coupling. Pairs ranked by Degree-of-Coupling. A non-source file is never a coupling PARTICIPANT either: documentation, schemas, config and data files are dropped with the rest, so a code↔docs pair — a command and the reference page that restates it — is not reported however strongly the two co-change; nor is coupling that runs THROUGH a build step or config file.
What it measures: Whether the build pipeline provides supply-chain integrity — generated provenance/attestation, signed artifacts (cosign/sigstore), an SBOM, and pinned build actions. Presence of the configuration, not a runtime guarantee.
Method: Supply-chain provenance/signing read deterministically from CI/build config (.github/workflows, .gitlab-ci.yml, azure-pipelines, Jenkinsfile, .circleci) + the release surface: four signals — generated provenance/attestation (SLSA/in-toto/actions-attest), artifact signing (cosign/sigstore/gitsign), an SBOM (syft/sbom-action/*.spdx.json/*.cdx.json), and SHA-pinned build actions — scored 10·present/denom. NotApplicable without a build pipeline. Detects configuration presence, not runtime enforcement.
Build pipeline generates provenance, signs artifacts and produces an SBOM.
REDACTED
REDACTED
REDACTED
What to do
Resolve the 1 REDACTED finding(s) in Supply-chain Provenance & Signing — start with REDACTED. — One of this dimension's main actionable groups (1 warning-level).
Resolve the 1 REDACTED finding(s) in Supply-chain Provenance & Signing. — One of this dimension's main actionable groups (1 warning-level).
Resolve the 1 REDACTED finding(s) in Supply-chain Provenance & Signing. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d36_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether the repository publishes a coordinated-vulnerability-disclosure policy (SECURITY.md or security.txt) with a reporting contact, so finders know how to report a vulnerability. Presence of a policy file with a contact, not whether the policy is adequate or honoured.
Method: Vulnerability-disclosure policy read deterministically from the repo: a SECURITY.md (root/.github/docs) or .well-known/security.txt / security.txt, regex-checked for a reporting contact (email / URL / mailto). Present + contact → 10; present without a contact → 4; NotApplicable when no policy file exists (it may live off-repo). Detects the policy file's presence + contact, not its adequacy.
What it measures: Whether any dependency the repository declares is published as MALICIOUS rather than merely vulnerable — a package that is an attacker's work, in any ecosystem osv-scanner reads. Reported apart from D30 because the answer is binary: there is no safe version to upgrade to, and the fix is to remove the package and rotate every credential it could have read.
Method: The same dependency scan D30 reads, partitioned on the scanner's own classification rather than rescanned: a row is MALICIOUS when its id is in the `MAL-` space (the ossf/malicious-packages feed) OR its `database_specific.cwe_ids` carries `CWE-506` ("Embedded Malicious Code"). Both channels are structural; the summary text is deliberately NOT read, because a malicious-package record whose summary says only "Critical severity vulnerability" is a real shape ([GHSA redacted]) and a text matcher misses it. Scored BINARY: any surviving row is 0, whatever its severity and however many CVEs sit beside it — a hostile dependency is not a quantity. Applicability and degradation are D30's: NotApplicable only when no ecosystem is readable, and an unscannable ecosystem degrades rather than reading clean. Advisory since rubric-2026.11.2 (CAI decision 0006): the malicious-package feed is a database that changes daily, so the reading is shown and never moves a scored dimension, lens or the headline.
What it measures: Whether anyone still ships security patches for the platform this repository RUNS ON — the runtime it pins and the framework majors its own constraints hold it to. Separate from D12 because the question differs: a current Django on an end-of-life Python is perfectly up to date and completely unsupported, and the fix is a migration rather than a version bump. What the repository says it merely SUPPORTS is never charged.
Method: End-of-life PLATFORM read from the repository's own declarations and graded against a FROZEN, dated table of vendor support dates — no network, no feed, no API, so this dimension answers identically inside a closed scan fence. Two subjects: a RUNTIME the project pins (a single or all-end-of-life TargetFramework, a .nvmrc or .python-version, a requires-python CAP) and a FRAMEWORK major a dependency constraint cannot move off (a caret, tilde or exact version; `vue@^2.7.16` pins Vue 2). A FLOOR is deliberately never charged — `requires-python = ">=3.8"` states what a package SUPPORTS, not what it runs on — and a multi-target project is charged only when EVERY target is out of support. Runtime 4.0/product capped 8.0, framework 1.5 capped 4.5. The table is safe to freeze because a statement about support that ended in the past cannot become false: it loses recall as it ages, never precision, and a test asserts every entry predates the freeze date. Disjoint from D31 (a container image's OS layer) and D29 (the toolchain a CI workflow installs). Abstains when the repository declares no platform this pass reads — never scores it clean.
1 end-of-life runtime(s) and 0 end-of-life framework(s), read from 3 platform declaration(s) and 12 dependency declaration(s). This dimension reads what the repository says about ITSELF — a pinned target framework, a version file, a capped requires-python, a Rust toolchain pin, a framework major a constraint cannot move off. A FLOOR is deliberately never charged: `requires-python = ">=3.8"` states what the package SUPPORTS, not what it runs on, and a well-maintained library declares exactly that while running its own CI on a current release. The end-of-life facts are FROZEN and dated, so this dimension needs no network and answers identically inside a closed scan fence; as the table ages it loses recall and never precision, because a statement about support that ended in the past cannot become false. The OS layer of a container image is D31's question and the toolchain a CI workflow installs is D29's; this row is neither.
Resolve the 1 End-of-life runtime finding(s) in Platform End-of-Life — start with rust-toolchain.toml. — One of this dimension's main actionable groups (1 warning-level).
Detailed fixes: d44_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
Frontend & cross-cutting dimensions
R = React/JS · M = Maturity · P = Readiness.
AC1 · Text alternatives10.0 / 10Exemplary○ Nothing flagged
Other · Accessibility — Whether non-text content carries a text alternative — img/area/input[type=image] have alt, a meaningful svg has a title or aria-label, video has a captions track, and object/embed/canvas have a name or fallback content. Static markup readiness, not a WCAG conformance claim.
Method: Static markup-model scan: every img/area/input[type=image] checked for alt, svg[role=img] for a title/aria-label, video for a captions <track>. Components skipped, spreads suppressed. Deterministic, hard fact per element.
Coverage: Population: image/media elements — img, area, input[type=image], svg, video, object, embed, canvas — across the PARSED MARKUP files only (.html/.htm/.cshtml/.razor/.vue/.svelte/.jsx/.tsx); components, hidden subtrees and dynamic-attribute elements are skipped. Markup built in script — tagged-template (html`…`) UIs and hyperscript DOM factories — is NOT read by any producer, so it contributes no element to this population; where such a frontend is present the card discloses it as an analyzer gap rather than scoring around it.
Do you agree with this assessment?
AC2 · Forms & labels10.0 / 10Exemplary○ Nothing flagged
Other · Accessibility — Whether form controls have a programmatic label (an associated label, aria-label or aria-labelledby), buttons have text, links have an accessible name, a click handler on a plain element names the control it declares, fieldsets have a non-empty legend, known UI-library field components carry a label prop, and a placeholder isn't used as the only label. Static markup readiness, not a WCAG conformance claim.
Method: Static markup-model scan: inputs/selects/textareas checked for an associated label[for]/wrapping label/aria-label/aria-labelledby (per document), buttons for accessible text, fieldsets for a legend; placeholder-only labelling flagged. Deterministic, hard fact per control.
Coverage: Population: form controls, buttons, links, fieldsets and known UI-library field components in the PARSED MARKUP files only (.html/.htm/.cshtml/.razor/.vue/.svelte/.jsx/.tsx); components, hidden subtrees and spread/dynamic-attribute elements are skipped, so a control whose label arrives through a spread or a runtime expression is deliberately not judged. Markup built in script — tagged-template (html`…`) UIs and hyperscript DOM factories — is not read at all.
Other · Accessibility — Whether pages declare a language (well-formed BCP-47) and a non-empty title, expose exactly one main landmark and a sane heading order with non-empty headings, keep zoom enabled, title their iframes, give data tables header cells, and avoid meta-refresh. Static markup readiness, not a WCAG conformance claim.
Method: Static markup-model scan: html lang, document <title>, a main landmark and heading order on full documents only, plus zoom-disabling viewports, untitled iframes and meta-refresh anywhere. Deterministic, per structural checkpoint.
Coverage: Population: the PARSED MARKUP documents (.html/.htm/.cshtml/.razor/.vue/.svelte/.jsx/.tsx). The page-level checks — lang, title, single main landmark — fire ONCE PER FULL DOCUMENT (an <html> root) and never on a partial or component fragment, so a repo of fragments is assessed only on the per-element checks (heading order, table headers, iframe titles, meta-refresh, zoom). Markup built in script — tagged-template (html`…`) UIs and hyperscript DOM factories — is not read at all.
No <main> (or role="main") means no "skip to content" target and a weaker landmark map. Wrap the primary content in <main>. (×3) — crates/headroom-proxy/src/observability/dashboard.html:2, docs/app/layout.tsx:50, headroom/dashboard/templates/settings.html:2
What to do
Declare <html lang>, a document <title> and a <main> landmark, keep headings in order, leave zoom enabled, title iframes and drop meta-refresh.
Other · Accessibility — Whether interactive behaviour is keyboard-reachable — no click handler on a non-interactive element lacking a role, tabindex and key handler, no element the repo's own CSS styles `cursor: pointer` without giving it any of the three, no unfocusable element whose only binding is a mouse enter/leave pair or a double-click, no positive tabindex, no href-less anchor, no placeholder-href (#/javascript) link acting as a button. Static markup readiness, not a WCAG conformance claim.
Method: Static markup-model scan: click handlers on non-interactive elements lacking role+tabindex+key handler, positive tabindex values, and href-less anchors. Components skipped, spreads suppressed. Deterministic, hard fact per element.
Coverage: Population: elements that pose a keyboard-semantics question, in the PARSED MARKUP files only (.html/.htm/.cshtml/.razor/.vue/.svelte/.jsx/.tsx) — a non-natively-interactive element carrying a click handler, a double-click or hover enter/leave binding, a pointer-only gesture on a tabindex="0" element, or `cursor: pointer` from the repo's own CSS; an href-less or placeholder-href (#, javascript:) anchor; and any element with a positive tabindex. Natively interactive elements used correctly (<button>, <a href>, form controls) are NOT in the population — there is nothing to judge — so a page of nothing but correct controls gives AC4 nothing to measure. Keyboard reachability is judged from the markup, never from a rendered page. ★ An interactive element declared in a tagged-template (html`…`) or hyperscript frontend is NOT in this population — no producer reads either — so an empty population is reported as an analyzer gap, never as "this repository has no interactive elements".
This <div role="dialog"> is a modal dialog, but focus is moved into it, but nothing keeps it there: Tab walks out to the page behind, so a keyboard or screen-reader user keeps acting on the content behind it (WCAG 2.4.3). Use a native <dialog> opened with showModal(), a dialog component that traps focus, or move focus to the dialog on open, trap Tab inside it (or make the page behind inert) and return focus to the control that opened it on close. — headroom/dashboard/templates/dashboard.html:2002
What to do
Make custom controls keyboard-operable (role + tabindex + key handler), drop positive tabindex, and give anchors a real href.
Other · Accessibility — Whether ARIA is used correctly — valid non-abstract roles, the ARIA state a role requires, valid (non-misspelled) aria-* attribute names, in-enum values for token-typed aria-* attributes, and no aria-hidden on (or wrapping) a focusable element. Static markup readiness, not a WCAG conformance claim.
Method: Static markup-model scan: role values checked against the WAI-ARIA role set (abstract/invalid flagged), required ARIA state for a role, and aria-hidden on a focusable element. Deterministic, role/attribute level.
Coverage: Population: elements in the PARSED MARKUP files (.html/.htm/.cshtml/.razor/.vue/.svelte/.jsx/.tsx) that carry a role or an aria-* attribute; roles and token values are checked against the ARIA enums exhaustively within that set. An expression-valued (dynamic) role or aria-* value is skipped rather than guessed, and markup built in script — tagged-template (html`…`) UIs and hyperscript DOM factories — is not read at all.
Other · Accessibility — Whether focus outlines aren't removed without a replacement, motion respects prefers-reduced-motion, and literal CSS colour pairs meet contrast — PARTIAL: inline styles, in-repo <style> blocks, in-repo .css files, var() tokens, Tailwind neutral utilities and CSS-in-JS literals are read (hex/rgb/hsl/named), never computed/runtime/external-CDN colour. Static markup readiness, not a WCAG conformance claim.
Method: Static markup/CSS scan: inline outline:none/0, literal inline colour/background contrast against the 4.5:1 AA floor, and <style>-block animation without a prefers-reduced-motion guard. Deterministic but PARTIAL — only inline styles and in-repo CSS literals are visible.
Coverage: Population: styled elements in the PARSED MARKUP files (.html/.htm/.cshtml/.razor/.vue/.svelte/.jsx/.tsx), plus in-repo <style> blocks, in-repo .css files and CSS-in-JS literals. Colour contrast is computed from LITERAL colour pairs only (hex/rgb/hsl/named, including var() tokens and Tailwind neutral utilities) — computed, runtime-themed and external-CDN colour is never resolved, so this is a partial read of contrast by construction. Markup built in script — tagged-template (html`…`) UIs and hyperscript DOM factories — is not read at all.
Other · Architecture — How the codebase splits by code ROLE — domain, application, infrastructure, test, generated. The significance map behind the knowledge/coupling weighting, and a DDD signal in its own right: a thin domain core under fat infrastructure is the anemic-domain smell, quantified. How each file's role is decided, because the split is only as good as that: a generated name or a build-output tree makes it Generated, a test project makes it Test, and otherwise the file's NAMESPACE and PATH words are matched against fixed vocabularies in a fixed ORDER — domain, then infrastructure, then application — so a file whose words hit two layers is counted under the earlier one. A production file matching none of them counts as application, so that share reads 'application or unclassified' rather than a measured application layer. Roles come from naming convention, never from what the code does. On this repository the split was taken from the source tree on disk rather than from a loaded .NET workspace, so a file's role is decided by its PATH segments alone — no declared namespace was available to add to the evidence — and generated output is excluded from the census entirely rather than counted as a generated share.
Method: Roslyn line-count by code ROLE: every source file classified Domain/Application/Infrastructure/Test/Generated by namespace + path convention (the shared CodeRoleClassifier), then significant lines summed per role. Deterministic; the advisory score is the business-logic (domain+application) share of production code.
Coverage: Population: ALL source files, each bucketed into ONE of five roles (Domain/Application/Infrastructure/Test/Generated) by namespace + path convention — a file whose layer isn't named in the convention falls to Application (the neutral default), and the split is line-count, not semantic depth or business value.
Other · Architecture — Whether the project-reference graph is acyclic (cycles block independent build/deploy and signal eroding boundaries).
Method: Project reference cycles via elementary-DFS over real .csproj references, using the engine shared with D5/D7; cyclic versus acyclic. Exhaustive, deterministic.
Other · Architecture — Whether dependencies point inward (Domain ← Application ← Infrastructure/Web) — the clean-architecture dependency rule, checked across the project graph.
Method: Layer violations by name-segment inference (Domain/Core to Application to Infrastructure/Web) over the project-reference graph. Exhaustive over all projects, deterministic.
Other · Architecture — Whether the codebase has a recognisable, scale-appropriate structure (a named architectural style, or modular enough for its size) rather than being an ad-hoc ball of mud.
Method: Roslyn plus csproj analysis: architecture style detection (DDD, clean, vertical-slice, CQRS) and structure fitness for repo size. Deterministic.
Do you agree with this assessment?
AX8 · Test isolation10.0 / 10Exemplary✓ Tool-verified
Other · Architecture — Whether production projects stay free of references to test projects — tests may depend on production, never the reverse.
Method: Csproj graph: each production project checked for references to test projects (identified by test-framework presence, not name). Zero violations is clean. Deterministic.
Other · Architecture — Whether read (query) handlers stay side-effect-free — a query that writes persistent state or raises events breaks CQS and makes reads unsafe to retry, cache, or route to a read replica.
Method: Roslyn scan: CQRS handlers classified query-vs-command by interface (IQueryHandler/ICommandHandler/IRequestHandler<TQuery,TResult>) and name convention (*Query/Get*/Find* vs *Command); each query handler's body checked for persistent-state writes (SaveChanges/repository Add-Update) or event publishes by resolved invocation. Deterministic, type-level, exhaustive over the detected handlers.
Coverage: Population: CQRS handlers identified by IQueryHandler/ICommandHandler/IRequestHandler interface + *Query/Get*/Find*/*Command NAME convention; query purity then checked exhaustively within that set — a query handler using neither convention is invisible, and mutation is a resolved persistence/publish CALL, not full dataflow.
Other · Domain Modelling — Whether the domain layer stays free of infrastructure dependencies — a domain aggregate fused to a persistence ORM (Django/SQLAlchemy) on its own declaration (active-record) couples the domain to infrastructure. The clean-architecture dependency rule.
Method: Roslyn (DDD-gated): domain-layer types scanned for infrastructure usage in member SIGNATURES and inside method/accessor BODIES — resolved calls and object-creations into EF/Marten/HTTP/Mongo/Redis/message-bus types (not just a namespace allowlist). Deterministic, symbol-resolved, exhaustive over domain-layer bodies, DDD-native.
Coverage: Domain layer identified by NAMESPACE heuristic; infrastructure then resolved by symbol in member SIGNATURES and method/accessor BODIES — rename the layer and the check evaporates.
`HeadroomStrandsModel` is a domain concept fused to persistence ON ITS OWN DECLARATION (Django/SQLAlchemy — `models.Model`/`db.Model`) — the domain entity IS the ORM row (active-record), and it carries domain behaviour on the persistence type. A schema/persistence change ripples straight into the domain. Keep the ORM/table mapping on a boundary data-model + a mapper, and the domain entity framework-free (map row↔domain through a repository). — headroom/integrations/strands/model.py:60
What to do
Keep the ORM/table mapping on a boundary data-model + mapper; leave the domain entity framework-free (map row↔domain through a repository).
Maturity · Maturity — Whether the repository and its projects have a README, and whether it is substantive.
Method: Filesystem scan: README presence, word count, and headings for depth; git history for staleness. Exhaustive across root and project dirs, deterministic.
What to do
Explain in the README how to run the tests. Add a section called Testing to the README in the repository's top folder, saying how to run the test suite.
Maturity · Maturity — Whether the repository is organised deliberately: production code and tests are set apart in a way its ecosystem or the repository itself declares.
Method: Filesystem scan: src/test folder separation and namespace-prefix consistency (majority RootNamespace agreement). Exhaustive across projects, deterministic.
Maturity · Maturity — Whether the project's current-state documentation describes the code that exists.
Method: Every current-state document's checkable claims looked up in the tree (links, versions, and artefact counts an order of magnitude off), plus two README checks: an advertised infrastructure product with no footprint, and a module the CHANGELOG records as removed. Deterministic, no model. Advisory.
Readiness · Readiness — Whether an automated pipeline builds and tests every change.
Method: Filesystem scan: CI workflow files (.github/workflows, .gitlab-ci.yml, etc.) for build and test stages. Exhaustive, deterministic.
Do you agree with this assessment?
P10 · Library API & versioning10.0 / 10Exemplary○ Nothing flagged
Readiness · Readiness — For a library: a deliberate (small) public API surface and explicit semantic versioning so consumers can depend on it safely.
Method: Roslyn scan: public API surface area and semantic-versioning markers (SemVer attributes, changelog entries) for libraries; off .NET, a library is the ecosystem's publication act (an npm package that is not private and names an entry point, a PyPI distribution with a build system, a Rust library crate, a Maven/Gradle module that publishes, a Go module with no package main, a gemspec, a Composer library, a SwiftPM library product, a pub.dev or Hex package), its surface is the share of types the language's code model records as public (Rust, Swift, Java, Kotlin, Go, Dart; not measured where the model records no type visibility or, as in TypeScript, only module-level export), and its version is read from the manifest, a semver CHANGELOG, release tooling or semver git tags. Exhaustive, deterministic.
Only 6/8 runnable modules use logging (modules with no entry point or server are excluded — they are libraries a runnable module hosts). Silent: `crates/headroom-parity`, `docs`.
`plugins/openclaw/src/proxy-manager.ts` reports through `console.*` at line 35 although other files in its module log through a logger. Console lines carry no level, fields or correlation and never reach the log pipeline. — plugins/openclaw/src/proxy-manager.ts:35
`plugins/openclaw/src/proxy-manager.ts` reports through `console.*` at line 36 although other files in its module log through a logger. Console lines carry no level, fields or correlation and never reach the log pipeline. — plugins/openclaw/src/proxy-manager.ts:36
`plugins/openclaw/src/proxy-manager.ts` reports through `console.*` at line 37 although other files in its module log through a logger. Console lines carry no level, fields or correlation and never reach the log pipeline. — plugins/openclaw/src/proxy-manager.ts:37
What to do
Extend structured logging to the remaining runnable modules so everything you run is diagnosable in production.
Route service-code `console.*` output through the module's structured logger (with named fields), so delivery outcomes and failures reach the log pipeline with a level.
Readiness · Readiness — Whether SAST, secret/dependency scanning and performance benchmarking are wired in (presence, not runtime).
Method: Filesystem scan: SAST configuration, dependency-update automation, secret scanning, and a benchmark harness or benchmark step — in this repository's own ecosystem. Exhaustive, deterministic.
`REDACTED` schedules updates, but no `package-ecosystem` entry covers `bun`, `uv`, which this tree depends on — so those dependencies get no update pull requests and no advisory pressure, however complete the dep-scan credit looks. Add the missing entries to the `updates:` list. — REDACTED:2
What to do
Dependabot is configured but does not watch `bun`, `uv` — add those `package-ecosystem` entries to REDACTED so those dependencies get the same automatic update and advisory pressure as the ones it already covers.
Readiness · Readiness — Whether releases are automated and safely reversible (probes, rolling updates, approval gates) — from manifests/pipeline files, not the live environment.
Method: Filesystem scan: deployment manifests/IaC (K8s YAML, Helm, Terraform) for rolling updates, probes, approval gates, migration hooks. Exhaustive, deterministic.
Do you agree with this assessment?
P5 · DR & Backup7.0 / 10Strong✓ Tool-verified
Readiness · Readiness — Whether disaster recovery is planned and codified — backups, geo-recovery, RTO/RPO, persistence guarantees — from IaC + container manifests + docs, never the live cloud.
Method: Filesystem scan: disaster recovery, backup, geo-recovery, RTO/RPO, persistence guarantees from IaC, manifests, and docs. Exhaustive, deterministic, never a live environment.
What to do
Document RTO/RPO and a tested restore procedure (a backup config alone isn't disaster recovery).
Readiness · Readiness — Whether outbound HTTP calls are wrapped in resilience (retry/timeout/circuit-breaker) so a failing dependency doesn't cascade.
Method: Source scan: outbound HTTP clients and what bounds them — resilience handlers (Polly, AddStandardResilienceHandler) on .NET; on Go, the JVM, Python, JavaScript/TypeScript, Ruby, PHP, Rust, Elixir, Swift, Dart and Erlang, a timeout, deadline, retry or breaker beside each call, or a process-wide client default (a framework-wide deadline such as Drupal core's, Laravel's or actix's awc counts). Exhaustive, deterministic.
`requests.get(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout. — headroom/ccr/batch_store.py:83
`urllib.request.urlopen(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout. (×2) — REDACTED:625, REDACTED:633
What to do
Pass `timeout=` on every `requests`/`httpx` call (requests has no default and will wait forever), mount an `HTTPAdapter(max_retries=Retry(...))` on shared sessions, and wrap calls to flaky dependencies in `tenacity` retries or a `pybreaker` circuit breaker.
Readiness · Performance — Whether the code protects its performance with benchmarks — a benchmark suite, allocation/memory measurement, and (ideally) a CI gate. Presence is credited as a bonus, never a deduction.
Method: Repo + source scan: BenchmarkDotNet referenced (csproj/source), [Benchmark]/[MemoryDiagnoser] attribute counts, and a benchmark step in CI; off .NET, the same ladder over Go testing.B, Rust criterion/#[bench]/divan, JMH/kotlinx-benchmark, pytest-benchmark/asv/pyperf, tinybench/mitata/vitest bench/benchmark.js and Swift package-benchmark — scored as a bonus ladder (absence is neutral, never a deduction). Deterministic, presence detection.
Readiness · Performance — Whether asynchronous code stays responsive — it avoids sync-over-async blocking (a .NET .Wait()/.GetAwaiter().GetResult(), a time.sleep or blocking HTTP call inside a Python coroutine, a *Sync call inside an async JavaScript function, block_on inside a Rust async fn, runBlocking inside a Kotlin suspend function, block() inside a Reactor publisher) that stalls a thread or event loop and risks deadlock, and, where the code is a reusable library on .NET, awaits with ConfigureAwait(false) so it never captures and stalls its caller's context.
Method: Production-source scan: sync-over-async blocking counted everywhere — .Wait()/.GetAwaiter().GetResult() in .NET; off .NET, read from each language's code model, a blocking call inside an async function (Python, TS/JS, Rust, Kotlin, Swift, Dart) or inside a Java method returning a Reactor Mono/Flux or a Scala method returning a Future or effect — and, for a .NET library with ≥5 awaits, the share of awaits using ConfigureAwait(false). Deterministic, syntax/text detection.
`run_demo` is async and calls urllib.request.urlopen — a blocking call inside async code stalls the event loop — every other task on it waits for as long as it runs. — REDACTED:275
What to do
Python: await the async equivalent (asyncio.sleep, an async HTTP client such as httpx.AsyncClient or aiohttp, asyncio.create_subprocess_exec), or move the blocking call off the loop with `await asyncio.to_thread(...)`; never call asyncio.run inside a coroutine — await the coroutine.
Do you agree with this assessment?
R1 · Type Safety8.4 / 10Strong✓ Tool-verified
React / JS · Code Health — How much of the frontend is typed TypeScript vs untyped JavaScript.
Method: Frontend file inventory: the share of typed TypeScript vs untyped JavaScript across the source tree. Deterministic, exhaustive over frontend files.
Do you agree with this assessment?
R10 · Code Duplication3.3 / 10Weak✓ Tool-verified
React / JS · Code Health — The share of the scored frontend lines inside a near-exact copy-pasted block of substantial extent (the D4 clone algorithm over JS/TS tokens, D-386; each line once, 10 at none and 0 at a quarter of the lines, as D4): a block is reported only where its copies still agree on most of their own identifiers and literals, or were renamed as they were pasted but kept most of their constants, and where the copies carry enough code to stand on their own or the copied extent reaches 30 lines — so a re-implementation sharing neither names nor values, and a small pasted declaration, are both found and deliberately not reported, and a clean R10 is not a claim that nothing was copied.
Method: Near-exact copy-pasted blocks of substantial extent across the frontend (the D4 clone algorithm run over JS/TS tokens). Masking finds the candidates; a block is reported when its copies still agree on most of their own identifiers and literals, or when a renamed copy still agrees on most of its constants, AND the copies carry enough code to stand on their own — or when the copied extent reaches 30 lines. So a re-implementation sharing neither names nor values, and a small pasted declaration, are deliberately not counted. Scored on the share of the scored frontend lines inside a reported copy, on the same curve as D4. Deterministic.
headroom/providers/opencode/hook-shim/handler.js:44 · plugins/opencode/src/transport.ts:114 — the two spans are one implementation copied and then locally edited — 3326 tokens are still identical, in the same order in both files, with only local edits between them. The copies have already begun to drift, which is this row's finding: an edit made to one and not the other changes behaviour silently. Diff the two spans first to learn what genuinely differs, then extract the shared core into one module both sites use, passing the differences in as parameters — or, if one copy exists only because the other could not be imported from its context, make one of them the single source the other is generated or re-exported from. If one copy is no longer reachable, delete it rather than letting it shadow the live one. — headroom/providers/opencode/hook-shim/handler.js:44
scripts/build_npm_release_assets.mjs:86 · scripts/verify_npm_release_assets.mjs:65 — the 2 copies are spread across 2 files, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — scripts/build_npm_release_assets.mjs:86
sdk/typescript/src/adapters/anthropic.ts:42 · sdk/typescript/src/adapters/openai.ts:42 — the two spans are one implementation copied and then locally edited — 135 tokens are still identical, in the same order in both files, with only local edits between them. The copies have already begun to drift, which is this row's finding: an edit made to one and not the other changes behaviour silently. Diff the two spans first to learn what genuinely differs, then extract the shared core into one module both sites use, passing the differences in as parameters — or, if one copy exists only because the other could not be imported from its context, make one of them the single source the other is generated or re-exported from. If one copy is no longer reachable, delete it rather than letting it shadow the live one. — sdk/typescript/src/adapters/anthropic.ts:42
plugins/openclaw/src/convert.ts:207 · plugins/openclaw/src/convert.ts:434 — all 2 copies are in the same file, and the CITED SPAN is a run of DECLARATIONS inside a construct — the members of a type, or the entries of an object or array literal — with no statement anywhere in it. Do not read this as an extract-a-helper row: nothing here executes, so there is no call site, and a call expression cannot stand where a member declaration or a literal's entry was. What repeats is a SHAPE, and which shape decides the move. Where the copies declare the same members, the repetition is a missing common ancestor: give it a base type, an interface both extend, a generic instantiated twice, or — where the copies are a literal's entries rather than a type's members — one shared constant each site spreads or refers to, so the set is written once. Where they declare DIFFERENT members and only the form is shared — a decorator and its options, an annotation, a registration table's keys — the form is prescribed by a framework or a schema rather than copied, and the only collapse available is to generate the declarations from that schema; where you do not own the generator, this is the cost of the framework and there is nothing to extract. Check which of the two it is before acting: these copies still drift apart the first time only one of them is edited, which is why the repetition is reported, but the sentence to act on is not the same in both cases. — plugins/openclaw/src/convert.ts:207
plugins/opencode/src/plugin.ts:244 · plugins/opencode/src/plugin.ts:292 — the two spans are one implementation copied and then locally edited — 79 tokens are still identical, in the same order in both spans, with only local edits between them. The copies have already begun to drift, which is this row's finding: an edit made to one and not the other changes behaviour silently. Diff the two spans first to learn what genuinely differs, then extract the shared core into one module both sites use, passing the differences in as parameters — or, if one copy exists only because the other could not be imported from its context, make one of them the single source the other is generated or re-exported from. If one copy is no longer reachable, delete it rather than letting it shadow the live one. — plugins/opencode/src/plugin.ts:244
plugins/openclaw/src/convert.ts:504 · plugins/openclaw/src/convert.ts:535 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — plugins/openclaw/src/convert.ts:504
scripts/verify_npm_release_assets.mjs:139 · scripts/verify_npm_release_assets.mjs:158 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. — scripts/verify_npm_release_assets.mjs:139
plugins/openclaw/src/proxy-manager.ts:288 · plugins/openclaw/src/proxy-manager.ts:306 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. — plugins/openclaw/src/proxy-manager.ts:288
sdk/typescript/src/errors.ts:11 · sdk/typescript/src/errors.ts:37 · sdk/typescript/src/errors.ts:51 · sdk/typescript/src/errors.ts:65 — all 4 copies are in the same file, and each CITED SPAN is a SPECIALISATION DECLARATION — a type whose `extends` clause names a base and whose body hands that base its own values through `super(…)`. The shared module this dimension usually asks you to extract already exists: it is that base, every one of these sites already reaches it, and the `super(…)` call this row matched on is where each site passes its differences in. So do not read this as an extract-a-helper row — there is no missing helper, and what is left at each site is the declaration of one distinct specialisation, which cannot be deleted without deleting the thing it declares. Read what actually differs between the spans, because two different answers follow. Where the sites differ only in the values they hand the base — a type argument, a service, an alias, a cache — the repetition is a TEMPLATE, and the only moves that collapse it are to generate these declarations from the set they enumerate or to replace the repeated construction with one factory each site calls with its own values; where that set is the point, each site pinning one distinct thing, the repetition IS the enumeration and there is nothing to remove. Where instead a span carries logic OUTSIDE the delegation that is the same at every site, that logic is the part to move, and its home is the base type rather than a new module. Reported because the copies still drift apart the first time only one of them is edited. — sdk/typescript/src/errors.ts:11
sdk/typescript/src/utils/format.ts:898 · sdk/typescript/src/utils/format.ts:957 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. — sdk/typescript/src/utils/format.ts:898
sdk/typescript/src/client.ts:145 · sdk/typescript/src/client.ts:206 — all 2 copies are in the same file, and the SHAPE of this repetition could not be determined. It is not a run of declarations, a listing, a declaration header, a type body or a slice through a construct — and it was not measured as a run of executable statements either, so this row cannot tell you whether a function can stand where these lines are. Read the two spans before acting, because the move is opposite in the two cases. Where they are statements, the ordinary answer holds: give the shared part one home and call it from each site. Where they turn out to be declarations, a literal's entries, or the cases of an enumeration, there is no call site to call anything from, and collapsing them would delete what each copy pins — a shared base type, a generated set, or one exported constant each site refers to is the move instead, and sometimes the honest answer is that there is nothing to extract at all. Reported because the copies drift apart the first time only one of them is edited, which is true whichever of those they are. — sdk/typescript/src/client.ts:145
headroom/providers/opencode/hook-shim/handler.js:133 · headroom/providers/opencode/hook-shim/handler.js:143 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. — headroom/providers/opencode/hook-shim/handler.js:133
sdk/typescript/src/utils/format.ts:279 · sdk/typescript/src/utils/format.ts:998 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — sdk/typescript/src/utils/format.ts:279
sdk/typescript/src/utils/format.ts:307 · sdk/typescript/src/utils/format.ts:692 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — sdk/typescript/src/utils/format.ts:307
sdk/typescript/src/utils/format.ts:543 · sdk/typescript/src/utils/format.ts:570 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — sdk/typescript/src/utils/format.ts:543
sdk/typescript/src/client.ts:373 · sdk/typescript/src/client.ts:389 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — sdk/typescript/src/client.ts:373
sdk/typescript/src/paths.ts:174 · sdk/typescript/src/paths.ts:189 · sdk/typescript/src/paths.ts:204 · sdk/typescript/src/paths.ts:219 — all 4 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — sdk/typescript/src/paths.ts:174
plugins/openclaw/src/proxy-manager.ts:347 · plugins/openclaw/src/proxy-manager.ts:389 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — plugins/openclaw/src/proxy-manager.ts:347
sdk/typescript/src/client.ts:301 · sdk/typescript/src/client.ts:333 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — sdk/typescript/src/client.ts:301
sdk/typescript/src/client.ts:474 · sdk/typescript/src/client.ts:501 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — sdk/typescript/src/client.ts:474
sdk/typescript/src/shared-context.ts:114 · sdk/typescript/src/shared-context.ts:129 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — sdk/typescript/src/shared-context.ts:114
sdk/typescript/src/utils/format.ts:194 · sdk/typescript/src/utils/format.ts:241 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — sdk/typescript/src/utils/format.ts:194
plugins/openclaw/src/convert.ts:475 · plugins/openclaw/src/convert.ts:518 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — plugins/openclaw/src/convert.ts:475
plugins/openclaw/src/tools/headroom-retrieve.ts:63 · plugins/opencode/src/retrieve.ts:58 — the 2 copies are spread across 2 directories, so the shared home is a decision rather than an obvious spot: check first whether one of them already owns this behaviour, and otherwise put the extracted module somewhere all of the sites already reach rather than making one of them depend on another. — plugins/openclaw/src/tools/headroom-retrieve.ts:63
scripts/verify_sdk_provider_peers.mjs:42 · scripts/verify_sdk_provider_peers.mjs:68 — the two spans are one implementation copied and then locally edited — 58 tokens are still identical, in the same order in both spans, with only local edits between them. The copies have already begun to drift, which is this row's finding: an edit made to one and not the other changes behaviour silently. Diff the two spans first to learn what genuinely differs, then extract the shared core into one module both sites use, passing the differences in as parameters — or, if one copy exists only because the other could not be imported from its context, make one of them the single source the other is generated or re-exported from. If one copy is no longer reachable, delete it rather than letting it shadow the live one. — scripts/verify_sdk_provider_peers.mjs:42
sdk/typescript/src/utils/format.ts:205 · sdk/typescript/src/utils/format.ts:255 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. — sdk/typescript/src/utils/format.ts:205
sdk/typescript/src/utils/format.ts:261 · sdk/typescript/src/utils/format.ts:974 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — sdk/typescript/src/utils/format.ts:261
plugins/headroom-snip/hooks/register.tsx:233 · plugins/headroom-snip/hooks/register.tsx:302 — all 2 copies are in the same file, and the CITED SPAN is a run of DECLARATIONS inside a construct — the members of a type, or the entries of an object or array literal — with no statement anywhere in it. Do not read this as an extract-a-helper row: nothing here executes, so there is no call site, and a call expression cannot stand where a member declaration or a literal's entry was. What repeats is a SHAPE, and which shape decides the move. Where the copies declare the same members, the repetition is a missing common ancestor: give it a base type, an interface both extend, a generic instantiated twice, or — where the copies are a literal's entries rather than a type's members — one shared constant each site spreads or refers to, so the set is written once. Where they declare DIFFERENT members and only the form is shared — a decorator and its options, an annotation, a registration table's keys — the form is prescribed by a framework or a schema rather than copied, and the only collapse available is to generate the declarations from that schema; where you do not own the generator, this is the cost of the framework and there is nothing to extract. Check which of the two it is before acting: these copies still drift apart the first time only one of them is edited, which is why the repetition is reported, but the sentence to act on is not the same in both cases. — plugins/headroom-snip/hooks/register.tsx:233
scripts/verify_anthropic_peer.mjs:10 · scripts/verify_sdk_provider_peers.mjs:13 — the 2 copies are spread across 2 files, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported. — scripts/verify_anthropic_peer.mjs:10
sdk/typescript/src/utils/case.ts:14 · sdk/typescript/src/utils/case.ts:25 — the two spans are one implementation copied and then locally edited — 67 tokens are still identical, in the same order in both spans, with only local edits between them. The copies have already begun to drift, which is this row's finding: an edit made to one and not the other changes behaviour silently. Diff the two spans first to learn what genuinely differs, then extract the shared core into one module both sites use, passing the differences in as parameters — or, if one copy exists only because the other could not be imported from its context, make one of them the single source the other is generated or re-exported from. If one copy is no longer reachable, delete it rather than letting it shadow the live one. — sdk/typescript/src/utils/case.ts:14
What to do
Act on each finding's own remediation rather than one rule: the move depends on what recurs. Where the copies are executable blocks, give the shared part one home and call it from each site; where they are declarations, a listing, a specialisation already delegating to its base, or one shape repeated per entity, there is no call site and the move is a shared type, a generated set or a factory — sometimes there is nothing to extract.
React / JS · Code Health — Per-function cyclomatic/cognitive complexity from the token-level function scanner (D-386) — real branching, not a regex heuristic.
Method: Per-function cyclomatic/cognitive complexity from a token-level function scanner (real branching, not a regex heuristic), computed over every frontend function. Deterministic.
vercelToOpenAI has cyclomatic complexity 48 and cognitive complexity 136; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/utils/format.ts:534
detectFormat has cyclomatic complexity 44 and cognitive complexity 81; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/utils/format.ts:39
openAIToVercel has cyclomatic complexity 40 and cognitive complexity 123; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/utils/format.ts:672
vercelMediaImageUrl has cyclomatic complexity 32 and cognitive complexity 36; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/utils/format.ts:419
clean has cyclomatic complexity 30 and cognitive complexity 46; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — deploy/beacon/worker.js:207
openAIToGemini has cyclomatic complexity 29 and cognitive complexity 80; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/utils/format.ts:1005
agentToOpenAI has cyclomatic complexity 27 and cognitive complexity 64; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/convert.ts:29
openAIToAgent has cyclomatic complexity 27 and cognitive complexity 64; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/convert.ts:155
start has cyclomatic complexity 26 and cognitive complexity 30; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/proxy-manager.ts:73
describe has cyclomatic complexity 24 and cognitive complexity 21; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/headroom-snip/hooks/snip.ts:103
vercelMediaPart has cyclomatic complexity 20 and cognitive complexity 26; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/utils/format.ts:476
geminiToOpenAI has cyclomatic complexity 19 and cognitive complexity 51; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/utils/format.ts:880
buildLaunchSpecs has cyclomatic complexity 19 and cognitive complexity 25; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/proxy-manager.ts:214
openAIToAnthropic has cyclomatic complexity 18 and cognitive complexity 48; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/utils/format.ts:286
rollupHour has cyclomatic complexity 18 and cognitive complexity 38; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — deploy/beacon/worker.js:388
anthropicToOpenAI has cyclomatic complexity 17 and cognitive complexity 60; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/utils/format.ts:190
anthropicMediaImageUrl has cyclomatic complexity 17 and cognitive complexity 17; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/utils/format.ts:139
assemble has cyclomatic complexity 17 and cognitive complexity 16; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/engine.ts:122
(anonymous) has cyclomatic complexity 15 and cognitive complexity 18; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/convert.ts:480
applyGatewayProviderBaseUrlsInPlace has cyclomatic complexity 15 and cognitive complexity 18; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/gateway-config.ts:67
fetch has cyclomatic complexity 15 and cognitive complexity 16; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — deploy/beacon/worker.js:528
migrateLegacyLog has cyclomatic complexity 14 and cognitive complexity 16; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/advancement-key-store.ts:195
anthropicMediaBlock has cyclomatic complexity 14 and cognitive complexity 14; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/utils/format.ts:168
rawFetch has cyclomatic complexity 13 and cognitive complexity 14; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/client.ts:527
(anonymous) has cyclomatic complexity 13 and cognitive complexity 13; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/test/client-expanded.test.ts:36
probeHeadroomProxy has cyclomatic complexity 13 and cognitive complexity 10; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/proxy-manager.ts:448
extractToolCalls has cyclomatic complexity 12 and cognitive complexity 22; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — sdk/typescript/src/hooks.ts:97
replaceTextBlocks has cyclomatic complexity 12 and cognitive complexity 18; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/convert.ts:361
scheduled has cyclomatic complexity 12 and cognitive complexity 17; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — deploy/beacon/worker.js:474
bar has cyclomatic complexity 12 and cognitive complexity 15; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/headroom-snip/hooks/snip.ts:220
(anonymous) has cyclomatic complexity 12 and cognitive complexity 11; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/headroom-snip/hooks/snip.ts:75
(anonymous) has cyclomatic complexity 12 and cognitive complexity 10; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. (×2) — plugins/headroom-snip/hooks/register.tsx:184, plugins/headroom-snip/hooks/register.tsx:259
extract has cyclomatic complexity 11 and cognitive complexity 17; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — deploy/beacon/worker.js:323
unwrap has cyclomatic complexity 11 and cognitive complexity 11; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — deploy/beacon/worker.js:296
withCompressedArguments has cyclomatic complexity 11 and cognitive complexity 11; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/convert.ts:380
(anonymous) has cyclomatic complexity 11 and cognitive complexity 10; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes. — plugins/openclaw/src/convert.ts:523
Do you agree with this assessment?
R3 · Large Files4.3 / 10Weak✓ Tool-verified
React / JS · Code Health — How many source files exceed the large-file threshold.
Method: Components/modules exceeding the large-file threshold, counted exhaustively across the frontend source tree. Deterministic.
sdk/typescript/src/utils/format.ts has 1020 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module. — sdk/typescript/src/utils/format.ts:1
plugins/opencode/src/transport.ts has 810 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module. — plugins/opencode/src/transport.ts:1
deploy/beacon/worker.js has 600 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module. — deploy/beacon/worker.js:1
headroom/providers/opencode/hook-shim/handler.js has 585 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module. — headroom/providers/opencode/hook-shim/handler.js:1
sdk/typescript/src/client.ts has 550 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module. — sdk/typescript/src/client.ts:1
plugins/openclaw/src/convert.ts has 500 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module. — plugins/openclaw/src/convert.ts:1
plugins/openclaw/src/proxy-manager.ts has 469 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module. — plugins/openclaw/src/proxy-manager.ts:1
What to do
Split each oversized file along the responsibilities already in it, into smaller focused modules in the same package.
Do you agree with this assessment?
R4 · Test Coverage8.3 / 10Exemplary✓ Tool-verified
React / JS · Readiness — Static test reachability (D-386): the share of production files reachable from any test via the import graph — measured without running anything.
Method: Static test reachability: the share of production files reachable from any test via the import graph — measured without running anything. Deterministic.
No test imports this module directly or transitively. Import reachability cannot see a test that executes a file by path instead of importing it, nor one that drives it through a running browser by navigating to a URL — if neither does, no test reaches this one. (×6) — headroom/providers/opencode/hook-shim/handler.js:1, deploy/beacon/test-rollup.mjs:1, plugins/headroom-snip/hooks/register.tsx:1, …
What to do
Add tests that import the unreached modules (directly or through their public entry).
React / JS · Readiness — How outdated the npm dependencies are (a maturity signal). JS/npm CVEs are scored separately in D30 (JS/npm Dependency Vulnerabilities).
Method: npm dependency staleness from manifest/registry metadata (a maturity signal; JS/npm CVEs are scored separately in D30, which answers dependency vulnerabilities for every ecosystem). Deterministic.
Do you agree with this assessment?
R6 · Tooling10.0 / 10Exemplary✓ Tool-verified
React / JS · Readiness — Whether the project wires up test, lint and typecheck — detected from each package.json script's COMMAND (eslint / tsc / vitest / jest / playwright), not just its name, and corroborated against CI-workflow invocations so a tool run only in CI still counts.
Method: package.json scanned for test/lint/typecheck script wiring. Deterministic presence check.
Do you agree with this assessment?
R7 · Dead Code9.1 / 10Exemplary✓ Tool-verified
React / JS · Code Health — Files unreachable from every application/tooling/test entry point, and exports nothing imports (module-graph reachability, D-386).
Method: Dead code: files unreachable from every application/tooling/test entry point plus exports nothing imports, via module-graph reachability. Deterministic, exhaustive over the import graph.
Unreachable from the 21 application, 12 tooling and 42 test entry point(s) detected in this repo. Gate removals on `npm run build` — an undetected custom entry would make these reachable.
no import path from any entry point (21 application, 12 tooling, 42 test roots considered), and no other file in the scanned tree imports it — nothing in-repo names this module at all, which is the strongest form of this claim the import graph can make (×5) — plugins/headroom-snip/hooks/register.tsx, scripts/verify_sdk_provider_peers.mjs, scripts/verify_anthropic_peer.mjs, …
What to do
Delete the dead files and unused exports — every line is maintenance cost and rebuild-estimate inflation with zero runtime value.
React / JS · Readiness — npm dependency truthfulness (D-386): unused dependencies, imports not declared anywhere, and type-/test-only packages shipped as production deps.
Method: npm dependency truthfulness: unused dependencies, imports declared nowhere, and type-/test-only packages shipped as production deps — from the manifest + import graph. Deterministic.
Imported but not declared in any reachable package.json — installs work only by hoisting accident. (×2) — scripts/verify_docs_anthropic_sdk.mjs:9, plugins/opencode/src/plugin.ts:4
Declared in e2e/wrap/tools/package.json but never imported anywhere in that package or its workspace members — no static import reaches it. Usually that is dead weight and attack surface, but two shapes are indistinguishable from source and are NOT dead: an optional or native peer that another dependency loads dynamically at runtime, and a package a build, docs or test step installs and invokes separately. Confirm which of the three this is before removing it.
Declared in plugins/openclaw/package.json but never imported anywhere in that package or its workspace members — no static import reaches it. Usually that is dead weight and attack surface, but two shapes are indistinguishable from source and are NOT dead: an optional or native peer that another dependency loads dynamically at runtime, and a package a build, docs or test step installs and invokes separately. Confirm which of the three this is before removing it.
Declared in plugins/opencode/package.json but never imported anywhere in that package or its workspace members — no static import reaches it. Usually that is dead weight and attack surface, but two shapes are indistinguishable from source and are NOT dead: an optional or native peer that another dependency loads dynamically at runtime, and a package a build, docs or test step installs and invokes separately. Confirm which of the three this is before removing it.
What to do
Remove unused dependencies, declare unlisted imports explicitly, and demote type-/test-only packages to devDependencies.
React / JS · Architecture — Import cycles in the module graph (D-386) — files that can only be understood and changed together.
Method: Import cycles in the module graph, detected exhaustively over JS/TS imports (the same cycle detection as the .NET coupling dimension). Deterministic.
Other · Security — Only what this repository's own non-C# files could be read for was assessed — and because this repository commits the configuration that serves its own HTTP surface, that configuration could be read in full for the security response headers it sets. Nothing else in this dimension was assessed: the transport, cookie, input-validation and crypto controls are read from a source model that was not loaded for this repository’s language, so their absence here is not a finding about this repository.
Method: Roslyn plus filesystem scan: HSTS/security headers, secure cookies, input validation, middleware order, weak crypto (MD5/SHA1/DES); HTTPS-metadata context-aware. On a repository with no .NET source it reads JavaScript/TypeScript, Dart, Ruby, Scala, Rust or Elixir source itself (test, vendored, generated and minified paths not) for the arms that hold whether or not the code serves HTTP: a weak hash or cipher, key material fixed in the source, a TLS client that accepts any certificate, and (JavaScript/TypeScript, Ruby, Scala, Rust and Elixir) an obsolete TLS version; the server controls are not assessed there, and a Dart, Ruby, Scala, Rust or Elixir repository that serves no HTTP of its own is N/A on them. Deterministic.
None of the 11 security response headers the OWASP Secure Headers Project recommends (Content-Security-Policy, Strict-Transport-Security, X-Content-Type-Options, X-Frame-Options, …) is configured — defense in depth, even when a reverse proxy could set them. This is reported because `vercel.json` configures this repository's static hosting, including its response headers, so the configuration that would carry these headers is in this repository and was read in full. (−2.0 on this card.) — docs/vercel.json:1
What to do
Set security response headers on the surface this repository serves: an `add_header` directive per header in the nginx/Caddy/Apache config, a `_headers` / `vercel.json` / `netlify.toml` entry for a static host, or `helmet()` in the HTTP server. `Content-Security-Policy` is the one that pays for itself first — it is what contains an injected script once one reaches the page — followed by `X-Content-Type-Options: nosniff` and a frame policy (`X-Frame-Options: DENY`, or CSP `frame-ancestors`). Where the app is served from a build container, the header configuration belongs in the image beside the built assets, so it ships with them rather than depending on where it lands.
Other · Code Health — Whether the code avoids sync-over-async (deadlock-prone blocking on tasks) and async void.
Method: Roslyn syntax scan: async methods scanned for .Wait()/.GetAwaiter().GetResult() and async-void outside event handlers. Deterministic, hard fact per invocation.
The task this creates is not kept anywhere. The event loop holds only a weak reference to its tasks, so a task nobody references can be garbage-collected before it finishes (Python's documentation for `asyncio.create_task`: save a reference to the result); and nothing ever awaits it, so an exception it raises is never handled — it surfaces, if at all, as "Task exception was never retrieved" in a log. Keep the task: `await` it, gather it, start it in an `asyncio.TaskGroup` (`async with asyncio.TaskGroup() as tg: tg.create_task(…)`), or, for genuine fire-and-forget, add it to a set and `task.add_done_callback(tasks.discard)` with a callback that also reads its exception. — headroom/subscription/codex_rate_limits.py:512
Other · Code Health — Whether any branch is dead by construction — a switch arm whose label can never equal a case-normalised subject, or an `else if` whose predicate the arm above has already swallowed.
Method: Roslyn syntax + semantics: switch labels compared against the subject's own case normaliser, and if/else-if chains checked for a literal an earlier arm's containment test already swallows. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X13 · Undrained process stream10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a child process that has BOTH standard streams redirected drains both — reading one to the end while the other is never read deadlocks once the child fills the unread pipe.
Method: Roslyn syntax + semantics: ProcessStartInfo launches with both streams redirected, checked for a drain of each stream across the enclosing type. On a repository with no .NET source it reads JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not) with the same rule: a `spawn` imported from `child_process` whose stdout and stderr are both pipes (no options, no `stdio`, or `stdio` of `'pipe'`), bound to a local that never leaves its scope, where exactly one of the two streams is read, the other never, and the child’s `close`/`exit` (or the read stream’s end) is awaited; a shell redirect in the call’s arguments or a `kill` of the child suppresses it. The same rule reads Python’s `subprocess.Popen`, Dart’s `Process.start`, Ruby’s `Open3.popen3`, and Scala’s JDK process starts (`new ProcessBuilder(…).start()` with no `redirectErrorStream`/`redirectError`/`redirectOutput`/`inheritIO`, `Runtime.getRuntime.exec`) where one of `getInputStream`/`getErrorStream` is read and the other never while `waitFor()` is called or the read stream is read to its end. Deterministic, provable per finding. Advisory.
Other · Security — Whether a hand-rolled public/private IP check can be walked past — a method that unwraps IPv4-mapped IPv6 but returns the opposite verdict for the same host written as IPv4-compatible, 6to4 or NAT64.
Method: Roslyn syntax + semantics: methods that unwrap IPv4-mapped IPv6 and hand-roll IPv4 range carve-outs, checked for whether the IPv6 branch also accounts for the IPv4-compatible, 6to4 and NAT64 embeddings. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X17 · Uncapped recursion over a caller-supplied document1.3 / 10Critical✓ Tool-verified
Other · Security — Whether a walk that recurses through a JSON/XML tree handed in by its caller bounds how deep it will go — an uncapped walk lets the document's nesting choose the stack depth, and the resulting StackOverflowException cannot be caught.
Method: Roslyn syntax + semantics: methods that take a JSON/XML document node and call themselves with a child of it, reachable from an externally-callable member of the same type that accepts a document, checked for any depth parameter, descent counter or threaded arithmetic anywhere in the walk. On a repository with no .NET source it reads TypeScript off the engine’s own token stream (test, vendored, generated and minified paths and `.d.ts` not) with the same rule: a function or method with a parameter typed as a document value — `unknown`, `any`, `object`, `Record<string, unknown|any>`, a JSON alias (`JsonValue`, `JSONObject`, …) or a DOM node global the file does not rebind — that calls itself (bare, or through `this` for a method, or hands itself to a call over the value as in `value.map(walk)`) with something it took out of that value and never through an ancestor accessor such as `closest()` or `parentElement`, that is exported or reached from an exported function (a public method of the same exported class) taking such a value, and that names no depth, level, nesting, recursion, remaining or budget anywhere and threads no `+`/`-` arithmetic through a self-call. Plain JavaScript is not read: with no annotation nothing tells a parsed document from a tree the code built itself. Deterministic, provable per finding. Advisory.
`deepCamelCase` is exported and takes `obj: any` from its caller, and it calls itself at line 16 (`deepCamelCase`) with a piece of `obj` (and at line 19) — and nowhere in `deepCamelCase` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. JavaScript sets no limit of its own on that nesting: `JSON.parse` accepts any depth, so a 100,000-byte body — inside Express's default 100kb limit — parses to 50,000 levels, and a walk like this one throws `RangeError: Maximum call stack size exceeded` long before it reaches the bottom. Wherever that throw lands, the work fails: a request errors, and a walk running outside any `try` — an event handler, a timer, a promise nobody awaits — takes the Node process down with every other request in flight. Thread a depth argument through `deepCamelCase` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — sdk/typescript/src/utils/case.ts:16
`deepSnakeCase` is exported and takes `obj: any` from its caller, and it calls itself at line 27 (`deepSnakeCase`) with a piece of `obj` (and at line 30) — and nowhere in `deepSnakeCase` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. JavaScript sets no limit of its own on that nesting: `JSON.parse` accepts any depth, so a 100,000-byte body — inside Express's default 100kb limit — parses to 50,000 levels, and a walk like this one throws `RangeError: Maximum call stack size exceeded` long before it reaches the bottom. Wherever that throw lands, the work fails: a request errors, and a walk running outside any `try` — an event handler, a timer, a promise nobody awaits — takes the Node process down with every other request in flight. Thread a depth argument through `deepSnakeCase` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — sdk/typescript/src/utils/case.ts:27
`unwrap_tool_call` is public, takes a document from its caller (line 546) and hands it to `_decoded_strings`, which calls itself at line 496 (`_decoded_strings`) with a piece of `value` — and nowhere in `_decoded_strings` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_decoded_strings` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/config.py:496
`strip_streaming_only_content_fields_in_place` is public, takes a document from its caller (line 429) and hands it to `_strip_index_from_content_blocks_in_place`, which calls itself at line 455 (`_strip_index_from_content_blocks_in_place`) with a piece of `content` — and nowhere in `_strip_index_from_content_blocks_in_place` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_strip_index_from_content_blocks_in_place` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — REDACTED:455
`build_otlp_logs` is public, takes a document from its caller (line 1565) and hands it to `_any_value`, which calls itself at line 1557 (`_any_value`) with a piece of `value` (and at line 1561) — and nowhere in `_any_value` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_any_value` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — REDACTED:1557
`strip_safeguard_payload` is public and takes `value: Any` from its caller, and it calls itself at line 131 (`strip_safeguard_payload`) with a piece of `value` (and at line 136) — and nowhere in `strip_safeguard_payload` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `strip_safeguard_payload` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/proxy/anthropic_wire.py:131
`compute_turn_id` is public, takes a document from its caller (line 3575) and hands it to `_strip_per_call_annotations`, which calls itself at line 3569 (`_strip_per_call_annotations`) with a piece of `obj` (and at line 3571) — and nowhere in `_strip_per_call_annotations` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_strip_per_call_annotations` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/proxy/helpers.py:3569
`redact_image_base64_value` is public, takes a document from its caller (line 77) and hands it to `_redact_value`, which calls itself at line 100 (`_redact_value`) with a piece of `value` (and at line 112) — and nowhere in `_redact_value` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_redact_value` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/proxy/request_log_redaction_policy.py:100
`strip_cache_control` is public, takes a document from its caller (line 105) and hands it to `_strip_cache_control`, which calls itself at line 119 (`_strip_cache_control`) with a piece of `obj` (and at line 124) — and nowhere in `_strip_cache_control` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_strip_cache_control` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/proxy/semantic_cache_key_policy.py:119
`compact_tool_schema_value` is public and takes `value: Any` from its caller, and it calls itself at line 218 (`compact_tool_schema_value`) with a piece of `value` (and at line 234) — and nowhere in `compact_tool_schema_value` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `compact_tool_schema_value` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/proxy/tool_schema_compaction.py:218
`compact_tool_descriptions` is public, takes a document from its caller (line 371) and hands it to `_truncate_descriptions_in_schema`, which calls itself at line 341 (`_truncate_descriptions_in_schema`) with a piece of `value` (and at line 360) — and nowhere in `_truncate_descriptions_in_schema` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_truncate_descriptions_in_schema` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/proxy/tool_schema_compaction.py:341
`redact_for_wire_debug` is public and takes `value: Any` from its caller, and it calls itself at line 60 (`redact_for_wire_debug`) with a piece of `value` (and at line 65) — and nowhere in `redact_for_wire_debug` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `redact_for_wire_debug` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/proxy/wire_debug_redaction_policy.py:60
`sanitize_anthropic_model_metadata` is public and takes `value: Any` from its caller, and it calls itself at line 98 (`sanitize_anthropic_model_metadata`) with a piece of `value` (and at line 107) — and nowhere in `sanitize_anthropic_model_metadata` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `sanitize_anthropic_model_metadata` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/providers/anthropic.py:98
`estimate_object_size` is public and takes `obj: Any` from its caller, and it calls itself at line 375 (`estimate_object_size`) with a piece of `obj` (and at line 378, line 380) — and nowhere in `estimate_object_size` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `estimate_object_size` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/memory/tracker.py:375
`probe_event` is public, takes a document from its caller (line 266) and hands it to `_all_text`, which calls itself at line 208 (`_all_text`) with a piece of `node` (and at line 211) — and nowhere in `_all_text` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_all_text` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/evals/session_probes.py:208
`resolve_markers_in_response` is public and takes `response: Any` from its caller, and it calls itself at line 77 (`resolve_markers_in_response`) with a piece of `response` (and at line 80) — and nowhere in `resolve_markers_in_response` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `resolve_markers_in_response` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — headroom/ccr/marker_resolution.py:77
`segment_fingerprint` is public, takes a document from its caller (line 582) and hands it to `_canonicalize_for_prefix_compare`, which calls itself at line 262 (`_canonicalize_for_prefix_compare`) with a piece of `obj` (and at line 265) — and nowhere in `_canonicalize_for_prefix_compare` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_canonicalize_for_prefix_compare` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack. — REDACTED:262
What to do
Each finding names the externally-callable member that accepts the document and the self-call that descends, and states that no depth parameter or counter exists anywhere in the walk. Confirm from the two, then thread a depth argument through the walk and reject documents past a fixed maximum, or rewrite it with an explicit stack.
Other · Code Health — Whether a method that temporarily changes state belonging to the whole process — the working directory, an environment variable — puts it back on EVERY path: a restore reached only when nothing throws leaks the change to the rest of the process.
Method: Roslyn syntax + semantics: method bodies that write the process working directory or an environment variable and write it back in the same body, checked for whether that restore sits in a `finally`/`catch` or only on the straight-line path. On a repository with no .NET source the same rule reads production JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not): `process.chdir`, `process.env.NAME =`/`["NAME"] =` and `delete process.env.NAME`, and Deno’s `Deno.chdir`/`Deno.env.set`/`Deno.env.delete`, paired per function body (a nested function or arrow is its own body, and module top-level code is none), where the last write puts back a local the body captured from the same global or deletes a variable the first write set, with at least one statement between them; a write in a `catch`/`finally` of that body silences it. Deterministic, provable per finding. Advisory.
`_demo` changes state that belongs to the whole PROCESS and changes it back at the end of the same body — the `DISABLE_PROMPT_CACHING` environment variable (set at line 285, cleared at line 289) and the `DISABLE_PROMPT_CACHING_OPUS` environment variable (set at line 290, cleared at line 293) and the `ENABLE_PROMPT_CACHING_1H` environment variable (set at line 294, cleared at line 298) — which says the change was meant to last no longer than this call. But the restore is an ordinary statement on the straight-line path, not a `finally`, so it is skipped by any exception raised in between: the process then keeps the overwritten value for the rest of its life, and every later relative path, `subprocess` launch, `os.environ` read or `print` in ANY module sees it. That failure is silent and remote from its cause — the function that breaks is not the function that moved the value. The window is not private while it is open either: the working directory, the environment, the umask and `sys.stdout` are per-process, not per-thread, so a concurrent thread sees the moved value too. The durable fix is not to widen the restore but to stop mutating the global: pass the value to the operation that needs it — the `cwd=` and `env=` arguments of `subprocess.run`/`Popen` scope both to the CHILD, absolute paths built with `os.path.join` or `pathlib` need no working directory, and a stream handed to the code that writes needs no `sys.stdout`. Where the global genuinely must move, `contextlib.chdir` (3.11+), `contextlib.redirect_stdout` or a `try`/`finally` makes the restore run on every path. — headroom/transforms/cold_prefix.py:239
What to do
Each finding names the statement that changes the process-global value and the statement that puts it back. Confirm from the two that nothing between them is protected — then prefer removing the mutation over widening the restore: a working directory or an environment variable passed to the operation that needs it (the `cwd` and `env` options of `child_process`, or of `Deno.Command`) is scoped to that operation, which is what the save-and-restore was trying to approximate. Where the global genuinely must move, a `try`/`finally` is the least that makes the restore unconditional. In Python the same holds for `os.chdir`, `os.environ` and `sys.stdout`: pass `cwd=`/`env=` to `subprocess`, or use `contextlib.chdir`/`redirect_stdout`, rather than moving the global by hand.
Other · Code Health — Whether async functions that make a cancellable request accept or pass on an AbortSignal (adoption curve).
Method: Roslyn scan: every async method (excluding framework-fixed overrides/Blazor handlers) checked for CancellationToken parameter presence. Deterministic, adoption percentage. On a repository with no .NET source it reads JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not) with the same question: every named async function that itself makes a request an AbortSignal can cancel (global `fetch`, axios and its file-local instances, ky, ofetch) counts, and it is compliant when its parameters or body name a signal or it hands one of its own parameters to the request as options; signatures a framework fixes (JSX event handlers, route and lifecycle exports, request-first handlers, `override`, `'use server'` modules, TanStack `mutationFn`) are exempt unless they take a signal. Deterministic, adoption percentage.
Other · Code Health — Whether a `when` guard is free of side effects — a guard that increments a counter or assigns while deciding whether its arm matches applies that change during PATTERN MATCHING, on an arm that may not be selected, and skips it entirely when a short-circuit to its left answers first.
Method: Roslyn syntax: `when` guards on case labels and switch-expression arms, read for a mutation (`++`/`--`/assignment) sitting in a position the guard's own `&&`/`||`/`??`/`?:`/`?.` can skip. Deterministic, provable per finding. Advisory.
Other · Code Health — Whether the work a diagnostic log line costs is paid only when that line is wanted — C# evaluates a call's arguments BEFORE the call, so a trace/debug message joined or projected out of a collection is built in full on every pass, and then discarded by a sink the shipped configuration leaves switched off.
Method: Roslyn syntax: log calls at a diagnostic level (a `Log`-prefixed method naming Trace/Debug/Verbose, or a bare `Debug`/`Trace`/`Verbose` on a receiver named for a logger), whose argument list is read for a call whose cost scales with a sequence — a LINQ operator, a materialisation, `string.Join`, a serializer — with no enclosing level check or conditional-compilation region. On a repository with no .NET source it reads JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not) with the same rule: a `debug`/`trace`/`verbose` call on a receiver named for a logger, or a `log`-prefixed method naming the level, whose argument calls an array operator (`map`/`filter`/`reduce`/`sort`/…), `Array.from`, `Object.keys/values/entries`, `JSON.stringify`/`util.inspect` over anything but a literal, or an array `join` — outside any arrow or function passed as an argument, which the logger calls only when the level is on — with no enclosing `if`, `&&` or `?:` whose condition names a level, a level string, or the `NODE_ENV`/`__DEV__`/`DEV` build switch. Deterministic, provable per finding. Advisory.
`debug` at line 4258 is called with an argument built by `"…".join(map(str, out.warnings))` (line 4259), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on. — headroom/transforms/content_router.py:4258
`debug` at line 363 is called with an argument built by `list(snapshot.categories.keys())` (line 366), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on. — headroom/subscription/copilot_quota.py:363
`debug` at line 378 is called with an argument built by `sorted(tool_input.keys())` (line 380), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on. — headroom/proxy/interceptors/astgrep.py:378
`debug` at line 8091 is called with an argument built by `[k for k in upstream_headers if k.lower() != "…"]` (line 8093), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on. — REDACTED:8091
`debug` at line 213 is called with an argument built by `sorted(payload.keys())` (line 213), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on. — REDACTED:213
`debug` at line 778 is called with an argument built by `sorted(values.keys())` (line 778), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on. — REDACTED:778
`debug` at line 943 is called with an argument built by `sorted(allowed)` (line 946), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on. — REDACTED:943
What to do
In Python, put the construction behind the logger's own check (`if logger.isEnabledFor(logging.DEBUG):`), or pass the collection itself with a `%s` placeholder (`logger.debug("Items %s", items)`) so the logging module renders it only when the record is emitted. The placeholder alone is not the fix when the argument is still built first: it defers the formatting, not a `json.dumps`, a `join` or a comprehension in the argument, and an f-string defers nothing at all.
Do you agree with this assessment?
X24 · Document value interpolated into markup unescaped10.0 / 10Exemplary○ Nothing flagged
Other · Security — Whether text read out of the document being converted is escaped before it is written into generated markup — a value the document's author chose, interpolated into an attribute the surrounding literal delimits, can close that attribute and open another.
Method: Roslyn semantic model over the whole compilation: a string-typed `Value`/`InnerText`/`InnerXml`/`Text` member declared inside `DocumentFormat.OpenXml` or `System.Xml` is a taint SOURCE, propagated through assignments, returns, arguments, tuple elements and string composition to its transitive closure, then read at interpolated-string holes that sit in a markup position the surrounding literal itself delimits. Escaper/encoder calls and enclosing validator conditions cut the flow. Flow- and container-insensitive by construction. A second arm needs no provenance at all and reports a type that CONTRADICTS ITSELF — the same expression escaped at one delimited markup hole and interpolated raw at another hole in the same markup position of the same type, which the type's own escaping proves is a defect without knowing where the value came from. On a repository with no .NET source it reads JavaScript/TypeScript off the token stream with the same rule: a DOM read of raw document text (`getAttribute`, `textContent`, `innerText`, `nodeValue`) is the source, propagated through local bindings and string composition, and judged at template-literal and concatenation holes in the same two delimited markup positions; escapers and validating conditions cut it, and documentation-site, test, vendored and minified scripts are not read. Deterministic, provable per finding. Advisory.
Other · Code Health — Whether a value the caller is invited to supply is the value the type actually uses — a constructor parameter stored in a private field that nothing ever reads while the default it was given is spelled out a second time at the site that should have read it, a keyed lookup that falls back to a different setting than the one its key names while the same type falls back to the matching one for that same key, or a culture-sensitive parse given no format provider by a type that feeds its own settable culture to the same kind of parse elsewhere, or a number an entry point writes to standard output under the host's culture while the same entry point formats with the invariant culture elsewhere. Either way, every caller who supplies a value silently gets something else.
Method: Roslyn syntax: private instance fields of a non-partial type assigned in a constructor from one of its own parameters with a `??` fallback, checked for whether anything in the type body reads the field and whether that same fallback expression is spelled out again outside the constructor; and `??` fallbacks onto a member access from a lookup call carrying exactly one string literal, grouped by that key across the type and checked for a fallback member whose folded name disagrees with the key while a sibling site for the same key agrees with it. On a repository with no .NET source the first two arms read JavaScript/TypeScript off the engine’s own token stream (tests included, bundles and vendored paths not): a `#x`, `private` or `private` parameter-property instance field filled in the constructor from a parameter (or one member of one) through `??`/`||` or a parameter default, never read anywhere in the file by name, whose constructed default is spelled again in the class body; and `lookup("key") ?? s.member` grouped by key per class, or per module outside every class. The culture arm has no JavaScript counterpart: its parses take no locale. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X27 · Collection changed while being enumerated10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a `for` loop leaves the `RefCell` it is walking alone — safe Rust rejects a body that changes the collection its loop borrows at compile time, except through interior mutability: a `RefCell` borrowed in the loop's header stays borrowed until the loop ends, so a `borrow_mut()` of it inside the body panics with `already borrowed: BorrowMutError` and the remaining elements are never seen. Whether a `for` loop leaves the `dict`, `set` or `deque` it is walking alone — CPython's iterators over those check that the collection has not changed size since the loop began, so a body that removes from (or empties) the very collection the loop is walking makes the next step raise `RuntimeError: dictionary changed size during iteration` and the remaining items are never seen.
Method: Roslyn syntax + semantics: `foreach` statements whose body calls a structural mutator (`Add`/`Remove`/`Clear`/`Insert`/…) on the very expression the loop is enumerating. Two arms. ARM A — the source is a concrete fragile BCL collection, or a live `Keys`/`Values` view over one, and the mutator resolves to that same collection's own member; concurrent and immutable collections and arrays are outside the population by construction, since their enumerators survive a structural change. ARM B — the source is an argument-less accessor CALL on a receiver whose body is in source: the accessor must return a stored field VERBATIM and a sibling member must structurally change that same field, both read off the implementations rather than from the members' names. A mutation the loop provably exits immediately after (`break`/`return`/`throw`/`goto`), or one written inside a nested loop or a lambda, is counted and never reported. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X28 · Index access outside its own emptiness guard10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a condition that tests a value for emptiness indexes that same value only where the test holds — an `||` written one parenthesis too far to the left leaves an index access outside the guard beside it, so the empty case the guard exists to anticipate reaches the index and throws.
Method: Roslyn syntax only, no semantic model: the OUTERMOST `&&`/`||` of every boolean condition, read for a symbol the condition tests for emptiness (`string.IsNullOrEmpty`/`IsNullOrWhiteSpace`, a `Length`/`Count` comparison against a literal, `Any()`, a `Length`/`Count` pattern, or a comparison against `""`) and ALSO indexes. Each `symbol[...]` access is placed by a boolean-reachability walk from the access up to the outermost connective: an access is COVERED when some enclosing step has it in the right operand and the left operand, under the truth value that step forces, proves the symbol non-empty — a recursion over `&&`/`||` whose true- and false-directions are asymmetric. A finding needs BOTH an uncovered access and a covered one on the same symbol in the same condition, which is the agreeing twin that separates a misplaced parenthesis from an unrelated length test. Bare index accesses with no emptiness test in the condition are neither counted nor reported; a non-identifier receiver and a lambda nested inside the condition are outside the population. Deterministic, provable per finding. Advisory.
Other · Code Health — Whether exceptions are handled rather than silently swallowed or rethrown with lost stack traces.
Method: Roslyn syntax scan: every catch clause counted; empty catches and bare rethrows flagged. Population is all catch clauses, not estimated. Deterministic, hard fact.
`except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter. (×27) — claude_analysis_ttl.py:55, claude_analysis_ttl.py:65, claude_analysis_ttl.py:108, …
An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it. (×11) — sdk/typescript/src/client.ts:570, sdk/typescript/src/paths.ts:69, sdk/typescript/src/paths.ts:86, …
`.catch(() => {})` handles the rejection by doing nothing — the failure is discarded with no log and no rethrow, and the chain carries on as if the work succeeded. Log it through whatever this codebase already uses to report problems, hand it to a caller that can (`next(error)`, a returned rejection), or don't catch it. (×2) — plugins/opencode/src/plugin.ts:100, plugins/openclaw/src/engine.ts:390
What to do
Swallowed exception (caught, then discarded)
Do you agree with this assessment?
X30 · Support guard that admits what it rejects10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a guard written as a NEGATED `||` says what its author meant — `!(a || b || x != k)` is `!a && !b && x == k` by De Morgan, so a bail-out that mixes capabilities the code needs with a fault it refuses turns inside out: it fires only where the capabilities are ABSENT, and lets every value the fault term names walk straight into the body that cannot handle it.
Method: Roslyn syntax only, no semantic model: every logical-not whose operand is a parenthesised `||` chain of two or more disjuncts, flattened (a left-nested `a || b || c` read once would see `(a || b)` as one disjunct). A site enters the population on that shape alone. A finding additionally needs the disjuncts to DISAGREE in polarity: at least one bare boolean read — an identifier or member access, never an invocation, which is a predicate rather than a capability flag — and at least one `x != <constant>`, the only form that negates into an exact-value pin (`== null` negates into a looser requirement and is outside the fault set). Consistently-polarised disjunctions, all-fault or all-capability, are counted and never reported; a negated `&&` is outside the population entirely. No same-receiver gate: it was measured to cost a real defect and remove no false positive. Deterministic, provable per finding. Advisory.
Other · Code Health — Whether log calls use message templates (queryable) rather than interpolated strings.
Method: Roslyn syntax scan: every log call-site counted; interpolated-string first-argument violations flagged. Population is all log calls, not estimated. On a repository with no .NET source it reads JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not) with the same rule: a `trace`/`debug`/`info`/`warn`/`error`/`fatal`/`verbose`/`silly`/`http`/`log` call on a receiver named for a logger, in a package whose own or an enclosing `package.json` declares a logger that carries values as fields (pino, pino-http, nestjs-pino, Fastify, winston, bunyan, tslog, LogTape, roarr), whose first deciding argument is a template literal with substitutions; an object-literal fields argument is stepped over, a plain string message clears the call. Python is read the same way: a `debug`/`info`/`warning`/`error`/`exception`/`critical`/`log` call on a logger in a file that imports the standard library’s `logging` or structlog (loguru, which formats at the call, is not judged), whose message is a whole f-string with a non-constant field; a `%`-formatted, `.format()`-ed or concatenated message is not convicted, as in C#. PHP is read the same way: a PSR-3 level call (`emergency`…`debug`, `log`) on a logger (`$logger`, `$this->logger`, Laravel’s `Log::`, `logger()`, `\Drupal::logger()`) in a package whose `composer.json` requires a PSR-3 logger or a framework that hands one out (psr/log, Monolog, Laravel, Symfony, Drupal, CakePHP), or a file that imports one, whose message is a double-quoted string interpolating a variable; a single-quoted message clears the call, and `sprintf` or `.` concatenation is not convicted, as in C#. Dart is read the same way: a `trace`/`debug`/`info`/`warn`/`error`/`fatal` call on Sentry’s structured logger (`Sentry.logger`) whose message is a whole string literal interpolating a value (`$name`, `${…}`); the `Sentry.logger.fmt` template API clears the call. Dart that logs only through loggers with one message and no fields (package:logging, package:logger, talker, dart:developer) is not applicable rather than a reach gap. Ruby is read the same way: a `trace`/`debug`/`info`/`warn`/`error`/`fatal` call on the console gem’s `Console` (declared by a Gemfile, gemspec or Gemfile.lock, or required) or, where SemanticLogger, Ougai or dry-logger is declared or required, on a receiver named for a logger (`logger`, `@logger`, `Rails.logger`, `log`), whose first deciding argument is, as the whole argument, a double-quoted string interpolating a non-constant value (`#{…}`, `#@ivar`); a plain literal clears the call, keyword arguments are the fields, and a block, `%`-format or `+` concatenation is not convicted. Ruby that logs only through the standard Logger (Rails.logger) is not applicable rather than a reach gap. Deterministic.
`debug` at line 582 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.debug("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.debug("order moved", order_id=order_id, status=status)` with structlog. — REDACTED:582
`info` at line 3131 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — headroom/transforms/content_router.py:3131
`warning` at line 219 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/tokenizers/huggingface.py:219
`warning` at line 252 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/tokenizers/huggingface.py:252
`warning` at line 260 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/tokenizers/huggingface.py:260
`warning` at line 292 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/tokenizers/huggingface.py:292
`warning` at line 298 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/tokenizers/huggingface.py:298
`debug` at line 213 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.debug("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.debug("order moved", order_id=order_id, status=status)` with structlog. — headroom/tokenizers/mistral.py:213
`warning` at line 225 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/tokenizers/registry.py:225
`warning` at line 396 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/tokenizers/registry.py:396
`debug` at line 629 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.debug("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.debug("order moved", order_id=order_id, status=status)` with structlog. — headroom/telemetry/toin.py:629
`warning` at line 212 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/buffered_ccr_response.py:212
`error` at line 257 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/buffered_ccr_response.py:257
`debug` at line 298 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.debug("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.debug("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/buffered_ccr_response.py:298
`warning` at line 1848 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/helpers.py:1848
`info` at line 255 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:255
`error` at line 308 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:308
`info` at line 327 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:327
`info` at line 408 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:408
`info` at line 455 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:455
`error` at line 457 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:457
`info` at line 489 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:489
`warning` at line 494 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:494
`debug` at line 875 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.debug("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.debug("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:875
`warning` at line 897 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:897
`info` at line 1212 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1212
`error` at line 1246 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1246
`debug` at line 1312 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.debug("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.debug("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1312
`info` at line 1446 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1446
`warning` at line 1535 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1535
`warning` at line 1545 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1545
`error` at line 1647 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1647
`error` at line 1735 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1735
`error` at line 1770 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1770
`error` at line 1802 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1802
`error` at line 1855 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1855
`info` at line 1896 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1896
`error` at line 1900 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1900
`info` at line 1963 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1963
`error` at line 1967 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog. — headroom/proxy/memory_handler.py:1967
Other · Code Health — Whether strict null checking is enabled and not undermined by heavy `!` assertion — TypeScript's `strictNullChecks` (which `strict` turns on) is what makes `string` exclude `null` and `undefined`, and the postfix `!` is the operator that silences it.
Method: Roslyn compiler-options scan: NullableContextOptions per project; null-forgiving (!) suppression density per 1k syntax nodes. Deterministic, adoption plus suppression penalty.
~0.3 `!` null assertions per 1k TypeScript source lines — 3 assertion(s) across the 9123 source line(s) of the 58 TypeScript file(s) read, which is the only code the operator asserts anything in (a `!` in a `.js` file is not this operator and was not counted, and one in a file whose null checking is off silences nothing). Densest: sdk/typescript/src/utils/stream.ts (2), plugins/openclaw/src/convert.ts (1). Each one tells the compiler to trust the author about null, suppressing the very diagnostic `strictNullChecks` exists to produce. Many are correct: each is a claim the checker could not verify, and it is wrong only where the value can in fact be missing, so review the densest places first.
What to do
The findings name the configuration each number was taken from and, for the assertions, the files that hold them. Turn null checking on where it is off — `"strict": true` in the base tsconfig that the others extend switches `strictNullChecks` on with the rest of the family — and then resolve the assertions rather than adding to them. A `!` on a value the checker could show to be null is a promise the author cannot check from where they are standing, and each one is a `TypeError: Cannot read properties of null` waiting for the path that makes it true; where the value genuinely cannot be null, say something the checker can see instead (narrow it with a test, make the property required, drop the `?`).
Do you agree with this assessment?
WCAG coverage — what static analysis assessed
Statically assessed 15 of 55 WCAG 2.2 Level A/AA success criteria (27%; ≈30% of the 50 WCAG 2.1 AA criteria for EN 301 549). The other 40 require runtime or manual evaluation. Partial signal only (a clean result is necessary, not sufficient; static analysis fully verifies none). This is accessibility readiness, not a conformance claim — a WCAG conformance claim requires manual evaluation (WCAG-EM 1.0).
The score is the rank-weighted fold of these lenses (worst-heaviest), each including its meta-dimensions; a lens with a Critical contributor is capped at Fair (its band reads "gated by …") and is never the strongest area however high its average.
Unscored — 5 check(s) recorded observations but carry no score
These checks ran and found something, but they do not carry a score — either by design (an advisory check reports evidence rather than grading it) or because they could not be scored here. They are excluded from the score for that reason, not because there was nothing to see.
P12 CI test-gate honesty — 1 observation(s) recorded · Reported, not scored — this card publishes what the CI gate does with the test inventory rather than grading it. The findings above are its output.
X10 Duplicated predicate — 40 observation(s) recorded · Advisory — this card reports evidence and never carries a score.
X6 Hand-rolled structured-format parsing — 2 observation(s) recorded · Advisory — this card reports evidence and never carries a score.
X7 Silent fallback defaults — 40 observation(s) recorded · Advisory — this card reports evidence and never carries a score.
X9 Subsumed condition operand — 1 observation(s) recorded · Advisory — this card reports evidence and never carries a score.
Not evidenced — 3 control(s) we could not find positive evidence for
These checks grade a working control, and the repository shows no evidence of one. That is deliberately not scored as a zero: a repository cannot show an ops runbook, a database TTL or an infrastructure-side audit log, so absence of evidence here is not evidence the control is missing. It is also not a statement that the check is irrelevant to this codebase — the thing it grades applies; we just could not see it. Excluded from the score either way.
C3 Audit Trail — Not assessed: these audit controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks audit controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
C4 Data Retention — Not assessed: these retention controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks retention controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
C5 Data-Subject Rights — Not assessed: these data-subject rights controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks data-subject rights controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
Not included — 36 check(s) not relevant to this codebase
These checks had nothing to measure here (no tests, no git history, the codebase is small, or the architecture style doesn't apply), so they're omitted above rather than scored low.
AX1 Captive dependencies — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX2 Stateful singletons — No container singleton was found, so there is no shared instance for concurrent requests to race on. No function in this Python code is served by a threaded web framework (a Flask, Bottle or FastAPI route, a Django or Pyramid view), so no module is shared between request threads. Rust's compiler refuses unsynchronised shared mutation — a value shared across threads must be Sync — so the race this check looks for cannot be written. TypeScript/JavaScript runs each process's requests on one event loop, so no two requests write a shared object at the same instant (interleaving across an await is a different defect).
AX6 Interface segregation — AX6 reached only 4% of this repository's production lines — python (246,006 lines), rust (70,014 lines), c (164 lines) was left unread. Not scored: a score over a minority of the product would be published as the whole of it.
AX7 Slice cohesion — not applicable — not a vertical-slice architecture
AXB2 Runtime readiness — Advisory — this card reports evidence and never carries a score, so there is nothing missing here.
AXR1 Runtime accessibility — compose up failed (exit 15 — the compose project is invalid) — error while interpolating services.headroom-proxy.environment.[]: required variable HEADROOM_PROXY_TOKEN is missing a value: set HEADROOM_PROXY_TOKEN (see .env.example; e.g. openssl rand -hex 32); runtime evidence skipped This is a statement about this run, not a statement about your application: nothing here says the surface is inaccessible, only that it was never rendered.
C1 Data Protection — Not assessed: these personal data controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks personal data controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
C2 Access Controls — Not assessed: these authorization controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks authorization controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
D11 Test Reliability — Test reliability not scored — polyglot repository, one half's runner produced no measurement
D18 Solution Shape — D18 scores the shape of a .NET solution; this repository has no .NET solution or project files, so the dimension does not apply.
D22 Internal API Consistency — API consistency is measured on C# only; the exposed Python, Rust, TypeScript surface was not measured.
D23 Boundary Type-Coupling — No bounded-context organisation was detected either — neither a context-shaped layout, nor 2+ sibling source directories each declaring an aggregate root, nor 2+ sibling projects each declaring an entity of their own or taking another project's integration events. Aggregate roots were found in only one source directory (headroom), which is a layered codebase, not two contexts. Declaring this codebase's bounded contexts (≥2) would let cross-boundary type coupling be assessed. Declare them in `.codehealth/config.yaml` at the repository root (create it if absent), mapping each context name to the module-path or namespace prefixes that belong to it — e.g. `architecture:` → `contexts:` → `Billing: ["src/billing", "Acme.Billing"]`, `Catalog: ["src/catalog", "Acme.Catalog"]`.
D25 ADR Conformance — None of 5 binding record(s) states a rule in checkable form (a backticked element with a prohibition, or an `adr-rules` block), so conformance cannot be read from the code. Write the rule as an `adr-rules` block (`forbid:` a symbol, a package or a dependency) to make it checkable.
D32 Data Compliance (PII/GDPR) — 2 file(s) were not parsed by semgrep — the PII/GDPR ruleset never ran over them
D40 Network Egress Confinement — No Kubernetes/orchestration workloads found in the repository manifests; network egress policy is a cluster-native control that may live at the platform/firewall layer, so there is nothing to assess here.
D41 Kernel & Syscall Confinement — No Kubernetes/orchestration workloads found in the repository manifests; seccomp/AppArmor/SELinux confinement is a workload-level control, so there is nothing to assess here.
D42 Runtime Threat Enforcement — No Kubernetes/orchestration workloads found in the repository manifests; runtime threat-detection and admission-control policy are cluster-level controls, so there is nothing to assess here.
D8 Code Coverage — Coverage NOT MEASURED: the JavaScript/TypeScript half could not be measured — the node:test suite in e2e/wrap/tools/ ran and not one test passed (throw new ERR_INVALID_ARG_VALUE(), so the coverage would describe the failed run, not the code. Coverage is excluded from the score rather than counted as a near-zero. The named suite step is one the repository's maintainers can perform; once it passes, the real number is measured on the next scan.
ED2 Event/command shape — not scored — deciding whether a command has more than one competing handler requires resolving the call graph, and a call made through an inferred or generic receiver has no resolvable owner in the source. Reported as guidance rather than measured
ED5 Idempotency — no mutating command handlers or message consumers detected — idempotency check not applicable
ES1 Event Sourcing — not scored — this repository shows none of the 3 signals this lens looks for
GD1 Unfinished & placeholder code — no source files were read — this check reads C#, F#, JavaScript/TypeScript, Dart, Ruby and Scala, and none was read for this repository's product. That is a limit of the analyzer, not a finding about your code.
IC1 Incompleteness & stubs — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
P8 Schema migrations — no ORM, schema-migration tool or schema auto-create was found in this repository's dependency manifests or source, so there is no database schema for this check to judge
P9 Domain vs controller coverage — coverage not measured: this check compares the coverage of the analyzer's own test run across the domain and web layers, and that run measured none here — Test coverage (D8) says why
PF2 Allocation hygiene — Not scored: this check counted allocation-aware idioms (Span, pools, stackalloc) per line, which describes what kind of code a repository is rather than whether it has an allocation problem, so it was withdrawn. Nothing here is a finding about your code.
R11 Import Boundaries — No recognizable feature-sliced/layered src layout — boundary rules not applicable.
SC1 Supply-chain hygiene — Advisory — this card reports evidence and never carries a score, so there is nothing missing here.
X15 Unvalidated length from an untrusted reader — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X16 Unfloored truncation loop — X16 reached only 4% of this repository's production lines — python (246,006 lines), rust (70,014 lines), c (164 lines) was left unread. Not scored: a score over a minority of the product would be published as the whole of it.
X18 Disposal-pattern correctness — X18 reached only 4% of this repository's production lines — python (246,006 lines), rust (70,014 lines), c (164 lines) was left unread. Not scored: a score over a minority of the product would be published as the whole of it.
X20 Mistyped argument guard — This check asks whether an argument guard reports an EMPTY value as a NULL one, which needs a language that throws a null-specific argument exception — .NET's ArgumentNullException, the JVM's NullPointerException, Dart's ArgumentError.notNull. This repository contains none of those languages: the ones it is written in have a single exception for a bad argument, so there is no pair of exceptions to confuse and nothing here for it to assess. Not a gap in the analyzer and not a finding about your code.
X22 Contradicted release guard — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X26 Unsynchronised callback handoff — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X29 Per-element action decided by a fixed element — X29 reached only 25% of this repository's production lines — python (246,006 lines), c (164 lines) was left unread. Not scored: a score over a minority of the product would be published as the whole of it.
X32 Type resolved by simple name across every loaded assembly — This check is about how a .NET program searches the assemblies loaded into its process for a type, and this repository contains no .NET source, so there is nothing here for it to assess. Not a gap in the analyzer and not a finding about your code.
Appendix A — Findings (grouped)
The findings behind the scores, grouped by severity, then by dimension and kind. The high-severity issues are enumerated in full below; items per group are capped at 25 with any overflow stated explicitly per group, never silently truncated. The complete machine-readable list of every finding (all severities) is the companion findings.md in this report's bundle.
Orphaned knowledge crates/headroom-proxy/src/cache_stabilization/beta_sticky.rs:1— No living knowledge remains for this large file — its last meaningful change has decayed away, so if it breaks, no one currently understands it. It does carry its own tests, so the behaviour is pinned even though the understanding is gone: schedule a read-through, using those tests as the specification, before the next change lands here.
Domain fused to persistence infrastructure: HeadroomStrandsModel headroom/integrations/strands/model.py:60— `HeadroomStrandsModel` is a domain concept fused to persistence ON ITS OWN DECLARATION (Django/SQLAlchemy — `models.Model`/`db.Model`) — the domain entity IS the ORM row (active-record), and it carries domain behaviour on the persistence type. A schema/persistence change ripples straight into the domain. Keep the ORM/table mapping on a boundary data-model + a mapper, and the domain entity framework-free (map row↔domain through a repository).
Unlisted import '@anthropic-ai/sdk' scripts/verify_docs_anthropic_sdk.mjs:9— Imported but not declared in any reachable package.json — installs work only by hoisting accident.
Unlisted import 'zod' plugins/opencode/src/plugin.ts:4— Imported but not declared in any reachable package.json — installs work only by hoisting accident.
Repeated repair: headroom/config.py headroom/config.py:546— headroom/config.py changed 18 times in last 90 days and 15 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 15 (its worst body is config.unwrap_tool_call at line 546), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(compress): stop adding markers the caller did not ask for (#4678)”; “fix(dashboard): lifetime metrics and refresh (#2374)”; “fix(config): use the longest matching model_context_limits prefix (#4288)”; “fix(proxy): preserve Cline headroom__headroom_retrieve results from recompression (#4586)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/config.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: REDACTED REDACTED:508— REDACTED changed 13 times in last 90 days and 12 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 15 (its worst body is copilot_auth._read_windows_copilot_cli_oauth_token at line 508), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(proxy): keep tool deferral on Copilot Business/Enterprise/Individual hosts (#4608)”; “fix(copilot): preserve native inline OAuth identity (#4144)”; “fix(copilot): send VS Code next-edit requests to the completions host (#4188)”; “fix(copilot): honour GitHub's advertised Business/Enterprise host by default (#4155)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- REDACTED`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/proxy/models.py headroom/proxy/models.py:603— headroom/proxy/models.py changed 16 times in last 90 days and 11 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 8 (its worst body is ProxyConfig.__post_init__ at line 603), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(read-maturation): keep the client's tail cache breakpoint on held Reads (#3977)”; “fix(proxy): let an explicit compress-user-messages off beat the profile (#3936)”; “fix(proxy)!: read HEADROOM_LICENSE and make usage reporting opt-in (#3857)”; “fix(settings): report live proxy configuration (#3177)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/models.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/providers/proxy_routes.py headroom/providers/proxy_routes.py:243— headroom/providers/proxy_routes.py changed 14 times in last 90 days and 11 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 4 (its worst body is proxy_routes._register_openai_responses_routes at line 243), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(vertex): explain Vertex failures in-band, correct the model/region matrix (#2640)”; “fix(proxy): use HTTP/1.1 client for ChatGPT streaming and model metadata (#4006)”; “fix(proxy): let model discovery honor the custom base URL (#4330)”; “fix(proxy): answer /api/hello probes behind the token gate, log rejection context (#4150)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/providers/proxy_routes.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/providers/opencode/hook-shim/handler.js headroom/providers/opencode/hook-shim/handler.js:355— headroom/providers/opencode/hook-shim/handler.js changed 12 times in last 90 days and 10 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 10 (its worst body is handler.splitNodeArgs at line 355), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(opencode): keep child process options when the args slot is null or undefined (#4748)”; “fix(opencode): default options-form https.request calls to https (#4749)”; “fix(opencode): stop routing non-LLM hosts and paths to the proxy (#4747) (#4758)”; “fix(opencode): do not break every request when the proxy URL is empty or invalid (#4750)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/providers/opencode/hook-shim/handler.js`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: plugins/opencode/src/transport.ts plugins/opencode/src/transport.ts:606— plugins/opencode/src/transport.ts changed 12 times in last 90 days and 10 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 10 (its worst body is transport.splitNodeArgs at line 606), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(opencode): keep child process options when the args slot is null or undefined (#4748)”; “fix(opencode): default options-form https.request calls to https (#4749)”; “fix(opencode): stop routing non-LLM hosts and paths to the proxy (#4747) (#4758)”; “fix(opencode): do not break every request when the proxy URL is empty or invalid (#4750)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- plugins/opencode/src/transport.ts`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: REDACTED REDACTED:218— REDACTED changed 11 times in last 90 days and 10 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 14 (its worst body is init._ensure_claude_hooks at line 218), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(init): handle non-UTF-8 directory names when deriving the init profile (#4673)”; “fix(codex): accept multi-line inline tables in Codex config.toml (#4436)”; “fix(cli): name the broken Codex config, write init configs atomically, keep the identity check (#4129)”; “fix(codex): preserve auth.json API keys through Headroom (#3355)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- REDACTED`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: plugins/openclaw/src/engine.ts plugins/openclaw/src/engine.ts:122— plugins/openclaw/src/engine.ts changed 7 times in last 90 days and 7 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 14 (its worst body is HeadroomContextEngine.assemble at line 122), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(openclaw): let the circuit breaker open on proxy failures (#4755)”; “fix(openclaw): record turn advancements as one marker file per key (#4212)”; “fix(openclaw/release): ship responsive npm integrations (#1458)”; “fix(plugins/openclaw): keep compression system-prompt notice cache-stable (#3811)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- plugins/openclaw/src/engine.ts`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/proxy/output_savings.py headroom/proxy/output_savings.py:670— headroom/proxy/output_savings.py changed 7 times in last 90 days and 7 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 13 (its worst body is SavingsLedger.from_dict at line 670), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(output-savings): rewrite a pre-rule ledger once instead of warning on every /stats poll (#4196)”; “fix(savings): don't let a thin holdout arm decide the headline number (#3127)”; “fix(savings): stop scoring unobserved strata against the global mean (#3128)”; “fix(stats): gate the output-shaping claim on the shaper being active (#3386)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/output_savings.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/learn/writer.py headroom/learn/writer.py:437— headroom/learn/writer.py changed 7 times in last 90 days and 7 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 13 (its worst body is writer._ensure_git_ignored at line 437), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(learn): anchor the managed block on its last start marker, append when no end marker (#4342)”; “fix(learn): decode sanitized pattern-id markers and keep visible-text dedup keys (#3956)”; “fix(learn): recognize escaped persisted pattern IDs (#3951)”; “fix(learn): preserve stable traffic pattern items (#2293)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/learn/writer.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: plugins/opencode/src/plugin.ts plugins/opencode/src/plugin.ts:158— plugins/opencode/src/plugin.ts changed 8 times in last 90 days and 6 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 9 (its worst body is plugin.modelWireSuffix at line 158), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(opencode): stop routing non-LLM hosts and paths to the proxy (#4747) (#4758)”; “fix(opencode): do not break every request when the proxy URL is empty or invalid (#4750)”; “fix(opencode): route Copilot Claude models through the proxy (#4594)”; “fix(proxy): astgrep disk verify truncation (#3192)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- plugins/opencode/src/plugin.ts`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/cache/semantic.py headroom/cache/semantic.py:140— headroom/cache/semantic.py changed 6 times in last 90 days and 6 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 14 (its worst body is SemanticCache.get at line 140), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(cache): refresh semantic cache recency on updates (#4767)”; “fix(cache): restore query-only semantic cache lookups (#4709)”; “fix(cache): reject nonpositive semantic cache capacities (#4301)”; “fix(cache): build semantic entry before evicting so a failed embedding keeps live entries (#4581)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/cache/semantic.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/memory/storage_router.py headroom/memory/storage_router.py:210— headroom/memory/storage_router.py changed 6 times in last 90 days and 6 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 11 (its worst body is ProjectResolver._extract_cwd_from_system_prompt at line 210), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(memory): resolve pi cwd before injecting project tools (#4618)”; “fix(memory): fail close unresolved project operations (#2637)”; “fix(memory): treat a cwd with no UTF-8 form as unresolved instead of raising (#4167)”; “fix(memory): ignore incidental cwd prose (#4166)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/memory/storage_router.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/proxy/persistent_metrics.py headroom/proxy/persistent_metrics.py:203— headroom/proxy/persistent_metrics.py changed 6 times in last 90 days and 6 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 15 (its worst body is PersistentMetricsState._normalize at line 203), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(dashboard): lifetime metrics and refresh (#2374)”; “fix(proxy): keep negative compression savings across restart (#4406)”; “fix(proxy): bound per-model state keyed by the client model string (#4407)”; “fix(metrics): split rate-limited by source and label failures by provider (#3707)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/persistent_metrics.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/pricing/litellm_pricing.py headroom/pricing/litellm_pricing.py:95— headroom/pricing/litellm_pricing.py changed 6 times in last 90 days and 6 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 8 (its worst body is litellm_pricing._reduce_to_priced_key at line 95), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(proxy): bound the model-keyed tokenizer, beacon and litellm caches (#4497)”; “fix(offline): keep litellm's pricing table local under HEADROOM_OFFLINE (#4242)”; “fix(pricing): suppress litellm's Provider List banner that corrupts perf JSON (#4197)”; “fix(pricing): DeepSeek V4.1-Flash peak/off-peak rate card (#3575)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/pricing/litellm_pricing.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/relevance/embedding.py headroom/relevance/embedding.py:315— headroom/relevance/embedding.py changed 6 times in last 90 days and 6 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 6 (its worst body is EmbeddingScorer._get_model at line 315), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(relevance): load the Rust default embedder from Python's pinned snapshot (#4190)”; “fix(relevance): hand the embedding arena back after each run on macOS (#4567)”; “fix(relevance): cap embedding batch size so ORT's arena stays small (#4507)”; “fix(relevance): load the default embedder from one pinned snapshot (#4152)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/relevance/embedding.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: REDACTED REDACTED:142— REDACTED changed 8 times in last 90 days and 5 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 13 (its worst body is utils.extract_user_query at line 142), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(proxy): don't take Claude Code's "Tool loaded." note as the user query (#4714)”; “fix(proxy): bound the model-keyed tokenizer, beacon and litellm caches (#4497)”; “fix: use all user text blocks for relevance scoring (#4628)”; “fix(utils): normalize timezone-aware datetimes in format_timestamp (#3116)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- REDACTED`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/cache/backends/sqlite.py headroom/cache/backends/sqlite.py:196— headroom/cache/backends/sqlite.py changed 7 times in last 90 days and 5 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 5 (its worst body is SQLiteBackend._handle_db_error at line 196), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(cache): fail closed on SQLite corruption instead of deleting the store online (#4361)”; “fix(memory): log storage and SQLite failures that currently make retrieval miss silently (#4111)”; “fix(security): create memory stores and other state files owner-only (#3848)”; “fix(cache/ccr): tolerate a malformed CCR entry row instead of crashing the store (#3156)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/cache/backends/sqlite.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/mcp_registry/codex.py headroom/mcp_registry/codex.py:211— headroom/mcp_registry/codex.py changed 6 times in last 90 days and 5 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 12 (its worst body is _TomlMarkerRegistrar.unregister_server at line 211), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(codex): accept multi-line inline tables in Codex config.toml (#4436)”; “fix(mcp_registry): atomic config writes, no traceback on non-UTF-8 configs, log failed removals (#4130)”; “fix(mcp): escape control characters when rendering TOML server blocks (#3964)”; “fix(mcp): keep other apps' tables when replacing the Codex/Grok MCP span (#3877)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/mcp_registry/codex.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/providers/proxy_targets.py headroom/providers/proxy_targets.py:97— headroom/providers/proxy_targets.py changed 6 times in last 90 days and 5 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 10 (its worst body is proxy_targets.select_passthrough_base_url at line 97), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(anthropic): route /api/hello connectivity probes to Anthropic (#3336) (#4059)”; “fix(grok): route CLI traffic to api.x.ai on shared proxies (#2693)”; “fix(security): validate caller-supplied upstreams on every resolution path (#3195)”; “fix(copilot): send VS Code inline completions to the host that serves them (#3112)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/providers/proxy_targets.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/tokenizers/huggingface.py headroom/tokenizers/huggingface.py:193— headroom/tokenizers/huggingface.py changed 5 times in last 90 days and 5 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 9 (its worst body is huggingface._load_tokenizer at line 193), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(tokenizers): unwrap BatchEncoding in HuggingFaceTokenizer.count_messages (#2447)”; “fix(offline): make HEADROOM_OFFLINE a real air-gap via one chokepoint (#3729)”; “fix: prevent HF tokenizer downloads in offline mode (#3783)”; “fix(pricing): DeepSeek V4.1-Flash peak/off-peak rate card (#3575)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/tokenizers/huggingface.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/providers/registry.py headroom/providers/registry.py:254— headroom/providers/registry.py changed 5 times in last 90 days and 5 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 13 (its worst body is registry.create_proxy_backend at line 254), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(vertex): explain Vertex failures in-band, correct the model/region matrix (#2640)”; “fix(client): preserve Anthropic create stream flags (#4500)”; “fix(anthropic): route /api/hello connectivity probes to Anthropic (#3336) (#4059)”; “fix(providers): route Claude requests to Copilot when the OpenAI target is a Copilot host (#3258)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/providers/registry.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: REDACTED REDACTED:304— REDACTED changed 5 times in last 90 days and 5 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 11 (its worst body is binaries._download at line 304), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(binaries): fail closed on HEADROOM_BINARIES_ALLOW_UNVERIFIED=0/false (#3218)”; “fix(cli): pass configured SSL context to stdlib urlopen calls (#4011)”; “fix(offline): make HEADROOM_OFFLINE a real air-gap via one chokepoint (#3729)”; “fix(binaries): fail closed when a download carries no sha256 pin (#3724)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- REDACTED`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/proxy/handlers/bedrock.py headroom/proxy/handlers/bedrock.py:58— headroom/proxy/handlers/bedrock.py changed 5 times in last 90 days and 5 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 15 (its worst body is BedrockHandlerMixin.handle_bedrock_invoke at line 58), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(proxy): bypass compression for large admitted histories (#4142)”; “fix(proxy): import Response at runtime in the Bedrock handler (#4397)”; “fix(proxy/bedrock): record the real upstream status on InvokeModel outcomes (#4025)”; “fix(proxy): keep exception text and the proxy token out of client output (#3851)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/handlers/bedrock.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Repeated repair: headroom/proxy/runtime_env.py headroom/proxy/runtime_env.py:160— headroom/proxy/runtime_env.py changed 5 times in last 90 days and 5 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 5 (its worst body is runtime_env.explicit_env at line 160), AT OR UNDER the 15 threshold, so this is deliberately not filed as a churn × complexity hotspot — the difficulty here is in the behaviour the file has to get right, not in its control flow, and refactoring it for complexity would be the wrong move. The repairs counted were: “fix(proxy): keep deferred tool loads out of the prefix-tracker lineage key (#4204)”; “fix(proxy): drop web_search_call history from a Responses request with no web_search tool (#4202)”; “fix(ccr): stream the buffered CCR upstream request so idle-killing networks cannot cut it (#4206)”; “fix(proxy): astgrep disk verify truncation (#3192)”. Each one is a case this code did not handle. Before the next change lands here, check that every one of them is pinned by a test that fails without its fix; where the same area keeps coming back, the durable fix is usually at the interface that keeps being misused rather than at the line that was last corrected. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/runtime_env.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
FileTooLong: REDACTED REDACTED— FileTooLong — 8519 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 8019 over it, 17.04× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: cli/wrap.py headroom/cli/wrap.py— FileTooLong — 5969 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 5469 over it, 11.94× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: REDACTED REDACTED— FileTooLong — 4600 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 4100 over it, 9.20× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: transforms/content_router.py headroom/transforms/content_router.py— FileTooLong — 4550 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 4050 over it, 9.10× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: REDACTED REDACTED— FileTooLong — 4240 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 3740 over it, 8.48× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: proxy/helpers.py headroom/proxy/helpers.py— FileTooLong — 2527 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 2027 over it, 5.05× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: REDACTED REDACTED— FileTooLong — 1759 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1259 over it, 3.52× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: proxy/savings_tracker.py headroom/proxy/savings_tracker.py— FileTooLong — 1742 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1242 over it, 3.48× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: transforms/code_compressor.py headroom/transforms/code_compressor.py— FileTooLong — 1702 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1202 over it, 3.40× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: transforms/kompress_compressor.py headroom/transforms/kompress_compressor.py— FileTooLong — 1642 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1142 over it, 3.28× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: memory/traffic_learner.py headroom/memory/traffic_learner.py— FileTooLong — 1376 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 876 over it, 2.75× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: REDACTED REDACTED— FileTooLong — 1343 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 843 over it, 2.69× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: cli/proxy.py headroom/cli/proxy.py— FileTooLong — 1332 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 832 over it, 2.66× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: proxy/memory_handler.py headroom/proxy/memory_handler.py— FileTooLong — 1269 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 769 over it, 2.54× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: proxy/prometheus_metrics.py headroom/proxy/prometheus_metrics.py— FileTooLong — 1254 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 754 over it, 2.51× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: testing/harness.py headroom/testing/harness.py— FileTooLong — 1234 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 734 over it, 2.47× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: transforms/code_compressor.rs crates/headroom-core/src/transforms/code_compressor.rs— FileTooLong — 1186 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted). The bar is 500 significant lines; this is 686 over it, 2.37× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: transforms/live_zone.rs crates/headroom-core/src/transforms/live_zone.rs— FileTooLong — 1175 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted), declaring 33 free functions. The bar is 500 significant lines; this is 675 over it, 2.35× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: src/lib.rs crates/headroom-py/src/lib.rs— FileTooLong — 1152 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted). The bar is 500 significant lines; this is 652 over it, 2.30× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: backends/litellm.py headroom/backends/litellm.py— FileTooLong — 1140 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 640 over it, 2.28× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: handlers/gemini.py headroom/proxy/handlers/gemini.py— FileTooLong — 1139 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 639 over it, 2.28× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: proxy/gateway_turn.py headroom/proxy/gateway_turn.py— FileTooLong — 1123 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 623 over it, 2.25× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: REDACTED REDACTED— FileTooLong — 1100 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 600 over it, 2.20× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: proxy/cost.py headroom/proxy/cost.py— FileTooLong — 1099 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 599 over it, 2.20× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: REDACTED REDACTED— FileTooLong — 1055 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 555 over it, 2.11× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
Hotspot: REDACTED REDACTED:1309— REDACTED changed 93 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 373 in AnthropicHandlerMixin.handle_anthropic_messages at line 1309. 80 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- REDACTED`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: REDACTED REDACTED:3542— REDACTED changed 108 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 205 in OpenAIHandlerMixin.handle_openai_chat at line 3542. 85 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- REDACTED`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/transforms/content_router.py headroom/transforms/content_router.py:6337— headroom/transforms/content_router.py changed 62 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 192 in ContentRouter.apply at line 6337. 53 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/transforms/content_router.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/cli/wrap.py headroom/cli/wrap.py:5091— headroom/cli/wrap.py changed 60 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 121 in wrap._ensure_proxy_unlocked at line 5091. 42 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/cli/wrap.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: REDACTED REDACTED:2204— REDACTED changed 94 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 56 in HeadroomProxy.startup at line 2204. 70 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- REDACTED`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/cli/proxy.py headroom/cli/proxy.py:1218— headroom/cli/proxy.py changed 28 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 120 in proxy.proxy at line 1218. 22 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/cli/proxy.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/dashboard/templates/dashboard.html headroom/dashboard/templates/dashboard.html:2056— headroom/dashboard/templates/dashboard.html changed 24 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 107 in dashboard.html.dashboard at line 2056. 13 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/dashboard/templates/dashboard.html`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/proxy/helpers.py headroom/proxy/helpers.py:1110— headroom/proxy/helpers.py changed 49 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 44 in helpers.relocate_system_messages_to_top_level at line 1110. 41 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/helpers.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/proxy/handlers/gemini.py headroom/proxy/handlers/gemini.py:399— headroom/proxy/handlers/gemini.py changed 18 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 95 in GeminiHandlerMixin.handle_gemini_generate_content at line 399. 15 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/handlers/gemini.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: REDACTED REDACTED:522— REDACTED changed 37 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 42 in StreamingMixin._continue_memory_tool_stream at line 522. 34 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- REDACTED`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/transforms/kompress_compressor.py headroom/transforms/kompress_compressor.py:2285— headroom/transforms/kompress_compressor.py changed 20 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 66 in KompressCompressor.compress_batch at line 2285. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/transforms/kompress_compressor.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/backends/litellm.py headroom/backends/litellm.py:1397— headroom/backends/litellm.py changed 16 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 66 in LiteLLMBackend.stream_message at line 1397. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/backends/litellm.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/proxy/cost.py headroom/proxy/cost.py:243— headroom/proxy/cost.py changed 20 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 46 in cost.build_prefix_cache_stats at line 243. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/cost.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/perf/analyzer.py headroom/perf/analyzer.py:523— headroom/perf/analyzer.py changed 13 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 63 in analyzer.format_report at line 523. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/perf/analyzer.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/proxy/prometheus_metrics.py headroom/proxy/prometheus_metrics.py:1427— headroom/proxy/prometheus_metrics.py changed 15 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 52 in PrometheusMetrics.export at line 1427. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/prometheus_metrics.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/proxy/gateway_turn.py headroom/proxy/gateway_turn.py:1607— headroom/proxy/gateway_turn.py changed 12 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 55 in gateway_turn.handle_compress_response at line 1607. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/gateway_turn.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: REDACTED REDACTED:478— REDACTED changed 17 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 32 in outcome.emit_request_outcome at line 478. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- REDACTED`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: REDACTED REDACTED:1876— REDACTED changed 16 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 32 in SessionTrackerStore.resolve_tracker at line 1876. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- REDACTED`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/cli/learn.py headroom/cli/learn.py:143— headroom/cli/learn.py changed 9 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 52 in learn.learn at line 143. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/cli/learn.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: sdk/typescript/src/utils/format.ts sdk/typescript/src/utils/format.ts:534— sdk/typescript/src/utils/format.ts changed 9 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 51 in format.vercelToOpenAI at line 534. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- sdk/typescript/src/utils/format.ts`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/proxy/savings_tracker.py headroom/proxy/savings_tracker.py:1896— headroom/proxy/savings_tracker.py changed 18 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 21 in SavingsTracker._sanitize_state at line 1896. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/savings_tracker.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/proxy/memory_handler.py headroom/proxy/memory_handler.py:724— headroom/proxy/memory_handler.py changed 12 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 29 in MemoryHandler.search_and_format_context at line 724. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/proxy/memory_handler.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/cli/install.py headroom/cli/install.py:659— headroom/cli/install.py changed 11 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 31 in install._apply_manifest at line 659. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/cli/install.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/transforms/code_compressor.py headroom/transforms/code_compressor.py:2186— headroom/transforms/code_compressor.py changed 10 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 34 in CodeAwareCompressor._compress_class_ast at line 2186. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/transforms/code_compressor.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: headroom/learn/analyzer.py headroom/learn/analyzer.py:869— headroom/learn/analyzer.py changed 14 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 23 in analyzer._call_claude_cli_streaming at line 869. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 15:41:29 -06:00' --until='2026-11-13 15:41:29 -06:00' --full-history --no-merges -- headroom/learn/analyzer.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
headroom_core::transforms::diff_compressor::parse_diff (cognitive 66) crates/headroom-core/src/transforms/diff_compressor.rs:696— headroom_core::transforms::diff_compressor::parse_diff has cognitive complexity 66 (threshold 15). Drivers by points: if/else 29 (60 pts), boolean chains 5, loops 1 (nesting depth added 31). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::safety::tool_pair_indices (cognitive 55) crates/headroom-core/src/transforms/safety.rs:40— headroom_core::transforms::safety::tool_pair_indices has cognitive complexity 55 (threshold 15). Drivers by points: if/else 11 (47 pts), loops 4 (8 pts) (nesting depth added 40). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
headroom_core::transforms::search_compressor::scan_marker (cognitive 48) crates/headroom-core/src/transforms/search_compressor.rs:857— headroom_core::transforms::search_compressor::scan_marker has cognitive complexity 48 (threshold 15). Drivers by points: if/else 10 (29 pts), boolean chains 10, match/switch 2 (5 pts), loops 2 (4 pts) (nesting depth added 24). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::code_compressor::collect_definitions (cognitive 39) crates/headroom-core/src/transforms/code_compressor.rs:1255— headroom_core::transforms::code_compressor::collect_definitions has cognitive complexity 39 (threshold 15). Drivers by points: if/else 10 (26 pts), loops 4 (13 pts) (nesting depth added 25). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
headroom_core::transforms::smart_crusher::crushers::crush_number_array (cognitive 39) crates/headroom-core/src/transforms/smart_crusher/crushers.rs:227— headroom_core::transforms::smart_crusher::crushers::crush_number_array has cognitive complexity 39 (threshold 15). Drivers by points: if/else 16 (30 pts), loops 3 (6 pts), boolean chains 3 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::diff_compressor::reduce_context (cognitive 37) crates/headroom-core/src/transforms/diff_compressor.rs:1055— headroom_core::transforms::diff_compressor::reduce_context has cognitive complexity 37 (threshold 15). Drivers by points: loops 9 (18 pts), if/else 10 (12 pts), boolean chains 5, match/switch 1 (2 pts) (nesting depth added 12). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
headroom_core::transforms::smart_crusher::outliers::detect_rare_status_values (cognitive 35) crates/headroom-core/src/transforms/smart_crusher/outliers.rs:122— headroom_core::transforms::smart_crusher::outliers::detect_rare_status_values has cognitive complexity 35 (threshold 15). Drivers by points: if/else 11 (26 pts), loops 4 (7 pts), match/switch 1 (2 pts) (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::code_compressor::detect_language (cognitive 34) crates/headroom-core/src/transforms/code_compressor.rs:699— headroom_core::transforms::code_compressor::detect_language has cognitive complexity 34 (threshold 15). Drivers by points: if/else 15 (26 pts), loops 4 (5 pts), boolean chains 3 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::smart_crusher::crushers::crush_string_array (cognitive 32) crates/headroom-core/src/transforms/smart_crusher/crushers.rs:112— headroom_core::transforms::smart_crusher::crushers::crush_string_array has cognitive complexity 32 (threshold 15). Drivers by points: if/else 13 (25 pts), loops 4 (7 pts) (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::diff_compressor::score_hunks (cognitive 31) crates/headroom-core/src/transforms/diff_compressor.rs:901— headroom_core::transforms::diff_compressor::score_hunks has cognitive complexity 31 (threshold 15). Drivers by points: if/else 5 (18 pts), loops 5 (12 pts), boolean chains 1 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::live_zone::compress_openai_responses_live_zone (cognitive 30) crates/headroom-core/src/transforms/live_zone.rs:2693— headroom_core::transforms::live_zone::compress_openai_responses_live_zone has cognitive complexity 30 (threshold 15). Drivers by points: if/else 10 (17 pts), match/switch 4 (6 pts), loops 4, boolean chains 3 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::anchor_selector::write_python_json_inner (cognitive 27) crates/headroom-core/src/transforms/anchor_selector.rs:432— headroom_core::transforms::anchor_selector::write_python_json_inner has cognitive complexity 27 (threshold 15). Drivers by points: if/else 9 (18 pts), loops 3 (8 pts), match/switch 1 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::smart_crusher::orchestration::numeric_anomaly_indices (cognitive 27) crates/headroom-core/src/transforms/smart_crusher/orchestration.rs:247— headroom_core::transforms::smart_crusher::orchestration::numeric_anomaly_indices has cognitive complexity 27 (threshold 15). Drivers by points: if/else 10 (23 pts), loops 2 (3 pts), boolean chains 1 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::tag_protector::parse_tag_at (cognitive 27) crates/headroom-core/src/transforms/tag_protector.rs:315— headroom_core::transforms::tag_protector::parse_tag_at has cognitive complexity 27 (threshold 15). Drivers by points: if/else 9 (14 pts), loops 4 (7 pts), boolean chains 4, match/switch 1 (2 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::log_compressor::is_summary_line (cognitive 25) crates/headroom-core/src/transforms/log_compressor.rs:850— headroom_core::transforms::log_compressor::is_summary_line has cognitive complexity 25 (threshold 15). Drivers by points: if/else 7 (15 pts), loops 5 (8 pts), boolean chains 2 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::log_compressor::summarize_omitted (cognitive 25) crates/headroom-core/src/transforms/log_compressor.rs:1044— headroom_core::transforms::log_compressor::summarize_omitted has cognitive complexity 25 (threshold 15). Drivers by points: if/else 13 (23 pts), loops 2 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::smart_crusher::orchestration::prioritize_indices (cognitive 25) crates/headroom-core/src/transforms/smart_crusher/orchestration.rs:155— headroom_core::transforms::smart_crusher::orchestration::prioritize_indices has cognitive complexity 25 (threshold 15). Drivers by points: if/else 10 (16 pts), loops 3 (6 pts), boolean chains 3 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::tag_protector::identify_spans (cognitive 25) crates/headroom-core/src/transforms/tag_protector.rs:490— headroom_core::transforms::tag_protector::identify_spans has cognitive complexity 25 (threshold 15). Drivers by points: if/else 7 (19 pts), match/switch 2 (5 pts), loops 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::diff_compressor::format_output (cognitive 22) crates/headroom-core/src/transforms/diff_compressor.rs:1355— headroom_core::transforms::diff_compressor::format_output has cognitive complexity 22 (threshold 15). Drivers by points: if/else 7 (12 pts), loops 5 (9 pts), boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::log_compressor::collapse_trace_frames (cognitive 22) crates/headroom-core/src/transforms/log_compressor.rs:782— headroom_core::transforms::log_compressor::collapse_trace_frames has cognitive complexity 22 (threshold 15). Drivers by points: if/else 8 (17 pts), boolean chains 4, loops 1 (nesting depth added 9). Of this number, 21 points are the body's own statements and 1 belongs to one function item inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::smart_crusher::field_detect::detect_id_field_statistically (cognitive 22) crates/headroom-core/src/transforms/smart_crusher/field_detect.rs:36— headroom_core::transforms::smart_crusher::field_detect::detect_id_field_statistically has cognitive complexity 22 (threshold 15). Drivers by points: if/else 10 (19 pts), boolean chains 3 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_core::transforms::smart_crusher::field_detect::detect_score_field_statistically (cognitive 22) crates/headroom-core/src/transforms/smart_crusher/field_detect.rs:116— headroom_core::transforms::smart_crusher::field_detect::detect_score_field_statistically has cognitive complexity 22 (threshold 15). Drivers by points: if/else 13 (14 pts), boolean chains 7, match/switch 1 (nesting depth added 1). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
headroom_core::transforms::live_zone::plan_responses_item (cognitive 21) crates/headroom-core/src/transforms/live_zone.rs:2905— headroom_core::transforms::live_zone::plan_responses_item has cognitive complexity 21 (threshold 15). Drivers by points: if/else 7 (17 pts), loops 1 (2 pts), boolean chains 1, match/switch 1 (nesting depth added 11). The drivers above price the dispatch low by construction — a dispatch is charged once however many cases it lists, while each branch inside an arm is charged in full — so most of this count is what the case bodies hold, and the arms are where it can be reduced. To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Keep every case explicit, and make the behaviour for cases you do not list a deliberate choice rather than an accident.
headroom_core::transforms::smart_crusher::compaction::compactor::flatten_uniform_nested (cognitive 21) crates/headroom-core/src/transforms/smart_crusher/compaction/compactor.rs:284— headroom_core::transforms::smart_crusher::compaction::compactor::flatten_uniform_nested has cognitive complexity 21 (threshold 15). Drivers by points: match/switch 4 (12 pts), loops 4 (8 pts), boolean chains 1 (nesting depth added 12). To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Keep every case explicit, and make the behaviour for cases you do not list a deliberate choice rather than an accident.
headroom_core::transforms::code_compressor::make_omitted_comment (cognitive 20) crates/headroom-core/src/transforms/code_compressor.rs:512— headroom_core::transforms::code_compressor::make_omitted_comment has cognitive complexity 20 (threshold 15). Drivers by points: if/else 5 (16 pts), loops 2 (4 pts) (nesting depth added 13). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
Swallowed exception (caught, then discarded) claude_analysis_ttl.py:55— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) claude_analysis_ttl.py:65— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) claude_analysis_ttl.py:108— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/_subprocess.py:35— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/_version.py:96— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/copilot_linux_secret.py:46— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/copilot_macos_keychain.py:69— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/onnx_runtime.py:311— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) REDACTED:80— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) REDACTED:90— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) REDACTED:109— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) REDACTED:128— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/code_compressor.py:90— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/code_compressor.py:2407— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/cold_prefix.py:65— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/content_detector.py:907— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/content_detector.py:927— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/content_router.py:3209— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/content_router.py:3215— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/content_router.py:3239— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/content_router.py:3246— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/content_router.py:3261— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/content_router.py:3955— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/content_router.py:7669— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) headroom/transforms/content_router.py:7713— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Duplicated block (14 lines × 2) REDACTED:241— REDACTED:241-254 | REDACTED:645-658 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:241` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (14 lines × 2) headroom/cli/wrap.py:4220— headroom/cli/wrap.py:4220-4234 | headroom/cli/wrap.py:5915-5928 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/cli/wrap.py:4220` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) headroom/evals/core.py:364— headroom/evals/core.py:364-377 | headroom/evals/runners/before_after.py:380-393 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/evals/core.py:364` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) headroom/learn/writer.py:693— headroom/learn/writer.py:693-706 | headroom/learn/writer.py:723-736 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (14 lines × 2) headroom/memory/adapters/graph.py:368— headroom/memory/adapters/graph.py:368-381 | headroom/memory/adapters/sqlite_graph.py:545-558 — before extracting anything, compare `headroom/memory/adapters/graph.py` and `headroom/memory/adapters/sqlite_graph.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 41 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (14 lines × 2) headroom/models/ml_models.py:257— headroom/models/ml_models.py:257-270 | headroom/models/ml_models.py:353-366 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/models/ml_models.py:257` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (14 lines × 2) REDACTED:3081— REDACTED:3081-3094 | REDACTED:4466-4479 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:3081` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) REDACTED:6715— REDACTED:6715-6728 | REDACTED:8802-8815 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:6715` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) REDACTED:1680— REDACTED:1680-1693 | REDACTED:2138-2151 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:1680` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) headroom/transforms/content_router.py:6147— headroom/transforms/content_router.py:6147-6160 | headroom/transforms/content_router.py:6168-6181 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (14 lines × 2) headroom/transforms/recursive_json.py:51— headroom/transforms/recursive_json.py:51-64 | headroom/transforms/recursive_json.py:96-109 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (14 lines × 2) REDACTED:400— REDACTED:400-413 | REDACTED:430-445 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:400` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (14 lines × 2) crates/headroom-core/src/transforms/live_zone.rs:1433— crates/headroom-core/src/transforms/live_zone.rs:1433-1446 | crates/headroom-core/src/transforms/live_zone.rs:1456-1469 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/live_zone.rs:1433` it runs out through the closing brace of the declaration holding it — the window is that declaration's tail, not a fragment that begins part-way through something, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:564— crates/headroom-core/src/transforms/smart_crusher/crusher.rs:564-577 | crates/headroom-core/src/transforms/smart_crusher/crusher.rs:664-677 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (14 lines × 2) crates/headroom-core/src/transforms/smart_crusher/crushers.rs:160— crates/headroom-core/src/transforms/smart_crusher/crushers.rs:160-173 | crates/headroom-core/src/transforms/smart_crusher/crushers.rs:316-329 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/smart_crusher/crushers.rs:160` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:251— crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:251-264 | crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:275-288 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:251` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) crates/headroom-proxy/src/compression/live_zone_openai.rs:265— crates/headroom-proxy/src/compression/live_zone_openai.rs:265-278 | crates/headroom-proxy/src/compression/live_zone_responses.rs:273-286 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_openai.rs` and `crates/headroom-proxy/src/compression/live_zone_responses.rs` as WHOLE FILES: this scan already matched 14 separate duplicated blocks between them, totalling at least 278 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_openai.rs:265` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) crates/headroom-proxy/src/proxy.rs:1687— crates/headroom-proxy/src/proxy.rs:1687-1700 | crates/headroom-proxy/src/proxy.rs:1808-1822 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/proxy.rs:1687` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) headroom/cli/memory.py:602— headroom/cli/memory.py:602-611 | headroom/cli/memory.py:755-764 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) headroom/cli/wrap.py:5228— headroom/cli/wrap.py:5228-5237 | headroom/cli/wrap.py:5275-5284 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/cli/wrap.py:5228` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/cli/wrap.py:5238` calls `echo`, `_proxy_status_line` and `headroom/cli/wrap.py:5285` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (10 lines × 2) headroom/integrations/langchain/chat_model.py:339— headroom/integrations/langchain/chat_model.py:339-348 | headroom/integrations/langchain/chat_model.py:909-918 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) headroom/memory/adapters/cache.py:120— headroom/memory/adapters/cache.py:120-132 | headroom/memory/adapters/cache.py:151-160 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) headroom/providers/cohere.py:183— headroom/providers/cohere.py:183-192 | headroom/providers/google.py:191-200 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (10 lines × 2) headroom/proxy/cost.py:1657— headroom/proxy/cost.py:1657-1666 | headroom/proxy/cost.py:1726-1735 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `headroom/proxy/cost.py:1723` calls `startswith` and `headroom/proxy/cost.py:1656` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (10 lines × 2) REDACTED:5759— REDACTED:5759-5768 | headroom/proxy/handlers/gemini.py:1219-1228 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (10 lines × 2) REDACTED:5759— REDACTED:5759-5768 | REDACTED:1743-1752 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (10 lines × 2) REDACTED:2195— REDACTED:2195-2204 | REDACTED:2239-2248 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) REDACTED:5458— REDACTED:5458-5467 | REDACTED:6094-6103 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:5458` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) REDACTED:1061— REDACTED:1061-1070 | REDACTED:2414-2423 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:1061` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) crates/headroom-core/src/transforms/pipeline/offloads/diff_noise.rs:327— crates/headroom-core/src/transforms/pipeline/offloads/diff_noise.rs:327-336 | crates/headroom-core/src/transforms/pipeline/offloads/json_offload.rs:217-226 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Each matched range is the entire body of the declaration above it, so the region is already a complete unit: move that whole declaration to the shared location and have each site call it, rather than lifting the lines out of their bodies. Any `return` inside it is the body's own exit and keeps its meaning in the moved unit.
Duplicated block (10 lines × 2) crates/headroom-core/src/transforms/smart_crusher/planning.rs:207— crates/headroom-core/src/transforms/smart_crusher/planning.rs:207-216 | crates/headroom-core/src/transforms/smart_crusher/planning.rs:462-471 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:662— crates/headroom-proxy/src/bedrock/invoke.rs:662-671 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:868-877 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:662` it runs out through the closing brace of the declaration holding it — the window is that declaration's tail, not a fragment that begins part-way through something, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) crates/headroom-proxy/src/main.rs:181— crates/headroom-proxy/src/main.rs:181-190 | crates/headroom-simulators/src/main.rs:41-50 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Each matched range is the entire body of the declaration above it, so the region is already a complete unit: move that whole declaration to the shared location and have each site call it, rather than lifting the lines out of their bodies. Any `return` inside it is the body's own exit and keeps its meaning in the moved unit.
Duplicated block (10 lines × 2) crates/headroom-core/src/transforms/safety.rs:60— crates/headroom-core/src/transforms/safety.rs:60-69 | crates/headroom-core/src/transforms/safety.rs:79-88 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/safety.rs:60` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) crates/headroom-core/src/ccr/backends/redis.rs:95— crates/headroom-core/src/ccr/backends/redis.rs:95-104 | crates/headroom-core/src/ccr/backends/redis.rs:137-146 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/ccr/backends/redis.rs:95` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) crates/headroom-proxy/src/observability/capture.rs:229— crates/headroom-proxy/src/observability/capture.rs:229-238 | crates/headroom-proxy/src/observability/capture.rs:246-255 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/observability/capture.rs:229` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
headroom_proxy::proxy::forward_http (cognitive 107) crates/headroom-proxy/src/proxy.rs:512— headroom_proxy::proxy::forward_http has cognitive complexity 107 (threshold 15). Drivers by points: if/else 44 (71 pts), match/switch 13 (23 pts), boolean chains 9, loops 1 (4 pts) (nesting depth added 40). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::proxy::run_sse_state_machine (cognitive 99) crates/headroom-proxy/src/proxy.rs:1557— headroom_proxy::proxy::run_sse_state_machine has cognitive complexity 99 (threshold 15). Drivers by points: if/else 23 (60 pts), match/switch 7 (24 pts), loops 6 (15 pts) (nesting depth added 63). The drivers above price the dispatch low by construction — a dispatch is charged once however many cases it lists, while each branch inside an arm is charged in full — so most of this count is what the case bodies hold, and the arms are where it can be reduced. To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Keep every case explicit, and make the behaviour for cases you do not list a deliberate choice rather than an accident.
headroom_proxy::compression::live_zone_anthropic::compress_anthropic_request (cognitive 47) crates/headroom-proxy/src/compression/live_zone_anthropic.rs:149— headroom_proxy::compression::live_zone_anthropic::compress_anthropic_request has cognitive complexity 47 (threshold 15). Drivers by points: if/else 16 (32 pts), match/switch 5 (9 pts), loops 2 (4 pts), boolean chains 2 (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::bedrock::invoke_streaming::handle_invoke_streaming (cognitive 40) crates/headroom-proxy/src/bedrock/invoke_streaming.rs:122— headroom_proxy::bedrock::invoke_streaming::handle_invoke_streaming has cognitive complexity 40 (threshold 15). Drivers by points: if/else 16 (28 pts), match/switch 9 (10 pts), loops 2 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::websocket::run_ws_pump (cognitive 40) crates/headroom-proxy/src/websocket.rs:111— headroom_proxy::websocket::run_ws_pump has cognitive complexity 40 (threshold 15). Drivers by points: if/else 9 (23 pts), match/switch 6 (14 pts), loops 3 (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::bedrock::eventstream::parse_headers (cognitive 36) crates/headroom-proxy/src/bedrock/eventstream.rs:359— headroom_proxy::bedrock::eventstream::parse_headers has cognitive complexity 36 (threshold 15). Drivers by points: if/else 12 (33 pts), match/switch 1 (2 pts), loops 1 (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::vertex::raw_predict::forward_vertex_request (cognitive 35) crates/headroom-proxy/src/vertex/raw_predict.rs:68— headroom_proxy::vertex::raw_predict::forward_vertex_request has cognitive complexity 35 (threshold 15). Drivers by points: if/else 14 (21 pts), match/switch 11 (13 pts), boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::bedrock::invoke::handle_invoke (cognitive 30) crates/headroom-proxy/src/bedrock/invoke.rs:137— headroom_proxy::bedrock::invoke::handle_invoke has cognitive complexity 30 (threshold 15). Drivers by points: if/else 13 (20 pts), match/switch 8, loops 2 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::cache_stabilization::anthropic_cache_control::any_anthropic_cache_control (cognitive 27) crates/headroom-proxy/src/cache_stabilization/anthropic_cache_control.rs:160— headroom_proxy::cache_stabilization::anthropic_cache_control::any_anthropic_cache_control has cognitive complexity 27 (threshold 15). Drivers by points: if/else 7 (17 pts), loops 4 (10 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::cache_stabilization::volatile_detector::walk_openai (cognitive 26) crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:212— headroom_proxy::cache_stabilization::volatile_detector::walk_openai has cognitive complexity 26 (threshold 15). Drivers by points: if/else 8 (22 pts), loops 2 (4 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::compression::live_zone_openai::compress_openai_chat_request (cognitive 25) crates/headroom-proxy/src/compression/live_zone_openai.rs:59— headroom_proxy::compression::live_zone_openai::compress_openai_chat_request has cognitive complexity 25 (threshold 15). Drivers by points: if/else 7 (16 pts), match/switch 3 (5 pts), loops 2 (4 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::compression::live_zone_responses::compress_openai_responses_request (cognitive 25) crates/headroom-proxy/src/compression/live_zone_responses.rs:59— headroom_proxy::compression::live_zone_responses::compress_openai_responses_request has cognitive complexity 25 (threshold 15). Drivers by points: if/else 7 (16 pts), match/switch 3 (5 pts), loops 2 (4 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::cache_stabilization::volatile_detector::walk_anthropic (cognitive 24) crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:172— headroom_proxy::cache_stabilization::volatile_detector::walk_anthropic has cognitive complexity 24 (threshold 15). Drivers by points: if/else 9 (19 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::sse::framing::parse_event_block (cognitive 23) crates/headroom-proxy/src/sse/framing.rs:258— headroom_proxy::sse::framing::parse_event_block has cognitive complexity 23 (threshold 15). Drivers by points: if/else 9 (15 pts), match/switch 2 (4 pts), loops 2 (3 pts), boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::bedrock::invoke_streaming::run_anthropic_state_machine (cognitive 22) crates/headroom-proxy/src/bedrock/invoke_streaming.rs:743— headroom_proxy::bedrock::invoke_streaming::run_anthropic_state_machine has cognitive complexity 22 (threshold 15). Drivers by points: if/else 5 (16 pts), loops 2 (3 pts), match/switch 1 (3 pts) (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_proxy::bedrock::invoke_streaming::translate_stream (cognitive 21) crates/headroom-proxy/src/bedrock/invoke_streaming.rs:521— headroom_proxy::bedrock::invoke_streaming::translate_stream has cognitive complexity 21 (threshold 15). Drivers by points: match/switch 4 (13 pts), if/else 3 (5 pts), loops 2 (3 pts) (nesting depth added 12). To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Keep every case explicit, and make the behaviour for cases you do not list a deliberate choice rather than an accident.
headroom_proxy::cache_stabilization::volatile_detector::scan_value_recursive (cognitive 20) crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:274— headroom_proxy::cache_stabilization::volatile_detector::scan_value_recursive has cognitive complexity 20 (threshold 15). Drivers by points: if/else 5 (14 pts), loops 2 (4 pts), boolean chains 1, match/switch 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Duplicated block (9 lines × 2) headroom/evals/batch_compression_eval.py:1134— headroom/evals/batch_compression_eval.py:1134-1142 | headroom/evals/core.py:315-323 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (9 lines × 2) headroom/evals/core.py:315— headroom/evals/core.py:315-323 | headroom/evals/runners/before_after.py:326-337 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (9 lines × 2) headroom/learn/analyzer.py:1154— headroom/learn/analyzer.py:1154-1162 | headroom/learn/analyzer.py:1172-1180 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/learn/analyzer.py:1154` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (9 lines × 2) headroom/memory/adapters/sqlite_vector.py:312— headroom/memory/adapters/sqlite_vector.py:312-320 | headroom/memory/adapters/sqlite_vector.py:326-334 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) REDACTED:4137— REDACTED:4137-4147 | REDACTED:6569-6577 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:4137` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) REDACTED:7519— REDACTED:7519-7527 | REDACTED:10222-10230 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) headroom/proxy/savings_tracker.py:1593— headroom/proxy/savings_tracker.py:1593-1601 | headroom/proxy/savings_tracker.py:1633-1641 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) headroom/proxy/tool_schema_compaction.py:256— headroom/proxy/tool_schema_compaction.py:256-264 | headroom/proxy/tool_schema_compaction.py:419-427 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (9 lines × 2) headroom/transforms/code_compressor.py:1117— headroom/transforms/code_compressor.py:1117-1125 | headroom/transforms/code_compressor.py:1129-1137 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (9 lines × 2) headroom/transforms/read_maturation.py:298— headroom/transforms/read_maturation.py:298-306 | headroom/transforms/read_maturation.py:317-325 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (9 lines × 2) headroom/cache/backends/redis.py:40— headroom/cache/backends/redis.py:40-48 | REDACTED:89-97 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (9 lines × 2) headroom/release_version.py:148— headroom/release_version.py:148-156 | scripts/changelog-gen.py:72-81 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (9 lines × 2) crates/headroom-core/src/signals/keyword_detector.rs:144— crates/headroom-core/src/signals/keyword_detector.rs:144-152 | crates/headroom-core/src/transforms/log_compressor.rs:358-366 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (9 lines × 2) crates/headroom-core/src/transforms/live_zone.rs:2470— crates/headroom-core/src/transforms/live_zone.rs:2470-2479 | crates/headroom-core/src/transforms/live_zone.rs:2997-3005 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/live_zone.rs:2470` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) crates/headroom-proxy/src/proxy.rs:602— crates/headroom-proxy/src/proxy.rs:602-612 | crates/headroom-proxy/src/websocket.rs:49-57 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (9 lines × 2) crates/headroom-proxy/src/bedrock/invoke_streaming.rs:797— crates/headroom-proxy/src/bedrock/invoke_streaming.rs:797-805 | crates/headroom-proxy/src/vertex/raw_predict.rs:525-533 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke_streaming.rs:797` it runs out through the closing brace of the declaration holding it and carries on into the declaration that follows — the window is the tail of one member plus the head of the next, so no call can be substituted for those exact lines, and the smallest declaration that contains all of them is the type they sit in. The repeated unit is the member each site sits in: where those members' bodies are the same, move one whole member to the shared location and have the others delegate to it; where the copies are a run of near-identical overloads or wrappers that differ only in their signatures, the repetition IS the run — a one-line delegation has no helper inside it to lift — so generate the run from the set it enumerates, or accept it and keep each member's own documentation with it.
Duplicated block (9 lines × 2) scripts/version-sync.py:66— scripts/version-sync.py:66-74 | scripts/version-sync.py:88-96 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `scripts/version-sync.py:64` calls `get`, `isinstance` and `scripts/version-sync.py:87` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
X17 · Uncapped recursion over a caller-supplied document· Recursive walk over a caller-supplied document has no depth cap · ×17
Recursive walk over a caller-supplied document has no depth cap sdk/typescript/src/utils/case.ts:16— `deepCamelCase` is exported and takes `obj: any` from its caller, and it calls itself at line 16 (`deepCamelCase`) with a piece of `obj` (and at line 19) — and nowhere in `deepCamelCase` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. JavaScript sets no limit of its own on that nesting: `JSON.parse` accepts any depth, so a 100,000-byte body — inside Express's default 100kb limit — parses to 50,000 levels, and a walk like this one throws `RangeError: Maximum call stack size exceeded` long before it reaches the bottom. Wherever that throw lands, the work fails: a request errors, and a walk running outside any `try` — an event handler, a timer, a promise nobody awaits — takes the Node process down with every other request in flight. Thread a depth argument through `deepCamelCase` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap sdk/typescript/src/utils/case.ts:27— `deepSnakeCase` is exported and takes `obj: any` from its caller, and it calls itself at line 27 (`deepSnakeCase`) with a piece of `obj` (and at line 30) — and nowhere in `deepSnakeCase` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. JavaScript sets no limit of its own on that nesting: `JSON.parse` accepts any depth, so a 100,000-byte body — inside Express's default 100kb limit — parses to 50,000 levels, and a walk like this one throws `RangeError: Maximum call stack size exceeded` long before it reaches the bottom. Wherever that throw lands, the work fails: a request errors, and a walk running outside any `try` — an event handler, a timer, a promise nobody awaits — takes the Node process down with every other request in flight. Thread a depth argument through `deepSnakeCase` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/config.py:496— `unwrap_tool_call` is public, takes a document from its caller (line 546) and hands it to `_decoded_strings`, which calls itself at line 496 (`_decoded_strings`) with a piece of `value` — and nowhere in `_decoded_strings` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_decoded_strings` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap REDACTED:455— `strip_streaming_only_content_fields_in_place` is public, takes a document from its caller (line 429) and hands it to `_strip_index_from_content_blocks_in_place`, which calls itself at line 455 (`_strip_index_from_content_blocks_in_place`) with a piece of `content` — and nowhere in `_strip_index_from_content_blocks_in_place` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_strip_index_from_content_blocks_in_place` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap REDACTED:1557— `build_otlp_logs` is public, takes a document from its caller (line 1565) and hands it to `_any_value`, which calls itself at line 1557 (`_any_value`) with a piece of `value` (and at line 1561) — and nowhere in `_any_value` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_any_value` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/proxy/anthropic_wire.py:131— `strip_safeguard_payload` is public and takes `value: Any` from its caller, and it calls itself at line 131 (`strip_safeguard_payload`) with a piece of `value` (and at line 136) — and nowhere in `strip_safeguard_payload` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `strip_safeguard_payload` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/proxy/helpers.py:3569— `compute_turn_id` is public, takes a document from its caller (line 3575) and hands it to `_strip_per_call_annotations`, which calls itself at line 3569 (`_strip_per_call_annotations`) with a piece of `obj` (and at line 3571) — and nowhere in `_strip_per_call_annotations` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_strip_per_call_annotations` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/proxy/request_log_redaction_policy.py:100— `redact_image_base64_value` is public, takes a document from its caller (line 77) and hands it to `_redact_value`, which calls itself at line 100 (`_redact_value`) with a piece of `value` (and at line 112) — and nowhere in `_redact_value` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_redact_value` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/proxy/semantic_cache_key_policy.py:119— `strip_cache_control` is public, takes a document from its caller (line 105) and hands it to `_strip_cache_control`, which calls itself at line 119 (`_strip_cache_control`) with a piece of `obj` (and at line 124) — and nowhere in `_strip_cache_control` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_strip_cache_control` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/proxy/tool_schema_compaction.py:218— `compact_tool_schema_value` is public and takes `value: Any` from its caller, and it calls itself at line 218 (`compact_tool_schema_value`) with a piece of `value` (and at line 234) — and nowhere in `compact_tool_schema_value` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `compact_tool_schema_value` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/proxy/tool_schema_compaction.py:341— `compact_tool_descriptions` is public, takes a document from its caller (line 371) and hands it to `_truncate_descriptions_in_schema`, which calls itself at line 341 (`_truncate_descriptions_in_schema`) with a piece of `value` (and at line 360) — and nowhere in `_truncate_descriptions_in_schema` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_truncate_descriptions_in_schema` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/proxy/wire_debug_redaction_policy.py:60— `redact_for_wire_debug` is public and takes `value: Any` from its caller, and it calls itself at line 60 (`redact_for_wire_debug`) with a piece of `value` (and at line 65) — and nowhere in `redact_for_wire_debug` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `redact_for_wire_debug` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/providers/anthropic.py:98— `sanitize_anthropic_model_metadata` is public and takes `value: Any` from its caller, and it calls itself at line 98 (`sanitize_anthropic_model_metadata`) with a piece of `value` (and at line 107) — and nowhere in `sanitize_anthropic_model_metadata` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `sanitize_anthropic_model_metadata` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/memory/tracker.py:375— `estimate_object_size` is public and takes `obj: Any` from its caller, and it calls itself at line 375 (`estimate_object_size`) with a piece of `obj` (and at line 378, line 380) — and nowhere in `estimate_object_size` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `estimate_object_size` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/evals/session_probes.py:208— `probe_event` is public, takes a document from its caller (line 266) and hands it to `_all_text`, which calls itself at line 208 (`_all_text`) with a piece of `node` (and at line 211) — and nowhere in `_all_text` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_all_text` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap headroom/ccr/marker_resolution.py:77— `resolve_markers_in_response` is public and takes `response: Any` from its caller, and it calls itself at line 77 (`resolve_markers_in_response`) with a piece of `response` (and at line 80) — and nowhere in `resolve_markers_in_response` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `resolve_markers_in_response` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
Recursive walk over a caller-supplied document has no depth cap REDACTED:262— `segment_fingerprint` is public, takes a document from its caller (line 582) and hands it to `_canonicalize_for_prefix_compare`, which calls itself at line 262 (`_canonicalize_for_prefix_compare`) with a piece of `obj` (and at line 265) — and nowhere in `_canonicalize_for_prefix_compare` is there a depth parameter, a descent counter, or any other cap. The walk therefore spends one stack frame per LEVEL of the value it is handed, so the nesting of the caller's document — not this code — decides how deep the stack goes. Python's parsers accept far more nesting than its stack allows: `json.loads` turns 3,000 bytes of brackets into 1,500 levels and `xml.etree.ElementTree` parses tens of thousands, while a walk like this one raises `RecursionError` once it passes the interpreter's default limit of 1,000 frames. Wherever that exception lands, the work fails: a request errors, and outside any `try` the worker or the program exits with it. Raising `sys.setrecursionlimit` only moves the number the document has to beat. Thread a depth argument through `_canonicalize_for_prefix_compare` and reject the value past a fixed maximum, or rewrite the descent with an explicit stack.
headroom_core::transforms::diff_compressor::parse_diff (cyclomatic 34) crates/headroom-core/src/transforms/diff_compressor.rs:696— headroom_core::transforms::diff_compressor::parse_diff has cyclomatic complexity 34 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_core::transforms::search_compressor::scan_marker (cyclomatic 25) crates/headroom-core/src/transforms/search_compressor.rs:857— headroom_core::transforms::search_compressor::scan_marker has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_core::transforms::code_compressor::detect_language (cyclomatic 23) crates/headroom-core/src/transforms/code_compressor.rs:699— headroom_core::transforms::code_compressor::detect_language has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_core::transforms::diff_compressor::reduce_context (cyclomatic 23) crates/headroom-core/src/transforms/diff_compressor.rs:1055— headroom_core::transforms::diff_compressor::reduce_context has cyclomatic complexity 23 (threshold 15). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
headroom_core::transforms::live_zone::compress_openai_responses_live_zone (cyclomatic 23) crates/headroom-core/src/transforms/live_zone.rs:2693— headroom_core::transforms::live_zone::compress_openai_responses_live_zone has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_core::transforms::smart_crusher::crushers::crush_number_array (cyclomatic 22) crates/headroom-core/src/transforms/smart_crusher/crushers.rs:227— headroom_core::transforms::smart_crusher::crushers::crush_number_array has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_core::transforms::tag_protector::parse_tag_at (cyclomatic 21) crates/headroom-core/src/transforms/tag_protector.rs:315— headroom_core::transforms::tag_protector::parse_tag_at has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_core::transforms::smart_crusher::field_detect::detect_score_field_statistically (cyclomatic 20) crates/headroom-core/src/transforms/smart_crusher/field_detect.rs:116— headroom_core::transforms::smart_crusher::field_detect::detect_score_field_statistically has cyclomatic complexity 20 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
headroom_core::transforms::smart_crusher::classifier::classify_array (cyclomatic 18) crates/headroom-core/src/transforms/smart_crusher/classifier.rs:70— headroom_core::transforms::smart_crusher::classifier::classify_array has cyclomatic complexity 18 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
headroom_core::transforms::smart_crusher::outliers::detect_rare_status_values (cyclomatic 18) crates/headroom-core/src/transforms/smart_crusher/outliers.rs:122— headroom_core::transforms::smart_crusher::outliers::detect_rare_status_values has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_core::transforms::smart_crusher::crushers::crush_string_array (cyclomatic 17) crates/headroom-core/src/transforms/smart_crusher/crushers.rs:112— headroom_core::transforms::smart_crusher::crushers::crush_string_array has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_core::transforms::anchor_selector::write_python_json_inner (cyclomatic 16) crates/headroom-core/src/transforms/anchor_selector.rs:432— headroom_core::transforms::anchor_selector::write_python_json_inner has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_core::transforms::live_zone::dispatch_compressor (cyclomatic 16) crates/headroom-core/src/transforms/live_zone.rs:1648— headroom_core::transforms::live_zone::dispatch_compressor has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_core::transforms::safety::tool_pair_indices (cyclomatic 16) crates/headroom-core/src/transforms/safety.rs:40— headroom_core::transforms::safety::tool_pair_indices has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_core::transforms::smart_crusher::orchestration::prioritize_indices (cyclomatic 16) crates/headroom-core/src/transforms/smart_crusher/orchestration.rs:155— headroom_core::transforms::smart_crusher::orchestration::prioritize_indices has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
D30 · Dependency Vulnerabilities· Medium CVE · ×15
FunctionTooLong: headroom_proxy::proxy::forward_http crates/headroom-proxy/src/proxy.rs:512— FunctionTooLong — headroom_proxy::proxy::forward_http runs 437 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 337 over it, 4.37× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: headroom_proxy::vertex::raw_predict::forward_vertex_request crates/headroom-proxy/src/vertex/raw_predict.rs:68— FunctionTooLong — headroom_proxy::vertex::raw_predict::forward_vertex_request runs 271 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 171 over it, 2.71× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: headroom_proxy::bedrock::invoke_streaming::handle_invoke_streaming crates/headroom-proxy/src/bedrock/invoke_streaming.rs:122— FunctionTooLong — headroom_proxy::bedrock::invoke_streaming::handle_invoke_streaming runs 259 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 159 over it, 2.59× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: headroom_proxy::compression::live_zone_anthropic::compress_anthropic_request crates/headroom-proxy/src/compression/live_zone_anthropic.rs:149— FunctionTooLong — headroom_proxy::compression::live_zone_anthropic::compress_anthropic_request runs 236 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 136 over it, 2.36× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: headroom_proxy::proxy::run_sse_state_machine crates/headroom-proxy/src/proxy.rs:1557— FunctionTooLong — headroom_proxy::proxy::run_sse_state_machine runs 228 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 128 over it, 2.28× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: headroom_proxy::bedrock::invoke::handle_invoke crates/headroom-proxy/src/bedrock/invoke.rs:137— FunctionTooLong — headroom_proxy::bedrock::invoke::handle_invoke runs 219 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 119 over it, 2.19× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: headroom_proxy::compression::live_zone_responses::compress_openai_responses_request crates/headroom-proxy/src/compression/live_zone_responses.rs:59— FunctionTooLong — headroom_proxy::compression::live_zone_responses::compress_openai_responses_request runs 189 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 89 over it, 1.89× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: headroom_proxy::compression::live_zone_openai::compress_openai_chat_request crates/headroom-proxy/src/compression/live_zone_openai.rs:59— FunctionTooLong — headroom_proxy::compression::live_zone_openai::compress_openai_chat_request runs 182 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 82 over it, 1.82× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: register.register plugins/headroom-snip/hooks/register.tsx:144— FunctionTooLong — register runs 158 significant lines (blank, comment-only and punctuation-only lines excluded) in one body. The bar is 100 significant lines; this is 58 over it, 1.58× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: headroom_proxy::bedrock::eventstream::parse_headers crates/headroom-proxy/src/bedrock/eventstream.rs:359— FunctionTooLong — headroom_proxy::bedrock::eventstream::parse_headers runs 114 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 14 over it, 1.14× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: settings.html.settingsPage headroom/dashboard/templates/settings.html:167— FunctionTooLong — settingsPage runs 114 significant lines (blank, comment-only and punctuation-only lines excluded) in one body. The bar is 100 significant lines; this is 14 over it, 1.14× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: dashboard.html.renderChart crates/headroom-proxy/src/observability/dashboard.html:435— FunctionTooLong — renderChart runs 110 significant lines (blank, comment-only and punctuation-only lines excluded) in one body. The bar is 100 significant lines; this is 10 over it, 1.10× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: headroom_core::transforms::live_zone::plan_block_replacements crates/headroom-core/src/transforms/live_zone.rs:1342— FunctionTooLong — headroom_core::transforms::live_zone::plan_block_replacements runs 106 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 6 over it, 1.06× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
FunctionTooLong: headroom_core::transforms::live_zone::compress_openai_responses_live_zone crates/headroom-core/src/transforms/live_zone.rs:2693— FunctionTooLong — headroom_core::transforms::live_zone::compress_openai_responses_live_zone runs 101 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 1 over it, 1.01× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
Duplicated block (7 lines × 2) docker/differential-network-capture/mitm_capture.py:45— docker/differential-network-capture/mitm_capture.py:45-51 | headroom/capture/network_diff.py:97-103 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (7 lines × 2) headroom/evals/reports/report_card.py:223— headroom/evals/reports/report_card.py:223-229 | headroom/evals/reports/report_card.py:236-242 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (7 lines × 2) headroom/memory/traffic_learner.py:1718— headroom/memory/traffic_learner.py:1718-1725 | headroom/transforms/read_lifecycle.py:232-238 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) headroom/proxy/context_guard.py:452— headroom/proxy/context_guard.py:452-458 | headroom/proxy/context_guard.py:493-499 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) REDACTED:1283— REDACTED:1283-1289 | headroom/proxy/output_turn_policy.py:69-75 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) REDACTED:8771— REDACTED:8771-8777 | REDACTED:8787-8793 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (7 lines × 2) headroom/transforms/content_router.py:971— headroom/transforms/content_router.py:971-977 | headroom/transforms/content_router.py:1113-1119 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) headroom/transforms/kompress_compressor.py:2140— headroom/transforms/kompress_compressor.py:2140-2146 | headroom/transforms/kompress_compressor.py:2570-2576 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) headroom/transforms/read_lifecycle.py:457— headroom/transforms/read_lifecycle.py:457-463 | headroom/transforms/read_lifecycle.py:511-517 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `headroom/transforms/read_lifecycle.py:509` calls `get` and `headroom/transforms/read_lifecycle.py:456` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (7 lines × 2) headroom/audit/maturation.py:60— headroom/audit/maturation.py:60-66 | headroom/audit/reads.py:131-137 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) headroom/pricing/counterfactual.py:137— headroom/pricing/counterfactual.py:137-143 | headroom/savings_ledger.py:176-182 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) REDACTED:417— REDACTED:417-423 | REDACTED:449-455 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) crates/headroom-proxy/src/websocket.rs:181— crates/headroom-proxy/src/websocket.rs:181-187 | crates/headroom-proxy/src/websocket.rs:200-206 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/websocket.rs:181` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (7 lines × 2) crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:525— crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:525-531 | crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:536-542 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:525` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12 lines × 2) headroom/audit/maturation.py:78— headroom/audit/maturation.py:78-89 | headroom/audit/maturation.py:194-205 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12 lines × 2) headroom/evals/html_extraction.py:274— headroom/evals/html_extraction.py:274-285 | headroom/evals/html_extraction.py:329-340 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/evals/html_extraction.py:274` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12 lines × 2) headroom/proxy/ccr_session_tracker.py:28— headroom/proxy/ccr_session_tracker.py:28-39 | headroom/proxy/tool_injection_tracker.py:28-39 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12 lines × 2) headroom/proxy/ccr_session_tracker.py:43— headroom/proxy/ccr_session_tracker.py:43-54 | headroom/proxy/tool_injection_tracker.py:45-56 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12 lines × 2) headroom/proxy/handlers/batch.py:194— headroom/proxy/handlers/batch.py:194-211 | headroom/proxy/handlers/batch.py:1193-1204 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/proxy/handlers/batch.py:194` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/proxy/handlers/batch.py:212` calls `items`, `get` and `headroom/proxy/handlers/batch.py:1206` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (12 lines × 2) REDACTED:6287— REDACTED:6287-6300 | REDACTED:6475-6486 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:6287` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12 lines × 2) headroom/proxy/helpers.py:594— headroom/proxy/helpers.py:594-605 | headroom/proxy/helpers.py:606-617 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12 lines × 2) crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:486— crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:486-497 | crates/headroom-core/src/transforms/smart_crusher/orchestration.rs:262-273 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:486` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12 lines × 2) crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:243— crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:243-254 | crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:481-492 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:243` it runs out through the closing brace of the declaration holding it — the window is that declaration's tail, not a fragment that begins part-way through something, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12 lines × 2) crates/headroom-core/src/transforms/smart_crusher/planning.rs:314— crates/headroom-core/src/transforms/smart_crusher/planning.rs:314-325 | crates/headroom-core/src/transforms/smart_crusher/planning.rs:529-540 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `crates/headroom-core/src/transforms/smart_crusher/planning.rs:313` calls `is_empty` and `crates/headroom-core/src/transforms/smart_crusher/planning.rs:526` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (12 lines × 2) crates/headroom-proxy/src/compression/live_zone_openai.rs:66— crates/headroom-proxy/src/compression/live_zone_openai.rs:66-77 | crates/headroom-proxy/src/compression/live_zone_openai.rs:107-118 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_openai.rs:66` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (12 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:459— crates/headroom-proxy/src/bedrock/invoke.rs:459-470 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:847-858 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:459` it runs out through the closing brace of the declaration holding it — the window is that declaration's tail, not a fragment that begins part-way through something, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12 lines × 2) crates/headroom-core/src/transforms/pipeline/orchestrator.rs:174— crates/headroom-core/src/transforms/pipeline/orchestrator.rs:174-185 | crates/headroom-core/src/transforms/pipeline/orchestrator.rs:234-245 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/pipeline/orchestrator.rs:174` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `crates/headroom-core/src/transforms/pipeline/orchestrator.rs:171` calls `push` and `crates/headroom-core/src/transforms/pipeline/orchestrator.rs:231` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Swallowed exception (empty catch) sdk/typescript/src/client.ts:570— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) sdk/typescript/src/paths.ts:69— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) sdk/typescript/src/paths.ts:86— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) sdk/typescript/src/utils/stream.ts:32— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) plugins/opencode/src/plugin.ts:100— `.catch(() => {})` handles the rejection by doing nothing — the failure is discarded with no log and no rethrow, and the chain carries on as if the work succeeded. Log it through whatever this codebase already uses to report problems, hand it to a caller that can (`next(error)`, a returned rejection), or don't catch it.
Swallowed exception (empty catch) plugins/opencode/src/transport.ts:366— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) plugins/openclaw/src/advancement-key-store.ts:252— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) plugins/openclaw/src/engine.ts:390— `.catch(() => {})` handles the rejection by doing nothing — the failure is discarded with no log and no rethrow, and the chain carries on as if the work succeeded. Log it through whatever this codebase already uses to report problems, hand it to a caller that can (`next(error)`, a returned rejection), or don't catch it.
Swallowed exception (empty catch) plugins/headroom-snip/hooks/snip.ts:185— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) headroom/_subprocess.py:30— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) headroom/_subprocess.py:61— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) headroom/onnx_runtime.py:287— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) headroom/proxy_client_liveness.py:35— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Duplicated block (17 lines × 2) headroom/copilot_linux_secret.py:38— headroom/copilot_linux_secret.py:38-54 | headroom/copilot_macos_keychain.py:61-77 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (17 lines × 2) headroom/integrations/agno/model.py:258— headroom/integrations/agno/model.py:258-274 | headroom/integrations/strands/model.py:130-146 — `headroom/integrations/agno/model.py` and `headroom/integrations/strands/model.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 4 separate duplicated blocks between them, totalling at least 113 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (17 lines × 2) headroom/integrations/agno/model.py:646— headroom/integrations/agno/model.py:646-662 | headroom/integrations/agno/model.py:687-703 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (17 lines × 2) headroom/memory/__init__.py:174— headroom/memory/__init__.py:174-190 | headroom/memory/backends/__init__.py:53-69 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (17 lines × 2) REDACTED:4484— REDACTED:4484-4501 | REDACTED:5722-5738 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:4484` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (17 lines × 2) headroom/proxy/savings_tracker.py:1320— headroom/proxy/savings_tracker.py:1320-1336 | headroom/proxy/savings_tracker.py:1372-1388 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (17 lines × 2) headroom/storage/sqlite.py:242— headroom/storage/sqlite.py:242-258 | headroom/storage/sqlite.py:279-295 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (17 lines × 2) crates/headroom-core/src/transforms/diff_compressor.rs:883— crates/headroom-core/src/transforms/diff_compressor.rs:883-899 | crates/headroom-core/src/transforms/search_compressor.rs:85-101 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Each matched range is the entire body of the declaration above it, so the region is already a complete unit: move that whole declaration to the shared location and have each site call it, rather than lifting the lines out of their bodies. Any `return` inside it is the body's own exit and keeps its meaning in the moved unit.
Duplicated block (17 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:279— crates/headroom-proxy/src/bedrock/invoke.rs:279-295 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:246-262 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:279` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (17 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:404— crates/headroom-proxy/src/bedrock/invoke.rs:404-420 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:366-382 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:404` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (17 lines × 2) crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:181— crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:181-197 | crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:214-230 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:181` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:231` calls `Some`, `get` and `crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:198` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (17 lines × 2) crates/headroom-proxy/src/handlers/chat_completions.rs:84— crates/headroom-proxy/src/handlers/chat_completions.rs:84-100 | crates/headroom-proxy/src/handlers/responses.rs:155-171 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/handlers/chat_completions.rs:84` it runs out through the closing brace of the declaration holding it — the window is that declaration's tail, not a fragment that begins part-way through something, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (13 lines × 2) headroom/evals/core.py:325— headroom/evals/core.py:325-337 | headroom/evals/runners/before_after.py:342-354 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (13 lines × 2) headroom/memory/adapters/hnsw.py:155— headroom/memory/adapters/hnsw.py:155-167 | headroom/memory/adapters/sqlite_vector.py:150-162 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (13 lines × 2) headroom/pipeline.py:247— headroom/pipeline.py:247-259 | headroom/transforms/compressor_registry.py:224-236 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (13 lines × 2) headroom/providers/cohere.py:355— headroom/providers/cohere.py:355-367 | headroom/providers/google.py:369-381 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (13 lines × 2) headroom/proxy/handlers/gemini.py:719— headroom/proxy/handlers/gemini.py:719-731 | REDACTED:4041-4053 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/proxy/handlers/gemini.py:719` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (13 lines × 2) REDACTED:6128— REDACTED:6128-6140 | REDACTED:7727-7739 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:6128` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (13 lines × 2) REDACTED:166— REDACTED:166-178 | headroom/proxy/helpers.py:3558-3572 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (13 lines × 2) crates/headroom-core/src/transforms/code_compressor.rs:1530— crates/headroom-core/src/transforms/code_compressor.rs:1530-1542 | crates/headroom-core/src/transforms/code_compressor.rs:1736-1748 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (13 lines × 2) crates/headroom-core/src/transforms/live_zone.rs:960— crates/headroom-core/src/transforms/live_zone.rs:960-972 | crates/headroom-core/src/transforms/live_zone.rs:2241-2253 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (13 lines × 2) crates/headroom-core/src/tokenizer/estimator.rs:19— crates/headroom-core/src/tokenizer/estimator.rs:19-31 | crates/headroom-core/src/transforms/text_crusher/crusher.rs:36-48 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (13 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:239— crates/headroom-proxy/src/bedrock/invoke.rs:239-252 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:207-219 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (5 lines × 2) headroom/cli/evals.py:726— headroom/cli/evals.py:726-730 | headroom/cli/evals.py:755-759 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (5 lines × 2) headroom/integrations/agno/model.py:771— headroom/integrations/agno/model.py:771-775 | headroom/integrations/strands/model.py:581-585 — `headroom/integrations/agno/model.py` and `headroom/integrations/strands/model.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 4 separate duplicated blocks between them, totalling at least 113 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/integrations/agno/model.py:776` calls `isinstance` and `headroom/integrations/strands/model.py:586` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (5 lines × 2) headroom/integrations/agno/providers.py:95— headroom/integrations/agno/providers.py:95-99 | headroom/integrations/strands/providers.py:71-75 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/integrations/agno/providers.py:100` calls `lower`, `debug`, `CohereProvider` and `headroom/integrations/strands/providers.py:76` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (5 lines × 2) headroom/learn/plugins/claude.py:602— headroom/learn/plugins/claude.py:602-606 | headroom/learn/plugins/claude.py:612-616 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (5 lines × 2) REDACTED:2904— REDACTED:2904-2908 | REDACTED:2946-2950 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:2904` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (5 lines × 2) headroom/proxy/savings_tracker.py:764— headroom/proxy/savings_tracker.py:764-768 | headroom/proxy/savings_tracker.py:2383-2387 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (5 lines × 2) headroom/install/paths.py:202— headroom/install/paths.py:202-213 | headroom/providers/grok_build/config.py:28-32 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (5 lines × 2) REDACTED:313— REDACTED:313-317 | headroom/integrations/_metrics.py:67-75 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (5 lines × 2) crates/headroom-proxy/src/proxy.rs:462— crates/headroom-proxy/src/proxy.rs:462-468 | crates/headroom-proxy/src/proxy.rs:1428-1432 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/proxy.rs:462` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note first that the copies are not typed on the same thing: the declarations holding them bind `headers` to `&HeaderMap` in one and `&http::HeaderMap` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (5 lines × 2) crates/headroom-core/src/signals/keyword_detector.rs:306— crates/headroom-core/src/signals/keyword_detector.rs:306-310 | crates/headroom-core/src/transforms/log_compressor.rs:388-392 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (5 lines × 2) crates/headroom-proxy/src/sse/anthropic.rs:232— crates/headroom-proxy/src/sse/anthropic.rs:232-236 | crates/headroom-proxy/src/sse/anthropic.rs:266-272 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
headroom_proxy::proxy::forward_http (cyclomatic 64) crates/headroom-proxy/src/proxy.rs:512— headroom_proxy::proxy::forward_http has cyclomatic complexity 64 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_proxy::proxy::run_sse_state_machine (cyclomatic 35) crates/headroom-proxy/src/proxy.rs:1557— headroom_proxy::proxy::run_sse_state_machine has cyclomatic complexity 35 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_proxy::bedrock::invoke_streaming::handle_invoke_streaming (cyclomatic 27) crates/headroom-proxy/src/bedrock/invoke_streaming.rs:122— headroom_proxy::bedrock::invoke_streaming::handle_invoke_streaming has cyclomatic complexity 27 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_proxy::vertex::raw_predict::forward_vertex_request (cyclomatic 26) crates/headroom-proxy/src/vertex/raw_predict.rs:68— headroom_proxy::vertex::raw_predict::forward_vertex_request has cyclomatic complexity 26 (threshold 15). To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Where every arm is uniform — the same kind of value, with no behaviour of its own — a table keyed by the case is the shorter form; wherever the arms carry different data or different behaviour, keep them as cases, because collapsing those trades an explicit, reviewable set of cases for nothing.
headroom_proxy::compression::live_zone_anthropic::compress_anthropic_request (cyclomatic 25) crates/headroom-proxy/src/compression/live_zone_anthropic.rs:149— headroom_proxy::compression::live_zone_anthropic::compress_anthropic_request has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_proxy::bedrock::eventstream::parse_headers (cyclomatic 23) crates/headroom-proxy/src/bedrock/eventstream.rs:359— headroom_proxy::bedrock::eventstream::parse_headers has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_proxy::bedrock::invoke::handle_invoke (cyclomatic 23) crates/headroom-proxy/src/bedrock/invoke.rs:137— headroom_proxy::bedrock::invoke::handle_invoke has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_proxy::websocket::run_ws_pump (cyclomatic 19) crates/headroom-proxy/src/websocket.rs:111— headroom_proxy::websocket::run_ws_pump has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_proxy::compression::live_zone_openai::compress_openai_chat_request (cyclomatic 16) crates/headroom-proxy/src/compression/live_zone_openai.rs:59— headroom_proxy::compression::live_zone_openai::compress_openai_chat_request has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_proxy::compression::live_zone_responses::compress_openai_responses_request (cyclomatic 16) crates/headroom-proxy/src/compression/live_zone_responses.rs:59— headroom_proxy::compression::live_zone_responses::compress_openai_responses_request has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
TodoComment tests/test_memory_bridge.py:63— ## TODO — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment tests/test_observed_wire_shapes.py:153— # EXTENSION TODO (handler): REDACTED cache mode currently does overlay + frozen-count, — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment tests/test_observed_wire_shapes.py:191— # EXTENSION TODO (handler): same delta-path wiring as Chat; ensure reasoning items are — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment tests/test_observed_wire_shapes.py:210— # EXTENSION TODO: `summary` (display-only per OpenAI docs) and the reasoning item — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment tests/test_observed_wire_shapes.py:221— # EXTENSION TODO (handler): bedrock.py bypasses compression in cache mode. Wire a — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment tests/test_observed_wire_shapes.py:262— # us — but we drop it defensively. EXTENSION TODO: if we ever ingest pre-wire AI-SDK — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment headroom/proxy/handlers/gemini.py:1170— # Eligible-tracking is TODO for Gemini; pass the full — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment REDACTED:5235— # TODO(#realignment): align REDACTED CCR block to — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment headroom/integrations/langchain/providers.py:169— # TODO: Add dedicated providers when needed — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment REDACTED:229— # TODO: Remove testing bypass before production release — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
Duplicated block (15 lines × 2) headroom/cache/dynamic_detector.py:365— headroom/cache/dynamic_detector.py:365-379 | headroom/cache/dynamic_detector.py:428-442 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/cache/dynamic_detector.py:365` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (15 lines × 2) headroom/evals/suite_runner.py:570— headroom/evals/suite_runner.py:570-584 | headroom/evals/suite_runner.py:588-602 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15 lines × 2) headroom/providers/anthropic.py:468— headroom/providers/anthropic.py:468-482 | headroom/providers/openai.py:225-239 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (15 lines × 2) REDACTED:6057— REDACTED:6057-6071 | REDACTED:7753-7767 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:6057` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (15 lines × 2) REDACTED:9255— REDACTED:9255-9269 | REDACTED:10475-10489 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15 lines × 2) headroom/transforms/compression_batches.py:345— headroom/transforms/compression_batches.py:345-359 | headroom/transforms/compression_batches.py:361-375 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15 lines × 2) headroom/memory/adapters/fts5.py:281— headroom/memory/adapters/fts5.py:281-295 | headroom/memory/adapters/sqlite.py:408-422 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (15 lines × 2) crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:224— crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:224-238 | crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:462-476 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:224` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note first that the copies are not typed on the same thing: the declarations holding them bind `fmt` to `&CsvSchemaFormatter` in one and `&MarkdownKvFormatter` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (15 lines × 2) crates/headroom-proxy/src/compression/live_zone_openai.rs:427— crates/headroom-proxy/src/compression/live_zone_openai.rs:427-441 | crates/headroom-proxy/src/compression/live_zone_responses.rs:435-449 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_openai.rs` and `crates/headroom-proxy/src/compression/live_zone_responses.rs` as WHOLE FILES: this scan already matched 14 separate duplicated blocks between them, totalling at least 278 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_openai.rs:427` it runs out through the closing brace of the declaration holding it and carries on into the declaration that follows — the window is the tail of one member plus the head of the next, so no call can be substituted for those exact lines, and the smallest declaration that contains all of them is the type they sit in. The repeated unit is the member each site sits in: where those members' bodies are the same, move one whole member to the shared location and have the others delegate to it; where the copies are a run of near-identical overloads or wrappers that differ only in their signatures, the repetition IS the run — a one-line delegation has no helper inside it to lift — so generate the run from the set it enumerates, or accept it and keep each member's own documentation with it.
Duplicated block (15 lines × 2) crates/headroom-proxy/src/compression/live_zone_openai.rs:79— crates/headroom-proxy/src/compression/live_zone_openai.rs:79-93 | crates/headroom-proxy/src/compression/live_zone_responses.rs:79-94 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_openai.rs` and `crates/headroom-proxy/src/compression/live_zone_responses.rs` as WHOLE FILES: this scan already matched 14 separate duplicated blocks between them, totalling at least 278 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_openai.rs:79` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) headroom/learn/plugins/codex.py:207— headroom/learn/plugins/codex.py:207-217 | headroom/learn/plugins/grok.py:112-122 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 2) headroom/memory/adapters/hnsw.py:737— headroom/memory/adapters/hnsw.py:737-754 | headroom/memory/adapters/sqlite_vector.py:816-826 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 2) headroom/proxy/helpers.py:849— headroom/proxy/helpers.py:849-859 | headroom/proxy/helpers.py:883-893 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (11 lines × 2) headroom/proxy/tool_schema_compaction.py:267— headroom/proxy/tool_schema_compaction.py:267-277 | headroom/proxy/tool_schema_compaction.py:430-440 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 2) headroom/transforms/content_router.py:4552— headroom/transforms/content_router.py:4552-4562 | headroom/transforms/content_router.py:4971-4981 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (11 lines × 2) crates/headroom-core/src/hf_cache.rs:340— crates/headroom-core/src/hf_cache.rs:340-350 | crates/headroom-core/src/hf_cache.rs:358-368 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/hf_cache.rs:340` it runs out through the closing brace of the declaration holding it — the window is that declaration's tail, not a fragment that begins part-way through something, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) crates/headroom-core/src/transforms/content_detector.rs:579— crates/headroom-core/src/transforms/content_detector.rs:579-589 | crates/headroom-core/src/transforms/content_detector.rs:622-632 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 2) crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:798— crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:798-808 | crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:824-834 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:798` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) crates/headroom-proxy/src/proxy.rs:1344— crates/headroom-proxy/src/proxy.rs:1344-1354 | crates/headroom-proxy/src/vertex/raw_predict.rs:423-437 — before extracting anything, compare `crates/headroom-proxy/src/proxy.rs` and `crates/headroom-proxy/src/vertex/raw_predict.rs` as WHOLE FILES: this scan already matched 5 separate duplicated blocks between them, totalling at least 53 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/proxy.rs:1344` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) examples/langchain_demo/show_compression.py:48— examples/langchain_demo/show_compression.py:48-58 | examples/langchain_demo/show_compression.py:111-121 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) headroom/integrations/agno/providers.py:89— headroom/integrations/agno/providers.py:89-96 | headroom/integrations/strands/providers.py:62-69 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (8 lines × 2) headroom/integrations/agno/providers.py:112— headroom/integrations/agno/providers.py:112-119 | headroom/integrations/strands/providers.py:85-92 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/integrations/agno/providers.py:121` calls `debug`, `CohereProvider` and `headroom/integrations/strands/providers.py:95` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (8 lines × 2) headroom/memory/adapters/sqlite_vector.py:706— headroom/memory/adapters/sqlite_vector.py:706-713 | headroom/memory/adapters/sqlite_vector.py:865-872 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) REDACTED:12345— REDACTED:12345-12352 | REDACTED:12628-12635 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) headroom/audit/maturation.py:91— headroom/audit/maturation.py:91-98 | headroom/audit/reads.py:193-200 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (8 lines × 2) REDACTED:313— REDACTED:313-320 | headroom/providers/codex/install.py:362-369 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (8 lines × 2) headroom/cli/wrap.py:723— headroom/cli/wrap.py:723-730 | headroom/evals/suite_runner.py:264-271 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (8 lines × 2) headroom/providers/openai.py:396— headroom/providers/openai.py:396-403 | headroom/tokenizers/tiktoken_counter.py:273-281 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (8 lines × 2) crates/headroom-core/src/transforms/code_compressor.rs:1828— crates/headroom-core/src/transforms/code_compressor.rs:1828-1836 | crates/headroom-core/src/transforms/code_compressor.rs:1841-1848 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/code_compressor.rs:1828` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2) crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:276— crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:276-283 | crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:519-526 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:276` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note first that the copies are not typed on the same thing: the declarations holding them bind `fmt` to `&CsvSchemaFormatter` in one and `&MarkdownKvFormatter` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (16 lines × 2) headroom/cli/wrap.py:7899— headroom/cli/wrap.py:7899-7916 | headroom/cli/wrap.py:8624-8639 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/cli/wrap.py:7899` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (16 lines × 2) headroom/memory/__init__.py:162— headroom/memory/__init__.py:162-177 | headroom/memory/backends/__init__.py:34-49 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (16 lines × 2) headroom/memory/adapters/hnsw.py:136— headroom/memory/adapters/hnsw.py:136-151 | headroom/memory/adapters/sqlite_vector.py:131-146 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (16 lines × 2) REDACTED:6604— REDACTED:6604-6619 | headroom/proxy/handlers/batch.py:381-396 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:6604` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `REDACTED:6603` calls `get` and `headroom/proxy/handlers/batch.py:380` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (16 lines × 2) headroom/proxy/cost.py:46— headroom/proxy/cost.py:46-61 | headroom/proxy/savings_tracker.py:151-166 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (16 lines × 2) headroom/observability/metrics.py:783— headroom/observability/metrics.py:783-798 | headroom/observability/tracing.py:232-247 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (16 lines × 2) crates/headroom-proxy/src/bedrock/eventstream.rs:396— crates/headroom-proxy/src/bedrock/eventstream.rs:396-411 | crates/headroom-proxy/src/bedrock/eventstream.rs:422-437 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (16 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:586— crates/headroom-proxy/src/bedrock/invoke.rs:586-601 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:966-981 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Each matched range is the entire body of the declaration above it, so the region is already a complete unit: move that whole declaration to the shared location and have each site call it, rather than lifting the lines out of their bodies. Any `return` inside it is the body's own exit and keeps its meaning in the moved unit.
Duplicated block (16 lines × 2) crates/headroom-proxy/src/compression/live_zone_openai.rs:230— crates/headroom-proxy/src/compression/live_zone_openai.rs:230-245 | crates/headroom-proxy/src/compression/live_zone_responses.rs:238-253 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_openai.rs` and `crates/headroom-proxy/src/compression/live_zone_responses.rs` as WHOLE FILES: this scan already matched 14 separate duplicated blocks between them, totalling at least 278 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_openai.rs:230` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
D4 · Code Duplication· Members sharing a duplicated core (4 members, 50+ identical tokens) · ×8
Members sharing a duplicated core (4 members, 50+ identical tokens) headroom/backends/litellm.py:1273— headroom/backends/litellm.py:1273-1395 | headroom/backends/litellm.py:1402-1810 | headroom/backends/litellm.py:1821-2030 | headroom/backends/litellm.py:2037-2116 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) REDACTED:1228— REDACTED:1228-1237 | REDACTED:1243-1252 | REDACTED:1258-1267 | REDACTED:1273-1282 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) headroom/integrations/langchain/chat_model.py:277— headroom/integrations/langchain/chat_model.py:277-306 | headroom/integrations/langchain/chat_model.py:858-943 | headroom/integrations/langchain/chat_model.py:952-1066 | headroom/integrations/langchain/memory.py:278-305 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) headroom/memory/adapters/embedders.py:403— headroom/memory/adapters/embedders.py:403-452 | headroom/memory/adapters/embedders.py:643-672 | headroom/memory/adapters/embedders.py:837-882 | headroom/memory/adapters/embedders.py:1070-1118 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) headroom/memory/writers/claude_writer.py:35— headroom/memory/writers/claude_writer.py:35-57 | headroom/memory/writers/codex_writer.py:25-43 | headroom/memory/writers/cursor_writer.py:35-54 | headroom/memory/writers/generic_writer.py:33-52 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) REDACTED:621— REDACTED:621-644 | headroom/providers/cohere.py:183-195 | headroom/providers/google.py:191-203 | headroom/tokenizers/mistral.py:167-215 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) headroom/proxy/handlers/gemini.py:406— headroom/proxy/handlers/gemini.py:406-1256 | headroom/proxy/handlers/gemini.py:1262-1461 | headroom/proxy/handlers/gemini.py:1483-1725 | REDACTED:3546-6200 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
Members sharing a duplicated core (4 members, 50+ identical tokens) scripts/version-sync.py:41— scripts/version-sync.py:41-47 | scripts/version-sync.py:51-57 | scripts/version-sync.py:122-133 | scripts/version-sync.py:137-148 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
D4 · Code Duplication· Edited copy of a member (17 corresponding lines) · ×8
Edited copy of a member (17 corresponding lines) headroom/copilot_linux_secret.py:38— headroom/copilot_linux_secret.py:38-54 | headroom/copilot_macos_keychain.py:59-77 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) headroom/proxy/savings_tracker.py:1644— headroom/proxy/savings_tracker.py:1644-1660 | headroom/proxy/savings_tracker.py:1663-1690 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) headroom/memory/adapters/hnsw.py:135— headroom/memory/adapters/hnsw.py:135-151 | headroom/memory/adapters/sqlite_vector.py:129-146 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) headroom/cli/wrap.py:275— headroom/cli/wrap.py:275-312 | headroom/providers/claude/vscode.py:49-65 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) headroom/cache/google.py:827— headroom/cache/google.py:827-843 | headroom/image/compressor.py:245-269 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:352— crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:352-371 | crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:559-575 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) headroom/cli/evals.py:714— headroom/cli/evals.py:714-730 | headroom/cli/evals.py:740-759 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) headroom/learn/plugins/claude.py:186— headroom/learn/plugins/claude.py:186-203 | headroom/learn/plugins/gemini.py:339-355 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (15–16 lines × 2) REDACTED:728— REDACTED:728-743 | REDACTED:768-782 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:728` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (15–16 lines × 2) headroom/evals/core.py:342— headroom/evals/core.py:342-357 | headroom/evals/runners/before_after.py:359-373 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/evals/core.py:342` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (15–16 lines × 2) headroom/learn/plugins/opencode.py:374— headroom/learn/plugins/opencode.py:374-389 | headroom/learn/plugins/opencode.py:463-477 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (15–16 lines × 2) headroom/memory/adapters/graph.py:343— headroom/memory/adapters/graph.py:343-358 | headroom/memory/adapters/graph.py:433-447 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (15–16 lines × 2) headroom/memory/bridge.py:463— headroom/memory/bridge.py:463-478 | headroom/memory/bridge.py:498-512 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (15–16 lines × 2) headroom/providers/anthropic.py:425— headroom/providers/anthropic.py:425-440 | headroom/providers/openai.py:206-220 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (15–16 lines × 2) headroom/telemetry/toin.py:803— headroom/telemetry/toin.py:803-818 | headroom/telemetry/toin.py:1092-1106 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15–16 lines × 2) crates/headroom-proxy/src/proxy.rs:1140— crates/headroom-proxy/src/proxy.rs:1140-1155 | crates/headroom-proxy/src/proxy.rs:1161-1175 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
TooManyMethods: ContentRouter headroom/transforms/content_router.py:2702— TooManyMethods — 72 methods. The bar is 30 methods; this is 42 over it, 2.40× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: MemoryHandler headroom/proxy/memory_handler.py:167— TooManyMethods — 43 methods. The bar is 30 methods; this is 13 over it, 1.43× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: SavingsTracker headroom/proxy/savings_tracker.py:973— TooManyMethods — 34 methods. The bar is 30 methods; this is 4 over it, 1.13× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: AnthropicHandlerMixin REDACTED:498— TooManyMethods — 33 methods. The bar is 30 methods; this is 3 over it, 1.10× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: OpenAIHandlerMixin REDACTED:2119— TooManyMethods — 33 methods. The bar is 30 methods; this is 3 over it, 1.10× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: TrafficLearner headroom/memory/traffic_learner.py:480— TooManyMethods — 32 methods. The bar is 30 methods; this is 2 over it, 1.07× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: PrometheusMetrics headroom/proxy/prometheus_metrics.py:126— TooManyMethods — 32 methods. The bar is 30 methods; this is 2 over it, 1.07× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
D4 · Code Duplication· Edited copy of a member (14 corresponding lines) · ×7
Edited copy of a member (14 corresponding lines) REDACTED:307— REDACTED:307-320 | headroom/providers/codex/install.py:354-369 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (14 corresponding lines) REDACTED:359— REDACTED:359-382 | REDACTED:425-438 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (14 corresponding lines) crates/headroom-proxy/src/observability/capture.rs:225— crates/headroom-proxy/src/observability/capture.rs:225-238 | crates/headroom-proxy/src/observability/capture.rs:242-255 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (14 corresponding lines) headroom/image/tile_optimizer.py:80— headroom/image/tile_optimizer.py:80-95 | headroom/image/tile_optimizer.py:149-162 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (14 corresponding lines) headroom/memory/adapters/graph.py:169— headroom/memory/adapters/graph.py:169-184 | headroom/memory/adapters/graph.py:282-295 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (14 corresponding lines) headroom/models/ml_models.py:142— headroom/models/ml_models.py:142-156 | headroom/models/ml_models.py:160-173 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (14 corresponding lines) scripts/version-sync.py:61— scripts/version-sync.py:61-74 | scripts/version-sync.py:78-96 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (12 corresponding lines) · ×7
Edited copy of a member (12 corresponding lines) headroom/mcp_registry/base.py:127— headroom/mcp_registry/base.py:127-141 | headroom/mcp_registry/opencode.py:119-130 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) crates/headroom-proxy/src/sse/openai_responses.rs:205— crates/headroom-proxy/src/sse/openai_responses.rs:205-216 | crates/headroom-proxy/src/sse/openai_responses.rs:426-442 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) crates/headroom-py/src/lib.rs:1286— crates/headroom-py/src/lib.rs:1286-1304 | crates/headroom-py/src/lib.rs:1491-1502 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) headroom/memory/adapters/graph_models.py:69— headroom/memory/adapters/graph_models.py:69-80 | headroom/memory/adapters/graph_models.py:128-139 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) headroom/providers/cohere.py:258— headroom/providers/cohere.py:258-269 | headroom/providers/google.py:293-304 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) headroom/learn/analyzer.py:144— headroom/learn/analyzer.py:144-162 | headroom/transforms/kompress_compressor.py:443-454 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (12 corresponding lines) headroom/memory/adapters/fts5.py:74— headroom/memory/adapters/fts5.py:74-85 | headroom/memory/adapters/sqlite.py:103-117 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (11 corresponding lines) · ×7
Edited copy of a member (11 corresponding lines) REDACTED:1278— REDACTED:1278-1289 | headroom/proxy/output_turn_policy.py:65-75 — These two members are one piece of code written twice and then edited apart: 11 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (11 corresponding lines) headroom/cache/openai.py:562— headroom/cache/openai.py:562-584 | headroom/evals/batch_compression_eval.py:967-977 — These two members are one piece of code written twice and then edited apart: 11 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (11 corresponding lines) crates/headroom-core/src/transforms/code_compressor.rs:1335— crates/headroom-core/src/transforms/code_compressor.rs:1335-1345 | crates/headroom-core/src/transforms/code_compressor.rs:1354-1366 — These two members are one piece of code written twice and then edited apart: 11 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (11 corresponding lines) crates/headroom-core/src/transforms/pipeline/orchestrator.rs:291— crates/headroom-core/src/transforms/pipeline/orchestrator.rs:291-301 | crates/headroom-core/src/transforms/pipeline/orchestrator.rs:306-316 — These two members are one piece of code written twice and then edited apart: 11 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (11 corresponding lines) crates/headroom-core/src/tokenizer/hf_impl.rs:83— crates/headroom-core/src/tokenizer/hf_impl.rs:83-93 | crates/headroom-core/src/tokenizer/hf_impl.rs:99-109 — These two members are one piece of code written twice and then edited apart: 11 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (11 corresponding lines) REDACTED:834— REDACTED:834-844 | REDACTED:848-859 — These two members are one piece of code written twice and then edited apart: 11 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (11 corresponding lines) crates/headroom-proxy/src/observability/proxy_metrics.rs:265— crates/headroom-proxy/src/observability/proxy_metrics.rs:265-281 | crates/headroom-proxy/src/observability/compression_ratio.rs:128-138 — These two members are one piece of code written twice and then edited apart: 11 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (4 corresponding lines) · ×7
Edited copy of a member (4 corresponding lines) headroom/audit/codex.py:157— headroom/audit/codex.py:157-160 | headroom/audit/maturation.py:170-173 — These two members are one piece of code written twice and then edited apart: 4 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (4 corresponding lines) REDACTED:567— REDACTED:567-579 | headroom/proxy/gateway_turn.py:1061-1064 — These two members are one piece of code written twice and then edited apart: 4 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (4 corresponding lines) headroom/proxy/body_forwarding.py:181— headroom/proxy/body_forwarding.py:181-190 | headroom/transforms/lossless_compaction.py:479-482 — These two members are one piece of code written twice and then edited apart: 4 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (4 corresponding lines) headroom/cli/proxy.py:120— headroom/cli/proxy.py:120-123 | REDACTED:7099-7103 — These two members are one piece of code written twice and then edited apart: 4 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (4 corresponding lines) crates/headroom-core/src/transforms/log_compressor.rs:218— crates/headroom-core/src/transforms/log_compressor.rs:218-221 | crates/headroom-core/src/transforms/search_compressor.rs:240-243 — These two members are one piece of code written twice and then edited apart: 4 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (4 corresponding lines) crates/headroom-proxy/src/bedrock/invoke.rs:100— crates/headroom-proxy/src/bedrock/invoke.rs:100-103 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:114-117 — These two members are one piece of code written twice and then edited apart: 4 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (4 corresponding lines) scripts/build_python_release_smoke.py:40— scripts/build_python_release_smoke.py:40-43 | scripts/release_smoke_all.py:36-39 — These two members are one piece of code written twice and then edited apart: 4 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (19 lines × 2) headroom/backends/litellm.py:1334— headroom/backends/litellm.py:1334-1352 | headroom/backends/litellm.py:1863-1881 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (19 lines × 2) headroom/copilot_linux_secret.py:88— headroom/copilot_linux_secret.py:88-106 | headroom/copilot_macos_keychain.py:106-124 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (19 lines × 2) headroom/memory/adapters/hnsw.py:411— headroom/memory/adapters/hnsw.py:411-429 | headroom/memory/adapters/hnsw.py:565-583 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (19 lines × 2) headroom/providers/proxy_routes.py:527— headroom/providers/proxy_routes.py:527-545 | headroom/providers/proxy_routes.py:574-592 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/providers/proxy_routes.py:527` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (19 lines × 2) REDACTED:6273— REDACTED:6273-6292 | headroom/proxy/handlers/gemini.py:434-452 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (19 lines × 2) REDACTED:1293— REDACTED:1293-1311 | REDACTED:1334-1352 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (19 lines × 2) crates/headroom-proxy/src/compression/live_zone_openai.rs:359— crates/headroom-proxy/src/compression/live_zone_openai.rs:359-377 | crates/headroom-proxy/src/compression/live_zone_responses.rs:367-385 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_openai.rs` and `crates/headroom-proxy/src/compression/live_zone_responses.rs` as WHOLE FILES: this scan already matched 14 separate duplicated blocks between them, totalling at least 278 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_openai.rs:359` it runs out through the closing brace of the declaration holding it and carries on into the declaration that follows — the window is the tail of one member plus the head of the next, so no call can be substituted for those exact lines, and the smallest declaration that contains all of them is the type they sit in. The repeated unit is the member each site sits in: where those members' bodies are the same, move one whole member to the shared location and have the others delegate to it; where the copies are a run of near-identical overloads or wrappers that differ only in their signatures, the repetition IS the run — a one-line delegation has no helper inside it to lift — so generate the run from the set it enumerates, or accept it and keep each member's own documentation with it.
Duplicated block (6 lines × 2) headroom/fsutil.py:99— headroom/fsutil.py:99-104 | headroom/install/state.py:53-58 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (6 lines × 2) headroom/providers/codex/recovery.py:282— headroom/providers/codex/recovery.py:282-287 | headroom/providers/codex/recovery.py:292-297 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (6 lines × 2) headroom/cli/wrap.py:4381— headroom/cli/wrap.py:4381-4386 | headroom/providers/copilot/wrap.py:35-40 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (6 lines × 2) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:641— crates/headroom-core/src/transforms/smart_crusher/crusher.rs:641-646 | crates/headroom-core/src/transforms/smart_crusher/crusher.rs:650-656 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/smart_crusher/crusher.rs:641` it runs out through the closing brace of the declaration holding it — the window is that declaration's tail, not a fragment that begins part-way through something, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (6 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:448— crates/headroom-proxy/src/bedrock/invoke.rs:448-453 | crates/headroom-proxy/src/vertex/raw_predict.rs:436-441 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:448` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (6 lines × 2) examples/langchain_demo/verify_errors_kept.py:25— examples/langchain_demo/verify_errors_kept.py:25-30 | examples/langchain_demo/verify_errors_kept.py:76-81 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (6 lines × 2) scripts/changelog-gen.py:140— scripts/changelog-gen.py:140-145 | scripts/changelog-gen.py:157-162 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
D4 · Code Duplication· Edited copy of a member (7 corresponding lines) · ×6
Edited copy of a member (7 corresponding lines) headroom/proxy/persistent_metrics.py:303— headroom/proxy/persistent_metrics.py:303-310 | headroom/proxy/persistent_metrics.py:316-322 — These two members are one piece of code written twice and then edited apart: 7 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (7 corresponding lines) REDACTED:319— REDACTED:319-326 | REDACTED:389-395 — These two members are one piece of code written twice and then edited apart: 7 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (7 corresponding lines) headroom/install/providers.py:33— headroom/install/providers.py:33-39 | headroom/memory/writers/base.py:192-198 — These two members are one piece of code written twice and then edited apart: 7 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (7 corresponding lines) headroom/proxy/forwarded_policy.py:50— headroom/proxy/forwarded_policy.py:50-57 | headroom/proxy/loopback_guard.py:288-294 — These two members are one piece of code written twice and then edited apart: 7 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (7 corresponding lines) headroom/cli/update.py:71— headroom/cli/update.py:71-78 | REDACTED:85-91 — These two members are one piece of code written twice and then edited apart: 7 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (7 corresponding lines) headroom/providers/codex/images.py:40— headroom/providers/codex/images.py:40-46 | headroom/providers/codex/responses.py:42-52 — These two members are one piece of code written twice and then edited apart: 7 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (9 corresponding lines) · ×6
Edited copy of a member (9 corresponding lines) crates/headroom-core/src/signals/keyword_detector.rs:165— crates/headroom-core/src/signals/keyword_detector.rs:165-173 | crates/headroom-core/src/transforms/log_compressor.rs:377-385 — These two members are one piece of code written twice and then edited apart: 9 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (9 corresponding lines) crates/headroom-core/src/rollout.rs:324— crates/headroom-core/src/rollout.rs:324-332 | crates/headroom-core/src/transforms/smart_crusher/hashing.rs:25-36 — These two members are one piece of code written twice and then edited apart: 9 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (9 corresponding lines) crates/headroom-core/src/transforms/smart_crusher/compaction/compactor.rs:436— crates/headroom-core/src/transforms/smart_crusher/compaction/compactor.rs:436-444 | crates/headroom-core/src/transforms/smart_crusher/crusher.rs:1312-1321 — These two members are one piece of code written twice and then edited apart: 9 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (9 corresponding lines) headroom/providers/anthropic.py:912— headroom/providers/anthropic.py:912-920 | headroom/providers/openai.py:644-652 — These two members are one piece of code written twice and then edited apart: 9 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (9 corresponding lines) headroom/proxy/context_guard.py:98— headroom/proxy/context_guard.py:98-106 | REDACTED:970-979 — These two members are one piece of code written twice and then edited apart: 9 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (9 corresponding lines) headroom/memory/adapters/fts5.py:326— headroom/memory/adapters/fts5.py:326-334 | headroom/memory/adapters/sqlite.py:884-902 — These two members are one piece of code written twice and then edited apart: 9 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
R4 · Test Coverage· No test reaches this file · ×6
No test reaches this file headroom/providers/opencode/hook-shim/handler.js:1— No test imports this module directly or transitively. Import reachability cannot see a test that executes a file by path instead of importing it, nor one that drives it through a running browser by navigating to a URL — if neither does, no test reaches this one.
No test reaches this file deploy/beacon/test-rollup.mjs:1— No test imports this module directly or transitively. Import reachability cannot see a test that executes a file by path instead of importing it, nor one that drives it through a running browser by navigating to a URL — if neither does, no test reaches this one.
No test reaches this file plugins/headroom-snip/hooks/register.tsx:1— No test imports this module directly or transitively. Import reachability cannot see a test that executes a file by path instead of importing it, nor one that drives it through a running browser by navigating to a URL — if neither does, no test reaches this one.
No test reaches this file plugins/openclaw/prepare-dist.mjs:1— No test imports this module directly or transitively. Import reachability cannot see a test that executes a file by path instead of importing it, nor one that drives it through a running browser by navigating to a URL — if neither does, no test reaches this one.
No test reaches this file plugins/opencode/src/hook-shim.ts:1— No test imports this module directly or transitively. Import reachability cannot see a test that executes a file by path instead of importing it, nor one that drives it through a running browser by navigating to a URL — if neither does, no test reaches this one.
No test reaches this file plugins/openclaw/hook-shim/handler.js:1— No test imports this module directly or transitively. Import reachability cannot see a test that executes a file by path instead of importing it, nor one that drives it through a running browser by navigating to a URL — if neither does, no test reaches this one.
SmartCrusher::process_value_with_hook (cognitive 77) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:497— SmartCrusher::process_value_with_hook has cognitive complexity 77 (threshold 15). Drivers by points: if/else 14 (52 pts), loops 5 (21 pts), match/switch 2 (4 pts) (nesting depth added 56). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
SmartCrusher::crush_mixed_array (cognitive 77) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:1041— SmartCrusher::crush_mixed_array has cognitive complexity 77 (threshold 15). Drivers by points: if/else 14 (56 pts), loops 5 (15 pts), match/switch 2 (6 pts) (nesting depth added 56). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
SmartCrusher::crush_array_with_source (cognitive 22) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:841— SmartCrusher::crush_array_with_source has cognitive complexity 22 (threshold 15). Drivers by points: if/else 13 (19 pts), match/switch 1 (2 pts), boolean chains 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SmartCrusher::process_string_with_hook (cognitive 20) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:733— SmartCrusher::process_string_with_hook has cognitive complexity 20 (threshold 15). Drivers by points: if/else 9 (15 pts), match/switch 2 (5 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SmartCrusher::execute_plan_tracked (cognitive 18) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:344— SmartCrusher::execute_plan_tracked has cognitive complexity 18 (threshold 15). Drivers by points: if/else 4 (11 pts), loops 2 (6 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MethodTooLong: SmartAnalyzer.analyze_crushability crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:421— MethodTooLong — analyze_crushability runs 157 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 57 over it, 1.57× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
MethodTooLong: DiffCompressor.compress_with_ccr_source crates/headroom-core/src/transforms/diff_compressor.rs:288— MethodTooLong — compress_with_ccr_source runs 156 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 56 over it, 1.56× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
MethodTooLong: Ctx.compress_function_ast crates/headroom-core/src/transforms/code_compressor.rs:1511— MethodTooLong — compress_function_ast runs 146 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 46 over it, 1.46× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
MethodTooLong: SmartCrusher.process_value_with_hook crates/headroom-core/src/transforms/smart_crusher/crusher.rs:497— MethodTooLong — process_value_with_hook runs 126 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 26 over it, 1.26× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
MethodTooLong: LogCompressor.select_lines crates/headroom-core/src/transforms/log_compressor.rs:1297— MethodTooLong — select_lines runs 114 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted) in one body. The bar is 100 significant lines; this is 14 over it, 1.14× the bar. This is length, not branching: a long straight-line body scores low on complexity and is still read whole to change any part of it, so the complexity numbers beside this row neither confirm nor excuse it. To reduce it, extract each cohesive step of the body — the runs of statements that work on the same values and would earn the same name — into its own named unit, and have this one call them in order.
D30 · Dependency Vulnerabilities· Medium vulnerability · ×5
REDACTED
REDACTED
REDACTED
REDACTED
REDACTED
D4 · Code Duplication· Edited copy of a member (13 corresponding lines) · ×5
Edited copy of a member (13 corresponding lines) crates/headroom-proxy/src/websocket.rs:223— crates/headroom-proxy/src/websocket.rs:223-235 | crates/headroom-proxy/src/websocket.rs:237-250 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (13 corresponding lines) crates/headroom-proxy/src/observability/capture.rs:183— crates/headroom-proxy/src/observability/capture.rs:183-195 | crates/headroom-proxy/src/observability/capture.rs:205-221 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (13 corresponding lines) headroom/integrations/langchain/agents.py:129— headroom/integrations/langchain/agents.py:129-154 | headroom/integrations/langchain/agents.py:185-197 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (13 corresponding lines) headroom/memory/adapters/sqlite_vector.py:309— headroom/memory/adapters/sqlite_vector.py:309-321 | headroom/memory/adapters/sqlite_vector.py:324-336 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (13 corresponding lines) headroom/memory/storage_router.py:483— headroom/memory/storage_router.py:483-495 | headroom/memory/storage_router.py:499-518 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (27 corresponding lines) · ×5
Edited copy of a member (27 corresponding lines) headroom/image/onnx_router.py:258— headroom/image/onnx_router.py:258-284 | headroom/image/trained_router.py:307-361 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) crates/headroom-core/src/transforms/text_crusher/crusher.rs:245— crates/headroom-core/src/transforms/text_crusher/crusher.rs:245-273 | crates/headroom-core/src/transforms/text_crusher/crusher.rs:276-302 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) headroom/transforms/lossless_compaction.py:243— headroom/transforms/lossless_compaction.py:243-269 | headroom/transforms/lossless_compaction.py:314-343 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) headroom/proxy/tool_schema_compaction.py:210— headroom/proxy/tool_schema_compaction.py:210-236 | headroom/proxy/tool_schema_compaction.py:334-368 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (27 corresponding lines) headroom/proxy/compression_decision.py:80— headroom/proxy/compression_decision.py:80-147 | headroom/proxy/image_compression_policy.py:43-69 — These two members are one piece of code written twice and then edited apart: 27 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (26 corresponding lines) · ×5
Edited copy of a member (26 corresponding lines) headroom/providers/codex/images.py:84— headroom/providers/codex/images.py:84-111 | headroom/providers/codex/responses.py:95-120 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) headroom/transforms/log_compressor.py:199— headroom/transforms/log_compressor.py:199-224 | headroom/transforms/search_compressor.py:172-200 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) headroom/pricing/litellm_model_resolution.py:84— headroom/pricing/litellm_model_resolution.py:84-114 | headroom/pricing/litellm_model_resolution.py:132-157 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) headroom/evals/html_oss_benchmarks.py:46— headroom/evals/html_oss_benchmarks.py:46-71 | headroom/evals/metrics.py:53-79 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (26 corresponding lines) headroom/integrations/autogen/agents.py:92— headroom/integrations/autogen/agents.py:92-120 | headroom/integrations/crewai/agents.py:175-200 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (18 corresponding lines) · ×5
Edited copy of a member (18 corresponding lines) crates/headroom-proxy/src/main.rs:220— crates/headroom-proxy/src/main.rs:220-239 | crates/headroom-simulators/src/main.rs:52-69 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) headroom/cli/wrap.py:2183— headroom/cli/wrap.py:2183-2214 | headroom/cli/wrap.py:2218-2235 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) crates/headroom-proxy/src/bedrock/invoke.rs:653— crates/headroom-proxy/src/bedrock/invoke.rs:653-671 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:860-877 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) headroom/cli/port_discovery.py:120— headroom/cli/port_discovery.py:120-137 | headroom/cli/wrap.py:5792-5814 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (18 corresponding lines) headroom/integrations/langchain/chat_model.py:397— headroom/integrations/langchain/chat_model.py:397-419 | headroom/integrations/langchain/chat_model.py:428-445 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (22 corresponding lines) · ×5
Edited copy of a member (22 corresponding lines) headroom/memory/adapters/sqlite_graph.py:181— headroom/memory/adapters/sqlite_graph.py:181-204 | headroom/memory/adapters/sqlite_graph.py:221-242 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) headroom/memory/adapters/sqlite_graph.py:781— headroom/memory/adapters/sqlite_graph.py:781-813 | headroom/memory/adapters/sqlite_vector.py:922-943 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) headroom/providers/registry.py:384— headroom/providers/registry.py:384-408 | headroom/providers/registry.py:448-469 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) headroom/memory/adapters/cache.py:105— headroom/memory/adapters/cache.py:105-132 | headroom/memory/adapters/cache.py:139-160 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (22 corresponding lines) headroom/proxy/persistent_metrics.py:166— headroom/proxy/persistent_metrics.py:166-187 | headroom/proxy/savings_tracker.py:123-147 — These two members are one piece of code written twice and then edited apart: 22 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (10 corresponding lines) · ×5
Edited copy of a member (10 corresponding lines) crates/headroom-proxy/src/proxy.rs:461— crates/headroom-proxy/src/proxy.rs:461-472 | crates/headroom-proxy/src/proxy.rs:1427-1436 — These two members are one piece of code written twice and then edited apart: 10 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (10 corresponding lines) headroom/proxy/request_limit_policy.py:18— headroom/proxy/request_limit_policy.py:18-27 | headroom/proxy/request_limit_policy.py:31-40 — These two members are one piece of code written twice and then edited apart: 10 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (10 corresponding lines) REDACTED:192— REDACTED:192-201 | REDACTED:205-216 — These two members are one piece of code written twice and then edited apart: 10 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (10 corresponding lines) headroom/proxy/beta_header_merge.py:7— headroom/proxy/beta_header_merge.py:7-16 | headroom/transforms/cache_aligner.py:207-221 — These two members are one piece of code written twice and then edited apart: 10 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (10 corresponding lines) headroom/providers/cortex_code/runtime.py:39— headroom/providers/cortex_code/runtime.py:39-48 | headroom/providers/grok/runtime.py:60-73 — These two members are one piece of code written twice and then edited apart: 10 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (6 corresponding lines) · ×5
Edited copy of a member (6 corresponding lines) crates/headroom-proxy/src/bedrock/eventstream_to_sse.rs:231— crates/headroom-proxy/src/bedrock/eventstream_to_sse.rs:231-237 | crates/headroom-proxy/src/handlers/responses.rs:182-187 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (6 corresponding lines) crates/headroom-proxy/src/cache_stabilization/beta_sticky.rs:152— crates/headroom-proxy/src/cache_stabilization/beta_sticky.rs:152-157 | crates/headroom-proxy/src/cache_stabilization/drift_detector.rs:323-328 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (6 corresponding lines) headroom/cache/backends/sqlite.py:77— headroom/cache/backends/sqlite.py:77-83 | REDACTED:177-182 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (6 corresponding lines) headroom/memory/tracker.py:199— headroom/memory/tracker.py:199-211 | headroom/models/ml_models.py:93-98 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (6 corresponding lines) REDACTED:581— REDACTED:581-586 | examples/vertex_genai_sdk_demo.py:204-209 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (18 lines × 2) headroom/cli/wrap.py:7898— headroom/cli/wrap.py:7898-7915 | headroom/cli/wrap.py:8165-8182 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/cli/wrap.py:7898` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (18 lines × 2) headroom/cli/wrap.py:9379— headroom/cli/wrap.py:9379-9396 | headroom/cli/wrap.py:9436-9453 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (18 lines × 2) headroom/providers/opencode/config.py:130— headroom/providers/opencode/config.py:130-147 | headroom/providers/opencode/config.py:167-184 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (18 lines × 2) REDACTED:9235— REDACTED:9235-9252 | REDACTED:9760-9777 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (18 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:260— crates/headroom-proxy/src/bedrock/invoke.rs:260-277 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:227-244 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:260` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12 lines × 3) headroom/cache/__init__.py:134— headroom/cache/__init__.py:134-145 | headroom/models/__init__.py:48-59 | headroom/providers/__init__.py:112-123 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (12 lines × 3) headroom/evals/runners/compression_only.py:155— headroom/evals/runners/compression_only.py:155-166 | headroom/evals/runners/compression_only.py:235-246 | headroom/evals/runners/compression_only.py:320-331 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/evals/runners/compression_only.py:155` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12 lines × 3) headroom/memory/adapters/graph.py:368— headroom/memory/adapters/graph.py:368-379 | headroom/memory/adapters/graph.py:450-461 | headroom/memory/adapters/sqlite_graph.py:545-556 — before extracting anything, compare `headroom/memory/adapters/graph.py` and `headroom/memory/adapters/sqlite_graph.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 41 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (12 lines × 3) headroom/storage/sqlite.py:241— headroom/storage/sqlite.py:241-252 | headroom/storage/sqlite.py:278-289 | headroom/storage/sqlite.py:316-327 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (12 lines × 3) crates/headroom-proxy/src/compression/live_zone_anthropic.rs:615— crates/headroom-proxy/src/compression/live_zone_anthropic.rs:615-626 | crates/headroom-proxy/src/compression/live_zone_openai.rs:346-357 | crates/headroom-proxy/src/compression/live_zone_responses.rs:354-365 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_anthropic.rs` and `crates/headroom-proxy/src/compression/live_zone_openai.rs` as WHOLE FILES: this scan already matched 6 separate duplicated blocks between them, totalling at least 113 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_anthropic.rs:615` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 3) headroom/evals/batch_compression_eval.py:1144— headroom/evals/batch_compression_eval.py:1144-1153 | headroom/evals/core.py:325-334 | headroom/evals/runners/before_after.py:342-351 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/evals/batch_compression_eval.py:1155` calls `compute_rouge_l` and `headroom/evals/core.py:337` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (10 lines × 3) headroom/evals/runners/compression_only.py:150— headroom/evals/runners/compression_only.py:150-159 | headroom/evals/runners/compression_only.py:230-239 | headroom/evals/runners/compression_only.py:653-662 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/evals/runners/compression_only.py:150` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (10 lines × 3) crates/headroom-core/src/transforms/diff_compressor.rs:1449— crates/headroom-core/src/transforms/diff_compressor.rs:1449-1458 | crates/headroom-core/src/transforms/log_compressor.rs:1685-1694 | crates/headroom-core/src/transforms/search_compressor.rs:990-999 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from all 3 call sites, so a change lands once. Each matched range is the entire body of the declaration above it, so the region is already a complete unit: move that whole declaration to the shared location and have each site call it, rather than lifting the lines out of their bodies. Any `return` inside it is the body's own exit and keeps its meaning in the moved unit.
Duplicated block (10 lines × 3) crates/headroom-proxy/src/sse/openai_responses.rs:319— crates/headroom-proxy/src/sse/openai_responses.rs:319-328 | crates/headroom-proxy/src/sse/openai_responses.rs:352-361 | crates/headroom-proxy/src/sse/openai_responses.rs:389-398 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (10 lines × 3) crates/headroom-proxy/src/compression/live_zone_anthropic.rs:581— crates/headroom-proxy/src/compression/live_zone_anthropic.rs:581-590 | crates/headroom-proxy/src/compression/live_zone_openai.rs:319-328 | crates/headroom-proxy/src/compression/live_zone_responses.rs:327-336 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_anthropic.rs` and `crates/headroom-proxy/src/compression/live_zone_openai.rs` as WHOLE FILES: this scan already matched 6 separate duplicated blocks between them, totalling at least 113 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (8 lines × 3) headroom/integrations/langchain/chat_model.py:280— headroom/integrations/langchain/chat_model.py:280-287 | headroom/integrations/langchain/chat_model.py:1027-1034 | headroom/integrations/langchain/memory.py:288-295 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart.
Duplicated block (8 lines × 3) REDACTED:637— REDACTED:637-644 | headroom/providers/cohere.py:188-195 | headroom/providers/google.py:196-203 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (8 lines × 3) crates/headroom-core/src/transforms/live_zone.rs:1371— crates/headroom-core/src/transforms/live_zone.rs:1371-1379 | crates/headroom-core/src/transforms/live_zone.rs:2440-2447 | crates/headroom-core/src/transforms/live_zone.rs:2954-2961 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/live_zone.rs:1371` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 3) crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:802— crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:802-809 | crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:811-818 | crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:828-835 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (8 lines × 3) REDACTED:141— REDACTED:141-148 | examples/vertex_gemini_benchmark/benchmark.py:155-162 | examples/vertex_genai_sdk_demo.py:111-118 — before extracting anything, compare `REDACTED` and `examples/vertex_genai_sdk_demo.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 33 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (7 lines × 3) headroom/integrations/langchain/chat_model.py:237— headroom/integrations/langchain/chat_model.py:237-243 | headroom/integrations/langchain/chat_model.py:871-877 | headroom/integrations/langchain/chat_model.py:984-990 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (7 lines × 3) headroom/memory/adapters/graph.py:235— headroom/memory/adapters/graph.py:235-241 | headroom/memory/adapters/graph.py:346-352 | headroom/memory/adapters/graph.py:436-442 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (7 lines × 3) crates/headroom-core/src/transforms/live_zone.rs:1367— crates/headroom-core/src/transforms/live_zone.rs:1367-1373 | crates/headroom-core/src/transforms/live_zone.rs:2384-2390 | crates/headroom-core/src/transforms/live_zone.rs:2436-2442 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (7 lines × 3) crates/headroom-core/src/transforms/live_zone.rs:1448— crates/headroom-core/src/transforms/live_zone.rs:1448-1454 | crates/headroom-core/src/transforms/live_zone.rs:2474-2480 | crates/headroom-core/src/transforms/live_zone.rs:3000-3006 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (7 lines × 3) crates/headroom-proxy/src/bedrock/invoke_streaming.rs:793— crates/headroom-proxy/src/bedrock/invoke_streaming.rs:793-799 | crates/headroom-proxy/src/proxy.rs:1625-1631 | crates/headroom-proxy/src/vertex/raw_predict.rs:521-527 — before extracting anything, compare `crates/headroom-proxy/src/proxy.rs` and `crates/headroom-proxy/src/vertex/raw_predict.rs` as WHOLE FILES: this scan already matched 5 separate duplicated blocks between them, totalling at least 53 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke_streaming.rs:793` it runs out through the closing brace of the declaration holding it — the window is that declaration's tail, not a fragment that begins part-way through something, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2 locations) plugins/openclaw/src/proxy-manager.ts:347— plugins/openclaw/src/proxy-manager.ts:347 · plugins/openclaw/src/proxy-manager.ts:389 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
Duplicated block (8 lines × 2 locations) sdk/typescript/src/client.ts:301— sdk/typescript/src/client.ts:301 · sdk/typescript/src/client.ts:333 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
Duplicated block (8 lines × 2 locations) sdk/typescript/src/client.ts:474— sdk/typescript/src/client.ts:474 · sdk/typescript/src/client.ts:501 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
Duplicated block (8 lines × 2 locations) sdk/typescript/src/shared-context.ts:114— sdk/typescript/src/shared-context.ts:114 · sdk/typescript/src/shared-context.ts:129 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
Duplicated block (8 lines × 2 locations) sdk/typescript/src/utils/format.ts:194— sdk/typescript/src/utils/format.ts:194 · sdk/typescript/src/utils/format.ts:241 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
SmartAnalyzer::analyze_crushability (cognitive 55) crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:421— SmartAnalyzer::analyze_crushability has cognitive complexity 55 (threshold 15). Drivers by points: if/else 26 (41 pts), boolean chains 9, loops 4 (5 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SmartAnalyzer::analyze_field (cognitive 20) crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:132— SmartAnalyzer::analyze_field has cognitive complexity 20 (threshold 15). Drivers by points: if/else 11 (17 pts), match/switch 2, boolean chains 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SmartAnalyzer::detect_temporal_field (cognitive 18) crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:370— SmartAnalyzer::detect_temporal_field has cognitive complexity 18 (threshold 15). Drivers by points: if/else 4 (13 pts), boolean chains 2, match/switch 1 (2 pts), loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SmartAnalyzer::detect_pattern (cognitive 16) crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:322— SmartAnalyzer::detect_pattern has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (9 pts), boolean chains 5, loops 2 (nesting depth added 3). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
D30 · Dependency Vulnerabilities· Medium advisory (unsound) · ×4
REDACTED
REDACTED
REDACTED
REDACTED
D4 · Code Duplication· Edited copy of a member (32 corresponding lines) · ×4
Edited copy of a member (32 corresponding lines) crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:172— crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:172-208 | crates/headroom-proxy/src/cache_stabilization/volatile_detector.rs:212-243 — These two members are one piece of code written twice and then edited apart: 32 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (32 corresponding lines) headroom/memory/__init__.py:159— headroom/memory/__init__.py:159-190 | headroom/memory/backends/__init__.py:31-69 — These two members are one piece of code written twice and then edited apart: 32 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (32 corresponding lines) headroom/proxy/loopback_guard.py:187— headroom/proxy/loopback_guard.py:187-229 | headroom/proxy/loopback_guard.py:317-348 — These two members are one piece of code written twice and then edited apart: 32 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (32 corresponding lines) headroom/evals/memory/runner.py:764— headroom/evals/memory/runner.py:764-796 | headroom/evals/memory/runner_v2.py:997-1028 — These two members are one piece of code written twice and then edited apart: 32 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (19 corresponding lines) · ×4
Edited copy of a member (19 corresponding lines) headroom/proxy/ccr_session_tracker.py:63— headroom/proxy/ccr_session_tracker.py:63-81 | headroom/proxy/tool_injection_tracker.py:66-87 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) crates/headroom-core/src/cache_control.rs:192— crates/headroom-core/src/cache_control.rs:192-213 | crates/headroom-core/src/cache_control.rs:218-236 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) crates/headroom-core/src/signals/keyword_detector.rs:143— crates/headroom-core/src/signals/keyword_detector.rs:143-161 | crates/headroom-core/src/transforms/log_compressor.rs:335-375 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) headroom/memory/adapters/sqlite.py:340— headroom/memory/adapters/sqlite.py:340-358 | headroom/memory/adapters/sqlite_graph.py:295-314 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (5 corresponding lines) · ×4
Edited copy of a member (5 corresponding lines) REDACTED:292— REDACTED:292-298 | REDACTED:1091-1095 — These two members are one piece of code written twice and then edited apart: 5 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (5 corresponding lines) headroom/proxy/helpers.py:2325— headroom/proxy/helpers.py:2325-2335 | headroom/proxy/tool_injection_tracker.py:13-17 — These two members are one piece of code written twice and then edited apart: 5 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (5 corresponding lines) headroom/memory/adapters/sqlite_graph.py:738— headroom/memory/adapters/sqlite_graph.py:738-743 | headroom/memory/adapters/sqlite_vector.py:406-410 — These two members are one piece of code written twice and then edited apart: 5 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (5 corresponding lines) headroom/capture/network_diff.py:224— headroom/capture/network_diff.py:224-228 | headroom/providers/codex/project_context.py:148-152 — These two members are one piece of code written twice and then edited apart: 5 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (26 lines × 2) headroom/integrations/langchain/chat_model.py:280— headroom/integrations/langchain/chat_model.py:280-305 | headroom/integrations/langchain/chat_model.py:1027-1052 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (26 lines × 2) headroom/memory/adapters/embedders.py:837— headroom/memory/adapters/embedders.py:837-862 | headroom/memory/adapters/embedders.py:1070-1096 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/memory/adapters/embedders.py:837` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (26 lines × 2) REDACTED:5862— REDACTED:5862-5887 | REDACTED:7697-7722 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (26 lines × 2) headroom/proxy/savings_tracker.py:2494— headroom/proxy/savings_tracker.py:2494-2519 | headroom/proxy/savings_tracker.py:2527-2552 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/proxy/savings_tracker.py:2526` calls `_normalize_agent`, `get` and `headroom/proxy/savings_tracker.py:2554` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (24 lines × 2) headroom/integrations/strands/model.py:384— headroom/integrations/strands/model.py:384-410 | headroom/integrations/strands/model.py:447-470 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (24 lines × 2) headroom/memory/wrapper_tools.py:235— headroom/memory/wrapper_tools.py:235-258 | headroom/memory/wrapper_tools.py:466-489 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/memory/wrapper_tools.py:235` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (24 lines × 2) headroom/transforms/kompress_compressor.py:2087— headroom/transforms/kompress_compressor.py:2087-2110 | headroom/transforms/kompress_compressor.py:2517-2540 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/transforms/kompress_compressor.py:2087` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (24 lines × 2) examples/strands_bedrock_demo.py:666— examples/strands_bedrock_demo.py:666-689 | examples/strands_bedrock_demo.py:835-858 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (20 lines × 2) REDACTED:4645— REDACTED:4645-4664 | REDACTED:6670-6689 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (20 lines × 2) REDACTED:12474— REDACTED:12474-12493 | REDACTED:12687-12706 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:12474` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (20 lines × 2) headroom/proxy/memory_handler.py:1867— headroom/proxy/memory_handler.py:1867-1886 | headroom/proxy/memory_handler.py:2059-2078 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (20 lines × 2) crates/headroom-proxy/src/compression/live_zone_openai.rs:379— crates/headroom-proxy/src/compression/live_zone_openai.rs:379-398 | crates/headroom-proxy/src/compression/live_zone_responses.rs:387-406 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_openai.rs` and `crates/headroom-proxy/src/compression/live_zone_responses.rs` as WHOLE FILES: this scan already matched 14 separate duplicated blocks between them, totalling at least 278 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_openai.rs:379` it runs out through the closing brace of the declaration holding it and carries on into the declaration that follows — the window is the tail of one member plus the head of the next, so no call can be substituted for those exact lines, and the smallest declaration that contains all of them is the type they sit in. The repeated unit is the member each site sits in: where those members' bodies are the same, move one whole member to the shared location and have the others delegate to it; where the copies are a run of near-identical overloads or wrappers that differ only in their signatures, the repetition IS the run — a one-line delegation has no helper inside it to lift — so generate the run from the set it enumerates, or accept it and keep each member's own documentation with it.
Duplicated block (10–13 lines × 2) headroom/integrations/langchain/agents.py:142— headroom/integrations/langchain/agents.py:142-154 | headroom/integrations/langchain/agents.py:188-197 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (10–13 lines × 2) headroom/integrations/langchain/chat_model.py:924— headroom/integrations/langchain/chat_model.py:924-933 | headroom/integrations/langchain/chat_model.py:1022-1034 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/integrations/langchain/chat_model.py:1022` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10–13 lines × 2) REDACTED:5248— REDACTED:5248-5260 | REDACTED:5803-5812 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:5248` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `REDACTED:5815` calls `pop` and `REDACTED:5262` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (10–13 lines × 2) crates/headroom-proxy/src/proxy.rs:1176— crates/headroom-proxy/src/proxy.rs:1176-1188 | crates/headroom-proxy/src/vertex/raw_predict.rs:363-372 — before extracting anything, compare `crates/headroom-proxy/src/proxy.rs` and `crates/headroom-proxy/src/vertex/raw_predict.rs` as WHOLE FILES: this scan already matched 5 separate duplicated blocks between them, totalling at least 53 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/proxy.rs:1176` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `crates/headroom-proxy/src/vertex/raw_predict.rs:373` calls `filter_response_headers`, `headers` and `crates/headroom-proxy/src/proxy.rs:1197` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (11–12 lines × 2) headroom/cache/google.py:830— headroom/cache/google.py:830-840 | headroom/image/compressor.py:254-265 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11–12 lines × 2) headroom/cli/wrap.py:8813— headroom/cli/wrap.py:8813-8823 | headroom/cli/wrap.py:8833-8844 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (11–12 lines × 2) headroom/learn/plugins/claude.py:313— headroom/learn/plugins/claude.py:313-323 | headroom/learn/plugins/claude.py:337-348 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (11–12 lines × 2) REDACTED:108— REDACTED:108-119 | examples/vertex_genai_sdk_demo.py:79-89 — before extracting anything, compare `REDACTED` and `examples/vertex_genai_sdk_demo.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 33 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:108` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (10 lines × 2 locations) headroom/providers/opencode/hook-shim/handler.js:133— headroom/providers/opencode/hook-shim/handler.js:133 · headroom/providers/opencode/hook-shim/handler.js:143 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2 locations) sdk/typescript/src/utils/format.ts:279— sdk/typescript/src/utils/format.ts:279 · sdk/typescript/src/utils/format.ts:998 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
Duplicated block (10 lines × 2 locations) sdk/typescript/src/utils/format.ts:307— sdk/typescript/src/utils/format.ts:307 · sdk/typescript/src/utils/format.ts:692 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
Duplicated block (10 lines × 2 locations) sdk/typescript/src/utils/format.ts:543— sdk/typescript/src/utils/format.ts:543 · sdk/typescript/src/utils/format.ts:570 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
Duplicated block (7 lines × 2 locations) plugins/openclaw/src/convert.ts:475— plugins/openclaw/src/convert.ts:475 · plugins/openclaw/src/convert.ts:518 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
Duplicated block (7 lines × 2 locations) plugins/openclaw/src/tools/headroom-retrieve.ts:63— plugins/openclaw/src/tools/headroom-retrieve.ts:63 · plugins/opencode/src/retrieve.ts:58 — the 2 copies are spread across 2 directories, so the shared home is a decision rather than an obvious spot: check first whether one of them already owns this behaviour, and otherwise put the extracted module somewhere all of the sites already reach rather than making one of them depend on another.
Duplicated block (7 lines × 2 locations) sdk/typescript/src/utils/format.ts:205— sdk/typescript/src/utils/format.ts:205 · sdk/typescript/src/utils/format.ts:255 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (7 lines × 2 locations) sdk/typescript/src/utils/format.ts:261— sdk/typescript/src/utils/format.ts:261 · sdk/typescript/src/utils/format.ts:974 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
AC3 · Page structure· Page without a main landmark · ×3
Page without a main landmark crates/headroom-proxy/src/observability/dashboard.html:2— No <main> (or role="main") means no "skip to content" target and a weaker landmark map. Wrap the primary content in <main>.
Page without a main landmark docs/app/layout.tsx:50— No <main> (or role="main") means no "skip to content" target and a weaker landmark map. Wrap the primary content in <main>.
Page without a main landmark headroom/dashboard/templates/settings.html:2— No <main> (or role="main") means no "skip to content" target and a weaker landmark map. Wrap the primary content in <main>.
Ctx::compress_function_ast (cyclomatic 42) crates/headroom-core/src/transforms/code_compressor.rs:1511— Ctx::compress_function_ast has cyclomatic complexity 42 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Ctx::visit (cyclomatic 21) crates/headroom-core/src/transforms/code_compressor.rs:1401— Ctx::visit has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Ctx::compress_class_ast (cyclomatic 18) crates/headroom-core/src/transforms/code_compressor.rs:1729— Ctx::compress_class_ast has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Ctx::compress_function_ast (cognitive 63) crates/headroom-core/src/transforms/code_compressor.rs:1511— Ctx::compress_function_ast has cognitive complexity 63 (threshold 15). Drivers by points: if/else 32 (50 pts), boolean chains 7, loops 3, match/switch 1 (3 pts) (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Ctx::visit (cognitive 32) crates/headroom-core/src/transforms/code_compressor.rs:1401— Ctx::visit has cognitive complexity 32 (threshold 15). Drivers by points: if/else 15 (24 pts), loops 3 (5 pts), match/switch 1 (2 pts), boolean chains 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Ctx::compress_class_ast (cognitive 27) crates/headroom-core/src/transforms/code_compressor.rs:1729— Ctx::compress_class_ast has cognitive complexity 27 (threshold 15). Drivers by points: if/else 13 (19 pts), loops 3 (5 pts), match/switch 1 (3 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LogCompressor::select_lines (cognitive 51) crates/headroom-core/src/transforms/log_compressor.rs:1297— LogCompressor::select_lines has cognitive complexity 51 (threshold 15). Drivers by points: if/else 17 (27 pts), loops 12 (19 pts), boolean chains 3, match/switch 1 (2 pts) (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LogCompressor::format_output (cognitive 24) crates/headroom-core/src/transforms/log_compressor.rs:1523— LogCompressor::format_output has cognitive complexity 24 (threshold 15). Drivers by points: if/else 9 (17 pts), loops 2 (4 pts), match/switch 1 (3 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LogCompressor::parse_lines (cognitive 16) crates/headroom-core/src/transforms/log_compressor.rs:1236— LogCompressor::parse_lines has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (12 pts), boolean chains 3, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SearchCompressor::score_matches (cognitive 29) crates/headroom-core/src/transforms/search_compressor.rs:442— SearchCompressor::score_matches has cognitive complexity 29 (threshold 15). Drivers by points: if/else 4 (15 pts), loops 4 (9 pts), match/switch 1 (5 pts) (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SearchCompressor::format_output (cognitive 23) crates/headroom-core/src/transforms/search_compressor.rs:608— SearchCompressor::format_output has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (16 pts), loops 3 (7 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SearchCompressor::select_matches (cognitive 17) crates/headroom-core/src/transforms/search_compressor.rs:497— SearchCompressor::select_matches has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (12 pts), loops 2 (3 pts), boolean chains 2 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
D4 · Code Duplication· Edited copy of a member (40 corresponding lines) · ×3
Edited copy of a member (40 corresponding lines) headroom/providers/openai.py:406— headroom/providers/openai.py:406-458 | headroom/providers/openai_compatible.py:152-191 — These two members are one piece of code written twice and then edited apart: 40 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (40 corresponding lines) crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:215— crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:215-254 | crates/headroom-core/src/transforms/smart_crusher/compaction/formatter.rs:453-492 — These two members are one piece of code written twice and then edited apart: 40 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (40 corresponding lines) headroom/cli/wrap.py:8387— headroom/cli/wrap.py:8387-8426 | headroom/cli/wrap.py:8530-8574 — These two members are one piece of code written twice and then edited apart: 40 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (34 corresponding lines) · ×3
Edited copy of a member (34 corresponding lines) headroom/memory/adapters/hnsw.py:696— headroom/memory/adapters/hnsw.py:696-754 | headroom/memory/adapters/sqlite_vector.py:793-826 — These two members are one piece of code written twice and then edited apart: 34 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (34 corresponding lines) headroom/providers/copilot/vscode.py:68— headroom/providers/copilot/vscode.py:68-108 | headroom/providers/opencode/config.py:130-163 — These two members are one piece of code written twice and then edited apart: 34 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (34 corresponding lines) headroom/memory/adapters/hnsw.py:517— headroom/memory/adapters/hnsw.py:517-550 | headroom/memory/adapters/hnsw.py:553-588 — These two members are one piece of code written twice and then edited apart: 34 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (31 corresponding lines) · ×3
Edited copy of a member (31 corresponding lines) REDACTED:2174— REDACTED:2174-2204 | REDACTED:2259-2317 — These two members are one piece of code written twice and then edited apart: 31 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (31 corresponding lines) headroom/proxy/memory_handler.py:1867— headroom/proxy/memory_handler.py:1867-1901 | headroom/proxy/memory_handler.py:1973-2003 — These two members are one piece of code written twice and then edited apart: 31 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (31 corresponding lines) headroom/cli/wrap.py:8210— headroom/cli/wrap.py:8210-8241 | headroom/cli/wrap.py:8265-8295 — These two members are one piece of code written twice and then edited apart: 31 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (42 corresponding lines) · ×3
Edited copy of a member (42 corresponding lines) headroom/models/ml_models.py:229— headroom/models/ml_models.py:229-270 | headroom/models/ml_models.py:313-366 — These two members are one piece of code written twice and then edited apart: 42 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (42 corresponding lines) headroom/memory/adapters/embedders.py:774— headroom/memory/adapters/embedders.py:774-815 | headroom/memory/adapters/embedders.py:996-1048 — These two members are one piece of code written twice and then edited apart: 42 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (42 corresponding lines) headroom/providers/cohere.py:326— headroom/providers/cohere.py:326-367 | headroom/providers/google.py:333-381 — These two members are one piece of code written twice and then edited apart: 42 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (16 corresponding lines) · ×3
Edited copy of a member (16 corresponding lines) headroom/proxy/gateway_turn.py:328— headroom/proxy/gateway_turn.py:328-343 | headroom/proxy/gateway_turn.py:346-362 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (16 corresponding lines) headroom/proxy/beta_header_policy.py:29— headroom/proxy/beta_header_policy.py:29-44 | headroom/proxy/tool_injection_policy.py:56-71 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (16 corresponding lines) REDACTED:91— REDACTED:91-119 | examples/vertex_genai_sdk_demo.py:74-89 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (8 corresponding lines) · ×3
Edited copy of a member (8 corresponding lines) docker/differential-network-capture/mitm_capture.py:45— docker/differential-network-capture/mitm_capture.py:45-52 | headroom/capture/network_diff.py:97-105 — These two members are one piece of code written twice and then edited apart: 8 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (8 corresponding lines) REDACTED:510— REDACTED:510-520 | REDACTED:524-531 — These two members are one piece of code written twice and then edited apart: 8 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (8 corresponding lines) crates/headroom-simulators/src/domain.rs:322— crates/headroom-simulators/src/domain.rs:322-332 | crates/headroom-simulators/src/domain.rs:353-360 — These two members are one piece of code written twice and then edited apart: 8 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (24 corresponding lines) · ×3
Edited copy of a member (24 corresponding lines) headroom/models/ml_models.py:185— headroom/models/ml_models.py:185-217 | headroom/models/ml_models.py:278-301 — These two members are one piece of code written twice and then edited apart: 24 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (24 corresponding lines) headroom/providers/google.py:102— headroom/providers/google.py:102-126 | headroom/providers/cohere.py:102-125 — These two members are one piece of code written twice and then edited apart: 24 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (24 corresponding lines) headroom/memory/adapters/sqlite.py:273— headroom/memory/adapters/sqlite.py:273-303 | headroom/memory/adapters/sqlite_graph.py:364-387 — These two members are one piece of code written twice and then edited apart: 24 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (27 lines × 2) headroom/evals/memory/runner.py:611— headroom/evals/memory/runner.py:611-637 | headroom/evals/memory/runner_v2.py:913-939 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/evals/memory/runner.py:611` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note first that the copies are not typed on the same thing: the declarations holding them bind `results` to `list[MemoryEvalResult]` in one and `list[MemoryEvalResultV2]` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (27 lines × 2) REDACTED:6453— REDACTED:6453-6479 | headroom/proxy/handlers/batch.py:206-232 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:6453` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (27 lines × 2) REDACTED:6126— REDACTED:6126-6152 | REDACTED:6459-6485 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (19–23 lines × 2) headroom/proxy/helpers.py:3457— headroom/proxy/helpers.py:3457-3479 | headroom/proxy/helpers.py:3503-3521 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (19–23 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:505— crates/headroom-proxy/src/bedrock/invoke.rs:505-527 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:898-916 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:505` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (19–23 lines × 2) examples/anthropic_create_stream_local.py:92— examples/anthropic_create_stream_local.py:92-110 | examples/cache_optimizer_config_local.py:45-67 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (21 lines × 2) headroom/learn/plugins/opencode.py:398— headroom/learn/plugins/opencode.py:398-418 | headroom/learn/plugins/opencode.py:482-502 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (21 lines × 2) REDACTED:2112— REDACTED:2112-2132 | REDACTED:4079-4099 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (21 lines × 2) REDACTED:6815— REDACTED:6815-6835 | REDACTED:8866-8886 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:6815` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (17–20 lines × 2) headroom/cli/wrap.py:1613— headroom/cli/wrap.py:1613-1632 | headroom/proxy/output_savings.py:418-434 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (17–20 lines × 2) REDACTED:9190— REDACTED:9190-9206 | REDACTED:9703-9722 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:9190` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (17–20 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:182— crates/headroom-proxy/src/bedrock/invoke.rs:182-201 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:157-173 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:182` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (18–19 lines × 2) headroom/cli/wrap.py:8871— headroom/cli/wrap.py:8871-8889 | headroom/cli/wrap.py:9323-9340 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (18–19 lines × 2) headroom/proxy/handlers/gemini.py:1266— headroom/proxy/handlers/gemini.py:1266-1283 | headroom/proxy/handlers/gemini.py:1493-1511 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (18–19 lines × 2) headroom/subscription/copilot_quota.py:280— headroom/subscription/copilot_quota.py:280-297 | headroom/subscription/tracker.py:371-389 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (13 lines × 3) REDACTED:1358— REDACTED:1358-1374 | REDACTED:3573-3585 | REDACTED:6233-6245 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `REDACTED:1352` calls `uuid4` and `REDACTED:3567` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (13 lines × 3) crates/headroom-proxy/src/compression/live_zone_anthropic.rs:664— crates/headroom-proxy/src/compression/live_zone_anthropic.rs:664-676 | crates/headroom-proxy/src/compression/live_zone_openai.rs:387-399 | crates/headroom-proxy/src/compression/live_zone_responses.rs:395-407 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_anthropic.rs` and `crates/headroom-proxy/src/compression/live_zone_openai.rs` as WHOLE FILES: this scan already matched 6 separate duplicated blocks between them, totalling at least 113 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_anthropic.rs:664` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `crates/headroom-proxy/src/compression/live_zone_openai.rs:386` calls `clone` and `crates/headroom-proxy/src/compression/live_zone_anthropic.rs:662` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (13 lines × 3) REDACTED:123— REDACTED:123-135 | examples/vertex_gemini_benchmark/benchmark.py:137-149 | examples/vertex_genai_sdk_demo.py:93-105 — before extracting anything, compare `REDACTED` and `examples/vertex_genai_sdk_demo.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 33 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:123` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note first that the copies are not typed on the same thing: the declarations holding them bind `timeout_s` to `float = 30.0` in one and `float = 35.0` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (12–13 lines × 2) headroom/evals/html_oss_benchmarks.py:165— headroom/evals/html_oss_benchmarks.py:165-176 | headroom/evals/html_oss_benchmarks.py:303-315 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12–13 lines × 2) REDACTED:1025— REDACTED:1025-1036 | headroom/memory/backends/mem0_system_adapter.py:379-391 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12–13 lines × 2) headroom/proxy/gateway_turn.py:328— headroom/proxy/gateway_turn.py:328-339 | headroom/proxy/gateway_turn.py:346-358 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/proxy/gateway_turn.py:328` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10–12 lines × 2) headroom/cli/memory.py:142— headroom/cli/memory.py:142-151 | headroom/cli/memory.py:1262-1273 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/cli/memory.py:1262` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `headroom/cli/memory.py:1259` calls `execute`, `fetchall` and `headroom/cli/memory.py:141` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (10–12 lines × 2) headroom/proxy/handlers/gemini.py:627— headroom/proxy/handlers/gemini.py:627-636 | headroom/proxy/handlers/gemini.py:963-974 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10–12 lines × 2) headroom/proxy/savings_tracker.py:189— headroom/proxy/savings_tracker.py:189-200 | headroom/subscription/models.py:34-43 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Outbound HTTP without resilience headroom/ccr/batch_store.py:83— `requests.get(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout.
Outbound HTTP without resilience REDACTED:625— `urllib.request.urlopen(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout.
Outbound HTTP without resilience REDACTED:633— `urllib.request.urlopen(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout.
SmartAnalyzer::analyze_crushability (cyclomatic 36) crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:421— SmartAnalyzer::analyze_crushability has cyclomatic complexity 36 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SmartAnalyzer::analyze_field (cyclomatic 16) crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:132— SmartAnalyzer::analyze_field has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SmartCrusher::process_value_with_hook (cyclomatic 25) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:497— SmartCrusher::process_value_with_hook has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SmartCrusher::crush_mixed_array (cyclomatic 23) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:1041— SmartCrusher::crush_mixed_array has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SmartCrusherPlanner::plan_top_n (cognitive 26) crates/headroom-core/src/transforms/smart_crusher/planning.rs:242— SmartCrusherPlanner::plan_top_n has cognitive complexity 26 (threshold 15). Drivers by points: if/else 7 (15 pts), loops 4 (6 pts), boolean chains 3, match/switch 1 (2 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SmartCrusherPlanner::plan_smart_sample (cognitive 17) crates/headroom-core/src/transforms/smart_crusher/planning.rs:169— SmartCrusherPlanner::plan_smart_sample has cognitive complexity 17 (threshold 15). Drivers by points: loops 4 (10 pts), if/else 2 (6 pts), boolean chains 1 (nesting depth added 10). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
LogTemplate::flush_run (cognitive 19) crates/headroom-core/src/transforms/pipeline/reformats/log_template.rs:221— LogTemplate::flush_run has cognitive complexity 19 (threshold 15). Drivers by points: if/else 4 (10 pts), loops 4 (6 pts), match/switch 1 (2 pts), boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LogTemplate::apply (cognitive 17) crates/headroom-core/src/transforms/pipeline/reformats/log_template.rs:103— LogTemplate::apply has cognitive complexity 17 (threshold 15). Drivers by points: if/else 9 (14 pts), match/switch 1 (2 pts), loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChunkState::apply (cognitive 17) crates/headroom-proxy/src/sse/openai_chat.rs:89— ChunkState::apply has cognitive complexity 17 (threshold 15). Drivers by points: if/else 11 (15 pts), loops 1 (2 pts) (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ChunkState::apply_choice (cognitive 17) crates/headroom-proxy/src/sse/openai_chat.rs:143— ChunkState::apply_choice has cognitive complexity 17 (threshold 15). Drivers by points: if/else 8 (14 pts), loops 1 (3 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ClassTooLong: SmartCrusher crates/headroom-core/src/transforms/smart_crusher/crusher.rs:121— ClassTooLong — 555 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted), 21 methods, 2 blocks, lines 121-1203. The bar is 400 significant lines; this is 155 over it, 1.39× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
ClassTooLong: SmartAnalyzer crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:48— ClassTooLong — 432 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted), 9 methods, 2 blocks, lines 48-731. The bar is 400 significant lines; this is 32 over it, 1.08× the bar. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
D30 · Dependency Vulnerabilities· Medium advisory (unmaintained) · ×2
REDACTED
REDACTED
D4 · Code Duplication· Members sharing a duplicated core (5 members, 50+ identical tokens) · ×2
Members sharing a duplicated core (5 members, 50+ identical tokens) headroom/backends/anyllm.py:230— headroom/backends/anyllm.py:230-277 | headroom/backends/anyllm.py:284-478 | headroom/backends/litellm.py:1273-1395 | headroom/backends/litellm.py:1402-1810 | REDACTED:1267-2196 — These 5 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 5 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 5 times.
Members sharing a duplicated core (5 members, 50+ identical tokens) headroom/proxy/handlers/batch.py:38— headroom/proxy/handlers/batch.py:38-407 | headroom/proxy/handlers/batch.py:534-618 | headroom/proxy/handlers/batch.py:684-832 | headroom/proxy/handlers/batch.py:835-1088 | headroom/proxy/handlers/gemini.py:1483-1725 — These 5 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 5 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 5 times.
D4 · Code Duplication· Edited copy of a member (97 corresponding lines) · ×2
Edited copy of a member (97 corresponding lines) headroom/audit/maturation.py:70— headroom/audit/maturation.py:70-166 | headroom/audit/maturation.py:177-277 — These two members are one piece of code written twice and then edited apart: 97 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (97 corresponding lines) headroom/integrations/agno/model.py:431— headroom/integrations/agno/model.py:431-545 | headroom/integrations/strands/model.py:275-371 — These two members are one piece of code written twice and then edited apart: 97 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (76 corresponding lines) · ×2
Edited copy of a member (76 corresponding lines) headroom/learn/plugins/opencode.py:347— headroom/learn/plugins/opencode.py:347-430 | headroom/learn/plugins/opencode.py:438-513 — These two members are one piece of code written twice and then edited apart: 76 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (76 corresponding lines) headroom/memory/adapters/graph.py:308— headroom/memory/adapters/graph.py:308-392 | headroom/memory/adapters/graph.py:401-476 — These two members are one piece of code written twice and then edited apart: 76 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (48 corresponding lines) · ×2
Edited copy of a member (48 corresponding lines) crates/headroom-proxy/src/bedrock/invoke_streaming.rs:747— crates/headroom-proxy/src/bedrock/invoke_streaming.rs:747-810 | crates/headroom-proxy/src/vertex/raw_predict.rs:489-536 — These two members are one piece of code written twice and then edited apart: 48 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (48 corresponding lines) headroom/relevance/hybrid.py:154— headroom/relevance/hybrid.py:154-201 | headroom/relevance/hybrid.py:204-259 — These two members are one piece of code written twice and then edited apart: 48 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (62 corresponding lines) · ×2
Edited copy of a member (62 corresponding lines) headroom/integrations/agno/providers.py:65— headroom/integrations/agno/providers.py:65-129 | headroom/integrations/strands/providers.py:38-99 — These two members are one piece of code written twice and then edited apart: 62 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (62 corresponding lines) headroom/memory/bridge_parsers.py:269— headroom/memory/bridge_parsers.py:269-336 | headroom/memory/bridge_parsers.py:390-451 — These two members are one piece of code written twice and then edited apart: 62 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (45 corresponding lines) · ×2
Edited copy of a member (45 corresponding lines) REDACTED:219— REDACTED:219-274 | REDACTED:634-678 — These two members are one piece of code written twice and then edited apart: 45 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (45 corresponding lines) headroom/compression/detector.py:188— headroom/compression/detector.py:188-232 | headroom/compression/detector.py:235-280 — These two members are one piece of code written twice and then edited apart: 45 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (33 corresponding lines) · ×2
Edited copy of a member (33 corresponding lines) crates/headroom-proxy/src/sse/openai_chat.rs:143— crates/headroom-proxy/src/sse/openai_chat.rs:143-181 | crates/headroom-proxy/src/sse/openai_chat.rs:184-216 — These two members are one piece of code written twice and then edited apart: 33 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (33 corresponding lines) headroom/cli/wrap.py:3089— headroom/cli/wrap.py:3089-3127 | headroom/cli/wrap.py:3161-3193 — These two members are one piece of code written twice and then edited apart: 33 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (47 corresponding lines) · ×2
Edited copy of a member (47 corresponding lines) headroom/proxy/memory_handler.py:2008— headroom/proxy/memory_handler.py:2008-2054 | headroom/proxy/memory_handler.py:2059-2114 — These two members are one piece of code written twice and then edited apart: 47 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (47 corresponding lines) crates/headroom-core/src/transforms/smart_crusher/planning.rs:178— crates/headroom-core/src/transforms/smart_crusher/planning.rs:178-237 | crates/headroom-core/src/transforms/smart_crusher/planning.rs:448-494 — These two members are one piece of code written twice and then edited apart: 47 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (38 corresponding lines) · ×2
Edited copy of a member (38 corresponding lines) crates/headroom-core/src/transforms/content_detector.rs:565— crates/headroom-core/src/transforms/content_detector.rs:565-602 | crates/headroom-core/src/transforms/content_detector.rs:604-646 — These two members are one piece of code written twice and then edited apart: 38 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (38 corresponding lines) headroom/integrations/langchain/chat_model.py:236— headroom/integrations/langchain/chat_model.py:236-274 | headroom/integrations/langchain/memory.py:238-275 — These two members are one piece of code written twice and then edited apart: 38 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (30 corresponding lines) · ×2
Edited copy of a member (30 corresponding lines) headroom/evals/memory/runner.py:171— headroom/evals/memory/runner.py:171-200 | headroom/evals/memory/runner_v2.py:278-310 — These two members are one piece of code written twice and then edited apart: 30 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (30 corresponding lines) headroom/fsutil.py:70— headroom/fsutil.py:70-110 | headroom/install/state.py:34-63 — These two members are one piece of code written twice and then edited apart: 30 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (28 corresponding lines) · ×2
Edited copy of a member (28 corresponding lines) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:154— crates/headroom-core/src/transforms/smart_crusher/crusher.rs:154-181 | crates/headroom-core/src/transforms/smart_crusher/crusher.rs:395-429 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (28 corresponding lines) examples/strands_bedrock_demo.py:215— examples/langchain_demo/mock_tools.py:53-80 | examples/strands_bedrock_demo.py:215-264 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (39 corresponding lines) · ×2
Edited copy of a member (39 corresponding lines) headroom/cli/wrap.py:1600— headroom/cli/wrap.py:1600-1638 | headroom/proxy/output_savings.py:399-440 — These two members are one piece of code written twice and then edited apart: 39 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (39 corresponding lines) headroom/integrations/autogen/agents.py:236— headroom/integrations/autogen/agents.py:236-278 | headroom/integrations/crewai/agents.py:218-256 — These two members are one piece of code written twice and then edited apart: 39 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (21 corresponding lines) · ×2
Edited copy of a member (21 corresponding lines) headroom/memory/adapters/embedders.py:379— headroom/memory/adapters/embedders.py:379-400 | headroom/memory/adapters/embedders.py:620-640 — These two members are one piece of code written twice and then edited apart: 21 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (21 corresponding lines) headroom/compression/masks.py:88— headroom/compression/masks.py:88-108 | headroom/compression/masks.py:111-131 — These two members are one piece of code written twice and then edited apart: 21 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (23 corresponding lines) · ×2
Edited copy of a member (23 corresponding lines) headroom/integrations/agno/model.py:646— headroom/integrations/agno/model.py:646-668 | headroom/integrations/agno/model.py:687-713 — These two members are one piece of code written twice and then edited apart: 23 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (23 corresponding lines) headroom/mcp_registry/claude.py:563— headroom/mcp_registry/claude.py:563-585 | headroom/mcp_registry/opencode.py:88-110 — These two members are one piece of code written twice and then edited apart: 23 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 14+ corresponding lines) · ×2
Edited copies of one member (3 members, 14+ corresponding lines) crates/headroom-proxy/src/sse/openai_responses.rs:351— crates/headroom-proxy/src/sse/openai_responses.rs:351-364 | crates/headroom-proxy/src/sse/openai_responses.rs:366-386 | crates/headroom-proxy/src/sse/openai_responses.rs:388-401 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 14 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
Edited copies of one member (3 members, 14+ corresponding lines) headroom/backends/litellm.py:322— headroom/backends/litellm.py:322-351 | headroom/observability/metrics.py:120-133 | headroom/transforms/kompress_remote.py:83-100 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 14 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 15+ corresponding lines) · ×2
Edited copies of one member (4 members, 15+ corresponding lines) crates/headroom-proxy/src/observability/proxy_metrics.rs:71— crates/headroom-proxy/src/observability/proxy_metrics.rs:71-85 | crates/headroom-proxy/src/observability/proxy_metrics.rs:87-101 | crates/headroom-proxy/src/observability/proxy_metrics.rs:103-117 | crates/headroom-proxy/src/observability/proxy_metrics.rs:119-133 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 15 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
Edited copies of one member (4 members, 15+ corresponding lines) headroom/proxy/output_shaper.py:344— headroom/proxy/output_shaper.py:344-358 | headroom/proxy/output_shaper.py:366-385 | headroom/proxy/output_shaper.py:393-412 | headroom/proxy/output_shaper.py:526-544 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 15 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 8+ corresponding lines) · ×2
Edited copies of one member (3 members, 8+ corresponding lines) headroom/cli/wrap.py:4377— headroom/cli/wrap.py:4377-4387 | REDACTED:12-19 | headroom/providers/copilot/wrap.py:34-45 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 8 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
Edited copies of one member (3 members, 8+ corresponding lines) headroom/mcp_registry/antigravity.py:111— headroom/mcp_registry/antigravity.py:111-120 | headroom/mcp_registry/codex.py:150-157 | headroom/mcp_registry/opencode.py:159-166 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 8 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (15 corresponding lines) · ×2
Edited copy of a member (15 corresponding lines) headroom/_subprocess.py:81— headroom/_subprocess.py:81-99 | headroom/proxy_client_liveness.py:49-63 — These two members are one piece of code written twice and then edited apart: 15 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (15 corresponding lines) headroom/providers/aider/runtime.py:18— headroom/providers/aider/runtime.py:18-32 | headroom/providers/kimi/runtime.py:17-40 — These two members are one piece of code written twice and then edited apart: 15 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 6+ corresponding lines) · ×2
Edited copies of one member (3 members, 6+ corresponding lines) REDACTED:415— REDACTED:415-420 | headroom/proxy/gateway_extension.py:59-64 | headroom/transforms/content_router.py:646-656 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 6 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
Edited copies of one member (3 members, 6+ corresponding lines) headroom/cli/wrap.py:1185— headroom/cli/wrap.py:1185-1198 | headroom/proxy/cc_switch_reconciler.py:66-71 | headroom/proxy/helpers.py:128-135 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 6 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
Duplicated block (34–35 lines × 2) REDACTED:807— REDACTED:807-840 | headroom/memory/backends/mem0_system_adapter.py:136-170 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:807` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `headroom/memory/backends/mem0_system_adapter.py:134` calls `_utcnow`, `isinstance` and `REDACTED:807` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (34–35 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:297— crates/headroom-proxy/src/bedrock/invoke.rs:297-331 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:264-297 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:297` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (33–35 lines × 2) headroom/proxy/handlers/gemini.py:743— headroom/proxy/handlers/gemini.py:743-777 | headroom/proxy/handlers/gemini.py:1359-1391 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/proxy/handlers/gemini.py:743` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (33–35 lines × 2) headroom/proxy/prometheus_metrics.py:269— headroom/proxy/prometheus_metrics.py:269-303 | headroom/proxy/prometheus_metrics.py:477-509 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (28 lines × 2) headroom/audit/maturation.py:139— headroom/audit/maturation.py:139-166 | headroom/audit/maturation.py:250-277 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (28 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:375— crates/headroom-proxy/src/bedrock/invoke.rs:375-402 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:337-364 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:375` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (24–28 lines × 2) headroom/backends/anyllm.py:455— headroom/backends/anyllm.py:455-478 | headroom/backends/litellm.py:1783-1810 — before extracting anything, compare `headroom/backends/anyllm.py` and `headroom/backends/litellm.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 90 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/backends/litellm.py:1812` calls `close` and `headroom/backends/anyllm.py:480` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (24–28 lines × 2) headroom/memory/adapters/hnsw.py:591— headroom/memory/adapters/hnsw.py:591-618 | headroom/memory/adapters/sqlite_vector.py:689-712 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (26–28 lines × 2) headroom/proxy/handlers/gemini.py:782— headroom/proxy/handlers/gemini.py:782-807 | headroom/proxy/handlers/gemini.py:1393-1420 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (26–28 lines × 2) REDACTED:9442— REDACTED:9442-9469 | REDACTED:9499-9524 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (25 lines × 2) headroom/_subprocess.py:47— headroom/_subprocess.py:47-71 | headroom/proxy_client_liveness.py:21-45 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (25 lines × 2) headroom/proxy/handlers/batch.py:548— headroom/proxy/handlers/batch.py:548-572 | headroom/proxy/handlers/batch.py:699-723 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (20–23 lines × 2) headroom/backends/litellm.py:1376— headroom/backends/litellm.py:1376-1395 | headroom/backends/litellm.py:2008-2030 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (20–23 lines × 2) headroom/providers/proxy_routes.py:457— headroom/providers/proxy_routes.py:457-476 | headroom/providers/proxy_routes.py:479-501 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/providers/proxy_routes.py:479` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (23 lines × 2) headroom/proxy/memory_handler.py:2011— headroom/proxy/memory_handler.py:2011-2033 | headroom/proxy/memory_handler.py:2065-2087 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (23 lines × 2) crates/headroom-core/src/transforms/code_compressor.rs:1266— crates/headroom-core/src/transforms/code_compressor.rs:1266-1288 | crates/headroom-core/src/transforms/code_compressor.rs:1294-1316 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/code_compressor.rs:1266` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (22 lines × 2) headroom/memory/wrapper_tools.py:208— headroom/memory/wrapper_tools.py:208-229 | headroom/memory/wrapper_tools.py:441-462 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (22 lines × 2) crates/headroom-proxy/src/compression/live_zone_openai.rs:401— crates/headroom-proxy/src/compression/live_zone_openai.rs:401-422 | crates/headroom-proxy/src/compression/live_zone_responses.rs:409-430 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_openai.rs` and `crates/headroom-proxy/src/compression/live_zone_responses.rs` as WHOLE FILES: this scan already matched 14 separate duplicated blocks between them, totalling at least 278 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_openai.rs:401` it runs out through the closing brace of the declaration holding it and carries on into the declaration that follows — the window is the tail of one member plus the head of the next, so no call can be substituted for those exact lines, and the smallest declaration that contains all of them is the type they sit in. The repeated unit is the member each site sits in: where those members' bodies are the same, move one whole member to the shared location and have the others delegate to it; where the copies are a run of near-identical overloads or wrappers that differ only in their signatures, the repetition IS the run — a one-line delegation has no helper inside it to lift — so generate the run from the set it enumerates, or accept it and keep each member's own documentation with it.
Duplicated block (16–20 lines × 2) REDACTED:1494— REDACTED:1494-1513 | REDACTED:3639-3654 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:1494` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (16–20 lines × 2) REDACTED:2981— REDACTED:2981-2996 | REDACTED:3000-3019 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:2981` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (15–19 lines × 2) headroom/image/tile_optimizer.py:61— headroom/image/tile_optimizer.py:61-75 | headroom/image/tile_optimizer.py:104-122 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15–19 lines × 2) headroom/proxy/helpers.py:2694— headroom/proxy/helpers.py:2694-2712 | headroom/proxy/helpers.py:2728-2742 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/proxy/helpers.py:2694` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (16–18 lines × 2) headroom/backends/litellm.py:1357— headroom/backends/litellm.py:1357-1374 | headroom/backends/litellm.py:1991-2006 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (16–18 lines × 2) headroom/proxy/handlers/gemini.py:947— headroom/proxy/handlers/gemini.py:947-964 | headroom/proxy/handlers/gemini.py:1627-1642 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/proxy/handlers/gemini.py:966` calls `replace` and `headroom/proxy/handlers/gemini.py:1643` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (15–17 lines × 2) REDACTED:712— REDACTED:712-726 | REDACTED:783-799 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:712` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (15–17 lines × 2) crates/headroom-core/src/transforms/live_zone.rs:2483— crates/headroom-core/src/transforms/live_zone.rs:2483-2499 | crates/headroom-core/src/transforms/live_zone.rs:3009-3023 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/live_zone.rs:2483` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14–16 lines × 2) REDACTED:9066— REDACTED:9066-9081 | REDACTED:9576-9589 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (14–16 lines × 2) headroom/relevance/bm25.py:196— headroom/relevance/bm25.py:196-209 | headroom/relevance/bm25.py:272-287 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/relevance/bm25.py:272` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14–15 lines × 2) headroom/memory/adapters/graph.py:419— headroom/memory/adapters/graph.py:419-433 | headroom/memory/adapters/sqlite_graph.py:615-628 — before extracting anything, compare `headroom/memory/adapters/graph.py` and `headroom/memory/adapters/sqlite_graph.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 41 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (14–15 lines × 2) REDACTED:5630— REDACTED:5630-5644 | REDACTED:7292-7305 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (14 lines × 3) headroom/learn/plugins/codex.py:187— headroom/learn/plugins/codex.py:187-200 | headroom/learn/plugins/codex.py:254-267 | headroom/learn/plugins/grok.py:159-172 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart.
Duplicated block (14 lines × 3) headroom/proxy/handlers/gemini.py:502— headroom/proxy/handlers/gemini.py:502-515 | REDACTED:3700-3714 | REDACTED:6411-6424 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:3700` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12–14 lines × 2) headroom/image/tile_optimizer.py:80— headroom/image/tile_optimizer.py:80-93 | headroom/image/tile_optimizer.py:149-160 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12–14 lines × 2) headroom/proxy/savings_tracker.py:431— headroom/proxy/savings_tracker.py:431-444 | headroom/proxy/savings_tracker.py:695-706 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `headroom/proxy/savings_tracker.py:691` calls `_get_litellm_module` and `headroom/proxy/savings_tracker.py:430` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (11–13 lines × 2) REDACTED:6508— REDACTED:6508-6520 | headroom/proxy/handlers/batch.py:304-314 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:6508` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11–13 lines × 2) crates/headroom-core/src/transforms/pipeline/offloads/log_offload.rs:159— crates/headroom-core/src/transforms/pipeline/offloads/log_offload.rs:159-169 | crates/headroom-core/src/transforms/pipeline/offloads/search_offload.rs:127-139 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/pipeline/offloads/log_offload.rs:159` it runs out through the closing brace of the declaration holding it — the window is that declaration's tail, not a fragment that begins part-way through something, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10–11 lines × 2) headroom/backends/anyllm.py:230— headroom/backends/anyllm.py:230-240 | headroom/backends/anyllm.py:284-293 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10–11 lines × 2) crates/headroom-core/src/transforms/live_zone.rs:2294— crates/headroom-core/src/transforms/live_zone.rs:2294-2304 | crates/headroom-core/src/transforms/live_zone.rs:2789-2798 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/live_zone.rs:2294` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9–11 lines × 2) headroom/memory/writers/base.py:163— headroom/memory/writers/base.py:163-171 | headroom/memory/writers/cursor_writer.py:123-133 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/memory/writers/cursor_writer.py:123` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (9–11 lines × 2) headroom/proxy/handlers/gemini.py:1544— headroom/proxy/handlers/gemini.py:1544-1552 | headroom/proxy/handlers/gemini.py:1641-1651 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 4) REDACTED:1228— REDACTED:1228-1237 | REDACTED:1243-1252 | REDACTED:1258-1267 | REDACTED:1273-1282 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (10 lines × 4) headroom/proxy/beta_header_policy.py:16— headroom/proxy/beta_header_policy.py:16-25 | headroom/proxy/internal_header_policy.py:73-82 | headroom/proxy/tool_injection_policy.py:25-34 | headroom/proxy/tool_injection_policy.py:38-52 — there are 4 copies across 3 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 4 sites; resolving a subset leaves the remainder to drift apart. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (9–10 lines × 2) headroom/proxy/savings_tracker.py:865— headroom/proxy/savings_tracker.py:865-873 | headroom/proxy/savings_tracker.py:899-908 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9–10 lines × 2) crates/headroom-core/src/transforms/live_zone.rs:1389— crates/headroom-core/src/transforms/live_zone.rs:1389-1398 | crates/headroom-core/src/transforms/live_zone.rs:2456-2464 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/live_zone.rs:1389` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `crates/headroom-core/src/transforms/live_zone.rs:1400` calls `bytes_offset_of`, `get`, `ok_or` and `crates/headroom-core/src/transforms/live_zone.rs:2465` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (7–9 lines × 2) headroom/tokenizers/base.py:817— headroom/tokenizers/base.py:817-825 | headroom/tokenizers/tiktoken_counter.py:346-352 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (7–9 lines × 2) crates/headroom-proxy/src/proxy.rs:1334— crates/headroom-proxy/src/proxy.rs:1334-1342 | crates/headroom-proxy/src/vertex/raw_predict.rs:415-421 — before extracting anything, compare `crates/headroom-proxy/src/proxy.rs` and `crates/headroom-proxy/src/vertex/raw_predict.rs` as WHOLE FILES: this scan already matched 5 separate duplicated blocks between them, totalling at least 53 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/proxy.rs:1334` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (6 lines × 3) headroom/learn/writer.py:661— headroom/learn/writer.py:661-666 | headroom/learn/writer.py:699-704 | headroom/learn/writer.py:729-734 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (6 lines × 3) REDACTED:993— REDACTED:993-998 | headroom/providers/grok/runtime.py:27-32 | REDACTED:303-308 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note first that the copies are not typed on the same thing: the declarations holding them bind `headers` to `Mapping[str, str]` in one and `dict[str, str]` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (5 lines × 3) headroom/proxy/savings_tracker.py:759— headroom/proxy/savings_tracker.py:759-763 | headroom/proxy/savings_tracker.py:1932-1936 | headroom/proxy/savings_tracker.py:2381-2385 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/proxy/savings_tracker.py:764` calls `_coerce_int`, `get`, `_coerce_float` and `headroom/proxy/savings_tracker.py:2386` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (5 lines × 3) headroom/evals/core.py:173— headroom/evals/core.py:173-177 | headroom/evals/memory/runner.py:164-168 | headroom/evals/memory/runner_v2.py:271-275 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times.
Duplicated block (9 lines × 4) headroom/providers/anthropic.py:588— headroom/providers/anthropic.py:588-601 | headroom/providers/openai.py:385-393 | headroom/tokenizers/estimator.py:93-109 | headroom/tokenizers/tiktoken_counter.py:255-270 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 4 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 4 times. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (9 lines × 4) crates/headroom-proxy/src/proxy.rs:1572— crates/headroom-proxy/src/proxy.rs:1572-1580 | crates/headroom-proxy/src/proxy.rs:1649-1657 | crates/headroom-proxy/src/proxy.rs:1765-1773 | crates/headroom-proxy/src/vertex/raw_predict.rs:493-501 — before extracting anything, compare `crates/headroom-proxy/src/proxy.rs` and `crates/headroom-proxy/src/vertex/raw_predict.rs` as WHOLE FILES: this scan already matched 5 separate duplicated blocks between them, totalling at least 53 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/proxy.rs:1572` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 3) crates/headroom-core/src/transforms/live_zone.rs:1349— crates/headroom-core/src/transforms/live_zone.rs:1349-1357 | crates/headroom-core/src/transforms/live_zone.rs:2373-2381 | crates/headroom-core/src/transforms/live_zone.rs:2423-2431 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (9 lines × 3) crates/headroom-proxy/src/sse/anthropic.rs:407— crates/headroom-proxy/src/sse/anthropic.rs:407-415 | crates/headroom-proxy/src/sse/openai_chat.rs:223-231 | crates/headroom-proxy/src/sse/openai_responses.rs:450-458 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from all 3 call sites, so a change lands once.
Low cohesion: HeadroomOtelMetrics (LCOM4 6) headroom/observability/metrics.py:190— HeadroomOtelMetrics's methods fall into 6 groups that share no field and call none of each other, against a bar of more than 3 for this run (LCOM4, configurable — your repository's bar is the one quoted here). Each group is a set of methods reachable from one another through shared fields or direct calls, so 6 groups means the type has that many internally-connected clusters with nothing tying them together. Types whose shape makes a high count expected — and which would otherwise dominate this list — are excluded before this row is raised, so this is a genuine split candidate rather than a metric reading. It is still a shape, not a defect: confirm the groups match responsibilities you can name before splitting.
Low cohesion: HeadroomProxy (LCOM4 5) REDACTED:1048— HeadroomProxy's methods fall into 5 groups that share no field and call none of each other, against a bar of more than 3 for this run (LCOM4, configurable — your repository's bar is the one quoted here). Each group is a set of methods reachable from one another through shared fields or direct calls, so 5 groups means the type has that many internally-connected clusters with nothing tying them together. Types whose shape makes a high count expected — and which would otherwise dominate this list — are excluded before this row is raised, so this is a genuine split candidate rather than a metric reading. It is still a shape, not a defect: confirm the groups match responsibilities you can name before splitting.
Duplicated block (14 lines × 2 locations) plugins/openclaw/src/convert.ts:504— plugins/openclaw/src/convert.ts:504 · plugins/openclaw/src/convert.ts:535 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
Duplicated block (14 lines × 2 locations) scripts/verify_npm_release_assets.mjs:139— scripts/verify_npm_release_assets.mjs:139 · scripts/verify_npm_release_assets.mjs:158 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12 lines × 2 locations) plugins/openclaw/src/proxy-manager.ts:288— plugins/openclaw/src/proxy-manager.ts:288 · plugins/openclaw/src/proxy-manager.ts:306 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12 lines × 2 locations) sdk/typescript/src/utils/format.ts:898— sdk/typescript/src/utils/format.ts:898 · sdk/typescript/src/utils/format.ts:957 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (6 lines × 2 locations) plugins/headroom-snip/hooks/register.tsx:233— plugins/headroom-snip/hooks/register.tsx:233 · plugins/headroom-snip/hooks/register.tsx:302 — all 2 copies are in the same file, and the CITED SPAN is a run of DECLARATIONS inside a construct — the members of a type, or the entries of an object or array literal — with no statement anywhere in it. Do not read this as an extract-a-helper row: nothing here executes, so there is no call site, and a call expression cannot stand where a member declaration or a literal's entry was. What repeats is a SHAPE, and which shape decides the move. Where the copies declare the same members, the repetition is a missing common ancestor: give it a base type, an interface both extend, a generic instantiated twice, or — where the copies are a literal's entries rather than a type's members — one shared constant each site spreads or refers to, so the set is written once. Where they declare DIFFERENT members and only the form is shared — a decorator and its options, an annotation, a registration table's keys — the form is prescribed by a framework or a schema rather than copied, and the only collapse available is to generate the declarations from that schema; where you do not own the generator, this is the cost of the framework and there is nothing to extract. Check which of the two it is before acting: these copies still drift apart the first time only one of them is edited, which is why the repetition is reported, but the sentence to act on is not the same in both cases.
Duplicated block (6 lines × 2 locations) scripts/verify_anthropic_peer.mjs:10— scripts/verify_anthropic_peer.mjs:10 · scripts/verify_sdk_provider_peers.mjs:13 — the 2 copies are spread across 2 files, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
Complex function (anonymous) (cyclomatic 12, cognitive 10) plugins/headroom-snip/hooks/register.tsx:184— (anonymous) has cyclomatic complexity 12 and cognitive complexity 10; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function (anonymous) (cyclomatic 12, cognitive 10) plugins/headroom-snip/hooks/register.tsx:259— (anonymous) has cyclomatic complexity 12 and cognitive complexity 10; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Unused dependency '@typescript/native' — Declared in plugins/openclaw/package.json but never imported anywhere in that package or its workspace members — no static import reaches it. Usually that is dead weight and attack surface, but two shapes are indistinguishable from source and are NOT dead: an optional or native peer that another dependency loads dynamically at runtime, and a package a build, docs or test step installs and invokes separately. Confirm which of the three this is before removing it.
Unused dependency '@typescript/native' — Declared in plugins/opencode/package.json but never imported anywhere in that package or its workspace members — no static import reaches it. Usually that is dead weight and attack surface, but two shapes are indistinguishable from source and are NOT dead: an optional or native peer that another dependency loads dynamically at runtime, and a package a build, docs or test step installs and invokes separately. Confirm which of the three this is before removing it.
AC4 · Keyboard semantics· Modal dialog does not manage focus · ×1
Modal dialog does not manage focus headroom/dashboard/templates/dashboard.html:2002— This <div role="dialog"> is a modal dialog, but focus is moved into it, but nothing keeps it there: Tab walks out to the page behind, so a keyboard or screen-reader user keeps acting on the content behind it (WCAG 2.4.3). Use a native <dialog> opened with showModal(), a dialog component that traps focus, or move focus to the dialog on open, trap Tab inside it (or make the page behind inert) and return focus to the control that opened it on close.
AnthropicHandlerMixin.handle_anthropic_messages (cyclomatic 373) REDACTED:1309— AnthropicHandlerMixin.handle_anthropic_messages has cyclomatic complexity 373 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
OpenAIHandlerMixin.handle_openai_chat (cyclomatic 205) REDACTED:3542— OpenAIHandlerMixin.handle_openai_chat has cyclomatic complexity 205 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ContentRouter.apply (cyclomatic 192) headroom/transforms/content_router.py:6337— ContentRouter.apply has cyclomatic complexity 192 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
OpenAIHandlerMixin.handle_openai_responses_ws (cyclomatic 178) REDACTED:7782— OpenAIHandlerMixin.handle_openai_responses_ws has cyclomatic complexity 178 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
OpenAIHandlerMixin.handle_openai_responses (cyclomatic 122) REDACTED:6202— OpenAIHandlerMixin.handle_openai_responses has cyclomatic complexity 122 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
wrap._ensure_proxy_unlocked (cyclomatic 121) headroom/cli/wrap.py:5091— wrap._ensure_proxy_unlocked has cyclomatic complexity 121 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
proxy.proxy (cyclomatic 120) headroom/cli/proxy.py:1218— proxy.proxy has cyclomatic complexity 120 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
OpenAIHandlerMixin._compress_openai_responses_live_text_units_with_router (cyclomatic 117) REDACTED:2421— OpenAIHandlerMixin._compress_openai_responses_live_text_units_with_router has cyclomatic complexity 117 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
dashboard.html.dashboard (cyclomatic 107) headroom/dashboard/templates/dashboard.html:2056— dashboard.html.dashboard has cyclomatic complexity 107 (threshold 15). Of this number, 102 points are the body's own statements and 5 belong to 4 function literals inside it that branch. To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
GeminiHandlerMixin.handle_gemini_generate_content (cyclomatic 95) headroom/proxy/handlers/gemini.py:399— GeminiHandlerMixin.handle_gemini_generate_content has cyclomatic complexity 95 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ContentRouter._apply_strategy_to_content (cyclomatic 94) headroom/transforms/content_router.py:4408— ContentRouter._apply_strategy_to_content has cyclomatic complexity 94 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ContentRouter._process_content_blocks (cyclomatic 87) headroom/transforms/content_router.py:7900— ContentRouter._process_content_blocks has cyclomatic complexity 87 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
OpenAIHandlerMixin.handle_compress (cyclomatic 83) REDACTED:11139— OpenAIHandlerMixin.handle_compress has cyclomatic complexity 83 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
wrap.claude (cyclomatic 67) headroom/cli/wrap.py:6373— wrap.claude has cyclomatic complexity 67 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
LiteLLMBackend.stream_message (cyclomatic 66) headroom/backends/litellm.py:1397— LiteLLMBackend.stream_message has cyclomatic complexity 66 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
KompressCompressor.compress_batch (cyclomatic 66) headroom/transforms/kompress_compressor.py:2285— KompressCompressor.compress_batch has cyclomatic complexity 66 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
CodeAwareCompressor._compress_function_ast (cyclomatic 60) headroom/transforms/code_compressor.py:1901— CodeAwareCompressor._compress_function_ast has cyclomatic complexity 60 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HeadroomProxy.startup (cyclomatic 56) REDACTED:2204— HeadroomProxy.startup has cyclomatic complexity 56 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
gateway_turn.handle_compress_response (cyclomatic 55) headroom/proxy/gateway_turn.py:1607— gateway_turn.handle_compress_response has cyclomatic complexity 55 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
anthropic_wire._response_from_events (cyclomatic 54) headroom/proxy/anthropic_wire.py:296— anthropic_wire._response_from_events has cyclomatic complexity 54 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
learn.learn (cyclomatic 52) headroom/cli/learn.py:143— learn.learn has cyclomatic complexity 52 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
PrometheusMetrics.export (cyclomatic 52) headroom/proxy/prometheus_metrics.py:1427— PrometheusMetrics.export has cyclomatic complexity 52 (threshold 15). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
format.vercelToOpenAI (cyclomatic 51) sdk/typescript/src/utils/format.ts:534— format.vercelToOpenAI has cyclomatic complexity 51 (threshold 15). Of this number, 46 points are the body's own statements and 5 belong to 3 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
KompressCompressor.compress (cyclomatic 50) headroom/transforms/kompress_compressor.py:1924— KompressCompressor.compress has cyclomatic complexity 50 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HeadroomProxy.__init__ (cyclomatic 49) REDACTED:1064— HeadroomProxy.__init__ has cyclomatic complexity 49 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
reads._audit_session (cyclomatic 47) headroom/audit/reads.py:159— reads._audit_session has cyclomatic complexity 47 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
cost.build_prefix_cache_stats (cyclomatic 46) headroom/proxy/cost.py:243— cost.build_prefix_cache_stats has cyclomatic complexity 46 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
PrometheusMetrics.record_request (cyclomatic 45) headroom/proxy/prometheus_metrics.py:867— PrometheusMetrics.record_request has cyclomatic complexity 45 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
helpers.relocate_system_messages_to_top_level (cyclomatic 44) headroom/proxy/helpers.py:1110— helpers.relocate_system_messages_to_top_level has cyclomatic complexity 44 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
format.detectFormat (cyclomatic 44) sdk/typescript/src/utils/format.ts:39— format.detectFormat has cyclomatic complexity 44 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
JSONStructureHandler._tokenize_json (cyclomatic 43) headroom/compression/handlers/json_handler.py:254— JSONStructureHandler._tokenize_json has cyclomatic complexity 43 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ContentRouter._try_ml_compressor (cyclomatic 43) headroom/transforms/content_router.py:5181— ContentRouter._try_ml_compressor has cyclomatic complexity 43 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
AnthropicHandlerMixin.handle_anthropic_batch_create (cyclomatic 42) REDACTED:6236— AnthropicHandlerMixin.handle_anthropic_batch_create has cyclomatic complexity 42 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
OpenAIHandlerMixin.handle_passthrough (cyclomatic 42) REDACTED:12290— OpenAIHandlerMixin.handle_passthrough has cyclomatic complexity 42 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
StreamingMixin._continue_memory_tool_stream (cyclomatic 42) REDACTED:522— StreamingMixin._continue_memory_tool_stream has cyclomatic complexity 42 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
session._fold_extra (cyclomatic 42) REDACTED:1385— session._fold_extra has cyclomatic complexity 42 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ContentRouter._compress_block_content (cyclomatic 42) headroom/transforms/content_router.py:8392— ContentRouter._compress_block_content has cyclomatic complexity 42 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
maturation.simulate_maturation (cyclomatic 41) headroom/audit/maturation.py:69— maturation.simulate_maturation has cyclomatic complexity 41 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
wrap.openclaw (cyclomatic 41) headroom/cli/wrap.py:8699— wrap.openclaw has cyclomatic complexity 41 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
parser.parse_message_to_blocks (cyclomatic 41) REDACTED:209— parser.parse_message_to_blocks has cyclomatic complexity 41 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
helpers.enforce_cache_breakpoint_budget (cyclomatic 41) headroom/proxy/helpers.py:793— helpers.enforce_cache_breakpoint_budget has cyclomatic complexity 41 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
format.openAIToVercel (cyclomatic 39) sdk/typescript/src/utils/format.ts:672— format.openAIToVercel has cyclomatic complexity 39 (threshold 15). Of this number, 37 points are the body's own statements and 2 belong to one function literal inside it that branches. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BatchHandlerMixin.handle_google_batch_create (cyclomatic 38) headroom/proxy/handlers/batch.py:33— BatchHandlerMixin.handle_google_batch_create has cyclomatic complexity 38 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
StreamingMixin._stream_response_inner (cyclomatic 38) REDACTED:1235— StreamingMixin._stream_response_inner has cyclomatic complexity 38 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
helpers.strip_unsupported_tool_search_blocks (cyclomatic 38) headroom/proxy/helpers.py:4441— helpers.strip_unsupported_tool_search_blocks has cyclomatic complexity 38 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
learn._run_verbosity (cyclomatic 37) headroom/cli/learn.py:650— learn._run_verbosity has cyclomatic complexity 37 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
OpenAIHandlerMixin._compress_openai_responses_payload (cyclomatic 37) REDACTED:3094— OpenAIHandlerMixin._compress_openai_responses_payload has cyclomatic complexity 37 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
StreamingMixin._finalize_stream_response (cyclomatic 37) REDACTED:886— StreamingMixin._finalize_stream_response has cyclomatic complexity 37 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
LiteLLMBackend.send_openai_message (cyclomatic 36) headroom/backends/litellm.py:1816— LiteLLMBackend.send_openai_message has cyclomatic complexity 36 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
wrap._start_proxy (cyclomatic 36) headroom/cli/wrap.py:857— wrap._start_proxy has cyclomatic complexity 36 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
server._build_agent_usage_summary (cyclomatic 36) REDACTED:341— server._build_agent_usage_summary has cyclomatic complexity 36 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
session._fold (cyclomatic 36) REDACTED:1277— session._fold has cyclomatic complexity 36 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
content_detector._try_detect_structured_config (cyclomatic 36) headroom/transforms/content_detector.py:932— content_detector._try_detect_structured_config has cyclomatic complexity 36 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
LiteLLMBackend._convert_messages_for_litellm (cyclomatic 35) headroom/backends/litellm.py:1003— LiteLLMBackend._convert_messages_for_litellm has cyclomatic complexity 35 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
wrap.copilot (cyclomatic 35) headroom/cli/wrap.py:7056— wrap.copilot has cyclomatic complexity 35 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseTokenizer._count_content_parts (cyclomatic 35) headroom/tokenizers/base.py:576— BaseTokenizer._count_content_parts has cyclomatic complexity 35 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
TransformPipeline.apply (cyclomatic 35) REDACTED:263— TransformPipeline.apply has cyclomatic complexity 35 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
TelemetryCollector._create_field_distribution (cyclomatic 34) headroom/telemetry/collector.py:488— TelemetryCollector._create_field_distribution has cyclomatic complexity 34 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ToolSignature.from_items (cyclomatic 34) headroom/telemetry/models.py:214— ToolSignature.from_items has cyclomatic complexity 34 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
CodeAwareCompressor._compress_class_ast (cyclomatic 34) headroom/transforms/code_compressor.py:2186— CodeAwareCompressor._compress_class_ast has cyclomatic complexity 34 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
planner.build_manifest (cyclomatic 33) headroom/install/planner.py:139— planner.build_manifest has cyclomatic complexity 33 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
parser.parse_messages (cyclomatic 33) REDACTED:393— parser.parse_messages has cyclomatic complexity 33 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ToolIntelligenceNetwork._merge_patterns (cyclomatic 33) headroom/telemetry/toin.py:1499— ToolIntelligenceNetwork._merge_patterns has cyclomatic complexity 33 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ContentRouter._cross_turn_dedup_messages (cyclomatic 33) headroom/transforms/content_router.py:7753— ContentRouter._cross_turn_dedup_messages has cyclomatic complexity 33 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SessionTrackerStore.resolve_tracker (cyclomatic 32) REDACTED:1876— SessionTrackerStore.resolve_tracker has cyclomatic complexity 32 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SQLiteMemoryStore._build_query_conditions (cyclomatic 32) headroom/memory/adapters/sqlite.py:446— SQLiteMemoryStore._build_query_conditions has cyclomatic complexity 32 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
StreamingMixin._parse_sse_usage_from_buffer (cyclomatic 32) REDACTED:307— StreamingMixin._parse_sse_usage_from_buffer has cyclomatic complexity 32 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
outcome.emit_request_outcome (cyclomatic 32) REDACTED:478— outcome.emit_request_outcome has cyclomatic complexity 32 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
settings_store._coerce (cyclomatic 32) headroom/settings_store.py:838— settings_store._coerce has cyclomatic complexity 32 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
LogCompressor::select_lines (cyclomatic 32) crates/headroom-core/src/transforms/log_compressor.rs:1297— LogCompressor::select_lines has cyclomatic complexity 32 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
maturation.simulate_codex_maturation (cyclomatic 31) headroom/audit/maturation.py:176— maturation.simulate_codex_maturation has cyclomatic complexity 31 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
AnyLLMBackend.stream_message (cyclomatic 31) headroom/backends/anyllm.py:279— AnyLLMBackend.stream_message has cyclomatic complexity 31 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
prefix_tracker.normalize_message_cache_control (cyclomatic 31) REDACTED:963— prefix_tracker.normalize_message_cache_control has cyclomatic complexity 31 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
install._apply_manifest (cyclomatic 31) headroom/cli/install.py:659— install._apply_manifest has cyclomatic complexity 31 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
wrap.opencode (cyclomatic 31) headroom/cli/wrap.py:8953— wrap.opencode has cyclomatic complexity 31 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ImageCompressor._apply_compression (cyclomatic 30) headroom/image/compressor.py:539— ImageCompressor._apply_compression has cyclomatic complexity 30 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ToolIntelligenceNetwork.record_retrieval (cyclomatic 30) headroom/telemetry/toin.py:974— ToolIntelligenceNetwork.record_retrieval has cyclomatic complexity 30 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
dashboard.html.renderChart (cyclomatic 30) crates/headroom-proxy/src/observability/dashboard.html:435— dashboard.html.renderChart has cyclomatic complexity 30 (threshold 15). Of this number, 18 points are the body's own statements and 12 belong to 5 function items inside it that branch. To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
worker.clean (cyclomatic 30) deploy/beacon/worker.js:207— worker.clean has cyclomatic complexity 30 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
DirectMem0Adapter._save_memory_internal (cyclomatic 29) REDACTED:709— DirectMem0Adapter._save_memory_internal has cyclomatic complexity 29 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
gateway_responses.build_view (cyclomatic 29) headroom/proxy/gateway_responses.py:157— gateway_responses.build_view has cyclomatic complexity 29 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
helpers.strip_unsupported_ccr_retrieve_blocks (cyclomatic 29) headroom/proxy/helpers.py:4589— helpers.strip_unsupported_ccr_retrieve_blocks has cyclomatic complexity 29 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
MemoryHandler.search_and_format_context (cyclomatic 29) headroom/proxy/memory_handler.py:724— MemoryHandler.search_and_format_context has cyclomatic complexity 29 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
LiteLLMBackend.send_message (cyclomatic 28) headroom/backends/litellm.py:1268— LiteLLMBackend.send_message has cyclomatic complexity 28 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Mem0Backend.query (cyclomatic 28) headroom/memory/backends/mem0.py:551— Mem0Backend.query has cyclomatic complexity 28 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
parser.find_tool_units (cyclomatic 28) REDACTED:527— parser.find_tool_units has cyclomatic complexity 28 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
cost.build_session_summary (cyclomatic 28) headroom/proxy/cost.py:665— cost.build_session_summary has cyclomatic complexity 28 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
OpenAIHandlerMixin._ws_http_fallback (cyclomatic 28) REDACTED:10793— OpenAIHandlerMixin._ws_http_fallback has cyclomatic complexity 28 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
base.apply_to_messages (cyclomatic 28) headroom/proxy/interceptors/base.py:193— base.apply_to_messages has cyclomatic complexity 28 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
CodeAwareCompressor.compress (cyclomatic 28) headroom/transforms/code_compressor.py:1293— CodeAwareCompressor.compress has cyclomatic complexity 28 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
code_compressor.detect_language (cyclomatic 28) headroom/transforms/code_compressor.py:882— code_compressor.detect_language has cyclomatic complexity 28 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
format.anthropicToOpenAI (cyclomatic 28) sdk/typescript/src/utils/format.ts:190— format.anthropicToOpenAI has cyclomatic complexity 28 (threshold 15). Of this number, 18 points are the body's own statements and 10 belong to 7 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
format.openAIToGemini (cyclomatic 28) sdk/typescript/src/utils/format.ts:1005— format.openAIToGemini has cyclomatic complexity 28 (threshold 15). Of this number, 25 points are the body's own statements and 3 belong to 3 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
MemoryToolStreamFilter._route (cyclomatic 27) headroom/proxy/memory_tool_stream.py:255— MemoryToolStreamFilter._route has cyclomatic complexity 27 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
format.vercelMediaImageUrl (cyclomatic 27) sdk/typescript/src/utils/format.ts:419— format.vercelMediaImageUrl has cyclomatic complexity 27 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
format.geminiToOpenAI (cyclomatic 27) sdk/typescript/src/utils/format.ts:880— format.geminiToOpenAI has cyclomatic complexity 27 (threshold 15). Of this number, 18 points are the body's own statements and 9 belong to 6 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
claude_analysis_ttl.main (cyclomatic 26) claude_analysis_ttl.py:98— claude_analysis_ttl.main has cyclomatic complexity 26 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
prefix_tracker.overlay_cached_prefix (cyclomatic 26) REDACTED:677— prefix_tracker.overlay_cached_prefix has cyclomatic complexity 26 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
StreamingCCRHandler._reconstruct_openai_response (cyclomatic 26) headroom/ccr/response_handler.py:884— StreamingCCRHandler._reconstruct_openai_response has cyclomatic complexity 26 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
traffic_learner._load_persisted_patterns_from_sqlite (cyclomatic 26) headroom/memory/traffic_learner.py:1912— traffic_learner._load_persisted_patterns_from_sqlite has cyclomatic complexity 26 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
config_toml.root_assignment_lines (cyclomatic 26) headroom/providers/codex/config_toml.py:51— config_toml.root_assignment_lines has cyclomatic complexity 26 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
StreamingMixin._record_ccr_feedback_from_openai_sse (cyclomatic 26) REDACTED:807— StreamingMixin._record_ccr_feedback_from_openai_sse has cyclomatic complexity 26 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
CompressionStore._evict_if_needed (cyclomatic 25) headroom/cache/compression_store.py:867— CompressionStore._evict_if_needed has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
update.safe_update (cyclomatic 25) headroom/cli/update.py:229— update.safe_update has cyclomatic complexity 25 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
compress.compress (cyclomatic 25) headroom/compress.py:215— compress.compress has cyclomatic complexity 25 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
CostTracker.stats (cyclomatic 25) headroom/proxy/cost.py:1676— CostTracker.stats has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
gateway_turn._wire_provider_from_shape (cyclomatic 25) headroom/proxy/gateway_turn.py:231— gateway_turn._wire_provider_from_shape has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
AnthropicHandlerMixin._append_proactive_expansion_after_cached_prefix (cyclomatic 25) REDACTED:1014— AnthropicHandlerMixin._append_proactive_expansion_after_cached_prefix has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
GeminiHandlerMixin.handle_gemini_count_tokens (cyclomatic 25) headroom/proxy/handlers/gemini.py:1476— GeminiHandlerMixin.handle_gemini_count_tokens has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
helpers.apply_session_sticky_memory_tools (cyclomatic 25) headroom/proxy/helpers.py:2622— helpers.apply_session_sticky_memory_tools has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
savings._compute (cyclomatic 25) headroom/proxy/savings.py:558— savings._compute has cyclomatic complexity 25 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
TiktokenCounter.count_messages (cyclomatic 25) headroom/tokenizers/tiktoken_counter.py:283— TiktokenCounter.count_messages has cyclomatic complexity 25 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HeadroomClient._create (cyclomatic 24) headroom/client.py:464— HeadroomClient._create has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
supervisors.install_supervisor (cyclomatic 24) REDACTED:538— supervisors.install_supervisor has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
GeminiHandlerMixin.handle_google_cloudcode_stream (cyclomatic 24) headroom/proxy/handlers/gemini.py:1258— GeminiHandlerMixin.handle_google_cloudcode_stream has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
OpenAIHandlerMixin.handle_compress_usage (cyclomatic 24) REDACTED:11908— OpenAIHandlerMixin.handle_compress_usage has cyclomatic complexity 24 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
HeadroomProxy._retry_request (cyclomatic 24) REDACTED:2739— HeadroomProxy._retry_request has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
savings_ledger.record_savings_event (cyclomatic 24) headroom/savings_ledger.py:285— savings_ledger.record_savings_event has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compaction_codec.factor_values (cyclomatic 24) headroom/transforms/compaction_codec.py:255— compaction_codec.factor_values has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ReadMaturationManager._scan_activity (cyclomatic 24) headroom/transforms/read_maturation.py:275— ReadMaturationManager._scan_activity has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
runtime-proof.run_case (cyclomatic 24) plugins/opencode/scripts/runtime-proof.py:104— runtime-proof.run_case has cyclomatic complexity 24 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
register.register (cyclomatic 24) plugins/headroom-snip/hooks/register.tsx:144— register.register has cyclomatic complexity 24 (threshold 15). Most of this is not in the body itself: 1 of the 24 points is its own statement and the rest belongs to 4 function literals inside it that branch (lines 184, 259, 296, …). The decisions are inside those literals, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literals' work into a named function or method at the enclosing scope and have each literal call it, then reduce whichever part then reads as the largest.
SharedSessions.fetch (cyclomatic 23) REDACTED:99— SharedSessions.fetch has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
tool_calls.extract_tool_calls (cyclomatic 23) headroom/ccr/tool_calls.py:30— tool_calls.extract_tool_calls has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
wrap._remove_claude_managed_hooks (cyclomatic 23) headroom/cli/wrap.py:1400— wrap._remove_claude_managed_hooks has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
wrap._ensure_serena_dashboard_disabled (cyclomatic 23) headroom/cli/wrap.py:2414— wrap._ensure_serena_dashboard_disabled has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
analyzer._call_claude_cli_streaming (cyclomatic 23) headroom/learn/analyzer.py:869— analyzer._call_claude_cli_streaming has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
OpenCodePlugin._scan_session_v2 (cyclomatic 23) headroom/learn/plugins/opencode.py:341— OpenCodePlugin._scan_session_v2 has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
verbosity._parse_session (cyclomatic 23) headroom/learn/verbosity.py:202— verbosity._parse_session has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
LocalBackend.save_memory (cyclomatic 23) headroom/memory/backends/local.py:232— LocalBackend.save_memory has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
counterfactual.resolve_rates (cyclomatic 23) headroom/pricing/counterfactual.py:437— counterfactual.resolve_rates has cyclomatic complexity 23 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
anthropic_wire._render_known_response (cyclomatic 23) headroom/proxy/anthropic_wire.py:576— anthropic_wire._render_known_response has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
helpers.count_cache_breakpoints (cyclomatic 23) headroom/proxy/helpers.py:439— helpers.count_cache_breakpoints has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
helpers.walk_cache_control (cyclomatic 23) headroom/proxy/helpers.py:572— helpers.walk_cache_control has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
lossless_compaction.compact_lossless (cyclomatic 23) headroom/transforms/lossless_compaction.py:485— lossless_compaction.compact_lossless has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SmartCrusher.apply (cyclomatic 23) headroom/transforms/smart_crusher.py:1279— SmartCrusher.apply has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
StackTraceDetector::terminates (cyclomatic 23) crates/headroom-core/src/transforms/log_compressor.rs:601— StackTraceDetector::terminates has cyclomatic complexity 23 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
snip.describe (cyclomatic 23) plugins/headroom-snip/hooks/snip.ts:103— snip.describe has cyclomatic complexity 23 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
convert.agentToOpenAI (cyclomatic 23) plugins/openclaw/src/convert.ts:29— convert.agentToOpenAI has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
CCRToolInjector.scan_for_markers (cyclomatic 22) headroom/ccr/tool_injection.py:287— CCRToolInjector.scan_for_markers has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
evals._run_memory_eval (cyclomatic 22) headroom/cli/evals.py:417— evals._run_memory_eval has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
inspect._render_request (cyclomatic 22) headroom/cli/inspect.py:59— inspect._render_request has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
LoCoMoEvaluatorV2._answer_question (cyclomatic 22) headroom/evals/memory/runner_v2.py:633— LoCoMoEvaluatorV2._answer_question has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HeadroomStrandsModel._convert_messages_to_openai (cyclomatic 22) headroom/integrations/strands/model.py:158— HeadroomStrandsModel._convert_messages_to_openai has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
GeminiPlugin._parse_messages (cyclomatic 22) headroom/learn/plugins/gemini.py:201— GeminiPlugin._parse_messages has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
verbosity.extract_signals (cyclomatic 22) headroom/learn/verbosity.py:323— verbosity.extract_signals has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SQLiteGraphStore.query_subgraph (cyclomatic 22) headroom/memory/adapters/sqlite_graph.py:456— SQLiteGraphStore.query_subgraph has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
LocalBackend.search_memories (cyclomatic 22) headroom/memory/backends/local.py:424— LocalBackend.search_memories has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
anthropic._load_custom_model_config (cyclomatic 22) headroom/providers/anthropic.py:406— anthropic._load_custom_model_config has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
live.handle_codex_live_websocket (cyclomatic 22) headroom/providers/codex/live.py:162— live.handle_codex_live_websocket has cyclomatic complexity 22 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
openai._load_custom_model_config (cyclomatic 22) headroom/providers/openai.py:187— openai._load_custom_model_config has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
gateway_responses.apply_view (cyclomatic 22) headroom/proxy/gateway_responses.py:289— gateway_responses.apply_view has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
server.run_server (cyclomatic 22) REDACTED:6862— server.run_server has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
stream_output_tokens.extract_stream_text (cyclomatic 22) headroom/proxy/stream_output_tokens.py:63— stream_output_tokens.extract_stream_text has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ToolIntelligenceNetwork.record_compression (cyclomatic 22) headroom/telemetry/toin.py:631— ToolIntelligenceNetwork.record_compression has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ReadLifecycleManager._build_tool_metadata (cyclomatic 22) headroom/transforms/read_lifecycle.py:188— ReadLifecycleManager._build_tool_metadata has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
DiffCompressor::compress_with_ccr_source (cyclomatic 22) crates/headroom-core/src/transforms/diff_compressor.rs:288— DiffCompressor::compress_with_ccr_source has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
convert.openAIToAgent (cyclomatic 22) plugins/openclaw/src/convert.ts:155— convert.openAIToAgent has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
StreamingCCRHandler.process_stream (cyclomatic 21) headroom/ccr/response_handler.py:707— StreamingCCRHandler.process_stream has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
report_card.generate_html (cyclomatic 21) headroom/evals/reports/report_card.py:210— report_card.generate_html has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
opencode._extract_output (cyclomatic 21) headroom/learn/plugins/opencode.py:87— opencode._extract_output has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
InMemoryGraphStore.find_path (cyclomatic 21) headroom/memory/adapters/graph.py:394— InMemoryGraphStore.find_path has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HeadroomOtelMetrics.record_proxy_request (cyclomatic 21) headroom/observability/metrics.py:446— HeadroomOtelMetrics.record_proxy_request has cyclomatic complexity 21 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
RequestTransformer.run (cyclomatic 21) headroom/proxy/gateway_turn.py:957— RequestTransformer.run has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SavingsTracker._sanitize_state (cyclomatic 21) headroom/proxy/savings_tracker.py:1896— SavingsTracker._sanitize_state has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
savings_ledger.aggregate_savings (cyclomatic 21) headroom/savings_ledger.py:637— savings_ledger.aggregate_savings has cyclomatic complexity 21 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
_PdfReader.read_xref_stream (cyclomatic 21) headroom/tokenizers/base.py:225— _PdfReader.read_xref_stream has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compaction_codec.expand_compacted (cyclomatic 21) headroom/transforms/compaction_codec.py:361— compaction_codec.expand_compacted has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ContentRouter.eager_load_compressors (cyclomatic 21) headroom/transforms/content_router.py:5783— ContentRouter.eager_load_compressors has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ContentRouter._build_tool_name_map (cyclomatic 21) headroom/transforms/content_router.py:6116— ContentRouter._build_tool_name_map has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
mixed_content.split_into_sections (cyclomatic 21) headroom/transforms/mixed_content.py:126— mixed_content.split_into_sections has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ProxyManager.start (cyclomatic 21) plugins/openclaw/src/proxy-manager.ts:73— ProxyManager.start has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
PrefixCacheTracker._estimate_message_tokens (cyclomatic 20) REDACTED:1666— PrefixCacheTracker._estimate_message_tokens has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ttl_estimator.estimate_ttls (cyclomatic 20) headroom/cache/ttl_estimator.py:71— ttl_estimator.estimate_ttls has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HeadroomMCPServer._handle_read (cyclomatic 20) headroom/ccr/mcp_server.py:1119— HeadroomMCPServer._handle_read has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BatchCompressionEvaluator.evaluate_case (cyclomatic 20) headroom/evals/batch_compression_eval.py:1108— BatchCompressionEvaluator.evaluate_case has cyclomatic complexity 20 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
BeforeAfterRunner._check_ground_truth_bfcl (cyclomatic 20) headroom/evals/runners/before_after.py:210— BeforeAfterRunner._check_ground_truth_bfcl has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
InMemoryGraphStore.query_subgraph (cyclomatic 20) headroom/memory/adapters/graph.py:301— InMemoryGraphStore.query_subgraph has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SQLiteGraphStore.find_path (cyclomatic 20) headroom/memory/adapters/sqlite_graph.py:579— SQLiteGraphStore.find_path has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
TrafficLearner.flush_to_file (cyclomatic 20) headroom/memory/traffic_learner.py:638— TrafficLearner.flush_to_file has cyclomatic complexity 20 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
TrafficLearner.extract_tool_results_from_openai_messages (cyclomatic 20) headroom/memory/traffic_learner.py:1753— TrafficLearner.extract_tool_results_from_openai_messages has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
openai._codex_ws_text_shape (cyclomatic 20) REDACTED:807— openai._codex_ws_text_shape has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
openai._restore_codex_additional_tools (cyclomatic 20) REDACTED:1060— openai._restore_codex_additional_tools has cyclomatic complexity 20 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
openai._responses_input_to_learner_messages (cyclomatic 20) REDACTED:1330— openai._responses_input_to_learner_messages has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
astgrep._open_regular_file_under_root (cyclomatic 20) headroom/proxy/interceptors/astgrep.py:188— astgrep._open_regular_file_under_root has cyclomatic complexity 20 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
content_detector.detect_content_type (cyclomatic 20) headroom/transforms/content_detector.py:182— content_detector.detect_content_type has cyclomatic complexity 20 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ContentRouter._compress_mixed (cyclomatic 20) headroom/transforms/content_router.py:3674— ContentRouter._compress_mixed has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
format.openAIToAnthropic (cyclomatic 20) sdk/typescript/src/utils/format.ts:286— format.openAIToAnthropic has cyclomatic complexity 20 (threshold 15). Of this number, 18 points are the body's own statements and 2 belong to one function literal inside it that branches. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
CompressionStore.process_pending_feedback (cyclomatic 19) headroom/cache/compression_store.py:1096— CompressionStore.process_pending_feedback has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
doctor.doctor (cyclomatic 19) headroom/cli/doctor.py:1279— doctor.doctor has cyclomatic complexity 19 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
memory.list_memories (cyclomatic 19) headroom/cli/memory.py:472— memory.list_memories has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
memory.prune_memories (cyclomatic 19) headroom/cli/memory.py:988— memory.prune_memories has cyclomatic complexity 19 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
memory.reindex_memories (cyclomatic 19) headroom/cli/memory.py:1157— memory.reindex_memories has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
LoCoMoEvaluatorV2._replay_conversation (cyclomatic 19) headroom/evals/memory/runner_v2.py:424— LoCoMoEvaluatorV2._replay_conversation has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BeforeAfterRunner.evaluate_case (cyclomatic 19) headroom/evals/runners/before_after.py:281— BeforeAfterRunner.evaluate_case has cyclomatic complexity 19 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
supervisors.remove_supervisor (cyclomatic 19) REDACTED:839— supervisors.remove_supervisor has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
OpenCodePlugin._scan_session_legacy (cyclomatic 19) headroom/learn/plugins/opencode.py:432— OpenCodePlugin._scan_session_legacy has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HNSWVectorIndex._passes_filter (cyclomatic 19) headroom/memory/adapters/hnsw.py:691— HNSWVectorIndex._passes_filter has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SQLiteVectorIndex._passes_filter (cyclomatic 19) headroom/memory/adapters/sqlite_vector.py:792— SQLiteVectorIndex._passes_filter has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
traffic_learner._refine_error_recovery (cyclomatic 19) headroom/memory/traffic_learner.py:2077— traffic_learner._refine_error_recovery has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
recovery._merge_database (cyclomatic 19) headroom/providers/codex/recovery.py:528— recovery._merge_database has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
memory_query_policy.extract_memory_query_sources (cyclomatic 19) headroom/proxy/memory_query_policy.py:74— memory_query_policy.extract_memory_query_sources has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HeadroomProxy._start_kompress_background_warmup (cyclomatic 19) REDACTED:2096— HeadroomProxy._start_kompress_background_warmup has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compaction_codec._iter_rows (cyclomatic 19) headroom/transforms/compaction_codec.py:146— compaction_codec._iter_rows has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ContentRouter._net_cost_allows (cyclomatic 19) headroom/transforms/content_router.py:6187— ContentRouter._net_cost_allows has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
content_router._detect_content (cyclomatic 19) headroom/transforms/content_router.py:1376— content_router._detect_content has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
thinking_compactor.compact_reasoning_openai_chat (cyclomatic 19) REDACTED:246— thinking_compactor.compact_reasoning_openai_chat has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
convert.normalizeAssistantContent (cyclomatic 19) plugins/openclaw/src/convert.ts:478— convert.normalizeAssistantContent has cyclomatic complexity 19 (threshold 15). Most of this is not in the body itself: 5 of the 19 points are its own statements and the rest belongs to one function literal inside it that branches (line 480). The decisions are inside the literal, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literal's work into a named function or method at the enclosing scope and have the literal call it, then reduce whichever part then reads as the largest.
ProxyManager.buildLaunchSpecs (cyclomatic 19) plugins/openclaw/src/proxy-manager.ts:214— ProxyManager.buildLaunchSpecs has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
rollupHour (cyclomatic 19) deploy/beacon/worker.js:388— rollupHour has cyclomatic complexity 19 (threshold 15). Of this number, 18 points are the body's own statements and 1 belongs to 3 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
agent_savings.proxy_pipeline_kwargs (cyclomatic 18) headroom/agent_savings.py:288— agent_savings.proxy_pipeline_kwargs has cyclomatic complexity 18 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
codex.audit_codex (cyclomatic 18) headroom/audit/codex.py:163— codex.audit_codex has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
LiteLLMBackend.map_model_id (cyclomatic 18) headroom/backends/litellm.py:920— LiteLLMBackend.map_model_id has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
LiteLLMBackend.stream_openai_message (cyclomatic 18) headroom/backends/litellm.py:2032— LiteLLMBackend.stream_openai_message has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
OpenAICacheOptimizer.optimize (cyclomatic 18) headroom/cache/openai.py:166— OpenAICacheOptimizer.optimize has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
recover.recover_codex (cyclomatic 18) headroom/cli/recover.py:39— recover.recover_codex has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
wrap._remove_claude_wrap_selfheal_hook (cyclomatic 18) headroom/cli/wrap.py:2118— wrap._remove_claude_wrap_selfheal_hook has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
JSONStructureHandler._extract_mask (cyclomatic 18) headroom/compression/handlers/json_handler.py:119— JSONStructureHandler._extract_mask has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
comprehensive_benchmark.parse_lm_eval_results (cyclomatic 18) headroom/evals/comprehensive_benchmark.py:293— comprehensive_benchmark.parse_lm_eval_results has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SuiteRunner.run (cyclomatic 18) headroom/evals/suite_runner.py:487— SuiteRunner.run has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ImageCompressor._ocr_extract (cyclomatic 18) headroom/image/compressor.py:419— ImageCompressor._ocr_extract has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
runtime._read_proc_metadata (cyclomatic 18) headroom/install/runtime.py:276— runtime._read_proc_metadata has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HeadroomAgnoModel._convert_messages_to_openai (cyclomatic 18) headroom/integrations/agno/model.py:286— HeadroomAgnoModel._convert_messages_to_openai has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HeadroomRunnable._optimize (cyclomatic 18) headroom/integrations/langchain/chat_model.py:857— HeadroomRunnable._optimize has cyclomatic complexity 18 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
MemorySystem.handle_memory_save (cyclomatic 18) headroom/memory/system.py:326— MemorySystem.handle_memory_save has cyclomatic complexity 18 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
BatchHandlerMixin._compress_batch_jsonl (cyclomatic 18) headroom/proxy/handlers/batch.py:1133— BatchHandlerMixin._compress_batch_jsonl has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
turn_hooks.run_request_hooks (cyclomatic 18) headroom/proxy/turn_hooks.py:256— turn_hooks.run_request_hooks has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
session_tracking.compute_window_tokens (cyclomatic 18) headroom/subscription/session_tracking.py:123— session_tracking.compute_window_tokens has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compression_batches.compress_batch_with_router (cyclomatic 18) headroom/transforms/compression_batches.py:240— compression_batches.compress_batch_with_router has cyclomatic complexity 18 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
update_check._select_latest (cyclomatic 18) REDACTED:153— update_check._select_latest has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
CodeAwareCompressor::analyze_symbol_importance (cyclomatic 18) crates/headroom-core/src/transforms/code_compressor.rs:1059— CodeAwareCompressor::analyze_symbol_importance has cyclomatic complexity 18 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ProviderPath::classify (cyclomatic 18) crates/headroom-simulators/src/domain.rs:28— ProviderPath::classify has cyclomatic complexity 18 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
dashboard.html.dashboard.renderTransformationCard (cyclomatic 18) headroom/dashboard/templates/dashboard.html:2292— dashboard.html.dashboard.renderTransformationCard has cyclomatic complexity 18 (threshold 15). Of this number, 17 points are the body's own statements and 1 belongs to one function literal inside it that branches. To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
compression_store._create_default_ccr_backend (cyclomatic 17) headroom/cache/compression_store.py:1230— compression_store._create_default_ccr_backend has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
prefix_tracker._classify_history_canonical (cyclomatic 17) REDACTED:333— prefix_tracker._classify_history_canonical has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
doctor.check_savings (cyclomatic 17) headroom/cli/doctor.py:1005— doctor.check_savings has cyclomatic complexity 17 (threshold 15). To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
memory.show_memory (cyclomatic 17) headroom/cli/memory.py:579— memory.show_memory has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
memory.edit_memory (cyclomatic 17) headroom/cli/memory.py:723— memory.edit_memory has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
wrap._setup_serena_mcp (cyclomatic 17) headroom/cli/wrap.py:2885— wrap._setup_serena_mcp has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
wrap._warn_proxy_mode_mismatch (cyclomatic 17) headroom/cli/wrap.py:9773— wrap._warn_proxy_mode_mismatch has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
comprehensive_benchmark.run_lm_eval (cyclomatic 17) headroom/evals/comprehensive_benchmark.py:174— comprehensive_benchmark.run_lm_eval has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
CompressionEvaluator.evaluate_case (cyclomatic 17) headroom/evals/core.py:280— CompressionEvaluator.evaluate_case has cyclomatic complexity 17 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
providers.get_headroom_provider (cyclomatic 17) headroom/integrations/agno/providers.py:64— providers.get_headroom_provider has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
chat_model.optimize_messages (cyclomatic 17) headroom/integrations/langchain/chat_model.py:946— chat_model.optimize_messages has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
analyzer._call_cli_llm (cyclomatic 17) headroom/learn/analyzer.py:755— analyzer._call_cli_llm has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ledger._read_ledger (cyclomatic 17) headroom/mcp_registry/ledger.py:123— ledger._read_ledger has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
hermes.compress_scoped_passthrough_body (cyclomatic 17) headroom/providers/hermes.py:89— hermes.compress_scoped_passthrough_body has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
CostTracker.record_tokens (cyclomatic 17) headroom/proxy/cost.py:1115— CostTracker.record_tokens has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
GeminiHandlerMixin._carry_tail_append_into_preserved (cyclomatic 17) headroom/proxy/handlers/gemini.py:229— GeminiHandlerMixin._carry_tail_append_into_preserved has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
openai._drop_undeclared_web_search_calls (cyclomatic 17) REDACTED:1175— openai._drop_undeclared_web_search_calls has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
helpers.apply_session_sticky_ccr_tool (cyclomatic 17) headroom/proxy/helpers.py:2934— helpers.apply_session_sticky_ccr_tool has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
helpers.compute_turn_id (cyclomatic 17) headroom/proxy/helpers.py:3575— helpers.compute_turn_id has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
helpers.inject_tool_search_deferral (cyclomatic 17) headroom/proxy/helpers.py:4240— helpers.inject_tool_search_deferral has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
MemoryHandler._extract_tool_calls (cyclomatic 17) headroom/proxy/memory_handler.py:1068— MemoryHandler._extract_tool_calls has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Headroom.with_provider (cyclomatic 17) headroom/testing/harness.py:658— Headroom.with_provider has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
CodeAwareCompressor._analyze_symbol_importance (cyclomatic 17) headroom/transforms/code_compressor.py:1085— CodeAwareCompressor._analyze_symbol_importance has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
CodeAwareCompressor._extract_structure (cyclomatic 17) headroom/transforms/code_compressor.py:1643— CodeAwareCompressor._extract_structure has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ContentRouter.compress (cyclomatic 17) headroom/transforms/content_router.py:3366— ContentRouter.compress has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SmartCrusher._extract_context_from_messages (cyclomatic 17) headroom/transforms/smart_crusher.py:1218— SmartCrusher._extract_context_from_messages has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
thinking_compactor.compact_thinking_to_text (cyclomatic 17) REDACTED:111— thinking_compactor.compact_thinking_to_text has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
headroom_simulators::domain::default_response (cyclomatic 17) crates/headroom-simulators/src/domain.rs:169— headroom_simulators::domain::default_response has cyclomatic complexity 17 (threshold 15). To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Where every arm is uniform — the same kind of value, with no behaviour of its own — a table keyed by the case is the shorter form; wherever the arms carry different data or different behaviour, keep them as cases, because collapsing those trades an explicit, reviewable set of cases for nothing.
format.anthropicMediaImageUrl (cyclomatic 17) sdk/typescript/src/utils/format.ts:139— format.anthropicMediaImageUrl has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
format.vercelMediaPart (cyclomatic 17) sdk/typescript/src/utils/format.ts:476— format.vercelMediaPart has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
AnyLLMBackend._to_anthropic_response (cyclomatic 16) headroom/backends/anyllm.py:142— AnyLLMBackend._to_anthropic_response has cyclomatic complexity 16 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
litellm._place_system_cache_control (cyclomatic 16) headroom/backends/litellm.py:191— litellm._place_system_cache_control has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
mcp_server._format_session_summary (cyclomatic 16) headroom/ccr/mcp_server.py:117— mcp_server._format_session_summary has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
audit.audit_reads_cmd (cyclomatic 16) headroom/cli/audit.py:38— audit.audit_reads_cmd has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
install._start_deployment (cyclomatic 16) headroom/cli/install.py:157— install._start_deployment has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
savings.savings (cyclomatic 16) headroom/cli/savings.py:160— savings.savings has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
wrap.unwrap_claude (cyclomatic 16) headroom/cli/wrap.py:6901— wrap.unwrap_claude has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
CompressionOnlyRunner.evaluate_tool_schema_compaction (cyclomatic 16) headroom/evals/runners/compression_only.py:562— CompressionOnlyRunner.evaluate_tool_schema_compaction has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HeadroomMCPCompressor.compress (cyclomatic 16) headroom/integrations/mcp/server.py:180— HeadroomMCPCompressor.compress has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
model.optimize_messages (cyclomatic 16) headroom/integrations/strands/model.py:532— model.optimize_messages has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
analyzer._build_digest (cyclomatic 16) headroom/learn/analyzer.py:358— analyzer._build_digest has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
CodexPlugin._scan_json_session (cyclomatic 16) headroom/learn/plugins/codex.py:126— CodexPlugin._scan_json_session has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
traffic_learner._project_for_pattern (cyclomatic 16) headroom/memory/traffic_learner.py:1854— traffic_learner._project_for_pattern has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
AnthropicProvider.get_context_limit (cyclomatic 16) headroom/providers/anthropic.py:837— AnthropicProvider.get_context_limit has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
recovery._merge_pinned_home (cyclomatic 16) headroom/providers/codex/recovery.py:636— recovery._merge_pinned_home has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
extensions.install_all (cyclomatic 16) headroom/proxy/extensions.py:200— extensions.install_all has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
base._build_tool_use_index (cyclomatic 16) headroom/proxy/interceptors/base.py:123— base._build_tool_use_index has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
output_shaper.classify_responses_turn (cyclomatic 16) headroom/proxy/output_shaper.py:467— output_shaper.classify_responses_turn has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
output_turn_policy.classify_turn (cyclomatic 16) headroom/proxy/output_turn_policy.py:28— output_turn_policy.classify_turn has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SavingsTracker.record_request (cyclomatic 16) headroom/proxy/savings_tracker.py:1145— SavingsTracker.record_request has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
server.create_app (cyclomatic 16) REDACTED:3448— server.create_app has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
compression_units.compress_unit_with_router (cyclomatic 16) headroom/transforms/compression_units.py:236— compression_units.compress_unit_with_router has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
content_detector._try_detect_json (cyclomatic 16) headroom/transforms/content_detector.py:363— content_detector._try_detect_json has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
kompress_compressor._load_kompress (cyclomatic 16) headroom/transforms/kompress_compressor.py:1229— kompress_compressor._load_kompress has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
tabular_ingest.parse_fixed_width (cyclomatic 16) headroom/transforms/tabular_ingest.py:117— tabular_ingest.parse_fixed_width has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
SmartCrusherPlanner::plan_top_n (cyclomatic 16) crates/headroom-core/src/transforms/smart_crusher/planning.rs:242— SmartCrusherPlanner::plan_top_n has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
proxy-manager.probeHeadroomProxy (cyclomatic 16) plugins/openclaw/src/proxy-manager.ts:448— proxy-manager.probeHeadroomProxy has cyclomatic complexity 16 (threshold 15). Of this number, 13 points are the body's own statements and 3 belong to one function item inside it that branches. To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
No assertions: execFile(file, null, callback) and execFile(file, callback) still call the callback REDACTED:1430— This method's body runs code, and no assertion call was recognised in it. Recognised by name: Assert*, *Should*/ShouldBe*, Verify, Expect, Throws, Record, Received/DidNotReceive, MustHaveHappened/MustNotHaveHappened, EnsureSuccessStatusCode and *AndEnsure*, in the test body and in the helpers it calls in the test and test-support code (a helper there that throws when its check fails counts as an assertion) — so verification routed through a callback object whose members hold the assertions, or through a harness in production code that fails by throwing, is not visible to this check and is not counted here. Read it as 'no assertion this check knows how to see', and if that is right, add one.
FixmeComment tests/test_search_compressor.py:317— # FIXME: this needs work — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
AnthropicHandlerMixin.handle_anthropic_messages (cognitive 650) REDACTED:1309— AnthropicHandlerMixin.handle_anthropic_messages has cognitive complexity 650 (threshold 15). Drivers by points: if/else 207 (398 pts), boolean chains 106, ternaries 30 (65 pts), error handling 31 (61 pts), loops 7 (20 pts) (nesting depth added 269). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContentRouter.apply (cognitive 435) headroom/transforms/content_router.py:6337— ContentRouter.apply has cognitive complexity 435 (threshold 15). Drivers by points: if/else 134 (327 pts), boolean chains 43, ternaries 13 (34 pts), loops 8 (18 pts), error handling 5 (13 pts) (nesting depth added 232). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
wrap._ensure_proxy_unlocked (cognitive 328) headroom/cli/wrap.py:5091— wrap._ensure_proxy_unlocked has cognitive complexity 328 (threshold 15). Drivers by points: if/else 67 (232 pts), ternaries 12 (49 pts), boolean chains 41, error handling 3 (6 pts) (nesting depth added 205). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
OpenAIHandlerMixin.handle_openai_chat (cognitive 328) REDACTED:3542— OpenAIHandlerMixin.handle_openai_chat has cognitive complexity 328 (threshold 15). Drivers by points: if/else 111 (196 pts), boolean chains 57, ternaries 21 (39 pts), error handling 18 (36 pts) (nesting depth added 121). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAIHandlerMixin.handle_openai_responses_ws (cognitive 303) REDACTED:7782— OpenAIHandlerMixin.handle_openai_responses_ws has cognitive complexity 303 (threshold 15). Drivers by points: if/else 91 (173 pts), ternaries 31 (56 pts), boolean chains 38, error handling 11 (20 pts), loops 9 (16 pts) (nesting depth added 123). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAIHandlerMixin._compress_openai_responses_live_text_units_with_router (cognitive 223) REDACTED:2421— OpenAIHandlerMixin._compress_openai_responses_live_text_units_with_router has cognitive complexity 223 (threshold 15). Drivers by points: if/else 61 (131 pts), loops 21 (41 pts), ternaries 14 (29 pts), boolean chains 20, error handling 2 (nesting depth added 105). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
ContentRouter._process_content_blocks (cognitive 218) headroom/transforms/content_router.py:7900— ContentRouter._process_content_blocks has cognitive complexity 218 (threshold 15). Drivers by points: if/else 46 (158 pts), ternaries 10 (33 pts), boolean chains 26, loops 1 (nesting depth added 135). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
OpenAIHandlerMixin.handle_openai_responses (cognitive 184) REDACTED:6202— OpenAIHandlerMixin.handle_openai_responses has cognitive complexity 184 (threshold 15). Drivers by points: if/else 61 (103 pts), boolean chains 39, ternaries 13 (23 pts), error handling 9 (17 pts), loops 1 (2 pts) (nesting depth added 61). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
GeminiHandlerMixin.handle_gemini_generate_content (cognitive 181) headroom/proxy/handlers/gemini.py:399— GeminiHandlerMixin.handle_gemini_generate_content has cognitive complexity 181 (threshold 15). Drivers by points: if/else 67 (129 pts), boolean chains 17, error handling 8 (13 pts), ternaries 4 (13 pts), loops 3 (9 pts) (nesting depth added 82). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContentRouter._apply_strategy_to_content (cognitive 171) headroom/transforms/content_router.py:4408— ContentRouter._apply_strategy_to_content has cognitive complexity 171 (threshold 15). Drivers by points: if/else 53 (125 pts), boolean chains 21, ternaries 4 (13 pts), error handling 4 (12 pts) (nesting depth added 89). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
format.vercelToOpenAI (cognitive 151) sdk/typescript/src/utils/format.ts:534— format.vercelToOpenAI has cognitive complexity 151 (threshold 15). Drivers by points: ternaries 14 (72 pts), if/else 22 (62 pts), boolean chains 10, loops 3 (7 pts) (nesting depth added 102). Of this number, 141 points are the body's own statements and 10 belong to 3 function literals inside it that branch. To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
helpers.enforce_cache_breakpoint_budget (cognitive 150) headroom/proxy/helpers.py:793— helpers.enforce_cache_breakpoint_budget has cognitive complexity 150 (threshold 15). Drivers by points: if/else 23 (111 pts), loops 6 (26 pts), boolean chains 10, ternaries 1 (3 pts) (nesting depth added 110). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
KompressCompressor.compress_batch (cognitive 140) headroom/transforms/kompress_compressor.py:2285— KompressCompressor.compress_batch has cognitive complexity 140 (threshold 15). Drivers by points: if/else 43 (92 pts), loops 13 (27 pts), ternaries 8 (15 pts), boolean chains 3, error handling 2 (3 pts) (nesting depth added 71). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodeAwareCompressor._compress_function_ast (cognitive 131) headroom/transforms/code_compressor.py:1901— CodeAwareCompressor._compress_function_ast has cognitive complexity 131 (threshold 15). Drivers by points: if/else 40 (92 pts), loops 9 (28 pts), boolean chains 10, ternaries 1 (nesting depth added 71). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
proxy.proxy (cognitive 130) headroom/cli/proxy.py:1218— proxy.proxy has cognitive complexity 130 (threshold 15). Drivers by points: if/else 50 (55 pts), boolean chains 34, ternaries 27 (31 pts), error handling 8 (10 pts) (nesting depth added 11). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
anthropic_wire._response_from_events (cognitive 121) headroom/proxy/anthropic_wire.py:296— anthropic_wire._response_from_events has cognitive complexity 121 (threshold 15). Drivers by points: if/else 27 (82 pts), ternaries 5 (16 pts), boolean chains 10, loops 3 (9 pts), error handling 1 (4 pts) (nesting depth added 75). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
maturation.simulate_maturation (cognitive 117) headroom/audit/maturation.py:69— maturation.simulate_maturation has cognitive complexity 117 (threshold 15). Drivers by points: if/else 20 (78 pts), loops 8 (23 pts), boolean chains 11, error handling 2 (5 pts) (nesting depth added 76). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
learn.learn (cognitive 113) headroom/cli/learn.py:143— learn.learn has cognitive complexity 113 (threshold 15). Drivers by points: if/else 30 (65 pts), loops 8 (24 pts), boolean chains 9, ternaries 3 (8 pts), error handling 3 (7 pts) (nesting depth added 60). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LiteLLMBackend.stream_message (cognitive 105) headroom/backends/litellm.py:1397— LiteLLMBackend.stream_message has cognitive complexity 105 (threshold 15). Drivers by points: if/else 34 (66 pts), boolean chains 20, loops 4 (9 pts), ternaries 2 (9 pts), error handling 1 (nesting depth added 44). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAIHandlerMixin.handle_compress (cognitive 105) REDACTED:11139— OpenAIHandlerMixin.handle_compress has cognitive complexity 105 (threshold 15). Drivers by points: if/else 36 (44 pts), ternaries 16 (26 pts), boolean chains 19, error handling 10 (16 pts) (nesting depth added 24). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
dashboard.html.dashboard (cognitive 103) headroom/dashboard/templates/dashboard.html:2056— dashboard.html.dashboard has cognitive complexity 103 (threshold 15). Drivers by points: boolean chains 74, if/else 16, loops 4 (6 pts), ternaries 6, error handling 1 (nesting depth added 2). Of this number, 98 points are the body's own statements and 5 belong to 4 function literals inside it that branch. To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
format.openAIToVercel (cognitive 103) sdk/typescript/src/utils/format.ts:672— format.openAIToVercel has cognitive complexity 103 (threshold 15). Drivers by points: if/else 27 (69 pts), error handling 3 (16 pts), loops 3 (9 pts), ternaries 1 (5 pts), boolean chains 4 (nesting depth added 65). Of this number, 95 points are the body's own statements and 8 belong to one function literal inside it that branches. To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
KompressCompressor.compress (cognitive 101) headroom/transforms/kompress_compressor.py:1924— KompressCompressor.compress has cognitive complexity 101 (threshold 15). Drivers by points: if/else 35 (73 pts), loops 5 (12 pts), ternaries 6 (9 pts), boolean chains 5, error handling 2 (nesting depth added 48). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LiteLLMBackend._convert_messages_for_litellm (cognitive 95) headroom/backends/litellm.py:1003— LiteLLMBackend._convert_messages_for_litellm has cognitive complexity 95 (threshold 15). Drivers by points: if/else 19 (74 pts), loops 4 (14 pts), boolean chains 4, ternaries 1 (3 pts) (nesting depth added 67). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
reads._audit_session (cognitive 93) headroom/audit/reads.py:159— reads._audit_session has cognitive complexity 93 (threshold 15). Drivers by points: if/else 20 (65 pts), boolean chains 17, loops 5 (9 pts), error handling 1 (2 pts) (nesting depth added 50). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
JSONStructureHandler._tokenize_json (cognitive 88) headroom/compression/handlers/json_handler.py:254— JSONStructureHandler._tokenize_json has cognitive complexity 88 (threshold 15). Drivers by points: if/else 21 (54 pts), loops 7 (21 pts), boolean chains 13 (nesting depth added 47). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
cost.build_prefix_cache_stats (cognitive 88) headroom/proxy/cost.py:243— cost.build_prefix_cache_stats has cognitive complexity 88 (threshold 15). Drivers by points: if/else 16 (46 pts), ternaries 10 (16 pts), boolean chains 13, loops 4 (7 pts), error handling 1 (6 pts) (nesting depth added 44). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
StreamingMixin._parse_sse_usage_from_buffer (cognitive 86) REDACTED:307— StreamingMixin._parse_sse_usage_from_buffer has cognitive complexity 86 (threshold 15). Drivers by points: if/else 18 (66 pts), loops 3 (11 pts), boolean chains 4, ternaries 2 (3 pts), error handling 1 (2 pts) (nesting depth added 58). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
wrap.claude (cognitive 85) headroom/cli/wrap.py:6373— wrap.claude has cognitive complexity 85 (threshold 15). Drivers by points: if/else 35 (47 pts), boolean chains 15, ternaries 7 (14 pts), loops 2 (5 pts), error handling 3 (4 pts) (nesting depth added 23). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
PrometheusMetrics.export (cognitive 85) headroom/proxy/prometheus_metrics.py:1427— PrometheusMetrics.export has cognitive complexity 85 (threshold 15). Drivers by points: loops 34 (66 pts), if/else 14 (16 pts), ternaries 3 (nesting depth added 34). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
parser.find_tool_units (cognitive 83) REDACTED:527— parser.find_tool_units has cognitive complexity 83 (threshold 15). Drivers by points: if/else 17 (68 pts), loops 5 (12 pts), boolean chains 3 (nesting depth added 58). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
ImageCompressor._apply_compression (cognitive 82) headroom/image/compressor.py:539— ImageCompressor._apply_compression has cognitive complexity 82 (threshold 15). Drivers by points: if/else 19 (57 pts), error handling 3 (17 pts), boolean chains 5, loops 2 (3 pts) (nesting depth added 53). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
format.openAIToGemini (cognitive 82) sdk/typescript/src/utils/format.ts:1005— format.openAIToGemini has cognitive complexity 82 (threshold 15). Drivers by points: if/else 15 (42 pts), loops 4 (15 pts), ternaries 4 (13 pts), error handling 2 (8 pts), boolean chains 4 (nesting depth added 53). Of this number, 76 points are the body's own statements and 6 belong to 3 function literals inside it that branch. To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
maturation.simulate_codex_maturation (cognitive 80) headroom/audit/maturation.py:176— maturation.simulate_codex_maturation has cognitive complexity 80 (threshold 15). Drivers by points: if/else 15 (52 pts), loops 6 (14 pts), error handling 3 (9 pts), boolean chains 5 (nesting depth added 51). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
helpers.strip_unsupported_tool_search_blocks (cognitive 79) headroom/proxy/helpers.py:4441— helpers.strip_unsupported_tool_search_blocks has cognitive complexity 79 (threshold 15). Drivers by points: if/else 15 (49 pts), boolean chains 14, loops 4 (10 pts), ternaries 4 (6 pts) (nesting depth added 42). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
format.detectFormat (cognitive 79) sdk/typescript/src/utils/format.ts:39— format.detectFormat has cognitive complexity 79 (threshold 15). Drivers by points: if/else 17 (57 pts), boolean chains 17, loops 2 (4 pts), ternaries 1 (nesting depth added 42). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContentRouter._try_ml_compressor (cognitive 77) headroom/transforms/content_router.py:5181— ContentRouter._try_ml_compressor has cognitive complexity 77 (threshold 15). Drivers by points: if/else 22 (47 pts), boolean chains 12, error handling 3 (11 pts), ternaries 4 (7 pts) (nesting depth added 36). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
helpers.relocate_system_messages_to_top_level (cognitive 76) headroom/proxy/helpers.py:1110— helpers.relocate_system_messages_to_top_level has cognitive complexity 76 (threshold 15). Drivers by points: if/else 20 (43 pts), boolean chains 13, ternaries 4 (11 pts), loops 6 (9 pts) (nesting depth added 33). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
StreamingMixin._continue_memory_tool_stream (cognitive 75) REDACTED:522— StreamingMixin._continue_memory_tool_stream has cognitive complexity 75 (threshold 15). Drivers by points: if/else 18 (41 pts), loops 7 (17 pts), boolean chains 9, ternaries 4 (7 pts), error handling 1 (nesting depth added 36). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomProxy.startup (cognitive 75) REDACTED:2204— HeadroomProxy.startup has cognitive complexity 75 (threshold 15). Drivers by points: if/else 44 (55 pts), ternaries 6 (7 pts), boolean chains 5, error handling 3 (5 pts), loops 2 (3 pts) (nesting depth added 15). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
stream_output_tokens.extract_stream_text (cognitive 73) headroom/proxy/stream_output_tokens.py:63— stream_output_tokens.extract_stream_text has cognitive complexity 73 (threshold 15). Drivers by points: if/else 13 (43 pts), loops 5 (17 pts), ternaries 2 (12 pts), boolean chains 1 (nesting depth added 52). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CCRToolInjector.scan_for_markers (cognitive 72) headroom/ccr/tool_injection.py:287— CCRToolInjector.scan_for_markers has cognitive complexity 72 (threshold 15). Drivers by points: if/else 10 (50 pts), loops 5 (21 pts), boolean chains 1 (nesting depth added 56). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
gateway_turn.handle_compress_response (cognitive 72) headroom/proxy/gateway_turn.py:1607— gateway_turn.handle_compress_response has cognitive complexity 72 (threshold 15). Drivers by points: if/else 27 (37 pts), boolean chains 16, ternaries 9 (14 pts), error handling 3 (5 pts) (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnthropicHandlerMixin.handle_anthropic_batch_create (cognitive 70) REDACTED:6236— AnthropicHandlerMixin.handle_anthropic_batch_create has cognitive complexity 70 (threshold 15). Drivers by points: if/else 23 (44 pts), ternaries 6 (10 pts), boolean chains 6, error handling 4 (6 pts), loops 2 (4 pts) (nesting depth added 29). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
format.anthropicToOpenAI (cognitive 70) sdk/typescript/src/utils/format.ts:190— format.anthropicToOpenAI has cognitive complexity 70 (threshold 15). Drivers by points: if/else 14 (45 pts), ternaries 3 (16 pts), loops 2 (5 pts), boolean chains 4 (nesting depth added 47). Of this number, 57 points are the body's own statements and 13 belong to 7 function literals inside it that branch. To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
GeminiPlugin._parse_messages (cognitive 68) headroom/learn/plugins/gemini.py:201— GeminiPlugin._parse_messages has cognitive complexity 68 (threshold 15). Drivers by points: if/else 17 (58 pts), ternaries 1 (5 pts), loops 2 (3 pts), boolean chains 2 (nesting depth added 46). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
wrap.copilot (cognitive 66) headroom/cli/wrap.py:7056— wrap.copilot has cognitive complexity 66 (threshold 15). Drivers by points: if/else 26 (46 pts), ternaries 4 (12 pts), boolean chains 8 (nesting depth added 28). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.parse_message_to_blocks (cognitive 66) REDACTED:209— parser.parse_message_to_blocks has cognitive complexity 66 (threshold 15). Drivers by points: if/else 15 (31 pts), ternaries 5 (15 pts), loops 4 (9 pts), boolean chains 8, error handling 1 (3 pts) (nesting depth added 33). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BatchHandlerMixin.handle_google_batch_create (cognitive 66) headroom/proxy/handlers/batch.py:33— BatchHandlerMixin.handle_google_batch_create has cognitive complexity 66 (threshold 15). Drivers by points: if/else 22 (41 pts), loops 4 (9 pts), error handling 4 (6 pts), boolean chains 5, ternaries 3 (5 pts) (nesting depth added 28). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContentRouter._build_tool_name_map (cognitive 65) headroom/transforms/content_router.py:6116— ContentRouter._build_tool_name_map has cognitive complexity 65 (threshold 15). Drivers by points: if/else 13 (55 pts), loops 3 (6 pts), boolean chains 4 (nesting depth added 45). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
session._fold_extra (cognitive 64) REDACTED:1385— session._fold_extra has cognitive complexity 64 (threshold 15). Drivers by points: if/else 22 (38 pts), boolean chains 12, loops 7 (11 pts), error handling 1 (3 pts) (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContentRouter._compress_block_content (cognitive 64) headroom/transforms/content_router.py:8392— ContentRouter._compress_block_content has cognitive complexity 64 (threshold 15). Drivers by points: if/else 24 (43 pts), boolean chains 14, ternaries 4 (7 pts) (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ToolIntelligenceNetwork.record_retrieval (cognitive 63) headroom/telemetry/toin.py:974— ToolIntelligenceNetwork.record_retrieval has cognitive complexity 63 (threshold 15). Drivers by points: if/else 21 (46 pts), loops 4 (10 pts), ternaries 3 (5 pts), boolean chains 2 (nesting depth added 33). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
TiktokenCounter.count_messages (cognitive 63) headroom/tokenizers/tiktoken_counter.py:283— TiktokenCounter.count_messages has cognitive complexity 63 (threshold 15). Drivers by points: if/else 12 (48 pts), loops 4 (12 pts), boolean chains 3 (nesting depth added 44). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
convert.agentToOpenAI (cognitive 63) plugins/openclaw/src/convert.ts:29— convert.agentToOpenAI has cognitive complexity 63 (threshold 15). Drivers by points: ternaries 8 (31 pts), if/else 10 (25 pts), loops 2 (5 pts), boolean chains 2 (nesting depth added 41). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
BeforeAfterRunner._check_ground_truth_bfcl (cognitive 62) headroom/evals/runners/before_after.py:210— BeforeAfterRunner._check_ground_truth_bfcl has cognitive complexity 62 (threshold 15). Drivers by points: if/else 9 (34 pts), loops 5 (15 pts), error handling 2 (6 pts), ternaries 1 (5 pts), boolean chains 2 (nesting depth added 43). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomProxy.__init__ (cognitive 62) REDACTED:1064— HeadroomProxy.__init__ has cognitive complexity 62 (threshold 15). Drivers by points: if/else 28 (36 pts), ternaries 11 (12 pts), boolean chains 8, error handling 4 (6 pts) (nesting depth added 11). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
ReadMaturationManager._scan_activity (cognitive 62) headroom/transforms/read_maturation.py:275— ReadMaturationManager._scan_activity has cognitive complexity 62 (threshold 15). Drivers by points: if/else 15 (49 pts), loops 3 (6 pts), boolean chains 4, error handling 1 (3 pts) (nesting depth added 39). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SmartCrusher.apply (cognitive 62) headroom/transforms/smart_crusher.py:1279— SmartCrusher.apply has cognitive complexity 62 (threshold 15). Drivers by points: if/else 15 (53 pts), boolean chains 5, loops 2 (4 pts) (nesting depth added 40). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
prefix_tracker.normalize_message_cache_control (cognitive 61) REDACTED:963— prefix_tracker.normalize_message_cache_control has cognitive complexity 61 (threshold 15). Drivers by points: if/else 13 (31 pts), ternaries 7 (14 pts), boolean chains 9, loops 3 (7 pts) (nesting depth added 29). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
base.apply_to_messages (cognitive 61) headroom/proxy/interceptors/base.py:193— base.apply_to_messages has cognitive complexity 61 (threshold 15). Drivers by points: if/else 16 (40 pts), error handling 3 (10 pts), loops 4 (6 pts), boolean chains 3, ternaries 1 (2 pts) (nesting depth added 34). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.parse_messages (cognitive 60) REDACTED:393— parser.parse_messages has cognitive complexity 60 (threshold 15). Drivers by points: if/else 15 (40 pts), loops 10 (13 pts), boolean chains 7 (nesting depth added 28). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAIHandlerMixin._compress_openai_responses_payload (cognitive 60) REDACTED:3094— OpenAIHandlerMixin._compress_openai_responses_payload has cognitive complexity 60 (threshold 15). Drivers by points: if/else 16 (27 pts), error handling 7 (16 pts), ternaries 6 (11 pts), boolean chains 5, loops 1 (nesting depth added 25). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAIHandlerMixin.handle_passthrough (cognitive 60) REDACTED:12290— OpenAIHandlerMixin.handle_passthrough has cognitive complexity 60 (threshold 15). Drivers by points: if/else 23 (32 pts), boolean chains 11, error handling 5 (9 pts), ternaries 3 (5 pts), loops 1 (3 pts) (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
convert.openAIToAgent (cognitive 60) plugins/openclaw/src/convert.ts:155— convert.openAIToAgent has cognitive complexity 60 (threshold 15). Drivers by points: ternaries 12 (36 pts), if/else 6 (14 pts), error handling 1 (5 pts), loops 2 (5 pts) (nesting depth added 39). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
gateway_responses.build_view (cognitive 59) headroom/proxy/gateway_responses.py:157— gateway_responses.build_view has cognitive complexity 59 (threshold 15). Drivers by points: if/else 15 (37 pts), ternaries 3 (9 pts), loops 3 (8 pts), boolean chains 5 (nesting depth added 33). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContentRouter._cross_turn_dedup_messages (cognitive 59) headroom/transforms/content_router.py:7753— ContentRouter._cross_turn_dedup_messages has cognitive complexity 59 (threshold 15). Drivers by points: if/else 15 (37 pts), boolean chains 9, ternaries 2 (7 pts), loops 3 (5 pts), error handling 1 (nesting depth added 29). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
config_toml.root_assignment_lines (cognitive 58) headroom/providers/codex/config_toml.py:51— config_toml.root_assignment_lines has cognitive complexity 58 (threshold 15). Drivers by points: if/else 11 (33 pts), loops 4 (12 pts), boolean chains 8, ternaries 1 (5 pts) (nesting depth added 34). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAIHandlerMixin._ws_http_fallback (cognitive 58) REDACTED:10793— OpenAIHandlerMixin._ws_http_fallback has cognitive complexity 58 (threshold 15). Drivers by points: if/else 14 (33 pts), loops 5 (11 pts), error handling 4 (9 pts), ternaries 2 (3 pts), boolean chains 2 (nesting depth added 31). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
helpers.count_cache_breakpoints (cognitive 58) headroom/proxy/helpers.py:439— helpers.count_cache_breakpoints has cognitive complexity 58 (threshold 15). Drivers by points: if/else 14 (44 pts), loops 2 (6 pts), boolean chains 4, ternaries 2 (4 pts) (nesting depth added 36). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
CompressionStore.process_pending_feedback (cognitive 57) headroom/cache/compression_store.py:1096— CompressionStore.process_pending_feedback has cognitive complexity 57 (threshold 15). Drivers by points: if/else 11 (38 pts), error handling 3 (10 pts), loops 3 (8 pts), boolean chains 1 (nesting depth added 39). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
PrometheusMetrics.record_request (cognitive 57) headroom/proxy/prometheus_metrics.py:867— PrometheusMetrics.record_request has cognitive complexity 57 (threshold 15). Drivers by points: if/else 22 (32 pts), boolean chains 16, loops 3 (5 pts), ternaries 3 (4 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
format.geminiToOpenAI (cognitive 57) sdk/typescript/src/utils/format.ts:880— format.geminiToOpenAI has cognitive complexity 57 (threshold 15). Drivers by points: if/else 14 (38 pts), ternaries 3 (11 pts), boolean chains 4, loops 2 (4 pts) (nesting depth added 34). Of this number, 46 points are the body's own statements and 11 belong to 6 function literals inside it that branch. To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
AnyLLMBackend.stream_message (cognitive 56) headroom/backends/anyllm.py:279— AnyLLMBackend.stream_message has cognitive complexity 56 (threshold 15). Drivers by points: if/else 20 (44 pts), loops 3 (5 pts), ternaries 1 (4 pts), boolean chains 2, error handling 1 (nesting depth added 29). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
StreamingCCRHandler._reconstruct_openai_response (cognitive 56) headroom/ccr/response_handler.py:884— StreamingCCRHandler._reconstruct_openai_response has cognitive complexity 56 (threshold 15). Drivers by points: if/else 18 (47 pts), loops 3 (6 pts), boolean chains 3 (nesting depth added 32). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
learn._run_verbosity (cognitive 56) headroom/cli/learn.py:650— learn._run_verbosity has cognitive complexity 56 (threshold 15). Drivers by points: if/else 20 (33 pts), boolean chains 10, ternaries 4 (9 pts), loops 2 (4 pts) (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
helpers.walk_cache_control (cognitive 56) headroom/proxy/helpers.py:572— helpers.walk_cache_control has cognitive complexity 56 (threshold 15). Drivers by points: if/else 11 (30 pts), loops 5 (16 pts), boolean chains 5, ternaries 1 (5 pts) (nesting depth added 34). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
format.openAIToAnthropic (cognitive 56) sdk/typescript/src/utils/format.ts:286— format.openAIToAnthropic has cognitive complexity 56 (threshold 15). Drivers by points: if/else 15 (43 pts), loops 3 (9 pts), ternaries 1 (3 pts), boolean chains 1 (nesting depth added 36). Of this number, 48 points are the body's own statements and 8 belong to one function literal inside it that branches. To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
StreamingMixin._finalize_stream_response (cognitive 55) REDACTED:886— StreamingMixin._finalize_stream_response has cognitive complexity 55 (threshold 15). Drivers by points: if/else 14 (26 pts), boolean chains 17, ternaries 6 (12 pts) (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
settings_store._coerce (cognitive 54) headroom/settings_store.py:838— settings_store._coerce has cognitive complexity 54 (threshold 15). Drivers by points: if/else 22 (38 pts), ternaries 4 (7 pts), boolean chains 6, error handling 1 (3 pts) (nesting depth added 21). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap.openclaw (cognitive 53) headroom/cli/wrap.py:8699— wrap.openclaw has cognitive complexity 53 (threshold 15). Drivers by points: if/else 26 (35 pts), boolean chains 13, ternaries 3 (5 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
StreamingMixin._stream_response_inner (cognitive 53) REDACTED:1235— StreamingMixin._stream_response_inner has cognitive complexity 53 (threshold 15). Drivers by points: if/else 13 (20 pts), boolean chains 13, error handling 6 (13 pts), ternaries 4 (6 pts), loops 1 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
helpers.strip_unsupported_ccr_retrieve_blocks (cognitive 53) headroom/proxy/helpers.py:4589— helpers.strip_unsupported_ccr_retrieve_blocks has cognitive complexity 53 (threshold 15). Drivers by points: if/else 15 (35 pts), boolean chains 6, loops 4 (6 pts), ternaries 4 (6 pts) (nesting depth added 24). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodeAwareCompressor._compress_class_ast (cognitive 53) headroom/transforms/code_compressor.py:2186— CodeAwareCompressor._compress_class_ast has cognitive complexity 53 (threshold 15). Drivers by points: if/else 19 (39 pts), boolean chains 8, loops 4 (6 pts) (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap._remove_claude_managed_hooks (cognitive 52) headroom/cli/wrap.py:1400— wrap._remove_claude_managed_hooks has cognitive complexity 52 (threshold 15). Drivers by points: if/else 20 (44 pts), loops 2 (5 pts), boolean chains 2, error handling 1 (nesting depth added 27). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
verbosity._parse_session (cognitive 52) headroom/learn/verbosity.py:202— verbosity._parse_session has cognitive complexity 52 (threshold 15). Drivers by points: if/else 8 (23 pts), ternaries 4 (15 pts), loops 3 (6 pts), boolean chains 5, error handling 2 (3 pts) (nesting depth added 30). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
ToolIntelligenceNetwork._merge_patterns (cognitive 52) headroom/telemetry/toin.py:1499— ToolIntelligenceNetwork._merge_patterns has cognitive complexity 52 (threshold 15). Drivers by points: if/else 26 (42 pts), loops 8, ternaries 1 (2 pts) (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
content_detector._try_detect_structured_config (cognitive 51) headroom/transforms/content_detector.py:932— content_detector._try_detect_structured_config has cognitive complexity 51 (threshold 15). Drivers by points: if/else 25 (40 pts), boolean chains 9, loops 1 (2 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
server._build_agent_usage_summary (cognitive 50) REDACTED:341— server._build_agent_usage_summary has cognitive complexity 50 (threshold 15). Drivers by points: if/else 10 (19 pts), boolean chains 11, loops 6 (10 pts), ternaries 6 (10 pts) (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
TransformPipeline.apply (cognitive 50) REDACTED:263— TransformPipeline.apply has cognitive complexity 50 (threshold 15). Drivers by points: if/else 18 (25 pts), ternaries 6 (11 pts), boolean chains 7, error handling 3 (6 pts), loops 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAICacheOptimizer.optimize (cognitive 49) headroom/cache/openai.py:166— OpenAICacheOptimizer.optimize has cognitive complexity 49 (threshold 15). Drivers by points: if/else 13 (42 pts), loops 2 (5 pts), boolean chains 2 (nesting depth added 32). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
SessionTrackerStore.resolve_tracker (cognitive 49) REDACTED:1876— SessionTrackerStore.resolve_tracker has cognitive complexity 49 (threshold 15). Drivers by points: if/else 19 (35 pts), boolean chains 9, loops 2 (3 pts), ternaries 1 (2 pts) (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._load_custom_model_config (cognitive 49) headroom/providers/openai.py:187— openai._load_custom_model_config has cognitive complexity 49 (threshold 15). Drivers by points: if/else 17 (36 pts), loops 3 (9 pts), error handling 2 (4 pts) (nesting depth added 27). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LoCoMoEvaluatorV2._replay_conversation (cognitive 48) headroom/evals/memory/runner_v2.py:424— LoCoMoEvaluatorV2._replay_conversation has cognitive complexity 48 (threshold 15). Drivers by points: if/else 8 (25 pts), error handling 2 (7 pts), loops 3 (6 pts), ternaries 1 (6 pts), boolean chains 4 (nesting depth added 30). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
TelemetryCollector._create_field_distribution (cognitive 48) headroom/telemetry/collector.py:488— TelemetryCollector._create_field_distribution has cognitive complexity 48 (threshold 15). Drivers by points: if/else 17 (40 pts), boolean chains 7, loops 1 (nesting depth added 23). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
comprehensive_benchmark.parse_lm_eval_results (cognitive 47) headroom/evals/comprehensive_benchmark.py:293— comprehensive_benchmark.parse_lm_eval_results has cognitive complexity 47 (threshold 15). Drivers by points: if/else 6 (20 pts), ternaries 5 (18 pts), loops 3 (6 pts), boolean chains 3 (nesting depth added 30). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
analyzer._call_claude_cli_streaming (cognitive 47) headroom/learn/analyzer.py:869— analyzer._call_claude_cli_streaming has cognitive complexity 47 (threshold 15). Drivers by points: if/else 13 (31 pts), error handling 6 (13 pts), boolean chains 2, loops 1 (nesting depth added 25). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
OpenCodePlugin._scan_session_v2 (cognitive 47) headroom/learn/plugins/opencode.py:341— OpenCodePlugin._scan_session_v2 has cognitive complexity 47 (threshold 15). Drivers by points: if/else 6 (15 pts), ternaries 5 (15 pts), boolean chains 7, error handling 2 (7 pts), loops 2 (3 pts) (nesting depth added 25). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContentRouter.eager_load_compressors (cognitive 47) headroom/transforms/content_router.py:5783— ContentRouter.eager_load_compressors has cognitive complexity 47 (threshold 15). Drivers by points: if/else 19 (32 pts), error handling 5 (11 pts), loops 1 (4 pts) (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
PrefixCacheTracker._estimate_message_tokens (cognitive 46) REDACTED:1666— PrefixCacheTracker._estimate_message_tokens has cognitive complexity 46 (threshold 15). Drivers by points: if/else 11 (38 pts), loops 3 (6 pts), boolean chains 2 (nesting depth added 30). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
session._fold (cognitive 46) REDACTED:1277— session._fold has cognitive complexity 46 (threshold 15). Drivers by points: boolean chains 18, if/else 9 (15 pts), loops 4 (6 pts), error handling 2 (4 pts), ternaries 2 (3 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
clean (cognitive 46) deploy/beacon/worker.js:207— clean has cognitive complexity 46 (threshold 15). Drivers by points: if/else 13 (19 pts), ternaries 9 (19 pts), boolean chains 5, loops 2 (3 pts) (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
codex.audit_codex (cognitive 45) headroom/audit/codex.py:163— codex.audit_codex has cognitive complexity 45 (threshold 15). Drivers by points: if/else 9 (31 pts), error handling 3 (9 pts), loops 2 (3 pts), boolean chains 2 (nesting depth added 29). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
SQLiteMemoryStore._build_query_conditions (cognitive 45) headroom/memory/adapters/sqlite.py:446— SQLiteMemoryStore._build_query_conditions has cognitive complexity 45 (threshold 15). Drivers by points: if/else 25 (37 pts), loops 3 (6 pts), boolean chains 2 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LocalBackend.search_memories (cognitive 45) headroom/memory/backends/local.py:424— LocalBackend.search_memories has cognitive complexity 45 (threshold 15). Drivers by points: if/else 10 (27 pts), loops 5 (12 pts), boolean chains 5, ternaries 1 (nesting depth added 24). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomProxy._retry_request (cognitive 45) REDACTED:2739— HeadroomProxy._retry_request has cognitive complexity 45 (threshold 15). Drivers by points: if/else 12 (32 pts), boolean chains 9, error handling 1 (2 pts), loops 1, ternaries 1 (nesting depth added 21). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ToolSignature.from_items (cognitive 45) headroom/telemetry/models.py:214— ToolSignature.from_items has cognitive complexity 45 (threshold 15). Drivers by points: if/else 16 (33 pts), loops 5 (8 pts), boolean chains 3, ternaries 1 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ReadLifecycleManager._build_tool_metadata (cognitive 45) headroom/transforms/read_lifecycle.py:188— ReadLifecycleManager._build_tool_metadata has cognitive complexity 45 (threshold 15). Drivers by points: if/else 11 (31 pts), boolean chains 6, loops 3 (5 pts), error handling 1 (3 pts) (nesting depth added 24). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
prefix_tracker.overlay_cached_prefix (cognitive 44) REDACTED:677— prefix_tracker.overlay_cached_prefix has cognitive complexity 44 (threshold 15). Drivers by points: if/else 12 (23 pts), ternaries 4 (12 pts), boolean chains 8, loops 1 (nesting depth added 19). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
install._apply_manifest (cognitive 44) headroom/cli/install.py:659— install._apply_manifest has cognitive complexity 44 (threshold 15). Drivers by points: if/else 12 (20 pts), error handling 9 (13 pts), boolean chains 7, ternaries 2 (4 pts) (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
update.safe_update (cognitive 44) headroom/cli/update.py:229— update.safe_update has cognitive complexity 44 (threshold 15). Drivers by points: error handling 8 (20 pts), if/else 11 (18 pts), boolean chains 6 (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SQLiteGraphStore.query_subgraph (cognitive 44) headroom/memory/adapters/sqlite_graph.py:456— SQLiteGraphStore.query_subgraph has cognitive complexity 44 (threshold 15). Drivers by points: if/else 13 (38 pts), loops 3 (4 pts), boolean chains 2 (nesting depth added 26). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
verbosity.extract_signals (cognitive 43) headroom/learn/verbosity.py:323— verbosity.extract_signals has cognitive complexity 43 (threshold 15). Drivers by points: if/else 11 (30 pts), loops 6 (9 pts), boolean chains 3, ternaries 1 (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
anthropic._load_custom_model_config (cognitive 43) headroom/providers/anthropic.py:406— anthropic._load_custom_model_config has cognitive complexity 43 (threshold 15). Drivers by points: if/else 15 (30 pts), loops 2 (6 pts), error handling 2 (4 pts), boolean chains 3 (nesting depth added 21). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
gateway_responses.apply_view (cognitive 43) headroom/proxy/gateway_responses.py:289— gateway_responses.apply_view has cognitive complexity 43 (threshold 15). Drivers by points: if/else 15 (34 pts), ternaries 2 (5 pts), boolean chains 3, loops 1 (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
StreamingMixin._record_ccr_feedback_from_openai_sse (cognitive 43) REDACTED:807— StreamingMixin._record_ccr_feedback_from_openai_sse has cognitive complexity 43 (threshold 15). Drivers by points: if/else 11 (24 pts), boolean chains 7, error handling 3 (6 pts), loops 3 (4 pts), ternaries 1 (2 pts) (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
base._build_tool_use_index (cognitive 43) headroom/proxy/interceptors/base.py:123— base._build_tool_use_index has cognitive complexity 43 (threshold 15). Drivers by points: if/else 8 (29 pts), loops 3 (7 pts), error handling 1 (5 pts), boolean chains 2 (nesting depth added 29). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compaction_codec.expand_compacted (cognitive 43) headroom/transforms/compaction_codec.py:361— compaction_codec.expand_compacted has cognitive complexity 43 (threshold 15). Drivers by points: if/else 12 (30 pts), error handling 2 (6 pts), loops 3 (4 pts), boolean chains 3 (nesting depth added 23). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomClient._create (cognitive 42) headroom/client.py:464— HeadroomClient._create has cognitive complexity 42 (threshold 15). Drivers by points: if/else 14 (30 pts), boolean chains 6, ternaries 2 (5 pts), error handling 1 (nesting depth added 19). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
mixed_content.split_into_sections (cognitive 42) headroom/transforms/mixed_content.py:126— mixed_content.split_into_sections has cognitive complexity 42 (threshold 15). Drivers by points: if/else 8 (19 pts), loops 4 (9 pts), boolean chains 6, error handling 1 (4 pts), ternaries 1 (4 pts) (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SmartCrusher._extract_context_from_messages (cognitive 42) headroom/transforms/smart_crusher.py:1218— SmartCrusher._extract_context_from_messages has cognitive complexity 42 (threshold 15). Drivers by points: if/else 8 (30 pts), loops 3 (8 pts), boolean chains 4 (nesting depth added 27). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
DiffCompressor::compress_with_ccr_source (cognitive 42) crates/headroom-core/src/transforms/diff_compressor.rs:288— DiffCompressor::compress_with_ccr_source has cognitive complexity 42 (threshold 15). Drivers by points: if/else 18 (34 pts), loops 4 (7 pts), boolean chains 1 (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
memory.reindex_memories (cognitive 41) headroom/cli/memory.py:1157— memory.reindex_memories has cognitive complexity 41 (threshold 15). Drivers by points: if/else 9 (19 pts), error handling 6 (11 pts), loops 4 (8 pts), ternaries 1 (3 pts) (nesting depth added 21). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
supervisors.install_supervisor (cognitive 41) REDACTED:538— supervisors.install_supervisor has cognitive complexity 41 (threshold 15). Drivers by points: if/else 12 (19 pts), ternaries 6 (13 pts), boolean chains 5, error handling 1 (2 pts), loops 1 (2 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LocalBackend.save_memory (cognitive 41) headroom/memory/backends/local.py:232— LocalBackend.save_memory has cognitive complexity 41 (threshold 15). Drivers by points: if/else 13 (24 pts), loops 5 (11 pts), boolean chains 5, ternaries 1 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
session_tracking.compute_window_tokens (cognitive 41) headroom/subscription/session_tracking.py:123— session_tracking.compute_window_tokens has cognitive complexity 41 (threshold 15). Drivers by points: if/else 9 (26 pts), error handling 3 (8 pts), loops 3 (4 pts), boolean chains 3 (nesting depth added 23). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodeAwareCompressor.compress (cognitive 41) headroom/transforms/code_compressor.py:1293— CodeAwareCompressor.compress has cognitive complexity 41 (threshold 15). Drivers by points: if/else 24 (32 pts), ternaries 2 (5 pts), boolean chains 3, error handling 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
code_compressor.detect_language (cognitive 41) headroom/transforms/code_compressor.py:882— code_compressor.detect_language has cognitive complexity 41 (threshold 15). Drivers by points: if/else 16 (26 pts), boolean chains 7, loops 3 (5 pts), error handling 1 (3 pts) (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
rollupHour (cognitive 41) deploy/beacon/worker.js:388— rollupHour has cognitive complexity 41 (threshold 15). Drivers by points: if/else 6 (17 pts), loops 5 (11 pts), error handling 1 (5 pts), ternaries 2 (5 pts), boolean chains 2, other 1 (nesting depth added 24). Of this number, 38 points are the body's own statements and 3 belong to 3 function literals inside it that branch. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap._ensure_serena_dashboard_disabled (cognitive 40) headroom/cli/wrap.py:2414— wrap._ensure_serena_dashboard_disabled has cognitive complexity 40 (threshold 15). Drivers by points: if/else 17 (29 pts), ternaries 2 (5 pts), loops 2 (3 pts), error handling 2, boolean chains 1 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomStrandsModel._convert_messages_to_openai (cognitive 40) headroom/integrations/strands/model.py:158— HeadroomStrandsModel._convert_messages_to_openai has cognitive complexity 40 (threshold 15). Drivers by points: if/else 12 (29 pts), boolean chains 7, ternaries 1 (3 pts), loops 1 (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
DirectMem0Adapter._save_memory_internal (cognitive 40) REDACTED:709— DirectMem0Adapter._save_memory_internal has cognitive complexity 40 (threshold 15). Drivers by points: boolean chains 18, if/else 9 (16 pts), ternaries 3 (6 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
gateway_turn._wire_provider_from_shape (cognitive 40) headroom/proxy/gateway_turn.py:231— gateway_turn._wire_provider_from_shape has cognitive complexity 40 (threshold 15). Drivers by points: if/else 10 (21 pts), ternaries 5 (9 pts), boolean chains 6, loops 3 (4 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnthropicHandlerMixin._append_proactive_expansion_after_cached_prefix (cognitive 40) REDACTED:1014— AnthropicHandlerMixin._append_proactive_expansion_after_cached_prefix has cognitive complexity 40 (threshold 15). Drivers by points: if/else 12 (23 pts), loops 4 (8 pts), boolean chains 7, ternaries 1 (2 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseTokenizer._count_content_parts (cognitive 40) headroom/tokenizers/base.py:576— BaseTokenizer._count_content_parts has cognitive complexity 40 (threshold 15). Drivers by points: if/else 12 (30 pts), boolean chains 9, loops 1 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnchorSelector._select_region_anchors (cognitive 40) REDACTED:630— AnchorSelector._select_region_anchors has cognitive complexity 40 (threshold 15). Drivers by points: if/else 10 (28 pts), loops 3 (11 pts), boolean chains 1 (nesting depth added 26). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
AnchorSelector::select_region (cognitive 40) crates/headroom-core/src/transforms/anchor_selector.rs:714— AnchorSelector::select_region has cognitive complexity 40 (threshold 15). Drivers by points: if/else 10 (27 pts), loops 3 (11 pts), boolean chains 2 (nesting depth added 25). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
StreamingCCRHandler.process_stream (cognitive 39) headroom/ccr/response_handler.py:707— StreamingCCRHandler.process_stream has cognitive complexity 39 (threshold 15). Drivers by points: if/else 9 (16 pts), loops 6 (14 pts), error handling 3 (6 pts), boolean chains 2, ternaries 1 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap._start_proxy (cognitive 39) headroom/cli/wrap.py:857— wrap._start_proxy has cognitive complexity 39 (threshold 15). Drivers by points: if/else 28 (32 pts), boolean chains 4, error handling 2, loops 1 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
LoCoMoEvaluatorV2._answer_question (cognitive 39) headroom/evals/memory/runner_v2.py:633— LoCoMoEvaluatorV2._answer_question has cognitive complexity 39 (threshold 15). Drivers by points: if/else 12 (23 pts), boolean chains 5, error handling 2 (4 pts), loops 2 (4 pts), ternaries 2 (3 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
planner.build_manifest (cognitive 39) headroom/install/planner.py:139— planner.build_manifest has cognitive complexity 39 (threshold 15). Drivers by points: if/else 26 (30 pts), ternaries 3 (6 pts), boolean chains 3 (nesting depth added 7). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
traffic_learner._load_persisted_patterns_from_sqlite (cognitive 39) headroom/memory/traffic_learner.py:1912— traffic_learner._load_persisted_patterns_from_sqlite has cognitive complexity 39 (threshold 15). Drivers by points: if/else 6 (14 pts), boolean chains 11, error handling 7 (11 pts), ternaries 1 (2 pts), loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CostTracker.stats (cognitive 39) headroom/proxy/cost.py:1676— CostTracker.stats has cognitive complexity 39 (threshold 15). Drivers by points: if/else 15 (28 pts), loops 7, boolean chains 2, ternaries 1 (2 pts) (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
helpers.apply_session_sticky_memory_tools (cognitive 39) headroom/proxy/helpers.py:2622— helpers.apply_session_sticky_memory_tools has cognitive complexity 39 (threshold 15). Drivers by points: if/else 13 (23 pts), loops 5 (8 pts), boolean chains 4, error handling 1 (3 pts), ternaries 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compaction_codec.factor_values (cognitive 39) headroom/transforms/compaction_codec.py:255— compaction_codec.factor_values has cognitive complexity 39 (threshold 15). Drivers by points: if/else 14 (27 pts), loops 5 (7 pts), boolean chains 4, ternaries 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap.opencode (cognitive 38) headroom/cli/wrap.py:8953— wrap.opencode has cognitive complexity 38 (threshold 15). Drivers by points: if/else 18 (25 pts), error handling 3 (5 pts), boolean chains 4, ternaries 4 (nesting depth added 9). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
InMemoryGraphStore.query_subgraph (cognitive 38) headroom/memory/adapters/graph.py:301— InMemoryGraphStore.query_subgraph has cognitive complexity 38 (threshold 15). Drivers by points: if/else 11 (32 pts), loops 3 (4 pts), boolean chains 2 (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
InMemoryGraphStore.find_path (cognitive 38) headroom/memory/adapters/graph.py:394— InMemoryGraphStore.find_path has cognitive complexity 38 (threshold 15). Drivers by points: if/else 12 (31 pts), loops 2 (3 pts), boolean chains 2, ternaries 1 (2 pts) (nesting depth added 21). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._responses_input_to_learner_messages (cognitive 38) REDACTED:1330— openai._responses_input_to_learner_messages has cognitive complexity 38 (threshold 15). Drivers by points: if/else 11 (22 pts), ternaries 2 (7 pts), boolean chains 4, error handling 1 (4 pts), loops 1 (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
outcome.emit_request_outcome (cognitive 38) REDACTED:478— outcome.emit_request_outcome has cognitive complexity 38 (threshold 15). Drivers by points: if/else 14 (18 pts), boolean chains 12, error handling 2 (4 pts), ternaries 4 (nesting depth added 6). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
compaction_codec._iter_rows (cognitive 38) headroom/transforms/compaction_codec.py:146— compaction_codec._iter_rows has cognitive complexity 38 (threshold 15). Drivers by points: if/else 9 (25 pts), loops 3 (7 pts), boolean chains 6 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
tool_calls.extract_tool_calls (cognitive 37) headroom/ccr/tool_calls.py:30— tool_calls.extract_tool_calls has cognitive complexity 37 (threshold 15). Drivers by points: if/else 16 (30 pts), boolean chains 5, ternaries 1 (2 pts) (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Mem0Backend.query (cognitive 37) headroom/memory/backends/mem0.py:551— Mem0Backend.query has cognitive complexity 37 (threshold 15). Drivers by points: if/else 13 (24 pts), boolean chains 9, ternaries 2, error handling 1, loops 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
traffic_learner._refine_error_recovery (cognitive 37) headroom/memory/traffic_learner.py:2077— traffic_learner._refine_error_recovery has cognitive complexity 37 (threshold 15). Drivers by points: if/else 11 (25 pts), boolean chains 4, error handling 1 (4 pts), loops 4 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
memory_query_policy.extract_memory_query_sources (cognitive 37) headroom/proxy/memory_query_policy.py:74— memory_query_policy.extract_memory_query_sources has cognitive complexity 37 (threshold 15). Drivers by points: if/else 9 (31 pts), boolean chains 5, loops 1 (nesting depth added 22). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
MemoryToolStreamFilter._route (cognitive 37) headroom/proxy/memory_tool_stream.py:255— MemoryToolStreamFilter._route has cognitive complexity 37 (threshold 15). Drivers by points: if/else 17 (27 pts), boolean chains 8, ternaries 1 (2 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
claude_analysis_ttl.main (cognitive 36) claude_analysis_ttl.py:98— claude_analysis_ttl.main has cognitive complexity 36 (threshold 15). Drivers by points: if/else 9 (16 pts), loops 9 (11 pts), ternaries 5 (6 pts), error handling 1 (2 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CompressionStore._evict_if_needed (cognitive 36) headroom/cache/compression_store.py:867— CompressionStore._evict_if_needed has cognitive complexity 36 (threshold 15). Drivers by points: if/else 14 (25 pts), boolean chains 9, loops 2 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
JSONStructureHandler._extract_mask (cognitive 36) headroom/compression/handlers/json_handler.py:119— JSONStructureHandler._extract_mask has cognitive complexity 36 (threshold 15). Drivers by points: if/else 9 (27 pts), loops 2 (4 pts), boolean chains 3, ternaries 1 (2 pts) (nesting depth added 21). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
ImageCompressor._count_result_tokens (cognitive 36) headroom/image/compressor.py:363— ImageCompressor._count_result_tokens has cognitive complexity 36 (threshold 15). Drivers by points: if/else 9 (31 pts), loops 2 (3 pts), boolean chains 1, ternaries 1 (nesting depth added 23). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
CodexPlugin._scan_json_session (cognitive 36) headroom/learn/plugins/codex.py:126— CodexPlugin._scan_json_session has cognitive complexity 36 (threshold 15). Drivers by points: if/else 9 (21 pts), ternaries 2 (8 pts), error handling 2 (5 pts), boolean chains 1, loops 1 (nesting depth added 21). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
anthropic_wire._render_known_response (cognitive 36) headroom/proxy/anthropic_wire.py:576— anthropic_wire._render_known_response has cognitive complexity 36 (threshold 15). Drivers by points: if/else 8 (22 pts), loops 4 (8 pts), boolean chains 4, ternaries 2 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
cost.build_session_summary (cognitive 36) headroom/proxy/cost.py:665— cost.build_session_summary has cognitive complexity 36 (threshold 15). Drivers by points: if/else 12 (20 pts), boolean chains 6, ternaries 4 (5 pts), loops 2 (3 pts), error handling 1 (2 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LiteLLMBackend.send_openai_message (cognitive 35) headroom/backends/litellm.py:1816— LiteLLMBackend.send_openai_message has cognitive complexity 35 (threshold 15). Drivers by points: boolean chains 15, if/else 11 (15 pts), ternaries 3, error handling 1, loops 1 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
recover.recover_codex (cognitive 35) headroom/cli/recover.py:39— recover.recover_codex has cognitive complexity 35 (threshold 15). Drivers by points: if/else 8 (17 pts), loops 5 (13 pts), boolean chains 3, error handling 1 (2 pts) (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap._remove_claude_wrap_selfheal_hook (cognitive 35) headroom/cli/wrap.py:2118— wrap._remove_claude_wrap_selfheal_hook has cognitive complexity 35 (threshold 15). Drivers by points: if/else 15 (29 pts), loops 2 (3 pts), boolean chains 2, error handling 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
TrafficLearner.extract_tool_results_from_openai_messages (cognitive 35) headroom/memory/traffic_learner.py:1753— TrafficLearner.extract_tool_results_from_openai_messages has cognitive complexity 35 (threshold 15). Drivers by points: if/else 9 (20 pts), boolean chains 5, loops 3 (4 pts), error handling 1 (3 pts), ternaries 1 (3 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
lossless_compaction.compact_lossless (cognitive 35) headroom/transforms/lossless_compaction.py:485— lossless_compaction.compact_lossless has cognitive complexity 35 (threshold 15). Drivers by points: if/else 13 (20 pts), ternaries 5 (10 pts), boolean chains 2, loops 1 (2 pts), error handling 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
memory.list_memories (cognitive 34) headroom/cli/memory.py:472— memory.list_memories has cognitive complexity 34 (threshold 15). Drivers by points: if/else 13 (25 pts), ternaries 2 (5 pts), error handling 2, boolean chains 1, loops 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap._restore_codex_provider_config (cognitive 34) headroom/cli/wrap.py:4034— wrap._restore_codex_provider_config has cognitive complexity 34 (threshold 15). Drivers by points: if/else 11 (25 pts), ternaries 2 (6 pts), error handling 1 (2 pts), boolean chains 1 (nesting depth added 19). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
SQLiteGraphStore.find_path (cognitive 34) headroom/memory/adapters/sqlite_graph.py:579— SQLiteGraphStore.find_path has cognitive complexity 34 (threshold 15). Drivers by points: if/else 11 (27 pts), loops 2 (3 pts), boolean chains 2, ternaries 1 (2 pts) (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
GeminiHandlerMixin.handle_gemini_count_tokens (cognitive 34) headroom/proxy/handlers/gemini.py:1476— GeminiHandlerMixin.handle_gemini_count_tokens has cognitive complexity 34 (threshold 15). Drivers by points: if/else 19 (26 pts), error handling 4 (5 pts), boolean chains 2, ternaries 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MemoryHandler.search_and_format_context (cognitive 34) headroom/proxy/memory_handler.py:724— MemoryHandler.search_and_format_context has cognitive complexity 34 (threshold 15). Drivers by points: if/else 16 (18 pts), ternaries 4 (6 pts), boolean chains 5, error handling 3 (4 pts), loops 1 (nesting depth added 5). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
utils.extract_user_query (cognitive 34) REDACTED:142— utils.extract_user_query has cognitive complexity 34 (threshold 15). Drivers by points: if/else 8 (27 pts), ternaries 1 (4 pts), boolean chains 2, loops 1 (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
supervisors.remove_supervisor (cognitive 33) REDACTED:839— supervisors.remove_supervisor has cognitive complexity 33 (threshold 15). Drivers by points: if/else 10 (18 pts), ternaries 5 (11 pts), boolean chains 2, loops 1 (2 pts) (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MemoryHandler._extract_tool_calls (cognitive 33) headroom/proxy/memory_handler.py:1068— MemoryHandler._extract_tool_calls has cognitive complexity 33 (threshold 15). Drivers by points: if/else 10 (27 pts), boolean chains 4, ternaries 1 (2 pts) (nesting depth added 18). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
server.run_server (cognitive 33) REDACTED:6862— server.run_server has cognitive complexity 33 (threshold 15). Drivers by points: if/else 15 (16 pts), ternaries 8 (15 pts), boolean chains 2 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
savings_ledger.record_savings_event (cognitive 33) headroom/savings_ledger.py:285— savings_ledger.record_savings_event has cognitive complexity 33 (threshold 15). Drivers by points: if/else 16 (23 pts), error handling 4 (6 pts), boolean chains 4 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
thinking_compactor.compact_reasoning_openai_chat (cognitive 33) REDACTED:246— thinking_compactor.compact_reasoning_openai_chat has cognitive complexity 33 (threshold 15). Drivers by points: if/else 12 (25 pts), boolean chains 6, loops 1, ternaries 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomMCPServer._handle_stats (cognitive 32) headroom/ccr/mcp_server.py:1016— HeadroomMCPServer._handle_stats has cognitive complexity 32 (threshold 15). Drivers by points: if/else 13 (29 pts), ternaries 1 (2 pts), boolean chains 1 (nesting depth added 17). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
CompressionOnlyRunner.evaluate_tool_schema_compaction (cognitive 32) headroom/evals/runners/compression_only.py:562— CompressionOnlyRunner.evaluate_tool_schema_compaction has cognitive complexity 32 (threshold 15). Drivers by points: if/else 7 (14 pts), loops 4 (10 pts), ternaries 4 (6 pts), error handling 1 (2 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
supervisors._parse_windows_task_xml (cognitive 32) REDACTED:403— supervisors._parse_windows_task_xml has cognitive complexity 32 (threshold 15). Drivers by points: if/else 8 (18 pts), error handling 4 (13 pts), boolean chains 1 (nesting depth added 19). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
HeadroomAgnoModel._convert_messages_to_openai (cognitive 32) headroom/integrations/agno/model.py:286— HeadroomAgnoModel._convert_messages_to_openai has cognitive complexity 32 (threshold 15). Drivers by points: if/else 9 (22 pts), boolean chains 6, ternaries 1 (3 pts), loops 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
analyzer._build_digest (cognitive 32) headroom/learn/analyzer.py:358— analyzer._build_digest has cognitive complexity 32 (threshold 15). Drivers by points: if/else 11 (23 pts), loops 3 (7 pts), boolean chains 1, ternaries 1 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomProxy._start_kompress_background_warmup (cognitive 32) REDACTED:2096— HeadroomProxy._start_kompress_background_warmup has cognitive complexity 32 (threshold 15). Drivers by points: if/else 9 (17 pts), error handling 4 (9 pts), boolean chains 3, loops 2 (3 pts) (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
convert.normalizeAssistantContent (cognitive 32) plugins/openclaw/src/convert.ts:478— convert.normalizeAssistantContent has cognitive complexity 32 (threshold 15). Drivers by points: if/else 8 (13 pts), ternaries 4 (13 pts), boolean chains 6 (nesting depth added 14). Most of this is not in the body itself: 4 of the 32 points are its own statements and the rest belongs to one function literal inside it that branches (line 480). The decisions are inside the literal, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literal's work into a named function or method at the enclosing scope and have the literal call it, then reduce whichever part then reads as the largest.
SharedSessions.fetch (cognitive 31) REDACTED:99— SharedSessions.fetch has cognitive complexity 31 (threshold 15). Drivers by points: if/else 11 (15 pts), error handling 5 (7 pts), boolean chains 3, loops 2 (3 pts), ternaries 1 (3 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
context_tool_cleanup._prune_hooks (cognitive 31) headroom/context_tool_cleanup.py:486— context_tool_cleanup._prune_hooks has cognitive complexity 31 (threshold 15). Drivers by points: if/else 9 (25 pts), loops 2 (3 pts), ternaries 1 (3 pts) (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
report_card.generate_markdown (cognitive 31) headroom/evals/reports/report_card.py:136— report_card.generate_markdown has cognitive complexity 31 (threshold 15). Drivers by points: ternaries 8 (24 pts), loops 2 (4 pts), if/else 3 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenCodePlugin._scan_session_legacy (cognitive 31) headroom/learn/plugins/opencode.py:432— OpenCodePlugin._scan_session_legacy has cognitive complexity 31 (threshold 15). Drivers by points: ternaries 5 (10 pts), if/else 4 (8 pts), boolean chains 6, error handling 2 (6 pts), loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._openai_responses_to_sse (cognitive 31) REDACTED:1695— openai._openai_responses_to_sse has cognitive complexity 31 (threshold 15). Drivers by points: if/else 9 (24 pts), loops 2 (4 pts), boolean chains 3 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
helpers.history_references_ccr_tool (cognitive 31) headroom/proxy/helpers.py:2897— helpers.history_references_ccr_tool has cognitive complexity 31 (threshold 15). Drivers by points: if/else 7 (19 pts), loops 3 (7 pts), ternaries 1 (4 pts), boolean chains 1 (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ToolIntelligenceNetwork.record_compression (cognitive 31) headroom/telemetry/toin.py:631— ToolIntelligenceNetwork.record_compression has cognitive complexity 31 (threshold 15). Drivers by points: if/else 16 (26 pts), ternaries 3, boolean chains 1, error handling 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
audit.audit_reads_cmd (cognitive 30) headroom/cli/audit.py:38— audit.audit_reads_cmd has cognitive complexity 30 (threshold 15). Drivers by points: if/else 17 (30 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
report_card.generate_html (cognitive 30) headroom/evals/reports/report_card.py:210— report_card.generate_html has cognitive complexity 30 (threshold 15). Drivers by points: ternaries 17 (27 pts), loops 2, if/else 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ImageCompressor._extract_image_data (cognitive 30) headroom/image/compressor.py:271— ImageCompressor._extract_image_data has cognitive complexity 30 (threshold 15). Drivers by points: if/else 8 (27 pts), loops 2 (3 pts) (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
grok._extract_tool_output (cognitive 30) headroom/learn/plugins/grok.py:182— grok._extract_tool_output has cognitive complexity 30 (threshold 15). Drivers by points: if/else 9 (24 pts), loops 2 (4 pts), boolean chains 2 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap.native_api_url_supported (cognitive 30) headroom/providers/copilot/wrap.py:198— wrap.native_api_url_supported has cognitive complexity 30 (threshold 15). Drivers by points: if/else 4 (13 pts), loops 4 (10 pts), error handling 1 (4 pts), ternaries 2, boolean chains 1 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BatchHandlerMixin._compress_batch_jsonl (cognitive 30) headroom/proxy/handlers/batch.py:1133— BatchHandlerMixin._compress_batch_jsonl has cognitive complexity 30 (threshold 15). Drivers by points: if/else 10 (19 pts), error handling 2 (5 pts), ternaries 3, boolean chains 2, loops 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
GeminiHandlerMixin.handle_google_cloudcode_stream (cognitive 30) headroom/proxy/handlers/gemini.py:1258— GeminiHandlerMixin.handle_google_cloudcode_stream has cognitive complexity 30 (threshold 15). Drivers by points: if/else 16 (22 pts), ternaries 3 (4 pts), error handling 2 (3 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RequestOutcome.from_stream (cognitive 30) REDACTED:313— RequestOutcome.from_stream has cognitive complexity 30 (threshold 15). Drivers by points: if/else 8 (19 pts), ternaries 2 (5 pts), boolean chains 3, loops 1 (3 pts) (nesting depth added 16). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
base._pdf_png_rows (cognitive 30) headroom/tokenizers/base.py:132— base._pdf_png_rows has cognitive complexity 30 (threshold 15). Drivers by points: ternaries 4 (18 pts), if/else 3 (7 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodeAwareCompressor._extract_structure (cognitive 30) headroom/transforms/code_compressor.py:1643— CodeAwareCompressor._extract_structure has cognitive complexity 30 (threshold 15). Drivers by points: if/else 11 (24 pts), boolean chains 5, loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContentRouter._compress_mixed (cognitive 30) headroom/transforms/content_router.py:3674— ContentRouter._compress_mixed has cognitive complexity 30 (threshold 15). Drivers by points: if/else 10 (19 pts), boolean chains 5, error handling 1 (3 pts), ternaries 2, loops 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
thinking_compactor.compact_thinking_to_text (cognitive 30) REDACTED:111— thinking_compactor.compact_thinking_to_text has cognitive complexity 30 (threshold 15). Drivers by points: if/else 10 (22 pts), boolean chains 4, loops 2 (3 pts), ternaries 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
format.vercelMediaImageUrl (cognitive 30) sdk/typescript/src/utils/format.ts:419— format.vercelMediaImageUrl has cognitive complexity 30 (threshold 15). Drivers by points: if/else 18 (20 pts), boolean chains 6, ternaries 3 (4 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
LiteLLMBackend.send_message (cognitive 29) headroom/backends/litellm.py:1268— LiteLLMBackend.send_message has cognitive complexity 29 (threshold 15). Drivers by points: if/else 17 (23 pts), boolean chains 5, error handling 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ttl_estimator.estimate_ttls (cognitive 29) headroom/cache/ttl_estimator.py:71— ttl_estimator.estimate_ttls has cognitive complexity 29 (threshold 15). Drivers by points: if/else 9 (19 pts), boolean chains 6, error handling 1 (2 pts), loops 2 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
inspect._render_request (cognitive 29) headroom/cli/inspect.py:59— inspect._render_request has cognitive complexity 29 (threshold 15). Drivers by points: boolean chains 9, ternaries 4 (9 pts), if/else 4 (8 pts), loops 2 (3 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap.unwrap_claude (cognitive 29) headroom/cli/wrap.py:6901— wrap.unwrap_claude has cognitive complexity 29 (threshold 15). Drivers by points: if/else 16 (25 pts), ternaries 1 (2 pts), boolean chains 1, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ClaudeCodePlugin.discover_projects (cognitive 29) headroom/learn/plugins/claude.py:63— ClaudeCodePlugin.discover_projects has cognitive complexity 29 (threshold 15). Drivers by points: if/else 11 (24 pts), boolean chains 2, ternaries 1 (2 pts), loops 1 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
GeminiHandlerMixin._gemini_contents_to_messages (cognitive 29) headroom/proxy/handlers/gemini.py:298— GeminiHandlerMixin._gemini_contents_to_messages has cognitive complexity 29 (threshold 15). Drivers by points: if/else 10 (23 pts), loops 2 (4 pts), ternaries 1 (2 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SavingsTracker._sanitize_state (cognitive 29) headroom/proxy/savings_tracker.py:1896— SavingsTracker._sanitize_state has cognitive complexity 29 (threshold 15). Drivers by points: if/else 13 (19 pts), boolean chains 6, loops 1 (2 pts), ternaries 1 (2 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
turn_hooks.run_request_hooks (cognitive 29) headroom/proxy/turn_hooks.py:256— turn_hooks.run_request_hooks has cognitive complexity 29 (threshold 15). Drivers by points: if/else 8 (16 pts), error handling 2 (4 pts), ternaries 2 (4 pts), boolean chains 3, loops 2 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
savings_ledger.aggregate_savings (cognitive 29) headroom/savings_ledger.py:637— savings_ledger.aggregate_savings has cognitive complexity 29 (threshold 15). Drivers by points: boolean chains 10, error handling 3 (7 pts), if/else 3 (6 pts), loops 2 (3 pts), ternaries 2 (3 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContentRouter.compress (cognitive 29) headroom/transforms/content_router.py:3366— ContentRouter.compress has cognitive complexity 29 (threshold 15). Drivers by points: if/else 10 (14 pts), ternaries 4 (10 pts), boolean chains 5 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
update_check._select_latest (cognitive 29) REDACTED:153— update_check._select_latest has cognitive complexity 29 (threshold 15). Drivers by points: if/else 8 (15 pts), boolean chains 6, error handling 2 (6 pts), loops 1 (2 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compress.compress (cognitive 28) headroom/compress.py:215— compress.compress has cognitive complexity 28 (threshold 15). Drivers by points: if/else 15 (17 pts), ternaries 4 (5 pts), boolean chains 4, error handling 1, loops 1 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
providers._extract_model_id (cognitive 28) headroom/integrations/strands/providers.py:102— providers._extract_model_id has cognitive complexity 28 (threshold 15). Drivers by points: if/else 8 (17 pts), loops 3 (6 pts), boolean chains 3, error handling 1 (2 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
recovery._merge_database (cognitive 28) headroom/providers/codex/recovery.py:528— recovery._merge_database has cognitive complexity 28 (threshold 15). Drivers by points: if/else 9 (15 pts), boolean chains 4, loops 2 (4 pts), error handling 2 (3 pts), ternaries 1 (2 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAIHandlerMixin.handle_compress_usage (cognitive 28) REDACTED:11908— OpenAIHandlerMixin.handle_compress_usage has cognitive complexity 28 (threshold 15). Drivers by points: if/else 13 (17 pts), boolean chains 7, error handling 3 (4 pts) (nesting depth added 5). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
_PdfReader.read_xref_stream (cognitive 28) headroom/tokenizers/base.py:225— _PdfReader.read_xref_stream has cognitive complexity 28 (threshold 15). Drivers by points: if/else 10 (16 pts), ternaries 4 (7 pts), boolean chains 4, loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
evals._run_memory_eval (cognitive 27) headroom/cli/evals.py:417— evals._run_memory_eval has cognitive complexity 27 (threshold 15). Drivers by points: if/else 10 (15 pts), boolean chains 5, error handling 3 (4 pts), ternaries 3 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
TrafficLearner.extract_tool_results_from_messages (cognitive 27) headroom/memory/traffic_learner.py:1693— TrafficLearner.extract_tool_results_from_messages has cognitive complexity 27 (threshold 15). Drivers by points: if/else 6 (17 pts), loops 4 (6 pts), boolean chains 4 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodexProjectContextResolver._rollout_for_thread (cognitive 27) headroom/providers/codex/project_context.py:346— CodexProjectContextResolver._rollout_for_thread has cognitive complexity 27 (threshold 15). Drivers by points: if/else 6 (14 pts), ternaries 3 (6 pts), error handling 2 (4 pts), boolean chains 2, loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RequestTransformer.run (cognitive 27) headroom/proxy/gateway_turn.py:957— RequestTransformer.run has cognitive complexity 27 (threshold 15). Drivers by points: if/else 9 (16 pts), boolean chains 9, error handling 2 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodeAwareCompressor.should_apply (cognitive 27) headroom/transforms/code_compressor.py:2566— CodeAwareCompressor.should_apply has cognitive complexity 27 (threshold 15). Drivers by points: if/else 6 (21 pts), loops 2 (4 pts), boolean chains 2 (nesting depth added 17). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
BatchResultProcessor._messages_to_google_contents (cognitive 26) headroom/ccr/batch_processor.py:439— BatchResultProcessor._messages_to_google_contents has cognitive complexity 26 (threshold 15). Drivers by points: if/else 7 (19 pts), loops 2 (4 pts), ternaries 1 (3 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CCRResponseHandler.handle_response (cognitive 26) headroom/ccr/response_handler.py:469— CCRResponseHandler.handle_response has cognitive complexity 26 (threshold 15). Drivers by points: if/else 10 (18 pts), ternaries 1 (3 pts), boolean chains 2, error handling 1 (2 pts), loops 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
claude._component_tokenizations (cognitive 26) headroom/learn/plugins/claude.py:589— claude._component_tokenizations has cognitive complexity 26 (threshold 15). Drivers by points: if/else 9 (22 pts), loops 2 (3 pts), boolean chains 1 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodexPlugin._scan_jsonl_session (cognitive 26) headroom/learn/plugins/codex.py:204— CodexPlugin._scan_jsonl_session has cognitive complexity 26 (threshold 15). Drivers by points: if/else 9 (19 pts), error handling 2 (3 pts), ternaries 1 (2 pts), boolean chains 1, loops 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
GrokPlugin._scan_session (cognitive 26) headroom/learn/plugins/grok.py:110— GrokPlugin._scan_session has cognitive complexity 26 (threshold 15). Drivers by points: if/else 9 (19 pts), error handling 2 (3 pts), ternaries 1 (2 pts), boolean chains 1, loops 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
verbosity._ordered_events (cognitive 26) headroom/learn/verbosity.py:279— verbosity._ordered_events has cognitive complexity 26 (threshold 15). Drivers by points: if/else 4 (11 pts), ternaries 3 (9 pts), error handling 2 (3 pts), boolean chains 2, loops 1 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
TrafficLearner.flush_to_file (cognitive 26) headroom/memory/traffic_learner.py:638— TrafficLearner.flush_to_file has cognitive complexity 26 (threshold 15). Drivers by points: if/else 13 (17 pts), error handling 4 (6 pts), loops 2, boolean chains 1 (nesting depth added 6). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
CohereProvider.get_context_limit (cognitive 26) headroom/providers/cohere.py:271— CohereProvider.get_context_limit has cognitive complexity 26 (threshold 15). Drivers by points: if/else 7 (18 pts), error handling 1 (3 pts), loops 2 (3 pts), boolean chains 2 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._codex_ws_text_shape (cognitive 26) REDACTED:807— openai._codex_ws_text_shape has cognitive complexity 26 (threshold 15). Drivers by points: if/else 14 (21 pts), boolean chains 5 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
savings._compute (cognitive 26) headroom/proxy/savings.py:558— savings._compute has cognitive complexity 26 (threshold 15). Drivers by points: ternaries 12 (13 pts), if/else 7 (8 pts), boolean chains 5 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
content_router._mask_quoted (cognitive 26) headroom/transforms/content_router.py:896— content_router._mask_quoted has cognitive complexity 26 (threshold 15). Drivers by points: if/else 8 (17 pts), boolean chains 5, loops 2 (4 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
kompress_compressor._load_kompress (cognitive 26) headroom/transforms/kompress_compressor.py:1229— kompress_compressor._load_kompress has cognitive complexity 26 (threshold 15). Drivers by points: if/else 10 (16 pts), error handling 4 (8 pts), ternaries 1 (2 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
smart_crusher._build_tool_name_index (cognitive 26) headroom/transforms/smart_crusher.py:132— smart_crusher._build_tool_name_index has cognitive complexity 26 (threshold 15). Drivers by points: if/else 5 (15 pts), loops 3 (6 pts), boolean chains 5 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
runtime-proof.run_case (cognitive 26) plugins/opencode/scripts/runtime-proof.py:104— runtime-proof.run_case has cognitive complexity 26 (threshold 15). Drivers by points: if/else 9 (11 pts), boolean chains 6, loops 4, ternaries 3, error handling 1 (2 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
ProxyManager.start (cognitive 26) plugins/openclaw/src/proxy-manager.ts:73— ProxyManager.start has cognitive complexity 26 (threshold 15). Drivers by points: if/else 8 (12 pts), ternaries 5 (7 pts), boolean chains 6, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LiteLLMBackend.map_model_id (cognitive 25) headroom/backends/litellm.py:920— LiteLLMBackend.map_model_id has cognitive complexity 25 (threshold 15). Drivers by points: if/else 13 (21 pts), boolean chains 4 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RegexDetector.detect (cognitive 25) headroom/cache/dynamic_detector.py:358— RegexDetector.detect has cognitive complexity 25 (threshold 15). Drivers by points: if/else 7 (18 pts), loops 5 (7 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
install.install_status (cognitive 25) headroom/cli/install.py:1164— install.install_status has cognitive complexity 25 (threshold 15). Drivers by points: if/else 5 (10 pts), ternaries 4 (10 pts), boolean chains 5 (nesting depth added 11). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
ImageCompressor.has_images (cognitive 25) headroom/image/compressor.py:226— ImageCompressor.has_images has cognitive complexity 25 (threshold 15). Drivers by points: if/else 5 (21 pts), loops 2 (4 pts) (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ledger._read_ledger (cognitive 25) headroom/mcp_registry/ledger.py:123— ledger._read_ledger has cognitive complexity 25 (threshold 15). Drivers by points: if/else 8 (16 pts), error handling 4, boolean chains 3, loops 1 (2 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HNSWVectorIndex._passes_filter (cognitive 25) headroom/memory/adapters/hnsw.py:691— HNSWVectorIndex._passes_filter has cognitive complexity 25 (threshold 15). Drivers by points: if/else 14 (21 pts), boolean chains 4 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
counterfactual.resolve_rates (cognitive 25) headroom/pricing/counterfactual.py:437— counterfactual.resolve_rates has cognitive complexity 25 (threshold 15). Drivers by points: if/else 11 (13 pts), boolean chains 8, ternaries 3 (4 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
openai._responses_input_to_waste_messages (cognitive 25) REDACTED:1292— openai._responses_input_to_waste_messages has cognitive complexity 25 (threshold 15). Drivers by points: if/else 9 (18 pts), boolean chains 3, ternaries 1 (3 pts), loops 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
helpers._inflate_bounded (cognitive 25) headroom/proxy/helpers.py:3145— helpers._inflate_bounded has cognitive complexity 25 (threshold 15). Drivers by points: if/else 8 (19 pts), boolean chains 3, loops 2 (3 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
anchor_selector._calculate_value_uniqueness (cognitive 25) REDACTED:203— anchor_selector._calculate_value_uniqueness has cognitive complexity 25 (threshold 15). Drivers by points: if/else 6 (11 pts), error handling 2 (5 pts), ternaries 2 (5 pts), loops 3 (4 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
content_detector._try_detect_json (cognitive 25) headroom/transforms/content_detector.py:363— content_detector._try_detect_json has cognitive complexity 25 (threshold 15). Drivers by points: if/else 8 (14 pts), error handling 4 (7 pts), boolean chains 2, ternaries 1 (2 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContentRouter._net_cost_allows (cognitive 25) headroom/transforms/content_router.py:6187— ContentRouter._net_cost_allows has cognitive complexity 25 (threshold 15). Drivers by points: if/else 9 (12 pts), ternaries 4 (6 pts), boolean chains 4, error handling 2 (3 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ProxyManager.buildLaunchSpecs (cognitive 25) plugins/openclaw/src/proxy-manager.ts:214— ProxyManager.buildLaunchSpecs has cognitive complexity 25 (threshold 15). Drivers by points: if/else 10 (15 pts), ternaries 4 (5 pts), loops 3 (4 pts), boolean chains 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
litellm._place_system_cache_control (cognitive 24) headroom/backends/litellm.py:191— litellm._place_system_cache_control has cognitive complexity 24 (threshold 15). Drivers by points: if/else 6 (13 pts), boolean chains 6, loops 3 (5 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
doctor._hook_commands (cognitive 24) headroom/cli/doctor.py:219— doctor._hook_commands has cognitive complexity 24 (threshold 15). Drivers by points: if/else 4 (11 pts), loops 3 (7 pts), ternaries 2 (4 pts), boolean chains 2 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
doctor.expected_init_hooks (cognitive 24) headroom/cli/doctor.py:301— doctor.expected_init_hooks has cognitive complexity 24 (threshold 15). Drivers by points: ternaries 3 (10 pts), if/else 4 (7 pts), boolean chains 3, loops 2 (3 pts), error handling 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
context_tool_cleanup.purge_context_tool_artifacts (cognitive 24) headroom/context_tool_cleanup.py:151— context_tool_cleanup.purge_context_tool_artifacts has cognitive complexity 24 (threshold 15). Drivers by points: if/else 7 (15 pts), loops 3 (6 pts), error handling 1 (3 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ImageCompressor._ocr_extract (cognitive 24) headroom/image/compressor.py:419— ImageCompressor._ocr_extract has cognitive complexity 24 (threshold 15). Drivers by points: if/else 10 (14 pts), error handling 4 (7 pts), boolean chains 3 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
runtime._read_proc_metadata (cognitive 24) headroom/install/runtime.py:276— runtime._read_proc_metadata has cognitive complexity 24 (threshold 15). Drivers by points: if/else 8 (12 pts), error handling 5 (8 pts), boolean chains 3, loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
model.optimize_messages (cognitive 24) headroom/integrations/strands/model.py:532— model.optimize_messages has cognitive complexity 24 (threshold 15). Drivers by points: if/else 6 (15 pts), boolean chains 7, loops 1, ternaries 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ClaudeCodePlugin._merge_worktrees (cognitive 24) headroom/learn/plugins/claude.py:121— ClaudeCodePlugin._merge_worktrees has cognitive complexity 24 (threshold 15). Drivers by points: if/else 5 (10 pts), ternaries 4 (8 pts), boolean chains 2, error handling 1 (2 pts), loops 2 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Mem0SystemAdapter.search_memories (cognitive 24) headroom/memory/backends/mem0_system_adapter.py:172— Mem0SystemAdapter.search_memories has cognitive complexity 24 (threshold 15). Drivers by points: if/else 6 (16 pts), boolean chains 4, error handling 1 (3 pts), loops 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
live.handle_codex_live_websocket (cognitive 24) headroom/providers/codex/live.py:162— live.handle_codex_live_websocket has cognitive complexity 24 (threshold 15). Drivers by points: if/else 12 (14 pts), error handling 4, boolean chains 3, loops 2, ternaries 1 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
extensions.install_all (cognitive 24) headroom/proxy/extensions.py:200— extensions.install_all has cognitive complexity 24 (threshold 15). Drivers by points: if/else 9 (15 pts), error handling 2 (4 pts), boolean chains 2, ternaries 1 (2 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
gateway_turn.shape_gateway_body (cognitive 24) headroom/proxy/gateway_turn.py:1265— gateway_turn.shape_gateway_body has cognitive complexity 24 (threshold 15). Drivers by points: if/else 9 (16 pts), boolean chains 3, loops 1 (3 pts), error handling 1, ternaries 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
helpers.append_text_to_latest_user_chat_message (cognitive 24) headroom/proxy/helpers.py:996— helpers.append_text_to_latest_user_chat_message has cognitive complexity 24 (threshold 15). Drivers by points: if/else 8 (17 pts), loops 2 (4 pts), boolean chains 3 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (helpers.append_text_to_latest_user_input_item) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
helpers.append_text_to_latest_user_input_item (cognitive 24) headroom/proxy/helpers.py:1282— helpers.append_text_to_latest_user_input_item has cognitive complexity 24 (threshold 15). Drivers by points: if/else 8 (17 pts), loops 2 (4 pts), boolean chains 3 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (helpers.append_text_to_latest_user_chat_message) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
helpers._decompress_bounded (cognitive 24) headroom/proxy/helpers.py:3254— helpers._decompress_bounded has cognitive complexity 24 (threshold 15). Drivers by points: error handling 10 (20 pts), if/else 4 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
output_shaper.classify_responses_turn (cognitive 24) headroom/proxy/output_shaper.py:467— output_shaper.classify_responses_turn has cognitive complexity 24 (threshold 15). Drivers by points: if/else 10 (18 pts), boolean chains 3, ternaries 1 (2 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ReadLifecycleManager._apply_lifecycle (cognitive 24) headroom/transforms/read_lifecycle.py:421— ReadLifecycleManager._apply_lifecycle has cognitive complexity 24 (threshold 15). Drivers by points: if/else 8 (21 pts), loops 2, boolean chains 1 (nesting depth added 13). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
CodeAwareCompressor::analyze_symbol_importance (cognitive 24) crates/headroom-core/src/transforms/code_compressor.rs:1059— CodeAwareCompressor::analyze_symbol_importance has cognitive complexity 24 (threshold 15). Drivers by points: if/else 10 (13 pts), loops 6 (8 pts), boolean chains 3 (nesting depth added 5). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
register.register (cognitive 24) plugins/headroom-snip/hooks/register.tsx:144— register.register has cognitive complexity 24 (threshold 15). Drivers by points: ternaries 13 (15 pts), boolean chains 5, if/else 4 (nesting depth added 2). None of this is in the body itself: all 24 points belong to 4 function literals inside it that branch (lines 184, 259, 172, …). The decisions are inside those literals, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literals' work into a named function or method at the enclosing scope and have each literal call it, then reduce whichever part then reads as the largest.
prefix_tracker._classify_history_canonical (cognitive 23) REDACTED:333— prefix_tracker._classify_history_canonical has cognitive complexity 23 (threshold 15). Drivers by points: if/else 9 (16 pts), boolean chains 5, loops 1, ternaries 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomMCPServer._handle_read (cognitive 23) headroom/ccr/mcp_server.py:1119— HeadroomMCPServer._handle_read has cognitive complexity 23 (threshold 15). Drivers by points: if/else 9 (13 pts), error handling 4, boolean chains 3, ternaries 2, loops 1 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
html_oss_benchmarks.evaluate_qa_accuracy_preservation (cognitive 23) headroom/evals/html_oss_benchmarks.py:259— html_oss_benchmarks.evaluate_qa_accuracy_preservation has cognitive complexity 23 (threshold 15). Drivers by points: if/else 8 (11 pts), ternaries 3 (7 pts), error handling 2 (3 pts), boolean chains 1, loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LoCoMoEvaluator._store_conversation (cognitive 23) headroom/evals/memory/runner.py:353— LoCoMoEvaluator._store_conversation has cognitive complexity 23 (threshold 15). Drivers by points: loops 5 (11 pts), if/else 5 (8 pts), ternaries 1 (4 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
supervisors.start_supervisor (cognitive 23) REDACTED:706— supervisors.start_supervisor has cognitive complexity 23 (threshold 15). Drivers by points: if/else 8 (15 pts), ternaries 3 (6 pts), boolean chains 2 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
opencode._extract_output (cognitive 23) headroom/learn/plugins/opencode.py:87— opencode._extract_output has cognitive complexity 23 (threshold 15). Drivers by points: if/else 6 (10 pts), boolean chains 9, loops 1 (2 pts), ternaries 1 (2 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
registry._discover (cognitive 23) headroom/learn/registry.py:23— registry._discover has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (16 pts), error handling 3 (5 pts), loops 2 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SQLiteVectorIndex._passes_filter (cognitive 23) headroom/memory/adapters/sqlite_vector.py:792— SQLiteVectorIndex._passes_filter has cognitive complexity 23 (threshold 15). Drivers by points: if/else 13 (18 pts), boolean chains 5 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ClaudeCodeAdapter.write_memories (cognitive 23) headroom/memory/sync_adapters/claude_code.py:130— ClaudeCodeAdapter.write_memories has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (19 pts), boolean chains 3, loops 1 (nesting depth added 12). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
HeadroomOtelMetrics.record_proxy_request (cognitive 23) headroom/observability/metrics.py:446— HeadroomOtelMetrics.record_proxy_request has cognitive complexity 23 (threshold 15). Drivers by points: if/else 14 (17 pts), boolean chains 5, loops 1 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
conversation_savings.turn_conversation_key (cognitive 23) headroom/proxy/conversation_savings.py:110— conversation_savings.turn_conversation_key has cognitive complexity 23 (threshold 15). Drivers by points: if/else 8 (16 pts), loops 3 (6 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
helpers.inject_tool_search_deferral (cognitive 23) headroom/proxy/helpers.py:4240— helpers.inject_tool_search_deferral has cognitive complexity 23 (threshold 15). Drivers by points: if/else 9 (15 pts), boolean chains 5, ternaries 1 (2 pts), loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodeAwareCompressor._analyze_symbol_importance (cognitive 23) headroom/transforms/code_compressor.py:1085— CodeAwareCompressor._analyze_symbol_importance has cognitive complexity 23 (threshold 15). Drivers by points: if/else 9 (15 pts), loops 4, boolean chains 2, ternaries 1 (2 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
content_router._detect_content (cognitive 23) headroom/transforms/content_router.py:1376— content_router._detect_content has cognitive complexity 23 (threshold 15). Drivers by points: if/else 13 (19 pts), boolean chains 2, error handling 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
cross_turn_dedup._longest_match (cognitive 23) headroom/transforms/cross_turn_dedup.py:177— cross_turn_dedup._longest_match has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (17 pts), boolean chains 3, loops 2 (3 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnyLLMBackend._convert_messages (cognitive 22) headroom/backends/anyllm.py:80— AnyLLMBackend._convert_messages has cognitive complexity 22 (threshold 15). Drivers by points: if/else 6 (17 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnyLLMBackend._to_anthropic_response (cognitive 22) headroom/backends/anyllm.py:142— AnyLLMBackend._to_anthropic_response has cognitive complexity 22 (threshold 15). Drivers by points: if/else 6 (9 pts), boolean chains 7, error handling 1 (4 pts), loops 1 (2 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnthropicCacheOptimizer._analyze_sections (cognitive 22) headroom/cache/anthropic.py:192— AnthropicCacheOptimizer._analyze_sections has cognitive complexity 22 (threshold 15). Drivers by points: if/else 5 (11 pts), ternaries 2 (6 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
prefix_tracker.mirror_client_message_cache_control (cognitive 22) REDACTED:1113— prefix_tracker.mirror_client_message_cache_control has cognitive complexity 22 (threshold 15). Drivers by points: if/else 6 (13 pts), ternaries 3 (5 pts), boolean chains 3, loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SemanticCacheLayer._extract_query (cognitive 22) headroom/cache/semantic.py:565— SemanticCacheLayer._extract_query has cognitive complexity 22 (threshold 15). Drivers by points: if/else 3 (10 pts), ternaries 1 (6 pts), loops 2 (5 pts), boolean chains 1 (nesting depth added 15). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
memory.delete_memories (cognitive 22) headroom/cli/memory.py:885— memory.delete_memories has cognitive complexity 22 (threshold 15). Drivers by points: if/else 11 (19 pts), error handling 2, loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
tools.tools_install_cmd (cognitive 22) headroom/cli/tools.py:198— tools.tools_install_cmd has cognitive complexity 22 (threshold 15). Drivers by points: if/else 6 (13 pts), error handling 3 (7 pts), loops 1, ternaries 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap._inject_codex_provider_config (cognitive 22) headroom/cli/wrap.py:3824— wrap._inject_codex_provider_config has cognitive complexity 22 (threshold 15). Drivers by points: if/else 9 (12 pts), error handling 5 (9 pts), ternaries 1 (nesting depth added 7). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
HeadroomClient._extract_query (cognitive 22) headroom/client.py:726— HeadroomClient._extract_query has cognitive complexity 22 (threshold 15). Drivers by points: if/else 3 (10 pts), ternaries 1 (6 pts), loops 2 (5 pts), boolean chains 1 (nesting depth added 15). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
config._orchestrator_invokes_retrieve (cognitive 22) headroom/config.py:500— config._orchestrator_invokes_retrieve has cognitive complexity 22 (threshold 15). Drivers by points: if/else 9 (17 pts), loops 3 (5 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ImageCompressor._extract_query (cognitive 22) headroom/image/compressor.py:244— ImageCompressor._extract_query has cognitive complexity 22 (threshold 15). Drivers by points: if/else 6 (18 pts), loops 2 (4 pts) (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomMCPCompressor.compress (cognitive 22) headroom/integrations/mcp/server.py:180— HeadroomMCPCompressor.compress has cognitive complexity 22 (threshold 15). Drivers by points: if/else 6 (11 pts), loops 3 (5 pts), boolean chains 3, error handling 2, ternaries 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodexAdapter.write_memories (cognitive 22) headroom/memory/sync_adapters/codex_agent.py:70— CodexAdapter.write_memories has cognitive complexity 22 (threshold 15). Drivers by points: if/else 9 (16 pts), loops 2 (3 pts), boolean chains 2, ternaries 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnthropicProvider.get_context_limit (cognitive 22) headroom/providers/anthropic.py:837— AnthropicProvider.get_context_limit has cognitive complexity 22 (threshold 15). Drivers by points: if/else 10 (16 pts), boolean chains 3, error handling 1 (2 pts), loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._restore_codex_additional_tools (cognitive 22) REDACTED:1060— openai._restore_codex_additional_tools has cognitive complexity 22 (threshold 15). Drivers by points: if/else 9 (11 pts), boolean chains 8, loops 2 (3 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
helpers.apply_session_sticky_ccr_tool (cognitive 22) headroom/proxy/helpers.py:2934— helpers.apply_session_sticky_ccr_tool has cognitive complexity 22 (threshold 15). Drivers by points: if/else 7 (9 pts), ternaries 4 (6 pts), boolean chains 4, error handling 1 (3 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MemoryHandler.handle_memory_tool_calls (cognitive 22) headroom/proxy/memory_handler.py:1122— MemoryHandler.handle_memory_tool_calls has cognitive complexity 22 (threshold 15). Drivers by points: if/else 7 (12 pts), boolean chains 6, error handling 1 (3 pts), loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
output_steering.apply_openai_chat_verbosity_steering (cognitive 22) headroom/proxy/output_steering.py:54— output_steering.apply_openai_chat_verbosity_steering has cognitive complexity 22 (threshold 15). Drivers by points: if/else 10 (17 pts), loops 2 (3 pts), boolean chains 2 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
stream_output_tokens._hit_output_ceiling (cognitive 22) headroom/proxy/stream_output_tokens.py:139— stream_output_tokens._hit_output_ceiling has cognitive complexity 22 (threshold 15). Drivers by points: if/else 6 (15 pts), loops 2 (4 pts), boolean chains 3 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
tabular_ingest.parse_fixed_width (cognitive 22) headroom/transforms/tabular_ingest.py:117— tabular_ingest.parse_fixed_width has cognitive complexity 22 (threshold 15). Drivers by points: if/else 8 (14 pts), boolean chains 4, loops 3 (4 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
StackTraceDetector::terminates (cognitive 22) crates/headroom-core/src/transforms/log_compressor.rs:601— StackTraceDetector::terminates has cognitive complexity 22 (threshold 15). Drivers by points: boolean chains 12, if/else 5 (9 pts), match/switch 1 (nesting depth added 4). The drivers above price the dispatch low by construction — a dispatch is charged once however many cases it lists, while each branch inside an arm is charged in full — so most of this count is what the case bodies hold, and the arms are where it can be reduced. To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Keep every case explicit, and make the behaviour for cases you do not list a deliberate choice rather than an accident.
TextCrusher::compress (cognitive 22) crates/headroom-core/src/transforms/text_crusher/crusher.rs:116— TextCrusher::compress has cognitive complexity 22 (threshold 15). Drivers by points: if/else 12 (18 pts), loops 3 (4 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnthropicCacheOptimizer._stabilize_prefix (cognitive 21) headroom/cache/anthropic.py:329— AnthropicCacheOptimizer._stabilize_prefix has cognitive complexity 21 (threshold 15). Drivers by points: if/else 5 (16 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
init._ensure_claude_hooks (cognitive 21) REDACTED:218— init._ensure_claude_hooks has cognitive complexity 21 (threshold 15). Drivers by points: if/else 3 (9 pts), ternaries 4 (5 pts), boolean chains 4, loops 2 (3 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
copilot_auth.apply_copilot_api_auth (cognitive 21) REDACTED:1726— copilot_auth.apply_copilot_api_auth has cognitive complexity 21 (threshold 15). Drivers by points: if/else 9 (14 pts), boolean chains 3, ternaries 2 (3 pts), loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
datasets.load_bfcl (cognitive 21) REDACTED:590— datasets.load_bfcl has cognitive complexity 21 (threshold 15). Drivers by points: if/else 5 (9 pts), error handling 3 (5 pts), ternaries 2 (4 pts), loops 2, boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SuiteRunner.run (cognitive 21) headroom/evals/suite_runner.py:487— SuiteRunner.run has cognitive complexity 21 (threshold 15). Drivers by points: if/else 5 (10 pts), boolean chains 8, error handling 1 (2 pts), loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
langgraph.compress_tool_messages (cognitive 21) headroom/integrations/langchain/langgraph.py:202— langgraph.compress_tool_messages has cognitive complexity 21 (threshold 15). Drivers by points: if/else 5 (8 pts), ternaries 3 (8 pts), boolean chains 2, error handling 1 (2 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
writer._merge_recommendations (cognitive 21) headroom/learn/writer.py:335— writer._merge_recommendations has cognitive complexity 21 (threshold 15). Drivers by points: if/else 8 (18 pts), loops 2, boolean chains 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
adapters.__getattr__ (cognitive 21) headroom/memory/adapters/__init__.py:42— adapters.__getattr__ has cognitive complexity 21 (threshold 15). Drivers by points: if/else 14 (21 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
DirectMem0Adapter.close (cognitive 21) REDACTED:1057— DirectMem0Adapter.close has cognitive complexity 21 (threshold 15). Drivers by points: if/else 6 (12 pts), error handling 2 (5 pts), loops 2 (3 pts), boolean chains 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MemorySystem.handle_memory_save (cognitive 21) headroom/memory/system.py:326— MemorySystem.handle_memory_save has cognitive complexity 21 (threshold 15). Drivers by points: if/else 13 (16 pts), boolean chains 5 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
TrafficLearner._load_pending_state (cognitive 21) headroom/memory/traffic_learner.py:1570— TrafficLearner._load_pending_state has cognitive complexity 21 (threshold 15). Drivers by points: if/else 7 (13 pts), boolean chains 3, error handling 2 (3 pts), loops 1, ternaries 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
traffic_learner._project_for_pattern (cognitive 21) headroom/memory/traffic_learner.py:1854— traffic_learner._project_for_pattern has cognitive complexity 21 (threshold 15). Drivers by points: if/else 5 (10 pts), boolean chains 6, loops 4 (5 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
recovery.discover_referenced_temp_homes (cognitive 21) headroom/providers/codex/recovery.py:82— recovery.discover_referenced_temp_homes has cognitive complexity 21 (threshold 15). Drivers by points: if/else 5 (12 pts), loops 3 (6 pts), error handling 1 (2 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
vscode._strip_jsonc_comments (cognitive 21) headroom/providers/copilot/vscode.py:67— vscode._strip_jsonc_comments has cognitive complexity 21 (threshold 15). Drivers by points: if/else 8 (20 pts), loops 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
install_registry.apply_provider_scope_mutations (cognitive 21) headroom/providers/install_registry.py:89— install_registry.apply_provider_scope_mutations has cognitive complexity 21 (threshold 15). Drivers by points: if/else 5 (12 pts), error handling 2 (4 pts), loops 2 (3 pts), boolean chains 2 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
gateway_turn.normalize_usage (cognitive 21) headroom/proxy/gateway_turn.py:391— gateway_turn.normalize_usage has cognitive complexity 21 (threshold 15). Drivers by points: if/else 10 (17 pts), boolean chains 2, loops 1 (2 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
helpers.compute_turn_id (cognitive 21) headroom/proxy/helpers.py:3575— helpers.compute_turn_id has cognitive complexity 21 (threshold 15). Drivers by points: if/else 7 (12 pts), boolean chains 5, error handling 2 (3 pts), loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
astgrep._run_ast_grep (cognitive 21) headroom/proxy/interceptors/astgrep.py:401— astgrep._run_ast_grep has cognitive complexity 21 (threshold 15). Drivers by points: if/else 6 (10 pts), error handling 3 (6 pts), loops 2 (3 pts), boolean chains 2 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MemoryHandler._init_backend_locked (cognitive 21) headroom/proxy/memory_handler.py:351— MemoryHandler._init_backend_locked has cognitive complexity 21 (threshold 15). Drivers by points: if/else 7 (11 pts), error handling 3 (8 pts), boolean chains 2 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
system_compaction._compact_system_blocks (cognitive 21) headroom/proxy/system_compaction.py:59— system_compaction._compact_system_blocks has cognitive complexity 21 (threshold 15). Drivers by points: if/else 5 (11 pts), boolean chains 3, loops 2 (3 pts), error handling 1 (2 pts), ternaries 1 (2 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ToolIntelligenceNetwork.import_patterns (cognitive 21) headroom/telemetry/toin.py:1414— ToolIntelligenceNetwork.import_patterns has cognitive complexity 21 (threshold 15). Drivers by points: if/else 7 (17 pts), error handling 1 (2 pts), boolean chains 1, loops 1 (nesting depth added 11). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
base._pdf_own_keys (cognitive 21) headroom/tokenizers/base.py:99— base._pdf_own_keys has cognitive complexity 21 (threshold 15). Drivers by points: if/else 8 (18 pts), boolean chains 1, loops 1, ternaries 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
RemoteKompressCompressor.compress (cognitive 21) headroom/transforms/kompress_remote.py:219— RemoteKompressCompressor.compress has cognitive complexity 21 (threshold 15). Drivers by points: if/else 8 (11 pts), ternaries 3 (7 pts), boolean chains 2, error handling 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
lossless_compaction.fold_repeated_blocks (cognitive 21) headroom/transforms/lossless_compaction.py:169— lossless_compaction.fold_repeated_blocks has cognitive complexity 21 (threshold 15). Drivers by points: loops 4 (10 pts), if/else 4 (9 pts), boolean chains 2 (nesting depth added 11). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
ReadMaturationManager._process_message (cognitive 21) headroom/transforms/read_maturation.py:328— ReadMaturationManager._process_message has cognitive complexity 21 (threshold 15). Drivers by points: if/else 7 (16 pts), boolean chains 3, loops 1 (2 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
dashboard.html.renderChart (cognitive 21) crates/headroom-proxy/src/observability/dashboard.html:435— dashboard.html.renderChart has cognitive complexity 21 (threshold 15). Drivers by points: boolean chains 8, if/else 5 (6 pts), ternaries 5, loops 2 (nesting depth added 1). Of this number, 12 points are the body's own statements and 9 belong to 5 function items inside it that branch. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
format.vercelMediaPart (cognitive 21) sdk/typescript/src/utils/format.ts:476— format.vercelMediaPart has cognitive complexity 21 (threshold 15). Drivers by points: if/else 11 (15 pts), boolean chains 4, ternaries 2 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
claude_analysis_ttl.turns_of (cognitive 20) claude_analysis_ttl.py:45— claude_analysis_ttl.turns_of has cognitive complexity 20 (threshold 15). Drivers by points: if/else 5 (11 pts), boolean chains 4, error handling 2 (4 pts), loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
agent_savings.proxy_pipeline_kwargs (cognitive 20) headroom/agent_savings.py:288— agent_savings.proxy_pipeline_kwargs has cognitive complexity 20 (threshold 15). Drivers by points: if/else 12 (14 pts), boolean chains 4, error handling 1 (2 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
codex._extract_edit_path (cognitive 20) headroom/audit/codex.py:80— codex._extract_edit_path has cognitive complexity 20 (threshold 15). Drivers by points: if/else 8 (15 pts), boolean chains 2, error handling 1 (2 pts), loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LiteLLMBackend.stream_openai_message (cognitive 20) headroom/backends/litellm.py:2032— LiteLLMBackend.stream_openai_message has cognitive complexity 20 (threshold 15). Drivers by points: if/else 10 (14 pts), boolean chains 3, loops 2, error handling 1 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
litellm._fetch_bedrock_inference_profiles (cognitive 20) headroom/backends/litellm.py:234— litellm._fetch_bedrock_inference_profiles has cognitive complexity 20 (threshold 15). Drivers by points: if/else 5 (11 pts), loops 3 (4 pts), boolean chains 2, error handling 2, ternaries 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compression_cache._extract_tool_result_content (cognitive 20) REDACTED:55— compression_cache._extract_tool_result_content has cognitive complexity 20 (threshold 15). Drivers by points: if/else 7 (17 pts), loops 1 (2 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CompressionStore.store (cognitive 20) headroom/cache/compression_store.py:300— CompressionStore.store has cognitive complexity 20 (threshold 15). Drivers by points: if/else 14 (18 pts), boolean chains 1, ternaries 1 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
compression_store._create_default_ccr_backend (cognitive 20) headroom/cache/compression_store.py:1230— compression_store._create_default_ccr_backend has cognitive complexity 20 (threshold 15). Drivers by points: if/else 9 (12 pts), boolean chains 5, error handling 2 (3 pts) (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
mcp_server._format_session_summary (cognitive 20) headroom/ccr/mcp_server.py:117— mcp_server._format_session_summary has cognitive complexity 20 (threshold 15). Drivers by points: if/else 10 (13 pts), boolean chains 5, loops 1 (2 pts) (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
savings.savings (cognitive 20) headroom/cli/savings.py:160— savings.savings has cognitive complexity 20 (threshold 15). Drivers by points: if/else 11 (13 pts), loops 2 (4 pts), boolean chains 3 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
wrap._warn_proxy_mode_mismatch (cognitive 20) headroom/cli/wrap.py:9773— wrap._warn_proxy_mode_mismatch has cognitive complexity 20 (threshold 15). Drivers by points: if/else 8 (11 pts), boolean chains 7, error handling 1 (2 pts) (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
config.unwrap_tool_call (cognitive 20) headroom/config.py:546— config.unwrap_tool_call has cognitive complexity 20 (threshold 15). Drivers by points: if/else 10 (14 pts), ternaries 2 (3 pts), boolean chains 2, loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BatchCompressionEvaluator.evaluate_case (cognitive 20) headroom/evals/batch_compression_eval.py:1108— BatchCompressionEvaluator.evaluate_case has cognitive complexity 20 (threshold 15). Drivers by points: boolean chains 8, ternaries 5, error handling 3 (4 pts), if/else 3 (nesting depth added 1). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BeforeAfterRunner.evaluate_case (cognitive 20) headroom/evals/runners/before_after.py:281— BeforeAfterRunner.evaluate_case has cognitive complexity 20 (threshold 15). Drivers by points: boolean chains 7, error handling 4 (5 pts), if/else 5, ternaries 3 (nesting depth added 1). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CompressionOnlyRunner.evaluate_ccr_lossless (cognitive 20) headroom/evals/runners/compression_only.py:75— CompressionOnlyRunner.evaluate_ccr_lossless has cognitive complexity 20 (threshold 15). Drivers by points: if/else 7 (13 pts), ternaries 3 (4 pts), error handling 1 (2 pts), loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CompressionMiddleware.__call__ (cognitive 20) headroom/integrations/asgi.py:90— CompressionMiddleware.__call__ has cognitive complexity 20 (threshold 15). Drivers by points: if/else 8 (12 pts), boolean chains 3, ternaries 1 (3 pts), error handling 1, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
loops.apply_loop_weighting (cognitive 20) headroom/learn/loops.py:356— loops.apply_loop_weighting has cognitive complexity 20 (threshold 15). Drivers by points: if/else 6 (16 pts), loops 2 (3 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
claude._greedy_path_decode (cognitive 20) headroom/learn/plugins/claude.py:549— claude._greedy_path_decode has cognitive complexity 20 (threshold 15). Drivers by points: if/else 5 (10 pts), loops 3 (4 pts), error handling 2 (3 pts), ternaries 1 (2 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ProjectResolver._extract_cwd_from_system_prompt (cognitive 20) headroom/memory/storage_router.py:210— ProjectResolver._extract_cwd_from_system_prompt has cognitive complexity 20 (threshold 15). Drivers by points: if/else 7 (16 pts), loops 2 (3 pts), boolean chains 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
metrics._dynamic_metric_attributes (cognitive 20) headroom/observability/metrics.py:66— metrics._dynamic_metric_attributes has cognitive complexity 20 (threshold 15). Drivers by points: if/else 5 (14 pts), loops 2 (3 pts), error handling 1 (2 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
hermes._restore_responses_text_parts (cognitive 20) headroom/providers/hermes.py:198— hermes._restore_responses_text_parts has cognitive complexity 20 (threshold 15). Drivers by points: if/else 7 (15 pts), loops 2 (3 pts), boolean chains 2 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
body_forwarding.select_outbound_body (cognitive 20) headroom/proxy/body_forwarding.py:291— body_forwarding.select_outbound_body has cognitive complexity 20 (threshold 15). Drivers by points: if/else 6 (11 pts), boolean chains 6, ternaries 2 (3 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
astgrep._open_regular_file_under_root (cognitive 20) headroom/proxy/interceptors/astgrep.py:188— astgrep._open_regular_file_under_root has cognitive complexity 20 (threshold 15). Drivers by points: if/else 9, error handling 4 (5 pts), boolean chains 4, loops 1, ternaries 1 (nesting depth added 1). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
MemoryHandler._extract_user_query (cognitive 20) headroom/proxy/memory_handler.py:1026— MemoryHandler._extract_user_query has cognitive complexity 20 (threshold 15). Drivers by points: if/else 5 (15 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MemoryToolStreamFilter.tail_frames (cognitive 20) headroom/proxy/memory_tool_stream.py:343— MemoryToolStreamFilter.tail_frames has cognitive complexity 20 (threshold 15). Drivers by points: if/else 5 (11 pts), boolean chains 5, loops 2 (4 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomProxy._eager_preload_transforms (cognitive 20) REDACTED:2033— HeadroomProxy._eager_preload_transforms has cognitive complexity 20 (threshold 15). Drivers by points: if/else 3 (9 pts), loops 3 (6 pts), error handling 2 (4 pts), ternaries 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
tls_diagnostics._probe_uncached (cognitive 20) headroom/proxy/tls_diagnostics.py:304— tls_diagnostics._probe_uncached has cognitive complexity 20 (threshold 15). Drivers by points: if/else 7 (9 pts), ternaries 3 (6 pts), error handling 3 (4 pts), boolean chains 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
upstream_guard.allowlisted_destinations (cognitive 20) headroom/proxy/upstream_guard.py:208— upstream_guard.allowlisted_destinations has cognitive complexity 20 (threshold 15). Drivers by points: if/else 6 (12 pts), ternaries 1 (3 pts), boolean chains 2, error handling 1 (2 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ToolSignature._matches_pattern (cognitive 20) headroom/telemetry/models.py:166— ToolSignature._matches_pattern has cognitive complexity 20 (threshold 15). Drivers by points: if/else 7 (15 pts), boolean chains 4, loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodeAwareCompressor.apply (cognitive 20) headroom/transforms/code_compressor.py:2468— CodeAwareCompressor.apply has cognitive complexity 20 (threshold 15). Drivers by points: if/else 7 (13 pts), loops 2 (4 pts), boolean chains 2, ternaries 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ReadLifecycleManager._find_tool_call_msg_index (cognitive 20) headroom/transforms/read_lifecycle.py:327— ReadLifecycleManager._find_tool_call_msg_index has cognitive complexity 20 (threshold 15). Drivers by points: if/else 4 (11 pts), loops 3 (6 pts), boolean chains 3 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
recursive_json._scan_from (cognitive 20) headroom/transforms/recursive_json.py:81— recursive_json._scan_from has cognitive complexity 20 (threshold 15). Drivers by points: if/else 5 (13 pts), loops 3 (6 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
headroom_parity::bin::parity_run::main (cognitive 20) crates/headroom-parity/src/bin/parity_run.rs:32— headroom_parity::bin::parity_run::main has cognitive complexity 20 (threshold 15). Drivers by points: loops 4 (10 pts), if/else 3 (9 pts), match/switch 1 (nesting depth added 12). The drivers above price the dispatch low by construction — a dispatch is charged once however many cases it lists, while each branch inside an arm is charged in full — so most of this count is what the case bodies hold, and the arms are where it can be reduced. To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Keep every case explicit, and make the behaviour for cases you do not list a deliberate choice rather than an accident.
snip.describe (cognitive 20) plugins/headroom-snip/hooks/snip.ts:103— snip.describe has cognitive complexity 20 (threshold 15). Drivers by points: if/else 16, boolean chains 4. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
mcp_server._read_shared_events (cognitive 19) headroom/ccr/mcp_server.py:253— mcp_server._read_shared_events has cognitive complexity 19 (threshold 15). Drivers by points: if/else 8 (12 pts), error handling 3 (5 pts), boolean chains 1, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
agent_savings.agent_savings (cognitive 19) headroom/cli/agent_savings.py:67— agent_savings.agent_savings has cognitive complexity 19 (threshold 15). Drivers by points: if/else 8 (16 pts), boolean chains 1, error handling 1, loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
doctor.check_claude_remote_control_gate (cognitive 19) headroom/cli/doctor.py:526— doctor.check_claude_remote_control_gate has cognitive complexity 19 (threshold 15). Drivers by points: if/else 6 (11 pts), boolean chains 3, error handling 1 (2 pts), ternaries 1 (2 pts), loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
doctor.doctor (cognitive 19) headroom/cli/doctor.py:1279— doctor.doctor has cognitive complexity 19 (threshold 15). Drivers by points: if/else 12, boolean chains 4, ternaries 3. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
learn._activate_output_shaper (cognitive 19) headroom/cli/learn.py:585— learn._activate_output_shaper has cognitive complexity 19 (threshold 15). Drivers by points: if/else 6 (11 pts), ternaries 4, boolean chains 2, error handling 2 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
memory.edit_memory (cognitive 19) headroom/cli/memory.py:723— memory.edit_memory has cognitive complexity 19 (threshold 15). Drivers by points: if/else 10 (12 pts), boolean chains 4, error handling 2 (3 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
memory.prune_memories (cognitive 19) headroom/cli/memory.py:988— memory.prune_memories has cognitive complexity 19 (threshold 15). Drivers by points: if/else 12, boolean chains 3, error handling 3, loops 1. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
perf.perf (cognitive 19) headroom/cli/perf.py:27— perf.perf has cognitive complexity 19 (threshold 15). Drivers by points: if/else 7 (9 pts), loops 3 (8 pts), ternaries 1 (2 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap._setup_serena_mcp (cognitive 19) headroom/cli/wrap.py:2885— wrap._setup_serena_mcp has cognitive complexity 19 (threshold 15). Drivers by points: if/else 11 (14 pts), boolean chains 3, ternaries 2 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
wrap.unwrap_opencode (cognitive 19) headroom/cli/wrap.py:9209— wrap.unwrap_opencode has cognitive complexity 19 (threshold 15). Drivers by points: if/else 10 (15 pts), boolean chains 2, error handling 1 (2 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
JSONStructureHandler._should_preserve_token (cognitive 19) headroom/compression/handlers/json_handler.py:196— JSONStructureHandler._should_preserve_token has cognitive complexity 19 (threshold 15). Drivers by points: if/else 9 (17 pts), boolean chains 2 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
context_tool_cleanup._names_managed_dir (cognitive 19) headroom/context_tool_cleanup.py:365— context_tool_cleanup._names_managed_dir has cognitive complexity 19 (threshold 15). Drivers by points: if/else 5 (10 pts), boolean chains 6, loops 2 (3 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LoCoMoEvaluatorV2._aggregate_results (cognitive 19) headroom/evals/memory/runner_v2.py:897— LoCoMoEvaluatorV2._aggregate_results has cognitive complexity 19 (threshold 15). Drivers by points: if/else 11 (16 pts), ternaries 2, loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomPostHook.__call__ (cognitive 19) headroom/integrations/agno/hooks.py:213— HeadroomPostHook.__call__ has cognitive complexity 19 (threshold 15). Drivers by points: if/else 10 (15 pts), boolean chains 2, ternaries 1 (2 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat_model.optimize_messages (cognitive 19) headroom/integrations/langchain/chat_model.py:946— chat_model.optimize_messages has cognitive complexity 19 (threshold 15). Drivers by points: if/else 4 (10 pts), loops 3 (6 pts), boolean chains 2, ternaries 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
analyzer._call_cli_llm (cognitive 19) headroom/learn/analyzer.py:755— analyzer._call_cli_llm has cognitive complexity 19 (threshold 15). Drivers by points: if/else 9 (11 pts), error handling 4 (5 pts), boolean chains 2, loops 1 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
ClaudeCodePlugin._project_path_from_session_cwd (cognitive 19) headroom/learn/plugins/claude.py:185— ClaudeCodePlugin._project_path_from_session_cwd has cognitive complexity 19 (threshold 15). Drivers by points: if/else 3 (10 pts), error handling 2 (5 pts), loops 2 (3 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HNSWVectorIndex.index_batch (cognitive 19) headroom/memory/adapters/hnsw.py:434— HNSWVectorIndex.index_batch has cognitive complexity 19 (threshold 15). Drivers by points: if/else 9 (13 pts), loops 4 (5 pts), boolean chains 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Mem0Backend._ensure_client (cognitive 19) headroom/memory/backends/mem0.py:130— Mem0Backend._ensure_client has cognitive complexity 19 (threshold 15). Drivers by points: if/else 8 (17 pts), error handling 1 (2 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
mcp_server._handle_search (cognitive 19) headroom/memory/mcp_server.py:281— mcp_server._handle_search has cognitive complexity 19 (threshold 15). Drivers by points: if/else 6 (9 pts), error handling 3 (4 pts), boolean chains 2, loops 2, ternaries 1 (2 pts) (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnthropicHandlerMixin._append_context_to_latest_non_frozen_user_turn (cognitive 19) REDACTED:939— AnthropicHandlerMixin._append_context_to_latest_non_frozen_user_turn has cognitive complexity 19 (threshold 15). Drivers by points: if/else 8 (11 pts), boolean chains 5, loops 2 (3 pts) (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._drop_undeclared_web_search_calls (cognitive 19) REDACTED:1175— openai._drop_undeclared_web_search_calls has cognitive complexity 19 (threshold 15). Drivers by points: boolean chains 7, if/else 6 (7 pts), ternaries 2 (4 pts), loops 1 (nesting depth added 3). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._dedup_responses_output_items (cognitive 19) REDACTED:1630— openai._dedup_responses_output_items has cognitive complexity 19 (threshold 15). Drivers by points: if/else 6 (10 pts), error handling 2 (4 pts), boolean chains 3, loops 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
public_errors.classify_exception (cognitive 19) headroom/proxy/public_errors.py:105— public_errors.classify_exception has cognitive complexity 19 (threshold 15). Drivers by points: if/else 12 (19 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
server.create_app (cognitive 19) REDACTED:3448— server.create_app has cognitive complexity 19 (threshold 15). Drivers by points: if/else 8 (9 pts), ternaries 4 (6 pts), boolean chains 3, error handling 1 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
workspace_registry.resolve_registered_cwd (cognitive 19) headroom/proxy/workspace_registry.py:27— workspace_registry.resolve_registered_cwd has cognitive complexity 19 (threshold 15). Drivers by points: if/else 6 (10 pts), error handling 2 (4 pts), boolean chains 2, ternaries 1 (2 pts), loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
storage.create_storage (cognitive 19) headroom/storage/__init__.py:36— storage.create_storage has cognitive complexity 19 (threshold 15). Drivers by points: if/else 6 (14 pts), error handling 1 (3 pts), ternaries 1 (2 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compression_batches.compress_batch_with_router (cognitive 19) headroom/transforms/compression_batches.py:240— compression_batches.compress_batch_with_router has cognitive complexity 19 (threshold 15). Drivers by points: if/else 11 (13 pts), boolean chains 3, loops 2, error handling 1 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
compression_units.compress_unit_with_router (cognitive 19) headroom/transforms/compression_units.py:236— compression_units.compress_unit_with_router has cognitive complexity 19 (threshold 15). Drivers by points: if/else 13 (17 pts), boolean chains 2 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
content_detector.detect_content_type (cognitive 19) headroom/transforms/content_detector.py:182— content_detector.detect_content_type has cognitive complexity 19 (threshold 15). Drivers by points: if/else 11, boolean chains 8. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
read_maturation._iter_tool_results (cognitive 19) headroom/transforms/read_maturation.py:115— read_maturation._iter_tool_results has cognitive complexity 19 (threshold 15). Drivers by points: if/else 5 (13 pts), loops 2 (4 pts), boolean chains 2 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
recursive_json.route_embedded_json (cognitive 19) headroom/transforms/recursive_json.py:238— recursive_json.route_embedded_json has cognitive complexity 19 (threshold 15). Drivers by points: if/else 8 (13 pts), boolean chains 3, loops 2, ternaries 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
DiffNoise::apply (cognitive 19) crates/headroom-core/src/transforms/pipeline/offloads/diff_noise.rs:115— DiffNoise::apply has cognitive complexity 19 (threshold 15). Drivers by points: if/else 7 (10 pts), loops 3 (6 pts), boolean chains 3 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Ledger::record (cognitive 19) crates/headroom-proxy/src/observability/ledger.rs:653— Ledger::record has cognitive complexity 19 (threshold 15). Drivers by points: if/else 14 (16 pts), match/switch 1 (2 pts), boolean chains 1 (nesting depth added 3). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
hooks.extractToolCalls (cognitive 19) sdk/typescript/src/hooks.ts:97— hooks.extractToolCalls has cognitive complexity 19 (threshold 15). Drivers by points: if/else 4 (12 pts), loops 3 (7 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
codex.classify_command (cognitive 18) headroom/audit/codex.py:112— codex.classify_command has cognitive complexity 18 (threshold 15). Drivers by points: if/else 8 (10 pts), boolean chains 3, loops 1 (2 pts), ternaries 1 (2 pts), error handling 1 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAICacheOptimizer._analyze_prefix (cognitive 18) headroom/cache/openai.py:463— OpenAICacheOptimizer._analyze_prefix has cognitive complexity 18 (threshold 15). Drivers by points: if/else 3 (10 pts), loops 2 (5 pts), boolean chains 3 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BatchContextStore.get_memory_stats (cognitive 18) headroom/ccr/batch_store.py:249— BatchContextStore.get_memory_stats has cognitive complexity 18 (threshold 15). Drivers by points: loops 4 (10 pts), if/else 2 (8 pts) (nesting depth added 12). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
init._ensure_codex_hooks (cognitive 18) REDACTED:633— init._ensure_codex_hooks has cognitive complexity 18 (threshold 15). Drivers by points: if/else 3 (9 pts), boolean chains 3, loops 2 (3 pts), ternaries 2 (3 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
install._start_deployment (cognitive 18) headroom/cli/install.py:157— install._start_deployment has cognitive complexity 18 (threshold 15). Drivers by points: if/else 10 (12 pts), boolean chains 2, error handling 2, ternaries 1 (2 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
mcp.mcp_uninstall (cognitive 18) headroom/cli/mcp.py:135— mcp.mcp_uninstall has cognitive complexity 18 (threshold 15). Drivers by points: if/else 8 (15 pts), loops 2 (3 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
memory.show_memory (cognitive 18) headroom/cli/memory.py:579— memory.show_memory has cognitive complexity 18 (threshold 15). Drivers by points: if/else 15 (17 pts), error handling 1 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
wrap._restore_claude_wrap_base_url (cognitive 18) headroom/cli/wrap.py:2249— wrap._restore_claude_wrap_base_url has cognitive complexity 18 (threshold 15). Drivers by points: if/else 11 (13 pts), boolean chains 2, ternaries 2, error handling 1 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
wrap._codex_session_launch_settings (cognitive 18) headroom/cli/wrap.py:3317— wrap._codex_session_launch_settings has cognitive complexity 18 (threshold 15). Drivers by points: if/else 5 (7 pts), boolean chains 5, ternaries 4 (5 pts), error handling 1 (nesting depth added 3). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CopilotTokenProvider.get_api_token (cognitive 18) REDACTED:1530— CopilotTokenProvider.get_api_token has cognitive complexity 18 (threshold 15). Drivers by points: if/else 8 (11 pts), boolean chains 4, ternaries 1 (3 pts) (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
__main__.cmd_benchmark (cognitive 18) headroom/evals/__main__.py:69— __main__.cmd_benchmark has cognitive complexity 18 (threshold 15). Drivers by points: if/else 9 (11 pts), error handling 2 (4 pts), ternaries 1 (2 pts), loops 1 (nesting depth added 5). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
BatchCompressionEvaluator.run (cognitive 18) headroom/evals/batch_compression_eval.py:1219— BatchCompressionEvaluator.run has cognitive complexity 18 (threshold 15). Drivers by points: if/else 6 (11 pts), ternaries 5, loops 2 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
planner.resolve_targets (cognitive 18) headroom/install/planner.py:88— planner.resolve_targets has cognitive complexity 18 (threshold 15). Drivers by points: if/else 8 (12 pts), boolean chains 3, ternaries 1 (2 pts), loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomAgnoModel._has_thinking_blocks (cognitive 18) headroom/integrations/agno/model.py:405— HeadroomAgnoModel._has_thinking_blocks has cognitive complexity 18 (threshold 15). Drivers by points: if/else 4 (13 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ClaudeCodePlugin._extract_tool_results (cognitive 18) headroom/learn/plugins/claude.py:328— ClaudeCodePlugin._extract_tool_results has cognitive complexity 18 (threshold 15). Drivers by points: if/else 6 (12 pts), boolean chains 3, ternaries 1 (2 pts), loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
GeminiPlugin._scan_jsonl_session (cognitive 18) headroom/learn/plugins/gemini.py:165— GeminiPlugin._scan_jsonl_session has cognitive complexity 18 (threshold 15). Drivers by points: if/else 5 (10 pts), ternaries 1 (4 pts), error handling 2 (3 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SQLiteVectorIndex.index_batch (cognitive 18) headroom/memory/adapters/sqlite_vector.py:465— SQLiteVectorIndex.index_batch has cognitive complexity 18 (threshold 15). Drivers by points: if/else 9 (12 pts), loops 3 (4 pts), error handling 1 (2 pts) (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
pipeline.discover_pipeline_extensions (cognitive 18) headroom/pipeline.py:198— pipeline.discover_pipeline_extensions has cognitive complexity 18 (threshold 15). Drivers by points: if/else 6 (10 pts), error handling 3 (6 pts), boolean chains 1, loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodexProjectContextResolver._fallback_or_skip (cognitive 18) headroom/providers/codex/project_context.py:200— CodexProjectContextResolver._fallback_or_skip has cognitive complexity 18 (threshold 15). Drivers by points: if/else 2 (9 pts), loops 3 (6 pts), ternaries 1 (2 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
vscode.unrouted_vscode_profiles (cognitive 18) headroom/providers/copilot/vscode.py:206— vscode.unrouted_vscode_profiles has cognitive complexity 18 (threshold 15). Drivers by points: if/else 3 (6 pts), boolean chains 4, ternaries 3 (4 pts), error handling 2 (3 pts), loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
hermes.compress_scoped_passthrough_body (cognitive 18) headroom/providers/hermes.py:89— hermes.compress_scoped_passthrough_body has cognitive complexity 18 (threshold 15). Drivers by points: if/else 12 (13 pts), boolean chains 3, error handling 1, ternaries 1 (nesting depth added 1). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
CostTracker.record_tokens (cognitive 18) headroom/proxy/cost.py:1115— CostTracker.record_tokens has cognitive complexity 18 (threshold 15). Drivers by points: if/else 10 (11 pts), boolean chains 4, ternaries 3 (nesting depth added 1). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
BedrockHandlerMixin.handle_bedrock_invoke (cognitive 18) headroom/proxy/handlers/bedrock.py:58— BedrockHandlerMixin.handle_bedrock_invoke has cognitive complexity 18 (threshold 15). Drivers by points: if/else 9 (12 pts), error handling 3 (4 pts), boolean chains 1, ternaries 1 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
loopback_guard.is_ip_literal_host_header (cognitive 18) headroom/proxy/loopback_guard.py:146— loopback_guard.is_ip_literal_host_header has cognitive complexity 18 (threshold 15). Drivers by points: if/else 8 (11 pts), boolean chains 4, error handling 2 (3 pts) (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
output_turn_policy.classify_turn (cognitive 18) headroom/proxy/output_turn_policy.py:28— output_turn_policy.classify_turn has cognitive complexity 18 (threshold 15). Drivers by points: if/else 9 (13 pts), boolean chains 2, ternaries 1 (2 pts), loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SavingsTracker.record_request (cognitive 18) headroom/proxy/savings_tracker.py:1145— SavingsTracker.record_request has cognitive complexity 18 (threshold 15). Drivers by points: if/else 7 (8 pts), ternaries 7 (8 pts), boolean chains 2 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
generator._build_waste_histogram (cognitive 18) headroom/reporting/generator.py:396— generator._build_waste_histogram has cognitive complexity 18 (threshold 15). Drivers by points: if/else 4 (9 pts), loops 3 (4 pts), ternaries 2 (3 pts), boolean chains 2 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
UsageReporter._report_usage (cognitive 18) headroom/telemetry/reporter.py:258— UsageReporter._report_usage has cognitive complexity 18 (threshold 15). Drivers by points: if/else 9 (13 pts), boolean chains 3, error handling 1, loops 1 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ToolIntelligenceNetwork._update_field_statistics (cognitive 18) headroom/telemetry/toin.py:846— ToolIntelligenceNetwork._update_field_statistics has cognitive complexity 18 (threshold 15). Drivers by points: if/else 6 (11 pts), loops 3 (4 pts), ternaries 2 (3 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
code_compressor._make_omitted_comment (cognitive 18) headroom/transforms/code_compressor.py:2776— code_compressor._make_omitted_comment has cognitive complexity 18 (threshold 15). Drivers by points: if/else 5 (15 pts), loops 1 (2 pts), boolean chains 1 (nesting depth added 11). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
compaction_codec._decode_cell (cognitive 18) headroom/transforms/compaction_codec.py:215— compaction_codec._decode_cell has cognitive complexity 18 (threshold 15). Drivers by points: error handling 4 (9 pts), if/else 8 (9 pts) (nesting depth added 6). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ProviderPath::classify (cognitive 18) crates/headroom-simulators/src/domain.rs:28— ProviderPath::classify has cognitive complexity 18 (threshold 15). Drivers by points: if/else 15 (16 pts), boolean chains 2 (nesting depth added 1). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
convert.normalizeToolResultContent (cognitive 18) plugins/openclaw/src/convert.ts:521— convert.normalizeToolResultContent has cognitive complexity 18 (threshold 15). Drivers by points: if/else 8 (13 pts), boolean chains 5 (nesting depth added 5). Most of this is not in the body itself: 4 of the 18 points are its own statements and the rest belongs to one function literal inside it that branches (line 523). The decisions are inside the literal, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literal's work into a named function or method at the enclosing scope and have the literal call it, then reduce whichever part then reads as the largest.
AnthropicCacheOptimizer._insert_breakpoints (cognitive 17) headroom/cache/anthropic.py:444— AnthropicCacheOptimizer._insert_breakpoints has cognitive complexity 17 (threshold 15). Drivers by points: if/else 5 (15 pts), boolean chains 1, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnthropicCacheOptimizer._extract_cacheable_content (cognitive 17) headroom/cache/anthropic.py:477— AnthropicCacheOptimizer._extract_cacheable_content has cognitive complexity 17 (threshold 15). Drivers by points: if/else 3 (11 pts), loops 2 (4 pts), boolean chains 2 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compression_cache._swap_tool_result_content (cognitive 17) REDACTED:130— compression_cache._swap_tool_result_content has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (13 pts), boolean chains 2, loops 1 (2 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SemanticCache.get (cognitive 17) headroom/cache/semantic.py:140— SemanticCache.get has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (11 pts), boolean chains 6 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContextTracker._calculate_relevance (cognitive 17) headroom/ccr/context_tracker.py:324— ContextTracker._calculate_relevance has cognitive complexity 17 (threshold 15). Drivers by points: if/else 8 (14 pts), loops 1 (2 pts), boolean chains 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomMCPServer._probe_proxy_unreachable (cognitive 17) headroom/ccr/mcp_server.py:707— HeadroomMCPServer._probe_proxy_unreachable has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (10 pts), error handling 3 (4 pts), boolean chains 3 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
StreamingCCRHandler._openai_response_to_chunks (cognitive 17) headroom/ccr/response_handler.py:987— StreamingCCRHandler._openai_response_to_chunks has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (11 pts), boolean chains 3, loops 1 (2 pts), ternaries 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
tool_calls.drop_tool_calls (cognitive 17) headroom/ccr/tool_calls.py:83— tool_calls.drop_tool_calls has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (15 pts), boolean chains 2 (nesting depth added 9). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
doctor.check_network_endpoints (cognitive 17) headroom/cli/doctor.py:855— doctor.check_network_endpoints has cognitive complexity 17 (threshold 15). Drivers by points: if/else 5 (8 pts), boolean chains 4, ternaries 2 (4 pts), loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
proxy._tcp_port_in_use (cognitive 17) headroom/cli/proxy.py:203— proxy._tcp_port_in_use has cognitive complexity 17 (threshold 15). Drivers by points: if/else 5 (8 pts), error handling 2 (4 pts), boolean chains 2, ternaries 1 (2 pts), loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
update.update (cognitive 17) headroom/cli/update.py:452— update.update has cognitive complexity 17 (threshold 15). Drivers by points: if/else 9 (10 pts), error handling 3 (5 pts), boolean chains 2 (nesting depth added 3). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
wrap._kill_proxy_by_pid (cognitive 17) headroom/cli/wrap.py:4596— wrap._kill_proxy_by_pid has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (8 pts), error handling 4 (5 pts), loops 3 (4 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
copilot_auth._parse_expiry (cognitive 17) REDACTED:594— copilot_auth._parse_expiry has cognitive complexity 17 (threshold 15). Drivers by points: if/else 8 (13 pts), error handling 2 (4 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
adversarial_grid.run_adversarial_grid (cognitive 17) headroom/evals/adversarial_grid.py:310— adversarial_grid.run_adversarial_grid has cognitive complexity 17 (threshold 15). Drivers by points: loops 4 (7 pts), if/else 3 (6 pts), ternaries 1 (4 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
comprehensive_benchmark.run_lm_eval (cognitive 17) headroom/evals/comprehensive_benchmark.py:174— comprehensive_benchmark.run_lm_eval has cognitive complexity 17 (threshold 15). Drivers by points: if/else 10, ternaries 3, boolean chains 2, loops 1 (2 pts) (nesting depth added 1). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
CompressionEvaluator.evaluate_case (cognitive 17) headroom/evals/core.py:280— CompressionEvaluator.evaluate_case has cognitive complexity 17 (threshold 15). Drivers by points: boolean chains 7, error handling 4 (5 pts), ternaries 3, if/else 2 (nesting depth added 1). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
datasets.load_natural_questions (cognitive 17) REDACTED:138— datasets.load_natural_questions has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (15 pts), boolean chains 1, loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LoCoMoEvaluator.run (cognitive 17) headroom/evals/memory/runner.py:664— LoCoMoEvaluator.run has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (12 pts), loops 3 (4 pts), boolean chains 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ImageCompressor.compress (cognitive 17) headroom/image/compressor.py:682— ImageCompressor.compress has cognitive complexity 17 (threshold 15). Drivers by points: error handling 4 (8 pts), if/else 6 (7 pts), boolean chains 2 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
providers._apply_unix_env_scope (cognitive 17) headroom/install/providers.py:62— providers._apply_unix_env_scope has cognitive complexity 17 (threshold 15). Drivers by points: if/else 5 (8 pts), error handling 2 (4 pts), loops 2 (3 pts), ternaries 1 (2 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
runtime.build_runtime_command (cognitive 17) headroom/install/runtime.py:138— runtime.build_runtime_command has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (12 pts), boolean chains 3, loops 2 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
providers.detect_provider (cognitive 17) headroom/integrations/langchain/providers.py:73— providers.detect_provider has cognitive complexity 17 (threshold 15). Drivers by points: if/else 3 (8 pts), loops 4 (8 pts), boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
analyzer._detect_default_model (cognitive 17) headroom/learn/analyzer.py:175— analyzer._detect_default_model has cognitive complexity 17 (threshold 15). Drivers by points: if/else 5 (12 pts), loops 3 (4 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
GeminiPlugin.discover_projects (cognitive 17) headroom/learn/plugins/gemini.py:70— GeminiPlugin.discover_projects has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (12 pts), boolean chains 2, ternaries 1 (2 pts), loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ClaudeRegistrar.get_plugin_servers (cognitive 17) headroom/mcp_registry/claude.py:153— ClaudeRegistrar.get_plugin_servers has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (9 pts), loops 2 (3 pts), ternaries 1 (3 pts), boolean chains 2 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HNSWVectorIndex.search (cognitive 17) headroom/memory/adapters/hnsw.py:590— HNSWVectorIndex.search has cognitive complexity 17 (threshold 15). Drivers by points: if/else 9 (15 pts), loops 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
bridge_parsers.detect_format (cognitive 17) headroom/memory/bridge_parsers.py:217— bridge_parsers.detect_format has cognitive complexity 17 (threshold 15). Drivers by points: if/else 8 (13 pts), boolean chains 3, loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
TrafficLearner.on_messages (cognitive 17) headroom/memory/traffic_learner.py:828— TrafficLearner.on_messages has cognitive complexity 17 (threshold 15). Drivers by points: if/else 5 (12 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
TrafficLearner._save_pattern (cognitive 17) headroom/memory/traffic_learner.py:1375— TrafficLearner._save_pattern has cognitive complexity 17 (threshold 15). Drivers by points: if/else 9 (11 pts), boolean chains 2, ternaries 1 (2 pts), error handling 1, loops 1 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
TrafficLearner._hydrate_persisted_state (cognitive 17) headroom/memory/traffic_learner.py:1455— TrafficLearner._hydrate_persisted_state has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (6 pts), error handling 3 (5 pts), ternaries 2 (4 pts), boolean chains 1, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
install._ensure_codex_auth_helper (cognitive 17) headroom/providers/codex/install.py:194— install._ensure_codex_auth_helper has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (12 pts), error handling 2 (4 pts), boolean chains 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
GatewayTurn.finish (cognitive 17) headroom/proxy/gateway_extension.py:169— GatewayTurn.finish has cognitive complexity 17 (threshold 15). Drivers by points: if/else 5 (10 pts), boolean chains 4, ternaries 2 (3 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
openai._lift_codex_additional_tools (cognitive 17) REDACTED:982— openai._lift_codex_additional_tools has cognitive complexity 17 (threshold 15). Drivers by points: if/else 9 (12 pts), boolean chains 4, loops 1 (nesting depth added 3). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
astgrep._build_outline (cognitive 17) headroom/proxy/interceptors/astgrep.py:490— astgrep._build_outline has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (12 pts), loops 2 (3 pts), boolean chains 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
orphan_watchdog.orphan_watchdog_loop (cognitive 17) headroom/proxy/orphan_watchdog.py:154— orphan_watchdog.orphan_watchdog_loop has cognitive complexity 17 (threshold 15). Drivers by points: if/else 5 (11 pts), boolean chains 5, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
output_steering.apply_verbosity_steering (cognitive 17) headroom/proxy/output_steering.py:16— output_steering.apply_verbosity_steering has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (11 pts), ternaries 1 (3 pts), loops 1 (2 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
savings_attribution.accumulate (cognitive 17) headroom/proxy/savings_attribution.py:228— savings_attribution.accumulate has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (15 pts), boolean chains 1, loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
tls_diagnostics.find_cert_verify_error (cognitive 17) headroom/proxy/tls_diagnostics.py:108— tls_diagnostics.find_cert_verify_error has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (10 pts), loops 3 (5 pts), boolean chains 1, ternaries 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
savings_ledger._read_events (cognitive 17) headroom/savings_ledger.py:452— savings_ledger._read_events has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (9 pts), boolean chains 3, error handling 2 (3 pts), loops 1, ternaries 1 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
savings_ledger._maybe_compact (cognitive 17) headroom/savings_ledger.py:736— savings_ledger._maybe_compact has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (9 pts), error handling 3 (4 pts), boolean chains 3, loops 1 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
Headroom.with_provider (cognitive 17) headroom/testing/harness.py:658— Headroom.with_provider has cognitive complexity 17 (threshold 15). Drivers by points: if/else 9 (17 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_PdfReader.__init__ (cognitive 17) headroom/tokenizers/base.py:167— _PdfReader.__init__ has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (8 pts), ternaries 4 (5 pts), loops 2 (3 pts), boolean chains 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ConfigCompressor.compress (cognitive 17) headroom/transforms/config_compressor.py:130— ConfigCompressor.compress has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (10 pts), ternaries 1 (4 pts), boolean chains 3 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
content_router._custom_tool_call_commands (cognitive 17) headroom/transforms/content_router.py:710— content_router._custom_tool_call_commands has cognitive complexity 17 (threshold 15). Drivers by points: if/else 5 (11 pts), boolean chains 3, error handling 1 (2 pts), loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
cross_turn_dedup.dedup_blocks (cognitive 17) headroom/transforms/cross_turn_dedup.py:235— cross_turn_dedup.dedup_blocks has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (11 pts), loops 2 (3 pts), boolean chains 2, error handling 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
DiffOffload::estimate_bloat (cognitive 17) crates/headroom-core/src/transforms/pipeline/offloads/diff_offload.rs:72— DiffOffload::estimate_bloat has cognitive complexity 17 (threshold 15). Drivers by points: if/else 9 (13 pts), match/switch 1 (2 pts), boolean chains 1, loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
worker.extract (cognitive 17) deploy/beacon/worker.js:323— worker.extract has cognitive complexity 17 (threshold 15). Drivers by points: loops 4 (8 pts), boolean chains 5, if/else 1 (4 pts) (nesting depth added 7). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
snip.bar (cognitive 17) plugins/headroom-snip/hooks/snip.ts:220— snip.bar has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (8 pts), ternaries 4 (6 pts), boolean chains 2, loops 1 (nesting depth added 3). Of this number, 14 points are the body's own statements and 3 belong to one function literal inside it that branches. To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
convert.replaceTextBlocks (cognitive 17) plugins/openclaw/src/convert.ts:361— convert.replaceTextBlocks has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (8 pts), ternaries 2 (5 pts), boolean chains 3, loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
format.anthropicMediaImageUrl (cognitive 17) sdk/typescript/src/utils/format.ts:139— format.anthropicMediaImageUrl has cognitive complexity 17 (threshold 15). Drivers by points: if/else 8 (9 pts), boolean chains 5, ternaries 1 (2 pts), loops 1 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
scheduled (cognitive 17) deploy/beacon/worker.js:474— scheduled has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (7 pts), loops 4 (5 pts), error handling 1 (2 pts), ternaries 1 (2 pts), boolean chains 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_fileperms_windows.open_no_follow (cognitive 16) headroom/_fileperms_windows.py:336— _fileperms_windows.open_no_follow has cognitive complexity 16 (threshold 15). Drivers by points: if/else 8 (12 pts), boolean chains 2, error handling 1, ternaries 1 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnthropicCacheOptimizer._looks_like_example (cognitive 16) headroom/cache/anthropic.py:291— AnthropicCacheOptimizer._looks_like_example has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (12 pts), boolean chains 3, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseCacheOptimizer._extract_system_content (cognitive 16) REDACTED:325— BaseCacheOptimizer._extract_system_content has cognitive complexity 16 (threshold 15). Drivers by points: if/else 3 (10 pts), loops 2 (5 pts), boolean chains 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SessionTrackerStore.compute_session_id (cognitive 16) REDACTED:2108— SessionTrackerStore.compute_session_id has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (11 pts), loops 2 (4 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SessionTrackerStore._decode_state (cognitive 16) REDACTED:2391— SessionTrackerStore._decode_state has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (9 pts), ternaries 1 (3 pts), boolean chains 2, loops 2 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ttl_observations.resolve_learned_ttl (cognitive 16) headroom/cache/ttl_observations.py:98— ttl_observations.resolve_learned_ttl has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (7 pts), boolean chains 3, error handling 2 (3 pts), ternaries 1 (2 pts), loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
doctor.check_savings (cognitive 16) headroom/cli/doctor.py:1005— doctor.check_savings has cognitive complexity 16 (threshold 15). Drivers by points: boolean chains 8, if/else 6, error handling 1 (2 pts) (nesting depth added 1). To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
init._ensure_codex_provider (cognitive 16) REDACTED:402— init._ensure_codex_provider has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (7 pts), ternaries 3 (4 pts), boolean chains 2, loops 1 (2 pts), error handling 1 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
wrap._remove_headroom_installed_serena_mcp (cognitive 16) headroom/cli/wrap.py:3050— wrap._remove_headroom_installed_serena_mcp has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (12 pts), loops 1 (2 pts), ternaries 1 (2 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomClient.__init__ (cognitive 16) headroom/client.py:334— HeadroomClient.__init__ has cognitive complexity 16 (threshold 15). Drivers by points: if/else 10 (15 pts), boolean chains 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
copilot_auth._read_windows_copilot_cli_oauth_token (cognitive 16) REDACTED:508— copilot_auth._read_windows_copilot_cli_oauth_token has cognitive complexity 16 (threshold 15). Drivers by points: if/else 8 (11 pts), boolean chains 2, loops 2, error handling 1 (nesting depth added 3). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
copilot_auth.poll_copilot_device_authorization (cognitive 16) REDACTED:747— copilot_auth.poll_copilot_device_authorization has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (12 pts), boolean chains 3, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
__main__.cmd_report (cognitive 16) headroom/evals/__main__.py:226— __main__.cmd_report has cognitive complexity 16 (threshold 15). Drivers by points: ternaries 5 (11 pts), loops 2 (3 pts), boolean chains 1, if/else 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
tile_optimizer._optimize_content_block (cognitive 16) headroom/image/tile_optimizer.py:259— tile_optimizer._optimize_content_block has cognitive complexity 16 (threshold 15). Drivers by points: if/else 9 (15 pts), error handling 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
model.optimize_messages (cognitive 16) headroom/integrations/agno/model.py:730— model.optimize_messages has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (9 pts), boolean chains 5, loops 1, ternaries 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ClaudeCodePlugin._extract_user_events (cognitive 16) headroom/learn/plugins/claude.py:396— ClaudeCodePlugin._extract_user_events has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (12 pts), boolean chains 2, loops 1 (2 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
DirectMem0Adapter.search_memories (cognitive 16) REDACTED:842— DirectMem0Adapter.search_memories has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (11 pts), boolean chains 3, loops 1, ternaries 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MemoryBridge._get_new_organic_memories (cognitive 16) headroom/memory/bridge.py:563— MemoryBridge._get_new_organic_memories has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (12 pts), boolean chains 3, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
bridge_parsers.extract_entities_from_text (cognitive 16) headroom/memory/bridge_parsers.py:122— bridge_parsers.extract_entities_from_text has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (8 pts), loops 5, boolean chains 3 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
factory._create_vector_index (cognitive 16) headroom/memory/factory.py:241— factory._create_vector_index has cognitive complexity 16 (threshold 15). Drivers by points: if/else 11 (16 pts) (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
traffic_learner._patterns_to_recommendations (cognitive 16) headroom/memory/traffic_learner.py:2014— traffic_learner._patterns_to_recommendations has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (8 pts), ternaries 3 (6 pts), loops 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HeadroomOtelMetrics.record_pipeline_run (cognitive 16) headroom/observability/metrics.py:589— HeadroomOtelMetrics.record_pipeline_run has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (9 pts), loops 3 (6 pts), boolean chains 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CodexProjectContextResolver._turn_identity (cognitive 16) headroom/providers/codex/project_context.py:154— CodexProjectContextResolver._turn_identity has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (13 pts), error handling 1 (2 pts), loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
recovery._merge_pinned_home (cognitive 16) headroom/providers/codex/recovery.py:636— recovery._merge_pinned_home has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (9 pts), boolean chains 5, loops 1, ternaries 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
threads._codex_state_db_paths (cognitive 16) headroom/providers/codex/threads.py:40— threads._codex_state_db_paths has cognitive complexity 16 (threshold 15). Drivers by points: if/else 3 (8 pts), loops 3 (5 pts), error handling 1 (2 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
config._strip_jsonc_comments (cognitive 16) headroom/providers/opencode/config.py:129— config._strip_jsonc_comments has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (15 pts), loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
gateway_turn._usage_in_shape (cognitive 16) headroom/proxy/gateway_turn.py:1582— gateway_turn._usage_in_shape has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (9 pts), boolean chains 4, ternaries 1 (3 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AnthropicHandlerMixin._extract_cache_stable_last_message_suffix (cognitive 16) REDACTED:1171— AnthropicHandlerMixin._extract_cache_stable_last_message_suffix has cognitive complexity 16 (threshold 15). Drivers by points: if/else 8 (10 pts), boolean chains 6 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
AnthropicHandlerMixin.handle_anthropic_batch_results (cognitive 16) REDACTED:6776— AnthropicHandlerMixin.handle_anthropic_batch_results has cognitive complexity 16 (threshold 15). Drivers by points: if/else 8 (10 pts), error handling 1 (3 pts), loops 2, boolean chains 1 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
GeminiHandlerMixin._carry_tail_append_into_preserved (cognitive 16) headroom/proxy/handlers/gemini.py:229— GeminiHandlerMixin._carry_tail_append_into_preserved has cognitive complexity 16 (threshold 15). Drivers by points: if/else 12, boolean chains 3, ternaries 1. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
OpenAIHandlerMixin._observe_openai_ws_response_create (cognitive 16) REDACTED:2250— OpenAIHandlerMixin._observe_openai_ws_response_create has cognitive complexity 16 (threshold 15). Drivers by points: if/else 7 (11 pts), boolean chains 3, error handling 1, loops 1 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
helpers._read_request_body_bytes (cognitive 16) headroom/proxy/helpers.py:3313— helpers._read_request_body_bytes has cognitive complexity 16 (threshold 15). Drivers by points: error handling 3 (6 pts), if/else 4 (6 pts), boolean chains 3, loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
helpers.inject_tool_search_deferral_openai (cognitive 16) headroom/proxy/helpers.py:4793— helpers.inject_tool_search_deferral_openai has cognitive complexity 16 (threshold 15). Drivers by points: if/else 10 (12 pts), boolean chains 3, loops 1 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
output_shaper._responses_tool_output_is_error (cognitive 16) headroom/proxy/output_shaper.py:431— output_shaper._responses_tool_output_is_error has cognitive complexity 16 (threshold 15). Drivers by points: if/else 7 (11 pts), boolean chains 2, error handling 1 (2 pts), loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
output_turn_policy.classify_openai_responses_input (cognitive 16) headroom/proxy/output_turn_policy.py:100— output_turn_policy.classify_openai_responses_input has cognitive complexity 16 (threshold 15). Drivers by points: if/else 7 (11 pts), boolean chains 2, ternaries 1 (2 pts), loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
PersistentMetricsState._normalize (cognitive 16) headroom/proxy/persistent_metrics.py:203— PersistentMetricsState._normalize has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (6 pts), loops 6, ternaries 2 (3 pts), boolean chains 1 (nesting depth added 3). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
sse_byte_buffer_policy.parse_sse_events_from_byte_buffer (cognitive 16) headroom/proxy/sse_byte_buffer_policy.py:31— sse_byte_buffer_policy.parse_sse_events_from_byte_buffer has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (13 pts), loops 2 (3 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
turn_hooks.merge_provider_headers (cognitive 16) headroom/proxy/turn_hooks.py:219— turn_hooks.merge_provider_headers has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (11 pts), boolean chains 4, loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
context.detect_stack (cognitive 16) headroom/telemetry/context.py:120— context.detect_stack has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (12 pts), boolean chains 3, error handling 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MistralTokenizer.count_messages (cognitive 16) headroom/tokenizers/mistral.py:166— MistralTokenizer.count_messages has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (10 pts), loops 2 (4 pts), boolean chains 1, error handling 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CompressionCache.get (cognitive 16) headroom/transforms/content_router.py:1914— CompressionCache.get has cognitive complexity 16 (threshold 15). Drivers by points: if/else 11 (15 pts), boolean chains 1 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ContentRouter._lossless_first (cognitive 16) headroom/transforms/content_router.py:3886— ContentRouter._lossless_first has cognitive complexity 16 (threshold 15). Drivers by points: if/else 8 (10 pts), boolean chains 2, error handling 1 (2 pts), loops 1, ternaries 1 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
ReadLifecycleManager.apply (cognitive 16) headroom/transforms/read_lifecycle.py:138— ReadLifecycleManager.apply has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (11 pts), loops 1 (3 pts), boolean chains 2 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ReadLifecycleManager._classify_reads (cognitive 16) headroom/transforms/read_lifecycle.py:376— ReadLifecycleManager._classify_reads has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (10 pts), boolean chains 3, loops 2 (3 pts) (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
recursive_json._scan_spans (cognitive 16) headroom/transforms/recursive_json.py:122— recursive_json._scan_spans has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (13 pts), loops 2 (3 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
dashboard.html.dashboard.renderTransformationCard (cognitive 16) headroom/dashboard/templates/dashboard.html:2292— dashboard.html.dashboard.renderTransformationCard has cognitive complexity 16 (threshold 15). Drivers by points: boolean chains 9, ternaries 6 (7 pts) (nesting depth added 1). Of this number, 15 points are the body's own statements and 1 belongs to one function literal inside it that branches. To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
DurableAdvancementKeyStore.migrateLegacyLog (cognitive 16) plugins/openclaw/src/advancement-key-store.ts:195— DurableAdvancementKeyStore.migrateLegacyLog has cognitive complexity 16 (threshold 15). Drivers by points: if/else 6 (9 pts), boolean chains 4, error handling 2, loops 1 (nesting depth added 3). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
gateway-config.applyGatewayProviderBaseUrlsInPlace (cognitive 16) plugins/openclaw/src/gateway-config.ts:67— gateway-config.applyGatewayProviderBaseUrlsInPlace has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (7 pts), boolean chains 4, ternaries 2 (4 pts), loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
stream.parseSSE (cognitive 16) sdk/typescript/src/utils/stream.ts:8— stream.parseSSE has cognitive complexity 16 (threshold 15). Drivers by points: if/else 3 (9 pts), error handling 1 (4 pts), loops 2 (3 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
fetch (cognitive 16) deploy/beacon/worker.js:528— fetch has cognitive complexity 16 (threshold 15). Drivers by points: if/else 7 (8 pts), error handling 3 (5 pts), boolean chains 2, ternaries 1 (nesting depth added 3). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
TooManyFields: CliArgs crates/headroom-proxy/src/config.rs:231— TooManyFields — 32 stored fields. The bar is 30 stored fields; this is 2 over it, 1.07× the bar. This is width in DATA, not behaviour: every reader that takes the whole type couples to all of its fields, so a change to any one of them is a change every reader has to be checked against. To reduce it, group the fields that are read together by the same callers into a smaller type of their own, and have this one hold that type as a single member — each reader then names only the group it uses.
D4 · Code Duplication· Near-duplicate member family (3 members, 39 shared lines) · ×1
Near-duplicate member family (3 members, 39 shared lines) crates/headroom-proxy/src/compression/live_zone_anthropic.rs:610— crates/headroom-proxy/src/compression/live_zone_anthropic.rs:610-713 | crates/headroom-proxy/src/compression/live_zone_openai.rs:345-450 | crates/headroom-proxy/src/compression/live_zone_responses.rs:353-458 — These 3 members are variants of one another: a block of 39 lines reported below appears in every one of them, and the pairwise near-duplicate rows they would otherwise produce are collapsed into this row. Read them as one construct written 3 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 3 times.
D4 · Code Duplication· Near-duplicate member family (3 members, 15 shared lines) · ×1
Near-duplicate member family (3 members, 15 shared lines) crates/headroom-core/src/transforms/live_zone.rs:1345— crates/headroom-core/src/transforms/live_zone.rs:1345-1519 | crates/headroom-core/src/transforms/live_zone.rs:2422-2510 | crates/headroom-core/src/transforms/live_zone.rs:2909-3037 — These 3 members are variants of one another: a block of 15 lines reported below appears in every one of them, and the pairwise near-duplicate rows they would otherwise produce are collapsed into this row. Read them as one construct written 3 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 3 times.
Near-duplicate member pair (211 shared lines) crates/headroom-proxy/src/bedrock/invoke.rs:146— crates/headroom-proxy/src/bedrock/invoke.rs:146-470 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:131-509 — These two members are variants of one another: 211 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
Near-duplicate member pair (105 shared lines) crates/headroom-proxy/src/compression/live_zone_openai.rs:64— crates/headroom-proxy/src/compression/live_zone_openai.rs:64-303 | crates/headroom-proxy/src/compression/live_zone_responses.rs:64-311 — These two members are variants of one another: 105 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
Near-duplicate member pair (52 shared lines) headroom/evals/core.py:285— headroom/evals/core.py:285-377 | headroom/evals/runners/before_after.py:286-393 — These two members are variants of one another: 52 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
Near-duplicate member pair (46 shared lines) headroom/providers/anthropic.py:407— headroom/providers/anthropic.py:407-505 | headroom/providers/openai.py:188-264 — These two members are variants of one another: 46 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
D4 · Code Duplication· Members sharing a duplicated core (7 members, 50+ identical tokens) · ×1
Members sharing a duplicated core (7 members, 50+ identical tokens) headroom/cli/evals.py:154— headroom/cli/evals.py:154-184 | headroom/cli/evals.py:343-361 | headroom/cli/install.py:976-1035 | headroom/cli/wrap.py:7808-7840 | REDACTED:1182-1233 | headroom/proxy/prometheus_metrics.py:904-1260 | headroom/testing/harness.py:1039-1059 — These 7 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 7 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 7 times.
D4 · Code Duplication· Edited copy of a member (67 corresponding lines) · ×1
Edited copy of a member (67 corresponding lines) crates/headroom-core/src/transforms/log_compressor.rs:1156— crates/headroom-core/src/transforms/log_compressor.rs:1156-1228 | crates/headroom-core/src/transforms/search_compressor.rs:335-401 — These two members are one piece of code written twice and then edited apart: 67 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (75 corresponding lines) · ×1
Edited copy of a member (75 corresponding lines) headroom/evals/runners/compression_only.py:79— headroom/evals/runners/compression_only.py:79-166 | headroom/evals/runners/compression_only.py:172-246 — These two members are one piece of code written twice and then edited apart: 75 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (66 corresponding lines) · ×1
Edited copy of a member (66 corresponding lines) crates/headroom-proxy/src/bedrock/invoke.rs:486— crates/headroom-proxy/src/bedrock/invoke.rs:486-570 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:889-954 — These two members are one piece of code written twice and then edited apart: 66 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 48+ corresponding lines) · ×1
Edited copies of one member (3 members, 48+ corresponding lines) headroom/evals/batch_compression_eval.py:1224— headroom/evals/batch_compression_eval.py:1224-1290 | headroom/evals/core.py:385-444 | headroom/evals/runners/before_after.py:471-518 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 48 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (65 corresponding lines) · ×1
Edited copy of a member (65 corresponding lines) headroom/memory/writers/base.py:107— headroom/memory/writers/base.py:107-171 | headroom/memory/writers/cursor_writer.py:66-133 — These two members are one piece of code written twice and then edited apart: 65 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (49 corresponding lines) · ×1
Edited copy of a member (49 corresponding lines) headroom/memory/wrapper_tools.py:208— headroom/memory/wrapper_tools.py:208-258 | headroom/memory/wrapper_tools.py:441-489 — These two members are one piece of code written twice and then edited apart: 49 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (68 corresponding lines) · ×1
Edited copy of a member (68 corresponding lines) headroom/integrations/agno/model.py:736— headroom/integrations/agno/model.py:736-803 | headroom/integrations/strands/model.py:537-611 — These two members are one piece of code written twice and then edited apart: 68 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (36 corresponding lines) · ×1
Edited copy of a member (36 corresponding lines) headroom/proxy/tool_schema_compaction.py:242— headroom/proxy/tool_schema_compaction.py:242-277 | headroom/proxy/tool_schema_compaction.py:375-440 — These two members are one piece of code written twice and then edited apart: 36 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 18+ corresponding lines) · ×1
Edited copies of one member (3 members, 18+ corresponding lines) headroom/learn/plugins/codex.py:97— headroom/learn/plugins/codex.py:97-118 | headroom/learn/plugins/gemini.py:113-136 | headroom/learn/plugins/grok.py:91-108 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 18 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (46 corresponding lines) · ×1
Edited copy of a member (46 corresponding lines) headroom/evals/memory/judge.py:53— headroom/evals/memory/judge.py:53-98 | headroom/evals/memory/judge.py:105-151 — These two members are one piece of code written twice and then edited apart: 46 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 28+ corresponding lines) · ×1
Edited copies of one member (3 members, 28+ corresponding lines) headroom/transforms/lossless_compaction.py:273— headroom/transforms/lossless_compaction.py:273-306 | headroom/transforms/lossless_compaction.py:347-374 | headroom/transforms/lossless_compaction.py:438-465 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 28 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (43 corresponding lines) · ×1
Edited copy of a member (43 corresponding lines) headroom/proxy/helpers.py:3457— headroom/proxy/helpers.py:3457-3499 | headroom/proxy/helpers.py:3503-3554 — These two members are one piece of code written twice and then edited apart: 43 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (37 corresponding lines) · ×1
Edited copy of a member (37 corresponding lines) headroom/transforms/content_detector.py:600— headroom/transforms/content_detector.py:600-636 | headroom/transforms/content_detector.py:640-679 — These two members are one piece of code written twice and then edited apart: 37 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 26+ corresponding lines) · ×1
Edited copies of one member (3 members, 26+ corresponding lines) headroom/proxy/savings_tracker.py:427— headroom/proxy/savings_tracker.py:427-452 | headroom/proxy/savings_tracker.py:456-485 | headroom/proxy/savings_tracker.py:500-537 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 26 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (29 corresponding lines) · ×1
Edited copy of a member (29 corresponding lines) headroom/proxy/auth_mode.py:40— headroom/proxy/auth_mode.py:40-75 | headroom/proxy/tenant_key.py:217-245 — These two members are one piece of code written twice and then edited apart: 29 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 16+ corresponding lines) · ×1
Edited copies of one member (3 members, 16+ corresponding lines) crates/headroom-proxy/src/observability/cache_hit_rate.rs:80— crates/headroom-proxy/src/observability/cache_hit_rate.rs:80-95 | crates/headroom-proxy/src/observability/compression_ratio.rs:53-68 | crates/headroom-proxy/src/observability/prometheus.rs:157-174 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 16 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 36+ corresponding lines) · ×1
Edited copies of one member (3 members, 36+ corresponding lines) headroom/cli/wrap.py:7880— headroom/cli/wrap.py:7880-7916 | headroom/cli/wrap.py:7948-7983 | headroom/cli/wrap.py:9517-9566 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 36 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (50 corresponding lines) · ×1
Edited copy of a member (50 corresponding lines) headroom/memory/system.py:500— headroom/memory/system.py:500-552 | headroom/memory/system.py:559-608 — These two members are one piece of code written twice and then edited apart: 50 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (6 members, 15+ corresponding lines) · ×1
Edited copies of one member (6 members, 15+ corresponding lines) crates/headroom-proxy/src/observability/compression_ratio.rs:71— crates/headroom-proxy/src/observability/compression_ratio.rs:71-85 | crates/headroom-proxy/src/observability/prometheus.rs:138-153 | crates/headroom-proxy/src/observability/prometheus.rs:178-194 | crates/headroom-proxy/src/observability/proxy_metrics.rs:36-50 | crates/headroom-proxy/src/observability/proxy_metrics.rs:213-227 | crates/headroom-proxy/src/observability/proxy_metrics.rs:244-258 — These 6 members are one piece of code written 6 times and then edited apart: every two of them correspond over at least 15 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 6 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 20+ corresponding lines) · ×1
Edited copies of one member (3 members, 20+ corresponding lines) crates/headroom-core/src/transforms/pipeline/offloads/diff_offload.rs:136— crates/headroom-core/src/transforms/pipeline/offloads/diff_offload.rs:136-156 | crates/headroom-core/src/transforms/pipeline/offloads/log_offload.rs:149-169 | crates/headroom-core/src/transforms/pipeline/offloads/search_offload.rs:120-139 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 20 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 25+ corresponding lines) · ×1
Edited copies of one member (3 members, 25+ corresponding lines) headroom/integrations/langchain/chat_model.py:506— headroom/integrations/langchain/chat_model.py:506-530 | headroom/integrations/strands/model.py:384-422 | headroom/integrations/strands/model.py:447-476 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 25 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 41+ corresponding lines) · ×1
Edited copies of one member (3 members, 41+ corresponding lines) headroom/memory/adapters/sqlite.py:120— headroom/memory/adapters/sqlite.py:120-196 | headroom/memory/adapters/sqlite_graph.py:105-163 | headroom/memory/adapters/sqlite_vector.py:347-387 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 41 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 5+ corresponding lines) · ×1
Edited copies of one member (3 members, 5+ corresponding lines) headroom/testing/harness.py:1012— headroom/testing/harness.py:1012-1016 | headroom/testing/harness.py:1274-1283 | headroom/testing/harness.py:1319-1325 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 5 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (20 corresponding lines) · ×1
Edited copy of a member (20 corresponding lines) headroom/cli/wrap.py:3497— headroom/cli/wrap.py:3497-3518 | headroom/cli/wrap.py:3522-3541 — These two members are one piece of code written twice and then edited apart: 20 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 11+ corresponding lines) · ×1
Edited copies of one member (3 members, 11+ corresponding lines) headroom/cache/backends/sqlite.py:300— headroom/cache/backends/sqlite.py:300-312 | headroom/cache/backends/sqlite.py:357-368 | headroom/cache/backends/sqlite.py:371-381 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 11 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 13+ corresponding lines) · ×1
Edited copies of one member (3 members, 13+ corresponding lines) headroom/cli/wrap.py:3620— headroom/cli/wrap.py:3620-3646 | headroom/providers/grok_build/config.py:43-55 | headroom/providers/opencode/config.py:96-113 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 13 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 9+ corresponding lines) · ×1
Edited copies of one member (4 members, 9+ corresponding lines) headroom/cli/port_discovery.py:105— headroom/cli/port_discovery.py:105-116 | headroom/cli/wrap.py:5779-5788 | headroom/proxy/orphan_watchdog.py:65-73 | headroom/proxy_client_liveness.py:67-77 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 9 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (4 members, 2+ corresponding lines) · ×1
Edited copies of one member (4 members, 2+ corresponding lines) headroom/mcp_registry/claude.py:589— headroom/mcp_registry/claude.py:589-590 | headroom/mcp_registry/ledger.py:174-175 | headroom/mcp_registry/opencode.py:114-115 | headroom/providers/claude/vscode.py:110-111 — These 4 members are one piece of code written 4 times and then edited apart: every two of them correspond over at least 2 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 4 times and the copies will drift further apart.
Duplicated block (64–66 lines × 2) headroom/integrations/agno/model.py:480— headroom/integrations/agno/model.py:480-545 | headroom/integrations/strands/model.py:308-371 — `headroom/integrations/agno/model.py` and `headroom/integrations/strands/model.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 4 separate duplicated blocks between them, totalling at least 113 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/integrations/agno/model.py:480` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (52–55 lines × 2) headroom/proxy/helpers.py:1000— headroom/proxy/helpers.py:1000-1054 | headroom/proxy/helpers.py:1286-1337 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (45–47 lines × 2) headroom/backends/litellm.py:1273— headroom/backends/litellm.py:1273-1319 | headroom/backends/litellm.py:1402-1446 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (43–47 lines × 2) REDACTED:3563— REDACTED:3563-3605 | REDACTED:6223-6269 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (33–46 lines × 2) headroom/memory/writers/base.py:107— headroom/memory/writers/base.py:107-152 | headroom/memory/writers/cursor_writer.py:66-98 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (33–45 lines × 2) REDACTED:4424— REDACTED:4424-4456 | REDACTED:5569-5613 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:4424` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (33–44 lines × 2) headroom/providers/openai.py:406— headroom/providers/openai.py:406-449 | headroom/providers/openai_compatible.py:152-184 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/providers/openai.py:450` calls `count_text`, `coerce_countable_text`, `get` and `headroom/providers/openai_compatible.py:185` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (35–40 lines × 2) REDACTED:281— REDACTED:281-315 | headroom/memory/backends/mem0.py:155-194 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (38 lines × 2) headroom/providers/openai_compatible.py:390— headroom/providers/openai_compatible.py:390-427 | headroom/providers/openai_compatible.py:433-470 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (33–38 lines × 2) REDACTED:5392— REDACTED:5392-5429 | REDACTED:5937-5969 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:5392` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (22–36 lines × 2) headroom/memory/adapters/hnsw.py:696— headroom/memory/adapters/hnsw.py:696-731 | headroom/memory/adapters/sqlite_vector.py:793-814 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (26–35 lines × 2) headroom/memory/bridge_parsers.py:269— headroom/memory/bridge_parsers.py:269-303 | headroom/memory/bridge_parsers.py:390-415 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/memory/bridge_parsers.py:416` calls `startswith` and `headroom/memory/bridge_parsers.py:305` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (34 lines × 2) headroom/memory/bridge_parsers.py:303— headroom/memory/bridge_parsers.py:303-336 | headroom/memory/bridge_parsers.py:418-451 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `headroom/memory/bridge_parsers.py:416` calls `startswith` and `headroom/memory/bridge_parsers.py:302` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (27–33 lines × 3) headroom/proxy/handlers/gemini.py:438— headroom/proxy/handlers/gemini.py:438-464 | REDACTED:3588-3616 | REDACTED:6248-6280 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (26–33 lines × 2) REDACTED:1869— REDACTED:1869-1901 | REDACTED:3873-3898 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:1869` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (28–33 lines × 2) REDACTED:2022— REDACTED:2022-2054 | REDACTED:4022-4049 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:2022` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `REDACTED:2055` calls `_finalize_pre_upstream` and `REDACTED:4050` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (12–32 lines × 2) headroom/backends/anyllm.py:81— headroom/backends/anyllm.py:81-92 | headroom/backends/litellm.py:1008-1039 — before extracting anything, compare `headroom/backends/anyllm.py` and `headroom/backends/litellm.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 90 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (26–32 lines × 2) headroom/cli/memory.py:110— headroom/cli/memory.py:110-141 | headroom/cli/memory.py:177-202 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/cli/memory.py:110` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (31–32 lines × 2) headroom/evals/runners/compression_only.py:131— headroom/evals/runners/compression_only.py:131-162 | headroom/evals/runners/compression_only.py:212-242 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/evals/runners/compression_only.py:131` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (27–32 lines × 2) REDACTED:4117— REDACTED:4117-4148 | REDACTED:5107-5133 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:4117` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (15–31 lines × 3) REDACTED:2174— REDACTED:2174-2188 | REDACTED:2213-2236 | REDACTED:2259-2289 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:2213` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (28–31 lines × 2) REDACTED:4949— REDACTED:4949-4979 | REDACTED:5686-5713 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (23–30 lines × 2) REDACTED:662— REDACTED:662-691 | headroom/providers/codex/recovery.py:408-430 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (22–30 lines × 2) headroom/image/onnx_router.py:262— headroom/image/onnx_router.py:262-283 | headroom/image/trained_router.py:329-358 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/image/onnx_router.py:262` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (30 lines × 2) REDACTED:8995— REDACTED:8995-9024 | REDACTED:9402-9431 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:8995` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (29 lines × 2) REDACTED:6858— REDACTED:6858-6886 | headroom/proxy/handlers/batch.py:771-799 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (26–27 lines × 2) headroom/evals/memory/runner.py:171— headroom/evals/memory/runner.py:171-196 | headroom/evals/memory/runner_v2.py:278-304 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (23–27 lines × 2) REDACTED:11817— REDACTED:11817-11843 | REDACTED:11859-11881 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:11817` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (21–25 lines × 2) headroom/integrations/agno/model.py:431— headroom/integrations/agno/model.py:431-451 | headroom/integrations/strands/model.py:275-299 — `headroom/integrations/agno/model.py` and `headroom/integrations/strands/model.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 4 separate duplicated blocks between them, totalling at least 113 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/integrations/agno/model.py:431` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11–24 lines × 2) REDACTED:326— REDACTED:326-336 | headroom/cache/openai.py:468-491 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (22–24 lines × 2) headroom/providers/proxy_routes.py:549— headroom/providers/proxy_routes.py:549-570 | headroom/providers/proxy_routes.py:599-622 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/providers/proxy_routes.py:549` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (23–24 lines × 2) headroom/proxy/handlers/gemini.py:494— headroom/proxy/handlers/gemini.py:494-516 | REDACTED:3692-3715 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/proxy/handlers/gemini.py:494` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `REDACTED:3690` calls `_openai_outcome_provider` and `headroom/proxy/handlers/gemini.py:493` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (19–23 lines × 3) headroom/memory/writers/claude_writer.py:35— headroom/memory/writers/claude_writer.py:35-57 | headroom/memory/writers/codex_writer.py:25-43 | headroom/memory/writers/generic_writer.py:33-52 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from all 3 call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (53–59 lines × 2) REDACTED:4986— REDACTED:4986-5044 | REDACTED:5716-5768 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (22–23 lines × 2) REDACTED:3642— REDACTED:3642-3664 | REDACTED:6340-6361 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:3642` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (22 lines × 3) REDACTED:6321— REDACTED:6321-6342 | REDACTED:6661-6682 | REDACTED:6806-6827 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:6321` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (18–22 lines × 2) REDACTED:1979— REDACTED:1979-2000 | REDACTED:3987-4004 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:1979` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (21–22 lines × 2) headroom/proxy/handlers/batch.py:587— headroom/proxy/handlers/batch.py:587-608 | headroom/proxy/handlers/batch.py:810-830 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/proxy/handlers/batch.py:587` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11–22 lines × 2) headroom/transforms/content_router.py:8057— headroom/transforms/content_router.py:8057-8067 | headroom/transforms/content_router.py:8151-8172 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (20–21 lines × 4) REDACTED:6712— REDACTED:6712-6732 | headroom/proxy/handlers/batch.py:508-527 | headroom/proxy/handlers/batch.py:599-618 | headroom/proxy/handlers/batch.py:1356-1375 — there are 4 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 4 sites; resolving a subset leaves the remainder to drift apart. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:6712` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (10–20 lines × 2) headroom/memory/adapters/hnsw.py:324— headroom/memory/adapters/hnsw.py:324-343 | headroom/memory/adapters/sqlite_vector.py:295-304 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (15–19 lines × 3) REDACTED:2515— REDACTED:2515-2529 | REDACTED:2615-2629 | REDACTED:2796-2814 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (17–19 lines × 2) REDACTED:5915— REDACTED:5915-5931 | REDACTED:7376-7394 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:7376` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (18 lines × 4) headroom/backends/litellm.py:1327— headroom/backends/litellm.py:1327-1344 | headroom/backends/litellm.py:1450-1467 | headroom/backends/litellm.py:1856-1873 | headroom/backends/litellm.py:2066-2083 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/backends/litellm.py:1346` calls `debug` and `headroom/backends/litellm.py:2087` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (16–18 lines × 3) REDACTED:1498— REDACTED:1498-1515 | REDACTED:3641-3656 | REDACTED:6337-6354 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart.
Duplicated block (14–18 lines × 3) REDACTED:2561— REDACTED:2561-2574 | REDACTED:2614-2627 | REDACTED:2795-2812 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:2561` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11–18 lines × 2) headroom/integrations/langchain/chat_model.py:277— headroom/integrations/langchain/chat_model.py:277-287 | headroom/integrations/langchain/memory.py:278-295 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (14–18 lines × 2) headroom/memory/adapters/hnsw.py:170— headroom/memory/adapters/hnsw.py:170-187 | headroom/memory/adapters/sqlite_vector.py:165-178 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (15–18 lines × 2) headroom/providers/anthropic.py:491— headroom/providers/anthropic.py:491-505 | headroom/providers/openai.py:247-264 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (17–18 lines × 2) headroom/release_version.py:316— headroom/release_version.py:316-333 | headroom/release_version.py:338-354 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/release_version.py:316` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (14–17 lines × 3) headroom/backends/anyllm.py:295— headroom/backends/anyllm.py:295-308 | headroom/backends/litellm.py:1282-1298 | headroom/backends/litellm.py:1415-1430 — before extracting anything, compare `headroom/backends/anyllm.py` and `headroom/backends/litellm.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 90 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/backends/litellm.py:1282` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9–17 lines × 3) headroom/context_tool_cleanup.py:542— headroom/context_tool_cleanup.py:542-550 | headroom/context_tool_cleanup.py:567-583 | headroom/context_tool_cleanup.py:686-699 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (16–17 lines × 3) headroom/learn/plugins/codex.py:103— headroom/learn/plugins/codex.py:103-118 | headroom/learn/plugins/gemini.py:120-136 | headroom/learn/plugins/grok.py:93-108 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from all 3 call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/learn/plugins/gemini.py:120` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (13–17 lines × 2) headroom/cli/wrap.py:5201— headroom/cli/wrap.py:5201-5213 | headroom/cli/wrap.py:5365-5381 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12–17 lines × 2) REDACTED:787— REDACTED:787-803 | REDACTED:898-909 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12–16 lines × 2) headroom/cache/semantic.py:566— headroom/cache/semantic.py:566-577 | headroom/client.py:727-742 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (15 lines × 7) headroom/cli/evals.py:170— headroom/cli/evals.py:170-184 | headroom/cli/evals.py:347-361 | headroom/cli/install.py:1008-1022 | headroom/cli/wrap.py:7826-7840 | REDACTED:1216-1230 | headroom/proxy/prometheus_metrics.py:1243-1257 | headroom/testing/harness.py:1043-1057 — there are 7 copies across 6 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 7 sites; resolving a subset leaves the remainder to drift apart. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/cli/evals.py:170` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14–15 lines × 4) headroom/proxy/handlers/gemini.py:740— headroom/proxy/handlers/gemini.py:740-754 | headroom/proxy/handlers/gemini.py:1356-1369 | headroom/proxy/handlers/gemini.py:1584-1597 | REDACTED:4213-4226 — there are 4 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 4 sites; resolving a subset leaves the remainder to drift apart. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/proxy/handlers/gemini.py:757` calls `_gemini_contents_to_messages` and `headroom/proxy/handlers/gemini.py:1598` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (15 lines × 3) headroom/proxy/handlers/batch.py:125— headroom/proxy/handlers/batch.py:125-139 | headroom/proxy/handlers/batch.py:910-924 | headroom/proxy/handlers/gemini.py:1515-1529 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart.
Duplicated block (14–15 lines × 3) REDACTED:9233— REDACTED:9233-9247 | REDACTED:9758-9772 | REDACTED:10058-10071 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:9233` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (11–15 lines × 2) headroom/integrations/strands/model.py:188— headroom/integrations/strands/model.py:188-202 | headroom/integrations/strands/model.py:258-268 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (13–15 lines × 2) headroom/learn/plugins/claude.py:363— headroom/learn/plugins/claude.py:363-375 | headroom/learn/plugins/gemini.py:287-301 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/learn/plugins/gemini.py:287` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11–14 lines × 3) REDACTED:4439— REDACTED:4439-4451 | REDACTED:5595-5608 | REDACTED:2418-2428 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:4439` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (13–14 lines × 2) headroom/evals/batch_compression_eval.py:210— headroom/evals/batch_compression_eval.py:210-223 | headroom/evals/core.py:180-192 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (4–14 lines × 3) headroom/evals/batch_compression_eval.py:1262— headroom/evals/batch_compression_eval.py:1262-1265 | headroom/evals/core.py:420-433 | headroom/evals/runners/before_after.py:494-507 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/evals/core.py:420` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (9–13 lines × 4) headroom/backends/anyllm.py:249— headroom/backends/anyllm.py:249-257 | headroom/backends/anyllm.py:301-309 | headroom/backends/litellm.py:1423-1431 | REDACTED:1884-1896 — before extracting anything, compare `headroom/backends/anyllm.py` and `headroom/backends/litellm.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 90 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (13 lines × 4) REDACTED:2560— REDACTED:2560-2572 | REDACTED:2613-2625 | REDACTED:2658-2670 | REDACTED:2721-2733 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:2560` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (6–13 lines × 3) headroom/proxy/prometheus_metrics.py:1538— headroom/proxy/prometheus_metrics.py:1538-1550 | headroom/proxy/prometheus_metrics.py:1552-1564 | headroom/proxy/prometheus_metrics.py:1565-1570 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `headroom/proxy/prometheus_metrics.py:1538` calls `_format_labels` and `headroom/proxy/prometheus_metrics.py:1565` does not — after which the two agree again for 5 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (8–12 lines × 4) headroom/memory/writers/claude_writer.py:40— headroom/memory/writers/claude_writer.py:40-51 | headroom/memory/writers/codex_writer.py:29-38 | headroom/memory/writers/cursor_writer.py:41-48 | headroom/memory/writers/generic_writer.py:38-47 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from all 4 call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/memory/writers/claude_writer.py:40` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11–12 lines × 3) REDACTED:6480— REDACTED:6480-6490 | headroom/proxy/handlers/batch.py:241-252 | headroom/proxy/handlers/batch.py:1224-1235 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:6480` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately. Note first that the copies are not typed on the same thing: `CCRToolInjector` names `headroom.ccr` in one and `headroom.ccr.tool_injection` in another — different types that share a simple name, which is why the text matched. A single extracted unit cannot be given a parameter type that fits both, so unifying those types (or introducing a shared abstraction over them) is the step that has to come BEFORE the extraction above; if they are deliberately separate, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `REDACTED:6490` calls `debug` and `headroom/proxy/handlers/batch.py:252` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (6–12 lines × 2) headroom/integrations/strands/model.py:195— headroom/integrations/strands/model.py:195-206 | headroom/integrations/strands/model.py:574-579 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/integrations/strands/model.py:195` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (11 lines × 5) headroom/proxy/handlers/batch.py:127— headroom/proxy/handlers/batch.py:127-137 | headroom/proxy/handlers/batch.py:552-562 | headroom/proxy/handlers/batch.py:703-713 | headroom/proxy/handlers/batch.py:912-922 | headroom/proxy/handlers/gemini.py:1517-1527 — there are 5 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 5 sites; resolving a subset leaves the remainder to drift apart. Read the line range as the matched WINDOW rather than a finished unit: at `headroom/proxy/handlers/batch.py:127` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9–11 lines × 3) headroom/memory/adapters/embedders.py:654— headroom/memory/adapters/embedders.py:654-662 | headroom/memory/adapters/embedders.py:857-867 | headroom/memory/adapters/embedders.py:1091-1101 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (8–9 lines × 4) headroom/memory/adapters/embedders.py:422— headroom/memory/adapters/embedders.py:422-430 | headroom/memory/adapters/embedders.py:653-660 | headroom/memory/adapters/embedders.py:856-864 | headroom/memory/adapters/embedders.py:1090-1098 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (8–9 lines × 3) headroom/memory/bridge.py:467— headroom/memory/bridge.py:467-475 | headroom/memory/bridge.py:502-509 | headroom/memory/bridge.py:631-639 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (6–9 lines × 2) headroom/proxy/savings_tracker.py:754— headroom/proxy/savings_tracker.py:754-762 | headroom/proxy/savings_tracker.py:1930-1935 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8–9 lines × 2) headroom/transforms/read_lifecycle.py:221— headroom/transforms/read_lifecycle.py:221-229 | headroom/transforms/read_lifecycle.py:246-253 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `headroom/transforms/read_lifecycle.py:219` calls `loads`, `get`, `except` and `headroom/transforms/read_lifecycle.py:245` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (7–8 lines × 3) REDACTED:330— REDACTED:330-337 | headroom/cache/openai.py:486-492 | REDACTED:2146-2152 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from all 3 call sites, so a change lands once.
Duplicated block (6–7 lines × 2) headroom/proxy/savings_tracker.py:1932— headroom/proxy/savings_tracker.py:1932-1937 | headroom/proxy/savings_tracker.py:2379-2385 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (6 lines × 4) REDACTED:637— REDACTED:637-642 | headroom/providers/cohere.py:188-193 | headroom/providers/google.py:196-201 | headroom/tokenizers/mistral.py:189-194 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 4 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 4 times.
Duplicated block (37–44 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:608— crates/headroom-proxy/src/bedrock/invoke.rs:608-651 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:994-1030 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Each matched range is the entire body of the declaration above it, so the region is already a complete unit: move that whole declaration to the shared location and have each site call it, rather than lifting the lines out of their bodies. Any `return` inside it is the body's own exit and keeps its meaning in the moved unit.
Duplicated block (40–43 lines × 2) crates/headroom-proxy/src/compression/live_zone_openai.rs:154— crates/headroom-proxy/src/compression/live_zone_openai.rs:154-196 | crates/headroom-proxy/src/compression/live_zone_responses.rs:165-204 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_openai.rs` and `crates/headroom-proxy/src/compression/live_zone_responses.rs` as WHOLE FILES: this scan already matched 14 separate duplicated blocks between them, totalling at least 278 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_openai.rs:154` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (37–41 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:333— crates/headroom-proxy/src/bedrock/invoke.rs:333-373 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:299-335 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:333` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (33–38 lines × 3) crates/headroom-proxy/src/compression/live_zone_anthropic.rs:440— crates/headroom-proxy/src/compression/live_zone_anthropic.rs:440-477 | crates/headroom-proxy/src/compression/live_zone_openai.rs:183-215 | crates/headroom-proxy/src/compression/live_zone_responses.rs:191-223 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_anthropic.rs` and `crates/headroom-proxy/src/compression/live_zone_openai.rs` as WHOLE FILES: this scan already matched 6 separate duplicated blocks between them, totalling at least 113 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_anthropic.rs:440` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (24–32 lines × 2) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:158— crates/headroom-core/src/transforms/smart_crusher/crusher.rs:158-181 | crates/headroom-core/src/transforms/smart_crusher/crusher.rs:398-429 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/smart_crusher/crusher.rs:158` it runs out through the closing brace of the declaration holding it — the window is that declaration's tail, not a fragment that begins part-way through something, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (23–29 lines × 2) crates/headroom-core/src/transforms/live_zone.rs:1351— crates/headroom-core/src/transforms/live_zone.rs:1351-1379 | crates/headroom-core/src/transforms/live_zone.rs:2425-2447 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/live_zone.rs:1351` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (24–29 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:529— crates/headroom-proxy/src/bedrock/invoke.rs:529-557 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:918-941 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:529` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (17–27 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:147— crates/headroom-proxy/src/bedrock/invoke.rs:147-173 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:132-148 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:147` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (24–25 lines × 2) crates/headroom-core/src/transforms/live_zone.rs:2323— crates/headroom-core/src/transforms/live_zone.rs:2323-2347 | crates/headroom-core/src/transforms/live_zone.rs:2834-2857 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/live_zone.rs:2323` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12–24 lines × 3) crates/headroom-proxy/src/compression/live_zone_anthropic.rs:416— crates/headroom-proxy/src/compression/live_zone_anthropic.rs:416-439 | crates/headroom-proxy/src/compression/live_zone_openai.rs:167-181 | crates/headroom-proxy/src/compression/live_zone_responses.rs:178-189 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_anthropic.rs` and `crates/headroom-proxy/src/compression/live_zone_openai.rs` as WHOLE FILES: this scan already matched 6 separate duplicated blocks between them, totalling at least 113 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_anthropic.rs:416` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (13–20 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:430— crates/headroom-proxy/src/bedrock/invoke.rs:430-449 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:426-438 — before extracting anything, compare `crates/headroom-proxy/src/bedrock/invoke.rs` and `crates/headroom-proxy/src/bedrock/invoke_streaming.rs` as WHOLE FILES: this scan already matched 16 separate duplicated blocks between them, totalling at least 371 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/bedrock/invoke.rs:430` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10–19 lines × 3) crates/headroom-core/src/transforms/live_zone.rs:1078— crates/headroom-core/src/transforms/live_zone.rs:1078-1096 | crates/headroom-core/src/transforms/live_zone.rs:2326-2335 | crates/headroom-core/src/transforms/live_zone.rs:2836-2845 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/live_zone.rs:1078` it runs out through the closing brace of the declaration holding it and carries on into the declaration that follows — the window is the tail of one member plus the head of the next, so no call can be substituted for those exact lines, and the smallest declaration that contains all of them is the type they sit in. The repeated unit is the member each site sits in: where those members' bodies are the same, move one whole member to the shared location and have the others delegate to it; where the copies are a run of near-identical overloads or wrappers that differ only in their signatures, the repetition IS the run — a one-line delegation has no helper inside it to lift — so generate the run from the set it enumerates, or accept it and keep each member's own documentation with it.
Duplicated block (18 lines × 3) crates/headroom-core/src/transforms/smart_crusher/planning.rs:220— crates/headroom-core/src/transforms/smart_crusher/planning.rs:220-237 | crates/headroom-core/src/transforms/smart_crusher/planning.rs:417-434 | crates/headroom-core/src/transforms/smart_crusher/planning.rs:477-494 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-core/src/transforms/smart_crusher/planning.rs:220` it runs out through the closing brace of the declaration holding it — the window is that declaration's tail, not a fragment that begins part-way through something, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `crates/headroom-core/src/transforms/smart_crusher/planning.rs:474` calls `apply_constraints` and `crates/headroom-core/src/transforms/smart_crusher/planning.rs:217` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (16–17 lines × 2) crates/headroom-proxy/src/main.rs:221— crates/headroom-proxy/src/main.rs:221-237 | crates/headroom-simulators/src/main.rs:53-68 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (14–16 lines × 3) crates/headroom-proxy/src/compression/live_zone_anthropic.rs:690— crates/headroom-proxy/src/compression/live_zone_anthropic.rs:690-705 | crates/headroom-proxy/src/compression/live_zone_openai.rs:412-425 | crates/headroom-proxy/src/compression/live_zone_responses.rs:420-433 — before extracting anything, compare `crates/headroom-proxy/src/compression/live_zone_anthropic.rs` and `crates/headroom-proxy/src/compression/live_zone_openai.rs` as WHOLE FILES: this scan already matched 6 separate duplicated blocks between them, totalling at least 113 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/compression/live_zone_anthropic.rs:690` it runs out through the closing brace of the declaration holding it and carries on into the declaration that follows — the window is the tail of one member plus the head of the next, so no call can be substituted for those exact lines, and the smallest declaration that contains all of them is the type they sit in. The repeated unit is the member each site sits in: where those members' bodies are the same, move one whole member to the shared location and have the others delegate to it; where the copies are a run of near-identical overloads or wrappers that differ only in their signatures, the repetition IS the run — a one-line delegation has no helper inside it to lift — so generate the run from the set it enumerates, or accept it and keep each member's own documentation with it.
Duplicated block (9–12 lines × 2) crates/headroom-proxy/src/handlers/chat_completions.rs:71— crates/headroom-proxy/src/handlers/chat_completions.rs:71-82 | crates/headroom-proxy/src/handlers/responses.rs:145-153 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `crates/headroom-proxy/src/handlers/chat_completions.rs:71` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
D4 · Code Duplication· Edited copy of a member (161 corresponding lines) · ×1
Edited copy of a member (161 corresponding lines) examples/strands_bedrock_demo.py:515— examples/strands_bedrock_demo.py:515-689 | examples/strands_bedrock_demo.py:698-858 — These two members are one piece of code written twice and then edited apart: 161 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (84 corresponding lines) · ×1
Edited copy of a member (84 corresponding lines) examples/langchain_demo/run_comparison.py:155— examples/langchain_demo/run_comparison.py:155-238 | examples/langchain_demo/run_comparison.py:242-339 — These two members are one piece of code written twice and then edited apart: 84 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 15+ corresponding lines) · ×1
Edited copies of one member (3 members, 15+ corresponding lines) REDACTED:123— REDACTED:123-137 | examples/vertex_gemini_benchmark/benchmark.py:137-151 | examples/vertex_genai_sdk_demo.py:93-107 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 15 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (2 corresponding lines) · ×1
Edited copy of a member (2 corresponding lines) scripts/build_python_release_smoke.py:52— scripts/build_python_release_smoke.py:52-53 | scripts/release_smoke_all.py:43-44 — These two members are one piece of code written twice and then edited apart: 2 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (3 corresponding lines) · ×1
Edited copy of a member (3 corresponding lines) scripts/build_python_release_smoke.py:57— scripts/build_python_release_smoke.py:57-59 | scripts/release_smoke_all.py:48-50 — These two members are one piece of code written twice and then edited apart: 3 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (60–63 lines × 2) examples/langchain_demo/run_comparison.py:164— examples/langchain_demo/run_comparison.py:164-226 | examples/langchain_demo/run_comparison.py:265-324 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `examples/langchain_demo/run_comparison.py:164` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7–12 lines × 4) scripts/version-sync.py:41— scripts/version-sync.py:41-47 | scripts/version-sync.py:51-57 | scripts/version-sync.py:122-133 | scripts/version-sync.py:137-148 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (7–11 lines × 2) scripts/build_python_release_smoke.py:194— scripts/build_python_release_smoke.py:194-204 | scripts/release_smoke_all.py:54-60 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `scripts/build_python_release_smoke.py:194` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `scripts/release_smoke_all.py:60` calls `add_argument`, `which` and `scripts/build_python_release_smoke.py:204` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
End-of-life runtime: Rust 1.95 rust-toolchain.toml:1— rust-toolchain.toml declares Rust 1.95 as this project's toolchain file, and Rust 1.95, superseded by 1.96 on 2026-05-28 (the Rust project patches only the current stable). An unsupported runtime receives no security patches, so every vulnerability disclosed in it since 2026-05-28 is present and unfixable without moving off it. This is a migration rather than an upgrade: there is no newer release of a runtime that has ended.
Off the main sequence: headroom-core — headroom-core: abstractness 0.06, instability 0.00, distance 0.94 — zone of pain — concrete and depended on by 3 project(s), so it's rigid to change.
Coverage not measured — JavaScript/TypeScript suite — Coverage NOT MEASURED: the JavaScript/TypeScript half could not be measured — the node:test suite in e2e/wrap/tools/ ran and not one test passed (throw new ERR_INVALID_ARG_VALUE(), so the coverage would describe the failed run, not the code. Coverage is excluded from the score rather than counted as a near-zero. The named suite step is one the repository's maintainers can perform; once it passes, the real number is measured on the next scan.
P12 · CI test-gate honesty· Changed-file filter skips the test gate for code the tests depend on · ×1
Changed-file filter skips the test gate for code the tests depend on .github/workflows/opencode-plugin.yml:11— `paths` runs `npm test` (the tests of `plugins/opencode`) only when a change touches `plugins/opencode/**`, `headroom/providers/opencode/_dist/**`, `headroom/providers/opencode/hook-shim/**`, `.github/workflows/opencode-plugin.yml`, but those tests also depend on `sdk/typescript` (e.g. `sdk/typescript/tsup.config.ts`, `sdk/typescript/vitest.config.ts`) — a change there merges with them not run, and no unfiltered gate runs them. List the package's tests and its workspace dependencies in the filter, or drop it.
Sync-over-async blocking REDACTED:275— `run_demo` is async and calls urllib.request.urlopen — a blocking call inside async code stalls the event loop — every other task on it waits for as long as it runs.
R10 · Code Duplication· Duplicated block with local edits (489 matched lines × 2 locations) · ×1
Duplicated block with local edits (489 matched lines × 2 locations) headroom/providers/opencode/hook-shim/handler.js:44— headroom/providers/opencode/hook-shim/handler.js:44 · plugins/opencode/src/transport.ts:114 — the two spans are one implementation copied and then locally edited — 3326 tokens are still identical, in the same order in both files, with only local edits between them. The copies have already begun to drift, which is this row's finding: an edit made to one and not the other changes behaviour silently. Diff the two spans first to learn what genuinely differs, then extract the shared core into one module both sites use, passing the differences in as parameters — or, if one copy exists only because the other could not be imported from its context, make one of them the single source the other is generated or re-exported from. If one copy is no longer reachable, delete it rather than letting it shadow the live one.
Duplicated block (28 lines × 2 locations) scripts/build_npm_release_assets.mjs:86— scripts/build_npm_release_assets.mjs:86 · scripts/verify_npm_release_assets.mjs:65 — the 2 copies are spread across 2 files, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
R10 · Code Duplication· Duplicated block with local edits (24 matched lines × 2 locations) · ×1
Duplicated block with local edits (24 matched lines × 2 locations) sdk/typescript/src/adapters/anthropic.ts:42— sdk/typescript/src/adapters/anthropic.ts:42 · sdk/typescript/src/adapters/openai.ts:42 — the two spans are one implementation copied and then locally edited — 135 tokens are still identical, in the same order in both files, with only local edits between them. The copies have already begun to drift, which is this row's finding: an edit made to one and not the other changes behaviour silently. Diff the two spans first to learn what genuinely differs, then extract the shared core into one module both sites use, passing the differences in as parameters — or, if one copy exists only because the other could not be imported from its context, make one of them the single source the other is generated or re-exported from. If one copy is no longer reachable, delete it rather than letting it shadow the live one.
Duplicated block (17 lines × 2 locations) plugins/openclaw/src/convert.ts:207— plugins/openclaw/src/convert.ts:207 · plugins/openclaw/src/convert.ts:434 — all 2 copies are in the same file, and the CITED SPAN is a run of DECLARATIONS inside a construct — the members of a type, or the entries of an object or array literal — with no statement anywhere in it. Do not read this as an extract-a-helper row: nothing here executes, so there is no call site, and a call expression cannot stand where a member declaration or a literal's entry was. What repeats is a SHAPE, and which shape decides the move. Where the copies declare the same members, the repetition is a missing common ancestor: give it a base type, an interface both extend, a generic instantiated twice, or — where the copies are a literal's entries rather than a type's members — one shared constant each site spreads or refers to, so the set is written once. Where they declare DIFFERENT members and only the form is shared — a decorator and its options, an annotation, a registration table's keys — the form is prescribed by a framework or a schema rather than copied, and the only collapse available is to generate the declarations from that schema; where you do not own the generator, this is the cost of the framework and there is nothing to extract. Check which of the two it is before acting: these copies still drift apart the first time only one of them is edited, which is why the repetition is reported, but the sentence to act on is not the same in both cases.
R10 · Code Duplication· Duplicated block with local edits (17 matched lines × 2 locations) · ×1
Duplicated block with local edits (17 matched lines × 2 locations) plugins/opencode/src/plugin.ts:244— plugins/opencode/src/plugin.ts:244 · plugins/opencode/src/plugin.ts:292 — the two spans are one implementation copied and then locally edited — 79 tokens are still identical, in the same order in both spans, with only local edits between them. The copies have already begun to drift, which is this row's finding: an edit made to one and not the other changes behaviour silently. Diff the two spans first to learn what genuinely differs, then extract the shared core into one module both sites use, passing the differences in as parameters — or, if one copy exists only because the other could not be imported from its context, make one of them the single source the other is generated or re-exported from. If one copy is no longer reachable, delete it rather than letting it shadow the live one.
Duplicated block (12 lines × 4 locations) sdk/typescript/src/errors.ts:11— sdk/typescript/src/errors.ts:11 · sdk/typescript/src/errors.ts:37 · sdk/typescript/src/errors.ts:51 · sdk/typescript/src/errors.ts:65 — all 4 copies are in the same file, and each CITED SPAN is a SPECIALISATION DECLARATION — a type whose `extends` clause names a base and whose body hands that base its own values through `super(…)`. The shared module this dimension usually asks you to extract already exists: it is that base, every one of these sites already reaches it, and the `super(…)` call this row matched on is where each site passes its differences in. So do not read this as an extract-a-helper row — there is no missing helper, and what is left at each site is the declaration of one distinct specialisation, which cannot be deleted without deleting the thing it declares. Read what actually differs between the spans, because two different answers follow. Where the sites differ only in the values they hand the base — a type argument, a service, an alias, a cache — the repetition is a TEMPLATE, and the only moves that collapse it are to generate these declarations from the set they enumerate or to replace the repeated construction with one factory each site calls with its own values; where that set is the point, each site pinning one distinct thing, the repetition IS the enumeration and there is nothing to remove. Where instead a span carries logic OUTSIDE the delegation that is the same at every site, that logic is the part to move, and its home is the base type rather than a new module. Reported because the copies still drift apart the first time only one of them is edited.
Duplicated block (11 lines × 2 locations) sdk/typescript/src/client.ts:145— sdk/typescript/src/client.ts:145 · sdk/typescript/src/client.ts:206 — all 2 copies are in the same file, and the SHAPE of this repetition could not be determined. It is not a run of declarations, a listing, a declaration header, a type body or a slice through a construct — and it was not measured as a run of executable statements either, so this row cannot tell you whether a function can stand where these lines are. Read the two spans before acting, because the move is opposite in the two cases. Where they are statements, the ordinary answer holds: give the shared part one home and call it from each site. Where they turn out to be declarations, a literal's entries, or the cases of an enumeration, there is no call site to call anything from, and collapsing them would delete what each copy pins — a shared base type, a generated set, or one exported constant each site refers to is the move instead, and sometimes the honest answer is that there is nothing to extract at all. Reported because the copies drift apart the first time only one of them is edited, which is true whichever of those they are.
Duplicated block (9 lines × 2 locations) sdk/typescript/src/client.ts:373— sdk/typescript/src/client.ts:373 · sdk/typescript/src/client.ts:389 — all 2 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
Duplicated block (9 lines × 4 locations) sdk/typescript/src/paths.ts:174— sdk/typescript/src/paths.ts:174 · sdk/typescript/src/paths.ts:189 · sdk/typescript/src/paths.ts:204 · sdk/typescript/src/paths.ts:219 — all 4 copies are in the same file, and the CITED SPAN is not a self-contained block — it runs from inside one construct into the next (the tail of a branch plus the head of the following one, a run of switch arms, the end of a declaration plus the list that follows it) rather than covering a whole unit. So do not lift these lines literally: no call can be substituted for a half-open construct. Extract the enclosing repeated UNIT instead — the whole function, component or branch these lines sit in — and where the repetition IS the construct (a run of switch arms, a stack of near-identical declarations) replace it with one table or registry looked up by key rather than a helper each arm calls. The copies still drift apart the first time only one of them is edited, which is why this is reported.
R10 · Code Duplication· Duplicated block with local edits (7 matched lines × 2 locations) · ×1
Duplicated block with local edits (7 matched lines × 2 locations) scripts/verify_sdk_provider_peers.mjs:42— scripts/verify_sdk_provider_peers.mjs:42 · scripts/verify_sdk_provider_peers.mjs:68 — the two spans are one implementation copied and then locally edited — 58 tokens are still identical, in the same order in both spans, with only local edits between them. The copies have already begun to drift, which is this row's finding: an edit made to one and not the other changes behaviour silently. Diff the two spans first to learn what genuinely differs, then extract the shared core into one module both sites use, passing the differences in as parameters — or, if one copy exists only because the other could not be imported from its context, make one of them the single source the other is generated or re-exported from. If one copy is no longer reachable, delete it rather than letting it shadow the live one.
R10 · Code Duplication· Duplicated block with local edits (6 matched lines × 2 locations) · ×1
Duplicated block with local edits (6 matched lines × 2 locations) sdk/typescript/src/utils/case.ts:14— sdk/typescript/src/utils/case.ts:14 · sdk/typescript/src/utils/case.ts:25 — the two spans are one implementation copied and then locally edited — 67 tokens are still identical, in the same order in both spans, with only local edits between them. The copies have already begun to drift, which is this row's finding: an edit made to one and not the other changes behaviour silently. Diff the two spans first to learn what genuinely differs, then extract the shared core into one module both sites use, passing the differences in as parameters — or, if one copy exists only because the other could not be imported from its context, make one of them the single source the other is generated or re-exported from. If one copy is no longer reachable, delete it rather than letting it shadow the live one.
Complex function vercelToOpenAI (cyclomatic 48, cognitive 136) sdk/typescript/src/utils/format.ts:534— vercelToOpenAI has cyclomatic complexity 48 and cognitive complexity 136; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function detectFormat (cyclomatic 44, cognitive 81) sdk/typescript/src/utils/format.ts:39— detectFormat has cyclomatic complexity 44 and cognitive complexity 81; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function openAIToVercel (cyclomatic 40, cognitive 123) sdk/typescript/src/utils/format.ts:672— openAIToVercel has cyclomatic complexity 40 and cognitive complexity 123; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function vercelMediaImageUrl (cyclomatic 32, cognitive 36) sdk/typescript/src/utils/format.ts:419— vercelMediaImageUrl has cyclomatic complexity 32 and cognitive complexity 36; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function clean (cyclomatic 30, cognitive 46) deploy/beacon/worker.js:207— clean has cyclomatic complexity 30 and cognitive complexity 46; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function openAIToGemini (cyclomatic 29, cognitive 80) sdk/typescript/src/utils/format.ts:1005— openAIToGemini has cyclomatic complexity 29 and cognitive complexity 80; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function agentToOpenAI (cyclomatic 27, cognitive 64) plugins/openclaw/src/convert.ts:29— agentToOpenAI has cyclomatic complexity 27 and cognitive complexity 64; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function openAIToAgent (cyclomatic 27, cognitive 64) plugins/openclaw/src/convert.ts:155— openAIToAgent has cyclomatic complexity 27 and cognitive complexity 64; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function start (cyclomatic 26, cognitive 30) plugins/openclaw/src/proxy-manager.ts:73— start has cyclomatic complexity 26 and cognitive complexity 30; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function describe (cyclomatic 24, cognitive 21) plugins/headroom-snip/hooks/snip.ts:103— describe has cyclomatic complexity 24 and cognitive complexity 21; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function vercelMediaPart (cyclomatic 20, cognitive 26) sdk/typescript/src/utils/format.ts:476— vercelMediaPart has cyclomatic complexity 20 and cognitive complexity 26; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function geminiToOpenAI (cyclomatic 19, cognitive 51) sdk/typescript/src/utils/format.ts:880— geminiToOpenAI has cyclomatic complexity 19 and cognitive complexity 51; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function buildLaunchSpecs (cyclomatic 19, cognitive 25) plugins/openclaw/src/proxy-manager.ts:214— buildLaunchSpecs has cyclomatic complexity 19 and cognitive complexity 25; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function openAIToAnthropic (cyclomatic 18, cognitive 48) sdk/typescript/src/utils/format.ts:286— openAIToAnthropic has cyclomatic complexity 18 and cognitive complexity 48; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function rollupHour (cyclomatic 18, cognitive 38) deploy/beacon/worker.js:388— rollupHour has cyclomatic complexity 18 and cognitive complexity 38; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function anthropicToOpenAI (cyclomatic 17, cognitive 60) sdk/typescript/src/utils/format.ts:190— anthropicToOpenAI has cyclomatic complexity 17 and cognitive complexity 60; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function anthropicMediaImageUrl (cyclomatic 17, cognitive 17) sdk/typescript/src/utils/format.ts:139— anthropicMediaImageUrl has cyclomatic complexity 17 and cognitive complexity 17; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function assemble (cyclomatic 17, cognitive 16) plugins/openclaw/src/engine.ts:122— assemble has cyclomatic complexity 17 and cognitive complexity 16; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function (anonymous) (cyclomatic 15, cognitive 18) plugins/openclaw/src/convert.ts:480— (anonymous) has cyclomatic complexity 15 and cognitive complexity 18; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function applyGatewayProviderBaseUrlsInPlace (cyclomatic 15, cognitive 18) plugins/openclaw/src/gateway-config.ts:67— applyGatewayProviderBaseUrlsInPlace has cyclomatic complexity 15 and cognitive complexity 18; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function fetch (cyclomatic 15, cognitive 16) deploy/beacon/worker.js:528— fetch has cyclomatic complexity 15 and cognitive complexity 16; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function migrateLegacyLog (cyclomatic 14, cognitive 16) plugins/openclaw/src/advancement-key-store.ts:195— migrateLegacyLog has cyclomatic complexity 14 and cognitive complexity 16; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function anthropicMediaBlock (cyclomatic 14, cognitive 14) sdk/typescript/src/utils/format.ts:168— anthropicMediaBlock has cyclomatic complexity 14 and cognitive complexity 14; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function rawFetch (cyclomatic 13, cognitive 14) sdk/typescript/src/client.ts:527— rawFetch has cyclomatic complexity 13 and cognitive complexity 14; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function (anonymous) (cyclomatic 13, cognitive 13) sdk/typescript/test/client-expanded.test.ts:36— (anonymous) has cyclomatic complexity 13 and cognitive complexity 13; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function probeHeadroomProxy (cyclomatic 13, cognitive 10) plugins/openclaw/src/proxy-manager.ts:448— probeHeadroomProxy has cyclomatic complexity 13 and cognitive complexity 10; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function extractToolCalls (cyclomatic 12, cognitive 22) sdk/typescript/src/hooks.ts:97— extractToolCalls has cyclomatic complexity 12 and cognitive complexity 22; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function replaceTextBlocks (cyclomatic 12, cognitive 18) plugins/openclaw/src/convert.ts:361— replaceTextBlocks has cyclomatic complexity 12 and cognitive complexity 18; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function scheduled (cyclomatic 12, cognitive 17) deploy/beacon/worker.js:474— scheduled has cyclomatic complexity 12 and cognitive complexity 17; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
R2 · Cyclomatic Complexity· Complex function bar (cyclomatic 12, cognitive 15) · ×1
Complex function bar (cyclomatic 12, cognitive 15) plugins/headroom-snip/hooks/snip.ts:220— bar has cyclomatic complexity 12 and cognitive complexity 15; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function (anonymous) (cyclomatic 12, cognitive 11) plugins/headroom-snip/hooks/snip.ts:75— (anonymous) has cyclomatic complexity 12 and cognitive complexity 11; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function extract (cyclomatic 11, cognitive 17) deploy/beacon/worker.js:323— extract has cyclomatic complexity 11 and cognitive complexity 17; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function unwrap (cyclomatic 11, cognitive 11) deploy/beacon/worker.js:296— unwrap has cyclomatic complexity 11 and cognitive complexity 11; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function withCompressedArguments (cyclomatic 11, cognitive 11) plugins/openclaw/src/convert.ts:380— withCompressedArguments has cyclomatic complexity 11 and cognitive complexity 11; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive is at or above cyclomatic here, so the branching is nested or entangled rather than laid out side by side — extracting each decision into its own named function is the change that pays. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
Complex function (anonymous) (cyclomatic 11, cognitive 10) plugins/openclaw/src/convert.ts:523— (anonymous) has cyclomatic complexity 11 and cognitive complexity 10; this row is raised above a cyclomatic bar of 10. The two numbers answer different questions and the gap between them is what decides whether to act: cyclomatic counts the independent arms through the body, cognitive counts what it costs to hold them in your head, so nesting and mixed boolean chains raise it while a flat run of independent arms does not. Cognitive sits below cyclomatic here, so much of the count is breadth — arms side by side rather than stacked — and splitting per arm would leave a function per arm; group the work between the checks into named steps instead. Measured by this repository's own parse of the file, so a body assembled at runtime, or generated, is counted as written rather than as it executes.
R3 · Large Files· sdk/typescript/src/utils/format.ts · ×1
sdk/typescript/src/utils/format.ts: 1020 lines of code sdk/typescript/src/utils/format.ts:1— sdk/typescript/src/utils/format.ts has 1020 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module.
R3 · Large Files· plugins/opencode/src/transport.ts · ×1
plugins/opencode/src/transport.ts: 810 lines of code plugins/opencode/src/transport.ts:1— plugins/opencode/src/transport.ts has 810 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module.
deploy/beacon/worker.js: 600 lines of code deploy/beacon/worker.js:1— deploy/beacon/worker.js has 600 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module.
R3 · Large Files· headroom/providers/opencode/hook-shim/handler.js · ×1
headroom/providers/opencode/hook-shim/handler.js: 585 lines of code headroom/providers/opencode/hook-shim/handler.js:1— headroom/providers/opencode/hook-shim/handler.js has 585 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module.
R3 · Large Files· sdk/typescript/src/client.ts · ×1
sdk/typescript/src/client.ts: 550 lines of code sdk/typescript/src/client.ts:1— sdk/typescript/src/client.ts has 550 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module.
R3 · Large Files· plugins/openclaw/src/convert.ts · ×1
plugins/openclaw/src/convert.ts: 500 lines of code plugins/openclaw/src/convert.ts:1— plugins/openclaw/src/convert.ts has 500 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module.
R3 · Large Files· plugins/openclaw/src/proxy-manager.ts · ×1
plugins/openclaw/src/proxy-manager.ts: 469 lines of code plugins/openclaw/src/proxy-manager.ts:1— plugins/openclaw/src/proxy-manager.ts has 469 significant lines (blank lines excluded), over the 400-line bar, and contains logic — a file this long is usually several responsibilities in one module.
Dead file (~336 LoC) plugins/headroom-snip/hooks/register.tsx— no import path from any entry point (21 application, 12 tooling, 42 test roots considered), and no other file in the scanned tree imports it — nothing in-repo names this module at all, which is the strongest form of this claim the import graph can make
Dead file (~96 LoC) scripts/verify_sdk_provider_peers.mjs— no import path from any entry point (21 application, 12 tooling, 42 test roots considered), and no other file in the scanned tree imports it — nothing in-repo names this module at all, which is the strongest form of this claim the import graph can make
Dead file (~62 LoC) scripts/verify_anthropic_peer.mjs— no import path from any entry point (21 application, 12 tooling, 42 test roots considered), and no other file in the scanned tree imports it — nothing in-repo names this module at all, which is the strongest form of this claim the import graph can make
Dead file (~26 LoC) scripts/verify_opencode_bundle.mjs— no import path from any entry point (21 application, 12 tooling, 42 test roots considered), and no other file in the scanned tree imports it — nothing in-repo names this module at all, which is the strongest form of this claim the import graph can make
Dead file (~15 LoC) scripts/verify_sdk_dist_compat.mjs— no import path from any entry point (21 application, 12 tooling, 42 test roots considered), and no other file in the scanned tree imports it — nothing in-repo names this module at all, which is the strongest form of this claim the import graph can make
Unused dependency '@openai/codex' — Declared in e2e/wrap/tools/package.json but never imported anywhere in that package or its workspace members — no static import reaches it. Usually that is dead weight and attack surface, but two shapes are indistinguishable from source and are NOT dead: an optional or native peer that another dependency loads dynamically at runtime, and a package a build, docs or test step installs and invokes separately. Confirm which of the three this is before removing it.
X1 · Async correctness· Task from `loop.create_task` is not kept · ×1
Task from `loop.create_task` is not kept headroom/subscription/codex_rate_limits.py:512— The task this creates is not kept anywhere. The event loop holds only a weak reference to its tasks, so a task nobody references can be garbage-collected before it finishes (Python's documentation for `asyncio.create_task`: save a reference to the result); and nothing ever awaits it, so an exception it raises is never handled — it surfaces, if at all, as "Task exception was never retrieved" in a log. Keep the task: `await` it, gather it, start it in an `asyncio.TaskGroup` (`async with asyncio.TaskGroup() as tg: tg.create_task(…)`), or, for genuine fire-and-forget, add it to a set and `task.add_done_callback(tasks.discard)` with a callback that also reads its exception.
X19 · Unrestored process-global state· Process-global state is restored only on the happy path · ×1
Process-global state is restored only on the happy path headroom/transforms/cold_prefix.py:239— `_demo` changes state that belongs to the whole PROCESS and changes it back at the end of the same body — the `DISABLE_PROMPT_CACHING` environment variable (set at line 285, cleared at line 289) and the `DISABLE_PROMPT_CACHING_OPUS` environment variable (set at line 290, cleared at line 293) and the `ENABLE_PROMPT_CACHING_1H` environment variable (set at line 294, cleared at line 298) — which says the change was meant to last no longer than this call. But the restore is an ordinary statement on the straight-line path, not a `finally`, so it is skipped by any exception raised in between: the process then keeps the overwritten value for the rest of its life, and every later relative path, `subprocess` launch, `os.environ` read or `print` in ANY module sees it. That failure is silent and remote from its cause — the function that breaks is not the function that moved the value. The window is not private while it is open either: the working directory, the environment, the umask and `sys.stdout` are per-process, not per-thread, so a concurrent thread sees the moved value too. The durable fix is not to widen the restore but to stop mutating the global: pass the value to the operation that needs it — the `cwd=` and `env=` arguments of `subprocess.run`/`Popen` scope both to the CHILD, absolute paths built with `os.path.join` or `pathlib` need no working directory, and a stream handed to the code that writes needs no `sys.stdout`. Where the global genuinely must move, `contextlib.chdir` (3.11+), `contextlib.redirect_stdout` or a `try`/`finally` makes the restore run on every path.
Duplicated predicate headroom/providers/opencode/hook-shim/handler.js:280— `!isLlmMethod(method) || !isRoutableUpstream(url, proxy, excludeHosts)` appears character-identically in 2 files — headroom/providers/opencode/hook-shim/handler.js, plugins/opencode/src/transport.ts. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/providers/opencode/hook-shim/handler.js:85— `Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof URL)` appears character-identically in 2 files — headroom/providers/opencode/hook-shim/handler.js, plugins/opencode/src/transport.ts. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate scripts/build_npm_release_assets.mjs:112— `dir && existsSync(path.join(dir, "npm.cmd"))` appears character-identically in 2 files — scripts/build_npm_release_assets.mjs, scripts/verify_npm_release_assets.mjs. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate plugins/opencode/src/retrieve.ts:24— `end > 0 && value.charCodeAt(end - 1) === 47` appears character-identically in 2 files — plugins/opencode/src/retrieve.ts, sdk/typescript/src/client.ts. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/providers/opencode/hook-shim/handler.js:175— `normalized === "localhost" || normalized === "::1" || normalized === "0.0.0.0"` appears character-identically in 2 files — headroom/providers/opencode/hook-shim/handler.js, plugins/opencode/src/transport.ts. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/providers/opencode/hook-shim/handler.js:247— `pathname.endsWith(":generateContent") || pathname.endsWith(":streamGenerateContent")` appears character-identically in 2 files — headroom/providers/opencode/hook-shim/handler.js, plugins/opencode/src/transport.ts. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/providers/opencode/hook-shim/handler.js:378— `protocol !== "http:" && protocol !== "https:"` appears character-identically in 2 files — headroom/providers/opencode/hook-shim/handler.js, plugins/opencode/src/transport.ts. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/providers/opencode/hook-shim/handler.js:160— `proxy.protocol !== "http:" && proxy.protocol !== "https:"` appears character-identically in 2 files — headroom/providers/opencode/hook-shim/handler.js, plugins/opencode/src/transport.ts. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/providers/opencode/hook-shim/handler.js:370— `typeof first === "object" && first !== null` appears character-identically in 2 files — headroom/providers/opencode/hook-shim/handler.js, plugins/opencode/src/transport.ts. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/providers/opencode/hook-shim/handler.js:277— `typeof method === "string" && method.toUpperCase() === "POST"` appears character-identically in 2 files — headroom/providers/opencode/hook-shim/handler.js, plugins/opencode/src/transport.ts. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/providers/opencode/hook-shim/handler.js:359— `typeof second === "object" && second !== null` appears character-identically in 2 files — headroom/providers/opencode/hook-shim/handler.js, plugins/opencode/src/transport.ts. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/providers/opencode/hook-shim/handler.js:221— `url.protocol !== "http:" && url.protocol !== "https:"` appears character-identically in 2 files — headroom/providers/opencode/hook-shim/handler.js, plugins/opencode/src/transport.ts. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/integrations/agno/providers.py:97— `"google" in module_path.lower() or "gemini" in module_path.lower()` appears character-identically in 2 files — headroom/integrations/agno/providers.py, headroom/integrations/strands/providers.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/integrations/agno/providers.py:117— `"gpt" in model_id_lower or "o1" in model_id_lower or "o3" in model_id_lower` appears character-identically in 2 files — headroom/integrations/agno/providers.py, headroom/integrations/strands/providers.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/integrations/agno/providers.py:103— `"openai" in module_path.lower() or "litellm" in module_path.lower()` appears character-identically in 2 files — headroom/integrations/agno/providers.py, headroom/integrations/strands/providers.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/backends/anyllm.py:580— `"rate" in error_str or "limit" in error_str` appears character-identically in 2 files — headroom/backends/anyllm.py, headroom/backends/litellm.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/cli/update.py:74— `Path("/.dockerenv").exists() or bool( os.environ.get("HEADROOM_IN_DOCKER", "").strip() )` appears character-identically in 2 files — headroom/cli/update.py, REDACTED. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/cli/wrap.py:9245— `_PROVIDER_MARKER_START in content or _MCP_MARKER_START in content` appears character-identically in 2 files — headroom/cli/wrap.py, headroom/providers/opencode/config.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate REDACTED:6873— `batch_context is None or not self.config.ccr_inject_tool` appears character-identically in 2 files — REDACTED, headroom/proxy/handlers/batch.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/proxy/conversation_savings.py:105— `body.get("previous_response_id") or body.get("conversation")` appears character-identically in 2 files — headroom/proxy/conversation_savings.py, REDACTED. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate REDACTED:1738— `body.get("stream", False) or force_stream` appears character-identically in 2 files — REDACTED, REDACTED. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate REDACTED:5870— `buffered_stream_ccr and response.status_code == 200 and not resp_json` appears character-identically in 2 files — REDACTED, REDACTED. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate REDACTED:5077— `buffered_stream_ccr and response.status_code == 200 and resp_json` appears character-identically in 2 files — REDACTED, REDACTED. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate headroom/cache/backends/redis.py:44— `client is not None and hasattr(client, "close")` appears character-identically in 2 files — headroom/cache/backends/redis.py, REDACTED. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate REDACTED:2346— `compressor and compressor.has_images(messages)` appears character-identically in 2 files — REDACTED, REDACTED. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Interpolated log message defeats structured logging REDACTED:582— `debug` at line 582 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.debug("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.debug("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/transforms/content_router.py:3131— `info` at line 3131 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/tokenizers/huggingface.py:219— `warning` at line 219 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/tokenizers/huggingface.py:252— `warning` at line 252 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/tokenizers/huggingface.py:260— `warning` at line 260 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/tokenizers/huggingface.py:292— `warning` at line 292 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/tokenizers/huggingface.py:298— `warning` at line 298 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/tokenizers/mistral.py:213— `debug` at line 213 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.debug("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.debug("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/tokenizers/registry.py:225— `warning` at line 225 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/tokenizers/registry.py:396— `warning` at line 396 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/telemetry/toin.py:629— `debug` at line 629 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.debug("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.debug("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/buffered_ccr_response.py:212— `warning` at line 212 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/buffered_ccr_response.py:257— `error` at line 257 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/buffered_ccr_response.py:298— `debug` at line 298 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.debug("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.debug("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/helpers.py:1848— `warning` at line 1848 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/memory_handler.py:255— `info` at line 255 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/memory_handler.py:308— `error` at line 308 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/memory_handler.py:327— `info` at line 327 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/memory_handler.py:408— `info` at line 408 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/memory_handler.py:455— `info` at line 455 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/memory_handler.py:457— `error` at line 457 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.error("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.error("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/memory_handler.py:489— `info` at line 489 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/memory_handler.py:494— `warning` at line 494 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/memory_handler.py:875— `debug` at line 875 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.debug("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.debug("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging headroom/proxy/memory_handler.py:897— `warning` at line 897 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.warning("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.warning("order moved", order_id=order_id, status=status)` with structlog.
Silent fallback default on parse failure benchmarks/ccr_regression_benchmark.py:86— `_ccr_retrieve_items` returns `[]` when `(json.JSONDecodeError, TypeError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/cache/anthropic.py:326— `_estimate_tools_tokens` returns `0` when `(TypeError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/cache/semantic.py:584— `_compute_messages_hash` returns `''` when `(TypeError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure REDACTED:257— `_held` returns `{}` when `(TypeError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/cli/doctor.py:461— `settings_env` (in `check_claude_auth_conflict`) returns `{}` when `(OSError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/cli/main.py:44— `get_version` returns `'unknown'` when `ImportError` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/cli/port_discovery.py:98— `_wrap_marker_ports` returns `[]` when `(OSError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/cli/port_discovery.py:144— `_marker_started_at` returns `0.0` when `(OSError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/cli/wrap.py:1644— `_read_wrap_owners` returns `{}` when `(OSError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/cli/wrap.py:4677— `_stop_local_proxy_for_unwrap` returns `'no_pid'` when `(TypeError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/compression/handlers/json_handler.py:437— `extract_json_schema` returns `{}` when `(json.JSONDecodeError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure REDACTED:198— `_enterprise_hostname` returns `''` when `ValueError` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure REDACTED:213— `_configured_url_hostname` returns `''` when `ValueError` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/learn/analyzer.py:1214— `_safe_int` returns `0` when `(ValueError, TypeError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/pricing/counterfactual.py:142— `_coerce_int` returns `0` when `(TypeError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/providers/claude/runtime.py:208— `_gate_view_host` returns `''` when `ValueError` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/providers/copilot/vscode.py:218— `unrouted_vscode_profiles` returns `[]` when `(OSError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/proxy/forwarded_headers.py:168— `_read_header` returns `''` when `UnicodeDecodeError` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure REDACTED:1882— `_openai_response_create_frame_input_tokens` returns `0` when `json.JSONDecodeError` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/proxy/interceptors/astgrep.py:45— `_min_chars_to_rewrite` returns `500` when `(TypeError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/proxy/interceptors/astgrep.py:165— `_max_disk_verify_bytes` returns `5000000` when `(TypeError, ValueError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/proxy/output_shaper.py:134— `output_holdout_fraction` returns `0.0` when `ValueError` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/proxy/persistent_metrics.py:61— `_coerce_int` returns `0` when `(TypeError, ValueError, OverflowError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure headroom/proxy/persistent_metrics.py:68— `_coerce_float` returns `0.0` when `(TypeError, ValueError, OverflowError)` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/capture/network_diff.py:113— `_body_bytes` swallows every exception into `return b''` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/ccr/tool_injection.py:407— `_safe_exists` (in `verify_ownership`) swallows every exception into `return False` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/image/compressor.py:351— `_estimate_tokens` swallows every exception into `return 765` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/memory/backends/mem0.py:548— `get_all_memories` swallows every exception into `return []` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/memory/backends/mem0.py:637— `query` swallows every exception into `return []` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/memory/backends/mem0.py:691— `get_related_memories` swallows every exception into `return []` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/perf/analyzer.py:129— `_decode_perf_savings` swallows every exception into `return []` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/perf/analyzer.py:1467— `_format_toin_highlights` swallows every exception into `return []` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/pricing/counterfactual.py:411— `_canonical_cache_rate` swallows every exception into `return 0.0` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/pricing/counterfactual.py:611— `long_context_premium_avoided_usd` swallows every exception into `return 0.0` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/proxy/compress_turn.py:153— `_registry` swallows every exception into `return []` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/proxy/context_guard.py:147— `credential_scope_from_headers` swallows every exception into `return ''` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/proxy/context_guard.py:275— `_sse_event_type` swallows every exception into `return b''` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/proxy/cost.py:150— `_long_context_threshold` swallows every exception into `return 200000` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch REDACTED:1970— `_extract_codex_handshake_headers` swallows every exception into `return []` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default in catch headroom/proxy/model_router.py:255— `estimate_input_tokens` swallows every exception into `return 0` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Orphaned file benchmarks/i18n_compression_eval.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file benchmarks/text_crusher_quality_eval.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file headroom/cli/agent_savings.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file scripts/build_python_release_smoke.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file headroom/proxy/background_compression.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file headroom/providers/grok_build/config.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file headroom/memory/qdrant_env.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file headroom/proxy/probe_recorder.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file scripts/release_smoke_all.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file sdk/typescript/src/hooks.ts:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file scripts/record_code_compressor_fixtures.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file headroom/transforms/text_crusher.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
X23 · Unguarded diagnostic materialisation· Diagnostic log message is built whether or not it is wanted · ×7
Diagnostic log message is built whether or not it is wanted headroom/transforms/content_router.py:4258— `debug` at line 4258 is called with an argument built by `"…".join(map(str, out.warnings))` (line 4259), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on.
Diagnostic log message is built whether or not it is wanted headroom/subscription/copilot_quota.py:363— `debug` at line 363 is called with an argument built by `list(snapshot.categories.keys())` (line 366), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on.
Diagnostic log message is built whether or not it is wanted headroom/proxy/interceptors/astgrep.py:378— `debug` at line 378 is called with an argument built by `sorted(tool_input.keys())` (line 380), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on.
Diagnostic log message is built whether or not it is wanted REDACTED:8091— `debug` at line 8091 is called with an argument built by `[k for k in upstream_headers if k.lower() != "…"]` (line 8093), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on.
Diagnostic log message is built whether or not it is wanted REDACTED:213— `debug` at line 213 is called with an argument built by `sorted(payload.keys())` (line 213), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on.
Diagnostic log message is built whether or not it is wanted REDACTED:778— `debug` at line 778 is called with an argument built by `sorted(values.keys())` (line 778), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on.
Diagnostic log message is built whether or not it is wanted REDACTED:943— `debug` at line 943 is called with an argument built by `sorted(allowed)` (line 946), whose cost grows with the collection it walks. Python evaluates a call's arguments BEFORE entering the method, so that join/projection runs in full every time this line is reached — and then the level check inside the logger discards the string it produced, because debug is a level a shipped configuration normally leaves off. Nothing here decides beforehand whether the message is wanted: no `isEnabledFor(logging.DEBUG)` test, no debug flag, no `lambda` the logger calls only when the level is on.
Off-boarding risk: anonymized user #1 — If anonymized user #1 becomes unavailable, 75 significant file(s) lose their only recent owner: crates/headroom-proxy/src/compression/live_zone_anthropic.rs, crates/headroom-core/src/transforms/smart_crusher/analyzer.rs, benchmarks/bench_latency.py, crates/headroom-parity/src/lib.rs, headroom/telemetry/collector.py, benchmarks/prefix_cache_benchmark.py, benchmarks/comprehensive_eval.py, crates/headroom-proxy/src/compression/live_zone_responses.rs (+67 more). Pair on, review, or document these before any departure.
Off-boarding risk: anonymized user #2 — If anonymized user #2 becomes unavailable, 16 significant file(s) lose their only recent owner: benchmarks/claude_session_mode_benchmark.py, headroom/testing/harness.py, benchmarks/cache_validation_bundle.py, benchmarks/claude_session_branch_compare.py, benchmarks/synthetic_long_cache_suite_report.py, benchmarks/synthetic_token_cache_bust_report.py, benchmarks/cache_bust_trace_report.py, headroom/proxy/request_log_redaction_policy.py (+8 more). Pair on, review, or document these before any departure.
Off-boarding risk: anonymized user #3 — If anonymized user #3 becomes unavailable, 3 significant file(s) lose their only recent owner: headroom/proxy/context_guard.py, headroom/proxy/tcp_keepalive.py, headroom/proxy/hard_watchdog.py. Pair on, review, or document these before any departure.
Off-boarding risk: anonymized user #4 — If anonymized user #4 becomes unavailable, 3 significant file(s) lose their only recent owner: benchmarks/memory_fts_reindex_benchmark.py, benchmarks/ccr_retrieval_history_benchmark.py, benchmarks/ccr_sqlite_expiry_benchmark.py. Pair on, review, or document these before any departure.
redundant comment plugins/openclaw/src/plugin/index.ts:125— "Register as context engine" repeats the code it sits on: 3 of its 3 words (register, context, engine) are already in `api.registerContextEngine("headroom", () => engine);`. Delete it, or replace it with what the code cannot say (why it is done here, a constraint, or a consequence).
redundant comment sdk/typescript/src/utils/format.ts:73— "Anthropic: image / document with source.type" repeats the code it sits on: 5 of its 5 words (anthropic, image, document, source, type) are already in `if ((part.type === "image" || part.type === "document") && part.source?.type) return "anthropic";`. Delete it, or replace it with what the code cannot say (why it is done here, a constraint, or a consequence).
redundant comment sdk/typescript/test/vercel-ai-e2e.test.ts:94— "Wrap model with Headroom middleware" repeats the code it sits on: 4 of its 4 words (wrap, model, headroom, middleware) are already in `const model = wrapLanguageModel({`. Delete it, or replace it with what the code cannot say (why it is done here, a constraint, or a consequence).
P2 · Observability· Console output used as the logging channel · ×3
Console output used as the logging channel plugins/openclaw/src/proxy-manager.ts:35— `plugins/openclaw/src/proxy-manager.ts` reports through `console.*` at line 35 although other files in its module log through a logger. Console lines carry no level, fields or correlation and never reach the log pipeline.
Console output used as the logging channel plugins/openclaw/src/proxy-manager.ts:36— `plugins/openclaw/src/proxy-manager.ts` reports through `console.*` at line 36 although other files in its module log through a logger. Console lines carry no level, fields or correlation and never reach the log pipeline.
Console output used as the logging channel plugins/openclaw/src/proxy-manager.ts:37— `plugins/openclaw/src/proxy-manager.ts` reports through `console.*` at line 37 although other files in its module log through a logger. Console lines carry no level, fields or correlation and never reach the log pipeline.
Mock-dominated test: falls back when proxy is down sdk/typescript/test/adapters/vercel-ai.test.ts:476— This test sets up 3 test doubles (for example `vi.fn`) against 1 real object(s) of its own, and its only verification is 1 check(s) that the doubles were called. It pins how the code is wired, not what it does: it passes with a wrong result and fails when a call is harmlessly reordered or merged. Assert the outcome instead (the value returned, the state left behind), build collaborators and value objects for real or with a small hand-written fake, and keep doubles for the boundaries the test cannot own — the network, the clock, the file system.
Mock-dominated test: keeps loopback spellings and a trailing-dot excluded host off the proxy for Node http/https.request (#4747) REDACTED:408— This test sets up 5 test doubles (for example `vi.fn`) against 0 real object(s) of its own, and its only verification is 4 check(s) that the doubles were called. It pins how the code is wired, not what it does: it passes with a wrong result and fails when a call is harmlessly reordered or merged. Assert the outcome instead (the value returned, the state left behind), build collaborators and value objects for real or with a small hand-written fake, and keep doubles for the boundaries the test cannot own — the network, the clock, the file system.
Hand-rolled JSON/XML parsing via regex headroom/log_safety.py:51— A regex whose pattern encodes JSON/XML syntax is parsing a structured format by hand — malformed or differently-typed content (e.g. `"amount": "5"` as a string) silently mis-parses instead of failing validation. This Python code already uses a real parser in the same package; use it here too.
Hand-rolled JSON/XML parsing via regex headroom/transforms/content_router.py:1351— A regex whose pattern encodes JSON/XML syntax is parsing a structured format by hand — malformed or differently-typed content (e.g. `"amount": "5"` as a string) silently mis-parses instead of failing validation. This Python code already uses a real parser in the same package; use it here too.
D16 · Bus Factor· Further sole-owners (lower concentration) · ×1
Further sole-owners (lower concentration) — 10 other contributor(s) are each the sole owner of a small amount of code below the off-boarding threshold — folded into the bus-factor score and metrics (109 single-owned of 679 analysed files in total, counted over production source files of roughly 2,400 bytes or more, excluding vendored, generated, example/demo and scaffolding-template trees and test files identified by path convention, largest first; 679 of the 842 production source files in this repository met that bar). They are anonymized user #5 (2 file(s)), anonymized user #6 (2 file(s)), anonymized user #7 (1 file(s)), anonymized user #8 (1 file(s)), anonymized user #9 (1 file(s)), anonymized user #10 (1 file(s)) (+4 more) — spread or document their files in the same way, at lower priority than the named off-boarding risks above. The files folded here: headroom/proxy/stage_timer.py, headroom/proxy/debug_introspection.py, headroom/memory/inline_extractor.py, headroom/proxy/malloc_trim.py, crates/headroom-core/src/transforms/text_crusher/crusher.rs, headroom/evals/adversarial_grid.py, headroom/proxy/uds.py, headroom/proxy/orphan_watchdog.py (+4 more).
D21 · Naming Consistency· `baseURL` spells `URL` where 59 names in the project spell it `Url` · ×1
`baseURL` spells `URL` where 59 names in the project spell it `Url` plugins/opencode/src/plugin.ts:179— 59 of 60 names in project repository spell the token `Url` (59 of 60; unit: names in project repository containing `Url`). Peers: source.getPageMarkdownUrl (docs/lib/source.ts:11); snip.proxyUrl (plugins/headroom-snip/hooks/snip.ts:32); snip.proxyUrl(baseUrl) (plugins/headroom-snip/hooks/snip.ts:32); HeadroomContextEngine.proxyUrl (plugins/openclaw/src/engine.ts:56); HeadroomContextEngine.getProxyUrl (plugins/openclaw/src/engine.ts:311). Rename to `baseUrl`. [rule N6]
D21 · Naming Consistency· `normalizedOpenAiProxyPath` spells `Ai` where 15 names in the project spell it `AI` · ×1
`normalizedOpenAiProxyPath` spells `Ai` where 15 names in the project spell it `AI` plugins/opencode/src/transport.ts:516— 15 of 16 names in project repository spell the token `AI` (15 of 16; unit: names in project repository containing `AI`). Peers: plugins.openclaw.src.convert.OpenAIMessage (plugins/openclaw/src/convert.ts:17); convert.agentToOpenAI (plugins/openclaw/src/convert.ts:29); convert.openAIToAgent (plugins/openclaw/src/convert.ts:155); convert.agentToOpenAIIndexed (plugins/openclaw/src/convert.ts:271); sdk.typescript.src.adapters.openai.OpenAILike (sdk/typescript/src/adapters/openai.ts:6). Rename to `normalizedOpenAIProxyPath`. [rule N6]
D26 · Project Cohesion· Projects may be oversized for their cohesion · ×1
Projects may be oversized for their cohesion — 3 of 12 project(s) overshoot their size bounds, lowering Project Cohesion to 5.0/10. The most over is `(repository root)` (267436 LoC, 1439 module-visible types across 88 directories). Review these for cohesion — draw the boundary inside the module first (group each responsibility into its own package or directory and keep the cross-boundary members non-public), since splitting a published package moves types between packages and breaks consumers.
Scattered collaborators — 99 % of calls cross a namespace and only 58 % of collaborators are co-located — group each feature's code into a vertical slice so a call's collaborators sit together.
D30 · Dependency Vulnerabilities· Medium advisory (unmaintained) · ×1
REDACTED
D34 · Knowledge Freshness· Further orphaned files (smaller) · ×1
Further orphaned files (smaller) — 12 smaller file(s) also have no living knowledge — folded into the freshness score and metrics rather than raised one row each — most significant first: benchmarks/i18n_compression_eval.py, benchmarks/text_crusher_quality_eval.py, headroom/cli/agent_savings.py, scripts/build_python_release_smoke.py, headroom/proxy/background_compression.py, headroom/memory/qdrant_env.py, headroom/proxy/probe_recorder.py, scripts/release_smoke_all.py (and 4 more) (13 orphaned of 679 analysed files in total, counted over production source files of roughly 2,400 bytes or more, excluding vendored, generated, example/demo and scaffolding-template trees and test files identified by path convention, largest first; 679 of the 842 production source files in this repository met that bar). Attach the read to the next change that touches one of them: have a second person review that change, and leave behind a short comment or test recording what the file is for, so the knowledge comes back at the cost of a change you were making anyway.
Logging is not universal — Only 6/8 runnable modules use logging (modules with no entry point or server are excluded — they are libraries a runnable module hosts). Silent: `crates/headroom-parity`, `docs`.
P3 · Security & performance tooling· Dependabot does not watch bun/uv · ×1
Dependabot does not watch bun/uv REDACTED:2— `REDACTED` schedules updates, but no `package-ecosystem` entry covers `bun`, `uv`, which this tree depends on — so those dependencies get no update pull requests and no advisory pressure, however complete the dep-scan credit looks. Add the missing entries to the `updates:` list.
No security response headers detected docs/vercel.json:1— None of the 11 security response headers the OWASP Secure Headers Project recommends (Content-Security-Policy, Strict-Transport-Security, X-Content-Type-Options, X-Frame-Options, …) is configured — defense in depth, even when a reverse proxy could set them. This is reported because `vercel.json` configures this repository's static hosting, including its response headers, so the configuration that would carry these headers is in this repository and was read in full. (−2.0 on this card.)
Null assertions (`!`) override strict null checking — ~0.3 `!` null assertions per 1k TypeScript source lines — 3 assertion(s) across the 9123 source line(s) of the 58 TypeScript file(s) read, which is the only code the operator asserts anything in (a `!` in a `.js` file is not this operator and was not counted, and one in a file whose null checking is off silences nothing). Densest: sdk/typescript/src/utils/stream.ts (2), plugins/openclaw/src/convert.ts (1). Each one tells the compiler to trust the author about null, suppressing the very diagnostic `strictNullChecks` exists to produce. Many are correct: each is a claim the checker could not verify, and it is wrong only where the value can in fact be missing, so review the densest places first.
Subsumed condition operand crates/headroom-core/src/auth_mode.rs:178— `token.starts_with("sk-ant-api")` can never decide this `||` — every value satisfying `token.starts_with("sk-ant-api")` also satisfies `token.starts_with("sk-")`, so the `||` chain is already decided by the latter. The expression is equivalent to the chain without it, which means it is wider than it reads. Delete the dead operand, or narrow the surviving one if IT is the accident.
Outdated: aws-config — `aws-config` is locked at 1.13.0 but 1.13.2 is the current stable release on crates.io, and it already satisfies the `"1"` requirement declared in crates/headroom-proxy/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p aws-config` and commit the updated REDACTED.
Outdated: aws-sigv4 — `aws-sigv4` is locked at 1.6.4 but 1.6.5 is the current stable release on crates.io, and it already satisfies the `"1"` requirement declared in crates/headroom-proxy/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p aws-sigv4` and commit the updated REDACTED.
Outdated: aws-smithy-runtime-api — `aws-smithy-runtime-api` is locked at 1.19.2 but 1.21.0 is the current stable release on crates.io, and it already satisfies the `"1"` requirement declared in crates/headroom-proxy/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p aws-smithy-runtime-api` and commit the updated REDACTED.
Outdated: cc — `cc` is locked at 1.10.0 but 1.11.2 is the current stable release on crates.io, and it already satisfies the `"1"` requirement declared in crates/headroom-py/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p cc` and commit the updated REDACTED.
Outdated: crc32fast — `crc32fast` is locked at 1.5.4 but 1.5.5 is the current stable release on crates.io, and it already satisfies the `"1"` requirement declared in crates/headroom-proxy/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p crc32fast` and commit the updated REDACTED.
Outdated: flate2 — `flate2` is locked at 1.1.10 but 1.1.11 is the current stable release on crates.io, and it already satisfies the `"1"` requirement declared in crates/headroom-core/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p flate2` and commit the updated REDACTED.
Outdated: icu_segmenter — `icu_segmenter` is locked at 2.2.0 but 2.4.0 is the current stable release on crates.io, and it already satisfies the `"2.2"` requirement declared in crates/headroom-core/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p icu_segmenter` and commit the updated REDACTED.
Outdated: rustls-pki-types — `rustls-pki-types` is locked at 1.15.1 but 1.16.0 is the current stable release on crates.io, and it already satisfies the `"1"` requirement declared in crates/headroom-proxy/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p rustls-pki-types` and commit the updated REDACTED.
Outdated: toml — `toml` is locked at 1.1.8+spec-1.1.0 but 1.2.1+spec-1.1.0 is the current stable release on crates.io, and it already satisfies the `"1.1"` requirement declared in crates/headroom-core/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p toml` and commit the updated REDACTED.
Outdated: uuid — `uuid` is locked at 1.29.0 but 1.29.2 is the current stable release on crates.io, and it already satisfies the `"1"` requirement declared in crates/headroom-proxy/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p uuid` and commit the updated REDACTED.
Outdated: webpki-roots — `webpki-roots` is locked at 1.0.11 but 1.0.12 is the current stable release on crates.io, and it already satisfies the `"1.0"` requirement declared in crates/headroom-proxy/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p webpki-roots` and commit the updated REDACTED.
Skipped (documented): (unnamed test) plugins/openclaw/test/advancement-key-store.test.ts:341— Skipped with a documented reason — a deferral, not lazy debt: switched off by it.skipIf
Skipped (documented): (unnamed test) plugins/openclaw/test/advancement-key-store.test.ts:360— Skipped with a documented reason — a deferral, not lazy debt: switched off by it.skipIf
Skipped (documented): (unnamed test) plugins/openclaw/test/advancement-key-store.test.ts:421— Skipped with a documented reason — a deferral, not lazy debt: switched off by it.skipIf
Skipped (documented): (unnamed test) plugins/openclaw/test/advancement-key-store.test.ts:447— Skipped with a documented reason — a deferral, not lazy debt: switched off by it.skipIf
Appendix B — Reproduction & audit trail
Every external tool invocation behind a deep-scan dimension — the tool, its captured version, the exact command, how many findings it yielded, and a link to the retained raw output. To reproduce any finding: check out the same commit and run the command shown (repo-relative — never an absolute scratch path). The complete raw scanner output is retained verbatim under artifacts/raw/ (indexed in artifacts/raw/index.json); per-invocation exit codes and wall-clock durations are in sidecar.json — kept out of this table so the rendered report stays byte-identical across runs of the same commit.
semgrep: not applicable — No personal data was found crossing a boundary the PII/GDPR ruleset checks — nothing written to a log or console sink, placed in a URL or query string, or persisted to browser storage. That is a clean result for the LEAK surface only: this ruleset detects personal data escaping, it does not inventory the personal data a repository holds, so it is not evidence that this repository has no personal-data surface. The personal-data map (Appendix C) and the C1-C5 compliance cards are what speak to that. semgrep could not parse 2 file(s) — `docs/components/mdx.tsx`, `headroom/providers/opencode/_dist/index.js` — so the PII/GDPR sweep did not cover the unparsed regions of them; rows reported elsewhere in those files are real.
runtime-hardening: not applicable — No Kubernetes/orchestration workloads found in the repository manifests; network egress policy is a cluster-native control that may live at the platform/firewall layer, so there is nothing to assess here.
runtime-hardening: not applicable — No Kubernetes/orchestration workloads found in the repository manifests; seccomp/AppArmor/SELinux confinement is a workload-level control, so there is nothing to assess here.
runtime-hardening: not applicable — No Kubernetes/orchestration workloads found in the repository manifests; runtime threat-detection and admission-control policy are cluster-level controls, so there is nothing to assess here.
Run 01a1d7c4-91e5-78cc-9dbf-8f84ab2ff6d0 · every finding is also locatable in findings.md, and the complete scoring record (with exit codes + durations) in sidecar.json.
Issues: 60 · Warnings: 2050 · Recommendations: 189 · Info: 15 — Appendix A · all findings · full markdown report.
Generated by the Canine Code Analyzer: deterministic code-health analysis. 14-11-2026 @ 01:55 UTC.
Downloadable artifacts
Machine-readable and reproducible from this commit + frozen rubric — drop them straight into a contract appendix, a CRA dossier, or a downstream SCA / VEX tool.