Skip to content

python: stream the diff walk into a bounded selection (#10594) - #10655

Merged
EffortlessSteven merged 4 commits into
mainfrom
claude/project-thread-w6b15g
Oct 26, 2026
Merged

EffortlessSteven merged 4 commits into
mainfrom
claude/project-thread-w6b15g

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

  • Python diff mode streams the workspace walk into WorkspaceFileSelection instead of collecting and sorting every discovered .py path before the cap selects. Selection keeps the changed files plus a max-heap holding at most RIPR_PYTHON_MAX_WORKSPACE_FILES of the earliest context paths, so discovery memory no longer grows with workspace size.
  • The analyzed set and refused count are identical to python: keep changed files when the workspace walk hits its cap (#10461) #10574 for any directory order, including cap 0, more changed files than the cap, and duplicate paths.
  • visit_workspace_with_handwritten takes a &mut dyn FnMut(PathBuf) sink. collect_workspace_python_files_with_handwritten becomes test-only.

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge,
    dependency, or repo-ops development for ripr-swarm

Source-of-truth Links

Proposal: n/a
Spec: RIPR-SPEC-0028
ADR: n/a
Plan item: n/a
Governing issue or accepted claim: #10594
Acceptance delta (one sentence): Python diff-mode discovery holds at most the file cap plus the changed files in memory, with the same analyzed set and refusal count as before.

Candidate Relationships

Candidate branch: claude/project-thread-w6b15g
Stack parent or prerequisite PR: #10574 (merged)

Scope

crates/ripr/src/analysis/language/python/{bounded_read.rs,workspace.rs,python_tests.rs}, python.rs, docs/LANGUAGE_ADAPTER_PREVIEW.md, changelog fragment, traceability fragments.

Proof

  • workspace_file_selection_is_order_independent_and_holds_at_most_the_cap: 2,000 paths in sorted and shuffled order with cap 5. It asserts the peak context buffer stays at or below 5, the kept set is the same in both orders, and the refused count is correct. It also covers more changed files than the cap.
  • An independent review ran four mutation checks: keep the latest paths, drop the truncate, cap changed files, and an unbounded heap. Each was caught; the unbounded heap only by the peak_context assertion.
  • cargo test -p ripr --lib python: 1570 passed. cargo clippy -p ripr --all-targets -D warnings: clean. cargo xtask precommit: pass.

Claim Boundary

This bounds path discovery memory only. Byte budgets, read failures and the analyzed-set semantics are unchanged.

Rollback

Revert this PR. #10574's behavior returns, with O(N) discovery memory.

Spec-Test-Code Traceability

.ripr/traceability.d/10594-python-walk-streams-bounded-selection.toml. The 10461 fragment is updated for the renamed test.

Gates

cargo xtask precommit passed locally on 2369e906.


Generated by Claude Code

The walk previously collected and sorted every discovered .py path before
the cap chose the analyzed set, so discovery memory scaled with workspace
size. WorkspaceFileSelection keeps changed files plus a max-heap of the
earliest-sorting context paths, never more than the cap, and yields the
same set and refused count whatever the directory iteration order.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 198 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: e9420a23-b7c2-4da8-9b5e-92c003c7d267
Commits

Reviewing files that changed from the base of the PR and between 9a763d7 and e32c85a.

Files selected for processing: 8
  • .ripr/traceability.d/10461-python-cap-keeps-changed-files.toml
  • .ripr/traceability.d/10594-python-walk-streams-bounded-selection.toml
  • changelog.d/10594-python-walk-streams-bounded-selection.md
  • crates/ripr/src/analysis/language/python.rs
  • crates/ripr/src/analysis/language/python/bounded_read.rs
  • crates/ripr/src/analysis/language/python/python_tests.rs
  • crates/ripr/src/analysis/language/python/workspace.rs
  • docs/LANGUAGE_ADAPTER_PREVIEW.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Copy link
Copy Markdown
Member Author

Review of record (source): no blocking findings. Head 2369e90658437c51d4245ead6967a7d912e8e539.

The source and oracle were reviewed independently on the same diff when it sat on 78e7aee4. The rebase onto main 901d9beb was a clean cherry-pick.

  • Correctness: the kept set and refused count match the prior truncate_workspace_files for every input. The heap keeps the cap-smallest unchanged paths under PathBuf order, and finish truncates to cap - changed. Cap 0, more changed files than the cap, duplicates and directory order were all checked.
  • Memory: buffered state is the heap (at most the cap, asserted through peak_context), the changed-file Vec and set, both diff-sized, and one read_dir per recursion level. Nothing grows with the workspace.
  • Callers: truncate_workspace_files has no remaining references. The new visit_workspace_with_handwritten sink has two callers. The TypeScript function of the same name is separate and untouched.
  • Oracle: the four mutations (keep the latest paths, drop the truncate, cap changed files, unbounded heap) are each caught. The unbounded heap is caught only by the test-only peak_context assertion.
  • Docs and traceability: accurate. Two wording nits are fixed in 2369e906.
  • Local checks: cargo test -p ripr --lib python ran 1570 passed. Clippy -D warnings is clean and cargo xtask precommit passes.

REVIEW_INCOMPLETE pending hosted qualification on this head.


Generated by Claude Code

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 26, 2026 09:59

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors the Python workspace file discovery process to stream discovered files into a bounded selection (WorkspaceFileSelection) using a max-heap (BinaryHeap) instead of collecting and sorting all files first. This optimization ensures that memory usage during discovery remains bounded by the file-count cap plus changed files, regardless of the workspace size, while maintaining order independence and determinism. As there are no review comments provided, I have no additional feedback to offer.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Decision

  • Needs one verification check before upstream.

Verification questions

  • Confirm the proof measures the context heap rather than all discovery memory, so the broad 'plus changed files' memory claim is not directly instrumented.

Refuted

  • The sink API might introduce a second traversal or duplicate implementation of workspace discovery.; refuted because: Rejected: production code performs one visit_workspace_with_handwritten walk; the collecting helper is test-only and delegates to the same visitor.
  • The change may exceed the advertised workspace discovery memory bound.; refuted because: The production selection stores only changed paths plus a context heap of at most max_files; the per-path PathBuf values and recursion stack remain bounded by the selected file count rather than all discovered paths.

Parked follow-ups

  • The public API claim is limited to discovery-path memory; byte budgets and read-failure behavior remain delegated to read_workspace_sources_capped.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.
  • Automated proof remains dependent on the scheduled cargo-test receipt because the ripr sensor failed with exit code 2.

Copy link
Copy Markdown
Member Author

Run 40303932921 failed in Rust gates (job 121508597723) with function parent_dir_follows_symlink is never used in the xtask build. That is the main break from #10624: xtask path-includes agent/loop_commands.rs, which this PR doesn't touch. The fix of record is #10663. Once it lands I'll merge main into this branch and request one complete qualification run.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

The verification question from the github-actions review is confirmed as stated. peak_context instruments only the context heap, which is the part that used to grow with the workspace. The changed-file Vec and changed_walk_paths aren't instrumented. They are bounded by construction: they hold only diff paths, which are known before the walk starts. So the claim "at most the cap plus the changed files" combines one measured bound (the heap) with one structural bound (the diff set). The PR body's Claim Boundary already limits it to path-discovery memory.


Generated by Claude Code

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Decision

  • Needs one verification check before upstream.

Verification questions

  • Confirm the new test validates expected selection directly but does not compare the streaming implementation against the removed truncate_workspace_files oracle for equivalent inputs.

Refuted

  • The sink API may duplicate traversal or leave production callers on the collecting path.; refuted because: Production calls visit_workspace_with_handwritten once; collect_workspace_python_files_with_handwritten is cfg(test)-only and delegates to that same visitor.
  • The broad memory claim is directly measured for all discovery state.; refuted because: The prior verification question was answered in the seeded thread: peak_context measures the workspace-sized heap, while changed files are structurally diff-sized. The PR claim is explicitly bounded to path-discovery memory.
  • The sink API creates a second production traversal or retains all discovered paths.; refuted because: Production PythonAdapter directly invokes visit_workspace_with_handwritten once and feeds WorkspaceFileSelection::push. The collecting helper is test-only, and selection retains only changed paths plus at most max_files context paths.

Parked follow-ups

  • The advertised memory boundary is structural for changed paths and measured for context paths; broad discovery-memory wording is limited but should remain accurately scoped.

Evidence gaps

  • The scheduled cargo-test receipt remains the only outstanding executable proof; the ripr sensor failed with exit code 2 rather than reporting a source defect.
  • Automated validation is still pending because the ripr sensor failed; the scheduled cargo-test receipt is required to substantiate the claimed test result.
  • Model proof intent was rejected by deterministic validation.
  • Clean automated qualification for the current head is not yet evidenced in the supplied packet.

Copy link
Copy Markdown
Member Author

On the second verification question: the removed truncate_workspace_files isn't called as an oracle because it no longer exists. Its rule is restated as expected in workspace_file_selection_is_order_independent_and_holds_at_most_the_cap: sort the walk, keep every changed file, and fill the remainder with the first cap - changed unchanged paths in sorted order. That is the same computation the old function did. The streaming selection must match it exactly over 2,000 paths, in both sorted and shuffled push order, and both kept set and refused count are asserted. The production path is still covered end to end by #10574's analyze_diff_keeps_a_late_sorting_changed_file_past_the_cap, which runs through analyze_diff on this head and passes.


Generated by Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

merge-ready is set, but no qualification run exists for head 42f422c7: it was pushed after the label was applied, or the label event was dropped. Remove and re-apply merge-ready to request it again.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Decision

  • Needs verification checks before upstream.

Verification questions

  • Confirm the implementation retains every changed path and at most the configured context budget, but the refusal count is computed from the number of discovered paths rather than the number of context files refused.
  • Confirm the new order-independence test covers shuffled versus sorted discovery, but it does not directly exercise the production analyze_diff route for duplicate paths or multiple changed-file cases beyond the separate unit test.
  • Confirm the bounded-selection helper owns discovery-retention state, while the traversal helper only streams admitted paths; this is the narrowest boundary for the stated memory improvement.
  • Confirm the sink API does not introduce a second workspace-discovery implementation or leave production callers using an unbounded collector.
  • Confirm the selected-set boundary preserves the previous cap semantics even when changed files exceed the cap.

Refuted

  • The memory claim is wholly unmeasured or includes workspace-sized changed-path storage.; refuted because: The assertion measures the workspace-sized context heap; changed-path storage contains only diff paths and is structurally bounded. The PR claim explicitly describes discovery memory as cap plus changed files, so this is a narrow residual wording/instrumentation limitation rather than a demonstrated regression.
  • The helper boundary is too narrow or requires broader production changes.; refuted because: The memory-bearing state is entirely encapsulated by WorkspaceFileSelection, and the existing traversal needed only a callback parameter; no unrelated adapter behavior is reorganized.
  • The sink API leaves production on an unbounded collecting path or causes a second traversal.; refuted because: The collecting helper is test-only; production invokes the visitor once and streams paths into bounded selection.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.

Copy link
Copy Markdown
Member Author

Answers to the github-actions verification questions on e32c85a1:

  1. Refused count. refused = discovered - kept. Every changed path is kept, so every path not kept is an unchanged context file the cap refused. The two counts are the same number. This is what python: keep changed files when the workspace walk hits its cap (#10461) #10574 computed, and the tests assert it, including the case of more changed files than the cap.
  2. Production route. The order-independence and duplicate cases are unit-level by design, because directory order can't be controlled in an integration fixture. The production route stays covered by python: keep changed files when the workspace walk hits its cap (#10461) #10574's analyze_diff_keeps_a_late_sorting_changed_file_past_the_cap, which passes on this head.
  3. Boundary. Confirmed. WorkspaceFileSelection owns all retention state. visit_workspace_with_handwritten only streams admitted paths to its sink.
  4. No second implementation. Confirmed. Production calls the visitor once. collect_workspace_python_files_with_handwritten is #[cfg(test)] and delegates to the same visitor.
  5. More changed files than the cap. Confirmed. saturating_sub leaves zero context and keeps every changed file, matching python: keep changed files when the workspace walk hits its cap (#10461) #10574. This is asserted in workspace_file_selection_is_order_independent_and_holds_at_most_the_cap, using the pkg01 predicate with cap 1.

Generated by Claude Code

Copy link
Copy Markdown
Member Author

Final review of record: REVIEW_READY at head e32c85a11b9bc0f828da2f1f616ae12e96a62b31

  • Source and oracle: unchanged since the reviewed source commits 2d935e49 and 2369e906, both cherry-picked onto 901d9beb. An independent review with four mutation checks found nothing blocking. The two wording nits are fixed.
  • Integration: two main merges with no conflicts. The second, e32c85a1, brings fix(main): clear both main breaks (xtask dead-code Clippy and owner-built-expected corpus row) #10663, which clears both main breaks. Locally, cargo clippy -p ripr -p xtask --all-targets -D warnings is clean and cargo test -p ripr --lib python passes 1576/1576.
  • Qualification: run 40342709991 attempt 1 succeeded. Shards verify counted 5604 + 5546 + 5494 + 5446 = 22,090 JUnit tests, all from the same attempt, and Ripr Rust Small Result is green. The earlier failure in run 40303932921 came from the main break and is preserved.
  • Remote review: 0 unresolved threads. Devin and Gemini found no issues. The github-actions verification questions are answered in comments above. CodeRabbit was rate-limited, so its review is missing, not clean.

Merging by squash at this exact head.


Generated by Claude Code

@EffortlessSteven
EffortlessSteven merged commit 2d6f94f into main Oct 26, 2026
56 checks passed
@EffortlessSteven
EffortlessSteven deleted the claude/project-thread-w6b15g branch October 26, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants