Skip to content

fix(import): fail when the push to the team repo fails instead of reporting a publish - #1541

Merged
SaulMoro merged 3 commits into
Tencent:mainfrom
pcbeingused333:fix/import-dir-push-failure
Oct 29, 2026
Merged

SaulMoro merged 3 commits into
Tencent:mainfrom
pcbeingused333:fix/import-dir-push-failure

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Summary

teamai import --dir printed Pushed to team knowledge repo and exited 0 when the push to the team repo had been rejected (for example because another member pushed to main first). The unpushed import commit was then dropped by the next teamai push / teamai pull. autoPushTeamRepo now throws Push to the team repo failed: <git error line>. Run \teamai pull`, then rerun this command.; importCmd`'s existing handler prints it and exits 1.

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
  • npm run lint passes
  • npx vitest run src/__tests__/auto-push-team-repo.test.ts src/__tests__/import-dir.test.ts src/__tests__/team-ref.test.ts passes (56 tests); the full suite was not run
  • Added/updated tests for the change: auto-push-team-repo.test.ts (new, real bare remote and a second clone that pushes main first; fails on main) and a case in import-dir.test.ts (no Pushed... / import complete line, exit 1)

Real-CLI run after npm run build (isolated HOME, team on a local bare repo reached through url.<local>.insteadOf, teamai init ... --provider git, then a second clone pushes to the team main):

