Skip to content

perf: Halve the cold consumer-reachability gate - #5305

Merged
Sinity merged 3 commits into
masterfrom
fix/w7-devtools-gate-cost
Sep 20, 2026
Merged

Sinity merged 3 commits into
masterfrom
fix/w7-devtools-gate-cost

Conversation

@Sinity

@Sinity Sinity commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Summary

Three beads: polylogue-uohdp (new mechanism, measured), polylogue-r2lud and polylogue-olw5e (already landed at head — residual tests plus one route).

Cold consumer-reachability gate: 25.6s → 12.3s, with byte-identical output proven by a differential harness. All six touched files are OUT of the derived schema closure.

The measurement, taken as a same-head pair

An earlier pair straddled #5299/#5300/#5301 and was discarded. Both arms below are the same tree at the same head; the base arm reverts this commit's three files from origin/master.

total wall consumer-reachability
base 239.42s 25.6s
head 224.19s 12.3s

Gate alone, cache cleared before each: base 25.12 / 24.34 / 24.58, head 12.50 / 12.67 / 12.42. Warm is unchanged at 0.26s both ways — the existing content-digest cache already served it; only the cold path moved.

Total-wall delta (−15.2s) exceeds the gate delta (−13.3s) purely because test-collection varied between runs. The gate-level number is the evidence.

The bead's diagnosis was partly wrong

It attributed the cost to re-parsing every source file with no caching. A fresh partition of the cold path (1,295 modules, 16,286 nodes) measured: ast.parse 3.0s, call-graph edge indexing 9.9s, reachability traversal 6.7s, a second full parse for the module-import closure 3.7s. Parsing was 6.7s of 23.5s. A cross-process content-digest cache also already existed.

So the fix is four equivalence-preserving changes, no new cache and no new cached verdict: reuse the modules the call graph already parsed; walk the union of entrypoints in one BFS (the tuple names polylogue.cli twice and most entries reach the same component); collect a function's imports and calls in one body scan instead of two structurally identical visitors; hoist per-function rebuilds to module level.

AC2–AC5 asked for a per-file content-hash fact cache. I did not build it, and this is a decision with a measurement rather than a silent omission: parsing is 3.0s of 23.5s, and the dominant edge indexing depends on the global node set so it is not per-file cacheable. If that judgment is wrong the bead should stay open with this measurement attached — it should not be closed silently on this commit.

The bead's historical 101s-of-214s figure no longer describes this gate. The quick set's dominant cost today is test-collection at 88–98s.

Equivalence proof

Both implementations loaded in one process over the same live tree: reachable symbols 18,662, reachable modules 1,180, graph nodes 16,286, and the full edge map all identical. Compute 24.12s → 11.79s (2.05x). reachable_from matched for 40 randomly sampled roots.

r2lud and olw5e — already landed

mypy_gate.py already takes an exclusive flock on a shared cache; the prior tests faked _git_common_dir and subprocess.run, so nothing exercised contention. Added a test with a real checkout plus a linked worktree and a stub checker claiming exclusive entry.

Four concurrent lanes against the warm shared cache all exit 0, completing at +0.75 / +1.28 / +1.84 / +2.37s versus 0.78s single-lane — a ~0.55s stagger, the signature of strict serialization. Cold-cache variant not measured: clearing the shared cache would have disrupted live sibling workers.

olw5e's AC3 premise was wrong — verify_population_coverage.py walks no denominator, so there was no re-walk to replace. The real gap was that the coverage route could not see the real source population at all without a live archive. census_constructs() now classifies through the same classifiers the source.db inventory uses (extracted so the two evidence sources cannot drift into two coverage policies), and resolve_census() raises for an absent, unreadable, foreign or bounded census rather than producing an empty construct list that would read as full coverage.

Verification

devtools verify --quick exit 0, all 22 gates. devtools render all --check exit 0, out of sync count 0. devtools test tests/unit/devtools: 1121 passed, 5 failed.

Four anti-vacuity mutations run and reverted, each proven red.

Inherited failures — all five reproduce on clean master

