Skip to content

feat(pull): opt-in git submodule population on pull (teamai.yaml submodules) - #501

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
flowjzh:feat/pull-git-submodules
Sep 11, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
flowjzh:feat/pull-git-submodules

Conversation

@flowjzh

@flowjzh flowjzh commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Teams that distribute skills as git submodules currently get an empty directory after clone/fetch - the submodules are never populated, so every resource deploy from the team repo silently misses their content. This PR adds a teamai.yaml knob:

submodules: true

After each repo refresh (and before the resource deploy step, so the freshly checked-out content is what gets deployed), pull runs git submodule update --init --depth 1. Off by default; gated on the knob being exactly true. Documented in docs/usage-guide (en + zh-CN).

Type of Change

  • New feature (non-breaking change that adds functionality)

Test Plan

  • npx tsc --noEmit passes
  • npx vitest run passes on macOS (full suite) and Windows (no new failures vs. the pre-existing Windows platform failures)
  • Unit test: the block is one git submodule update call behind two config gates; happy to add a mocked test if reviewers want one.

Verified end-to-end in a 20-member production fleet (submodule-distributed skill, populated on every member machine via session-start sync).

Notes for Reviewers

  • Kept the mechanics inline in refreshTeamRepo; a follow-up could move it next to pullRepo in src/utils/git.ts so other clone-tree consumers get populated submodules too. Did not do that here to keep the diff additive.
  • loadTeamConfig re-parses the yaml once per refresh for the knob; the file was just written by the pull seconds earlier, so caching felt premature.

@jeff-r2026

Copy link
Copy Markdown
Collaborator

@flowjzh This branch conflicts with main — please rebase first.

Also: lastPullRev is the parent-repo SHA, and a failed submodule update is only a warn. That pull still deploys empty dirs and caches the SHA; the next pull can succeed at filling submodules while the parent SHA is unchanged, so sync is skipped and tool-dir skills stay empty. Don't write lastPullRev on submodule failure, and don't skip when the update succeeded and the tree changed.

@flowjzh
flowjzh force-pushed the feat/pull-git-submodules branch from 65cd565 to 7be5b56 Compare September 11, 2026 09:47
@flowjzh

flowjzh commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (the conflict was our two knobs landing on adjacent types.ts/docs anchor lines — submodules now sits after usageReport).

Fair catch on the rev cache — the failure mode you describe (failed submodule update still persists the new rev → every later pull takes the unchanged-rev fast path → tool dirs stay empty forever) is real. Fixed: refreshTeamRepo now reports submodulesFailed, and pullForScope skips rev persistence for that run. The next pull sees a changed rev, runs a full sync, and retries the update. The update itself remains best-effort (warn, non-fatal) so an unreachable submodule remote can never block deploying the parent repo's content.

The failure semantics are now documented in the usage guide (en + zh-CN): warn + revision held back → next pull re-syncs and retries.

@jeff-r2026

Copy link
Copy Markdown
Collaborator

Reviewed the diff against the surrounding code, checked out the head, ran tsc --noEmit (clean) and the full suite (3006 pass). The core idea is sound and the state-machine reasoning behind the rev hold-back is correct. One blocking concern plus two follow-ups.

🔴 Blocking — --depth 1 on a pinned submodule

Submodules are pinned to an exact SHA. --depth 1 only fetches the branch tip, so unless the pinned commit is the current tip (or a tag), git has to request an unadvertised SHA — which GitHub and many servers refuse (Server does not allow request for unadvertised object <hash>). This isn't a corner case; it triggers the moment the submodule's upstream advances past the pinned commit.

Combined with the rev hold-back this PR adds, the failure mode is worse than the bug it fixes: a submodule that can't be reached at depth 1 fails on every pull → rev is held back every time → the pull re-runs a full sync forever and never populates the directory. A silent infinite-resync loop, i.e. the "empty directory" symptom made permanent.

Two clean ways out, either is fine:

  • Minimal: change ['--init', '--depth', '1'] → ['--init', '--recommend-shallow'] (Git ≥2.34), or --depth 50 to match the fetch --depth=50 already used in clone.ts. One line, keeps the recovery mechanism.
  • Simpler: drop the submodulesFailed rev hold-back and keep only the best-effort warn. That mechanism guards a narrow case (a transient submodule failure that later succeeds while the parent rev is unchanged); against the deterministic --depth 1 failure above it's a net negative. Removing it halves the conceptual surface and stops it interacting with the depth bug. Trade-off: on a transient failure the submodule content deploys on the next pull that moves the parent rev rather than immediately — acceptable, and strictly better in the deterministic-failure case.

