# agent's SBOM diff timed out on a monorepo

## TL;DR
Diffing two full monorepo SBOMs is the slow path: the tool walks every file in every workspace, twice. Diff the lockfiles from the change instead to get the short list of changed packages, generate SBOMs per package or workspace, and compare only those. Cache the baseline SBOM in CI so each run processes just what changed.

```text
agent's SBOM diff timed out on a monorepo
```

## Use this when
- SBOM generation or comparison hangs or times out on a monorepo
- The agent retries the full diff and it never finishes
- CI time balloons after adding an SBOM step
- You only need to know what changed between two revisions

## Not for this skill when
- You are generating your first SBOM and choosing a format
- You are doing license compliance review (that needs the full SBOM, done once)
- The SBOM tool itself crashes (that is a tool bug, not a scale problem)

## Steps
1. Get the lockfile diff for the change: diff the package-lock, pnpm-lock, or equivalent files between the two revisions.
   Expected: a short list of added, removed, and changed packages instead of the whole tree.
2. Generate SBOMs per package or workspace rather than one giant SBOM.
   ```sh
   syft packages dir:[HOME]/... -o cyclonedx-json
   ```
   Expected: small SBOM files per package that generate in seconds each.
3. Diff only the package-level SBOMs for the changed packages from step 1.
   Expected: the diff completes in seconds and lists exactly what changed.
4. Cache the baseline SBOMs as CI artifacts and reuse them across runs.
   Expected: subsequent runs skip regeneration of unchanged packages entirely.

### Variant: syft SBOM generation too slow monorepo
Point syft at each workspace directory instead of the repo root, and run the workspaces in parallel. The root scan re-walks shared dependency trees.

### Variant: SBOM comparison times out large repo
Compare the lockfile-derived package lists first; most "SBOM diffs" only need the package delta, and that never requires parsing two giant SBOM files.

### Variant: cyclonedx diff performance monorepo
Split the CycloneDX files per workspace before diffing. Per-workspace files also make the results readable, which the giant diff is not.

## Why this happens
SBOM tools walk every file to inventory dependencies, and monorepos multiply that work by every workspace. A full diff then compares everything twice. The change itself usually touches a handful of packages, so the full-repo approach does orders of magnitude more work than the question requires.

## Edge cases and pitfalls
- Lockfile diffs miss vendored or manually copied dependencies; spot-check those paths separately.
- Per-package SBOMs need merging if you must produce one final artifact; keep the merge step after the diff.
- Set an explicit timeout on the SBOM step so the agent fails fast instead of hanging the whole pipeline.
- Watch disk usage: cached SBOMs for every workspace add up; prune old baselines on a schedule.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_feBBmCH_kdXsJ22GXfZtNA