Proven on a detached origin/master worktree with its own venv: three test_cli_acceptance.py reflow-ratchet failures (root-help and read-help exceed recorded baselines at widths 40/60/80), one test_verify_provider_completeness.py (grok-export/export-json@v1 is partial, schema_package missing), and one intermittent test_pytest_slot.py telemetry-sidecar flake that asserts peak pss_kib > 0 for a child exiting immediately against a 0.5s sampler.

Environment note

uv sync --extra dev --frozen prunes the audit group and removes grimp, making devtools gate layering fail with grimp_unavailable. The correct incantation is uv sync --extra dev --group audit --frozen (audit is a [dependency-groups] entry, not an extra). Every number above was measured with grimp present and layering green.

🤖 Generated with Claude Code

https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq

Sinity and others added 3 commits September 20, 2026 23:03
…ylogue-uohdp)

The cold `devtools gate consumer-reachability` walked the production tree
more times than the answer needs. A fresh partition of the cold gate
(1,295 production modules, 16,322 graph nodes) showed the historical
"re-parses every file" framing was only part of it:

  ast.parse                      3.0s
  call-graph edge indexing       9.9s
  reachability traversal         6.7s
  a second full ast.parse for
  the module-import closure      3.7s

Four equivalence-preserving changes, none of which adds a cache or a new
verdict:

- `_import_reachable_modules` takes the modules the call graph already
  parsed instead of re-reading and re-parsing the same 1,295 files.
- `reachable_from_any` walks the union of the entrypoints in one BFS.
  The entrypoint tuple has ten entries that almost all reach the same
  component, and names `polylogue.cli` twice. Reachability distributes
  over union, so the result is unchanged.
- One `_BodyScanner` collects a function's imports and its calls in a
  single walk; the two former visitors had an identical traversal rule.
- `_index_prefixes` stores frozensets, and the shadow scanner is a module
  level class, so neither is rebuilt per function.

Verification, on this checkout at 0d02434:

- Differential harness running origin/master's modules and this branch's
  in one process over the real tree: reachable symbols (18,700), reachable
  modules (1,180), graph nodes (16,322) and the full edge map are all
  identical; 24.54s -> 11.25s.
- Gate wall clock, cold cache: 25.011s before, 12.07/12.10/12.19s after.
  Warm cache is 0.24s before and after.
- devtools test tests/unit/devtools/test_production_reachability.py
  tests/unit/devtools/test_consumer_reachability.py -- 21 passed
  (receipt 20260920T194730Z-focused-test-1823559-3bd03bf8).

The bead also asks whether per-file fact caching is justified. On this
measurement it is not: parsing is 3.0s of 23.5s, the edge indexing that
dominates depends on the global node set, and the existing content-digest
cache in `consumer_reachability` already answers the unchanged-tree case
in 0.24s. Recorded rather than built.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq
…olylogue-r2lud)

The mechanism this bead asked for is already at head: devtools/mypy_gate.py
takes an exclusive fcntl.flock on <git-common-dir>/polylogue-mypy/lock (:43)
and runs the checker with --cache-dir <git-common-dir>/polylogue-mypy/cache
(:47), and devtools/gate.py:51-58 routes the quick mypy gate through it. What
was missing was a test that exercises the contention rather than a faked
subprocess.

The new test builds a real git checkout plus a linked worktree, gives each a
stub checker that claims exclusive entry with mkdir and holds it for half a
second, and runs both lanes concurrently. Both must exit 0 and must record
the same --cache-dir under the common git dir.

Anti-vacuity, both confirmed by mutation:

- removing the flock -> statuses [9, 0]
  (receipt 20260920T195456Z-focused-test-1845458-529631c7)
- --cache-dir pointed at a per-worktree path -> the two recorded cache dirs
  differ (receipt 20260920T195517Z-focused-test-1846725-d42b9c69)

Green run: devtools test tests/unit/devtools/test_mypy_daemon_lifetime.py,
4 passed (receipt 20260920T195411Z-focused-test-1843658-208375c4).

The bead's four-concurrent-worker number is a measurement, not repository
content, so it is reported rather than turned into a standing gate: four
concurrent `devtools gate mypy` lanes against the warm shared cache all exit
0 with "Success: no issues found in 2926 source files", completing at +0.75,
+1.28, +1.84 and +2.37 seconds -- the ~0.55s stagger of strict
serialization, against 0.78s for a single lane. A cold-cache number was not
taken because clearing the shared cache would have disrupted sibling batch
workers using it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq
…olylogue-olw5e)

Most of this bead is already at head and is not touched here: `devtools
bench parser-census` is implemented in devtools/parser_census.py, and
.agentctl/project.toml:120-128 declares [operations.parser_census] with its
weekly schedule. AC4's anti-vacuity test is also already landed, at
tests/unit/devtools/test_parser_census.py:78 ("Acceptance criterion 4,
demonstrated red") -- a stubbed parse_stream_payload returning no sessions
makes diff_censuses report new_failures for every claude-code-session member
and zero for the other origin. Nothing was re-implemented for it.

AC3's second clause needed a correction before it could be built. The clause
says population coverage should read the census "instead of re-walking", but
devtools/verify_population_coverage.py does not walk any denominator at
head: it evaluates declarations, plus an archive's source.db when given
--archive-root. The only denominator walkers in the tree are the census's
own frontier_denominator/source_denominator. So the real gap is the opposite
one -- the coverage route had no way to see the real source population at
all without the live archive.

This adds that route:

- `census_constructs` classifies every origin and (origin, artifact kind)
  pair a census recorded, through the same classifiers the source.db
  inventory uses. `_origin_construct` is extracted from the inventory path
  so the two evidence sources cannot drift into two coverage policies.
- `resolve_census` loads the newest census under --census-dir (or an exact
  --census). Every failure is typed: no directory, no census, an unreadable
  or foreign document, and a bounded (--limit) run each raise
  PopulationCoverageError, and `main` exits 1 with the reason.
- The report carries `census_evaluated`, so "nothing uncovered" is never
  read as evidence about a population nothing looked at.

A census member carries no support_status, so the empty token never takes
the `unsupported_parseable` short circuit: a census-observed artifact kind
must earn coverage from a declared rule or a matrix witness.

The registered quick gate deliberately does not pass --census-dir. It is
opt-in exactly like --archive-root, because a checkout with no census would
otherwise get a refusal from a gate that has nothing to do with it.

Verification, on this checkout at 0d02434:

- devtools test tests/unit/devtools/test_verify_population_coverage.py
  tests/unit/devtools/test_parser_census.py -- 34 passed
  (receipt 20260920T200221Z-focused-test-1869342-1218205a).
- Anti-vacuity, confirmed by mutation (receipt
  20260920T200630Z-focused-test-1877559-99f0974a): making an absent census
  return an empty Census instead of raising turns
  test_an_absent_or_bounded_census_is_refused_not_reported_as_clean red, and
  dropping members whose origin has no OriginSpec turns
  test_a_census_origin_without_a_declaration_is_uncovered red.
- devtools gate population-coverage, lint, format, mypy, layering and
  schema-closure all pass; devtools render all --check reports no surface
  out of sync.

Scope note: the bead's write_scope named tests/unit/devtools/
test_parser_census.py, but the coverage-route tests belong with the coverage
gate, so they are in tests/unit/devtools/test_verify_population_coverage.py.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@coderabbitai

coderabbitai Bot commented Sep 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 22d8dee0-5760-41c1-9aff-9fe6b21795e8

📥 Commits

Reviewing files that changed from the base of the PR and between 5c2fae0 and 367aeee.

📒 Files selected for processing (6)
  • devtools/consumer_reachability.py
  • devtools/production_reachability.py
  • devtools/verify_population_coverage.py
  • tests/unit/devtools/test_mypy_daemon_lifetime.py
  • tests/unit/devtools/test_production_reachability.py
  • tests/unit/devtools/test_verify_population_coverage.py

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

❤️ Share

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-20T21:09:07.429901Z 367aeee PR opened
ℹ️ About Codex in GitHub

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

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

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 367aeee443

ℹ️ About Codex in GitHub

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

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

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

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

Comment thread devtools/verify_population_coverage.py Resolved
Comment thread devtools/verify_population_coverage.py Resolved
@Sinity
Sinity merged commit d4a3af1 into master Sep 20, 2026
3 checks passed
@Sinity
Sinity deleted the fix/w7-devtools-gate-cost branch September 20, 2026 21:15
@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at bf68918):

Resolving every thread listed; confirmed defects are fixed under the named bead.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant