Skip to content

fix(deep-enrich): retry missing AI docs after temporary failures - #491

Merged
jeff-r2026 merged 2 commits into
Tencent:mainfrom
jimpablo:fix/488-deep-enrich-retry
Sep 11, 2026
Merged

jeff-r2026 merged 2 commits into
Tencent:mainfrom
jimpablo:fix/488-deep-enrich-retry

Conversation

@jimpablo

Copy link
Copy Markdown
Contributor

Summary

A temporary AI failure during deep enrichment left component and architecture documents missing, but the engine still saved phase: \"done\". The next run skipped the missing AI work because deterministic graph markdown kept docs/ nonempty, and the public command still reported complete: true.

Resume now treats files on disk as the source of truth: missing docs/<slug>.md and docs/architecture.md are retried, completed AI docs and G1/G2/G3 graph files are preserved, and teamai codebase --deep-enrich reports incomplete work in English instead of claiming full completion.

Fixes #488.

Type of Change

  • Bug fix (non-breaking change that fixes an existing 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 — clean
  • npx vitest run src/__tests__/codebase-deep-enrich.test.ts src/__tests__/deep-enrich-graph-preserve.test.ts — 10/10 passed (AI client mocked; no live LLM)
  • Fail then recover: first codebaseCmd --deep-enrich with rejecting AI writes graph docs, omits Auth.md / architecture.md, JSON complete: false; second call with recovered mocks writes those AI docs and keeps G1 unchanged
  • Fail again: a later rejecting retry still reports complete: false / Deep enrichment incomplete with missing component and architecture docs listed
  • Completed Auth.md is preserved when architecture generation still fails
  • Did not spawn a live enrich on the built CLI (AI hang up to 600s)

Related Issues

Fixes #488. Related to #480 / #360 (does not close #360).

Notes for Reviewers

  • Public entry is still teamai codebase --deep-enrich --project <slug> --output <repo>.
  • Hidden teamai deep-enrich is unchanged.
  • Incomplete runs set process.exitCode = 1 and print Deep enrichment incomplete.
  • Graph generation remains deterministic and may rewrite G1/G2/G3 with the same content; existing component/architecture files are not overwritten.

Resume from files on disk so a skipped AI phase does not stay stuck at
phase done once deterministic graph markdown fills docs/. The public
codebase --deep-enrich command reports incomplete work instead of
complete true.

Fixes Tencent#488.
@jeff-r2026

jeff-r2026 commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Found a locally reproduced regression that I recommend fixing before merging: after a new code extraction, existing component and architecture documents are treated as complete indefinitely, even when they describe the previous code, and the CLI reports success.

Tested PR HEAD: 41155e79736b885c1373f4ad68b70b6f194e0b57; parent used for comparison: 9e7adc79faa03ef4c3a49cb7a148bba83b7dc1f3.

Cause and affected workflow

deep-enrich.ts L817–830 now skips component and architecture generation based only on file existence. This also removes the previous invalidation check for manifest.generatedAt > progress.startedAt.

This affects running codebase --extract again after deep documents have already been generated: extraction writes a new manifest without clearing existing docs/. If component slugs remain unchanged, changes to responsibilities, interfaces, or dependencies do not trigger regeneration. The architecture document also remains stale. Repeated deep-enrich runs continue skipping these files.

Minimal reproduction using the built CLI (no AI service needed)

Run this from the PR checkout. The fixture represents the on-disk state after extraction updates the manifest while older documents and completed progress remain. This does not claim to run a full extraction against a live AI service.

npm ci --ignore-scripts
npm run build
node --input-type=module <<'JS'
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pr491-stale-'));
const evidence = path.join(root, 'teamwiki/evidence/code/demo');
fs.mkdirSync(path.join(evidence, 'docs'), { recursive: true });
fs.mkdirSync(path.join(evidence, '_review'), { recursive: true });
fs.writeFileSync(path.join(evidence, '_manifest.json'), JSON.stringify({
  project: 'demo', generatedAt: '2026-09-11T00:00:00Z',
  components: [{ slug: 'Auth', responsibilities: ['NEW OAuth flow'] }], edges: []
}));
fs.writeFileSync(path.join(evidence, '_review/progress.json'), JSON.stringify({
  project: 'demo', phase: 'done', componentsDone: ['Auth'], componentsPending: [],
  startedAt: '2026-01-01T00:00:00Z', updatedAt: '2026-01-01T00:00:00Z'
}));
fs.writeFileSync(path.join(evidence, 'docs/Auth.md'), '# OLD password flow');
fs.writeFileSync(path.join(evidence, 'docs/architecture.md'), '# OLD architecture');
const run = spawnSync(process.execPath, [
  'dist/index.js', 'codebase', '--deep-enrich', '--project', 'demo',
  '--output', root, '--json'
], { encoding: 'utf8' });
console.log(run.stdout);
console.log('exit code:', run.status);
assert.equal(run.status, 0);
assert.match(run.stdout, /"complete": true/);
assert.equal(fs.readFileSync(path.join(evidence, 'docs/Auth.md'), 'utf8'), '# OLD password flow');
assert.equal(fs.readFileSync(path.join(evidence, 'docs/architecture.md'), 'utf8'), '# OLD architecture');
console.log('REPRODUCED: success reported, both documents still contain old content.');
console.log('fixture:', root);
JS

Actual output from the built CLI, with paths and routine logs omitted:

Phase 3 — Generating deterministic graph docs
Phase 4 — Generating AI graph docs (G5/G6)
Phase 5 — Index enhancement
Deep knowledge generation complete
{
  "project": "demo",
  "complete": true,
  "missingComponents": [],
  "missingArchitecture": false
}

Exit code: 0. Auth.md still contains # OLD password flow, and architecture.md still contains # OLD architecture. Neither Phase 1 nor Phase 2 runs. I also reran the exact reproduction script above successfully before posting.

Parent comparison and validation scope

Separately, I ran the same fixture against the parent and PR implementations in Vitest, with the AI client returning fixed new text (no live LLM calls):

  • Parent: detects progress_stale=true, runs Phase 1/2, and replaces the two documents with # NEW Auth and # NEW architecture.
  • PR: preserves both old documents and returns complete: true.
  • npm run build passed.
  • The PR's existing codebase-deep-enrich.test.ts and deep-enrich-graph-preserve.test.ts passed 10/10. They do not cover invalidation after the input changes.

Please retain input-version invalidation alongside file-based resume: completed documents can be preserved when retrying failures for the same input, but a newer manifest should invalidate the corresponding old component/architecture documents (and G5). A regression test with existing documents plus an updated manifest would cover this case.

@jeff-r2026
jeff-r2026 self-requested a review September 11, 2026 02:41
File-based resume still retries missing docs for the same extract. A newer
_manifest.json generatedAt now drops stale component, architecture, and G5
files so extract → deep-enrich regenerates them instead of reporting success
with old content.
@jimpablo

Copy link
Copy Markdown
Contributor Author

Thanks — that was a real regression from dropping the manifest.generatedAt > progress.startedAt check.

Pushed 3daa3bd on this branch:

  • Same-extract resume is still file-based (retry missing AI docs; keep completed ones and G1/G2/G3).
  • A newer extract manifest invalidates component docs, architecture.md, and G5, then regenerates them.
  • If AI is still down after that invalidation, the CLI reports complete: false instead of success with the old files.

Covered by two handler tests on codebaseCmd (mocked AI, no live LLM): newer manifest + recovered AI replaces the docs; newer manifest + failing AI does not keep the stale files or report complete.

@jeff-r2026
jeff-r2026 merged commit 34e1cfb into Tencent:main Sep 11, 2026
7 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…cent#491)

* fix(deep-enrich): retry missing AI docs after temporary failures

Resume from files on disk so a skipped AI phase does not stay stuck at
phase done once deterministic graph markdown fills docs/. The public
codebase --deep-enrich command reports incomplete work instead of
complete true.

Fixes Tencent#488.

* fix(deep-enrich): invalidate AI docs when extract manifest is newer

File-based resume still retries missing docs for the same extract. A newer
_manifest.json generatedAt now drops stale component, architecture, and G5
files so extract → deep-enrich regenerates them instead of reporting success
with old content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants