Skip to content

test: stop holding every parsed src module in the argv-floor derivations - #38935

Merged
iamwhatever merged 1 commit into
mainfrom
crew/testoptimizer/argv-floor-ast-memory
Nov 18, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
crew/testoptimizer/argv-floor-ast-memory

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Stop the argv-floor derivation tests from holding every parsed src/ module in memory, keeping every check they make.

test_argv_floor_inline_and_brace_scope.py shares a module-scoped _ProductTree between its two mint-surface derivations. It kept the AST of every candidate module it parsed until the module ended, so the two tests grew the worker's memory by about 240 MiB (tools/cost-baseline/memory.md row 4 measured 282 MiB peak growth).

Why it matters

A worker's peak memory is what the xdist budget has to reserve. This file alone lifted a worker from ~200 MiB to ~450 MiB.

Not a goal

  • Changing what either derivation checks, its seeds, its fixed point, or the verify_only / not_readers tables.
  • Changing src/ (the denied-command floor) or test/conftest.py.

What changed (motivation → approach → change)

Before After
_ProductTree.tree() parsed a module once and kept its AST to module end parses for the caller that asks; the AST is dropped when the caller is done
import_from() walked each candidate's kept AST reads each module's from X import y lines, kept as plain tuples, parsed once

The text filter that picks candidate modules is unchanged, and so is every AST walk the two tests do. The import-graph fixed point asks import_from many times, so its lines are the one thing kept; producers_in re-parses the few modules it needs.

Backwards compatibility

Compatible: test-only change.

Removes nothing: no test, case, assertion or table entry is dropped.

Tests

Proof: not provable -- test-only change

Same host, Linux, the file alone at -n 0, no coverage, main to branch (two runs each):

main branch
Peak RSS (VmHWM) 438 / 438 MiB 205 / 206 MiB
Growth across the two derivation tests +144 / +96 MiB +5 / +2 MiB
Mint-surface test 16.3 / 16.5 s 15.7 / 15.2 s
Credential-word test 2.0 / 2.1 s 1.4 / 1.5 s

Under --cov=kiro_crew: peak 457-458 MiB to 235 MiB, wall 42.4-44.4 s to 42.2-43.5 s.

Planted bugs, each run on this branch and on main (cda68bf2b):

Plant Result on both trees
inline_payload._MINT_VERB_RE drops secret the same 20 tests fail, both derivations among them
inline_payload._MINT_VERB_RE drops token the same 6 tests fail, the mint-surface derivation among them
a new module re-exports generate_token as make_pass test_the_mint_surface_covers_every_token_producer_in_the_tree fails, naming from kiro_crew.planted_reexport import make_pass

The third plant goes through the rewritten import_from and the re-export fixed point.

Coverage, the file at -n 0 -p no:randomly: TOTAL 870570 statements / 776934 missed on both trees, every per-file row equal.

Determinism: 3 shuffled orders of the 243 items and 5 repeats at -n 0 all pass. Flake-pattern ratchet, comment-history, brand and black gates pass. #36096 adds one verify_only row in this file; it touches no line this PR changes.

Manual verification

N/A — test-only change; the runs above are the evidence.

Related Issues

N/A — test-memory work from tools/cost-baseline/memory.md.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners November 18, 2026 02:43
@iamwhatever
iamwhatever enabled auto-merge (squash) November 18, 2026 02:43
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision 61463bcc580326de7212a6c17b8644b5f14b1f9c ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Does not block merge.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 61463bcc580326de7212a6c17b8644b5f14b1f9c and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 61463bc

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 61463bcc580326de7212a6c17b8644b5f14b1f9c false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 61463bcc580326de7212a6c17b8644b5f14b1f9c touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 61463bcc580326de7212a6c17b8644b5f14b1f9c — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. This is a test-only change that swaps a cached AST for cached import tuples, and every check the derivations make stays the same.

[DESIGN-REVIEWED] 61463bc

Description read

[DESCRIPTION-READ] 3c018e9bbb7ed0b8812aafbaad193152bb9ad9b2c8200ef2f9aeb9611be41df7

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 61463bcc580326de7212a6c17b8644b5f14b1f9c — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 61463bc

Verdict parsed from the review's SHA-scoped output markers for commit 61463bcc580326de7212a6c17b8644b5f14b1f9c.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 61463bcc580326de7212a6c17b8644b5f14b1f9c false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 18, 2026
@iamwhatever
iamwhatever disabled auto-merge November 18, 2026 04:42
The two mint-surface derivations shared a module-scoped view of the
product tree that kept the AST of every candidate module until the
module ended, about 240 MiB of live memory per worker. Each tree is
now parsed for the caller that asks and then dropped; only the import
lines the import-graph walk reads again are kept, as plain tuples.
Every check and derivation is unchanged.
@iamwhatever
iamwhatever force-pushed the crew/testoptimizer/argv-floor-ast-memory branch from 550ce12 to 61463bc Compare November 18, 2026 04:45
@iamwhatever
iamwhatever enabled auto-merge (squash) November 18, 2026 04:45
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 18, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved. Review checks on head 61463bc:

  • The rewritten import_from gives the same output in the same order. It walks the same sorted paths, uses the same byte filter and builds the same (module, name, bound) tuples.
  • Modules that do not parse are still skipped.
  • The producers_in not-None assertion still holds.
  • No assertion, seed or table changed, and nothing outside the test helper changed.

Done well: only the small per-module import tuples stay cached and the full ASTs are dropped. The planted re-export run through the new path shows the checks still fire.

Optional:

  • The body cites tools/cost-baseline/memory.md, but that file is not in the repository. The before/after RSS table already supports the goal, so you could drop that reference.
  • _imports_of could store [] for an unparseable module. That would remove the | None annotations and the or () at its one call site.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Nov 18, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider estimates a 4% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier pending: waiting for the review lanes to finish.

Test-only memory optimization of _ProductTree. tree() now parses for each caller instead of caching ASTs. import_from() keeps the same text filter and caches only per-module ImportFrom tuples, which don't depend on the target. The tuples, their walk order, the skipping of modules that don't parse, and the order across modules are all unchanged, so both derivations compute the same results. producers_in re-parses its module, which is deterministic, so its assert still holds. No other users of the helper, no src/ changes, and CI is green.

Tier: pending: waiting for the review lanes to finish.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 61463bcc58 · 47 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 18, 2026
@iamwhatever
iamwhatever merged commit 44769db into main Nov 18, 2026
138 of 160 checks passed
@iamwhatever
iamwhatever deleted the crew/testoptimizer/argv-floor-ast-memory branch November 18, 2026 17:02
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 18, 2026
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.

2 participants