Skip to content

fix(push): update the open PR instead of opening duplicates - #350

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
rzexin:fix/push-duplicate-pr
Aug 28, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
rzexin:fix/push-duplicate-pr

Conversation

@rzexin

@rzexin rzexin commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

teamai push diffs against the team repo's default branch, where a resource waiting in an unmerged PR is absent — so every run flagged it as new and opened another PR, and the timestamped branch names kept git-level deduplication from kicking in.

Push now records each branch, PR URL and its resources in the machine-local state, and splits the selection into one branch/PR per group:

  • Resources already in an open PR force-push that branch, updating the PR in place and reusing its original namespace. An unchanged tree is not pushed, so a repeated push is a no-op.
  • Everything else still gets its own new PR, so unrelated resources are never pulled into someone else's review. A partially selected PR also goes to a new PR, with a warning.
  • Records are pruned once the branch is gone from origin or its resources reach the default branch, and kept when the remote is unreachable.

The listing marks these resources with awaiting review: <url>.

Summary

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit passes
  • npx vitest run passes
  • Added/updated tests for the change

Related Issues

Notes for Reviewers

`teamai push` diffs against the team repo's default branch, where a
resource waiting in an unmerged PR is absent — so every run flagged it as
new and opened another PR, and the timestamped branch names kept git-level
deduplication from kicking in.

Push now records each branch, PR URL and its resources in the machine-local
state, and splits the selection into one branch/PR per group:

- Resources already in an open PR force-push that branch, updating the PR
  in place and reusing its original namespace. An unchanged tree is not
  pushed, so a repeated push is a no-op.
- Everything else still gets its own new PR, so unrelated resources are
  never pulled into someone else's review. A partially selected PR also
  goes to a new PR, with a warning.
- Records are pruned once the branch is gone from origin or its resources
  reach the default branch, and kept when the remote is unreachable.

The listing marks these resources with `awaiting review: <url>`.

Co-authored-by: Cursor <[email protected]>
@jeff-r2026
jeff-r2026 self-requested a review August 27, 2026 09:30
@jeff-r2026 jeff-r2026 self-assigned this Aug 27, 2026
@jeff-r2026
jeff-r2026 requested a review from m0Nst3r873 August 27, 2026 12:00
@jeff-r2026
jeff-r2026 merged commit 5ddd9fd into Tencent:main Aug 28, 2026
7 checks passed
jeff-r2026 added a commit that referenced this pull request Aug 28, 2026
Address two correctness bugs found in review of the #350 follow-up:

- push --skill force-construct: when the scanner returns nothing for the
  target skill (local content is byte-identical to the team repo), the
  matchedItem was pushed into allItems but not fullScan, so
  prunePendingPushes dropped the skill's OWN open-PR record and the next
  run opened a duplicate. Add the force-constructed item to fullScan too.
- pushRepoBranch: three early-exit paths deleted the local branch right
  after switchToDefaultBranch, but when the default branch is held by
  another worktree the switch returns silently with HEAD still on the push
  branch, and `git branch -D` then throws an uncaught error out of the
  function. switchToDefaultBranch now reports whether it actually switched,
  and a new leaveAndDeletePushBranch helper skips the delete when it didn't.

Tests:
- force-constructed --skill keeps its own open-PR record (real skill dir on
  disk to exercise the force-construct path; fails without the fullScan fix).
- pushRepoBranch skips the delete without throwing when the default branch
  is busy in another worktree (fails without the guard).
- push-team-config: assert the catch path lands back on 'main' (not just
  off the stuck branch) and move logSpy.mockRestore into finally.
