Skip to content

feat(gc): add "bit gc" to remove unneeded objects from the local scope - #10714

Merged
davidfirst merged 24 commits into
masterfrom
feat/bit-gc
Sep 23, 2026
Merged

davidfirst merged 24 commits into
masterfrom
feat/bit-gc

Conversation

@davidfirst

Copy link
Copy Markdown
Member

A workspace keeps all versions of all components that it imports. Each new version adds its source files, and nothing removes the superseded ones. The local scope thus grows to many gigabytes.

bit gc removes the versions that nothing refers to. It keeps the checked-out version of each component, all heads (of the workspace, of its lanes and of the tracked remotes), all local snaps that you did not export yet, and the dependencies of these. Bit fetches a removed version again from the remote when it needs it.

The command removes a version as a unit: the Version object and its Source objects together. sources.get() reads only the Version object to decide if a version is local. A Version object without its files thus makes the importer skip the fetch, and the command fails later.

--keep-versions <n> keeps the last n versions of each workspace component. The recent history stays local for bit log and bit blame.

In a bare scope the command runs the existing collector that keeps all history, because a bare scope is the source of truth and not a cache.

On this repository: 5.3 GB to 254 MB in 45 seconds, or 364 MB with --keep-versions 5.

Other options: --dry-run, --backup, --restore, --verbose, --json. 11 unit tests cover the collector.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Add workspace garbage collection with safe object retention

✨ Enhancement 🧪 Tests ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Adds bit gc to prune re-fetchable versions and their referenced source objects.
• Preserves checked-out, headed, unexported, recent, and dependency versions through retention
 roots.
• Supports dry runs, backups, restoration, JSON output, and safe bare-scope behavior.
Diagram

graph TD
A["bit gc CLI"] --> B["GC runtime"] --> C{"Workspace context?"}
C -->|Workspace| D["Workspace collector"] --> E["Retention roots"] --> F["Object repository"]
C -->|Bare scope| G["Bare collector"] --> F
B -->|Restore| H["Backup restore"] --> F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Incremental pruning during import
  • ➕ Prevents obsolete versions from accumulating between explicit GC runs.
  • ➕ Removes the need for users to schedule maintenance manually.
  • ➖ Adds substantial I/O and reachability work to a frequently used command.
  • ➖ Import failures or incomplete workspace state could make deletion riskier.
  • ➖ Provides less control over dry runs, backups, and offline-history retention.
2. Size-based LRU cache eviction
  • ➕ Can maintain a predictable maximum scope size automatically.
  • ➕ Prioritizes retaining recently accessed history.
  • ➖ Recency does not represent semantic reachability or export safety.
  • ➖ Requires durable access metadata that the object repository does not currently maintain.
  • ➖ Could remove needed pinned dependencies while retaining irrelevant objects.

Recommendation: Keep the explicit, retention-root-based collector. It aligns deletion with Bit’s component graph, allows inspection and backup before destructive work, and preserves authoritative bare-scope behavior. Incremental or quota-based eviction could be considered later as an opt-in policy built on the same reachability rules.

Files changed (19) +871 / -5

Enhancement (14) +643 / -3
index.tsExport workspace GC contracts +1/-0

Export workspace GC contracts

• Exposes the workspace GC result, options, and deleted-object directory through the legacy scope package.

components/legacy/scope/index.ts

remote-lanes.tsExpose every tracked remote component head +23/-0

Expose every tracked remote component head

• Adds an unfiltered component-to-refs map across all tracked remote lanes. These refs become mandatory retention roots for safe divergence calculations.

components/legacy/scope/lanes/remote-lanes.ts

scope.tsAdd workspace collection and restoration APIs +14/-0

Add workspace collection and restoration APIs

• Provides Scope methods for running the workspace-specific collector and restoring objects moved during backup-mode collection.

components/legacy/scope/scope.ts

staged-snaps.tsExpose all valid staged snap hashes +4/-0

Expose all valid staged snap hashes

• Adds access to non-empty staged snap hashes so unexported local snaps can be retained during collection.

components/legacy/scope/staged-snaps.ts

workspace-garbage-collector.tsImplement retention-based workspace garbage collection +311/-0

Implement retention-based workspace garbage collection

• Classifies scope objects and builds retention roots from workspace versions, component and lane heads, remote refs, staged or unmerged snaps, recent history, and flattened dependencies. Deletes only unretained Version and Source objects, with dry-run, verbose, backup, restore, metrics, and stray-file cleanup support.

components/legacy/scope/workspace-garbage-collector.ts

esm.mjsProvide the GC aspect ESM bridge +6/-0

Provide the GC aspect ESM bridge

• Re-exports the CommonJS-built GC aspect for ESM consumers.

scopes/scope/gc/esm.mjs

gc-cmd.tsImplement the bit gc command interface +139/-0

Implement the bit gc command interface

