Skip to content

fix(import): publish the learning import --from-mr extracts (#823) - #825

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
SaulMoro:fix-823-import-mr-and-cleanup
Sep 25, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
SaulMoro:fix-823-import-mr-and-cleanup

Conversation

@SaulMoro

@SaulMoro SaulMoro commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

teamai import --from-mr never published its learning, although it reported the push as done. It now takes teamai contribute's path: queue, then publish on teamai-learnings, in the active project's learnings namespace when contribute would use one. Also #823's three Cleanup items.

 import --from-mr
+  resolveLearningsSubdir (contribute's): one active learnings namespace -> <ns>/, else the root
   Extract learning from MR
-    write learning -> learnings-wt/learnings/            (never committed: autoPushViaMR commits team-repo/)
+    write learning -> pending-learnings/[<ns>/]          (the contribute queue)
+  Publish learning
+    publishQueuedLearnings -> commit + push teamai-learnings, drop the entry once on origin
+    failed -> "Learning saved locally (…); the next `teamai pull` publishes it"
+    rebuild the recall index (as contribute)
   Incremental teamwiki update
-  Push changes via MR   when learning || teamwiki changed   (the learning was never in that checkout)
+  Push changes via MR   when teamwiki changed
+ read-only (HTTP) source -> refused up front, as contribute (--dry-run / --output still work)
Case Before After
import --from-mr ✔ Push changes via MR; learning untracked in learnings-wt; nothing on team.git learning on teamai-learnings; worktree clean
one active project, learnings namespace alpha shared learnings/ root, recalled by every project learnings/alpha/, as contribute
publishing fails same as the first row queued, says so; next teamai pull publishes it
HTTP source learning written, never published read-only HTTP source error, nothing queued; --dry-run previews
two learnings, same title and day one file, the second overwrites it two files (contribute's name, random suffix)
wiki slug of a main checkout opened through a symlink alias alias (its worktrees: my-repo) my-repo
labels for github.com/acme/api, /x/acme/api, /y/other/api acme/api twice (one stats --by-repo row) acme/api, /x/acme/api, other/api
local-agent.test.ts in overlapping runs fails in 12 of 16 0 of 16

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: 307 files, 4781 passed, 1 skipped
  • Added/updated tests: e2e import-mr-publish-823.test.ts (11 cases); unit cases in anchors.test.ts (slug) and session-analytics.test.ts (labels, bare repo still one row); local-agent.test.ts uses a session id unique per run
  • E2E locally: the new file, codebase-extract-cli, repo-attribution-worktrees-809, multi-project, learnings-sync-704-705: 5 files, 29 passed. CI runs the rest.

The e2e drives the built CLI: sandbox HOME, local bare team repo (provider github), user scope, git mode, fake gh/claude.

teamai pull; teamai import --from-mr https://github.com/acme/app/pull/7 --all
reachable       at the root of teamai-learnings; learnings-wt clean; queue empty;
                recall indexes the published copy; a second import keeps both files
project alpha   `alpha` owns learnings `alpha` and is active: under learnings/alpha/, not "saved locally"
stuck entry     an unreadable older queue entry stays; this learning still publishes
offline         team.git moved away during the import: queued + "Learning saved locally";
                back, then `teamai pull` -> published, queue empty
HTTP source     "read-only HTTP source", nothing queued; --dry-run still previews
Build Result
origin/main 10 of 11 fail (the --dry-run case passes on both), e.g. expected [] to have a length of 1 but got +0 (nothing on teamai-learnings)
this PR, namespace change reverted 1 of 11 fails: expected [ 'learnings' ] to deeply equal [ 'learnings/alpha' ]
this PR 11 of 11 pass

Reverting any one of 13 parts and rebuilding fails a test: queue write, publish step, "saved locally" line, per-learning status, index rebuild, HTTP guard, its dry-run exemption, filename, namespace in the queue path, namespace in the status check, slug rule, remote-label rule, its directory fallback. Flake: local-agent.test.ts, 4 in parallel × 4 rounds: 12 of 16 fail before, 0 after.

Reproduced with the real CLI (git mode, sandbox HOME, fake gh/claude)
# origin/main
$ teamai import --from-mr https://github.com/acme/app/pull/7 --all
✔ Extract learning from MR
↓ Incremental teamwiki update [SKIPPED: No existing evidence for this repo]
✔ Push changes via MR
$ git -C ~/.teamai/learnings-wt status --short
?? learnings/
$ git -C team.git ls-tree -r --name-only teamai-learnings
fatal: Not a valid object name teamai-learnings

# this PR
$ teamai import --from-mr https://github.com/acme/app/pull/7 --all
✔ Extract learning from MR
✔ Publish learning
↓ Incremental teamwiki update [SKIPPED: No existing evidence for this repo]
↓ Push changes via MR [SKIPPED: No teamwiki changes to push]
$ git -C ~/.teamai/learnings-wt status --short
$ git -C team.git ls-tree -r --name-only teamai-learnings
.gitignore
learnings/retry-flaky-s3-uploads-2026-09-24-58z251.md

Read in the code, not run with the real CLI:

  • Self mode runs contribute's .gitignore self-heal before the steps.
  • No real GitHub/GitLab/TGit MR or AI CLI: both are stand-ins, and only the publish path is under test.
  • A learning 0.22 already left untracked in learnings-wt stays there; teamai contribute --file <path> publishes it.
  • The supersede check reads only the top level of each directory, so it skips namespaced learnings, queued or published (as on main).

Related Issues

Part of #823: items 1 and 6 and the three Cleanup items. Items 2-5 follow once #819 is merged.

Notes for Reviewers

  • Same path as contribute. publishQueuedLearnings publishes the whole queue, so an older queued contribution goes out with this one. The commit message and the namespace rule (resolveLearningsSubdir: zero or several active namespaces mean the shared root) are contribute's.
  • Flaky test. Test-only: the markers are machine-wide files in os.tmpdir() keyed by session id (src/local-agent.ts:1117, :1192); the fixed id let overlapping runs delete each other's.
  • Reversible. No new state. rebuildIndexAfterContribute, generateFilename and resolveLearningsSubdir are now exported.
  • Docs: usage-guide{,.zh-CN}.md (--from-mr publishing and its namespace, slug rule, HTTP read-only list), the --project help, and commands.md regenerated.

@github-actions

Copy link
Copy Markdown

No findings.

The PR description includes a representative real-CLI end-to-end verification, so it satisfies the runtime-change testing requirement. Reviewed only the specified diff; no tests or PR code were executed.

@SaulMoro
SaulMoro force-pushed the fix-823-import-mr-and-cleanup branch from d31c026 to 5db2158 Compare September 24, 2026 23:09
@github-actions

Copy link
Copy Markdown
  • [P2 non-blocking] Clarify the HTTP-mode exception — docs/usage-guide.md:506 and docs/usage-guide.zh-CN.md:469 state that import --from-mr is entirely unavailable, but src/import.ts:245 explicitly permits --dry-run and --output. Document that only publishing mode is unavailable to avoid misleading HTTP users.

The PR description includes sufficient representative real-CLI end-to-end verification. No PR code or tests were executed.

…t#823)

`import --from-mr` wrote its learning into the teamai-learnings worktree,
then pushed with autoPushViaMR, which commits `.` in repo.localPath: the
knowledge clone, another checkout. That found nothing to commit, so the
learning stayed untracked on this machine and never reached the team,
while the command still reported the push step as done.

The draft now goes into the contribution queue, and a "Publish learning"
step calls publishQueuedLearnings, the path `teamai contribute` uses: it
commits and pushes the queue on teamai-learnings and drops an entry once
it is on origin. When publishing fails the learning stays queued, the step
says so, and the next `teamai pull` publishes it. As in contribute, the
queued file takes contribute's name (a random suffix keeps two learnings
with the same title and day apart), the recall index is rebuilt after the
publish attempt, the supersede check also reads the queue, and a read-only
(HTTP) source is refused up front instead of queueing a learning nothing
can publish; --dry-run and --output still work there. "Push changes via
MR" is left for the teamwiki update it was also for.

The learning also lands where contribute puts it: resolveLearningsSubdir
(now exported) picks learnings/<namespace>/ when exactly one active project
declares a learnings namespace, else the shared root. It used to go to the
root, where every project's members recall it.

Also, from the same follow-up issue:
- wiki slug: the main checkout's root takes its repo's name too, so one
  opened through a differently named symlink writes the same evidence as
  its worktrees. Subdirectories keep their own name.
- repo labels: a path is not qualified into a label a remote-form key
  already has (github.com/acme/api vs /x/acme/api), so the two no longer
  merge in `stats --by-repo`. The fallback is the repo's directory, so a
  bare repo's keys still share one row.
- local-agent tests use a session id unique per run: the hint markers are
  machine-wide files in os.tmpdir() keyed by session id, and overlapping
  runs deleted each other's.
@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Re the P2 in #825 (comment): fixed in 91e11ce. The HTTP read-only line in docs/usage-guide.md and docs/usage-guide.zh-CN.md now reads "push / contribute / remove are not available, and import --from-mr cannot publish its learning (--dry-run and --output still work)", which matches the guard in src/import.ts.

@SaulMoro
SaulMoro force-pushed the fix-823-import-mr-and-cleanup branch from 5db2158 to 91e11ce Compare September 24, 2026 23:22
@github-actions

Copy link
Copy Markdown

No findings.

The earlier HTTP-mode documentation issue is resolved: both usage guides now clarify that publishing is unavailable while --dry-run and --output remain supported.

The PR description includes sufficient representative real-CLI end-to-end verification for the runtime changes. Reviewed only the specified diff; no PR code, tests, builds, or installs were executed.

@jeff-r2026
jeff-r2026 merged commit 4a65e3f into Tencent:main Sep 25, 2026
11 checks passed
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Sep 25, 2026
…ashboard; show the MR import prompt (Tencent#823)

Three places that decide which learnings are found, and the MR import
prompt.

Recall index rebuild (item 12). When recall had to build a missing index,
one unreadable roles.yaml or projects.yaml failed the whole build:
deliveredIndexSources and resolveActiveLearningsNamespaces threw, the error
went to log.debug, and recall said "No learnings available. Run `teamai
pull` first", which pull does not fix. Each now runs in its own try.
Learnings do not depend on the manifests and are always indexed: a broken
projects.yaml leaves only the shared root, never every namespace. Docs,
rules and skills get empty lists (undefined would index the whole trees),
and one warning names the cause; a broken projects.yaml, which both read,
gives one warning for both. The partial index is saved like any
other, so later recalls stay quiet and the next pull rebuilds it whole. A
skills collision with no index to keep skills from indexed none silently;
IndexedSkills' keep-indexed now carries the conflict line and recall shows
it when there are no indexed skills to keep (no index, or an older one).
Any other build failure is shown with its cause, not as "No learnings
available".

import --from-mr duplicate check (item 9). The scan listed only each root's
top level, so learnings under learnings/<ns>/, where Tencent#825 files MR
learnings, were never compared. Its result fed only a "marking as
superseded" warning, and nothing stored or read LearningDraft.supersedes,
so the claim was false. The scan (now findOverlappingLearnings) also walks
the active project namespaces, as the index does (safe single segments,
first root wins per relative path), and the warning becomes a
possible-duplicate notice naming the files. `import` ran the extraction as a task,
with the logger silenced, so importFromMR's warning never reached the
terminal; the extraction now runs before the tasks (item 18), where the
logger prints it. The namespaces are resolved first: a broken projects.yaml narrows the check to the
shared root with a warning, as recall does, so --dry-run and --output keep
working. LearningDraft.supersedes and SUPERSEDE_THRESHOLD are removed. The
CI extractor still reads only the root (it has no LocalConfig).

Dashboard knowledge report (item 16). Its fallback index, built when no
search index exists, passed no learningsNamespaces, so project learnings
were missing in both scopes; in user scope it read learningsRoots().read,
which keeps another repository's learnings checkout in the write root
(Tencent#808). It now uses indexableLearningsRoots in user scope, as project scope
already did, and resolves the active namespaces with the paths. A broken
projects.yaml leaves the shared root, with a warning when the report builds
its own index.

import --from-mr prompt (item 18). importFromMR, which asks "Accept
learning? [Y/n]" on a readline, ran inside the first listr2 task. In a
terminal the default renderer holds stdout back while a task runs, so only a
spinner showed and the prompt appeared after it was answered. The
extraction now runs before the task list, which starts at "Publish
learning" with the extraction's result as its context.
jeff-r2026 pushed a commit that referenced this pull request Sep 26, 2026
…ashboard; show the MR import prompt (#823) (#834)

* fix(learnings): find learnings despite a broken manifest and in the dashboard; show the MR import prompt (#823)

Three places that decide which learnings are found, and the MR import
prompt.

Recall index rebuild (item 12). When recall had to build a missing index,
one unreadable roles.yaml or projects.yaml failed the whole build:
deliveredIndexSources and resolveActiveLearningsNamespaces threw, the error
went to log.debug, and recall said "No learnings available. Run `teamai
pull` first", which pull does not fix. Each now runs in its own try.
Learnings do not depend on the manifests and are always indexed: a broken
projects.yaml leaves only the shared root, never every namespace. Docs,
rules and skills get empty lists (undefined would index the whole trees),
and one warning names the cause; a broken projects.yaml, which both read,
gives one warning for both. The partial index is saved like any
other, so later recalls stay quiet and the next pull rebuilds it whole. A
skills collision with no index to keep skills from indexed none silently;
IndexedSkills' keep-indexed now carries the conflict line and recall shows
it when there are no indexed skills to keep (no index, or an older one).
Any other build failure is shown with its cause, not as "No learnings
available".

import --from-mr duplicate check (item 9). The scan listed only each root's
top level, so learnings under learnings/<ns>/, where #825 files MR
learnings, were never compared. Its result fed only a "marking as
superseded" warning, and nothing stored or read LearningDraft.supersedes,
so the claim was false. The scan (now findOverlappingLearnings) also walks
the active project namespaces, as the index does (safe single segments,
first root wins per relative path), and the warning becomes a
possible-duplicate notice naming the files. `import` ran the extraction as a task,
with the logger silenced, so importFromMR's warning never reached the
terminal; the extraction now runs before the tasks (item 18), where the
logger prints it. The namespaces are resolved first: a broken projects.yaml narrows the check to the
shared root with a warning, as recall does, so --dry-run and --output keep
working. LearningDraft.supersedes and SUPERSEDE_THRESHOLD are removed. The
CI extractor still reads only the root (it has no LocalConfig).

Dashboard knowledge report (item 16). Its fallback index, built when no
search index exists, passed no learningsNamespaces, so project learnings
were missing in both scopes; in user scope it read learningsRoots().read,
which keeps another repository's learnings checkout in the write root
(#808). It now uses indexableLearningsRoots in user scope, as project scope
already did, and resolves the active namespaces with the paths. A broken
projects.yaml leaves the shared root, with a warning when the report builds
its own index.

import --from-mr prompt (item 18). importFromMR, which asks "Accept
learning? [Y/n]" on a readline, ran inside the first listr2 task. In a
terminal the default renderer holds stdout back while a task runs, so only a
spinner showed and the prompt appeared after it was answered. The
extraction now runs before the task list, which starts at "Publish
learning" with the extraction's result as its context.

* fix(learnings): address review — write the partial recall index past the shrink guard (#823)

With a manifest recall cannot read, the rebuild leaves docs, rules and
skills out on purpose. Against an older-format index of a full corpus the
result is under 20% of it, so buildIndex's shrink guard kept the old file
and recall searched the entries its warning said were left out. The
degraded rebuild now passes `partial`, which skips the guard; every other
build keeps it.

* fix(learnings): address review — skip the older recall index when the partial one cannot be written (#823)

* fix(learnings): address review — show queued learnings in the dashboard's fallback index (#823)

The dashboard's temporary index now reads the contribution queue, as recall's
does; promotion and prune candidates keep to the published roots. The recall
rule tells the agent to relay the skipped-older-index warning.
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…t#823) (Tencent#825)

`import --from-mr` wrote its learning into the teamai-learnings worktree,
then pushed with autoPushViaMR, which commits `.` in repo.localPath: the
knowledge clone, another checkout. That found nothing to commit, so the
learning stayed untracked on this machine and never reached the team,
while the command still reported the push step as done.

The draft now goes into the contribution queue, and a "Publish learning"
step calls publishQueuedLearnings, the path `teamai contribute` uses: it
commits and pushes the queue on teamai-learnings and drops an entry once
it is on origin. When publishing fails the learning stays queued, the step
says so, and the next `teamai pull` publishes it. As in contribute, the
queued file takes contribute's name (a random suffix keeps two learnings
with the same title and day apart), the recall index is rebuilt after the
publish attempt, the supersede check also reads the queue, and a read-only
(HTTP) source is refused up front instead of queueing a learning nothing
can publish; --dry-run and --output still work there. "Push changes via
MR" is left for the teamwiki update it was also for.

The learning also lands where contribute puts it: resolveLearningsSubdir
(now exported) picks learnings/<namespace>/ when exactly one active project
declares a learnings namespace, else the shared root. It used to go to the
root, where every project's members recall it.

Also, from the same follow-up issue:
- wiki slug: the main checkout's root takes its repo's name too, so one
  opened through a differently named symlink writes the same evidence as
  its worktrees. Subdirectories keep their own name.
- repo labels: a path is not qualified into a label a remote-form key
  already has (github.com/acme/api vs /x/acme/api), so the two no longer
  merge in `stats --by-repo`. The fallback is the repo's directory, so a
  bare repo's keys still share one row.
- local-agent tests use a session id unique per run: the hint markers are
  machine-wide files in os.tmpdir() keyed by session id, and overlapping
  runs deleted each other's.
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…ashboard; show the MR import prompt (Tencent#823) (Tencent#834)

* fix(learnings): find learnings despite a broken manifest and in the dashboard; show the MR import prompt (Tencent#823)

Three places that decide which learnings are found, and the MR import
prompt.

Recall index rebuild (item 12). When recall had to build a missing index,
one unreadable roles.yaml or projects.yaml failed the whole build:
deliveredIndexSources and resolveActiveLearningsNamespaces threw, the error
went to log.debug, and recall said "No learnings available. Run `teamai
pull` first", which pull does not fix. Each now runs in its own try.
Learnings do not depend on the manifests and are always indexed: a broken
projects.yaml leaves only the shared root, never every namespace. Docs,
rules and skills get empty lists (undefined would index the whole trees),
and one warning names the cause; a broken projects.yaml, which both read,
gives one warning for both. The partial index is saved like any
other, so later recalls stay quiet and the next pull rebuilds it whole. A
skills collision with no index to keep skills from indexed none silently;
IndexedSkills' keep-indexed now carries the conflict line and recall shows
it when there are no indexed skills to keep (no index, or an older one).
Any other build failure is shown with its cause, not as "No learnings
available".

import --from-mr duplicate check (item 9). The scan listed only each root's
top level, so learnings under learnings/<ns>/, where Tencent#825 files MR
learnings, were never compared. Its result fed only a "marking as
superseded" warning, and nothing stored or read LearningDraft.supersedes,
so the claim was false. The scan (now findOverlappingLearnings) also walks
the active project namespaces, as the index does (safe single segments,
first root wins per relative path), and the warning becomes a
possible-duplicate notice naming the files. `import` ran the extraction as a task,
with the logger silenced, so importFromMR's warning never reached the
terminal; the extraction now runs before the tasks (item 18), where the
logger prints it. The namespaces are resolved first: a broken projects.yaml narrows the check to the
shared root with a warning, as recall does, so --dry-run and --output keep
working. LearningDraft.supersedes and SUPERSEDE_THRESHOLD are removed. The
CI extractor still reads only the root (it has no LocalConfig).

Dashboard knowledge report (item 16). Its fallback index, built when no
search index exists, passed no learningsNamespaces, so project learnings
were missing in both scopes; in user scope it read learningsRoots().read,
which keeps another repository's learnings checkout in the write root
(Tencent#808). It now uses indexableLearningsRoots in user scope, as project scope
already did, and resolves the active namespaces with the paths. A broken
projects.yaml leaves the shared root, with a warning when the report builds
its own index.

import --from-mr prompt (item 18). importFromMR, which asks "Accept
learning? [Y/n]" on a readline, ran inside the first listr2 task. In a
terminal the default renderer holds stdout back while a task runs, so only a
spinner showed and the prompt appeared after it was answered. The
extraction now runs before the task list, which starts at "Publish
learning" with the extraction's result as its context.

* fix(learnings): address review — write the partial recall index past the shrink guard (Tencent#823)

With a manifest recall cannot read, the rebuild leaves docs, rules and
skills out on purpose. Against an older-format index of a full corpus the
result is under 20% of it, so buildIndex's shrink guard kept the old file
and recall searched the entries its warning said were left out. The
degraded rebuild now passes `partial`, which skips the guard; every other
build keeps it.

* fix(learnings): address review — skip the older recall index when the partial one cannot be written (Tencent#823)

* fix(learnings): address review — show queued learnings in the dashboard's fallback index (Tencent#823)

The dashboard's temporary index now reads the contribution queue, as recall's
does; promotion and prune candidates keep to the published roots. The recall
rule tells the agent to relay the skipped-older-index warning.
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.

2 participants