Public report of headroomlabs-ai/headroom, published 25 October 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.10.5). Watchdog 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, 25 October 2026, 06:17 UTC · Survey ID cd_db31edb3696d49f7982734b79a98c6e0
headroomlabs-ai/headroom
Measured 25 October 2026, 06:07 UTC, at code version 3fef15d
A regression is a drop of 0.5 points or more in the score, or of 2.5 or more out of 10 in a dimension, since the last survey.
Code coverage is not measured: JavaScript/TypeScript suite (CouldNotMeasureNoCollector).
CAI scoreAt riskDown 4 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: 310,545 lines of product code in 12 projects, tests not counted · Estimated rebuild effort: about 4.4 person-years · Weakest lens: Domain Modelling, 10
Findings by how serious they are
258 critical1769 serious219 minor
11 dimensions are left out of the score. For each one, Watchdog either couldn't measure it in this code, or found no evidence of the safeguard it looks 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
Watchdog
Producer
Canine Development
Analyzer
Watchdog engine 1.0.0
Measured
25 October 2026, 06:07 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 Watchdog. It is open to any tool that
implements it, and today Watchdog 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. Watchdog works 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 ▸
88of 93 dimensions measured by tools. The other 5 are advisory notes from an AI model, which explain the code but don't count towards the score.
2213of 2246 findings point to an exact file and line, so you can open each one in the code. The other 33 concern the repository as a whole, such as missing documentation.
93dimensions across 8 lenses, read from 310,545 lines of product code in 12 projects.
headroomlabs-ai/headroom scores 36 out of 100, but it is rated At risk while a critical security finding is open; the score itself is unchanged. The project hasn't declared a stable release yet, so its lenses are rated against a lower bar than a released product's, while the score itself is worked out as for any repository.
The weakest lens counts most in the score, and here that is Domain Modelling, which scores 10 and is rated Critical. Its Domain ↔ infrastructure boundary dimension scores 1 out of 10, and until that reaches 4, Domain Modelling can't be rated higher than Adequate. The first actions are to keep the ORM/table mapping on a boundary data-model + mapper; leave the domain entity framework-free (map row↔domain through a repository) and to make custom controls keyboard-operable (role + tabindex + key handler), drop positive tabindex, and give anchors a real href, and if Domain Modelling rose to 70, the score would rise from 36 to about 57.
258 findings are critical: 220 in Static Analysis (SAST), 31 in Dependency Vulnerabilities, two in IaC & Container Security, two in Secrets (history), one in Dependency Hygiene, one in Domain ↔ infrastructure boundary and one in REDACTED Scanning.
Watchdog couldn't measure 11 dimensions in this code, among them Test Reliability, Navigability and Data Protection, so they are left out of the score. The product code is 310,545 lines, which would take an estimated 4.4 person-years, around €640,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 70, the lowest score rated Strong, the score would rise from 36 to about 57.
Code composition: what the lines of code are
Product code 50%Tests 50%
New since the last survey: 123 findings
These 123 critical or serious findings weren't in the previous survey, on 11 October 2026. The first 100 are listed here, and the findings file in the download package lists them all.
Watchdog compares 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: 201 findings
These 201 critical or serious findings were in the previous survey, on 11 October 2026, and are gone from this one. The first 100 are listed here.
Code Duplication · Near-duplicate member pair (93 shared lines) REDACTED
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/mcp_registry/antigravity.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 · Members sharing a duplicated core (4 members, 50+ identical tokens) scripts/version-sync.py
€210,000 to €1,100,000, for 3,532 to 11,203 hours of work, about 4.4 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 36. 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: 310,545 lines of product code
How the estimate is made: Watchdog prices 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).
Enforce accessibility in the toolchain: add eslint-plugin-jsx-a11y, then assert with vitest-axe in tests, then gate axe/pa11y/Lighthouse in CI.
Raises the score by about 2 points · Medium effort · A11y enforcement
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 €640,000 to build again, about 4.4 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 22 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 6.1 out of 10. Code at that level is slower to change than clean code, and Watchdog estimates the extra work at 5% to 10% on every change. The history of the code shows how much it changes: about 327,777 lines over the last 90 days, which is about 1,329,318 lines a year. At that pace, the extra work comes to an estimated 154.8 to 928.9 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 Watchdog's 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; 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 — a layering smell or cycle. A clean layered graph 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.
630 modules, with 567 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; 590 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.
29→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.
benchmarks uses headroom.cache.compression_store, so a change to headroom.cache.compression_store can break benchmarks, while a change to benchmarks can't break headroom.cache.compression_store.
Position
Below the diagonal: benchmarks uses a module listed above it, which is the healthy direction.
benchmarks uses headroom.proxy.server, so a change to headroom.proxy.server can break benchmarks, while a change to benchmarks can't break headroom.proxy.server.
Position
Below the diagonal: benchmarks uses a module listed above it, which is the healthy direction.
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 · 59% · Adequate · gated by D1, D2, R3 ·
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
287
High / Critical
A03:2025 — Software Supply Chain Failures
56
High / Critical
A02:2025 — Security Misconfiguration
20
High / Critical
A07:2025 — Authentication Failures
4
High / Critical
Roadmap
First, isolate the domain layer from infrastructure by using a repository pattern to map data, ensuring entities remain framework-free. Next, enhance accessibility by making custom controls keyboard-operable, enforcing a11y rules in the toolchain and CI, and ensuring visual safety through proper focus styles, motion guards, and color contrast. Finally, correct page structure by adding essential landmarks, language attributes, and titles while maintaining zoom and iframe accessibility.
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).
Keep a visible focus style (don't remove the outline without a replacement), guard animation with prefers-reduced-motion, and raise low-contrast colour pairs to at least 4.5:1.
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.
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 — 258
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 — 1769
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 — 219
Recorded, with no effect on how the codebase functions.
Present so the survey is complete, not because it needs doing.
Could not be resolved — 11
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
Watchdog 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. 88 of 93 evaluated dimensions are computed purely by tools and static analysis (confidence 1.0); 5 documentation/naming judgement(s) are LLM-assisted and labelled advisory. Overall confidence is 0.9 — the weighted average across measured dimensions; it falls as more of the score leans on LLM-assisted judgement and rises when it's fully tool-backed.
Every figure here is one of three 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; ◐ Advisory — an LLM prose judgement. 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; ◐ Sampled · advisory marks an LLM verdict over a bounded sample — advisory, never a deterministic measurement.
What we checked — 93 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, 2213 of 2246 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, a scanner, or (for a handful of documentation/naming dimensions) an LLM labelled sampled · advisory — 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 — Watchdog measured this, but not all of it. What it 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 585 test(s) behind this row are the ones the JavaScript/TypeScript census could read, and this repository also carries at least 1,139 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 — Watchdog 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 .py, .rs, and the python executor ran against the .py half and did not finish re-running within its tier budget; 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 (vitest via `npm ci --ignore-scripts` in plugins/openclaw/ (125 tests); vitest via `npm ci --ignore-scripts` in plugins/opencode/ (58 tests); vitest via `npm ci --ignore-scripts` in sdk/typescript/ (404 tests)): measured (0 flaky) suite(s) did re-run, and came back with 0 flaky across 1 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 — Watchdog measured this, but not all of it. What it 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 — Watchdog measured this, but not all of it. What it 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.
D27 Navigability — not measured this run — Watchdog 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. Navigability is taken over call sites whose callee resolved. For C# that population includes calls into referenced assemblies; for this language only calls declared inside the repository count, so the abstention threshold reads the repository's use of its standard library as a resolution failure. That is a limit of this analyzer, not a build problem in this repository.
D32 Data Compliance (PII/GDPR) — not measured this run — Watchdog 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` 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 — Watchdog 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/cache/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.
AXR1 Runtime accessibility — not measured this run — Watchdog 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 — Watchdog 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 — Watchdog 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 — Watchdog 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 — Watchdog 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 — Watchdog 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 — Watchdog 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 — Watchdog 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 — Watchdog measured this, but not all of it. What it 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. 34 further occurrence(s) are not listed individually; the score already reflects all 74.
X3 Exception handling — measured, with a gap in what it reached — Watchdog measured this, but not all of it. What it 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. 99 further occurrence(s) are not listed individually; the score already reflects all 139.
X4 Structured logging — measured, with a gap in what it reached — Watchdog measured this, but not all of it. What it 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. 513 further occurrence(s) are not listed individually; the score already reflects all 553.
X7 Silent fallback defaults — not measured this run — Watchdog 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. 18 further occurrence(s) are not listed individually; the score already reflects all 58.
Repo exclusion declarations (.gitattributes linguist-generated/vendored, .editorconfig generated_code): none declared — every source file was scored.
Limitations & what we did not check
Watchdog assesses the repository exactly as committed, and only the repository. By design it does 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.
D9 Test Distribution: The test-pyramid shape is inferred from project/folder naming and references, with a single test host bucketed per-file by its path tier and content signals — a suite that names tiers unconventionally and gives no per-file signal can still be mis-bucketed.
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 REDACTED Scanning: REDACTED 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 is judged by an LLM over a bounded sample of docs — it reads what is written, not whether the docs match the running system, and it is advisory, not a measurement. Its critique rows are drawn from a closed category vocabulary and each row means the same thing in every run, so two scans can be compared row by row; the SET that fires is still a sample, and does not repeat exactly. Measured on one frozen input, six scans at one engine SHA: 2-5 critique rows per scan, 8 distinct rows across the six, 3 of those 8 seen in only one scan. So a D19 row is evidence about the documentation, but a COUNT of D19 rows is not a quantity — never read a change in it as an improvement or a regression.
D20 ADR Quality: ADR quality is an LLM read of the decision records present — it cannot know about decisions made and never recorded, and its verdict is sampled and advisory.
D21 Naming Consistency: Naming quality is an LLM judgement over a bounded sample — it assesses clarity/consistency of the names it sees, not domain-correctness, and is advisory.
D22 Internal API Consistency: API-surface coherence is an LLM judgement over a sample of the public surface — consistency of intent across the whole API is approximated, not exhaustively verified.
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.
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.
AC7 A11y enforcement: Enforcement is scored from in-repo config/CI evidence only — an a11y gate enforced in external tooling with no in-repo trace can't be credited, and a configured linter is presence, not proof the rules actually run or block a merge.
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: Onboarding quality is an LLM read of the docs/setup present — it cannot run the onboarding or measure how long a real new joiner takes; the verdict is sampled and advisory.
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.
The LLM boundary
LLM-set scores this run (5): D19, D20, D21, D22, M4 (model: Local LLM). For these, a model reads a bounded sample and sets the numeric score; each names its own sample and method on its card. They are sampled and advisory by design: they vary at the margins between runs and are never a deterministic measurement. Every other score in this report is tool-computed at confidence 1.0.
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.
299 method(s) exceeded the cyclomatic complexity threshold of 15; the worst was AnthropicHandlerMixin.handle_anthropic_messages at 327. 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.
+ 269 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 327). — Refactoring it lifts Cyclomatic Complexity from 3.3 to about 3.8/10.
Enforce Cyclomatic Complexity in CI to reach Verified (currently Documented). — Hardens enforcement from Documented toward Prevented — provenance only; does not change the score.
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.
+ 520 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Bring the 58 bodies over 60 down to 60 or less in Cognitive Complexity — start with AnthropicHandlerMixin.handle_anthropic_messages (cognitive 593), OpenAIHandlerMixin.handle_openai_chat (cognitive 445), ContentRouter.apply (cognitive 414). — 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 58 together lifts Cognitive Complexity from 2.0 to about 3.8/10, projected with the scoring formula itself and assuming each lands exactly at 60; a cleaner split scores higher.
Enforce Cognitive Complexity in CI to reach Verified (currently Documented). — Hardens enforcement from Documented toward Prevented — provenance only; does not change the score.
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 65 FileTooLong finding(s) in God Classes — start with lib.rs (2), REDACTED, wrap.py. — One of this dimension's main actionable groups (65 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 5 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 (5 warning-level).
Enforce God Classes in CI to reach Verified (currently Documented). — Hardens enforcement from Documented toward Prevented — provenance only; does not change the score.
Detailed fixes: d3_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Copy-pasted code that should be shared instead.
Method: Code duplication via token-stream sliding windows with type-aware normalization (locals masked, type names preserved), density-scored per KLoC of production code. Deterministic.
409 duplicated block group(s) detected. A further 15 rows report members as variants of one another; they aggregate block groups already counted above and are not themselves counted. 8 of the 424 are in trees this repository does not ship — vendored, example/demo, 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.
+ 175 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 19 Duplicated block (10 lines × 2) finding(s) in Code Duplication — start with REDACTED (2), REDACTED (2), REDACTED (2). — One of this dimension's main actionable groups (19 warning-level).
Resolve the 18 Duplicated block (14 lines × 2) finding(s) in Code Duplication — start with REDACTED (2), REDACTED, memory.py. — One of this dimension's main actionable groups (18 warning-level).
Resolve the 16 Duplicated block (7 lines × 2) finding(s) in Code Duplication — start with maturation.py (2), REDACTED (2), mitm_capture.py. — One of this dimension's main actionable groups (16 warning-level).
Enforce Code Duplication in CI to reach Verified (currently Documented). — Hardens enforcement from Documented toward Verified — provenance only; does not change the score.
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).
Enforce Coupling in CI to reach Verified (currently Documented). — Hardens enforcement from Documented toward Prevented — provenance only; does not change the score.
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).
Enforce Cohesion (LCOM4) in CI to reach Verified (currently Documented). — Hardens enforcement from Documented toward Verified — provenance only; does not change the score.
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.
All 4 mechanizable ADR(s) are enforced: 2 by analyzers, 2 by tests. Dependency cycles not checked (no project-reference graph; where this repository's language has an import-cycle lens, cycles are reported there).
✓ On the Gold path — maintain.
Detailed fixes: d7_recommendation.md.
Do you agree with this assessment?
D9 · Test Distribution10.0 / 10Exemplary✓ Tool-verified
What it measures: Whether the test suite has a healthy mix of unit / integration / end-to-end tests.
Method: Test projects classified (Unit/Integration/BDD/E2E) from compiled metadata; test methods counted exhaustively across projects with placement-agnostic disk fallback. Deterministic.
16820 test methods: 16229 unit, 560 integration, 10 BDD, 21 e2e. The JavaScript/TypeScript suite contributes 585 `it`/`test` case(s) across 35 test file(s) declaring at least one; its tier split is read from package names and paths only. The Rust suite contributes 1663 `#[test]` function(s) across 172 file(s) declaring at least one; its unit/integration split is Cargo's own — 55 of those file(s) are integration-test targets under a crate's tests/ directory, and the rest are #[test] functions compiled into the crate they test. The Python suite contributes 14572 test function(s) across 1007 file(s) declaring at least one — every `def test…` in a file pytest or unittest would collect, which is those frameworks' own definition of a case; a parametrize table counts once, so this is a floor. Its tier split is read from file names and paths only.
✓ On the Gold path — maintain.
Detailed fixes: d9_recommendation.md.
Do you agree with this assessment?
D10 · Test Quality10.0 / 10Exemplary✓ 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.
3 skipped (3 with a documented reason), 0 zero-assertion, no mocking-framework packages referenced (hand-written doubles or no mocking) across 585 tests. Measured on the JavaScript/TypeScript suite only — at least 1,139 test source file(s) (.py, .rs) went unread, so its test quality is unmeasured and is not in these counts.
Mock-dominated test: falls back when proxy is downsdk/typescript/test/adapters/vercel-ai.test.ts:476
What it measures: Whether dependencies are current, secure, and not bloated.
Method: Manifest scan via dotnet list package across all projects; worst-signal-per-package deduction (saturating for vulnerabilities, capped-linear for deprecation/outdated) per KLoC. Exhaustive, deterministic.
13 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 Cargo.lock there.
Outdated: aws-config · ×13
✓ 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 507 shipped crate(s) use a banned license. Licences were resolved from crates.io over the crates a consumer compiles — this repository's Cargo.lock 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 (102×327=33354); REDACTED (115×235=27025); headroom/transforms/content_router.py (59×182=10738) Repeated repair below the complexity floor: headroom/proxy/models.py (13 of 16 changes were fixes); REDACTED (9 of 10 changes were fixes); headroom/providers/proxy_routes.py (7 of 8 changes were fixes)
Resolve the 64 Hotspot finding(s) in Churn × Complexity Hotspots — start with REDACTED (2), analyzer.py (2), REDACTED. — One of this dimension's main actionable groups (64 warning-level).
Resolve the 55 Repeated repair finding(s) in Churn × Complexity Hotspots — start with models.py (2), paths.py (2), REDACTED. — One of this dimension's main actionable groups (55 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.2 / 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.
122 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 668 of the 824 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 · ×3
Further sole-owners (lower concentration)
What to do
Resolve the 3 Off-boarding risk finding(s) in Bus Factor. — One of this dimension's main actionable groups (3 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 310545 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 · ×10REDACTED:229
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), REDACTED, providers.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).
Enforce Explicit Debt in CI to reach Verified (currently Documented). — Hardens enforcement from Documented toward Prevented — provenance only; does not change the score.
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: Judged by language model at low temperature (0.0-0.1) on a deterministic doc sample (READMEs plus first 25 architecture docs), with two-pass stability filtering. Advisory, sampled.
The repository's root README and a docs/README describe the project (Headroom context compression layer for AI agents) with strong branding, an online docs badge, and a clear roadmap of sections to read. The docs directory is itself a Next.js application documenting its own structure (fenced shell commands, a table-of-contents), while examples/, scripts/, benchmarks/tool_search_vs_native/, and crates/headroom-simulators/ directories each serve as internal documentation for their respective tiers. All visible documents are complete: the root README covers installation, usage, contribution, and license; docs/README is an unstructured Next.js docs site with no overview (but it does document its own directory); examples/, scripts/, benchmarks/, and headroom-simulators/ each show commands to run and explain what they do. A comprehensive headroom evaluation suite and testing harness plus dozens of plugins documenting their respective directories. The repository's READMEs are focused on the directory they describe (e.g., 'headroom-ai' for compression, 'headroom-testing' for simulation), so each one is judged only against its own scope; the root README is not shown here. All visible documents are well structured with a clear overview and an outline of present sections, showing high quality. The repository's documentation is comprehensive and well-structured: the READMEs for each directory (e2e/wrap/tools/, examples/deployment/macos-launchagent/, sdk/typescript/examples/) document their own directories rather than the root repo, while architecture/design docs such as REALIGNMENT/02-architecture.md provide a full target architecture with request-lifecycle phases, invariants, and what it explicitly does not do. The e2e/wrap/tools README explains how the Docker harness installs Codex/OpenClaw via npm ci without global install support and how to regenerate the lockfile; the macOS LaunchAgent README is an excellent deployment guide with installation options, verification commands, and troubleshooting for a persistent background service; the context-mode integration analysis is deep and covers the two-layer cost problem, lossless vs. lossy compression, and three strategic unlocks (cache safety, subscription safety, realignment extension).
✓ On the Gold path — maintain.
Detailed fixes: d19_recommendation.md.
Do you agree with this assessment?
D20 · ADR QualityExemplary◐ Sampled · advisory
What it measures: Whether architecture decisions are recorded well (context, decision, consequences).
Method: Per-ADR judgment by language model at low temperature with two-pass stability; confidence is share of ADRs evaluated; enforcement-field presence detected deterministically. Advisory.
What it measures: Whether names — types, methods, variables — are clear and consistent.
Method: Judged by language model at low temperature (0.0-0.1) on a deterministic random symbol sample (fixed size, not exhaustive), with disclosed confidence band. Advisory, sampled.
0 naming inconsistencies across 0 sampled symbols.
✓ On the Gold path — maintain.
Detailed fixes: d21_recommendation.md.
Do you agree with this assessment?
D22 · Internal API ConsistencyStronggated by 1 serious finding◐ Sampled · advisory
What it measures: Whether the internal API surface is consistent and coherent.
Method: Judged by language model at low temperature over a sample of the public API surface (IsPackable or .Contracts types). Sampled, advisory; confidence discounted by model uncertainty.
1 API inconsistencies across a 400-member sample of 1732 exposed types.
Redundant operations with nearly identical signatures. `run_case_sequence` appears to be a wrapper around `run_cases` that adds a `label` parameter, likely for logging or grouping. This creates confusion about which method to use for a single batch of cases versus a labeled group, especially since the core logic is identical.
What to do
Resolve the 1 Redundant operations with nearly identical signatures.… finding(s) in Internal API Consistency. — One of this dimension's main actionable groups (1 warning-level).
Detailed fixes: d22_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.
What it measures: Whether any secrets were ever committed — scanned across the full git history, not just now.
Method: REDACTED 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.
2 finding(s): 0 critical, 2 high, 0 medium, 0 low. 2 detection(s) in paths this repository declares as reviewed specimen content (its credential-scanner allowlist) were excluded. Remediation for historically-committed secrets is credential rotation — they remain in history regardless of later deletion.
REDACTED
REDACTED
REDACTED
What to do
Resolve the 1 High secret finding(s) in Secrets (history) — start with REDACTED. — One of this dimension's main actionable groups (1 issue-level).
Resolve the 1 REDACTED finding(s) in Secrets (history) — start with REDACTED. — One of this dimension's main actionable groups (1 issue-level).
Resolve the 1 Rotate the exposed credentials finding(s) in Secrets (history). — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d28_recommendation.md · top locations in Appendix A, every location in findings.md.
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).
288 finding(s): 0 critical, 220 high, 51 medium, 17 low. 190 unpinned-GitHub-Actions row(s) are reported here but scored by D36 (supply-chain provenance), which measures that posture as `pinned_actions` — one pinning decision is charged once, not once per lens. semgrep hit a parse error in 9 file(s) — `REDACTED` (line 66), `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
+ 12 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 20 REDACTED finding(s) in Static Analysis (SAST) — start with REDACTED (16), REDACTED (2), REDACTED. — One of this dimension's main actionable groups (20 issue-level).
Resolve the 5 REDACTED finding(s) in Static Analysis (SAST) — start with REDACTED (2), REDACTED, REDACTED. — One of this dimension's main actionable groups (5 issue-level).
No action in Static Analysis (SAST) — all 190 REDACTED finding(s) are reported here at file:line but scored by D36 (supply-chain provenance), so none is charged to this dimension. — One of this dimension's main actionable groups (190 issue-level, 0 of them charged here).
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.
+ 4 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 21 High CVE finding(s) in Dependency Vulnerabilities — start with REDACTED (7), REDACTED (6), REDACTED (5). — One of this dimension's main actionable groups (21 issue-level).
Resolve the 7 Critical CVE finding(s) in Dependency Vulnerabilities — start with REDACTED (4), REDACTED (2), REDACTED. — One of this dimension's main actionable groups (7 issue-level).
Resolve the 2 Critical vulnerability finding(s) in Dependency Vulnerabilities — start with REDACTED, REDACTED. — One of this dimension's main actionable groups (2 issue-level).
Detailed fixes: d30_recommendation.md · top locations in Appendix A, every location in findings.md.
Resolve the 2 High IaC finding(s) in IaC & Container Security — start with REDACTED, REDACTED.runner. — One of this dimension's main actionable groups (2 issue-level).
Resolve the 13 Medium IaC finding(s) in IaC & Container Security — start with REDACTED (6), REDACTED (5), REDACTED.runner (2). — One of this dimension's main actionable groups (13 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.
9 of 668 significant source file(s) are orphaned — their living knowledge has decayed to nothing, so no one currently understands them. The largest is scripts/build_python_release_smoke.py. Counted over 668 of the 824 production source files in this repository: the rest are under the ~2,400-byte size floor this dimension measures over.
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.
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 — 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).
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. Scored 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. SCORED, not informational.
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 13 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) — REDACTED: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:2001
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.
`#chart g.col:focus` sets the outline to none/0 and no visible :focus / :focus-visible style for that element replaces it in this stylesheet, so a keyboard user cannot see where focus is. Draw a focus ring (outline, box-shadow or border) under :focus-visible. — REDACTED:110
What to do
Keep a visible focus style (don't remove the outline without a replacement), guard animation with prefers-reduced-motion, and raise low-contrast colour pairs to at least 4.5:1.
Do you agree with this assessment?
AC7 · A11y enforcement4.0 / 10Weak✓ Tool-verified
Other · Accessibility — Whether accessibility is ENFORCED in the toolchain — an accessibility checker configured over the markup (an a11y lint rule set, e.g. eslint-plugin-jsx-a11y or vuejs-accessibility where the project lints JavaScript) and an automated accessibility assertion wired into tests or CI (axe/pa11y/Lighthouse or an equivalent) — on the Documented→Verified→Prevented ladder.
Method: Repo config/CI scan: an accessibility checker configured over the markup (an a11y lint rule set such as eslint-plugin-jsx-a11y / vuejs-accessibility where JavaScript is linted) and an automated accessibility assertion in tests or CI (axe/pa11y/Lighthouse or equivalent), graded on the Documented→Verified→Prevented rungs. Deterministic, presence/rung detection.
Coverage: Population: the repository's own tooling configuration — lint config, test and CI files — NOT the markup. It is read for a configured accessibility checker and an automated accessibility assertion (axe/pa11y/Lighthouse, or a native-toolkit equivalent), and it credits an INVOCATION, never a mention: a licence filename, an import comment or a doc reference earns no rung. Enforcement configured entirely outside the repository leaves no evidence here and cannot be credited.
No accessibility enforcement found — no a11y linter (eslint-plugin-jsx-a11y) and no axe/pa11y/Lighthouse in tests or CI. Start with the linter to catch issues at author time. What was searched, so you can tell an absence from a miss: the 13 markup file(s) this pass actually assessed, the linter configuration checked in beside them, and this repository's test and CI files — matched by name against the accessibility checkers this dimension carries. An audit run outside the repository, a hosted scanner, or a check whose name is not one of those, is not seen here.
What to do
Enforce accessibility in the toolchain: add eslint-plugin-jsx-a11y, then assert with vitest-axe in tests, then gate axe/pa11y/Lighthouse in CI.
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.
What to do
The domain core is a small share of production code, but most of the rest matched no layer vocabulary at all — so this is not yet an anemic-domain finding. The namespace/path convention could not place that code, which makes the composition above a statement about the naming, not about the design. Name the layers (or check that the repository's conventions differ from the ones this check knows) before reading a thin domain into it.
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.
Other · Architecture — Whether interfaces stay focused rather than fat — the Interface-Segregation principle (SOLID 'I').
Method: Roslyn scan: public interface declared-member counts (accessors fold into their property/event); fat-interface threshold (over 15 declared members) flagged per type. Each finding also reports the distinct-OPERATION count — members counted by name, so an overload group counts once — which decides whether it states the caller-side ISP harm or the implementer-side burden of an overload set. TypeScript: exported interfaces that declare behaviour, counted over their REQUIRED operations (method signatures and function-typed properties with no `?`, once per signature) — data-shape interfaces and ambient .d.ts declarations are outside the population; JavaScript declares no interfaces and is not applicable. Deterministic, type-level.
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 repo and its projects have a README, and whether it's substantive and current.
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.
Add a README to the 5 of 11 project(s) that lack one — worth up to 0.9 pts.
Maturity · Maturity — Whether the README actually describes the code that exists (LLM-judged, advisory).
Method: Judged by language model at low temperature: README accuracy versus actual projects, within a disclosed tolerance. Advisory, not a measured number.
CONTRIBUTING.md names `AGENTS.md`, but no file or folder `AGENTS.md` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — CONTRIBUTING.md:132
README.md documents the environment variable `HF_ENDPOINT`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — README.md:552
README.md documents the environment variable `ORT_STRATEGY`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — README.md:562
README.md documents the environment variable `ORT_LIB_LOCATION`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — README.md:563
README.md documents the environment variable `ORT_PREFER_DYNAMIC_LINK`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — README.md:564
README.md names `AGENTS.md`, but no file or folder `AGENTS.md` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — README.md:613
docs/claude-code-bedrock-headroom.md documents the environment variable `ANTHROPIC_DEFAULT_SONNET_MODEL`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/claude-code-bedrock-headroom.md:89
docs/claude-code-bedrock-headroom.md documents the environment variable `ANTHROPIC_DEFAULT_OPUS_MODEL`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/claude-code-bedrock-headroom.md:90
docs/claude-code-bedrock-headroom.md documents the environment variable `ANTHROPIC_DEFAULT_HAIKU_MODEL`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/claude-code-bedrock-headroom.md:91
docs/context-mode-integration-analysis.md names `src/adapters/types.ts`, but no file or folder `src/adapters/types.ts` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/context-mode-integration-analysis.md:58
docs/context-mode-integration-analysis.md names `src/adapters/detect.ts`, but no file or folder `src/adapters/detect.ts` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/context-mode-integration-analysis.md:59
docs/context-mode-integration-analysis.md documents the environment variable `SHELL_ESCAPE_PATTERNS`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/context-mode-integration-analysis.md:74
docs/context-mode-integration-analysis.md names `headroom/lean_ctx/installer.py`, but no file or folder `headroom/lean_ctx/installer.py` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/context-mode-integration-analysis.md:139
docs/context-mode-integration-analysis.md names `headroom/rtk/installer.py`, but no file or folder `headroom/rtk/installer.py` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/context-mode-integration-analysis.md:139
docs/context-mode-integration-analysis.md names `tests/security/`, but no file or folder `tests/security` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/context-mode-integration-analysis.md:209
docs/context-mode-integration-analysis.md names `app/middleware/`, but no file or folder `app/middleware` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/context-mode-integration-analysis.md:324
docs/context-mode-integration-analysis.md names `app/routes/`, but no file or folder `app/routes` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/context-mode-integration-analysis.md:324
docs/context-mode-integration-analysis.md names `app/services/`, but no file or folder `app/services` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/context-mode-integration-analysis.md:324
docs/context-mode-integration-analysis.md names `app/models.py`, but no file or folder `app/models.py` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/context-mode-integration-analysis.md:324
plugins/opencode/README.md names `headroom/claude-sonnet-4-6`, but no file or folder `headroom/claude-sonnet-4-6` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — plugins/opencode/README.md:116
docs/content/docs/anthropic-sdk.mdx links to `/docs/proxy#message-format`, but `docs/proxy` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/anthropic-sdk.mdx:62
docs/content/docs/api-reference.mdx links to `/docs/troubleshooting#compression-too-aggressive`, but `docs/troubleshooting` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/api-reference.mdx:118
docs/content/docs/architecture.mdx links to `/docs/proxy#cloud-providers`, but `docs/proxy` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/architecture.mdx:44
docs/content/docs/architecture.mdx links to `/docs/text-and-logs`, but `docs/text-and-logs` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/architecture.mdx:77
docs/content/docs/architecture.mdx links to `/docs/cache-optimization`, but `docs/cache-optimization` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/architecture.mdx:94
docs/content/docs/architecture.mdx links to `/docs/ccr`, but `docs/ccr` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/architecture.mdx:106
docs/content/docs/cache-optimization.mdx links to `/docs/proxy#savings-profiles`, but `docs/proxy` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/cache-optimization.mdx:9
docs/content/docs/cache-optimization.mdx links to `/docs/configuration#cold-prefix-hook--reasoning-compaction`, but `docs/configuration` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/cache-optimization.mdx:101
docs/content/docs/ccr.mdx links to `/docs/how-compression-works#content-type-detection`, but `docs/how-compression-works` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/ccr.mdx:9
docs/content/docs/code-compression.mdx links to `/docs/how-compression-works#content-type-detection`, but `docs/how-compression-works` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/code-compression.mdx:172
docs/content/docs/configuration.mdx links to `/docs/runtime-rollouts`, but `docs/runtime-rollouts` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/configuration.mdx:20
docs/content/docs/configuration.mdx links to `/docs/codex-recovery`, but `docs/codex-recovery` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/configuration.mdx:22
docs/content/docs/configuration.mdx links to `/docs/memory#embedding-runtime--gpu-offload-apple-silicon`, but `docs/memory` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/configuration.mdx:390
docs/content/docs/configuration.mdx links to `/docs/configuration#session-beta-header-tracking`, but `docs/configuration` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/configuration.mdx:395
docs/content/docs/configuration.mdx links to `/docs/filesystem-contract`, but `docs/filesystem-contract` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/configuration.mdx:529
docs/content/docs/context-management.mdx links to `/docs/ccr`, but `docs/ccr` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/context-management.mdx:10
docs/content/docs/corporate-networks.mdx documents the environment variable `HF_ENDPOINT`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/corporate-networks.mdx:54
docs/content/docs/docker-install.mdx links to `/docs/filesystem-contract`, but `docs/filesystem-contract` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/docker-install.mdx:163
docs/content/docs/docker-install.mdx links to `/docs/persistent-installs`, but `docs/persistent-installs` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/docker-install.mdx:211
docs/content/docs/grok-build.mdx documents the environment variable `XAI_API_KEY`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong. — docs/content/docs/grok-build.mdx:51
What to do
Reconcile the README with reality: CONTRIBUTING.md names `AGENTS.md`, but no file or folder `AGENTS.md` exists; README.md documents the environment variable `HF_ENDPOINT`, but no code, script or configuration file names it; README.md documents the environment variable `ORT_STRATEGY`, but no code, script or configuration file names it; README.md documents the environment variable `ORT_LIB_LOCATION`, but no code, script or configuration file names it; README.md documents the environment variable `ORT_PREFER_DYNAMIC_LINK`, but no code, script or configuration file names it.
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 & versioning6.0 / 10Adequate✓ Tool-verified
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 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.
257/334 types (77%) declared in the published library are public. For a library, every public type is a stability contract — keep implementation types off the surface and expose only the intended API.
What to do
Keep implementation types off the public surface (Rust: `pub(crate)`, or keep the module private) so internals can change without breaking consumers.
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.
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 the language 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 Safety9.0 / 10Exemplary✓ 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.
What to do
Migrate the remaining .js/.jsx files to TypeScript.
React / JS · Code Health — Near-exact copy-pasted blocks of substantial extent across the frontend (the D4 clone algorithm over JS/TS tokens, D-386): 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. Deterministic.
headroom/providers/opencode/hook-shim/handler.js:66 · plugins/opencode/src/transport.ts:141 — the two spans are one implementation copied and then locally edited — 2376 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:66
plugins/openclaw/src/tools/headroom-retrieve.ts:12 · plugins/opencode/src/retrieve.ts:25 — 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. — plugins/openclaw/src/tools/headroom-retrieve.ts:12
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
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/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/adapters/gemini.ts:40 · sdk/typescript/src/adapters/gemini.ts:58 — 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/adapters/gemini.ts:40
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/client.ts:125 · sdk/typescript/src/client.ts:186 — 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:125
sdk/typescript/src/utils/format.ts:234 · sdk/typescript/src/utils/format.ts:548 · sdk/typescript/src/utils/format.ts:769 — all 3 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:234
headroom/providers/opencode/hook-shim/handler.js:114 · headroom/providers/opencode/hook-shim/handler.js:124 — 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:114
sdk/typescript/src/utils/format.ts:255 · sdk/typescript/src/utils/format.ts:789 — 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:255
sdk/typescript/src/utils/format.ts:283 · sdk/typescript/src/utils/format.ts:619 — 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:283
sdk/typescript/src/utils/format.ts:503 · sdk/typescript/src/utils/format.ts:528 — 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:503
sdk/typescript/src/client.ts:358 · sdk/typescript/src/client.ts:374 — 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:358
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:286 · sdk/typescript/src/client.ts:318 — 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:286
sdk/typescript/src/shared-context.ts:108 · sdk/typescript/src/shared-context.ts:123 — 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:108
sdk/typescript/src/utils/format.ts:170 · sdk/typescript/src/utils/format.ts:217 — 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:170
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
sdk/typescript/src/utils/format.ts:181 · sdk/typescript/src/utils/format.ts:231 · sdk/typescript/src/utils/format.ts:519 · sdk/typescript/src/utils/format.ts:545 — 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. — sdk/typescript/src/utils/format.ts:181
sdk/typescript/src/utils/format.ts:730 · sdk/typescript/src/utils/format.ts:766 — 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:730
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
sdk/typescript/src/client.ts:457 · sdk/typescript/src/client.ts:468 — 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/client.ts:457
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
sdk/typescript/src/client.ts:470 · sdk/typescript/src/client.ts:486 — 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:470
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.
vercelMediaImageUrl has cyclomatic complexity 30 and cognitive complexity 34; 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:394
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
detectFormat has cyclomatic complexity 26 and cognitive complexity 52; 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:34
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
vercelToOpenAI has cyclomatic complexity 24 and cognitive complexity 70; 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:497
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
openAIToVercel has cyclomatic complexity 21 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:599
vercelMediaPart has cyclomatic complexity 20 and cognitive complexity 24; 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:450
openAIToGemini has cyclomatic complexity 19 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. — sdk/typescript/src/utils/format.ts:796
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:262
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:260
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:166
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:115
(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:400
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:144
geminiToOpenAI has cyclomatic complexity 13 and cognitive complexity 34; 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:716
What to do
Break down the listed branch-heavy functions; aim P95 cyclomatic ≤ 5.
Do you agree with this assessment?
R3 · Large Files3.6 / 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 801 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 571 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
sdk/typescript/src/client.ts has 536 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
deploy/beacon/worker.js has 477 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
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
headroom/providers/opencode/hook-shim/handler.js has 451 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
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.4 / 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, plugins/headroom-snip/hooks/register.tsx:1, deploy/beacon/test-rollup.mjs: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.
What to do
Bump outdated dependencies to current versions to limit upgrade debt.
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.4 / 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 17 application, 12 tooling and 38 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 (17 application, 12 tooling, 38 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 — plugins/headroom-snip/hooks/register.tsx
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. — 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?
X15 · Unvalidated length from an untrusted reader10.0 / 10Exemplary○ Nothing flagged
Other · Security — Whether a length read out of the stream being parsed is bounded before it is allocated or read — an unchecked count taken from the input lets the input choose the allocation.
Method: Roslyn syntax + semantics: integer lengths read from a BinaryReader and spent on a bulk read or an array allocation, checked for any comparison or bounding call on the value anywhere in the method. Deterministic, provable per finding. Advisory.
Other · Code Health — Whether a loop that shortens a string until it fits a length budget has a floor — one with none grinds the value down to the empty string, or past it into a negative-length `Substring`.
Method: Roslyn syntax + semantics: while/do loops whose body's only effect on a string is to drop its last character, checked for whether anything — a direct comparison on the length, a body guard, a break — bounds that length below. 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 `while`/`do` loop whose body’s one assignment to a value is `x = x.slice(0, -1)` or `x = x.slice|substring|substr(0, x.length - 1)`, driven by a condition that reads `x.length` only as a term of a larger expression — never compared directly, never tested for truthiness, and with no other read of `x` — and whose body has no `break`, `return`, `throw` or `if` naming `x`. 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.
`strip_streaming_only_content_fields_in_place` is public, takes a document from its caller (line 343) and hands it to `_strip_index_from_content_blocks_in_place`, which calls itself at line 369 (`_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:369
`unwrap_tool_call` is public, takes a document from its caller (line 524) and hands it to `_decoded_strings`, which calls itself at line 474 (`_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:474
`segment_fingerprint` is public, takes a document from its caller (line 566) 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
`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
`probe_event` is public, takes a document from its caller (line 263) and hands it to `_all_text`, which calls itself at line 207 (`_all_text`) with a piece of `node` (and at line 210) — 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:207
`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
`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
`redact_for_wire_debug` is public and takes `value: Any` from its caller, and it calls itself at line 58 (`redact_for_wire_debug`) with a piece of `value` (and at line 63) — 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:58
`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
`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
`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
`compute_turn_id` is public, takes a document from its caller (line 3521) and hands it to `_strip_per_call_annotations`, which calls itself at line 3515 (`_strip_per_call_annotations`) with a piece of `obj` (and at line 3517) — 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:3515
`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
`build_otlp_logs` is public, takes a document from its caller (line 1556) and hands it to `_any_value`, which calls itself at line 1548 (`_any_value`) with a piece of `value` (and at line 1552) — 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:1548
`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
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 type's disposal matches what it OWNS — releasing what it created, leaving alone what it was handed, and not declaring a finalizer for state that has nothing unmanaged to finalize.
Method: Roslyn syntax + semantics: every assignment to a disposable field is read to decide whether the type CREATED the value or was handed it, and the type's disposal is checked against that answer — an injected interface it disposes, a value it constructed and never releases, a finalizer on a type holding nothing unmanaged, and a disposable local whose every reference is a plain member read. A value handed to a container that disposes its contents (a parent control's `Controls` collection, a component `IContainer`) is released by that container and is not reported; generated code is out of population. On a repository with no .NET source the same ownership questions are read in JavaScript/TypeScript off the engine’s own token stream (test, vendored, generated and minified paths not): a class declaring `dispose()`, `[Symbol.dispose]()` or `[Symbol.asyncDispose]()` that disposes a field it was handed through a constructor parameter typed as a repository interface or resolved by a dependency-injection container; that assigns a field only ever from `new X(…)` of a disposable class and neither releases it anywhere in the class nor names it in its disposal member or a method that member calls, nor hands it to anything else; and a `const`/`let` local built from literals only whose every reference opens a statement operating on a non-release member of it. A class is disposable when every repository declaration of its name declares or inherits a disposal member, or when it is a documented library disposable (`vscode` EventEmitter, CancellationTokenSource and Disposable; three.js geometries, materials, textures, render targets, renderers, controls and composers). The finalizer arm has no JavaScript counterpart: a class cannot declare one. Dart is read for the owned-and-never-released arm: a Flutter `State` (or a class declaring `dispose()`/`close()`) whose library-private field is written only with direct creations of a framework controller, `FocusNode`, `StreamController` or periodic `Timer` (or a `.listen(…)` into a field declared `StreamSubscription`), which nothing in the class or its library releases (`dispose`/`close`/`cancel`) and which is never handed on except as a named argument. Ruby is read for the owned-and-never-released arm and the abandoned-local arm: a class declaring an instance `close`, `dispose`, `shutdown`, `stop`, `disconnect` or `terminate` whose instance variable is written only with a blockless core descriptor creation (`File.open`/`new`, `Tempfile`, `Dir.open`, `IO.popen`, the `socket` and `openssl` socket classes) that no method of the class closes and that is never handed on (passed, returned, stored, exposed by `attr_reader`, delegated) — a class whose superclass or mixin lies outside the repository is not judged — and a blockless creation read through and dropped (`File.open(path).read`) or held in a local that is never closed, returned, passed or stored (a `&:read` block-pass, an `autoclose: false` borrow and a `fileno` hand-over are not abandonment). PHP is read for the same two arms: a class (not a trait, and not one using a trait) declaring an instance `close`, `dispose`, `shutdown`, `stop`, `disconnect` or `terminate` whose `private` property (or a `final` class's `protected` one) is written only with a direct core `fopen`, `tmpfile`, `popen`, `proc_open`, `fsockopen`, `stream_socket_client`/`server` or `opendir` that nothing in the class closes (`fclose`, `pclose`, `closedir`, `unset`, a reset to `null`) and that is never handed on, and a handle held in a function's local, or read through as the argument of a reader, that is never closed, returned, passed, captured or stored; a `php://` stream, `curl_init`, `SplFileObject`, `PDO` and a function the repository declares under the core name are not read. Deterministic, provable per finding. Advisory.
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 279, cleared at line 283) and the `DISABLE_PROMPT_CACHING_OPUS` environment variable (set at line 284, cleared at line 287) and the `ENABLE_PROMPT_CACHING_1H` environment variable (set at line 288, cleared at line 292) — 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:233
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 a method that TAKES a lock or semaphore and gives it back from a flag-guarded `finally` returns the value that flag implies — reporting success while the guard hands the primitive back admits a second caller the exclusion was there to keep out, and reporting failure while the guard keeps it leaves nothing to ever give it back.
Method: Roslyn syntax: `try` statements whose `finally` releases a synchronisation primitive under a bare local-bool guard, where the method also TOOK that same primitive before the `try`, checked for a `return` of a bool literal whose value disagrees with the flag state the method's own straight-line assignments put it in. 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 201 is called with an argument built by `sorted(payload.keys())` (line 201), 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:201
`debug` at line 764 is called with an argument built by `sorted(values.keys())` (line 764), 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:764
`debug` at line 929 is called with an argument built by `sorted(allowed)` (line 932), 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:929
`debug` at line 7562 is called with an argument built by `[k for k in upstream_headers if k.lower() != "…"]` (line 7564), 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:7562
`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 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 3951 is called with an argument built by `"…".join(map(str, out.warnings))` (line 3952), 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:3951
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.
Other · Code Health — Whether a value handed from a callback to the body that waits on it crosses on something built to be crossed — a `Queue<T>`/`List<T>`/`Dictionary<K,V>` written inside an event handler and read back outside it is mutated by two flows at once, and the semaphore or completion source beside it orders how MANY items exist while leaving the collection's own head, tail and backing array unprotected.
Method: Roslyn syntax: method, accessor, local-function and lambda bodies that declare BOTH a non-thread-safe generic collection (`Queue`/`Stack`/`List`/`Dictionary`/`HashSet`/`Sorted*`/`LinkedList`) and a synchronisation primitive (`SemaphoreSlim`/`TaskCompletionSource`/`ManualResetEvent(Slim)`/`AutoResetEvent`/`CountdownEvent`) as locals, then read for a `+=`-registered lambda that raises that primitive while the body outside every lambda waits on it — and, in that scope, a mutating call on the collection inside the lambda paired with a mention of it outside. Any `lock` in the scope abstains it. On a repository with no .NET source the same handoff is read in Java off the engine’s own token stream (test source sets, vendored and demonstration paths not): an `ArrayList`/`LinkedList`/`ArrayDeque`/`PriorityQueue`/`Hash*`/`LinkedHash*`/`Tree*` local and a `CountDownLatch`/`Semaphore`/`CompletableFuture` local, a lambda or anonymous class that raises the primitive and mutates the collection, and a wait outside it; any `synchronized` or `lock()` abstains the body. Because each of those primitives orders what the callback wrote before raising it, only a touch that provably overlaps the callback is convicted: one after the registration and before the next wait, or one in a loop registered-before, waiting on every pass and not declaring the collection. 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.
Do you agree with this assessment?
X29 · Per-element action decided by a fixed element10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a decision taken once per element is taken ABOUT that element — a test inside a counted loop that reads a fixed subscript of the very collection its guarded statement indexes by the loop variable applies element zero's answer to all of them, so the elements that differ from it are all handled wrongly, and in the same direction.
Method: Roslyn syntax only, no semantic model: every `for` statement declaring exactly ONE loop variable, and every `if` inside its body that is not under a nested loop or a lambda. A site enters the population when the `if`’s condition never mentions the loop variable while the statement it guards indexes some collection by that variable ALONE (`c[i]`; `c[i + 1]` and `c[i, j]` are outside it). A finding additionally needs the AGREEING TWIN at the same-collection grain: the condition must read THAT SAME collection at a subscript that does not move — written into the condition, or reached through a local declared BEFORE the loop, so an alias bound inside the body is not followed. Both collection expressions must be simple identifiers. On a repository with no .NET source the same rule reads JavaScript/TypeScript off the engine’s own token stream (tests included, bundles and vendored paths not): a `for (let|var|const x = …; …; …)` with one declarator and a braced body, an alias followed only when it is declared before the loop in a block that encloses it and never assigned inside the loop. 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, …
`.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) — deploy/beacon/worker.js:159, deploy/beacon/worker.js:500
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) — headroom/proxy_client_liveness.py:35, headroom/onnx_runtime.py:284, headroom/_subprocess.py:30, …
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.
`info` at line 307 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/backends/litellm.py:307
`warning` at line 309 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/backends/litellm.py:309
`info` at line 887 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/backends/litellm.py:887
`info` at line 901 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/backends/litellm.py:901
`debug` at line 1322 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/backends/litellm.py:1322
`error` at line 1341 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/backends/litellm.py:1341
`error` at line 1774 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/backends/litellm.py:1774
`debug` at line 1846 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/backends/litellm.py:1846
`debug` at line 1898 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/backends/litellm.py:1898
`error` at line 1970 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/backends/litellm.py:1970
`error` at line 2078 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/backends/litellm.py:2078
`info` at line 63 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/backends/anyllm.py:63
`debug` at line 262 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/backends/anyllm.py:262
`error` at line 274 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/backends/anyllm.py:274
`error` at line 467 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/backends/anyllm.py:467
`debug` at line 501 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/backends/anyllm.py:501
`error` at line 560 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/backends/anyllm.py:560
`error` at line 635 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/backends/anyllm.py:635
`debug` at line 484 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/cache/google.py:484
`info` at line 504 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/cache/google.py:504
`debug` at line 537 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/cache/google.py:537
`warning` at line 586 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/cache/google.py:586
`info` at line 592 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/cache/google.py:592
`info` at line 615 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/cache/google.py:615
`info` at line 647 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/cache/google.py:647
`debug` at line 730 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/cache/google.py:730
`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/cache/google.py:897
`info` at line 900 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/cache/google.py:900
`error` at line 263 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/ccr/response_handler.py:263
`info` at line 521 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/ccr/response_handler.py:521
`debug` at line 528 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/ccr/response_handler.py:528
`warning` at line 576 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/ccr/response_handler.py:576
`error` at line 755 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/ccr/response_handler.py:755
`error` at line 792 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/ccr/response_handler.py:792
`error` at line 807 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/ccr/mcp_server.py:807
`warning` at line 59 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/ccr/marker_resolution.py:59
`debug` 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.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/ccr/context_tracker.py:225
`info` at line 532 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/ccr/context_tracker.py:532
`warning` at line 537 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/ccr/context_tracker.py:537
`debug` at line 146 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/ccr/batch_store.py:146
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.4 `!` null assertions per 1k TypeScript source lines — 3 assertion(s) across the 8274 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.
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 — 25 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 — 31 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).
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.
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+ projects each declaring an entity of their own. 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"]`.
D24 Comment Value — No inline comments to assess — comment value is not applicable here.
D25 ADR Conformance — none of 5 ADRs are conformance-checkable — unverifiable.
D27 Navigability — D27 counts a call into the standard library or a dependency as unresolved for this repository's language (.py), so too few call sites counted as resolved to assess navigability. Not scored: this is a gap in the analyzer, not a verdict about this repository.
D32 Data Compliance (PII/GDPR) — 1 file(s) were not parsed by semgrep — the PII/GDPR ruleset never ran over them
D39 IL Efficiency — D39 measures the IL emitted by a .NET build; this repository has no .NET solution or project files, so the dimension does not apply.
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 — plugins/openclaw/ runs vitest but declares no coverage provider, so the suite can run and still produce no lcov — add `@vitest/coverage-v8` (or `@vitest/coverage-istanbul`) as a devDependency. 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. Alternatively, commit the lcov/Cobertura report your CI produces and it is read without a re-run.
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 — no coverage report found on disk — produce a coverage report in a standard format (`coverage run -m pytest` then `coverage xml`) and commit it — a hosted scan measures a clone of the repository, so a report that exists only in a working tree, a CI runner's or your own, never reaches it; the artefact is commonly gitignored, so `git add -f` that one file (or un-ignore its path) and commit it alongside the code it measures, or wire coverage collection into CI, to enable this cross-layer check
PF2 Allocation hygiene — Not applicable: Python and TypeScript/JavaScript runs on a garbage-collected runtime that gives a program no allocation-control idiom to choose on a hot path — no pools, stack allocation or value types — so allocation awareness is not something this code can be rated on. Rust spells out every heap allocation and makes borrowed slices (&[T], &str) its ordinary parameter types, so the allocation-aware style this card rewards elsewhere is the language's baseline rather than a rung to climb.
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.
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.
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.
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 'zod' plugins/opencode/src/plugin.ts:4— Imported but not declared in any reachable package.json — installs work only by hoisting accident.
FileTooLong: REDACTED REDACTED— FileTooLong — 7911 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 7411 over it, 15.82× 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 — 5639 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 5139 over it, 11.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: REDACTED REDACTED— FileTooLong — 4395 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 3895 over it, 8.79× 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 — 4242 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 3742 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: REDACTED REDACTED— FileTooLong — 3880 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 3380 over it, 7.76× 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 — 2491 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1991 over it, 4.98× 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 — 1708 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1208 over it, 3.42× 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 — 1681 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1181 over it, 3.36× 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: transforms/code_compressor.py headroom/transforms/code_compressor.py— FileTooLong — 1639 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1139 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: REDACTED REDACTED— FileTooLong — 1291 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 791 over it, 2.58× 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 — 1272 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 772 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: memory/traffic_learner.py headroom/memory/traffic_learner.py— FileTooLong — 1248 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 748 over it, 2.50× 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: proxy/prometheus_metrics.py headroom/proxy/prometheus_metrics.py— FileTooLong — 1216 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 716 over it, 2.43× 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 — 1205 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 705 over it, 2.41× 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 — 1164 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 664 over it, 2.33× 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 — 1145 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 645 over it, 2.29× 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 — 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/gateway_turn.py headroom/proxy/gateway_turn.py— FileTooLong — 1070 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 570 over it, 2.14× 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 — 1056 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 556 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.
FileTooLong: REDACTED REDACTED— FileTooLong — 1047 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 547 over it, 2.09× 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 — 1046 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 546 over it, 2.09× 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:1034— REDACTED changed 102 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 327 in AnthropicHandlerMixin.handle_anthropic_messages at line 1034. 88 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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:3313— REDACTED changed 115 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 235 in OpenAIHandlerMixin.handle_openai_chat at line 3313. 93 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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:5982— headroom/transforms/content_router.py changed 59 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 182 in ContentRouter.apply at line 5982. 46 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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:4847— headroom/cli/wrap.py changed 70 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 117 in wrap._ensure_proxy_unlocked at line 4847. 54 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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:2059— 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 2059. 73 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/dashboard/templates/dashboard.html headroom/dashboard/templates/dashboard.html:2055— headroom/dashboard/templates/dashboard.html changed 29 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 107 in REDACTED.dashboard at line 2055. 17 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/cli/proxy.py headroom/cli/proxy.py:1156— headroom/cli/proxy.py changed 26 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 115 in proxy.proxy at line 1156. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/proxy/helpers.py headroom/proxy/helpers.py:1072— headroom/proxy/helpers.py changed 59 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 43 in helpers.relocate_system_messages_to_top_level at line 1072. 51 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/transforms/kompress_compressor.py headroom/transforms/kompress_compressor.py:2285— headroom/transforms/kompress_compressor.py changed 22 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 66 in KompressCompressor.compress_batch at line 2285. 19 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/proxy/handlers/gemini.py headroom/proxy/handlers/gemini.py:328— headroom/proxy/handlers/gemini.py changed 17 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 85 in GeminiHandlerMixin.handle_gemini_generate_content at line 328. 14 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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:1135— REDACTED changed 36 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 37 in StreamingMixin._stream_response_inner at line 1135. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/backends/litellm.py headroom/backends/litellm.py:1373— headroom/backends/litellm.py changed 17 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 65 in LiteLLMBackend.stream_message at line 1373. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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:231— headroom/proxy/cost.py changed 23 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 231. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/proxy/prometheus_metrics.py headroom/proxy/prometheus_metrics.py:1402— headroom/proxy/prometheus_metrics.py changed 22 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 47 in PrometheusMetrics.export at line 1402. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/perf/analyzer.py headroom/perf/analyzer.py:517— headroom/perf/analyzer.py changed 15 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 62 in analyzer.format_report at line 517. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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: REDACTED REDACTED:478— REDACTED changed 23 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 31 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/proxy/gateway_turn.py headroom/proxy/gateway_turn.py:1524— headroom/proxy/gateway_turn.py changed 9 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 1524. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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:1771— REDACTED changed 14 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 32 in SessionTrackerStore.resolve_tracker at line 1771. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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: crates/headroom-proxy/src/proxy.rs crates/headroom-proxy/src/proxy.rs:499— crates/headroom-proxy/src/proxy.rs changed 7 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 64 in headroom_proxy::proxy::forward_http at line 499. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07:00' --full-history --no-merges -- crates/headroom-proxy/src/proxy.rs`: 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:1852— 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 1852. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/cli/learn.py headroom/cli/learn.py:143— headroom/cli/learn.py changed 7 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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: REDACTED REDACTED:1268— REDACTED changed 10 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 36 in session._fold at line 1268. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/learn/analyzer.py headroom/learn/analyzer.py:864— 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 864. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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.
Hotspot: headroom/install/planner.py headroom/install/planner.py:139— headroom/install/planner.py changed 9 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 33 in planner.build_manifest at line 139. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07:00' --full-history --no-merges -- headroom/install/planner.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/models.py headroom/proxy/models.py:577— headroom/proxy/models.py changed 16 times in last 90 days and 13 of those changes were fix/bug commits, so repair is the majority of this file's churn. Its max cyclomatic complexity is 7 (its worst body is ProxyConfig.__post_init__ at line 577), 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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: REDACTED REDACTED:206— REDACTED changed 10 times in last 90 days and 9 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 206), 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(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)”; “fix(codex): make unwrap codex remove headroom init routing (#3920)”; “fix(install): replace the launchd wrapper with the proxy listener (#3224)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/providers/proxy_routes.py headroom/providers/proxy_routes.py:215— headroom/providers/proxy_routes.py changed 8 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 4 (its worst body is proxy_routes._register_openai_responses_routes at line 215), 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(grok): route CLI traffic to api.x.ai on shared proxies (#2693)”; “fix(proxy): support Codex Live HTTP call creation (#3464)”; “fix(security): validate caller-supplied upstreams on every resolution path (#3195)”; “fix(security): address u9up assessment findings (WEB-01–07) (#2207)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/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), 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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: headroom/transforms/kompress_remote.py headroom/transforms/kompress_remote.py:219— headroom/transforms/kompress_remote.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 14 (its worst body is RemoteKompressCompressor.compress at line 219), 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(router): bound ML compression per request, not just per block (#3721)”; “fix(offline): make HEADROOM_OFFLINE a real air-gap via one chokepoint (#3729)”; “fix(kompress): append the CCR marker whenever the saving pays for it (#3484)”; “fix(transforms): stop compression garbling mixed subagent output (#3286)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07:00' --full-history --no-merges -- headroom/transforms/kompress_remote.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/transport.ts plugins/opencode/src/transport.ts:396— plugins/opencode/src/transport.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 10 (its worst body is transport.splitNodeArgs at line 396), 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): restore process env keys on transport dispose (#4430)”; “fix(proxy): astgrep disk verify truncation (#3192)”; “fix(opencode): hide spawned Windows console windows (#3743)”; “fix(opencode): route only LLM traffic through Headroom (#3884)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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: headroom/proxy/output_savings.py headroom/proxy/output_savings.py:619— headroom/proxy/output_savings.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 SavingsLedger.from_dict at line 619), 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(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)”; “fix(output-savings): count conversations, not requests, in the holdout gate (#3460)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/pricing/litellm_pricing.py headroom/pricing/litellm_pricing.py:91— headroom/pricing/litellm_pricing.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 8 (its worst body is litellm_pricing._reduce_to_priced_key at line 91), 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(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)”; “fix(deps): install on Python 3.14 from prebuilt wheels only (#3631)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/providers/opencode/hook-shim/handler.js headroom/providers/opencode/hook-shim/handler.js:245— headroom/providers/opencode/hook-shim/handler.js 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 10 (its worst body is handler.splitNodeArgs at line 245), 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): restore process env keys on transport dispose (#4430)”; “fix(proxy): astgrep disk verify truncation (#3192)”; “fix(opencode): hide spawned Windows console windows (#3743)”; “fix(opencode): route only LLM traffic through Headroom (#3884)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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: headroom/integrations/litellm_callback.py headroom/integrations/litellm_callback.py:101— headroom/integrations/litellm_callback.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 11 (its worst body is HeadroomCallback.async_pre_call_hook at line 101), 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(offline): keep litellm's pricing table local under HEADROOM_OFFLINE (#4242)”; “fix(offline): make HEADROOM_OFFLINE a real air-gap via one chokepoint (#3729)”; “fix(litellm): compress anthropic messages route in HeadroomCallback (#3504)”; “fix(litellm): close shared cloud client”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07:00' --full-history --no-merges -- headroom/integrations/litellm_callback.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/subscription/tracker.py headroom/subscription/tracker.py:391— headroom/subscription/tracker.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 9 (its worst body is SubscriptionTracker._maybe_poll at line 391), 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(subscription): log a failed OTEL window update instead of passing silently (#4131)”; “fix(subscription): poll with the refreshed credentials-file OAuth token (#3916)”; “fix(security): poll usage only with the operator's own credential (#3863)”; “fix(proxy): make --stateless write nothing to the workspace (#3846)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07:00' --full-history --no-merges -- headroom/subscription/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.
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), 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/memory/storage_router.py headroom/memory/storage_router.py:149— headroom/memory/storage_router.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 ProjectResolver.resolve at line 149), 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): treat a cwd with no UTF-8 form as unresolved instead of raising (#4167)”; “fix(memory): ignore incidental cwd prose (#4166)”; “fix(memory): align project routing with wrap headers (#3603)”; “fix(memory): make extract_system_prompt concatenative, not first-match (#3644)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/onnx_runtime.py headroom/onnx_runtime.py:250— headroom/onnx_runtime.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 onnx_runtime.create_cpu_session_options at line 250), 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 default embedder from one pinned snapshot (#4152)”; “fix(offline): make HEADROOM_OFFLINE a real air-gap via one chokepoint (#3729)”; “fix(kompress): pin ModernBERT tokenizer and encoder revisions (#3808)”; “fix(onnx): stop ONNX thread pools from spinning idle cores (#2495) (#2540)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07:00' --full-history --no-merges -- headroom/onnx_runtime.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/tool_schema_savings_policy.py headroom/proxy/tool_schema_savings_policy.py:119— headroom/proxy/tool_schema_savings_policy.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 14 (its worst body is tool_schema_savings_policy.reconcile_deferred_tokens at line 119), 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): show turn-hook savings in /stats extension_savings, incl. Codex WS (#4233)”; “fix(proxy): net tools a turn hook adds against the saving it books (#4057)”; “fix(proxy): log the savings and metrics failures that currently vanish (#4084)”; “fix(proxy): ignore defer_loading when measuring a turn hook's tool delta (#4056)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07:00' --full-history --no-merges -- headroom/proxy/tool_schema_savings_policy.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/openclaw/src/engine.ts plugins/openclaw/src/engine.ts:130— plugins/openclaw/src/engine.ts 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 10 (its worst body is HeadroomContextEngine.assemble at line 130), 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(plugins/openclaw): keep compression system-prompt notice cache-stable (#3811)”; “fix(plugins/openclaw): return messages the proxy did not change exactly as they came in (#3826)”; “fix(openclaw): declare transcriptSemantics and implement commitTurn (#3442)”; “fix(openclaw): delegate native compaction (#2304)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/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), 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(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)”; “fix(tokenizers): disable trust_remote_code and allowlist HF tokenizer repos (#3723)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/cache/backends/sqlite.py headroom/cache/backends/sqlite.py:190— headroom/cache/backends/sqlite.py changed 6 times in last 90 days and 4 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._entry_from_json at line 190), 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): 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)”; “fix(security): create credential files private instead of narrowing after write (#3215)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/proxy/runtime_env.py headroom/proxy/runtime_env.py:154— headroom/proxy/runtime_env.py changed 5 times in last 90 days and 4 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 154), 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): 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)”; “fix(shaper): measure output-token steering, and stop claiming savings we did not measure (#3377)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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.
Repeated repair: headroom/providers/opencode/config.py headroom/providers/opencode/config.py:129— headroom/providers/opencode/config.py changed 5 times in last 90 days and 4 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 config._strip_jsonc_comments at line 129), 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): do not rewrite an OpenCode config that fails to parse (#4424)”; “fix(install): preserve OpenCode edits during reactivation (#4022)”; “fix(wrap): let `wrap opencode` target a third-party OpenAI-compatible upstream (#3125)”; “fix(opencode): keep Claude models off OpenAI provider”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07:00' --full-history --no-merges -- headroom/providers/opencode/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: headroom/mcp_registry/claude.py headroom/mcp_registry/claude.py:153— headroom/mcp_registry/claude.py changed 5 times in last 90 days and 4 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 ClaudeRegistrar.get_plugin_servers at line 153), 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(mcp_registry): atomic config writes, no traceback on non-UTF-8 configs, log failed removals (#4130)”; “fix(wrap): scope Serena's MCP registration to the wrapped project (#2787) (#2992)”; “fix(mcp): report a plugin-provided Serena that reconcile cannot see (#3578)”; “fix(mcp): add explicit Serena reconciliation (#3222)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07:00' --full-history --no-merges -- headroom/mcp_registry/claude.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:210— headroom/mcp_registry/codex.py changed 5 times in last 90 days and 4 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 210), 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(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)”; “fix(cli): honor CODEX_HOME and align wrap/init/doctor with the live proxy port (#3855)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/graph/installer.py headroom/graph/installer.py:25— headroom/graph/installer.py changed 5 times in last 90 days and 4 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 installer.get_cbm_path at line 25), 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(offline): make HEADROOM_OFFLINE a real air-gap via one chokepoint (#3729)”; “fix(graph): fetch and extract the zip codebase-memory-mcp asset on Windows (#3730)”; “fix(binaries): fail closed when a download carries no sha256 pin (#3724)”; “fix(security): address u9up assessment findings (WEB-01–07) (#2207)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07:00' --full-history --no-merges -- headroom/graph/installer.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:289— REDACTED changed 5 times in last 90 days and 4 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 289), 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(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)”; “fix(security): address u9up assessment findings (WEB-01–07) (#2207)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07: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/transforms/tabular_ingest.py headroom/transforms/tabular_ingest.py:127— headroom/transforms/tabular_ingest.py changed 4 times in last 90 days and 4 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 tabular_ingest.parse_tabular at line 127), 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(tabular): pass tables with repeated header names through verbatim (#4278)”; “fix(router): preserve human-readable Git status losslessly (#4020)”; “fix(transforms): detect fixed-width command output as tabular and keep it out of Kompress (#3786)”; “fix(tabular): pass a table through when one cell is past the csv field limit (#3618)”. 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-07-26..2026-10-24, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-07-26 08:45:38 -07:00' --until='2026-10-24 08:45:38 -07:00' --full-history --no-merges -- headroom/transforms/tabular_ingest.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 58) crates/headroom-core/src/transforms/diff_compressor.rs:679— headroom_core::transforms::diff_compressor::parse_diff has cognitive complexity 58 (threshold 15). Drivers by points: if/else 25 (53 pts), boolean chains 4, loops 1 (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.
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:812— 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::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:873— 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:2676— 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:234— 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::tag_protector::identify_spans (cognitive 25) crates/headroom-core/src/transforms/tag_protector.rs:487— 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::smart_crusher::orchestration::prioritize_indices (cognitive 24) crates/headroom-core/src/transforms/smart_crusher/orchestration.rs:152— headroom_core::transforms::smart_crusher::orchestration::prioritize_indices has cognitive complexity 24 (threshold 15). Drivers by points: if/else 9 (15 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::diff_compressor::format_output (cognitive 22) crates/headroom-core/src/transforms/diff_compressor.rs:1085— 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:2888— 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.
headroom_core::transforms::content_detector::detect_content_type (cognitive 19) crates/headroom-core/src/transforms/content_detector.rs:397— headroom_core::transforms::content_detector::detect_content_type has cognitive complexity 19 (threshold 15). Drivers by points: if/else 13 (18 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.
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) docker/differential-network-capture/mitm_capture.py:58— `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/onnx_runtime.py:308— `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/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/_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/_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/cache/ttl_observations.py:113— `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/capture/network_diff.py:113— `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/capture/network_diff.py:126— `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/ccr/mcp_server.py:637— `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/cli/wrap.py:2551— `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/cli/wrap.py:4477— `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/cli/update.py:51— `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/cli/update.py:66— `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/cli/update.py:77— `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/cli/update.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/cli/update.py:117— `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/cli/update.py:158— `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 (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:4982— headroom/cli/wrap.py:4982-4991 | headroom/cli/wrap.py:5029-5038 — 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:4982` 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:4992` calls `echo`, `_proxy_status_line` and `headroom/cli/wrap.py:5039` 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:1579— headroom/proxy/cost.py:1579-1588 | headroom/proxy/cost.py:1648-1657 — 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:1645` calls `startswith` and `headroom/proxy/cost.py:1578` 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:5269— REDACTED:5269-5278 | headroom/proxy/handlers/gemini.py:1099-1108 — 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:5269— REDACTED:5269-5278 | REDACTED:1632-1641 — 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:1987— REDACTED:1987-1996 | REDACTED:2028-2037 — 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:5087— REDACTED:5087-5096 | REDACTED:5691-5700 — 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:5087` 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:963— REDACTED:963-972 | REDACTED:2282-2291 — 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:963` 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) REDACTED:1947— REDACTED:1947-1956 | REDACTED:1973-1982 — 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-core/src/transforms/pipeline/offloads/diff_noise.rs:326— crates/headroom-core/src/transforms/pipeline/offloads/diff_noise.rs:326-335 | crates/headroom-core/src/transforms/pipeline/offloads/json_offload.rs:213-222 — 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) 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:446-455 — 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:640— crates/headroom-proxy/src/bedrock/invoke.rs:640-649 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:850-859 — 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 15 separate duplicated blocks between them, totalling at least 353 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 (10 lines × 2) crates/headroom-proxy/src/main.rs:167— crates/headroom-proxy/src/main.rs:167-176 | 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.
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.
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.
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.
Duplicated block (14 lines × 2) REDACTED:229— REDACTED:229-242 | REDACTED:631-644 — 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: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. 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/memory.py:947— headroom/cli/memory.py:947-960 | headroom/cli/memory.py:1138-1151 — 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/cli/wrap.py:3977— headroom/cli/wrap.py:3977-3991 | headroom/cli/wrap.py:5646-5659 — 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:3977` 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:525-538 — 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:2647— REDACTED:2647-2660 | REDACTED:4190-4203 — 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:2647` 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:6173— REDACTED:6173-6186 | REDACTED:8215-8228 — 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:6173` 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:1575— REDACTED:1575-1588 | REDACTED:2009-2022 — 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:1575` 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:5792— headroom/transforms/content_router.py:5792-5805 | headroom/transforms/content_router.py:5813-5826 — 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:256— REDACTED:256-269 | REDACTED:344-359 — 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:256` 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:1422— crates/headroom-core/src/transforms/live_zone.rs:1422-1435 | crates/headroom-core/src/transforms/live_zone.rs:1445-1458 — 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/crusher.rs:561— crates/headroom-core/src/transforms/smart_crusher/crusher.rs:561-574 | crates/headroom-core/src/transforms/smart_crusher/crusher.rs:661-674 — 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.
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.
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.
Duplicated block (14 lines × 2) crates/headroom-proxy/src/proxy.rs:1674— crates/headroom-proxy/src/proxy.rs:1674-1687 | crates/headroom-proxy/src/proxy.rs:1795-1809 — 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_proxy::proxy::forward_http (cognitive 107) crates/headroom-proxy/src/proxy.rs:499— 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:1544— 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::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::invoke_streaming::handle_invoke_streaming (cognitive 39) crates/headroom-proxy/src/bedrock/invoke_streaming.rs:122— headroom_proxy::bedrock::invoke_streaming::handle_invoke_streaming has cognitive complexity 39 (threshold 15). Drivers by points: if/else 16 (28 pts), match/switch 8 (9 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::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 29) crates/headroom-proxy/src/bedrock/invoke.rs:133— headroom_proxy::bedrock::invoke::handle_invoke has cognitive complexity 29 (threshold 15). Drivers by points: if/else 13 (20 pts), match/switch 7, 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:725— 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:503— 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.
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 REDACTED:369— `strip_streaming_only_content_fields_in_place` is public, takes a document from its caller (line 343) and hands it to `_strip_index_from_content_blocks_in_place`, which calls itself at line 369 (`_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 headroom/config.py:474— `unwrap_tool_call` is public, takes a document from its caller (line 524) and hands it to `_decoded_strings`, which calls itself at line 474 (`_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:262— `segment_fingerprint` is public, takes a document from its caller (line 566) 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.
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 headroom/evals/session_probes.py:207— `probe_event` is public, takes a document from its caller (line 263) and hands it to `_all_text`, which calls itself at line 207 (`_all_text`) with a piece of `node` (and at line 210) — 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/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/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/proxy/wire_debug_redaction_policy.py:58— `redact_for_wire_debug` is public and takes `value: Any` from its caller, and it calls itself at line 58 (`redact_for_wire_debug`) with a piece of `value` (and at line 63) — 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/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/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/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/helpers.py:3515— `compute_turn_id` is public, takes a document from its caller (line 3521) and hands it to `_strip_per_call_annotations`, which calls itself at line 3515 (`_strip_per_call_annotations`) with a piece of `obj` (and at line 3517) — 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/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 REDACTED:1548— `build_otlp_logs` is public, takes a document from its caller (line 1556) and hands it to `_any_value`, which calls itself at line 1548 (`_any_value`) with a piece of `value` (and at line 1552) — 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 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.
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/audit/maturation.py:91— headroom/audit/maturation.py:91-97 | headroom/audit/reads.py:193-199 — 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 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:1581— headroom/memory/traffic_learner.py:1581-1588 | headroom/transforms/read_lifecycle.py:202-208 — 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:1251— REDACTED:1251-1257 | 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:2311— REDACTED:2311-2317 | REDACTED:2321-2327 — 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/content_router.py:873— headroom/transforms/content_router.py:873-879 | headroom/transforms/content_router.py:946-952 — 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:396— headroom/transforms/read_lifecycle.py:396-402 | headroom/transforms/read_lifecycle.py:450-456 — 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:448` calls `get` and `headroom/transforms/read_lifecycle.py:395` 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:131— headroom/pricing/counterfactual.py:131-137 | 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:273— REDACTED:273-279 | REDACTED:363-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 (7 lines × 2) crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:523— crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:523-529 | crates/headroom-core/src/transforms/smart_crusher/analyzer.rs:534-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.
Duplicated block (7 lines × 2) crates/headroom-proxy/src/bedrock/invoke_streaming.rs:776— crates/headroom-proxy/src/bedrock/invoke_streaming.rs:776-782 | crates/headroom-proxy/src/proxy.rs:1613-1619 — 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/perf/analyzer.py:733— headroom/perf/analyzer.py:733-739 | headroom/perf/analyzer.py:742-748 — 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/perf/analyzer.py:733` 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 (5 lines × 2) headroom/cli/evals.py:723— headroom/cli/evals.py:723-727 | headroom/cli/evals.py:752-756 — 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:301— REDACTED:301-305 | headroom/providers/codex/install.py:361-365 — 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) headroom/cli/wrap.py:4139— headroom/cli/wrap.py:4139-4143 | headroom/providers/copilot/wrap.py:36-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 (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:2689— REDACTED:2689-2693 | REDACTED:2731-2735 — 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:2689` 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) REDACTED:133— REDACTED:133-138 | REDACTED:261-265 — 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 (5 lines × 2) headroom/install/paths.py:120— headroom/install/paths.py:120-131 | 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) headroom/learn/plugins/codex.py:55— headroom/learn/plugins/codex.py:55-59 | headroom/learn/plugins/gemini.py:59-63 — 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 (5 lines × 2) crates/headroom-proxy/src/proxy.rs:449— crates/headroom-proxy/src/proxy.rs:449-455 | crates/headroom-proxy/src/proxy.rs:1415-1419 — 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) 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.
Duplicated block (5 lines × 2) crates/headroom-proxy/src/sse/openai_chat.rs:159— crates/headroom-proxy/src/sse/openai_chat.rs:159-164 | crates/headroom-proxy/src/sse/openai_chat.rs:196-200 — 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.
FunctionTooLong: headroom_proxy::proxy::forward_http crates/headroom-proxy/src/proxy.rs:499— 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 245 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 145 over it, 2.45× 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:1544— 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:133— FunctionTooLong — headroom_proxy::bedrock::invoke::handle_invoke runs 205 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 105 over it, 2.05× 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: REDACTED.renderChart REDACTED: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:1331— 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:2676— 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 (9 lines × 2) headroom/cli/proxy.py:1454— headroom/cli/proxy.py:1454-1462 | headroom/memory/system.py:333-351 — 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:1138— headroom/learn/analyzer.py:1138-1146 | headroom/learn/analyzer.py:1156-1164 — 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:1138` 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:2278— REDACTED:2278-2286 | REDACTED:2292-2300 — 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:2278` 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) REDACTED:3861— REDACTED:3861-3871 | REDACTED:6054-6062 — 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:3861` 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) headroom/proxy/savings_tracker.py:1550— headroom/proxy/savings_tracker.py:1550-1558 | headroom/proxy/savings_tracker.py:1590-1598 — 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:1113— headroom/transforms/code_compressor.py:1113-1121 | headroom/transforms/code_compressor.py:1125-1133 — 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) 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.
Duplicated block (9 lines × 2) headroom/providers/anthropic.py:826— headroom/providers/anthropic.py:826-834 | headroom/providers/openai.py:644-652 — 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/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:2453— crates/headroom-core/src/transforms/live_zone.rs:2453-2462 | crates/headroom-core/src/transforms/live_zone.rs:2980-2988 — 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) crates/headroom-proxy/src/bedrock/invoke_streaming.rs:779— crates/headroom-proxy/src/bedrock/invoke_streaming.rs:779-787 | 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.
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) headroom/proxy/helpers.py:578— headroom/proxy/helpers.py:578-589 | headroom/proxy/helpers.py:590-601 — 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) headroom/memory/adapters/fts5.py:74— headroom/memory/adapters/fts5.py:74-85 | headroom/memory/adapters/sqlite.py:83-96 — 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 (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:249-260 — 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 (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.
Duplicated block (12 lines × 2) crates/headroom-core/src/transforms/smart_crusher/planning.rs:306— crates/headroom-core/src/transforms/smart_crusher/planning.rs:306-317 | crates/headroom-core/src/transforms/smart_crusher/planning.rs:502-513 — 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-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.
Duplicated block (12 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:437— crates/headroom-proxy/src/bedrock/invoke.rs:437-448 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:829-840 — 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 15 separate duplicated blocks between them, totalling at least 353 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 × 2) crates/headroom-core/src/transforms/pipeline/orchestrator.rs:172— crates/headroom-core/src/transforms/pipeline/orchestrator.rs:172-183 | crates/headroom-core/src/transforms/pipeline/orchestrator.rs:232-243 — 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/ccr/tool_calls.py:42— headroom/ccr/tool_calls.py:42-52 | headroom/ccr/tool_calls.py:55-65 — 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/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:729— headroom/memory/adapters/hnsw.py:729-746 | 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) REDACTED:6119— REDACTED:6119-6129 | headroom/proxy/handlers/gemini.py:1585-1597 — 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:1585` 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 (11 lines × 2) REDACTED:6990— REDACTED:6990-7000 | REDACTED:9619-9629 — 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/helpers.py:833— headroom/proxy/helpers.py:833-843 | headroom/proxy/helpers.py:857-867 — 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:4236— headroom/transforms/content_router.py:4236-4246 | headroom/transforms/content_router.py:4642-4652 — 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/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.
Duplicated block (11 lines × 2) crates/headroom-core/src/transforms/pipeline/offloads/log_offload.rs:158— crates/headroom-core/src/transforms/pipeline/offloads/log_offload.rs:158-168 | crates/headroom-core/src/transforms/pipeline/offloads/search_offload.rs:124-134 — 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 (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.
Duplicated block (11 lines × 2) crates/headroom-proxy/src/proxy.rs:1331— crates/headroom-proxy/src/proxy.rs:1331-1341 | 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 4 separate duplicated blocks between them, totalling at least 45 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.
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.
Swallowed exception (empty catch) deploy/beacon/worker.js:159— `.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) deploy/beacon/worker.js:500— `.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) 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.
Swallowed exception (empty catch) headroom/onnx_runtime.py:284— 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/cli/wrap.py:2497— 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/cli/wrap.py:2502— 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/cli/wrap.py:2510— 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/cli/wrap.py:2514— 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/cli/wrap.py:2520— 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/cli/wrap.py:4371— 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/cli/update.py:311— 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.
headroom_core::transforms::diff_compressor::parse_diff (cyclomatic 30) crates/headroom-core/src/transforms/diff_compressor.rs:679— headroom_core::transforms::diff_compressor::parse_diff 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.
headroom_core::transforms::search_compressor::scan_marker (cyclomatic 25) crates/headroom-core/src/transforms/search_compressor.rs:812— 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::live_zone::compress_openai_responses_live_zone (cyclomatic 23) crates/headroom-core/src/transforms/live_zone.rs:2676— 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::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.
Duplicated block (13 lines × 2) headroom/cli/wrap.py:4702— headroom/cli/wrap.py:4702-4714 | headroom/cli/wrap.py:4743-4755 — 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/cli/wrap.py:4742` calls `stop_runtime` and `headroom/cli/wrap.py:4701` 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 × 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:202— headroom/pipeline.py:202-214 | 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:607— headroom/proxy/handlers/gemini.py:607-619 | REDACTED:3765-3777 — 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:607` 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:5725— REDACTED:5725-5737 | REDACTED:7198-7210 — 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:5725` 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:3504-3518 — 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:952— crates/headroom-core/src/transforms/live_zone.rs:952-964 | crates/headroom-core/src/transforms/live_zone.rs:2224-2236 — 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:235— crates/headroom-proxy/src/bedrock/invoke.rs:235-248 | 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 15 separate duplicated blocks between them, totalling at least 353 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 × 2) REDACTED:123— REDACTED:123-135 | examples/vertex_gemini_benchmark/benchmark.py:137-149 — 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: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.
D30 · Dependency Vulnerabilities· Medium CVE · ×11
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:4020— REDACTED:4020-4037 | REDACTED:5232-5248 — 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:4020` 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:1291— headroom/proxy/savings_tracker.py:1291-1307 | headroom/proxy/savings_tracker.py:1337-1353 — 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:171— headroom/storage/sqlite.py:171-187 | headroom/storage/sqlite.py:208-224 — 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:855— crates/headroom-core/src/transforms/diff_compressor.rs:855-871 | 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.
Duplicated block (17 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:382— crates/headroom-proxy/src/bedrock/invoke.rs:382-398 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:348-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 15 separate duplicated blocks between them, totalling at least 353 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 (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.
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.
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:389— headroom/providers/anthropic.py:389-403 | 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:5567— REDACTED:5567-5581 | REDACTED:7224-7238 — 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:5567` 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:8665— REDACTED:8665-8679 | REDACTED:9872-9886 — 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) REDACTED:11588— REDACTED:11588-11602 | REDACTED:11818-11832 — 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 lines × 2) headroom/transforms/compression_batches.py:333— headroom/transforms/compression_batches.py:333-347 | headroom/transforms/compression_batches.py:349-363 — 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:387-401 — 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.
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.
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.
headroom_proxy::proxy::forward_http (cyclomatic 64) crates/headroom-proxy/src/proxy.rs:499— 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:1544— 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 26) crates/headroom-proxy/src/bedrock/invoke_streaming.rs:122— headroom_proxy::bedrock::invoke_streaming::handle_invoke_streaming 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.
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 22) crates/headroom-proxy/src/bedrock/invoke.rs:133— headroom_proxy::bedrock::invoke::handle_invoke 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_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 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.
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:4865— # 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/proxy/handlers/gemini.py:1047— # 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 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 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.
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:11573— REDACTED:11573-11580 | REDACTED:11807-11814 — 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/proxy/savings_tracker.py:737— headroom/proxy/savings_tracker.py:737-744 | headroom/proxy/savings_tracker.py:2329-2336 — 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/cli/wrap.py:615— headroom/cli/wrap.py:615-622 | 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:268-276 — 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.
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.
Duplicated block (8 lines × 2) REDACTED:141— REDACTED:141-148 | examples/vertex_gemini_benchmark/benchmark.py:155-162 — 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 (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/embedders.py:800— headroom/memory/adapters/embedders.py:800-815 | headroom/memory/adapters/embedders.py:1033-1048 — 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 (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:6114— REDACTED:6114-6129 | 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:6114` 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:6113` 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:45— headroom/proxy/cost.py:45-60 | 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.
Duplicated block (16 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:564— crates/headroom-proxy/src/bedrock/invoke.rs:564-579 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:948-963 — 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 15 separate duplicated blocks between them, totalling at least 353 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 (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.
Duplicated block (18 lines × 2) headroom/cli/wrap.py:7542— headroom/cli/wrap.py:7542-7559 | headroom/cli/wrap.py:7808-7825 — 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:7542` 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:8951— headroom/cli/wrap.py:8951-8968 | headroom/cli/wrap.py:9008-9025 — 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/image/compressor.py:633— headroom/image/compressor.py:633-652 | headroom/image/compressor.py:654-671 — 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) headroom/providers/proxy_routes.py:401— headroom/providers/proxy_routes.py:401-418 | headroom/providers/proxy_routes.py:446-463 — 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:401` 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 lines × 2) REDACTED:8645— REDACTED:8645-8662 | REDACTED:9159-9176 — 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/transforms/content_router.py:7796— headroom/transforms/content_router.py:7796-7813 | headroom/transforms/content_router.py:7868-7885 — 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/content_router.py:7796` 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 (18 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:256— crates/headroom-proxy/src/bedrock/invoke.rs:256-273 | 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 15 separate duplicated blocks between them, totalling at least 353 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.
D4 · Code Duplication· Members sharing a duplicated core (4 members, 50+ identical tokens) · ×7
Members sharing a duplicated core (4 members, 50+ identical tokens) REDACTED:1214— REDACTED:1214-1223 | REDACTED:1229-1238 | REDACTED:1244-1253 | REDACTED:1259-1268 — 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:335— headroom/proxy/handlers/gemini.py:335-1138 | headroom/proxy/handlers/gemini.py:1144-1343 | headroom/proxy/handlers/gemini.py:1365-1610 | REDACTED:3317-5766 — 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:116-127 | scripts/version-sync.py:131-142 — 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.
Duplicated block (6 lines × 2) headroom/fsutil.py:99— headroom/fsutil.py:99-104 | headroom/install/state.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. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `headroom/fsutil.py:105` calls `exists`, `copymode` and `headroom/install/state.py:41` 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 (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) 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.
Duplicated block (6 lines × 2) headroom/memory/adapters/sqlite_graph.py:709— headroom/memory/adapters/sqlite_graph.py:709-714 | headroom/memory/adapters/sqlite_vector.py:894-899 — 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 (6 lines × 2) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:638— crates/headroom-core/src/transforms/smart_crusher/crusher.rs:638-643 | crates/headroom-core/src/transforms/smart_crusher/crusher.rs:647-653 — 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) crates/headroom-proxy/src/websocket.rs:181— crates/headroom-proxy/src/websocket.rs:181-186 | crates/headroom-proxy/src/websocket.rs:200-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.
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 (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/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:346— headroom/providers/anthropic.py:346-361 | 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:763— headroom/telemetry/toin.py:763-778 | headroom/telemetry/toin.py:1052-1066 — 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:1127— crates/headroom-proxy/src/proxy.rs:1127-1142 | crates/headroom-proxy/src/proxy.rs:1148-1162 — 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.
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 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 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/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:494— 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 69) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:1030— SmartCrusher::crush_mixed_array has cognitive complexity 69 (threshold 15). Drivers by points: if/else 12 (52 pts), loops 5 (15 pts), match/switch 1 (2 pts) (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.
SmartCrusher::crush_array_with_source (cognitive 22) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:838— 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:730— 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 (cognitive 18) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:335— SmartCrusher::execute_plan 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.
TooManyMethods: ContentRouter headroom/transforms/content_router.py:2445— TooManyMethods — 70 methods. The bar is 30 methods; this is 40 over it, 2.33× 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 — 42 methods. The bar is 30 methods; this is 12 over it, 1.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: SavingsTracker headroom/proxy/savings_tracker.py:948— 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: PrometheusMetrics headroom/proxy/prometheus_metrics.py:117— 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: OpenAIHandlerMixin REDACTED:1914— TooManyMethods — 31 methods. The bar is 30 methods; this is 1 over it, 1.03× 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.
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_store crates/headroom-core/src/transforms/diff_compressor.rs:275— MethodTooLong — compress_with_store runs 154 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 54 over it, 1.54× 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:494— 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:1283— 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
Duplicated block (19 lines × 2) headroom/backends/litellm.py:1310— headroom/backends/litellm.py:1310-1328 | headroom/backends/litellm.py:1834-1852 — 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:557-575 — 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) REDACTED:1261— REDACTED:1261-1279 | REDACTED:1302-1320 — 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.
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:963— REDACTED:963-974 | 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:270— headroom/proxy/gateway_turn.py:270-281 | headroom/proxy/gateway_turn.py:288-300 — 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:270` 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 (12–13 lines × 2) headroom/proxy/savings_tracker.py:2395— headroom/proxy/savings_tracker.py:2395-2407 | headroom/proxy/savings_tracker.py:2410-2421 — 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/savings_tracker.py:2395` 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/savings_tracker.py:2409` calls `round` and `headroom/proxy/savings_tracker.py:2422` 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–13 lines × 2) headroom/tokenizers/base.py:314— headroom/tokenizers/base.py:314-326 | headroom/tokenizers/base.py:333-344 — 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/tokenizers/base.py:314` 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:525-536 — 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:170— headroom/storage/sqlite.py:170-181 | headroom/storage/sqlite.py:207-218 | headroom/storage/sqlite.py:245-256 — 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.
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:1179— crates/headroom-core/src/transforms/diff_compressor.rs:1179-1188 | crates/headroom-core/src/transforms/log_compressor.rs:1671-1680 | crates/headroom-core/src/transforms/search_compressor.rs:938-947 — 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 (10 lines × 3) crates/headroom-core/src/transforms/smart_crusher/planning.rs:220— crates/headroom-core/src/transforms/smart_crusher/planning.rs:220-229 | crates/headroom-core/src/transforms/smart_crusher/planning.rs:409-418 | crates/headroom-core/src/transforms/smart_crusher/planning.rs:461-470 — 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/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:1339— crates/headroom-core/src/transforms/live_zone.rs:1339-1346 | crates/headroom-core/src/transforms/live_zone.rs:2357-2364 | crates/headroom-core/src/transforms/live_zone.rs:2407-2414 — 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) crates/headroom-core/src/transforms/live_zone.rs:1360— crates/headroom-core/src/transforms/live_zone.rs:1360-1368 | crates/headroom-core/src/transforms/live_zone.rs:2423-2430 | crates/headroom-core/src/transforms/live_zone.rs:2937-2944 — 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) 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.
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.
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:5372— REDACTED:5372-5397 | REDACTED:7168-7193 — 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:2443— headroom/proxy/savings_tracker.py:2443-2468 | headroom/proxy/savings_tracker.py:2476-2501 — 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:2475` calls `_normalize_agent`, `get` and `headroom/proxy/savings_tracker.py:2503` 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 (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:4878— REDACTED:4878-4890 | REDACTED:5397-5406 — 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:4878` 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:5409` calls `pop` and `REDACTED:4892` 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:1163— crates/headroom-proxy/src/proxy.rs:1163-1175 | 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 4 separate duplicated blocks between them, totalling at least 45 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.
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:1356— crates/headroom-core/src/transforms/live_zone.rs:1356-1362 | crates/headroom-core/src/transforms/live_zone.rs:2367-2373 | crates/headroom-core/src/transforms/live_zone.rs:2419-2425 — 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:1437— crates/headroom-core/src/transforms/live_zone.rs:1437-1443 | crates/headroom-core/src/transforms/live_zone.rs:2457-2463 | crates/headroom-core/src/transforms/live_zone.rs:2983-2989 — 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 × 2 locations) headroom/providers/opencode/hook-shim/handler.js:114— headroom/providers/opencode/hook-shim/handler.js:114 · headroom/providers/opencode/hook-shim/handler.js:124 — 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:255— sdk/typescript/src/utils/format.ts:255 · sdk/typescript/src/utils/format.ts:789 — 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:283— sdk/typescript/src/utils/format.ts:283 · sdk/typescript/src/utils/format.ts:619 — 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:503— sdk/typescript/src/utils/format.ts:503 · sdk/typescript/src/utils/format.ts:528 — 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) 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:286— sdk/typescript/src/client.ts:286 · sdk/typescript/src/client.ts:318 — 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:108— sdk/typescript/src/shared-context.ts:108 · sdk/typescript/src/shared-context.ts:123 — 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:170— sdk/typescript/src/utils/format.ts:170 · sdk/typescript/src/utils/format.ts:217 — 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 REDACTED: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:1283— 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:1509— 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:1222— 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::select_matches (cognitive 31) crates/headroom-core/src/transforms/search_compressor.rs:448— SearchCompressor::select_matches has cognitive complexity 31 (threshold 15). Drivers by points: if/else 11 (27 pts), loops 2 (3 pts), boolean chains 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.
SearchCompressor::score_matches (cognitive 29) crates/headroom-core/src/transforms/search_compressor.rs:393— 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:565— 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.
Duplicated block (26–28 lines × 2) headroom/models/registry.py:128— headroom/models/registry.py:128-155 | headroom/models/registry.py:420-445 — 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/registry.py:128` 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 (26–28 lines × 2) headroom/proxy/handlers/gemini.py:670— headroom/proxy/handlers/gemini.py:670-695 | headroom/proxy/handlers/gemini.py:1275-1302 — 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:8841— REDACTED:8841-8868 | REDACTED:8898-8923 — 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 (27 lines × 2) headroom/evals/memory/runner.py:608— headroom/evals/memory/runner.py:608-634 | headroom/evals/memory/runner_v2.py:907-933 — 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:608` 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:5963— REDACTED:5963-5989 | 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:5963` 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:5768— REDACTED:5768-5794 | REDACTED:6101-6127 — 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/cli/wrap.py:8450— headroom/cli/wrap.py:8450-8468 | headroom/cli/wrap.py:8895-8912 — 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:1148— headroom/proxy/handlers/gemini.py:1148-1165 | headroom/proxy/handlers/gemini.py:1375-1393 — 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 (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:8392— headroom/cli/wrap.py:8392-8402 | headroom/cli/wrap.py:8412-8423 — 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 (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:513— headroom/proxy/handlers/gemini.py:513-522 | headroom/proxy/handlers/gemini.py:840-851 — 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:494— 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 21) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:1030— SmartCrusher::crush_mixed_array 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.
SmartCrusherPlanner::plan_top_n (cognitive 26) crates/headroom-core/src/transforms/smart_crusher/planning.rs:234— 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:213— 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:95— 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:118— ClassTooLong — 535 significant lines (blank, comment-only and punctuation-only lines excluded, and inline test code — #[cfg(test)] modules and bare #[test] functions — not counted), 20 methods, 2 blocks, lines 118-1175. The bar is 400 significant lines; this is 135 over it, 1.34× 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.
Duplicated block (34–35 lines × 2) REDACTED:749— REDACTED:749-782 | 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:749` 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:749` 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:275— crates/headroom-proxy/src/bedrock/invoke.rs:275-309 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:246-279 — 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 15 separate duplicated blocks between them, totalling at least 353 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 (33–35 lines × 2) headroom/proxy/handlers/gemini.py:631— headroom/proxy/handlers/gemini.py:631-665 | headroom/proxy/handlers/gemini.py:1241-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/proxy/handlers/gemini.py:631` 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:259— headroom/proxy/prometheus_metrics.py:259-293 | headroom/proxy/prometheus_metrics.py:466-498 — 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–29 lines × 2) headroom/proxy/prometheus_metrics.py:1930— headroom/proxy/prometheus_metrics.py:1930-1958 | headroom/proxy/prometheus_metrics.py:1977-2000 — 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/prometheus_metrics.py:1977` 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 (24–29 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:507— crates/headroom-proxy/src/bedrock/invoke.rs:507-535 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:900-923 — 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 15 separate duplicated blocks between them, totalling at least 353 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 (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:353— crates/headroom-proxy/src/bedrock/invoke.rs:353-380 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:319-346 — 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 15 separate duplicated blocks between them, totalling at least 353 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 (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 (26–27 lines × 2) headroom/models/registry.py:170— headroom/models/registry.py:170-196 | headroom/models/registry.py:282-307 — 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/registry.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 (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 (24–25 lines × 2) headroom/backends/anyllm.py:451— headroom/backends/anyllm.py:451-474 | headroom/backends/litellm.py:1757-1781 — before extracting anything, compare `headroom/backends/anyllm.py` and `headroom/backends/litellm.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 74 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:1783` calls `close` and `headroom/backends/anyllm.py:476` 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–25 lines × 2) crates/headroom-core/src/transforms/live_zone.rs:2306— crates/headroom-core/src/transforms/live_zone.rs:2306-2330 | crates/headroom-core/src/transforms/live_zone.rs:2817-2840 — 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–23 lines × 2) headroom/providers/proxy_routes.py:422— headroom/providers/proxy_routes.py:422-442 | headroom/providers/proxy_routes.py:470-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 `headroom/providers/proxy_routes.py:422` 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 (21–23 lines × 2) REDACTED:4503— REDACTED:4503-4525 | REDACTED:5310-5330 — 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:4503` 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 lines × 2) headroom/proxy/memory_handler.py:1925— headroom/proxy/memory_handler.py:1925-1947 | headroom/proxy/memory_handler.py:1977-1999 — 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 after the matched lines, `headroom/proxy/memory_handler.py:2002` calls `replace` and `headroom/proxy/memory_handler.py:1950` 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 (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.
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.
Duplicated block (21 lines × 2) REDACTED:1703— REDACTED:1703-1723 | REDACTED:3803-3823 — 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:6268— REDACTED:6268-6288 | REDACTED:8279-8299 — 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:6268` 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) REDACTED:8600— REDACTED:8600-8616 | REDACTED:9102-9121 — 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:8600` 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:178— crates/headroom-proxy/src/bedrock/invoke.rs:178-197 | 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 15 separate duplicated blocks between them, totalling at least 353 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 (20 lines × 2) headroom/proxy/memory_handler.py:1787— headroom/proxy/memory_handler.py:1787-1806 | headroom/proxy/memory_handler.py:1971-1990 — 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.
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:2645— headroom/proxy/helpers.py:2645-2663 | headroom/proxy/helpers.py:2679-2693 — 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:2645` 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:1333— headroom/backends/litellm.py:1333-1350 | headroom/backends/litellm.py:1962-1977 — 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:824— headroom/proxy/handlers/gemini.py:824-841 | headroom/proxy/handlers/gemini.py:1511-1526 — 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:843` calls `replace` and `headroom/proxy/handlers/gemini.py:1527` 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:612— REDACTED:612-626 | REDACTED:662-678 — 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:612` 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:2466— crates/headroom-core/src/transforms/live_zone.rs:2466-2482 | crates/headroom-core/src/transforms/live_zone.rs:2992-3006 — 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) REDACTED:8476— REDACTED:8476-8491 | REDACTED:8975-8988 — 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 (15 lines × 3) headroom/models/registry.py:141— headroom/models/registry.py:141-156 | headroom/models/registry.py:296-310 | headroom/models/registry.py:432-446 — 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/models/registry.py:141` 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 × 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:1397-1411 — 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 × 2) headroom/memory/adapters/graph.py:419— headroom/memory/adapters/graph.py:419-433 | headroom/memory/adapters/sqlite_graph.py:595-608 — 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:5224— REDACTED:5224-5238 | REDACTED:6763-6776 — 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:481— headroom/proxy/handlers/gemini.py:481-494 | REDACTED:3630-3644 | REDACTED:6098-6111 — 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:3630` 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 (13–14 lines × 2) headroom/proxy/prometheus_metrics.py:1949— headroom/proxy/prometheus_metrics.py:1949-1962 | headroom/proxy/prometheus_metrics.py:2021-2033 — 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/prometheus_metrics.py:1949` 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 (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:673-684 — 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:669` 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 (13 lines × 3) REDACTED:1073— REDACTED:1073-1089 | REDACTED:3343-3355 | REDACTED:5798-5810 — 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:1067` calls `uuid4` and `REDACTED:3337` 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.
Duplicated block (10–11 lines × 2) headroom/backends/anyllm.py:230— headroom/backends/anyllm.py:230-240 | headroom/backends/anyllm.py:282-291 — 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:2277— crates/headroom-core/src/transforms/live_zone.rs:2277-2287 | crates/headroom-core/src/transforms/live_zone.rs:2772-2781 — 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–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:1426— headroom/proxy/handlers/gemini.py:1426-1434 | headroom/proxy/handlers/gemini.py:1525-1535 — 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:1214— REDACTED:1214-1223 | REDACTED:1229-1238 | REDACTED:1244-1253 | REDACTED:1259-1268 — 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:840— headroom/proxy/savings_tracker.py:840-848 | headroom/proxy/savings_tracker.py:874-883 — 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:1378— crates/headroom-core/src/transforms/live_zone.rs:1378-1387 | crates/headroom-core/src/transforms/live_zone.rs:2439-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.
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:285-290 — 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 (9 lines × 4) headroom/providers/anthropic.py:509— headroom/providers/anthropic.py:509-522 | headroom/providers/openai.py:385-393 | headroom/tokenizers/estimator.py:93-109 | headroom/tokenizers/tiktoken_counter.py:250-265 — 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:1559— crates/headroom-proxy/src/proxy.rs:1559-1567 | crates/headroom-proxy/src/proxy.rs:1636-1644 | crates/headroom-proxy/src/proxy.rs:1752-1760 | 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 4 separate duplicated blocks between them, totalling at least 45 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.
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:946— 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/adapters/gemini.ts:40— sdk/typescript/src/adapters/gemini.ts:40 · sdk/typescript/src/adapters/gemini.ts:58 — 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) 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) sdk/typescript/src/utils/format.ts:730— sdk/typescript/src/utils/format.ts:730 · sdk/typescript/src/utils/format.ts:766 — 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) sdk/typescript/src/client.ts:457— sdk/typescript/src/client.ts:457 · sdk/typescript/src/client.ts:468 — 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.
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:2001— 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.
AC6 · Visual & motion safety· Focus outline removed in CSS without a · ×1
Focus outline removed in CSS without a :focus replacement REDACTED:110— `#chart g.col:focus` sets the outline to none/0 and no visible :focus / :focus-visible style for that element replaces it in this stylesheet, so a keyboard user cannot see where focus is. Draw a focus ring (outline, box-shadow or border) under :focus-visible.
AC7 · A11y enforcement· Accessibility enforcement below the top rung · ×1
Accessibility enforcement below the top rung — No accessibility enforcement found — no a11y linter (eslint-plugin-jsx-a11y) and no axe/pa11y/Lighthouse in tests or CI. Start with the linter to catch issues at author time. What was searched, so you can tell an absence from a miss: the 13 markup file(s) this pass actually assessed, the linter configuration checked in beside them, and this repository's test and CI files — matched by name against the accessibility checkers this dimension carries. An audit run outside the repository, a hosted scanner, or a check whose name is not one of those, is not seen here.
AnthropicHandlerMixin.handle_anthropic_messages (cyclomatic 327) REDACTED:1034— AnthropicHandlerMixin.handle_anthropic_messages has cyclomatic complexity 327 (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 235) REDACTED:3313— OpenAIHandlerMixin.handle_openai_chat has cyclomatic complexity 235 (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 182) headroom/transforms/content_router.py:5982— ContentRouter.apply has cyclomatic complexity 182 (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:7253— 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._compress_openai_responses_live_text_units_with_router (cyclomatic 119) REDACTED:2207— OpenAIHandlerMixin._compress_openai_responses_live_text_units_with_router has cyclomatic complexity 119 (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 117) headroom/cli/wrap.py:4847— wrap._ensure_proxy_unlocked 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.
proxy.proxy (cyclomatic 115) headroom/cli/proxy.py:1156— proxy.proxy has cyclomatic complexity 115 (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.handle_openai_responses (cyclomatic 111) REDACTED:5768— OpenAIHandlerMixin.handle_openai_responses has cyclomatic complexity 111 (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.
REDACTED.dashboard (cyclomatic 107) headroom/dashboard/templates/dashboard.html:2055— REDACTED.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.
ContentRouter._apply_strategy_to_content (cyclomatic 91) headroom/transforms/content_router.py:4101— ContentRouter._apply_strategy_to_content has cyclomatic complexity 91 (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_generate_content (cyclomatic 85) headroom/proxy/handlers/gemini.py:328— GeminiHandlerMixin.handle_gemini_generate_content has cyclomatic complexity 85 (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 76) headroom/transforms/content_router.py:7478— ContentRouter._process_content_blocks has cyclomatic complexity 76 (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 73) REDACTED:10517— OpenAIHandlerMixin.handle_compress has cyclomatic complexity 73 (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.
LiteLLMBackend.stream_message (cyclomatic 65) headroom/backends/litellm.py:1373— LiteLLMBackend.stream_message has cyclomatic complexity 65 (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 57) headroom/transforms/code_compressor.py:1834— CodeAwareCompressor._compress_function_ast has cyclomatic complexity 57 (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:2059— 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:1524— 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.
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.
wrap.claude (cyclomatic 49) headroom/cli/wrap.py:6100— wrap.claude has cyclomatic complexity 49 (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:962— 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.
PrometheusMetrics.export (cyclomatic 47) headroom/proxy/prometheus_metrics.py:1402— PrometheusMetrics.export has cyclomatic complexity 47 (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.
cost.build_prefix_cache_stats (cyclomatic 46) headroom/proxy/cost.py:231— 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.
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.
helpers.relocate_system_messages_to_top_level (cyclomatic 43) headroom/proxy/helpers.py:1072— helpers.relocate_system_messages_to_top_level 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:4841— 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:5746— 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.
PrometheusMetrics.record_request (cyclomatic 42) headroom/proxy/prometheus_metrics.py:856— PrometheusMetrics.record_request 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:1376— 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.
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:8278— 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.
ContentRouter._compress_block_content (cyclomatic 40) headroom/transforms/content_router.py:7912— ContentRouter._compress_block_content has cyclomatic complexity 40 (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.
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.
helpers.strip_unsupported_tool_search_blocks (cyclomatic 38) headroom/proxy/helpers.py:4378— 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:645— 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:2879— 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._stream_response_inner (cyclomatic 37) REDACTED:1135— StreamingMixin._stream_response_inner 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:1787— 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.
server._build_agent_usage_summary (cyclomatic 36) REDACTED:329— 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:1268— 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:891— 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.
wrap.copilot (cyclomatic 35) headroom/cli/wrap.py:6700— 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.
SQLiteMemoryStore._build_query_conditions (cyclomatic 35) headroom/memory/adapters/sqlite.py:425— SQLiteMemoryStore._build_query_conditions 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.
StreamingMixin._finalize_stream_response (cyclomatic 35) REDACTED:791— StreamingMixin._finalize_stream_response 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.
wrap._start_proxy (cyclomatic 34) headroom/cli/wrap.py:749— wrap._start_proxy has cyclomatic complexity 34 (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.
helpers.enforce_cache_breakpoint_budget (cyclomatic 34) headroom/proxy/helpers.py:777— helpers.enforce_cache_breakpoint_budget 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.
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.
BaseTokenizer._count_content_parts (cyclomatic 34) headroom/tokenizers/base.py:246— BaseTokenizer._count_content_parts 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:1434— 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:7331— 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.
pr-governance.validate_pull_request (cyclomatic 33) scripts/pr-governance.py:171— pr-governance.validate_pull_request 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.
LiteLLMBackend._convert_messages_for_litellm (cyclomatic 32) headroom/backends/litellm.py:990— LiteLLMBackend._convert_messages_for_litellm 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.
SessionTrackerStore.resolve_tracker (cyclomatic 32) REDACTED:1771— 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.
wrap.opencode (cyclomatic 32) headroom/cli/wrap.py:8526— wrap.opencode 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.
OpenAIHandlerMixin.handle_passthrough (cyclomatic 32) REDACTED:11529— OpenAIHandlerMixin.handle_passthrough 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:295— 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.
settings_store._coerce (cyclomatic 32) headroom/settings_store.py:815— 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:1283— 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.
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.
StreamingMixin._continue_memory_tool_stream (cyclomatic 31) REDACTED:510— StreamingMixin._continue_memory_tool_stream 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.
outcome.emit_request_outcome (cyclomatic 31) REDACTED:478— outcome.emit_request_outcome 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.
format.vercelToOpenAI (cyclomatic 31) sdk/typescript/src/utils/format.ts:497— format.vercelToOpenAI has cyclomatic complexity 31 (threshold 15). Of this number, 24 points are the body's own statements and 7 belong to 4 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.
AnyLLMBackend.stream_message (cyclomatic 30) headroom/backends/anyllm.py:277— AnyLLMBackend.stream_message 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.
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:934— 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.
CodeAwareCompressor._compress_class_ast (cyclomatic 30) headroom/transforms/code_compressor.py:2104— CodeAwareCompressor._compress_class_ast 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.
REDACTED.renderChart (cyclomatic 30) REDACTED:435— REDACTED.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.
DirectMem0Adapter._save_memory_internal (cyclomatic 29) REDACTED:651— 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:4526— 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.
Mem0Backend.query (cyclomatic 28) headroom/memory/backends/mem0.py:543— 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:617— 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:10190— 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.
CodeAwareCompressor.compress (cyclomatic 28) headroom/transforms/code_compressor.py:1289— 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:878— 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:166— 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.
LiteLLMBackend.send_message (cyclomatic 27) headroom/backends/litellm.py:1247— LiteLLMBackend.send_message 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.
prefix_tracker.normalize_message_cache_control (cyclomatic 27) REDACTED:945— prefix_tracker.normalize_message_cache_control 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.
base.apply_to_messages (cyclomatic 27) headroom/proxy/interceptors/base.py:192— base.apply_to_messages 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.
MemoryHandler.search_and_format_context (cyclomatic 27) headroom/proxy/memory_handler.py:715— MemoryHandler.search_and_format_context 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.
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:659— 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:852— 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:1775— 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.
format.detectFormat (cyclomatic 26) sdk/typescript/src/utils/format.ts:34— format.detectFormat 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:848— 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:213— 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.
StreamingMixin._record_ccr_feedback_from_openai_sse (cyclomatic 25) REDACTED:718— StreamingMixin._record_ccr_feedback_from_openai_sse 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:2573— 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.
format.vercelMediaImageUrl (cyclomatic 25) sdk/typescript/src/utils/format.ts:394— format.vercelMediaImageUrl 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.
supervisors.install_supervisor (cyclomatic 24) REDACTED:448— 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:1140— 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.
GeminiHandlerMixin.handle_gemini_count_tokens (cyclomatic 24) headroom/proxy/handlers/gemini.py:1358— GeminiHandlerMixin.handle_gemini_count_tokens 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:11247— 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.
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.
TiktokenCounter.count_messages (cyclomatic 24) headroom/tokenizers/tiktoken_counter.py:278— TiktokenCounter.count_messages 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.
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:88— 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:1287— 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.
HeadroomClient._create (cyclomatic 23) headroom/client.py:394— HeadroomClient._create 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:864— 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.
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.
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.walk_cache_control (cyclomatic 23) headroom/proxy/helpers.py:556— 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:472— 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:1275— 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:60— 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:630— 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.
OpenCodePlugin._scan_session (cyclomatic 22) headroom/learn/plugins/opencode.py:213— OpenCodePlugin._scan_session 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:436— 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.save_memory (cyclomatic 22) headroom/memory/backends/local.py:232— LocalBackend.save_memory 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:422— 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.
counterfactual.resolve_rates (cyclomatic 22) headroom/pricing/counterfactual.py:400— counterfactual.resolve_rates 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.
anthropic._load_custom_model_config (cyclomatic 22) headroom/providers/anthropic.py:327— 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.
HeadroomProxy._retry_request (cyclomatic 22) REDACTED:2583— HeadroomProxy._retry_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.
server.run_server (cyclomatic 22) REDACTED:6500— 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:591— 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.
compression_units.compress_unit_with_router (cyclomatic 22) headroom/transforms/compression_units.py:221— compression_units.compress_unit_with_router 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.
mixed_content.split_into_sections (cyclomatic 22) headroom/transforms/mixed_content.py:108— mixed_content.split_into_sections 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.
format.geminiToOpenAI (cyclomatic 22) sdk/typescript/src/utils/format.ts:716— format.geminiToOpenAI has cyclomatic complexity 22 (threshold 15). Of this number, 13 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.
StreamingCCRHandler.process_stream (cyclomatic 21) headroom/ccr/response_handler.py:675— 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.
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.
MemoryToolStreamFilter._route (cyclomatic 21) headroom/proxy/memory_tool_stream.py:198— MemoryToolStreamFilter._route 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:1852— 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.
ContentRouter.eager_load_compressors (cyclomatic 21) headroom/transforms/content_router.py:5433— 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.
DiffCompressor::compress_with_store (cyclomatic 21) crates/headroom-core/src/transforms/diff_compressor.rs:275— DiffCompressor::compress_with_store 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.
format.openAIToVercel (cyclomatic 21) sdk/typescript/src/utils/format.ts:599— format.openAIToVercel has cyclomatic complexity 21 (threshold 15). Of this number, 19 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.
PrefixCacheTracker._estimate_message_tokens (cyclomatic 20) REDACTED:1566— 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.
BeforeAfterRunner._check_ground_truth_bfcl (cyclomatic 20) headroom/evals/runners/before_after.py:211— 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:559— 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:629— 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:1616— 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.
CostTracker.stats (cyclomatic 20) headroom/proxy/cost.py:1598— CostTracker.stats 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:775— 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:1028— 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:1298— 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.
helpers.count_cache_breakpoints (cyclomatic 20) headroom/proxy/helpers.py:429— helpers.count_cache_breakpoints 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._build_tool_name_map (cyclomatic 20) headroom/transforms/content_router.py:5763— ContentRouter._build_tool_name_map 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.
ReadMaturationManager._scan_activity (cyclomatic 20) headroom/transforms/read_maturation.py:274— ReadMaturationManager._scan_activity 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:262— 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:1077— 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:1192— 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.
supervisors.remove_supervisor (cyclomatic 19) REDACTED:696— 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.
HNSWVectorIndex._passes_filter (cyclomatic 19) headroom/memory/adapters/hnsw.py:683— 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:1940— 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.
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:5832— 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:1204— 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.
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.
format.openAIToGemini (cyclomatic 19) sdk/typescript/src/utils/format.ts:796— format.openAIToGemini has cyclomatic complexity 19 (threshold 15). Of this number, 17 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.
rollupHour (cyclomatic 19) deploy/beacon/worker.js:260— 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:907— 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:2003— 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.
ttl_estimator.estimate_ttls (cyclomatic 18) headroom/cache/ttl_estimator.py:71— ttl_estimator.estimate_ttls 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:2005— 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.
RequestTransformer.run (cyclomatic 18) headroom/proxy/gateway_turn.py:891— RequestTransformer.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.
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.
HeadroomProxy._start_kompress_background_warmup (cyclomatic 18) REDACTED:1986— HeadroomProxy._start_kompress_background_warmup 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:238— 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.
compaction_codec.expand_compacted (cyclomatic 18) headroom/transforms/compaction_codec.py:361— compaction_codec.expand_compacted 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.
ReadLifecycleManager._build_tool_metadata (cyclomatic 18) headroom/transforms/read_lifecycle.py:164— ReadLifecycleManager._build_tool_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.
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.
REDACTED.dashboard.renderTransformationCard (cyclomatic 18) headroom/dashboard/templates/dashboard.html:2292— REDACTED.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:1211— 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:918— 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:2660— 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:9256— 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.
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:750— 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:32— 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.
openai._drop_undeclared_web_search_calls (cyclomatic 17) REDACTED:1143— 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:2885— 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:3521— 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:4177— 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.
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:1081— 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.
compression_batches.compress_batch_with_router (cyclomatic 17) headroom/transforms/compression_batches.py:231— compression_batches.compress_batch_with_router 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.
ContentRouter.compress (cyclomatic 17) headroom/transforms/content_router.py:3109— 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:1214— 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_reasoning_openai_chat (cyclomatic 17) REDACTED:234— thinking_compactor.compact_reasoning_openai_chat 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:115— 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:450— 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:190— 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:104— 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.
wrap.unwrap_claude (cyclomatic 16) headroom/cli/wrap.py:6545— 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:1717— 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:754— 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.
conversation_savings.savings_conversation_key (cyclomatic 16) headroom/proxy/conversation_savings.py:68— conversation_savings.savings_conversation_key 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:122— 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:1117— 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:3163— 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.
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.
thinking_compactor.compact_thinking_to_text (cyclomatic 16) REDACTED:102— thinking_compactor.compact_thinking_to_text 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:234— 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.
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 593) REDACTED:1034— AnthropicHandlerMixin.handle_anthropic_messages has cognitive complexity 593 (threshold 15). Drivers by points: if/else 195 (377 pts), boolean chains 80, ternaries 26 (60 pts), error handling 28 (56 pts), loops 7 (20 pts) (nesting depth added 257). To reduce it, split the body into named stages: move each independent 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_chat (cognitive 445) REDACTED:3313— OpenAIHandlerMixin.handle_openai_chat has cognitive complexity 445 (threshold 15). Drivers by points: if/else 133 (267 pts), error handling 25 (59 pts), ternaries 27 (58 pts), boolean chains 57, loops 1 (4 pts) (nesting depth added 202). 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.apply (cognitive 414) headroom/transforms/content_router.py:5982— ContentRouter.apply has cognitive complexity 414 (threshold 15). Drivers by points: if/else 128 (310 pts), boolean chains 39, ternaries 13 (34 pts), loops 8 (18 pts), error handling 5 (13 pts) (nesting depth added 221). 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 319) headroom/cli/wrap.py:4847— wrap._ensure_proxy_unlocked has cognitive complexity 319 (threshold 15). Drivers by points: if/else 65 (227 pts), ternaries 11 (46 pts), boolean chains 40, error handling 3 (6 pts) (nesting depth added 200). 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_ws (cognitive 303) REDACTED:7253— 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 228) REDACTED:2207— OpenAIHandlerMixin._compress_openai_responses_live_text_units_with_router has cognitive complexity 228 (threshold 15). Drivers by points: if/else 62 (135 pts), loops 21 (41 pts), ternaries 14 (29 pts), boolean chains 21, error handling 2 (nesting depth added 108). 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 192) headroom/transforms/content_router.py:7478— ContentRouter._process_content_blocks has cognitive complexity 192 (threshold 15). Drivers by points: if/else 41 (141 pts), ternaries 7 (27 pts), boolean chains 23, loops 1 (nesting depth added 120). 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 170) REDACTED:5768— OpenAIHandlerMixin.handle_openai_responses has cognitive complexity 170 (threshold 15). Drivers by points: if/else 59 (100 pts), boolean chains 36, ternaries 11 (19 pts), error handling 7 (13 pts), loops 1 (2 pts) (nesting depth added 56). To reduce it, split the body into named stages: move each independent 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 166) headroom/proxy/handlers/gemini.py:328— GeminiHandlerMixin.handle_gemini_generate_content has cognitive complexity 166 (threshold 15). Drivers by points: if/else 63 (120 pts), boolean chains 14, error handling 7 (12 pts), ternaries 3 (11 pts), loops 3 (9 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.
ContentRouter._apply_strategy_to_content (cognitive 159) headroom/transforms/content_router.py:4101— ContentRouter._apply_strategy_to_content has cognitive complexity 159 (threshold 15). Drivers by points: if/else 51 (114 pts), boolean chains 20, ternaries 4 (13 pts), error handling 4 (12 pts) (nesting depth added 80). 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 126) headroom/transforms/code_compressor.py:1834— CodeAwareCompressor._compress_function_ast has cognitive complexity 126 (threshold 15). Drivers by points: if/else 38 (89 pts), loops 8 (27 pts), boolean chains 9, ternaries 1 (nesting depth added 70). 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 125) headroom/cli/proxy.py:1156— proxy.proxy has cognitive complexity 125 (threshold 15). Drivers by points: if/else 50 (55 pts), boolean chains 32, ternaries 26 (30 pts), error handling 6 (8 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.
helpers.enforce_cache_breakpoint_budget (cognitive 121) headroom/proxy/helpers.py:777— helpers.enforce_cache_breakpoint_budget has cognitive complexity 121 (threshold 15). Drivers by points: if/else 19 (89 pts), loops 5 (21 pts), boolean chains 8, ternaries 1 (3 pts) (nesting depth added 88). 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_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 104) headroom/backends/litellm.py:1373— LiteLLMBackend.stream_message has cognitive complexity 104 (threshold 15). Drivers by points: if/else 33 (65 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.
REDACTED.dashboard (cognitive 103) headroom/dashboard/templates/dashboard.html:2055— REDACTED.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.
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.
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.
OpenAIHandlerMixin.handle_compress (cognitive 91) REDACTED:10517— OpenAIHandlerMixin.handle_compress has cognitive complexity 91 (threshold 15). Drivers by points: if/else 32 (38 pts), ternaries 17 (28 pts), boolean chains 17, error handling 6 (8 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.
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:231— 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.
LiteLLMBackend._convert_messages_for_litellm (cognitive 86) headroom/backends/litellm.py:990— LiteLLMBackend._convert_messages_for_litellm has cognitive complexity 86 (threshold 15). Drivers by points: if/else 17 (65 pts), loops 4 (14 pts), boolean chains 4, ternaries 1 (3 pts) (nesting depth added 60). 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._parse_sse_usage_from_buffer (cognitive 86) REDACTED:295— 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.
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.
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:4378— 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.
ContentRouter._try_ml_compressor (cognitive 77) headroom/transforms/content_router.py:4841— 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 75) headroom/proxy/helpers.py:1072— helpers.relocate_system_messages_to_top_level has cognitive complexity 75 (threshold 15). Drivers by points: if/else 20 (43 pts), boolean chains 12, 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.
PrometheusMetrics.export (cognitive 75) headroom/proxy/prometheus_metrics.py:1402— PrometheusMetrics.export has cognitive complexity 75 (threshold 15). Drivers by points: loops 32 (61 pts), if/else 11, ternaries 3 (nesting depth added 29). 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.
HeadroomProxy.startup (cognitive 75) REDACTED:2059— 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:1524— 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:5746— 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:166— 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:6700— 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.
session._fold_extra (cognitive 64) REDACTED:1376— 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.
format.vercelToOpenAI (cognitive 64) sdk/typescript/src/utils/format.ts:497— format.vercelToOpenAI has cognitive complexity 64 (threshold 15). Drivers by points: if/else 16 (40 pts), ternaries 5 (16 pts), boolean chains 4, loops 2 (4 pts) (nesting depth added 37). Of this number, 54 points are the body's own statements and 10 belong to 4 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.
ToolIntelligenceNetwork.record_retrieval (cognitive 63) headroom/telemetry/toin.py:934— 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.
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.
wrap.claude (cognitive 62) headroom/cli/wrap.py:6100— wrap.claude has cognitive complexity 62 (threshold 15). Drivers by points: if/else 29 (38 pts), ternaries 6 (13 pts), boolean chains 7, error handling 3 (4 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.
BeforeAfterRunner._check_ground_truth_bfcl (cognitive 62) headroom/evals/runners/before_after.py:211— 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:962— 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.
ContentRouter._compress_block_content (cognitive 62) headroom/transforms/content_router.py:7912— ContentRouter._compress_block_content has cognitive complexity 62 (threshold 15). Drivers by points: if/else 24 (43 pts), boolean chains 12, 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.
SmartCrusher.apply (cognitive 62) headroom/transforms/smart_crusher.py:1275— 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.
ContentRouter._build_tool_name_map (cognitive 61) headroom/transforms/content_router.py:5763— ContentRouter._build_tool_name_map has cognitive complexity 61 (threshold 15). Drivers by points: if/else 12 (51 pts), loops 3 (6 pts), boolean chains 4 (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.
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:2879— 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.
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.
StreamingMixin._continue_memory_tool_stream (cognitive 59) REDACTED:510— StreamingMixin._continue_memory_tool_stream has cognitive complexity 59 (threshold 15). Drivers by points: if/else 14 (33 pts), loops 6 (15 pts), ternaries 3 (6 pts), boolean chains 4, error handling 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.
base.apply_to_messages (cognitive 59) headroom/proxy/interceptors/base.py:192— base.apply_to_messages has cognitive complexity 59 (threshold 15). Drivers by points: if/else 15 (38 pts), error handling 3 (10 pts), loops 4 (6 pts), boolean chains 3, ternaries 1 (2 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.
ContentRouter._cross_turn_dedup_messages (cognitive 59) headroom/transforms/content_router.py:7331— 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.
OpenAIHandlerMixin._ws_http_fallback (cognitive 58) REDACTED:10190— 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.
TiktokenCounter.count_messages (cognitive 58) headroom/tokenizers/tiktoken_counter.py:278— TiktokenCounter.count_messages has cognitive complexity 58 (threshold 15). Drivers by points: if/else 10 (43 pts), loops 4 (12 pts), boolean chains 3 (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.
CompressionStore.process_pending_feedback (cognitive 57) headroom/cache/compression_store.py:1077— 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.
format.openAIToVercel (cognitive 57) sdk/typescript/src/utils/format.ts:599— format.openAIToVercel has cognitive complexity 57 (threshold 15). Drivers by points: if/else 14 (37 pts), loops 3 (9 pts), error handling 2 (8 pts), ternaries 1 (3 pts) (nesting depth added 37). Of this number, 49 points are the body's own statements and 8 belong to one function literal 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.
prefix_tracker.normalize_message_cache_control (cognitive 56) REDACTED:945— prefix_tracker.normalize_message_cache_control has cognitive complexity 56 (threshold 15). Drivers by points: if/else 12 (30 pts), ternaries 5 (11 pts), boolean chains 8, loops 3 (7 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.
StreamingCCRHandler._reconstruct_openai_response (cognitive 56) headroom/ccr/response_handler.py:852— 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:645— 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:556— 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:262— 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.
AnyLLMBackend.stream_message (cognitive 55) headroom/backends/anyllm.py:277— AnyLLMBackend.stream_message has cognitive complexity 55 (threshold 15). Drivers by points: if/else 19 (43 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.
settings_store._coerce (cognitive 54) headroom/settings_store.py:815— 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:8278— 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.
helpers.strip_unsupported_ccr_retrieve_blocks (cognitive 53) headroom/proxy/helpers.py:4526— 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.
wrap._remove_claude_managed_hooks (cognitive 52) headroom/cli/wrap.py:1287— 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.
StreamingMixin._finalize_stream_response (cognitive 52) REDACTED:791— StreamingMixin._finalize_stream_response has cognitive complexity 52 (threshold 15). Drivers by points: if/else 13 (24 pts), boolean chains 16, ternaries 6 (12 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.
StreamingMixin._stream_response_inner (cognitive 52) REDACTED:1135— StreamingMixin._stream_response_inner has cognitive complexity 52 (threshold 15). Drivers by points: if/else 13 (20 pts), error handling 6 (13 pts), boolean chains 12, 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.
ToolIntelligenceNetwork._merge_patterns (cognitive 52) headroom/telemetry/toin.py:1434— 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.
format.openAIToGemini (cognitive 52) sdk/typescript/src/utils/format.ts:796— format.openAIToGemini has cognitive complexity 52 (threshold 15). Drivers by points: if/else 13 (36 pts), loops 3 (9 pts), error handling 1 (3 pts), ternaries 1 (3 pts), boolean chains 1 (nesting depth added 33). Of this number, 44 points are the body's own statements and 8 belong to one function literal 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.
PrometheusMetrics.record_request (cognitive 51) headroom/proxy/prometheus_metrics.py:856— PrometheusMetrics.record_request has cognitive complexity 51 (threshold 15). Drivers by points: if/else 20 (27 pts), boolean chains 15, loops 3 (5 pts), ternaries 3 (4 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.
content_detector._try_detect_structured_config (cognitive 51) headroom/transforms/content_detector.py:891— 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.
format.detectFormat (cognitive 51) sdk/typescript/src/utils/format.ts:34— format.detectFormat has cognitive complexity 51 (threshold 15). Drivers by points: if/else 11 (36 pts), boolean chains 11, loops 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.
helpers.count_cache_breakpoints (cognitive 50) headroom/proxy/helpers.py:429— helpers.count_cache_breakpoints has cognitive complexity 50 (threshold 15). Drivers by points: if/else 12 (37 pts), loops 2 (6 pts), ternaries 2 (4 pts), boolean chains 3 (nesting depth added 31). 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._build_agent_usage_summary (cognitive 50) REDACTED:329— 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:1771— 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:864— 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.
ContentRouter.eager_load_compressors (cognitive 47) headroom/transforms/content_router.py:5433— 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:1566— 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.
SQLiteMemoryStore._build_query_conditions (cognitive 46) headroom/memory/adapters/sqlite.py:425— SQLiteMemoryStore._build_query_conditions has cognitive complexity 46 (threshold 15). Drivers by points: if/else 24 (38 pts), loops 3 (6 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.
session._fold (cognitive 46) REDACTED:1268— 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.
CodeAwareCompressor._compress_class_ast (cognitive 46) headroom/transforms/code_compressor.py:2104— CodeAwareCompressor._compress_class_ast has cognitive complexity 46 (threshold 15). Drivers by points: if/else 17 (34 pts), boolean chains 6, loops 4 (6 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.
ReadMaturationManager._scan_activity (cognitive 46) headroom/transforms/read_maturation.py:274— ReadMaturationManager._scan_activity has cognitive complexity 46 (threshold 15). Drivers by points: if/else 10 (32 pts), loops 3 (6 pts), boolean chains 5, error handling 1 (3 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.
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.
LocalBackend.search_memories (cognitive 45) headroom/memory/backends/local.py:422— 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.
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.
prefix_tracker.overlay_cached_prefix (cognitive 44) REDACTED:659— 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:436— 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:327— 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.
OpenAIHandlerMixin.handle_passthrough (cognitive 43) REDACTED:11529— OpenAIHandlerMixin.handle_passthrough has cognitive complexity 43 (threshold 15). Drivers by points: if/else 16 (23 pts), boolean chains 9, error handling 5 (8 pts), loops 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.
base._build_tool_use_index (cognitive 43) headroom/proxy/interceptors/base.py:122— 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.
HeadroomProxy._retry_request (cognitive 43) REDACTED:2583— HeadroomProxy._retry_request has cognitive complexity 43 (threshold 15). Drivers by points: if/else 12 (32 pts), boolean chains 8, error handling 1 (2 pts), loops 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.
mixed_content.split_into_sections (cognitive 43) headroom/transforms/mixed_content.py:108— mixed_content.split_into_sections has cognitive complexity 43 (threshold 15). Drivers by points: if/else 8 (19 pts), loops 4 (9 pts), boolean chains 7, 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.
StreamingMixin._record_ccr_feedback_from_openai_sse (cognitive 42) REDACTED:718— StreamingMixin._record_ccr_feedback_from_openai_sse has cognitive complexity 42 (threshold 15). Drivers by points: if/else 11 (24 pts), boolean chains 6, 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.
SmartCrusher._extract_context_from_messages (cognitive 42) headroom/transforms/smart_crusher.py:1214— 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.
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.
HeadroomClient._create (cognitive 41) headroom/client.py:394— HeadroomClient._create has cognitive complexity 41 (threshold 15). Drivers by points: if/else 13 (29 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.
supervisors.install_supervisor (cognitive 41) REDACTED:448— 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.
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:1289— 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:878— 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.
format.geminiToOpenAI (cognitive 41) sdk/typescript/src/utils/format.ts:716— format.geminiToOpenAI has cognitive complexity 41 (threshold 15). Drivers by points: if/else 10 (27 pts), ternaries 2 (6 pts), boolean chains 4, loops 2 (4 pts) (nesting depth added 23). Of this number, 30 points are the body's own statements and 11 belong to 6 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.
rollupHour (cognitive 41) deploy/beacon/worker.js:260— 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.opencode (cognitive 40) headroom/cli/wrap.py:8526— wrap.opencode has cognitive complexity 40 (threshold 15). Drivers by points: if/else 20 (27 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, 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.
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:651— 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.
LocalBackend.save_memory (cognitive 40) headroom/memory/backends/local.py:232— LocalBackend.save_memory has cognitive complexity 40 (threshold 15). Drivers by points: if/else 13 (24 pts), loops 5 (11 pts), boolean chains 4, 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.
BaseTokenizer._count_content_parts (cognitive 40) headroom/tokenizers/base.py:246— 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.
pr-governance.validate_pull_request (cognitive 40) scripts/pr-governance.py:171— pr-governance.validate_pull_request has cognitive complexity 40 (threshold 15). Drivers by points: if/else 19 (25 pts), boolean chains 12, loops 3 (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.
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:675— 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.
LoCoMoEvaluatorV2._answer_question (cognitive 39) headroom/evals/memory/runner_v2.py:630— 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:1775— 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.
helpers.apply_session_sticky_memory_tools (cognitive 39) headroom/proxy/helpers.py:2573— 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.
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:1298— 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.
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.
DiffCompressor::compress_with_store (cognitive 38) crates/headroom-core/src/transforms/diff_compressor.rs:275— DiffCompressor::compress_with_store has cognitive complexity 38 (threshold 15). Drivers by points: if/else 18 (33 pts), loops 3 (4 pts), 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.
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.
wrap._start_proxy (cognitive 37) headroom/cli/wrap.py:749— wrap._start_proxy has cognitive complexity 37 (threshold 15). Drivers by points: if/else 26 (30 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.
Mem0Backend.query (cognitive 37) headroom/memory/backends/mem0.py:543— 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:1940— 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.
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:848— 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:617— 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.
outcome.emit_request_outcome (cognitive 36) REDACTED:478— outcome.emit_request_outcome has cognitive complexity 36 (threshold 15). Drivers by points: if/else 13 (16 pts), boolean chains 12, error handling 2 (4 pts), ternaries 4 (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.
compaction_codec.expand_compacted (cognitive 36) headroom/transforms/compaction_codec.py:361— compaction_codec.expand_compacted has cognitive complexity 36 (threshold 15). Drivers by points: if/else 9 (23 pts), error handling 2 (6 pts), loops 3 (4 pts), boolean chains 3 (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.
LiteLLMBackend.send_openai_message (cognitive 35) headroom/backends/litellm.py:1787— 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:2005— 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.
OpenCodePlugin._scan_session (cognitive 35) headroom/learn/plugins/opencode.py:213— OpenCodePlugin._scan_session has cognitive complexity 35 (threshold 15). Drivers by points: ternaries 5 (10 pts), if/else 5 (9 pts), error handling 3 (8 pts), boolean chains 7, 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.extract_tool_results_from_openai_messages (cognitive 35) headroom/memory/traffic_learner.py:1616— 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:472— 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:3791— 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:559— 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.
supervisors.remove_supervisor (cognitive 33) REDACTED:696— 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.
GeminiHandlerMixin.handle_gemini_count_tokens (cognitive 33) headroom/proxy/handlers/gemini.py:1358— GeminiHandlerMixin.handle_gemini_count_tokens has cognitive complexity 33 (threshold 15). Drivers by points: if/else 18 (25 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.
server.run_server (cognitive 33) REDACTED:6500— 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.
ReadLifecycleManager._build_tool_metadata (cognitive 33) headroom/transforms/read_lifecycle.py:164— ReadLifecycleManager._build_tool_metadata has cognitive complexity 33 (threshold 15). Drivers by points: if/else 7 (19 pts), boolean chains 6, loops 3 (5 pts), error handling 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.
HeadroomMCPServer._handle_stats (cognitive 32) headroom/ccr/mcp_server.py:912— 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.
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.
CostTracker.stats (cognitive 32) headroom/proxy/cost.py:1598— CostTracker.stats has cognitive complexity 32 (threshold 15). Drivers by points: if/else 13 (24 pts), loops 6, ternaries 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.
MemoryHandler.search_and_format_context (cognitive 32) headroom/proxy/memory_handler.py:715— MemoryHandler.search_and_format_context has cognitive complexity 32 (threshold 15). Drivers by points: if/else 15 (17 pts), ternaries 4 (6 pts), boolean chains 5, error handling 2 (3 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.
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:88— 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.
openai._openai_responses_to_sse (cognitive 31) REDACTED:1508— 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:2848— 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:591— 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:1140— 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.
HeadroomProxy._start_kompress_background_warmup (cognitive 30) REDACTED:1986— HeadroomProxy._start_kompress_background_warmup has cognitive complexity 30 (threshold 15). Drivers by points: if/else 9 (17 pts), error handling 3 (7 pts), boolean chains 3, loops 2 (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.
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 10 (20 pts), boolean chains 5, 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:60— 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:6545— 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:227— 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:1852— 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:238— 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:3109— 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.
thinking_compactor.compact_reasoning_openai_chat (cognitive 29) REDACTED:234— thinking_compactor.compact_reasoning_openai_chat has cognitive complexity 29 (threshold 15). Drivers by points: if/else 11 (22 pts), boolean chains 5, 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.
utils.extract_user_query (cognitive 29) REDACTED:64— utils.extract_user_query has cognitive complexity 29 (threshold 15). Drivers by points: if/else 6 (22 pts), loops 2 (5 pts), boolean chains 2 (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.
LiteLLMBackend.send_message (cognitive 28) headroom/backends/litellm.py:1247— LiteLLMBackend.send_message has cognitive complexity 28 (threshold 15). Drivers by points: if/else 16 (22 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.
compress.compress (cognitive 28) headroom/compress.py:213— 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:11247— 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.
format.vercelMediaImageUrl (cognitive 28) sdk/typescript/src/utils/format.ts:394— format.vercelMediaImageUrl has cognitive complexity 28 (threshold 15). Drivers by points: if/else 17 (19 pts), boolean chains 5, 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.
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:1556— 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:348— 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.
CodeAwareCompressor.should_apply (cognitive 27) headroom/transforms/code_compressor.py:2465— 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.
thinking_compactor.compact_thinking_to_text (cognitive 27) REDACTED:102— thinking_compactor.compact_thinking_to_text has cognitive complexity 27 (threshold 15). Drivers by points: if/else 9 (19 pts), boolean chains 4, loops 2 (3 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.
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:437— 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:629— 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.
conversation_savings.savings_conversation_key (cognitive 26) headroom/proxy/conversation_savings.py:68— conversation_savings.savings_conversation_key has cognitive complexity 26 (threshold 15). Drivers by points: if/else 10 (18 pts), loops 3 (6 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.
openai._codex_ws_text_shape (cognitive 26) REDACTED:775— 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.
MemoryToolStreamFilter._route (cognitive 26) headroom/proxy/memory_tool_stream.py:198— MemoryToolStreamFilter._route has cognitive complexity 26 (threshold 15). Drivers by points: if/else 13 (19 pts), boolean chains 5, 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.
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.
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.
update_check._select_latest (cognitive 26) REDACTED:153— update_check._select_latest has cognitive complexity 26 (threshold 15). Drivers by points: if/else 7 (14 pts), error handling 2 (6 pts), boolean chains 4, 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.
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:907— 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.
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:683— 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.
openai._responses_input_to_waste_messages (cognitive 25) REDACTED:1260— 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:3096— 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.
compression_units.compress_unit_with_router (cognitive 25) headroom/transforms/compression_units.py:221— compression_units.compress_unit_with_router has cognitive complexity 25 (threshold 15). Drivers by points: if/else 17 (21 pts), boolean chains 4 (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._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:5832— 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.
smoke_issue_327._drive_conversation (cognitive 25) scripts/smoke_issue_327.py:85— smoke_issue_327._drive_conversation has cognitive complexity 25 (threshold 15). Drivers by points: if/else 8 (15 pts), loops 3 (6 pts), boolean chains 2, 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.
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:190— 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:167— 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:249— 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.
install.install_status (cognitive 24) headroom/cli/install.py:1161— install.install_status has cognitive complexity 24 (threshold 15). Drivers by points: if/else 5 (10 pts), ternaries 3 (9 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.
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.
gateway_turn.shape_gateway_body (cognitive 24) headroom/proxy/gateway_turn.py:1182— 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:970— 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:1236— 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:3205— 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:360— 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.
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:350— 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.
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.
counterfactual.resolve_rates (cognitive 23) headroom/pricing/counterfactual.py:400— counterfactual.resolve_rates has cognitive complexity 23 (threshold 15). Drivers by points: if/else 10 (11 pts), boolean chains 9, ternaries 2 (3 pts) (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.
RequestTransformer.run (cognitive 23) headroom/proxy/gateway_turn.py:891— RequestTransformer.run has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (13 pts), boolean chains 8, 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.
helpers.inject_tool_search_deferral (cognitive 23) headroom/proxy/helpers.py:4177— 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.
MemoryHandler._init_backend_locked (cognitive 23) headroom/proxy/memory_handler.py:345— MemoryHandler._init_backend_locked has cognitive complexity 23 (threshold 15). Drivers by points: if/else 7 (11 pts), error handling 3 (8 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.
CodeAwareCompressor._analyze_symbol_importance (cognitive 23) headroom/transforms/code_compressor.py:1081— 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.
ContentRouter._compress_mixed (cognitive 23) headroom/transforms/content_router.py:3392— ContentRouter._compress_mixed has cognitive complexity 23 (threshold 15). Drivers by points: if/else 8 (15 pts), boolean chains 3, error handling 1 (3 pts), 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.
content_router._detect_content (cognitive 23) headroom/transforms/content_router.py:1204— 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:173— 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.
SemanticCacheLayer._extract_query (cognitive 22) headroom/cache/semantic.py:460— 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:3581— 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:658— 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:478— 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:754— AnthropicProvider.get_context_limit has cognitive complexity 22 (threshold 15). Drivers by points: if/else 9 (15 pts), boolean chains 4, 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:1028— 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:2885— 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.
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.
refresh_tool_hashes.main (cognitive 22) scripts/refresh_tool_hashes.py:35— refresh_tool_hashes.main has cognitive complexity 22 (threshold 15). Drivers by points: if/else 7 (19 pts), loops 2 (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.
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.
CompressionStore.store (cognitive 21) headroom/cache/compression_store.py:298— CompressionStore.store has cognitive complexity 21 (threshold 15). Drivers by points: if/else 14 (18 pts), boolean chains 2, 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.
init._ensure_claude_hooks (cognitive 21) REDACTED:206— 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.
CompressionMiddleware.__call__ (cognitive 21) headroom/integrations/asgi.py:90— CompressionMiddleware.__call__ has cognitive complexity 21 (threshold 15). Drivers by points: if/else 8 (13 pts), boolean chains 3, ternaries 1 (3 pts), error handling 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.
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:995— 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.
traffic_learner._project_for_pattern (cognitive 21) headroom/memory/traffic_learner.py:1717— 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.
extensions.install_all (cognitive 21) headroom/proxy/extensions.py:163— extensions.install_all has cognitive complexity 21 (threshold 15). Drivers by points: if/else 8 (12 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.
gateway_turn.normalize_usage (cognitive 21) headroom/proxy/gateway_turn.py:333— 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:3521— 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._extract_tool_calls (cognitive 21) headroom/proxy/memory_handler.py:1049— MemoryHandler._extract_tool_calls has cognitive complexity 21 (threshold 15). Drivers by points: if/else 8 (19 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.
MemoryHandler.handle_memory_tool_calls (cognitive 21) headroom/proxy/memory_handler.py:1085— MemoryHandler.handle_memory_tool_calls has cognitive complexity 21 (threshold 15). Drivers by points: if/else 7 (12 pts), boolean chains 5, 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.
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.
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:317— 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.
repro_codex_replay.warmup_probe (cognitive 21) scripts/repro_codex_replay.py:176— repro_codex_replay.warmup_probe has cognitive complexity 21 (threshold 15). Drivers by points: if/else 5 (10 pts), error handling 5 (8 pts), 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.
REDACTED.renderChart (cognitive 21) REDACTED:435— REDACTED.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.
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:2003— 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:233— 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.
compression_store._create_default_ccr_backend (cognitive 20) headroom/cache/compression_store.py:1211— 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:104— 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.
wrap._warn_proxy_mode_mismatch (cognitive 20) headroom/cli/wrap.py:9256— 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:524— 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.
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.
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.
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:141— 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:1007— 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:270— 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:1923— 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:2367— 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:266— 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:240— 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.
StreamingCCRHandler._openai_response_to_chunks (cognitive 19) headroom/ccr/response_handler.py:954— StreamingCCRHandler._openai_response_to_chunks has cognitive complexity 19 (threshold 15). Drivers by points: if/else 7 (12 pts), boolean chains 3, loops 2 (3 pts), ternaries 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:474— 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:1192— 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:582— 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:2660— 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:8781— 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:891— 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:750— 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.
Mem0Backend._ensure_client (cognitive 19) headroom/memory/backends/mem0.py:114— 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:271— 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:767— 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:1143— 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:1443— 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:3163— 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.
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:114— 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.
repro_codex_replay._ws_client (cognitive 19) scripts/repro_codex_replay.py:254— repro_codex_replay._ws_client has cognitive complexity 19 (threshold 15). Drivers by points: error handling 7 (10 pts), if/else 3 (6 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.
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.
format.vercelMediaPart (cognitive 19) sdk/typescript/src/utils/format.ts:450— format.vercelMediaPart has cognitive complexity 19 (threshold 15). Drivers by points: if/else 10 (13 pts), boolean chains 4, 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, 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.
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:619— 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:2136— 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:3083— 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:1204— 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.
HNSWVectorIndex.index_batch (cognitive 18) headroom/memory/adapters/hnsw.py:434— HNSWVectorIndex.index_batch has cognitive complexity 18 (threshold 15). Drivers by points: if/else 8 (12 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.
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:153— 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:202— 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:32— 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.
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:1117— 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:806— 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:2659— 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.
compression_batches.compress_batch_with_router (cognitive 18) headroom/transforms/compression_batches.py:231— compression_batches.compress_batch_with_router has cognitive complexity 18 (threshold 15). Drivers by points: if/else 10 (12 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.
changelog-gen.generate_changelog (cognitive 18) scripts/changelog-gen.py:131— changelog-gen.generate_changelog has cognitive complexity 18 (threshold 15). Drivers by points: if/else 7 (12 pts), loops 4 (6 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.
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.
ContextTracker._calculate_relevance (cognitive 17) headroom/ccr/context_tracker.py:318— 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:621— 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.
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:767— 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:201— 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._ensure_serena_dashboard_disabled (cognitive 17) headroom/cli/wrap.py:2250— wrap._ensure_serena_dashboard_disabled has cognitive complexity 17 (threshold 15). Drivers by points: if/else 10 (13 pts), error handling 2, ternaries 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.
wrap._kill_proxy_by_pid (cognitive 17) headroom/cli/wrap.py:4352— 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.
HeadroomClient.__init__ (cognitive 17) headroom/client.py:264— HeadroomClient.__init__ has cognitive complexity 17 (threshold 15). Drivers by points: if/else 11 (16 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._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.
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:661— 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:59— 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:582— 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:211— 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:819— 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._hydrate_persisted_state (cognitive 17) headroom/memory/traffic_learner.py:1362— 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:193— 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.
BedrockHandlerMixin.handle_bedrock_invoke (cognitive 17) headroom/proxy/handlers/bedrock.py:58— BedrockHandlerMixin.handle_bedrock_invoke has cognitive complexity 17 (threshold 15). Drivers by points: if/else 8 (11 pts), error handling 3 (4 pts), boolean chains 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.
openai._lift_codex_additional_tools (cognitive 17) REDACTED:950— 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:227— 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.
ToolIntelligenceNetwork.import_patterns (cognitive 17) headroom/telemetry/toin.py:1374— ToolIntelligenceNetwork.import_patterns has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (16 pts), loops 1 (nesting depth added 10). 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.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.
ConfigCompressor.compress (cognitive 17) headroom/transforms/config_compressor.py:125— 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:681— 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.
recursive_json.route_embedded_json (cognitive 17) headroom/transforms/recursive_json.py:238— recursive_json.route_embedded_json has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (11 pts), boolean chains 3, loops 2, 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.
changelog-gen.parse_commits (cognitive 17) scripts/changelog-gen.py:84— changelog-gen.parse_commits has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (11 pts), boolean chains 3, 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.
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:196— 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:115— 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:346— 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:2003— 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:2285— 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.
doctor.check_savings (cognitive 16) headroom/cli/doctor.py:918— 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.
wrap._remove_headroom_installed_serena_mcp (cognitive 16) headroom/cli/wrap.py:2825— 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.
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.
runtime.stop_runtime (cognitive 16) headroom/install/runtime.py:566— runtime.stop_runtime has cognitive complexity 16 (threshold 15). Drivers by points: if/else 9 (14 pts), error handling 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.
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.
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:230— 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:1877— 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:156— 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.
GatewayTurn.finish (cognitive 16) headroom/proxy/gateway_extension.py:157— GatewayTurn.finish has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (10 pts), boolean chains 3, 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.
gateway_turn._usage_in_shape (cognitive 16) headroom/proxy/gateway_turn.py:1499— 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:896— 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:6286— 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.
helpers._read_request_body_bytes (cognitive 16) headroom/proxy/helpers.py:3264— 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:4721— 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:209— 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:25— 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:201— 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:1718— 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:3582— 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.
cross_turn_dedup.dedup_blocks (cognitive 16) headroom/transforms/cross_turn_dedup.py:231— cross_turn_dedup.dedup_blocks has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (11 pts), loops 2 (3 pts), boolean chains 1, 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.
ReadLifecycleManager.apply (cognitive 16) headroom/transforms/read_lifecycle.py:114— 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:315— 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.
eval_output_shaper.main (cognitive 16) scripts/eval_output_shaper.py:120— eval_output_shaper.main has cognitive complexity 16 (threshold 15). Drivers by points: if/else 5 (7 pts), loops 5 (7 pts), boolean chains 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.
REDACTED.dashboard.renderTransformationCard (cognitive 16) headroom/dashboard/templates/dashboard.html:2292— REDACTED.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.
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:400— 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.
D22 · Internal API Consistency· Redundant operations with nearly identical signatures. `run_case_sequence` appears to be a wrapper around `run_cases` that adds a `label` parameter, likely for logging or grouping. This creates confusion about which method to use for a single batch of cases versus a labeled group, especially since the core logic is identical. · ×1
Redundant operations with nearly identical signatures. `run_case_sequence` appears to be a wrapper around `run_cases` that adds a `label` parameter, likely for logging or grouping. This creates confusion about which method to use for a single batch of cases versus a labeled group, especially since the core logic is identical. — Remove `run_case_sequence` and add an optional `label: str | None` parameter to `run_cases`. This unifies the API into a single entry point for executing test cases. (signatures: e2e._lib.harness.run_cases(cases: list[Case], headroom_bin: str, fail_fast: bool): int | e2e._lib.harness.run_case_sequence(cases: list[Case], headroom_bin: str, label: str, fail_fast: bool): int)
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.
D30 · Dependency Vulnerabilities· Medium advisory (unmaintained) · ×1
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:1334— crates/headroom-core/src/transforms/live_zone.rs:1334-1508 | crates/headroom-core/src/transforms/live_zone.rs:2405-2493 | crates/headroom-core/src/transforms/live_zone.rs:2892-3020 — 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 (194 shared lines) crates/headroom-proxy/src/bedrock/invoke.rs:142— crates/headroom-proxy/src/bedrock/invoke.rs:142-448 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:131-491 — These two members are variants of one another: 194 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 (64 shared lines) headroom/backends/litellm.py:1252— headroom/backends/litellm.py:1252-1371 | headroom/backends/litellm.py:1792-2001 — These two members are variants of one another: 64 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:328— headroom/providers/anthropic.py:328-426 | 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· Edited copy of a member (40 corresponding lines) · ×1
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.
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:973-1032 | headroom/cli/wrap.py:7452-7484 | REDACTED:1083-1133 | headroom/proxy/prometheus_metrics.py:893-1235 | 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.
Duplicated block (30–70 lines × 2) headroom/models/registry.py:80— headroom/models/registry.py:80-109 | headroom/models/registry.py:201-270 — 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/registry.py:80` 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 (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 (54–59 lines × 2) headroom/backends/litellm.py:1252— headroom/backends/litellm.py:1252-1310 | headroom/backends/litellm.py:1378-1431 — 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 (52–55 lines × 2) headroom/proxy/helpers.py:974— headroom/proxy/helpers.py:974-1028 | headroom/proxy/helpers.py:1240-1291 — 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:3960— REDACTED:3960-3992 | REDACTED:5081-5125 — 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:3960` 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 (39–43 lines × 2) REDACTED:3334— REDACTED:3334-3372 | REDACTED:5789-5831 — 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 (35–40 lines × 2) REDACTED:225— REDACTED:225-259 | headroom/memory/backends/mem0.py:138-177 — 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 (32–38 lines × 2) REDACTED:1466— REDACTED:1466-1503 | REDACTED:3580-3611 — 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:1466` 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 × 2) REDACTED:5021— REDACTED:5021-5058 | REDACTED:5530-5562 — 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:5021` 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:688— headroom/memory/adapters/hnsw.py:688-723 | 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:263— headroom/memory/bridge_parsers.py:263-297 | headroom/memory/bridge_parsers.py:384-409 — 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:410` calls `startswith` and `headroom/memory/bridge_parsers.py:299` 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 (19–35 lines × 2) REDACTED:1968— REDACTED:1968-1986 | REDACTED:2047-2081 — 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 (34 lines × 2) headroom/memory/bridge_parsers.py:297— headroom/memory/bridge_parsers.py:297-330 | headroom/memory/bridge_parsers.py:412-445 — 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:410` calls `startswith` and `headroom/memory/bridge_parsers.py:296` 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 (28–33 lines × 2) REDACTED:1613— REDACTED:1613-1645 | REDACTED:3746-3773 — 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:1613` 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:1646` calls `_finalize_pre_upstream` and `REDACTED:3774` 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 (32–33 lines × 2) headroom/proxy/handlers/gemini.py:463— headroom/proxy/handlers/gemini.py:463-494 | REDACTED:3612-3644 — 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 (12–32 lines × 2) headroom/backends/anyllm.py:81— headroom/backends/anyllm.py:81-92 | headroom/backends/litellm.py:995-1026 — before extracting anything, compare `headroom/backends/anyllm.py` and `headroom/backends/litellm.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 74 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:3670— REDACTED:3670-3701 | REDACTED:4737-4763 — 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:3670` 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–31 lines × 2) REDACTED:4466— REDACTED:4466-4496 | REDACTED:5280-5307 — 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 (27–31 lines × 2) REDACTED:5787— REDACTED:5787-5813 | REDACTED:5813-5843 — 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 (31 lines × 2) REDACTED:8408— REDACTED:8408-8438 | REDACTED:8806-8836 — 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 (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 (29 lines × 2) REDACTED:6368— REDACTED:6368-6396 | 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 (24–28 lines × 2) headroom/memory/adapters/hnsw.py:583— headroom/memory/adapters/hnsw.py:583-610 | 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 (27–28 lines × 2) headroom/proxy/helpers.py:3408— headroom/proxy/helpers.py:3408-3435 | headroom/proxy/helpers.py:3454-3480 — 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 after the matched lines, `headroom/proxy/helpers.py:3481` calls `dumps`, `encode` and `headroom/proxy/helpers.py:3436` 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–27 lines × 3) headroom/models/registry.py:144— headroom/models/registry.py:144-167 | headroom/models/registry.py:338-364 | headroom/models/registry.py:447-473 — 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/models/registry.py:144` 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 (25–27 lines × 3) headroom/proxy/handlers/batch.py:69— headroom/proxy/handlers/batch.py:69-95 | headroom/proxy/handlers/gemini.py:362-386 | REDACTED:3358-3384 — 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 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–27 lines × 2) REDACTED:11156— REDACTED:11156-11182 | REDACTED:11198-11220 — 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:11156` 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–26 lines × 3) headroom/models/registry.py:130— headroom/models/registry.py:130-153 | headroom/models/registry.py:184-209 | headroom/models/registry.py:422-443 — 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/models/registry.py:130` 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–25 lines × 3) headroom/models/registry.py:93— headroom/models/registry.py:93-114 | headroom/models/registry.py:118-139 | headroom/models/registry.py:227-251 — 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/models/registry.py:93` 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 (20–24 lines × 4) headroom/models/registry.py:106— headroom/models/registry.py:106-125 | headroom/models/registry.py:158-178 | headroom/models/registry.py:394-417 | headroom/models/registry.py:435-458 — 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 `headroom/models/registry.py:106` 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–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 (17–24 lines × 2) headroom/proxy/handlers/gemini.py:708— headroom/proxy/handlers/gemini.py:708-731 | REDACTED:4331-4347 — 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 (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 (20–23 lines × 2) headroom/backends/litellm.py:1352— headroom/backends/litellm.py:1352-1371 | headroom/backends/litellm.py:1979-2001 — 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–23 lines × 2) REDACTED:1353— REDACTED:1353-1375 | REDACTED:3502-3516 — 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:1353` 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 × 3) REDACTED:5831— REDACTED:5831-5852 | REDACTED:6171-6192 | REDACTED:6316-6337 — 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:5831` 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–22 lines × 2) headroom/providers/proxy_routes.py:334— headroom/providers/proxy_routes.py:334-352 | headroom/providers/proxy_routes.py:355-376 — 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:355` 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 (18–22 lines × 2) REDACTED:1570— REDACTED:1570-1591 | REDACTED:3711-3728 — 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:1570` 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:7620— headroom/transforms/content_router.py:7620-7630 | headroom/transforms/content_router.py:7714-7735 — 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:6222— REDACTED:6222-6242 | 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:6222` 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 (20–21 lines × 2) REDACTED:11660— REDACTED:11660-11680 | REDACTED:11857-11876 — 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:11660` 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:11856` calls `send`, `except` and `REDACTED:11660` 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 (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 (16–20 lines × 2) REDACTED:2552— REDACTED:2552-2567 | REDACTED:2571-2590 — 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:2552` 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 × 3) REDACTED:2086— REDACTED:2086-2100 | REDACTED:2186-2200 | REDACTED:2367-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.
Duplicated block (17–19 lines × 2) REDACTED:5508— REDACTED:5508-5524 | REDACTED:6847-6865 — 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:6847` 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:1303— headroom/backends/litellm.py:1303-1320 | headroom/backends/litellm.py:1424-1441 | headroom/backends/litellm.py:1827-1844 | headroom/backends/litellm.py:2037-2054 — 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:1322` calls `debug` and `headroom/backends/litellm.py:2058` 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:1360— REDACTED:1360-1377 | REDACTED:3503-3518 | REDACTED:5900-5917 — 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 after the matched lines, `REDACTED:3523` calls `apply_to_tags` and `REDACTED:5923` 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 (14–18 lines × 3) REDACTED:2132— REDACTED:2132-2145 | REDACTED:2185-2198 | REDACTED:2366-2383 — 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:2132` 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:412— headroom/providers/anthropic.py:412-426 | 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:319— headroom/release_version.py:319-336 | headroom/release_version.py:341-357 — 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:319` 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:293— headroom/backends/anyllm.py:293-306 | headroom/backends/litellm.py:1261-1277 | headroom/backends/litellm.py:1391-1406 — before extracting anything, compare `headroom/backends/anyllm.py` and `headroom/backends/litellm.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 74 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:1261` 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:4955— headroom/cli/wrap.py:4955-4967 | headroom/cli/wrap.py:5119-5135 — 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:666— REDACTED:666-682 | REDACTED:755-766 — 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:461— headroom/cache/semantic.py:461-472 | headroom/client.py:659-674 — 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:1005-1019 | headroom/cli/wrap.py:7470-7484 | REDACTED:1116-1130 | headroom/proxy/prometheus_metrics.py:1218-1232 | 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 (15 lines × 5) headroom/models/registry.py:155— headroom/models/registry.py:155-169 | headroom/models/registry.py:279-297 | headroom/models/registry.py:352-366 | headroom/models/registry.py:391-409 | headroom/models/registry.py:461-475 — all 5 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/models/registry.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 (14–15 lines × 4) headroom/proxy/handlers/gemini.py:628— headroom/proxy/handlers/gemini.py:628-642 | headroom/proxy/handlers/gemini.py:1238-1251 | headroom/proxy/handlers/gemini.py:1468-1481 | REDACTED:3937-3950 — 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:645` calls `_gemini_contents_to_messages` and `headroom/proxy/handlers/gemini.py:1482` 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 (14–15 lines × 3) REDACTED:8643— REDACTED:8643-8657 | REDACTED:9157-9171 | REDACTED:9457-9470 — 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:8643` 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:3975— REDACTED:3975-3987 | REDACTED:5107-5120 | REDACTED:2286-2296 — 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:3975` 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 (4–14 lines × 3) headroom/evals/batch_compression_eval.py:1247— headroom/evals/batch_compression_eval.py:1247-1250 | headroom/evals/core.py:412-425 | headroom/evals/runners/before_after.py:484-497 — 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:412` 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 (13 lines × 4) REDACTED:2131— REDACTED:2131-2143 | REDACTED:2184-2196 | REDACTED:2229-2241 | REDACTED:2292-2304 — 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:2131` 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–13 lines × 3) headroom/backends/anyllm.py:249— headroom/backends/anyllm.py:249-257 | headroom/backends/anyllm.py:299-307 | REDACTED:1759-1771 — 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 (11–13 lines × 2) REDACTED:6018— REDACTED:6018-6030 | 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:6018` 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–13 lines × 3) headroom/proxy/prometheus_metrics.py:1513— headroom/proxy/prometheus_metrics.py:1513-1525 | headroom/proxy/prometheus_metrics.py:1527-1539 | headroom/proxy/prometheus_metrics.py:1540-1545 — 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:1513` calls `_format_labels` and `headroom/proxy/prometheus_metrics.py:1540` 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 (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:116-127 | scripts/version-sync.py:131-142 — 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 (11–12 lines × 3) REDACTED:5990— REDACTED:5990-6000 | 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:5990` 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:6000` 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 (8–12 lines × 2) REDACTED:4550— REDACTED:4550-4561 | REDACTED:5355-5362 — 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:4550` 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 (11 lines × 6) 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:1399-1409 | REDACTED:11812-11822 — there are 6 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 6 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. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `REDACTED:11811` calls `pop` and `headroom/proxy/handlers/batch.py:551` 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 (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 (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.
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:731— headroom/proxy/savings_tracker.py:731-739 | headroom/proxy/savings_tracker.py:1885-1890 — 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–9 lines × 2) headroom/tokenizers/base.py:441— headroom/tokenizers/base.py:441-449 | headroom/tokenizers/tiktoken_counter.py:334-340 — 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–9 lines × 2) headroom/transforms/content_router.py:7099— headroom/transforms/content_router.py:7099-7107 | headroom/transforms/content_router.py:7110-7117 — 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/content_router.py:7099` 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 (7–8 lines × 3) REDACTED:330— REDACTED:330-337 | headroom/cache/openai.py:486-492 | REDACTED:2041-2047 — 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 × 3) headroom/proxy/savings_tracker.py:736— headroom/proxy/savings_tracker.py:736-741 | headroom/proxy/savings_tracker.py:1887-1892 | headroom/proxy/savings_tracker.py:2328-2334 — 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:741` calls `_coerce_float`, `get` and `headroom/proxy/savings_tracker.py:2334` 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 (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 (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 (36–43 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:587— crates/headroom-proxy/src/bedrock/invoke.rs:587-629 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:977-1012 — 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 15 separate duplicated blocks between them, totalling at least 353 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 (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.
Duplicated block (37–41 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:311— crates/headroom-proxy/src/bedrock/invoke.rs:311-351 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:281-317 — 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 15 separate duplicated blocks between them, totalling at least 353 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 (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.
Duplicated block (24–32 lines × 2) crates/headroom-core/src/transforms/smart_crusher/crusher.rs:155— crates/headroom-core/src/transforms/smart_crusher/crusher.rs:155-178 | crates/headroom-core/src/transforms/smart_crusher/crusher.rs:388-419 — 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 (23–29 lines × 2) crates/headroom-core/src/transforms/live_zone.rs:1340— crates/headroom-core/src/transforms/live_zone.rs:1340-1368 | crates/headroom-core/src/transforms/live_zone.rs:2408-2430 — 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–27 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:143— crates/headroom-proxy/src/bedrock/invoke.rs:143-169 | 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 15 separate duplicated blocks between them, totalling at least 353 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–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.
Duplicated block (19–23 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:483— crates/headroom-proxy/src/bedrock/invoke.rs:483-505 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:880-898 — 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 15 separate duplicated blocks between them, totalling at least 353 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–20 lines × 2) crates/headroom-proxy/src/bedrock/invoke.rs:408— crates/headroom-proxy/src/bedrock/invoke.rs:408-427 | crates/headroom-proxy/src/bedrock/invoke_streaming.rs:408-420 — 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 15 separate duplicated blocks between them, totalling at least 353 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 (10–19 lines × 3) crates/headroom-core/src/transforms/live_zone.rs:1070— crates/headroom-core/src/transforms/live_zone.rs:1070-1088 | crates/headroom-core/src/transforms/live_zone.rs:2309-2318 | crates/headroom-core/src/transforms/live_zone.rs:2819-2828 — 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 (16–17 lines × 2) crates/headroom-proxy/src/main.rs:204— crates/headroom-proxy/src/main.rs:204-220 | 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.
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.
Duplicated block (6–8 lines × 2) crates/headroom-proxy/src/proxy.rs:1321— crates/headroom-proxy/src/proxy.rs:1321-1328 | crates/headroom-proxy/src/vertex/raw_predict.rs:415-420 — 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 4 separate duplicated blocks between them, totalling at least 45 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.
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.
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 (22–24 lines × 2) examples/strands_bedrock_demo.py:277— examples/langchain_demo/mock_tools.py:92-113 | examples/strands_bedrock_demo.py:277-300 — 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.
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 — plugins/openclaw/ runs vitest but declares no coverage provider, so the suite can run and still produce no lcov — add `@vitest/coverage-v8` (or `@vitest/coverage-istanbul`) as a devDependency. 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. Alternatively, commit the lcov/Cobertura report your CI produces and it is read without a re-run.
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 REDACTED: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/**`, `REDACTED`, but those tests also depend on `sdk/typescript` (e.g. `sdk/typescript/vitest.config.ts`, `sdk/typescript/tsup.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 (338 matched lines × 2 locations) · ×1
Duplicated block with local edits (338 matched lines × 2 locations) headroom/providers/opencode/hook-shim/handler.js:66— headroom/providers/opencode/hook-shim/handler.js:66 · plugins/opencode/src/transport.ts:141 — the two spans are one implementation copied and then locally edited — 2376 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 (51 lines × 2 locations) plugins/openclaw/src/tools/headroom-retrieve.ts:12— plugins/openclaw/src/tools/headroom-retrieve.ts:12 · plugins/opencode/src/retrieve.ts:25 — 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.
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.
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.
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:125— sdk/typescript/src/client.ts:125 · sdk/typescript/src/client.ts:186 — 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 (11 lines × 3 locations) sdk/typescript/src/utils/format.ts:234— sdk/typescript/src/utils/format.ts:234 · sdk/typescript/src/utils/format.ts:548 · sdk/typescript/src/utils/format.ts:769 — all 3 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 × 2 locations) sdk/typescript/src/client.ts:358— sdk/typescript/src/client.ts:358 · sdk/typescript/src/client.ts:374 — 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.
Duplicated block (7 lines × 4 locations) sdk/typescript/src/utils/format.ts:181— sdk/typescript/src/utils/format.ts:181 · sdk/typescript/src/utils/format.ts:231 · sdk/typescript/src/utils/format.ts:519 · sdk/typescript/src/utils/format.ts:545 — 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.
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.
Duplicated block (5 lines × 2 locations) sdk/typescript/src/client.ts:470— sdk/typescript/src/client.ts:470 · sdk/typescript/src/client.ts:486 — 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.
Complex function vercelMediaImageUrl (cyclomatic 30, cognitive 34) sdk/typescript/src/utils/format.ts:394— vercelMediaImageUrl has cyclomatic complexity 30 and cognitive complexity 34; 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 detectFormat (cyclomatic 26, cognitive 52) sdk/typescript/src/utils/format.ts:34— detectFormat has cyclomatic complexity 26 and cognitive complexity 52; 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 vercelToOpenAI (cyclomatic 24, cognitive 70) sdk/typescript/src/utils/format.ts:497— vercelToOpenAI has cyclomatic complexity 24 and cognitive complexity 70; 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 openAIToVercel (cyclomatic 21, cognitive 51) sdk/typescript/src/utils/format.ts:599— openAIToVercel has cyclomatic complexity 21 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 vercelMediaPart (cyclomatic 20, cognitive 24) sdk/typescript/src/utils/format.ts:450— vercelMediaPart has cyclomatic complexity 20 and cognitive complexity 24; 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 19, cognitive 46) sdk/typescript/src/utils/format.ts:796— openAIToGemini has cyclomatic complexity 19 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 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:262— 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:260— 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:166— 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:115— 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 (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:400— 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 anthropicMediaBlock (cyclomatic 14, cognitive 14) sdk/typescript/src/utils/format.ts:144— 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 geminiToOpenAI (cyclomatic 13, cognitive 34) sdk/typescript/src/utils/format.ts:716— geminiToOpenAI has cyclomatic complexity 13 and cognitive complexity 34; 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.
R3 · Large Files· sdk/typescript/src/utils/format.ts · ×1
sdk/typescript/src/utils/format.ts: 801 lines of code sdk/typescript/src/utils/format.ts:1— sdk/typescript/src/utils/format.ts has 801 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: 571 lines of code plugins/opencode/src/transport.ts:1— plugins/opencode/src/transport.ts has 571 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: 536 lines of code sdk/typescript/src/client.ts:1— sdk/typescript/src/client.ts has 536 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.
deploy/beacon/worker.js: 477 lines of code deploy/beacon/worker.js:1— deploy/beacon/worker.js has 477 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.
R3 · Large Files· headroom/providers/opencode/hook-shim/handler.js · ×1
headroom/providers/opencode/hook-shim/handler.js: 451 lines of code headroom/providers/opencode/hook-shim/handler.js:1— headroom/providers/opencode/hook-shim/handler.js has 451 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 (17 application, 12 tooling, 38 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:233— `_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 279, cleared at line 283) and the `DISABLE_PROMPT_CACHING_OPUS` environment variable (set at line 284, cleared at line 287) and the `ENABLE_PROMPT_CACHING_1H` environment variable (set at line 288, cleared at line 292) — 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.
README/code drift CONTRIBUTING.md:132— CONTRIBUTING.md names `AGENTS.md`, but no file or folder `AGENTS.md` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift README.md:552— README.md documents the environment variable `HF_ENDPOINT`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift README.md:562— README.md documents the environment variable `ORT_STRATEGY`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift README.md:563— README.md documents the environment variable `ORT_LIB_LOCATION`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift README.md:564— README.md documents the environment variable `ORT_PREFER_DYNAMIC_LINK`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift README.md:613— README.md names `AGENTS.md`, but no file or folder `AGENTS.md` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/claude-code-bedrock-headroom.md:89— docs/claude-code-bedrock-headroom.md documents the environment variable `ANTHROPIC_DEFAULT_SONNET_MODEL`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/claude-code-bedrock-headroom.md:90— docs/claude-code-bedrock-headroom.md documents the environment variable `ANTHROPIC_DEFAULT_OPUS_MODEL`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/claude-code-bedrock-headroom.md:91— docs/claude-code-bedrock-headroom.md documents the environment variable `ANTHROPIC_DEFAULT_HAIKU_MODEL`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/context-mode-integration-analysis.md:58— docs/context-mode-integration-analysis.md names `src/adapters/types.ts`, but no file or folder `src/adapters/types.ts` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/context-mode-integration-analysis.md:59— docs/context-mode-integration-analysis.md names `src/adapters/detect.ts`, but no file or folder `src/adapters/detect.ts` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/context-mode-integration-analysis.md:74— docs/context-mode-integration-analysis.md documents the environment variable `SHELL_ESCAPE_PATTERNS`, but no code, script or configuration file names it. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/context-mode-integration-analysis.md:139— docs/context-mode-integration-analysis.md names `headroom/lean_ctx/installer.py`, but no file or folder `headroom/lean_ctx/installer.py` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/context-mode-integration-analysis.md:139— docs/context-mode-integration-analysis.md names `headroom/rtk/installer.py`, but no file or folder `headroom/rtk/installer.py` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/context-mode-integration-analysis.md:209— docs/context-mode-integration-analysis.md names `tests/security/`, but no file or folder `tests/security` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/context-mode-integration-analysis.md:324— docs/context-mode-integration-analysis.md names `app/middleware/`, but no file or folder `app/middleware` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/context-mode-integration-analysis.md:324— docs/context-mode-integration-analysis.md names `app/routes/`, but no file or folder `app/routes` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/context-mode-integration-analysis.md:324— docs/context-mode-integration-analysis.md names `app/services/`, but no file or folder `app/services` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/context-mode-integration-analysis.md:324— docs/context-mode-integration-analysis.md names `app/models.py`, but no file or folder `app/models.py` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift plugins/opencode/README.md:116— plugins/opencode/README.md names `headroom/claude-sonnet-4-6`, but no file or folder `headroom/claude-sonnet-4-6` exists. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/content/docs/anthropic-sdk.mdx:62— docs/content/docs/anthropic-sdk.mdx links to `/docs/proxy#message-format`, but `docs/proxy` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/content/docs/api-reference.mdx:118— docs/content/docs/api-reference.mdx links to `/docs/troubleshooting#compression-too-aggressive`, but `docs/troubleshooting` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/content/docs/architecture.mdx:44— docs/content/docs/architecture.mdx links to `/docs/proxy#cloud-providers`, but `docs/proxy` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/content/docs/architecture.mdx:77— docs/content/docs/architecture.mdx links to `/docs/text-and-logs`, but `docs/text-and-logs` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
README/code drift docs/content/docs/architecture.mdx:94— docs/content/docs/architecture.mdx links to `/docs/cache-optimization`, but `docs/cache-optimization` does not exist. Checked without a model against the repository: its files and folders, the scripts and dependencies of every package.json, the projects, namespaces, package references and target frameworks of the .NET build, the SDK and Node pins, and the identifiers of every file that is not a document; the documents' own text never counts. A footprint generated at build time, read only by a platform, or living outside this repository is not seen, and this row is then wrong.
Interpolated log message defeats structured logging headroom/backends/litellm.py:307— `info` at line 307 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/backends/litellm.py:309— `warning` at line 309 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/backends/litellm.py:887— `info` at line 887 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/backends/litellm.py:901— `info` at line 901 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/backends/litellm.py:1322— `debug` at line 1322 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/backends/litellm.py:1341— `error` at line 1341 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/backends/litellm.py:1774— `error` at line 1774 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/backends/litellm.py:1846— `debug` at line 1846 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/backends/litellm.py:1898— `debug` at line 1898 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/backends/litellm.py:1970— `error` at line 1970 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/backends/litellm.py:2078— `error` at line 2078 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/backends/anyllm.py:63— `info` at line 63 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/backends/anyllm.py:262— `debug` at line 262 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/backends/anyllm.py:274— `error` at line 274 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/backends/anyllm.py:467— `error` at line 467 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/backends/anyllm.py:501— `debug` at line 501 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/backends/anyllm.py:560— `error` at line 560 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/backends/anyllm.py:635— `error` at line 635 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/cache/google.py:484— `debug` at line 484 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/cache/google.py:504— `info` at line 504 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/cache/google.py:537— `debug` at line 537 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/cache/google.py:586— `warning` at line 586 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/cache/google.py:592— `info` at line 592 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/cache/google.py:615— `info` at line 615 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/cache/google.py:647— `info` at line 647 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.
Duplicated predicate headroom/providers/opencode/hook-shim/handler.js:304— `!parts.url || !shouldRoute(parts.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:75— `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:174— `isRoutableUpstream(url, proxy, excludeHosts) && isLlmEndpointPath(url.pathname)` 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:139— `normalized === "localhost" || normalized === "127.0.0.1" || normalized === "::1"` 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:156— `pathname.endsWith("/chat/completions") || pathname.endsWith("/responses") || pathname.endsWith("/messages") || pathname.endsWith(":generateC…` 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:268— `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:260— `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:249— `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:159— `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:575— `"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:8817— `_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:6383— `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:104— `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:5380— `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:4594— `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 REDACTED:1917— `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.
Duplicated predicate REDACTED:1936— `compressor and hasattr(compressor, "close")` 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:1199— `content_length and int(content_length) > MAX_REQUEST_BODY_SIZE` appears character-identically in 4 files — REDACTED, headroom/proxy/handlers/batch.py, headroom/proxy/handlers/gemini.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/transforms/compression_batches.py:244— `deadline_started_at is not None and not router.share_request_deadline(deadline_started_at)` appears character-identically in 2 files — headroom/transforms/compression_batches.py, headroom/transforms/compression_units.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.
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:481— `_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:246— `_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:409— `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:93— `_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/wrap.py:1531— `_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:4433— `_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:1187— `_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:136— `_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:1695— `_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:74— `_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:81— `_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 on parse failure headroom/proxy/persistent_metrics.py:90— `_coerce_signed_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 on parse failure headroom/proxy/savings_attribution.py:223— `event_count` returns `1` 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:540— `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:629— `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:683— `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:1455— `_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:374— `_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/proxy/compress_turn.py:146— `_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 REDACTED:1784— `_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:218— `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.
Silent fallback default in catch headroom/proxy/route_advice.py:226— `_provider_of` 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.
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/providers/omp/runtime.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 sdk/typescript/src/shared-context.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/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/errors.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 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 sdk/typescript/src/adapters/gemini.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.
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 REDACTED:201— `debug` at line 201 is called with an argument built by `sorted(payload.keys())` (line 201), 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:764— `debug` at line 764 is called with an argument built by `sorted(values.keys())` (line 764), 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:929— `debug` at line 929 is called with an argument built by `sorted(allowed)` (line 932), 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:7562— `debug` at line 7562 is called with an argument built by `[k for k in upstream_headers if k.lower() != "…"]` (line 7564), 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 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/transforms/content_router.py:3951— `debug` at line 3951 is called with an argument built by `"…".join(map(str, out.warnings))` (line 3952), 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, 86 significant file(s) lose their only recent owner: headroom/evals/batch_compression_eval.py, crates/headroom-proxy/src/compression/live_zone_anthropic.rs, crates/headroom-core/src/transforms/tag_protector.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 (+78 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: 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.
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.
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:1179— 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.
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.
D16 · Bus Factor· Further sole-owners (lower concentration) · ×1
Further sole-owners (lower concentration) — 13 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 (122 single-owned of 668 analysed files in total, counted over production source files of roughly 2,400 bytes or more, excluding vendored, generated and example/demo trees and test files identified by path convention, largest first; 668 of the 824 production source files in this repository met that bar). They are anonymized user #4 (2 file(s)), anonymized user #5 (2 file(s)), anonymized user #6 (2 file(s)), anonymized user #7 (2 file(s)), anonymized user #8 (1 file(s)), anonymized user #9 (1 file(s)) (+7 more) — spread or document their files in the same way, at lower priority than the named off-boarding risks above. The files folded here: crates/headroom-core/src/transforms/text_crusher/crusher.rs, benchmarks/i18n_compression_eval.py, headroom/cache/ttl_estimator.py, headroom/proxy/conversation_savings.py, headroom/proxy/stage_timer.py, headroom/proxy/debug_introspection.py, headroom/memory/inline_extractor.py, headroom/proxy/malloc_trim.py (+9 more).
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)` (257279 LoC, 1405 module-visible types across 86 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.
D28 · Secrets (history)· Rotate the exposed credentials · ×1
D34 · Knowledge Freshness· Orphaned files with no living knowledge · ×1
Orphaned files with no living knowledge — 9 of 668 analysed file(s) have no living knowledge left — their last meaningful change has decayed away, so if one breaks, no one currently understands it (counted over production source files of roughly 2,400 bytes or more, excluding vendored, generated and example/demo trees and test files identified by path convention, largest first; 668 of the 824 production source files in this repository met that bar). None is large enough to earn a read-through of its own, so this row stands in for the per-file rows rather than raising one each — most significant first: scripts/build_python_release_smoke.py, headroom/providers/omp/runtime.py, headroom/memory/qdrant_env.py, sdk/typescript/src/shared-context.ts, scripts/release_smoke_all.py, sdk/typescript/src/errors.ts, headroom/providers/grok_build/config.py, sdk/typescript/src/hooks.ts (and 1 more). 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.
P10 · Library API & versioning· Large public API surface · ×1
Large public API surface — 257/334 types (77%) declared in the published library are public. For a library, every public type is a stability contract — keep implementation types off the surface and expose only the intended API.
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`.
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 (`!`) reduce the strict null checking score — ~0.4 `!` null assertions per 1k TypeScript source lines — 3 assertion(s) across the 8274 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.
Subsumed condition operand crates/headroom-core/src/auth_mode.rs:172— `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.12.0 but 1.13.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-config` and commit the updated Cargo.lock.
Outdated: aws-credential-types — `aws-credential-types` is locked at 1.3.0 but 1.3.1 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-credential-types` and commit the updated Cargo.lock.
Outdated: aws-sigv4 — `aws-sigv4` is locked at 1.6.0 but 1.6.3 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 Cargo.lock.
Outdated: aws-smithy-runtime-api — `aws-smithy-runtime-api` is locked at 1.19.0 but 1.19.1 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 Cargo.lock.
Outdated: cc — `cc` is locked at 1.8.0 but 1.10.0 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 Cargo.lock.
Outdated: crc32fast — `crc32fast` is locked at 1.5.2 but 1.5.3 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 Cargo.lock.
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 Cargo.lock.
Outdated: redis — `redis` is locked at 1.7.1 but 1.8.0 is the current stable release on crates.io, and it already satisfies the `"1.6"` requirement declared in crates/headroom-core/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p redis` and commit the updated Cargo.lock.
Outdated: rustls-native-certs — `rustls-native-certs` is locked at 0.8.4 but 0.8.5 is the current stable release on crates.io, and it already satisfies the `"0.8"` requirement declared in crates/headroom-proxy/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p rustls-native-certs` and commit the updated Cargo.lock.
Outdated: sha2 — `sha2` is locked at 0.11.0 but 0.11.1 is the current stable release on crates.io, and it already satisfies the `"0.11"` requirement declared in crates/headroom-core/Cargo.toml — so the lockfile is behind this repository's own declared range. Run `cargo update -p sha2` and commit the updated Cargo.lock.
Outdated: tokio — `tokio` is locked at 1.53.3 but 1.54.1 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 tokio` and commit the updated Cargo.lock.
Outdated: uuid — `uuid` is locked at 1.28.0 but 1.29.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 uuid` and commit the updated Cargo.lock.
Outdated: webpki-roots — `webpki-roots` is locked at 1.0.10 but 1.0.11 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 Cargo.lock.
Skipped (documented): (unnamed test) plugins/openclaw/test/advancement-key-store.test.ts:222— 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:249— 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:272— 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 1 file(s) — `docs/components/mdx.tsx` — 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 01a171ab-a4d1-7351-b4b7-5b398828a1bf · every finding is also locatable in findings.md, and the complete scoring record (with exit codes + durations) in sidecar.json.
Issues: 258 · Warnings: 1769 · Recommendations: 203 · Info: 16 — Appendix A · all findings · full markdown report.
Generated by Watchdog — deterministic code-health analysis. 25-10-2026 @ 06:07 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.