• Defines command help, option validation, execution, restoration, JSON output, and human-readable storage summaries. Supports dry-run, recent-version retention, backup, restore, overwrite, and verbose modes.

scopes/scope/gc/gc-cmd.ts

gc.aspect.tsDefine the GC Harmony aspect +9/-0

Define the GC Harmony aspect

• Creates the 'teambit.scope/gc' aspect used to register and load garbage-collection functionality.

scopes/scope/gc/gc.aspect.ts

gc.main.runtime.tsDispatch GC by scope context +49/-0

Dispatch GC by scope context

• Registers the command and routes workspace scopes to retention-based collection while preserving the existing history-safe collector for bare scopes. Also exposes backup restoration.

scopes/scope/gc/gc.main.runtime.ts

index.tsExport the GC public API +2/-0

Export the GC public API

• Exports the GC runtime type and aspect from the component entry point.

scopes/scope/gc/index.ts

index.tsExpose typed object metadata publicly +1/-0

Expose typed object metadata publicly

• Re-exports the 'ObjectWithType' contract from the scope objects package.

scopes/scope/objects/index.ts

index.tsExport repository object classification metadata +1/-0

Export repository object classification metadata

• Makes the repository’s object type and size result type available to package consumers.

scopes/scope/objects/objects/index.ts

object.tsParse object types from compressed headers +31/-1

Parse object types from compressed headers

• Adds partial and full object-type parsing helpers. Partial parsing uses zlib synchronization flushing to classify objects without inflating their complete contents.

scopes/scope/objects/objects/object.ts

repository.tsClassify repository objects efficiently +52/-2

Classify repository objects efficiently

• Adds concurrent object listing with type and file size metadata, reading only a 4 KB compressed header when possible and falling back to full reads when necessary. It also marks repository content-transform hooks as optional.

scopes/scope/objects/objects/repository.ts

Refactor (1) +1 / -2
garbage-collector.tsShare the deleted-objects directory constant +1/-2

Share the deleted-objects directory constant

• Reuses the workspace collector’s exported backup directory name instead of maintaining a duplicate constant.

components/legacy/scope/garbage-collector.ts

Tests (2) +211 / -0
workspace-garbage-collector.spec.tsTest workspace garbage collection safety +210/-0

Test workspace garbage collection safety

• Adds eleven tests covering checked-out and head retention, whole-version deletion, reporting, recent-version retention, dry runs, backup restoration, unexported history, and stray temporary files.

components/legacy/scope/workspace-garbage-collector.spec.ts

core-aspects-ids.jsonInclude GC in core aspect loading coverage +1/-0

Include GC in core aspect loading coverage

• Adds 'teambit.scope/gc' to the core aspect IDs exercised by aspect-loading tests.

scopes/harmony/testing/load-aspect/core-aspects-ids.json

Other (2) +16 / -0
.bitmapRegister the GC core aspect component +14/-0

Register the GC core aspect component

• Adds the 'gc' component under 'scopes/scope/gc' and configures it to use the core aspect environment.

.bitmap

manifests.tsRegister the GC aspect manifest +2/-0

Register the GC aspect manifest

• Adds 'GcAspect' to Bit’s core manifest map so Harmony can load the new aspect.

scopes/harmony/bit/manifests.ts

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Concurrent imports can lose objects 🐞 Bug ☼ Reliability
Description
collectGarbageInWorkspace() deletes candidates selected from an earlier inventory without
coordinating its removal pass with Repository.writeObjectsToTheFS(). If an import or snap rewrites
an old candidate and then points metadata at it after inventory, the later deletion can remove that
newly written object and leave the updated component referring to a missing version or source.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R395-396]

+    await remove(versionRefsToDelete);
+    await remove(sourceRefsToDelete);
Evidence
The collector inventories object modification times near the start, performs substantial
asynchronous root traversal, and only later deletes the saved references. Repository writes use
_writeOne() independently of these deletion methods, so no lock or final identity check prevents a
file rewritten after inventory from being removed.

scopes/workspace/clear-cache/workspace-garbage-collector.ts[127-151]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[380-396]
scopes/scope/objects/objects/repository.ts[665-681]
scopes/scope/objects/objects/repository.ts[749-783]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Garbage collection inventories candidates and later removes them without synchronization with repository writers. A concurrent import or snap can rewrite a candidate after inventory and have that object deleted after its metadata is updated.
## Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[383-396]
- scopes/scope/objects/objects/repository.ts[749-783]
## Recommended Fix
Coordinate the GC removal phase and object persistence through a shared scope-level lock respected by all repository write, move, and delete paths. Ensure the lock covers both publishing objects and updating their structural references so GC cannot act on an obsolete inventory.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Unexported lane history can be lost ✓ Resolved 🐞 Bug ≡ Correctness
Description
collectGarbageInWorkspace() adds a lane entry to laneHeads only when componentsById contains
its model component, although the lane tip itself is rooted unconditionally. When a valid lane entry
has no local model object, keepUnexportedHistory() never traverses its parents, so older locally
created versions and their sources reach the deletion pass even though no remote can restore them.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R238-239]

+      const component = componentsById.get(id.toStringWithoutVersion());
+      if (component && id.version) laneHeads.push({ component, head: Ref.from(id.version) });
Evidence
The collector roots every lane version but only schedules ancestry traversal when a model component
exists, while the traversal later operates exclusively on those scheduled starting points. Lane APIs
explicitly treat a missing model component as a valid unmerged lane entry, and the final candidate
pass deletes every unrooted Version and Source, establishing the data-loss path.

scopes/workspace/clear-cache/workspace-garbage-collector.ts[233-240]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[437-463]
scopes/scope/objects/models/lane.ts[306-314]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[346-363]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Lane entries without a local model component retain only their tip, allowing unexported parent versions and sources to be deleted.
## Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[233-240]
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[437-463]
## Recommended Fix
Collect lane heads whose model component is missing and walk their Version parent ancestry directly. Stop at the matching component's tracked remote heads where possible; if no reliable remote boundary exists, retain the full locally available ancestry.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Restoring lane history loses sources ✓ Resolved 🐞 Bug ≡ Correctness
Description
collectGarbageInWorkspace() roots only current lane component heads and the lane README, while
persistent LaneHistory entries are neither loaded nor traversed. When an older entry records a
component version that was later removed from the lane—especially before the lane is exported—its
Version and Source objects are collected even though checkoutHistory() and revertHistory() pass
that exact recorded version to checkout.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R235-242]

+  lanes.forEach((lane) => {
+    lane.toComponentIdsIncludeUpdateDependents().forEach((id) => {
+      addRoot(id.version);
+      const component = componentsById.get(id.toStringWithoutVersion());
+      if (component && id.version) laneHeads.push({ component, head: Ref.from(id.version) });
+    });
+    // the lane's readme is pointed at separately and needn't be among the components above
+    addRoot(lane.readmeComponent?.head);
Evidence
The collector considers only Version and Source objects as deletion candidates, but its lane
processing adds roots only for the current lane state. Lane history persists exact historical
component IDs, including deleted components, and the lane commands use those IDs as the checkout
version set.

scopes/workspace/clear-cache/workspace-garbage-collector.ts[178-184]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[233-243]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[320-352]
scopes/scope/objects/models/lane-history.ts[79-96]
scopes/lanes/lanes/lanes.main.runtime.ts[410-417]
scopes/lanes/lanes/lanes.main.runtime.ts[425-461]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
Issue description
The workspace garbage collector preserves only current lane heads and README heads. Persisted lane-history entries can retain older, including deleted, component versions that checkout and revert later request by exact version, so those versions and their sources must be roots too.
Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[178-243]
Recommended Fix
Load `LaneHistory` objects from the classified inventory and add every version referenced by each history entry (including normal components, deleted components, and update dependents where present) through `addRoot()`. Ensure their Version objects then expand normally to retain their Source and auxiliary object references.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View action required (12)
4. Restore can erase a concurrent backup ✓ Resolved 🐞 Bug ☼ Reliability
Description
restoreDeletedObjects() restores the current backup contents and then unconditionally removes the
entire backup directory without isolating that directory from writers. If another garbage-collection
process moves objects there after the copy starts but before removal, those objects disappear from
both the live object store and the backup.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R606-607]

+  await scope.objects.restoreFromDir(DELETED_OBJECTS_DIR, overwrite);
+  await fs.remove(deletedObjectsDir);
Evidence
The new restore path copies the backup and then removes its shared directory, while garbage
collection independently moves candidate objects into that same directory. Repository movement
removes each source object from the live store, and neither operation uses a shared cross-process
lock, so an interleaving between the copy and removal permanently loses the newly moved object.

scopes/workspace/clear-cache/workspace-garbage-collector.ts[359-373]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[600-608]
scopes/scope/objects/objects/repository.ts[673-721]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`restoreDeletedObjects()` copies from the shared backup directory and then removes that directory, allowing a concurrent garbage-collection run to add objects that are subsequently deleted without being restored.
## Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[600-608]
- scopes/scope/objects/objects/repository.ts[673-721]
## Recommended Fix
Atomically rename the existing backup directory to a restore-specific staging directory before copying any objects. Restore and remove only that staging directory, allowing concurrent backup runs to create or populate a new `deleted-objects` directory without their objects being removed by the restore.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Resolved merges lose the other head ✓ Resolved 🐞 Bug ≡ Correctness
Description
collectGarbageInWorkspace() expands retained versions through refsWithOptions(false, true),
which omits the separate unrelated.head reference stored by resolved unrelated merges. When that
referenced snap has no independent root, cleanup removes its Version and Source objects, and later
divergence calculation fails because it loads the target version before interpreting the unrelated
relationship.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[302]

+      version.refsWithOptions(false, true).forEach((ref) => keep.add(ref.toString()));
Evidence
Resolved unrelated merges record the other lane head only in Version.unrelated, while
refsWithOptions() collects files, optional parents, artifacts, and graph refs but not that head.
Snapping creates exactly this shape by assigning unrelatedHead and making only headOnCurrentLane
a parent; divergence handling then requires the target Version object to be present before checking
the unrelated marker.

scopes/scope/objects/models/version.ts[129-135]
scopes/scope/objects/models/version.ts[357-380]
scopes/component/snapping/snapping.main.runtime.ts[1112-1117]
scopes/component/snap-distance/get-diverge-data.ts[182-194]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[293-305]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Resolved unrelated merges store the other head in `Version.unrelated.head`, outside both `Version.parents` and `refsWithOptions()`. The garbage collector must retain that version, its referenced objects, and its dependencies whenever the containing version is retained.
## Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[289-305]
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[485-521]
- scopes/workspace/clear-cache/workspace-garbage-collector.spec.ts[390-434]
## Recommended Fix
Extend root closure so every retained Version contributes its locally available `unrelated.head` as another root before final dependency and object expansion. Process newly discovered unrelated heads through the same closure and add a regression test where the other head has no independent component, lane, or remote root.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. A remote lane head can be deleted ✓ Resolved 🐞 Bug ≡ Correctness
Description
getAllRefsPerComponent() filters lane-reference files solely by basename, so it drops a real lane
named .DS_Store, Thumbs.db, or desktop.ini. Remote lane names accept these single-segment
values, and the collector uses this method as its remote-head root set, so the excluded lane's
cached head and sources become deletion candidates.
Code

components/legacy/scope/lanes/remote-lanes.ts[R169-173]

+    const matches = await glob(path.join('*', '*'), { cwd: this.basePath, dot: true, nodir: true });
+    const laneIds = matches
+      .filter((match) => !FS_METADATA_FILES.includes(path.basename(match)))
+      .map((match) => match.split(path.sep))
+      .map(([head, ...tail]) => LaneId.from(tail.join('/'), head));
Evidence
The new filter removes these names before lane refs are loaded. The existing path validator permits
any non-empty, non-traversal single segment—including these names—and syncWithLaneObject()
persists lane names after that validation; the new workspace collector relies on the resulting map
to root remote heads.

components/legacy/scope/lanes/remote-lanes.ts[18-35]
components/legacy/scope/lanes/remote-lanes.ts[164-183]
components/legacy/scope/lanes/remote-lanes.ts[205-220]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[232-241]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
Issue description
`getAllRefsPerComponent()` excludes paths by lane-file basename, but those names are valid remote lane names. This omits tracked remote heads from the GC root set and lets their objects be removed.
Fix Focus Areas
- components/legacy/scope/lanes/remote-lanes.ts[169-173]
Recommended Fix
Do not blanket-filter valid lane names by basename. Classify candidate files by successfully reading/parsing the remote-lane ref format (while tolerating actual filesystem metadata), or otherwise use a metadata-detection rule that cannot collide with valid lane names. Add coverage for a remote lane named `.DS_Store` whose head remains included.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


7. Failed cleanup breaks cached versions ✓ Resolved 🐞 Bug ☼ Reliability
Description
collectGarbageInWorkspace() sends Version and Source references through one concurrent,
non-transactional delete or move operation without controlling their order. If any filesystem
operation fails after a Source is processed but before its Version, the remaining Version suppresses
future fetching even though one or more files are missing.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R330-336]

+  if (!dryRun && refsToDelete.length) {
+    if (backup) {
+      logger.debug(`gc, moving ${refsToDelete.length} objects to ${DELETED_OBJECTS_DIR}`);
+      await repo.moveObjectsToDir(refsToDelete, DELETED_OBJECTS_DIR);
+    } else {
+      logger.debug(`gc, deleting ${refsToDelete.length} objects`);
+      await repo.deleteObjectsFromFS(refsToDelete);
Evidence
The collector places both types in the same candidate array and submits them together, while
repository batches mutate each path independently and update the index only after the whole pool
succeeds. Version file references prove that retaining a Version after an earlier Source operation
creates the incomplete state the command is designed to avoid.

scopes/workspace/clear-cache/workspace-garbage-collector.ts[310-323]
scopes/scope/objects/objects/repository.ts[663-681]
scopes/scope/objects/objects/repository.ts[720-726]
scopes/scope/objects/models/version.ts[361-377]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Garbage collection deletes or moves Version and Source objects concurrently, so a partial filesystem failure can leave a Version present after its Source objects are gone. Source lookup then treats that version as locally available and does not fetch its missing files.
## Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[301-337]
- scopes/scope/objects/objects/repository.ts[663-681]
## Recommended Fix
Partition candidates by type and complete all Version removals or moves before beginning any Source operation. This ordering ensures that every partial failure leaves either a complete local Version or no Version, allowing the importer to fetch missing versions normally.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. Cleanup can erase lane readmes ✓ Resolved 🐞 Bug ≡ Correctness
Description
collectGarbageInWorkspace() roots lane entries returned by
toComponentIdsIncludeUpdateDependents() but never roots the separate readmeComponent.head. A
lane whose readme pointer no longer appears among its visible or hidden components therefore retains
that pointer while cleanup removes the referenced Version and Source objects.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R215-220]

+  lanes.forEach((lane) => {
+    lane.toComponentIdsIncludeUpdateDependents().forEach((id) => {
+      addRoot(id.version);
+      const component = componentsById.get(id.toStringWithoutVersion());
+      if (component && id.version) laneHeads.push({ component, head: Ref.from(id.version) });
+    });
Evidence
The lane enumeration method only includes components and updateDependents, while the model
serializes the readme as an independent field and component removal does not clear it. The lane API
later loads the readme using that exact stored head, demonstrating that the omitted reference
remains operationally significant.

scopes/scope/objects/models/lane.ts[332-338]
scopes/scope/objects/models/lane.ts[254-260]
scopes/scope/objects/models/lane.ts[280-296]
scopes/lanes/lanes/lanes.main.runtime.ts[979-986]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Lane readme heads are stored separately from the component and update-dependent lists traversed by garbage collection. A valid readme pointer can consequently survive while its referenced version and files are deleted.
## Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[213-221]
- scopes/scope/objects/models/lane.ts[280-296]
## Recommended Fix
For every live or trashed lane, root its non-null readme head independently. When its model component is available, also include it as a lane traversal starting point so unexported ancestry and requested recent history receive the same treatment as other lane heads.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


9. Kept extensions lose their dependencies ✓ Resolved 🐞 Bug ≡ Correctness
Description
keepFlattenedDependencies() discovers extension versions while iterating a snapshot of the
original roots, but it never processes the dependencies of those newly added roots. For historical
versions that record an extension outside flattenedDependencies, cleanup can retain the extension
itself while deleting versions pinned by that extension.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R461-464]

+        version.flattenedDependencies.forEach((dependency) => dependencies.add(dependency.toString()));
+        // an env or aspect the version was built with. versions written by older bits record these
+        // only here, so taking `flattenedDependencies` at its word would miss them.
+        version.extensions.extensionsBitIds.forEach((extension) => dependencies.add(extension.toString()));
Evidence
The function snapshots rootVersions once, gathers IDs, and only afterward adds the resolved
versions to the root set. Final expansion follows object references rather than dependency IDs, so
dependencies belonging only to a newly added extension version are never retained.

scopes/workspace/clear-cache/workspace-garbage-collector.ts[454-480]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[284-296]
components/legacy/scope/version-validator.ts[184-198]
scopes/component/snapping/get-flattened-dependencies.ts[130-144]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Extension versions discovered while resolving dependencies become roots only after the dependency scan has passed. Their own flattened dependencies and extensions are never visited, leaving the retained extension's dependency closure eligible for deletion.
## Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[450-480]
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[284-296]
## Recommended Fix
Resolve dependencies with a queue or repeated pass until no new version roots are added. Load each newly rooted version exactly once and enqueue both its flattened dependencies and component extension IDs before expanding the final object-reference keep set.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


10. Older extension versions can be lost ✓ Resolved 🐞 Bug ≡ Correctness
Description
keepFlattenedDependencies() derives every retained dependency solely from
version.flattenedDependencies, although older valid Version objects may store extension IDs only
in version.extensions. When a kept historical version uses such an extension and that exact
extension version has no independent root, garbage collection deletes its Version and Source objects
despite the kept version depending on it.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R459-462]

+        const version = (await Ref.from(hash).load(repo)) as Version | undefined;
+        if (!version) return;
+        version.flattenedDependencies.forEach((dependency) => dependencies.add(dependency.toString()));
+      },
Evidence
The collector only inspects flattenedDependencies, while the validator explicitly permits older
versions affected by a bug that omitted extensions from that list. Extension IDs remain available
separately, and retaining a version's direct object references does not retain another component's
Version or Source objects.

scopes/workspace/clear-cache/workspace-garbage-collector.ts[454-475]
components/legacy/scope/version-validator.ts[181-211]
scopes/scope/objects/models/version.ts[298-333]
scopes/scope/objects/models/version.ts[357-376]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Older Version objects can omit extension component IDs from `flattenedDependencies`, causing required extension versions and sources to be collected.
## Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[454-475]
- components/legacy/scope/version-validator.ts[181-211]
- scopes/scope/objects/models/version.ts[298-333]
## Recommended Fix
Build dependency roots from both `flattenedDependencies` and `extensions.extensionsBitIds`, and traverse newly added dependency versions until the dependency closure is complete so legacy extension dependencies and their transitive dependencies survive.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


11. Cached dependency versions are removed ✓ Resolved 🐞 Bug ≡ Correctness
Description
keepFlattenedDependencies() returns when a flattened dependency's ModelComponent object is
absent, even when the dependency ID already contains a locally stored snap hash. When a retained
version depends on such a snap, its Version and Source objects never enter the root set and are
selected for deletion despite being pinned by that retained version.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R469-471]

+        const component = await scope.getModelComponentIfExist(id.changeVersion(undefined));
+        if (!component) return;
+        addRoot(component.getRef(id.version as string));
Evidence
The collector gathers every rooted Version's flattened dependencies, but only roots each dependency
after resolving its component model. ModelComponent.getRef() confirms that hash versions are
directly representable as refs, while the later deletion pass removes every unrooted Version and
Source object.

scopes/workspace/clear-cache/workspace-garbage-collector.ts[454-475]
scopes/scope/objects/models/model-component.ts[189-201]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[310-337]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
Issue description
`keepFlattenedDependencies()` drops a flattened dependency when its `ModelComponent` object is missing, even though a snap-version dependency already identifies the required Version object by hash.
Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[465-472]
Recommended Fix
Call `addRoot(id.version)` before loading the dependency's `ModelComponent`. Keep the model lookup afterward to resolve tag versions through `component.getRef()`, but do not let a missing model object discard an exact hash dependency.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


12. Corrupted versions can lose their files ✓ Resolved 🐞 Bug ☼ Reliability
Description
BitObject.parseObjectTypeFromChunk() and parseObjectType() return a header type without checking
that it is a registered object type, so listObjectsWithType() treats a compressed object with an
unknown header as successfully classified. If that object is a Version referenced by a component, it
never enters versionSizes or the root set while its Source refs remain deletion candidates,
leaving the still-present Version pointing at deleted files.
Code

scopes/scope/objects/objects/object.ts[R168-170]

+  static async parseObjectType(fileContents: Buffer, filePath?: string): Promise<string> {
+    const buffer = await inflate(fileContents, filePath);
+    return extractHeaderAndContent(buffer).type;
Evidence
Normal object parsing rejects a type absent from types, but both new type-only parsing methods
return the extracted header value directly. The new inventory then records that value as a valid
classification; GC adds only objects classified as Version to versionSizes and deletes unkept
Source objects, so an unknown-typed damaged Version is neither rooted nor expanded to its files.

scopes/scope/objects/objects/object.ts[7-20]
scopes/scope/objects/objects/object.ts[152-170]
scopes/scope/objects/objects/repository.ts[308-317]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[129-157]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[298-323]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
Issue description
Header-only type parsing accepts arbitrary type names, unlike normal object parsing. A damaged Version header can consequently hide the Version from the collector while allowing its referenced Source objects to be removed.
Fix Focus Areas
- scopes/scope/objects/objects/object.ts[152-170]
- scopes/scope/objects/objects/repository.ts[308-317]
Recommended Fix
Validate the extracted type against the registered `types` map in both header-only and full type parsing. Throw for an unknown type so `getObjectTypeGracefully()` records the ref as unreadable and GC aborts before deleting from an incomplete inventory.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


13. Cross-scope merges lose imported history ✓ Resolved 🐞 Bug ≡ Correctness
Description
keepAncestryOf() stops at any hash in remoteRefs, including an unmerged incoming head whose
cross-scope history was imported specifically for onward export. Running garbage collection after
applying a non-squash cross-scope merge but before its merge snap can therefore delete the incoming
head's intermediate versions and sources before the receiving lane exports them.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R343-346]

+      addRoot(hash);
+      if (remoteRefs.has(hash)) continue;
+      const version = (await Ref.from(hash).load(repo)) as Version | undefined;
+      if (!version) continue;
Evidence
Merge preparation imports the target-only gap when the source lane has another scope because those
versions must be exported onward, and the pending merge records its remote head only in unmerged
state. GC includes that head as a bare root but immediately stops because the same hash is recorded
by remoteLanes, leaving the imported parents unrooted and eligible for deletion.

scopes/component/merging/merge-status-provider.ts[55-84]
scopes/component/merging/merging.main.runtime.ts[489-503]
scopes/component/merging/merging.main.runtime.ts[647-659]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[214-239]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[334-348]
scopes/scope/export/export.main.runtime.ts[570-604]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Unmerged incoming heads share the ancestry traversal used by ordinary bare roots, which stops at any tracked remote head. For non-squash cross-scope merges, this discards the imported source-side history that must later be exported onward.
## Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[223-240]
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[326-349]
## Recommended Fix
Traverse non-squash unmerged heads separately without stopping at `remoteRefs`, retaining every locally available ancestor needed for the pending merge and export. Keep the remote-boundary optimization for staged, stashed, and other roots where reaching an exported head genuinely marks recoverable history.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


14. Fresh versions can lose their files ✓ Resolved 🐞 Bug ≡ Correctness
Description
collectGarbageInWorkspace() applies the recent-write exemption independently to each object, so it
skips a fresh Version without adding the Version’s older unreferenced Source refs to keep,
allowing them into refsToDelete. This occurs when their modification times straddle the
five-minute cutoff, and the surviving Version then makes source lookup and the importer treat it as
cached and skip remote fetching before later reads encounter its missing files.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R283-287]

