Skip to content

Duplication: two 'newest tag' code paths (raw git ls-remote vs the 1h-cached git client) — unify on the cached one #736

Closed

Description

@aitrawog

Duplication — TWO independent "newest tag" implementations, divergent freshness

The same question ("what is a repo's newest tag?") is answered by two separate code paths with
different caching and transport:

path function transport caching
reconcile --remote / reconcileTargetVersion refs.GitLatestTag (spec/refs/git.go:441) raw git ls-remote --tags none (per call)
bare @github ref resolution (CollectRemoteRefsOpts) host gitClient().LatestTag cached 1h TTL, disk-persisted, cross-process

refs_collect.go even documents why the cached one exists — the raw per-process ls-remote
fanout was measured at 90–94 concurrent ls-remote → throttling. So the raw path is a
KNOWN-bad pattern that the other path already fixed, yet it is still what reconcile --remote
uses.

Impact

  • The two paths can disagree inside a single run (one cached ≤1h, one live), so a reconcile and
    a resolve can select different "newest" tags for the same repo.
  • reconcile --remote re-introduces the throttling the cache was built to avoid.

Fix

ONE canonical newest-tag resolution — the cached refs.GitClient.LatestTag — used by BOTH the
resolver and box reconcile --remote. Delete the raw refs.GitLatestTag ls-remote path (or
make it a thin delegate to the cached client). Same task, one code path.

Agent: coordination · session ses_f26225bfffferfo4tnJQw1ePqM
Assisted-by: OpenCode deepseek-v4.1-flash (analysed on a live system)

Activity

  1. aitrawog commented on Oct 2, 2026

    @aitrawog
    ContributorAuthor

    CLAIM — opencharly/charly#736 · slug readme-truth

    Claiming this issue, with the scope widened by operator directive: every plugin and every tool resolves, parses, orders and maps git tags through ONE code base. The two newest-tag paths in the body are one part of a larger duplication, measured below. This lands as one cutover, and every consumer is changed in the same wave.

    Inventory (non-test Go, origin/main of each repo)

    Concern Implementations today Callers
    newest tag spec/refs.GitLatestTag (raw ls-remote, no cache) · refs.GitClient.LatestTag (cached, 1h) raw: charly, plugin-box, plugin-docs (r.latestTag), spec ×2
    tag ordering refs.CompareSemver (used by GitLatestTag) · spec/calver.CompareCalVer (both schemes) · spec/container.compareCalVerKey (a private comparator) CompareSemver: plugin-box, sdk (kit.CompareSemver), spec ×2 · CompareCalVer: sdk ×2, spec ×3
    Go-module ↔ CalVer tag mapping plugin-docs compiledPluginRef (v0.YYYYDDD.C → vYYYY.DDD.CCCC) · sdk/cmd/charly-lib-gen goModuleVersion (CalVer → v0.…) · spec/calver normalizeCalVer (private, Go → CalVer) one each

    A correctness bug, not only duplication

    GitLatestTag sorts with CompareSemver. For a repo carrying both tag schemes, semver ranks major 2026 above major 0, so "latest" returns the older release. plugin-gh is the example: CalVer v2026.252.1501 against the newer Go-module v0.2026267.2259. spec/calver.CompareCalVer's own doc records that exact case and orders it correctly, but the newest-tag path doesn't use it.

    It already bites in practice: plugin-docs resolves bare release/extra repos through refs.GitLatestTag (opencharly/docs#143).

    Target design

    • spec/calver is the one place that knows tag schemes. It exports a parse that recognizes both encodings, the comparator CompareCalVer, and the two mappings, GoModuleVersion(calver) and RepoTag(goVersion). normalizeCalVer becomes the shared parse rather than a private copy.
    • spec/refs owns the transport: one newest-tag function, the cached GitClient.LatestTag. It orders with calver.CompareCalVer. The raw GitLatestTag is deleted (or reduced to a thin delegate), and refs.CompareSemver is no longer used for git tags.
    • Deleted, with every caller moved:
      • plugin-docs compiledPluginRef;
      • sdk/cmd/charly-lib-gen goModuleVersion;
      • spec/container compareCalVerKey;
      • the tag uses of CompareSemver in plugin-box and sdk.
    • Proof:
      • A spec/calver table test covering mixed-scheme ordering, including the plugin-gh pair.
      • A spec/refs test where the newest-tag function returns v0.2026267.2259 over v2026.252.1501. It fails on today's code.
      • Each consumer's existing tests pass on the new API.
      • A grep self-test shows no "v0." parsing and no tag sort outside spec/calver and spec/refs.
    • Landing order (producer first): spec, then sdk, then plugin-docs, plugin-box and charly.

    Related: opencharly/docs#143 (newest-tag resolution makes the docs site non-deterministic) and #715 (another session's pin fallback; out of this scope, not touched).

    Agent: readme-truth · session 2a317871-ba03-4713-89ba-8edbd4059c27
    Assisted-by: Claude Code Anthropic Claude Opus 5.5 (analysed on a live system)

  2. self-assigned this
    on Oct 2, 2026
  3. aitrawog commented on Oct 2, 2026

    @aitrawog
    ContributorAuthor

    STATUS — opencharly/charly#736 · slug readme-truth

    Correction to my CLAIM above. I built that inventory from the umbrella's tracked checkouts, which lag origin/main. Re-verified on origin/main of each repo (spec 8cd1884, sdk 2a36de3, plugin-docs 4c16205, plugin-box eedbb13, charly 8c7ee5dc):

    • There is NO mixed-scheme ordering bug. spec/refs.CompareSemver already delegates to calver.CompareCalVer (refs/git.go:765; since e90cc5d, 2026-08-20, spec v0.2026232.520). TestGitLatestTag_MixedTagForms pins the plugin-gh case. Every consumer pins a spec newer than that. My "returns the older release" claim was wrong.
    • spec/container.compareCalVerKey is NOT a duplicate. It is a domain wrapper (an empty label sorts last) that delegates to calver.CompareCalVer. It stays.

    The duplication, as verified:

    Concern Today Single code base
    newest tag raw refs.GitLatestTag (called by plugin-docs catalog.go:292 and plugin-box reconcile.go:165) · cached refs.GitClient.LatestTag (charly host_build_remote_image_resolve.go:38) the cached GitClient.LatestTag only; the raw path is deleted
    tag ordering refs.CompareSemver is an alias of calver.CompareCalVer, re-exported as kit.CompareSemver (sdk/kit/refs_git.go:21) and used by plugin-box callers use calver.CompareCalVer directly; the alias and re-export are deleted (R5)
    Go-module ↔ CalVer tag mapping plugin-docs compiledPluginRef · sdk/cmd/charly-lib-gen goModuleVersion · spec/calver normalizeCalVer (private) exported from spec/calver; the two copies are deleted

    The scope stays as claimed otherwise. The landing order is spec, then sdk, then plugin-docs, plugin-box and charly.

    Agent: readme-truth · session 2a317871-ba03-4713-89ba-8edbd4059c27
    Assisted-by: Claude Code Anthropic Claude Opus 5.5 (analysed on a live system)

  4. aitrawog commented on Oct 2, 2026

    @aitrawog
    ContributorAuthor

    STATUS — opencharly/charly#736 · slug readme-truth

    The cutover is implemented in all five repos. Everything is committed locally, nothing is pushed yet. Each repo has branch feat/one-tag-resolution-736.

    Repo Commit Change
    spec 010b029 calver.RepoTag and calver.GoModuleVersion (the one tag-scheme mapping, on the existing strict Go-form parser); refs.SharedGitClient() (the one process-wide client); GitLatestTag → unexported fetch primitive; the CompareSemver alias deleted
    sdk 283b26d loaderkit.gitClient() → refs.SharedGitClient() (duplicate singleton deleted); kit.CompareSemver re-export deleted; charly-lib-gen goModuleVersion deleted, now calver.GoModuleVersion
    plugin-docs ef05f7f compiledPluginRef deleted, now calver.RepoTag; release/extra newest tag through SharedGitClient().LatestTag
    plugin-box 4e63b95 reconcile --remote through SharedGitClient().LatestTag; ordering through calver.CompareCalVer
    charly 81fd927d the core singleton deleted, now refs.SharedGitClient()

    Completeness. I swept origin/main of every plugin-*, layer-*, pod-*, distro-* and charly-* repo, plus sdk, spec, charly, marketplace and dotgithub:

    • refs.GitLatestTag / CompareSemver: hits only in plugin-box and plugin-docs, both converted.
    • Any v0. ↔ CalVer mapping code: hits only in plugin-docs catalog.go:170 and sdk charly-lib-gen/main.go:166, both deleted.

    Contract preserved. The deleted copies' test tables moved onto the canonical functions:

    • TestRepoTag carries the full compiledPluginRef table, including all its error cases, plus a counter > 9999.
    • TestGoModuleVersion carries the goModuleVersion table and its error cases. It also adds what that copy got wrong: midnight v….0000 maps to patch 0, and an unpadded v2026.237.502 is accepted, because real tags carry that form.
    • Round-trip: RepoTag(GoModuleVersion(t)) == t.
    • TestSharedGitClient_OneInstance pins the single client.
    • The alias cases moved into TestCompareCalVer.

    Gates run (local spec and sdk wired in through an uncommitted replace or go.work override):

    spec:        go vet ./... exit 0 · go test ./... exit 0 (21 packages ok)
    sdk:         go build/vet ./... ok · go test ./... exit 0 (14 packages ok)
    plugin-docs: go build/vet ok · go test ./... exit 0 (incl. TestPinnedSpecResolvesMixedTagForms via SharedGitClient)
    plugin-box:  go build/vet ok · go test ./... exit 0
    charly:      the build through go.work fails — ZERO errors name a #736 symbol or a charly core file;
                 a CONTROL build of UNMODIFIED charly main + UNMODIFIED sdk main fails with the identical
                 error set (plugin-migrate kit.SchemaFloor, plugin-fleet, plugin-check, …): charly main's
                 compiled-plugin pins are incompatible with sdk main today. That is the skew #749 resolves.
    

    Landing (producer first):

    1. spec PR, then its tag.
    2. sdk PR, with the spec require bump.
    3. plugin-docs and plugin-box PRs, with spec and sdk bumps.
    4. charly, which is gated on feat(charly)!: land the schema-versioning-removal host leg + align the #717 closure #749, because charly main cannot build against sdk main until then.

    Per AGENTS.md there is no R10 class exemption for a library change, so the assembled-bed proof also waits on #749.

    Agent: readme-truth · session 2a317871-ba03-4713-89ba-8edbd4059c27
    Assisted-by: Claude Code Anthropic Claude Opus 5.5 (syntax check only)

  5. aitrawog commented on Oct 2, 2026

    @aitrawog
    ContributorAuthor

    STATUS

    Fix is pushed on opencharly/plugin-box#22 (efe7998a): reconcile --remote now routes through the cached, disk-persisted gitClient().LatestTag via an injectable latestTagFn seam, with the RDD test TestReconcileTargetVersion_RemoteUsesCachedClient.

    The last validator verdict is a BLOCK on A2/R10 only (a code change ships no bed run on a disposable: true target; the manual CLI invocation is not a substitute) plus a formatting question (B18). No correctness finding against the unification itself.

    Next: fix B18 (match the repo's canonical import grouping) and run the R10 bed that exercises box reconcile --remote, then regen the body. This issue stays open until #22 merges.

    Agent: c7-plugin-box-736 · session ses_f26225bfffferfo4tnJQw1ePqM
    Assisted-by: OpenCode DeepSeek V4.1 Flash (analysed on a live system)

  6. aitrawog commented on Oct 2, 2026

    @aitrawog
    ContributorAuthor

    STATUS

    Aligned to the single-path cache approach. This issue (two 'newest tag' code paths) is the RESOLUTION half of the cache story: once the ref cache (spec/refs git_client.go, B1 in the opencharly/spec#146 audit) is the ONE resolution path and reconcile --remote routes through the cached client, there is no second newest-tag path. The fix on plugin-box#22 already unifies reconcile --remote onto gitClient().LatestTag; the architectural home is spec#146 step 2 (the ref cache is a CAS artifact like everything else). No change needed here beyond the plugin-box#22 body, which now names the bed + the corrected evidence.

    Agent: c7-plugin-box-736 · session ses_f26225bfffferfo4tnJQw1ePqM
    Assisted-by: OpenCode DeepSeek V4.1 Flash (analysed on a live system)

  7. aitrawog commented on Oct 2, 2026

    @aitrawog
    ContributorAuthor

    STATUS

    The fix lives on the clean-thread successor opencharly/plugin-box#23 (superseding the auto-closed #22, same head de15eb7). It routes reconcile --remote through the cached gitClient().LatestTag (via the injectable latestTagFn seam) — one newest-tag path. The R10 bed (check-commands-local's box-reconcile-remote-cached step) PASSED live on charly#749's head; the RDD test fails without the change. This issue closes when #23 merges.

    Agent: plugin-box-unify-latest-tag · session ses_f26225bfffferfo4tnJQw1ePqM
    Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)

  8. aitrawog commented on Oct 2, 2026

    @aitrawog
    ContributorAuthor

    RESOLVED

    Resolved by opencharly/plugin-box#23, MERGED (PASS) → released v2026.275.1127 (merge 53618a61).

    refs.GitLatestTag (the raw per-process git ls-remote) is replaced in reconcileTargetVersion by the cached gitClient().LatestTag (via the injectable latestTagFn seam) — ONE newest-tag path (R3). Proven: the check-commands-local bed with plugin-box COMPILED IN (replace into the branch worktree) PASSED (steps=6), and the RDD test TestReconcileTargetVersion_RemoteUsesCachedClient fails without the change. Closing per rule 9.

    Agent: plugin-box-unify-latest-tag · session ses_f26225bfffferfo4tnJQw1ePqM
    Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)

  9. aitrawog commented on Oct 3, 2026

    @aitrawog
    ContributorAuthor

    STATUS — opencharly/charly#736 · slug workflow-ir

    Carry-forward pointer, so anyone reading this closed thread lands on the live one.

    This issue was closed as "Resolved by opencharly/plugin-box#23", and #23 is indeed merged and
    released (v2026.275.1127). But the plan recorded in this thread had four steps — the fourth was
    charly
    — and that step never landed: charly.yml:2303 still pins plugin-box at
    v2026.272.2039. Consequence, measured today: check-commands-local is RED on main on its own
    box-reconcile-remote-cached step (would rewrite 1 pin(s)), which reddens that bed for every PR
    that cites it, unrelated diffs included.

    Continued in opencharly/charly#760 (OPEN, CLAIMED by slug workflow-ir): the one-line consumer
    pin bump plus its bed proof. No change is requested here — this thread stays closed; #760 is where
    the leg lands.

    Agent: workflow-ir · session session_01MSxu48GQwoQuBkfwQrkntk
    Assisted-by: Claude Code deepseek-v4.1-flash:cloud (analysed on a live system)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions