Skip to content

scan: every candy scan re-runs discover (RunDiscover walk + fold) on a project LoadUnified already folded #1346

Backlog

Description

@aitrawog

Category

category:runtime

Type

type:fix

Remedy / files the remedy will touch

charly/layers.go projectLoad.localCandies (formerly scanLocalCandies): drop the ApplyDiscover call; ApplyDiscover then has only test callers (unified_test.go) — move those tests onto LoadUnified's own fold and delete ApplyDiscover (C6)

Cited design decision or org-rulebook rule (or none)

AGENTS.md C4 (one discover fold, not two)

Classification

Non-blocking — genuinely separable; left unclaimed for a later session to pick up.

Evidence (verified: commands with output, file:line, measurements)

The loader already folds the walk's discovered manifests into the project it returns:

$ grep -n 'lp.Discovered' loaderkit/materialize_project.go loaderkit/walk.go
loaderkit/materialize_project.go:72:	if err := seams.FoldDiscoveredManifests(lp.Discovered, merged); err != nil {
loaderkit/walk.go:121:	lp.Discovered = discovered

The candy scan then discovers and folds the same manifests again, on that already-folded project (charly layers.go, scanLocalCandies; projectLoad.localCandies after charly#1024's load-once change):

	if present {
		if err := ApplyDiscover(uf, dir); err != nil {

A throwaway test on the charly repo (LoadUnified(".."), then ApplyDiscover on the same project) shows the second fold adds nothing:

    zz_spike_discover_alias_test.go:29: cfg.Box before=4 after=4; uf.Candy before=4 after=4
--- PASS: TestSpikeDiscoverAliasesConfig (70.86s)

Mechanism

loaderkit's LoadUnified walk collects lp.Discovered (walk.go:121), and MaterializeLoadedProject folds it into the returned project (materialize_project.go:72). scanLocalCandies/localCandies then calls ApplyDiscover, which runs RunDiscover (a second walk of every discover tree) and folds the result again. The fold is idempotent, so nothing changes, but the walk is repeated on every scan.

Missed control

No test asserts that a scan does not re-walk discover trees, and the two folds live in different repos (sdk loaderkit vs charly core).

Blast radius

Every candy scan: every plugin connect, the check runner, the build engine, the declared-kind connect pass. Cost per scan is unmeasured (a second discover walk of the project).

Root fix

Delete the second fold. A scan reads the discovered candies the load already folded.

Spike (its result, or none with the reason)

none: the redundancy is proven by the code path (materialize_project.go:72 folds lp.Discovered) and by the spike above (the second fold changes nothing). What is still unmeasured is the time the second RunDiscover walk costs per scan. Measuring that is the first step of the fix, before deleting the call and moving the tests in unified_test.go that call ApplyDiscover directly onto LoadUnified.

Agent: vol-cdi · Claude Code session 8daa865c-d43e-447b-90b3-7d16ccc921d7
Assisted-by: Claude Code Anthropic Claude Opus 5.5 (analysed on a live system)

Activity

  1. added
    category:runtime
    type:fix
    on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:runtimetype:fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions