Skip to content

Fix synthetic probe PR close matching#280

Merged
kjgbot merged 2 commits into
mainfrom
factory-sdk-close-synthetic-pr-sb-impl3
Jun 13, 2026
Merged

Fix synthetic probe PR close matching#280
kjgbot merged 2 commits into
mainfrom
factory-sdk-close-synthetic-pr-sb-impl3

Conversation

@kjgbot

@kjgbot kjgbot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the synthetic close-probe path so completed [factory-e2e] issues close their PRs even when real agents use natural PR titles.

  • Keeps #isSyntheticProbeIssue as the safety boundary: only synthetic issue titles enter close-never-merge handling.
  • Stops requiring a PR title marker on the already issue-gated synthetic close path.
  • Adds exact issue-key matching for branch convention refs like ar-229-is-positive, with numeric-prefix protection so AR-22 does not match AR-229.
  • Scores PR matches by deterministic signal: branch, then title, then explicit body references such as Linear: AR-235.
  • Leaves manual/default closeProbePr strict unless the issue-gated caller explicitly opts out of title-marker enforcement.

Mutation / Regression Proofs

Validation

  • npm run typecheck:node
  • npx vitest run packages/factory-sdk

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@kjgbot, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 30 minutes and 1 second. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 022eb20c-2e87-4960-822f-849dab83adf4

📥 Commits

Reviewing files that changed from the base of the PR and between de24cb3 and 94bdad1.

📒 Files selected for processing (8)
  • packages/factory-sdk/src/cli/fleet.ts
  • packages/factory-sdk/src/github/probe-closer.test.ts
  • packages/factory-sdk/src/github/probe-closer.ts
  • packages/factory-sdk/src/issue-key-match.test.ts
  • packages/factory-sdk/src/issue-key-match.ts
  • packages/factory-sdk/src/orchestrator/factory.test.ts
  • packages/factory-sdk/src/orchestrator/factory.ts
  • packages/factory-sdk/src/types.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch factory-sdk-close-synthetic-pr-sb-impl3

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 and usage tips.

@kjgbot kjgbot added the no-agent-relay-review Disable agent-relay automated PR review/fixes label Jun 13, 2026

@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 introduces a scoring mechanism to match and close synthetic probe PRs based on issue key references in the branch name, title, or body, and adds a new issue-key-match utility. The review feedback highlights two logical bugs in the regular expression lookaheads within issue-key-match.ts that could cause incorrect matches, and suggests a performance optimization in factory.ts to parallelize sequential I/O operations when reading PR candidates.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.


const prefix = escapeRegex(parts[1] ?? '')
const number = escapeRegex(parts[2] ?? '')
return new RegExp(`(^|[^A-Za-z0-9])${prefix}-${number}(?=$|[^A-Za-z0-9]|-(?!\\d))`, 'i').test(value)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The regular expression lookahead (?=$|[^A-Za-z0-9]|-(?!\d)) contains a logical bug. Because [^A-Za-z0-9] matches any non-alphanumeric character (including hyphens), any hyphen will immediately satisfy this part of the lookahead, completely bypassing and rendering the -(?!\d) check redundant.

To fix this and ensure that a hyphen followed by a digit (e.g., ar-22-9) does not incorrectly match AR-22, the hyphen must be excluded from the character class.

Suggest updating the lookahead to (?=$|[^A-Za-z0-9-]|-(?!\d)).

Suggested change
return new RegExp(`(^|[^A-Za-z0-9])${prefix}-${number}(?=$|[^A-Za-z0-9]|-(?!\\d))`, 'i').test(value)
return new RegExp(`(^|[^A-Za-z0-9])${prefix}-${number}(?=$|[^A-Za-z0-9-]|-(?!\\d))`, 'i').test(value)


const prefix = escapeRegex(parts[1] ?? '')
const number = escapeRegex(parts[2] ?? '')
const issue = `${prefix}-${number}(?=$|[^A-Za-z0-9]|-(?!\\d))`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The lookahead in the explicit issue reference regex has the same logical bug where [^A-Za-z0-9] matches hyphens, making the -(?!\d) check redundant.