🟡 Follow-ups (non-blocking)

  • Private submodules likely won't authenticate. pullRepo relies on the ambient credential helper, and for token-authed hosts the parent clone injects auth via http.extraHeader per-command rather than persisting it. A bare submoduleUpdate inherits neither, so private submodules on a token host hit the same permanent-retry loop. Worth documenting the limitation (public submodules / helper-configured hosts) at minimum.
  • A test for the submodulesFailed → rev-not-persisted branch would be worth it — that's the non-obvious invariant, and a future refactor of the persistence block could silently break it. pull-skip-sync.test.ts is a close template.

Nits

  • loadTeamConfig is now parsed a third time per pull in pullForScope (also at the top of the function and again after the fast path). Fine, just noting.
  • The docs say submodules are "kept current" — slightly oversells given the reachability caveat above.

Overall: well-reasoned, correct where it counts. I'd just want the --depth 1 issue resolved (either path) before merge, since its failure mode is invisible and self-perpetuating.

Teams that distribute skills as git submodules get an empty directory after
clone/fetch - the submodules are never populated, so every resource deploy
silently misses their content.

Add a teamai.yaml knob (off by default):

    submodules: true

After each repo refresh (and before the resource deploy step, so freshly
checked-out content is what gets deployed), pull runs
`git submodule update --init`. Deliberately not shallow: submodules are
pinned to exact SHAs, and a shallow fetch only brings the remote tip, so
checking out any older pin fails with "reference is not a tree" - the full
history guarantees the pinned commit is always present.

A failed submodule update does not abort the pull (best-effort warn), but it
also must not persist the new rev: the parent-repo SHA is the
incremental-sync cache key, and caching it while the tree is incomplete
would let the unchanged-rev fast path suppress the retry on every later
pull - tool directories would stay empty forever. refreshTeamRepo therefore
reports submodulesFailed and pullForScope skips the rev persistence for that
run, so the next pull re-runs a full sync and retries the update.

Documented in docs/usage-guide (en + zh-CN), including the auth caveat for
private submodules on token-injecting hosts. Unit tests cover the
submodulesFailed -> rev-not-persisted invariant.
@flowjzh
flowjzh force-pushed the feat/pull-git-submodules branch from 7be5b56 to 90efd43 Compare September 11, 2026 11:59
@flowjzh

flowjzh commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main, and the --depth 1 catch is correct — thanks for drawing the line to the interaction with the rev hold-back. Fixed, with a third variant of your "minimal" option that removes the failure class outright rather than widening the window:

Dropped --depth 1 entirely — the update is now git submodule update --init (full history). Shallow depth of any kind only mitigates: --depth 50 still fails once a pin scrolls out of the window, and --recommend-shallow defers to .gitmodules' own shallow settings (plus needs Git ≥ 2.34). Since submodules are pinned to exact SHAs, only the full history guarantees the pinned commit is present at checkout — and skill-sized submodule repos make the cost a non-issue. (The parent-repo --depth=50 in clone.ts doesn't have this problem because a branch checkout follows the tip.) The in-code comment now explains why the fetch is deliberately not shallow.

Kept the rev hold-back. With the deterministic --depth 1 failure gone, submodulesFailed now guards exactly the narrow case it was built for — a transient failure (network hiccup) on a pull whose rev would otherwise be cached, which was the stuck-empty-directory bug from the first review. Dropping it would reintroduce that. The permanent-resync scenario you describe required the failure to be deterministic; that's gone at the source.

Also addressed the non-blocking items:

  • Added the two unit tests for the invariant: submodulesFailed → rev not persisted (stays at the previous rev), and the success path persists the new rev (pull-skip-sync.test.ts).
  • Documented the auth limitation in the usage guide (en + zh-CN): submodule fetching relies on ambient git credentials — private submodules on hosts authenticated by per-command token injection (rather than a configured credential helper) will not authenticate.
  • Softened the "kept current" wording to "populated at the revisions pinned by the team repo", which is what the mechanism actually guarantees.