+    if (type !== Version.name && type !== Source.name) return;
+    if (keep.has(ref.toString())) return;
+    if (mtimeMs > settledBefore) {
+      recentlyWritten += 1;
+      return;
Evidence
The sweep checks each Version and Source object’s mtimeMs independently, while only explicitly
retained versions expand their file refs into keep: a fresh Version returns early, but an older
Source not already in keep is added to refsToDelete. The test ages all objects, then makes the
Version fresh and confirms that exactly one object—the Source—is selected while the Version remains;
because source lookup treats the Version object as sufficient and the importer excludes cached
versions from remote fetching without validating all Source refs, this directly demonstrates the
resulting inconsistent local state.

scopes/workspace/clear-cache/workspace-garbage-collector.ts[248-258]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[282-295]
scopes/workspace/clear-cache/workspace-garbage-collector.spec.ts[152-165]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[248-260]
components/legacy/scope/repositories/sources.ts[158-172]
components/legacy/scope/component-ops/scope-components-importer.ts[159-176]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The recent-write margin currently protects only the object whose timestamp is recent, allowing a fresh `Version` to remain while its older referenced `Source` objects are deleted. Because a surviving Version suppresses remote fetching even when its files are missing, garbage collection must retain the Version and its referenced objects consistently.
## Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[248-295]
- scopes/workspace/clear-cache/workspace-garbage-collector.spec.ts[152-165]
## Recommended Fix
Before selecting deletion candidates, identify recently written Version objects and add each Version plus all refs returned by `refsWithOptions(false, true)` to the keep set, so the Version and its Source objects are deferred as an atomic unit whenever the Version is within the write-safety margin. Continue allowing unrelated recent Source objects to age out naturally on a later run, and update the test to assert that the older referenced Source is retained alongside the fresh Version.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


15. Checked-out versions can be deleted ✓ Resolved 🐞 Bug ≡ Correctness
Description
collectGarbageInWorkspace() returns from the workspace-ID callback when
getModelComponentIfExist() yields no component, without first rooting a snap hash already present
in id.version. When a bitmap entry still names a locally available snap but its model-component
object is absent, the collector reaches that Version and its Source objects as unreferenced deletion
candidates.
Code

scopes/workspace/clear-cache/workspace-garbage-collector.ts[R186-188]

+        const component = await scope.getModelComponentIfExist(id.changeVersion(undefined));
+        if (!component) return null;
+        addRoot(id.hasVersion() ? component.getRef(id.version as string) : component.getHead());
Evidence
The workspace loop only calls addRoot() after successfully loading a ModelComponent, while
getModelComponentIfExist() returns undefined when that object is absent. The later deletion pass
removes every old Version or Source not reached through the root set, and Version expansion is the
mechanism that retains its Source refs.

scopes/workspace/clear-cache/workspace-garbage-collector.ts[182-193]
components/legacy/scope/scope.ts[421-423]
components/legacy/scope/repositories/sources.ts[190-203]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[232-244]
scopes/workspace/clear-cache/workspace-garbage-collector.ts[266-278]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workspace garbage collector silently skips a bitmap entry when its model-component object is absent, even when the bitmap version itself is a locally available snap hash. This allows the checked-out Version and its Source objects to be collected.
## Fix Focus Areas
- scopes/workspace/clear-cache/workspace-garbage-collector.ts[182-193]
## Recommended Fix
Call `addRoot(id.version)` before attempting to load the model component so an exact local snap hash is retained independently. Continue resolving tags through the model component, and fail safely rather than deleting when a versioned workspace entry cannot be resolved.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread scopes/scope/gc/gc-cmd.ts Resolved
Comment thread scopes/scope/gc/gc-cmd.ts Resolved
…ot set

the scope layer no longer refers to workspaces - it is handed the ids to keep.
also keeps stashed snaps, refuses to delete from a partial object inventory,
and keeps unexported local-lane ancestry.
Comment thread scopes/workspace/clear-cache/gc-cmd.ts Resolved
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 99e0e08

Comment thread scopes/scope/gc/gc.main.runtime.ts Resolved
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit e5a669c

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

Grey Divider

New Review Started

This review has been superseded by a new analysis

Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 4080e13

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 454dfa6

…core aspect

both commands prune local state, and clear-cache already reaches the scope and the
consumer lazily, so no workspace/scope aspect dependencies are added to it.
Comment thread scopes/workspace/clear-cache/gc-cmd.ts Resolved
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 856176d

… restore and size reporting

the header-only read was never reached: the scope aspect installs onPostObjectRead
whether or not a transformer is registered, so every run inflated every object.
~27% less cpu on a 254 MB scope.

also: a stash that parses but has no stashCompsData no longer reads as empty, the
backup directory is emptied once restored, and stray temp files count towards the
size freed.
Comment thread scopes/workspace/clear-cache/gc-cmd.ts Resolved
Comment thread scopes/workspace/clear-cache/gc-cmd.ts Resolved
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 9ef5f37

…rom acting

a lane in the trash still names its snaps and can be brought back, and a detached
head's unexported parents are reachable from nowhere else - both are roots now,
as they already were in the collector for bare scopes.

also: --dry-run no longer performs a --restore, --dry-run --backup no longer
previews disk savings a real backup run wouldn't make, and a temp file is only
removed once it is old enough not to be a write in progress.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 2bff1d0

… progress

an import writes a Version and its Sources before pointing the ModelComponent at
them. a run that reads the components in between sees objects nothing refers to
yet. anything written in the last few minutes is now left for the next run.

this narrows the window rather than closing it - only a scope-wide lock held
across every object write would do that, and there is none today.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit aaa855d

…om the checkout

- a lane's readme is pointed at separately from its components, so it needed its
  own root
- an env reached through "extensions" is rooted after the first dependency pass,
  so that pass now repeats until it stops adding roots - otherwise the env is
  kept while what it depends on is not
- --keep-versions counts back from where the workspace is checked out rather than
  from the head; the head is kept because it is a head, so starting there too
  would just double what N means
- versions are removed before the files they point at, in two passes, since each
  pass is concurrent and nothing here is transactional
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit d614de5

refsWithOptions doesn't report it, and the diverge calculation loads it before it
can tell the two sides are unrelated, so it has to be here.

also decide a remote-lane file by whether it reads as one rather than by its
name: a lane is allowed to be called .DS_Store, and skipping it by name would
delete the head it holds.
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

Grey Divider

New Review Started

This review has been superseded by a new analysis

Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 5c915a8

…he stat walks

both sit inside the scope and gc frees neither, so leaving them out reported a
scope smaller than the disk. they get a line of their own rather than silently
swelling the total.

the directory-size walks now go through pMapPool like everything else here - a
backup or a trash can hold as many files as the scope itself.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 5c17b2e

restore emptied the directory in place, so objects a concurrent --backup moved
there mid-restore were removed from the backup without ever being brought back.
the directory is renamed first - atomic within the scope - leaving a concurrent
run to write into a fresh one it can keep.

a restore interrupted after the rename leaves a directory nothing would look for
again, so those are picked up on the next restore.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 2e9db9f

…dirs

"bit lane checkout-history" and "revert-history" hand checkout the exact versions
written in a history entry. a version that has since left the lane is reachable
from nothing else, and on a lane that was never exported it is here and nowhere
else, so every entry's versions are roots now.

restore also claims each staging directory by renaming it again before copying,
so two restores at once can't both read a directory one of them is removing.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit f06f296

the tip was rooted on its own and its chain left to the deletion pass, which is
the wrong half to keep for a lane that was never exported. it goes through the
same bare-hash walk as staged snaps and stashes, stopping where the remote has it.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit f2355b4

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit b942c64

@davidfirst
davidfirst enabled auto-merge (squash) September 23, 2026 20:49
@davidfirst
davidfirst merged commit 33116ef into master Sep 23, 2026
14 checks passed
@davidfirst
davidfirst deleted the feat/bit-gc branch September 23, 2026 21:24
davidfirst added a commit that referenced this pull request Sep 24, 2026
….list (#10730)

`Repository.list(types)` read and inflated every object file in the
scope just to check its type, then discarded almost all of them — most
of a scope is file contents, which no caller of `list()` asks for. It
now reads the type from the header in the first 512 bytes (the mechanism
`bit gc` added in #10714) and only reads the full file when the type
matches.

This speeds up every `list()` caller: rebuilding a missing `index.json`
(on scope load, and after every `bit clear-cache`), `bit cat-scope`, the
bare-scope garbage collector, `toObjectList` and the doctor's
orphan-symlink check. On a 254 MB scope (27k objects) the index rebuild
went from ~3.1s to ~1.4s; the full read scales with the scope's bytes
and the header read with its object count, so the gap grows on larger
scopes.

When a content transformer is registered the header can't be read on its
own, so that case keeps the single full read. An object of an
unregistered type is still skipped rather than thrown on, as before.
davidfirst added a commit that referenced this pull request Sep 28, 2026
…ects

The merge brings in the workspace-root aspect (#10698), 'bit gc' (#10714) and the
ripple/lane commands (#10712), each adding a @teambit/* shim barrel. shims-total
measured 11.27 MB against a 11.12 MB ceiling (baseline 10.11 + 10% margin); the
other six pre-phase checks stayed within budget.
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