Skip to content

perf(staged): pre-compute git context before create-PR agent session#485

Draft
matt2e wants to merge 3 commits intomainfrom
faster-create-pr
Draft

perf(staged): pre-compute git context before create-PR agent session#485
matt2e wants to merge 3 commits intomainfrom
faster-create-pr

Conversation

@matt2e
Copy link
Contributor

@matt2e matt2e commented Mar 26, 2026

Summary

  • Pre-computes git context (log, stat, diff) before starting the create-PR agent session, so the agent receives the analysis upfront and can skip running those deterministic commands itself
  • For local branches, the three git commands run in parallel using std::thread::scope; for remote branches they run sequentially (SSH transport serializes anyway)
  • Includes diff truncation at 50K characters to avoid sending excessively large diffs to the agent
  • Falls back to the original behavior (agent runs commands itself) if any pre-computation fails

Test plan

  • Create a PR from a local branch and verify the agent skips the git analysis step
  • Create a PR from a remote/workstation branch and verify correct behavior
  • Test with a branch that has a very large diff (>50K chars) to verify truncation
  • Verify fallback works by simulating a git command failure

🤖 Generated with Claude Code

Run `git log`, `git diff --stat`, and `git diff` in parallel on the
Rust side before the agent session starts, then inject the results
into the prompt. This lets the agent skip straight to pushing and
creating the PR instead of spending time on deterministic git commands.

Falls back to the original prompt (agent runs git itself) if any
pre-computation command fails. Large diffs are truncated at 50k chars.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt2e matt2e requested review from baxen and wesbillman as code owners March 26, 2026 04:27
@matt2e matt2e marked this pull request as draft March 26, 2026 04:28
Copy link

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

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: a3eef30849

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

if diff.len() <= DIFF_TRUNCATION_LIMIT {
return diff;
}
let truncated = &diff[..DIFF_TRUNCATION_LIMIT];

Choose a reason for hiding this comment

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

P2 Badge Avoid slicing diff at non-UTF-8 character boundaries

truncate_diff indexes the string with a raw byte offset (&diff[..DIFF_TRUNCATION_LIMIT]). If a large diff contains multibyte UTF-8 text, hitting the 50,000-byte cutoff in the middle of a character will panic, which can crash create_pr instead of gracefully falling back. This is reproducible when the diff exceeds the limit and includes non-ASCII content (for example in source strings/comments or filenames), so truncation needs to find a valid character boundary before slicing.

Useful? React with 👍 / 👎.

matt2e and others added 2 commits March 26, 2026 15:29
The `parseContentSegments` regex used non-greedy matching (`*?`),
causing it to match nested `<action>` tags inside pre-computed diffs
(e.g. diffs of prs.rs itself) instead of the outermost wrapper. Switch
to greedy matching so the first opening tag pairs with the last
matching closing tag.

Also fix a potential panic in `truncate_diff` when slicing at a byte
index that falls mid-character in multi-byte UTF-8 by using
`floor_char_boundary`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove the `git diff origin/{base}...HEAD` pre-computation and the
`truncate_diff` helper. The commit log and diff stat are sufficient
for the agent to write a good PR title and body, and skipping the
full diff avoids large payloads and speeds up the pre-computation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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