$ teamai init https://git.example.test/team/a.git --provider git --scope user --agent claude --role dev
✔ Member registered on the teamai-reports branch
✔ teamai initialized successfully!
$ (a second member pushes to the team main)
$ teamai import --dir ./svc --skip-enrich
ℹ teamwiki/ knowledge graph updated: svc
ℹ global graph-index.json aggregated (1 nodes, 0 edges)
✖ Push to the team repo failed: error: failed to push some refs to 'file:///<team repo>.git'. Run `teamai pull`, then rerun this command.
exit=1
$ teamai pull
exit=0
$ teamai import --dir ./svc --skip-enrich
✔ Pushed to team knowledge repo (https://git.example.test/team/a.git)
✔ Local directory svc import complete
exit=0
remote main has teamwiki/evidence/code/svc: yes (6 files)

Only the git provider and the Claude agent were exercised; github/gitlab and the other agents are left to CI.

Related Issues

Fixes #1539

Notes for Reviewers

  • autoPushTeamRepo (@deprecated) is also used by the iWiki import and the --from-claude path, so they now also fail with exit 1 on a rejected push instead of carrying on; the --from-claude path logs Import complete after the push instead of before it.
  • This is the first fix in the issue ("let the failure reach the caller"). Publishing through a branch, as import --from-repo does, changes how a team reviews the result and is left to the maintainers.

This change was made with Claude Code (Claude Sonnet 5.5).

pcbeingused333 and others added 2 commits October 28, 2026 21:34
…orting a publish

autoPushTeamRepo swallowed every push error as a warning, so import --dir printed
'Pushed to team knowledge repo' and exited 0 after a rejected push, and the
unpushed commit was later dropped by the next teamai push/pull. It now throws a
message with the next step; import's top-level handler prints it and exits 1.
The claude-rules path reports completion only after the push.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…t line

Satisfies preserve-caught-error and reports git's error:/fatal: line instead of the
remote URL line git prints first.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

No findings in the specified PR diff.

The PR description satisfies the testing requirement: it records a representative real-CLI run after npm run build, showing the rejected push exits 1 without reporting success, followed by a successful pull and re-import. Additional providers and agents are explicitly deferred to CI.

Reviewed only the diff against the trusted base review rules; did not run, build, or install PR code.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This was generated by AI during triage.

@pcbeingused333 Thanks for taking #1539. With the built CLI at 63c6d852 against main (2fa1ab2f): when another member has pushed main first, main prints Pushed to team knowledge repo, exits 0 and leaves the docs off the remote. This branch exits 1, and after teamai pull, rerunning the import exits 0 and publishes the docs. The success path is unchanged. DetachedTeamRepoError still passes through unchanged (team-ref.test.ts:268). tsc, lint and your three unit files pass, and the new auto-push-team-repo.test.ts fails on main. One thing blocks approval:

  • [P1 blocking] The message drops the reason the push failed, and its advice is wrong when main is protected. autoPushTeamRepo keeps the first error:/fatal: line. For a rejected push that is always git's generic error: failed to push some refs to '<url>'. The line that says why comes before it and is lost: ! refs/heads/main:refs/heads/main [rejected] (fetch first), or [remote rejected] (pre-receive hook declined) plus the hook's remote: lines. Main's warning showed them. With a pre-receive hook that refuses main (one of the cases #1539 names):

    1. teamai import --dir ./svc prints ✖ Push to the team repo failed: error: failed to push some refs to '<url>'. Run teamai pull, then rerun this command. and exits 1.
    2. teamai pull exits 0 and changes nothing.
    3. Rerunning the import fails with the same message. The clone is now two commits ahead, and nothing is published.

    The member is told to retry, with no cause shown, in a loop that can't succeed. Keep the ! line and any remote: lines in the message, or print git's whole message as #1538 does for deep-enrich. Give the Run teamai pull advice only for fetch first / non-fast-forward rejections.

Non-blocking:

  • [P3 nit] The new import-dir.test.ts case also passes on main, because importCmd already exits 1 when autoPushTeamRepo rejects. Only auto-push-team-repo.test.ts, against a real bare remote, separates main from this branch.

The iWiki import and --from-claude paths share autoPushTeamRepo. We read them (both now exit 1 on a failed push) but didn't run them. The gitlab/github providers, the other agents and Windows are left to CI. This merges cleanly with #1538, #1534, #1518, #1450 and #1379.

The CI review reported no findings. We agree the test record is enough, but it ran no code, so it couldn't see the protected-branch case.

… a pull only when main moved

Signed-off-by: Alex Castillo <[email protected]>
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks for the careful read and for running it. Pushed a follow-up commit for the P1:

  • autoPushTeamRepo now keeps every line that says why git refused: the ! ... [rejected] (fetch first) / [remote rejected] (pre-receive hook declined) ref line, the hook's remote: lines, and the error:/fatal: line (the remote URL line is still dropped).
  • The Run teamai pull, then rerun this command. advice is appended only for (fetch first) / (non-fast-forward) rejections, so a protected main or a hook rejection shows its cause with no retry advice.
  • auto-push-team-repo.test.ts (real bare remote) now asserts the (fetch first) text plus the advice, and has a new case with a pre-receive hook that declines: the message contains the hook's output and pre-receive hook declined, and no teamai pull. Both cases fail on the previous commit and pass now.

On the P3: agreed, the import-dir.test.ts case also passes on main; the bare-remote file is the one that separates the two.

Disclosure: this change was prepared with an AI coding agent (Claude).

@github-actions

Copy link
Copy Markdown

No findings in the specified PR diff. The earlier review also reported no findings, so none require a resolution update.

The PR description satisfies the testing requirement: it records a representative real-CLI run after npm run build, demonstrating a rejected push exits 1 without reporting success, followed by a successful pull and re-import. Additional providers and agents are explicitly deferred to CI.

Reviewed only the specified diff against the trusted base review rules. Did not run, build, or install PR code.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This was generated by AI during triage.

@pcbeingused333 Thanks, approving 203e1dce.

  • The P1 is fixed. With the built CLI at this head and the same fixtures as before:
    • When another member pushed main first, the import exits 1 with ✖ Push to the team repo failed: ! refs/heads/main:refs/heads/main [rejected] (fetch first), git's error: line and Run `teamai pull`, then rerun this command.. Following that, teamai pull realigns the clone and the rerun publishes the docs (14 svc files on the remote).
    • With a pre-receive hook refusing main, it exits 1 with [remote rejected] (pre-receive hook declined) and remote: main is protected, and gives no pull advice.
    • The success path is unchanged.
  • Tests. The bare-remote test now covers both cases, and the hook case fails on the previous commit.
  • Against current main. 203e1dce merges cleanly with main at f7e11fe4.

The record in the body is from the earlier commit and doesn't show the hook case. The run above covers it. In the protected-main case the unpushed import commit stays in the clone, which is the branch-publishing question #1539 leaves to the maintainers. The CI review found nothing, and we agree.

#1543 fixes the same issue. With this one merged, we'll close it with thanks.

@SaulMoro
SaulMoro merged commit 793e035 into Tencent:main Oct 29, 2026
18 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…orting a publish (Tencent#1541)

teamai import --dir printed 'Pushed to team knowledge repo' and exited 0 when the push to the team repo was rejected, and the next push or pull dropped the unpushed import. autoPushTeamRepo now throws: the message keeps git's reason (the rejected ref line and the hook's remote: lines), and advises `teamai pull` only when main moved (fetch first or non-fast-forward). Import commands exit 1. Closes Tencent#1539.
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.

[bug] import --dir reports a publish that failed, and the next push drops the imported docs

3 participants