jeff-r2026 added a commit that referenced this pull request Aug 31, 2026
…lus review follow-ups (#359)

* fix(push): preserve other resources' open-PR records under --skill, plus review follow-ups

Follow-up fixes for the #350 open-PR-update feature, found in code review:

- push --skill: prune pending-push records against the full scan, not the
  narrowed single-skill list. Narrowing dropped every OTHER resource's
  open-PR record and the next run opened duplicate PRs for them.
- pushRepoBranch (reuse, no-op): delete the local branch when the rebuilt
  tree already matches the remote, matching the other early-exit paths so
  stale local branches don't accumulate.
- pushTeamConfigOnly: switch back to the default branch in the catch path so
  a mid-push failure never strands the team repo on the push branch.
- hasCommits: correct the comment to describe the real guard (the catch
  block), the command uses no --quiet.
- push: replace Chinese comment and error string with English (CLAUDE.md).
- docs: document the update-open-PR behavior in README (both langs) and
  usage-guide (both langs).

* fix(push): handle force-construct prune + multi-worktree branch delete

Address two correctness bugs found in review of the #350 follow-up:

- push --skill force-construct: when the scanner returns nothing for the
  target skill (local content is byte-identical to the team repo), the
  matchedItem was pushed into allItems but not fullScan, so
  prunePendingPushes dropped the skill's OWN open-PR record and the next
  run opened a duplicate. Add the force-constructed item to fullScan too.
- pushRepoBranch: three early-exit paths deleted the local branch right
  after switchToDefaultBranch, but when the default branch is held by
  another worktree the switch returns silently with HEAD still on the push
  branch, and `git branch -D` then throws an uncaught error out of the
  function. switchToDefaultBranch now reports whether it actually switched,
  and a new leaveAndDeletePushBranch helper skips the delete when it didn't.

Tests:
- force-constructed --skill keeps its own open-PR record (real skill dir on
  disk to exercise the force-construct path; fails without the fullScan fix).
- pushRepoBranch skips the delete without throwing when the default branch
  is busy in another worktree (fails without the guard).
- push-team-config: assert the catch path lands back on 'main' (not just
  off the stuck branch) and move logSpy.mockRestore into finally.

* test(push): pin bare repo default branch to main in initTeamRepos

CI failed on `config-only: switches back to the default branch when the
push throws` with `expected '' to be 'main'`. Root cause: the test harness's
`git init --bare` inherits the runner's init.defaultBranch. On a runner where
that is `master` (GitHub's ubuntu/macos images), the bare HEAD points at
`master` while the seed only ever pushes `main`, so `git clone` lands on an
unborn HEAD and the working clone has no local `main`. simple-git then reports
`.branch().current` as '' — which the tightened assertion (toBe('main'),
added for the reviewer's nit) surfaced.

Fix: pass --initial-branch=main to the bare init so the clone checks out main
regardless of the runner's git default. Reproduced locally with
GIT_CONFIG_GLOBAL forcing init.defaultBranch=master (full suite: 2341 pass).
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
)

`teamai push` diffs against the team repo's default branch, where a
resource waiting in an unmerged PR is absent — so every run flagged it as
new and opened another PR, and the timestamped branch names kept git-level
deduplication from kicking in.

Push now records each branch, PR URL and its resources in the machine-local
state, and splits the selection into one branch/PR per group:

- Resources already in an open PR force-push that branch, updating the PR
  in place and reusing its original namespace. An unchanged tree is not
  pushed, so a repeated push is a no-op.
- Everything else still gets its own new PR, so unrelated resources are
  never pulled into someone else's review. A partially selected PR also
  goes to a new PR, with a warning.
- Records are pruned once the branch is gone from origin or its resources
  reach the default branch, and kept when the remote is unreachable.

The listing marks these resources with `awaiting review: <url>`.

Co-authored-by: JasonRUAN <[email protected]>
Co-authored-by: Cursor <[email protected]>
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…lus review follow-ups (Tencent#359)

* fix(push): preserve other resources' open-PR records under --skill, plus review follow-ups

Follow-up fixes for the Tencent#350 open-PR-update feature, found in code review:

- push --skill: prune pending-push records against the full scan, not the
  narrowed single-skill list. Narrowing dropped every OTHER resource's
  open-PR record and the next run opened duplicate PRs for them.
- pushRepoBranch (reuse, no-op): delete the local branch when the rebuilt
  tree already matches the remote, matching the other early-exit paths so
  stale local branches don't accumulate.
- pushTeamConfigOnly: switch back to the default branch in the catch path so
  a mid-push failure never strands the team repo on the push branch.
- hasCommits: correct the comment to describe the real guard (the catch
  block), the command uses no --quiet.
- push: replace Chinese comment and error string with English (CLAUDE.md).
- docs: document the update-open-PR behavior in README (both langs) and
  usage-guide (both langs).

* fix(push): handle force-construct prune + multi-worktree branch delete

Address two correctness bugs found in review of the Tencent#350 follow-up:

- push --skill force-construct: when the scanner returns nothing for the
  target skill (local content is byte-identical to the team repo), the
  matchedItem was pushed into allItems but not fullScan, so
  prunePendingPushes dropped the skill's OWN open-PR record and the next
  run opened a duplicate. Add the force-constructed item to fullScan too.
- pushRepoBranch: three early-exit paths deleted the local branch right
  after switchToDefaultBranch, but when the default branch is held by
  another worktree the switch returns silently with HEAD still on the push
  branch, and `git branch -D` then throws an uncaught error out of the
  function. switchToDefaultBranch now reports whether it actually switched,
  and a new leaveAndDeletePushBranch helper skips the delete when it didn't.

Tests:
- force-constructed --skill keeps its own open-PR record (real skill dir on
  disk to exercise the force-construct path; fails without the fullScan fix).
- pushRepoBranch skips the delete without throwing when the default branch
  is busy in another worktree (fails without the guard).
- push-team-config: assert the catch path lands back on 'main' (not just
  off the stuck branch) and move logSpy.mockRestore into finally.

* test(push): pin bare repo default branch to main in initTeamRepos

CI failed on `config-only: switches back to the default branch when the
push throws` with `expected '' to be 'main'`. Root cause: the test harness's
`git init --bare` inherits the runner's init.defaultBranch. On a runner where
that is `master` (GitHub's ubuntu/macos images), the bare HEAD points at
`master` while the seed only ever pushes `main`, so `git clone` lands on an
unborn HEAD and the working clone has no local `main`. simple-git then reports
`.branch().current` as '' — which the tightened assertion (toBe('main'),
added for the reviewer's nit) surfaced.

Fix: pass --initial-branch=main to the bare init so the clone checks out main
regardless of the runner's git default. Reproduced locally with
GIT_CONFIG_GLOBAL forcing init.defaultBranch=master (full suite: 2341 pass).
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.

3 participants