Suggest updating the lookahead to (?=$|[^A-Za-z0-9-]|-(?!\d)) to correctly prevent partial matches on hyphens followed by digits.

Suggested change
const issue = `${prefix}-${number}(?=$|[^A-Za-z0-9]|-(?!\\d))`
const issue = `${prefix}-${number}(?=$|[^A-Za-z0-9-]|-(?!\\d))`

Comment on lines 2099 to 2109
for (const repo of reposFromConfig(config)) {
for (const path of await mount.listTree(githubPullRoot(repo))) {
if (!path.endsWith('.json')) continue
const pr = await readProbePrCandidate(mount, path)
if (!pr || !issuePrMatchesIssue(pr, issue, opts.titleMarker ?? config.safety.requireTitlePrefix, opts)) continue
candidates.push({ repo, prNumber: pr.number })
const score = pr
? issuePrMatchScore(pr, issue, opts.titleMarker ?? config.safety.requireTitlePrefix, opts)
: 0
if (!pr || score <= 0) continue
candidates.push({ repo, prNumber: pr.number, score })
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Reading each PR candidate sequentially with await readProbePrCandidate(mount, path) inside a nested loop can cause significant performance bottlenecks due to sequential I/O operations (especially if mount.readFile involves network latency).

Suggest parallelizing the PR candidate reading using Promise.all to fetch and score the candidates concurrently.

  for (const repo of reposFromConfig(config)) {
    const paths = (await mount.listTree(githubPullRoot(repo))).filter((path) => path.endsWith('.json'))
    const results = await Promise.all(
      paths.map(async (path) => {
        const pr = await readProbePrCandidate(mount, path)
        if (!pr) return null
        const score = issuePrMatchScore(pr, issue, opts.titleMarker ?? config.safety.requireTitlePrefix, opts)
        return score > 0 ? { repo, prNumber: pr.number, score } : null
      })
    )
    for (const cand of results) {
      if (cand) candidates.push(cand)
    }
  }

This was referenced Jun 13, 2026
@kjgbot kjgbot merged commit 7c4ab03 into main Jun 13, 2026
5 checks passed
@kjgbot kjgbot deleted the factory-sdk-close-synthetic-pr-sb-impl3 branch June 13, 2026 18:48
@agent-relay-code

Copy link
Copy Markdown
Contributor

Implemented one safety fix in the PR scope:

closeProbePr now uses the same strict markerless issue-reference rules as the mount resolver: branch/title issue keys are accepted, but body-only markerless matches must be explicit (Linear:, Closes, etc.). Added a regression test for loose body mentions.

Addressed comments

  • CodeRabbit: review was rate-limited and did not raise a code finding; no code change.
  • gemini-code-assist: containsIssueKey hyphen lookahead bug; stale, already fixed in packages/factory-sdk/src/issue-key-match.ts:14 and covered by packages/factory-sdk/src/issue-key-match.test.ts:11.
  • gemini-code-assist: containsExplicitIssueReference hyphen lookahead bug; stale, already fixed in packages/factory-sdk/src/issue-key-match.ts:23.
  • gemini-code-assist: parallelize PR candidate reads in resolveIssuePrFromMount; not changed, treated as advisory because it is a performance suggestion and no correctness/CI failure was demonstrated in the current checkout.
  • gemini-code-assist review summary: covered by the three thread-specific items above.

Advisory Notes

  • The resolveIssuePrFromMount candidate scan could be parallelized with Promise.all if mount latency becomes a measured bottleneck, but I left it unchanged to avoid restructuring working code without a demonstrated failure.

Verification

Local commands run:

  • npm ci
  • npm run verify:mcp-resources-drift
  • npm run lint
  • npm run typecheck:web
  • npm run typecheck:node
  • npm test
  • npx vitest run (first run hit an unrelated ChatView.dom.test.ts teardown race; exact rerun passed)
  • npm run build
  • npm run build:web
  • npx playwright install --with-deps chromium
  • npx playwright test --config playwright.fidelity.config.ts
  • npx playwright test --config playwright.redraw.config.ts

Remote PR metadata currently reports PR #280 is already merged and closed, so I’m not marking this as needing human-ready handoff.

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

Labels

no-agent-relay-review Disable agent-relay automated PR review/fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant