Skip to content

fix(import,init): fail the command when deep enrich or local-agent init fails - #1544

Closed
kittimzhe wants to merge 1 commit into
Tencent:mainfrom
kittimzhe:fix/exit-codes-import-init-1500
Closed

kittimzhe wants to merge 1 commit into
Tencent:mainfrom
kittimzhe:fix/exit-codes-import-init-1500

Conversation

@kittimzhe

Copy link
Copy Markdown
Contributor

Closes the remaining Part 1 rows of #1500 (A3–A5), following the pull exit-1 fix in #1512.

Summary

  • teamai import --dir <src> / --from-repo: an incomplete deep enrich printed Deep enrich complete and exited 0, and a deep-enrich throw (refused symlink, lock, I/O) surfaced only in the debug log — both with ✔ … import complete and exit 0 after them. reconcileAndDeepEnrich now reads deepEnrich's result: an incomplete run prints a warning naming what is missing plus the teamai codebase --deep-enrich --project <slug> retry command, a throw is logged at warning level, both set process.exitCode = 1, and the extracted evidence is still published — matching the exit-1 precedent codebase --deep-enrich (src/codebase-cmd.ts:165) and the deep-enrich command (src/deep-enrich.ts:853) already set. import was the odd one out.
  • teamai init --http <url> --token <t> over an existing local agent without --force: initLocalAgentHttp throws "already initialized. Re-run with --force", but init caught it at debug level and still printed ✔ teamai initialized (HTTP read-only)!, so the old endpoint and token stayed while the member read a success line. The catch now logs the local agent's error (which names --force) at error level, sets process.exitCode = 1, and returns before the success line — the same shape reconcileHooksForInit above it already uses. With --force nothing changes.

Hooks keep their own rule: only import/init a person or script started is affected; --silent hook pulls and recordGitHookFailure are untouched (#1512 territory).

Testing

  • importLocalCheckout through its command entry, deep-enrich.js mocked at the module boundary:
    • fails the command when deep enrich leaves docs missing, and still publishes the evidence — warning names missing component docs: src, missing architecture.md and the retry command, no Deep enrich complete line, exit 1, overview.md published (A3).
    • exits 0 and reports completion when deep enrich completes.
    • fails the command when deep enrich throws — warning carries the error and the retry command, exit 1 (A4).
  • init --http through the real init() entry with the mock team server: a forced init seeds the local agent, a second init without --force (overwrite confirmation answered) logs HTTP local agent is already initialized with --force, prints no success line, and exits 1; the --force run before it succeeds as today (A5).
  • Full suites import-codebase.test.ts + http-repo-integration.test.ts (31 tests), tsc --noEmit, oxlint --type-aware clean.
  • docs/guide and skill-data grepped: no text claims a failed deep enrich or init --http exits 0 or is non-blocking, so no doc changes.

Real-CLI verification (npm run build, then the built CLI)

import --dir with no working AI tool on a stripped PATH, isolated HOME, after a source change (A3+A4 shape):

$ node dist/cli.js import --dir /tmp/1500-cli/repo/svc --output /tmp/1500-cli/out --incremental
ℹ deep-enrich[svc]: Phase 1 — Generating 1 component design docs
⚠ deep-enrich[svc]: batch[0] partially failed, falling back to sequential
⚠ Deep enrich incomplete: missing component docs: a.ts, missing architecture.md. Run `teamai codebase --deep-enrich --project svc` to retry.
ℹ Output written: /tmp/1500-cli/out/teamwiki
✔ Local directory svc import complete
$ echo $?
1

The evidence is published and the import still completes its report; before this PR the third line read ℹ Deep enrich complete: svc and the exit status was 0.

init --http twice without --force needs a live team server, so it is covered through the real init() entry over the mock server in the test above rather than a run against a real endpoint.

Breaking Changes

None for interactive members: the message and evidence are unchanged, only the exit status and the log level of the failure lines. Scripts that matched on exit 0 from a failed deep enrich or a blocked init --http now see 1, as #1500 specifies.

Checklist

  • Tests added/updated and passing
  • Lint and typecheck clean
  • CHANGELOG Changed entry added

…it fails

An incomplete or failed deep enrich in `teamai import` printed 'Deep
enrich complete' or logged the error below notice level and exited 0,
and `teamai init --http` reported success when the local agent was
already initialized and --force was not given, leaving the old endpoint
and token in place. Scripts, CI jobs and git hooks read the exit status
and carried on as if the commands had worked (Tencent#1500 Part 1, A3-A5).

import now reports what a deep enrich missed with the retry command and
exits 1 while still publishing the extracted evidence, and a deep-enrich
throw is logged at warning level and exits 1, matching the exit-1
precedent of `codebase --deep-enrich` and the `deep-enrich` command.
init --http logs the local agent's error and exits 1 without the success
line.
@github-actions

Copy link
Copy Markdown

No findings in the specified diff.

The PR description satisfies the testing requirement: it records npm run build followed by a representative real-CLI import run that exits 1 and still publishes evidence. The HTTP init case is covered by an integration test; a full provider × agent matrix is not required.

Review was read-only. I 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.

@kittimzhe Thanks for picking up #1500's Part 1 rows. #1534 (opened earlier) fixes the same rows A3 to A5. We review both in full, the first one ready merges, and the other closes. Several points below are already fixed there, so it's worth reading #1534 and our review on it.

With the built CLI at 70fa38a8 against main (f7e11fe4): an incomplete deep enrich on import --dir, --from-repo and --from-repo-list now exits 1, names what's missing, drops Deep enrich complete and still publishes the evidence. A deep-enrich throw shows as a warning and exits 1. A complete run and init --http --force are unchanged. tsc, lint and the two changed test files pass, and the three new tests fail on main. What blocks approval:

  • [P1 blocking] The first init --http on a clean machine now fails. In an empty HOME, teamai init --http http://127.0.0.1:9/a --token t1 --scope user prints ✖ Local agent init: HTTP local agent is already initialized. Re-run with --force to overwrite. and exits 1. Main exits 0 with ✔ teamai initialized (HTTP read-only)!. The legacy backfill in loadLocalAgentConfig reads the config.yaml that init has just written, so the agent looks initialized before it is. The new test misses this because it seeds the local agent with --force in project scope. Any endpoint works for this check, even an unreachable one. A live server isn't needed.
  • [P1 blocking] The printed retry fails with --output. teamai import --dir <src> --output <dir> prints teamai codebase --deep-enrich --project <slug> without the output directory. Run as printed, it gives No teamwiki found and exit 1. The --output run in your record has the same retry line.
  • [P1 blocking] In a team repo, the printed retry never publishes. codebase --deep-enrich writes the docs into the team clone but doesn't commit or push them, and the next teamai push refuses the dirty clone. This is #1537, and it's the point still open on #1534. Pointing a member at that command makes things worse until #1537 is fixed, so the retry needs to work in a team repo, or name a command that does.
  • [P2 non-blocking, but it fits this PR] Paths documented as non-blocking now exit 1. ci extract-mr --mode write and the teamwiki update in import --from-mr treat deep enrich as best effort, and with this change an incomplete enrich makes them exit 1. #1534 keeps them at 0. We found this in the code; it needs an MR API to run.
  • [P2 non-blocking, but it fits this PR] A refused init --http has already written files. By the time it refuses, it has saved the project config and the API key, as the log above shows. Refusing before writing anything leaves the member's previous setup intact.

Non-blocking:

  • [P3 nit] The body says init --http needs a live server to test. An unreachable endpoint is enough.

All CI checks are green at this head. The CI review found nothing and judged the record sufficient. We agree on the record, but it ran no code, so it couldn't see the first three points.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@kittimzhe Thanks for this. #1534 fixed the same #1500 rows and was ready first, so it's merged (5807b7da) and #1500 is closed. It also covers the points from our review here: a first init --http exits 0, a refused one writes nothing, the printed retry works with --output and in a team repo, and ci extract-mr / --from-mr stay best effort. Closing this one as a duplicate, per how we handle two PRs for one issue.

@SaulMoro SaulMoro closed this Oct 29, 2026
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