(The third loadTeamConfig parse is deliberate — it reads the post-pull yaml so a team adding submodules: true gets it on the very pull that delivers it; same idiom as the usageReport read below it.)

@jeff-r2026
jeff-r2026 merged commit ad5dea5 into Tencent:main Sep 11, 2026
7 checks passed
jeff-r2026 pushed a commit that referenced this pull request Sep 12, 2026
…526)

`refreshTeamRepo` reports a failed submodule update so the caller holds
`lastPullRev` back and retries next pull (#501). It does not cover the
successful update: `getInstalledResourceTargets` only records which AI
tools are installed, not which skills appeared, so filling an empty
submodule leaves the parent SHA — the fast path's only cache key —
untouched and the unchanged-rev fast path skips the deploy.

That is the upgrade path in #525: a member pulls with a CLI that predates
`submodules: true` (the unknown yaml key is stripped), so the parent SHA
is cached with the submodule directories still empty. Upgrading the CLI
and pulling fills the clone, then reports "Already synced at <rev>,
skipping" and the tool directories stay empty until `pull --force` or an
unrelated parent commit.

Compare `git submodule status` before and after the update and carry the
result into the fast path as `submodulesChanged`. The leading status char
is `-` while uninitialized and ` `/`+` once checked out, so a changed
string means the on-disk tree the deploy step reads is not what was
cached. The fast path only skips when the update left the tree alone, so
a submodule-using team still takes it in steady state instead of paying a
full re-deploy on every pull.

An unreadable status degrades to "changed": a redundant full sync is
cheap and self-correcting, whereas wrongly skipping re-pins the empty
tool directories this fixes. It is only the status read that degrades —
an update failure still reaches the outer catch and holds the rev back.

Fixes #525
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
Tencent#501)

Teams that distribute skills as git submodules get an empty directory after
clone/fetch - the submodules are never populated, so every resource deploy
silently misses their content.

Add a teamai.yaml knob (off by default):

    submodules: true

After each repo refresh (and before the resource deploy step, so freshly
checked-out content is what gets deployed), pull runs
`git submodule update --init`. Deliberately not shallow: submodules are
pinned to exact SHAs, and a shallow fetch only brings the remote tip, so
checking out any older pin fails with "reference is not a tree" - the full
history guarantees the pinned commit is always present.

A failed submodule update does not abort the pull (best-effort warn), but it
also must not persist the new rev: the parent-repo SHA is the
incremental-sync cache key, and caching it while the tree is incomplete
would let the unchanged-rev fast path suppress the retry on every later
pull - tool directories would stay empty forever. refreshTeamRepo therefore
reports submodulesFailed and pullForScope skips the rev persistence for that
run, so the next pull re-runs a full sync and retries the update.

Documented in docs/usage-guide (en + zh-CN), including the auth caveat for
private submodules on token-injecting hosts. Unit tests cover the
submodulesFailed -> rev-not-persisted invariant.

Co-authored-by: flowjzh <[email protected]>
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…encent#526)

`refreshTeamRepo` reports a failed submodule update so the caller holds
`lastPullRev` back and retries next pull (Tencent#501). It does not cover the
successful update: `getInstalledResourceTargets` only records which AI
tools are installed, not which skills appeared, so filling an empty
submodule leaves the parent SHA — the fast path's only cache key —
untouched and the unchanged-rev fast path skips the deploy.

That is the upgrade path in Tencent#525: a member pulls with a CLI that predates
`submodules: true` (the unknown yaml key is stripped), so the parent SHA
is cached with the submodule directories still empty. Upgrading the CLI
and pulling fills the clone, then reports "Already synced at <rev>,
skipping" and the tool directories stay empty until `pull --force` or an
unrelated parent commit.

Compare `git submodule status` before and after the update and carry the
result into the fast path as `submodulesChanged`. The leading status char
is `-` while uninitialized and ` `/`+` once checked out, so a changed
string means the on-disk tree the deploy step reads is not what was
cached. The fast path only skips when the update left the tree alone, so
a submodule-using team still takes it in steady state instead of paying a
full re-deploy on every pull.

An unreadable status degrades to "changed": a redundant full sync is
cheap and self-correcting, whereas wrongly skipping re-pins the empty
tool directories this fixes. It is only the status read that degrades —
an update failure still reaches the outer catch and holds the rev back.

Fixes Tencent#525
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