Skip to content

fix: bound canonical patch prefix scanning - #801

Closed
luvs01 wants to merge 5 commits into
devfrom
codex/fix-quadratic-work-in-apply_patch
Closed

luvs01 wants to merge 5 commits into
devfrom
codex/fix-quadratic-work-in-apply_patch

Conversation

@luvs01

@luvs01 luvs01 commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

Streamed apply_patch previews previously scanned the complete accumulated argument buffer on every delta. This bounds recognition to a rolling 64-character tail while preserving canonical and decorated delimiter semantics.

The follow-up adds four routed-stream regressions: 64 KiB LF/CRLF patches, with and without a decorated closer, split into 37-character body fragments and single-character closing-marker/newline fragments. They verify operation progress before the closer, withheld decoration, identical completion inputs, and stable call identity.

Integrated upstream dev 3cab4a74e4eec15ee5ff3bdd59dcab8ede938372 without conflict. The unique upstream-relative delta is six files; GUI changes visible against the older fork dev are inherited upstream changes.

Verification

  • Bun 1.4.4 on Windows, isolated homes with the real-home write guard: bun test tests/responses/apply-patch-envelope.test.ts tests/responses/responses-custom-tool-stream-consistency.test.ts: 50 pass, 0 fail, 2,092 assertions, including all four new cases.
  • Aligned head df76e957d9b7baf602a47e7d159f0aee3f71c56f: typecheck 2,252 files, structure, privacy, and repository file-size ratchet PASS. Native Job exit, both stream EOFs, and supervisor reap confirmed.
  • Initial setup attempts exposed a Bun bin-shim resolution error and a sparse-checkout missing-document error. Direct invocation of the same pinned Bun and materializing the tracked documentation corrected those environment failures; the final gates above passed without changing product code or checks.
  • Full local import-graph execution is disproportionate on the shared Windows storage. Focused production-path regressions ran locally; broader validation completed in exact-head PR CI. Earlier-head CI is not new-head evidence. No live service, configuration, credentials, or permission mode changed.

Checklist

  • Focused behavior tests, typecheck, structure, privacy, and file-size checks passed.
  • Latest observed upstream dev integrated; exact authored delta identified.
  • Routed streaming regression requested in r4420398375 implemented.
  • Exact-head Cross-platform CI41080927181, Catalog41080927157, Service lifecycle41080927136, React Doctor41080927189 and Enforce41080920051 passed; unresolved reviews: 0. Hosted job124149703591 records all four new routed long-patch cases passing.

Codex Task


Devin Review

Summary by CodeRabbit

  • Bug Fixes
    • Improved streaming restoration of canonical patch responses, including recognition of terminal decorations that arrive across partial chunks.
    • Preserved stable patch output when responses contain very long lines.
    • Improved consistency between streamed previews and completed patch inputs, including patches wrapped in JSON and patches using LF or CRLF line endings.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

  • No new commits to review - use @coderabbitai full review for a full pass

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 3ea8965 and fec893d.

Files selected for processing: 5
  • src/responses/apply-patch-envelope.ts
  • src/server/responses-custom-tool-repair.ts
  • structure/transports/inventory.md
  • structure/transports/responses.md
  • tests/responses/apply-patch-envelope.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The patch-prefix helper now accepts a bounded tail and an opening-validation flag. The routed streaming path retains a bounded suffix of argument deltas and passes it to the helper. The transport documentation and tests reflect these changes.

Changes: Canonical patch prefix handling

Layer / File(s) Summary
Bounded-tail prefix detection
src/responses/apply-patch-envelope.ts, tests/responses/apply-patch-envelope.test.ts
stableCanonicalPatchPrefix accepts an optional bounded tail and openingValidated flag. It uses the tail to detect partial terminal decorations and retains opening-prefix handling when opening validation is not supplied. A test covers a canonical prefix containing a 200,000-character LF-terminated line.
Streaming tail collection and integration
src/server/responses-custom-tool-repair.ts, structure/transports/inventory.md, structure/transports/responses.md
The streaming path retains the last 64 characters of custom-exec and routed function-argument deltas. It passes the tail to stableCanonicalPatchPrefix when the full input is unchanged, along with canonicalPatchProgress. The transport docs describe recognizing rewritable terminal decorations from a bounded suffix.

Priority: Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: platinum-scripts, lidge-jun

Merge Risk: Minimal · previous review fec89

The change bounds patch-preview scanning. No material merge risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: limiting canonical patch prefix scanning with bounded inspection.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 30, 2026

@devin-ai-integration devin-ai-integration 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.

Devin Review found 1 potential issue.

Devin Review

@luvs01

luvs01 commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner Author

No description provided.

@luvs01
luvs01 marked this pull request as ready for review October 30, 2026 15:47
@luvs01

luvs01 commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

No description provided.

@luvs01 luvs01 closed this Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant