fix: [#1052] bundled cleanup — 5 deferred items + 3 review-fixes
Issue for this PR
Closes #1052 (partial — see "Not in this PR" below)
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Fixes 5 of 13 deferred items from #1052 (the v0.9.4 post-release cleanup tracking issue), plus 3 review-fixes flagged by a 6-model consensus code review on the initial 5 commits, plus one follow-up scrub.
Scope: the deferred items trace back to my own commits, so the split here is by size rather than by ownership. This batch takes the five that are self-contained enough to review together — D8, D10, D11, D12 and D14. The rest each want a change of their own: D9 crosses TUI + auth + manifest storage, D13 is a gateway-protocol change rather than a CLI patch, and D2–D6 span server-side validation, bundle slimming, Windows path handling and the /event contract. Bundling those in would bury the work that is here.
Commits (bottom-up, oldest first)
Original D-item fixes:
chore(hygiene): [#1052 D8] pre-push scan for internal-tracker refs— scanner + hook + docs. CI mirror deferred to a follow-up PR (needsworkflow-scoped token).test(build): [#1052 D10] stamp-based staleness guard for the smoke test— build.ts emitsdist/<target>/bin/build-inputs.jsonwith sha256s; smoke test compares against it.test(harness): [#1052 D11] idempotent retry in cli-process.run()— scrubopencode*.db*before the SQLite-lock retry so the second attempt starts clean.test(tui): [#1052 D12] deterministic regression test for phaseLabel()— util-level unit test replacing the flaky PTY e2e.fix(models): [#1052 D14] drop eager import-time ModelsDev.refresh()— the fetch was holding the event loop underunshare --neton CI. Snapshot covers cold-start.
Review-fixes (from a 6-model consensus code review of the above):
6. fix(hygiene): [#1052 D8 review-fix M1] catch suffix-adjacent tracker leaks + self-test — regex missed <prefix>-<n><suffix> (5/6 reviewers flagged, some as CRITICAL). Also adds a 28-case self-test file for the RULES.
7. test(build): [#1052 D10 review-fix M2] widen stamp to workspace packages + lockfile — the original stamp missed packages/{tui,core,util,plugin,...}/src, the workspace-root package.json, and bun.lock. Now walks each workspace src/ and hashes those files.
8. fix(models): [#1052 D14 review-fix M3] don't crash on non-JSON error body + fire refresh at boot — pre-existing JSON.parse(<HTML>) crash on 5xx from models.dev + a fire-and-forget Promise.resolve().then(refresh) so short-lived commands still warm the cache without holding the loop.
9. fix(hygiene): [#1052 D8 review-fix follow-up] scrub example strings from scanner source — the M1 commit accidentally embedded concrete tracker-key literals in its own test file + doc comments. Fixtures now build the strings at runtime; scanner source drops the verbatim examples.
Not in this PR (still open on #1052)
- D1 — Interactive activation-menu picker. Design decision, not mechanical.
- D2, D3, D4, D5, D6 — deferred on size, not ownership. Each sits in its own area (Question pending-registry, server-side shell-arg validation, manifest slimming, Windows long paths,
/eventdedup) and is better reviewed on its own. - D7 — pruned (false positive) at v0.9.4 review time.
- D9 —
useConnected()regression detector. Crosses TUI + auth + manifest storage; deserves its own PR. - D13 — SSH port-forwarding / device-code flow. Gateway-protocol change, not a CLI patch.
- CI mirror for D8 — the
.github/workflows/tracker-leak-check.ymlfile was in the local branch but this session's token lacks theworkflowscope; add it in a follow-up PR.
Test plan
-
bun turbo typecheck— 13/13 clean -
bun test packages/opencode/test/skill/tracker-leak-check.test.ts— 28/28 (scanner RULES) -
bun test packages/tui/test/util/phase-label.test.ts— 4/4 (phaseLabel util) -
bun script/check-tracker-leaks.tson the branch itself — silent (no leaks) -
bun run --cwd packages/opencode --conditions=browser ./src/index.ts --version— exits in ~1s, no hang - Full pre-release sanity (Verdaccio Phase 3 [10/10] no-internet check) — will run in CI. Note: D14's fire-and-forget refresh may reintroduce the sanity hang; if it does, the fix is dropping one line (documented in the D14 review-fix commit body).
D14 caveat worth explicit reviewer attention
Commit 8 adds Promise.resolve().then(() => ModelsDev.refresh().catch(() => {})) alongside the hourly interval. A microtask doesn't itself keep Bun alive, and the fetch it schedules will just be abandoned at process-exit if unresolved — but if this reintroduces the original v0.9.4 blocker (sanity Phase 3 [10/10] under Linux unshare --net), the fix is to delete that one line and take the "snapshot-only cold-start" trade-off documented in commit 5.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Q8FGy89Qpr39k8nCSpCcK2
Summary by cubic
Closes five deferred items from #1052 and hardens release safety: blocks tracker leaks on push, makes binary staleness detection accurate across all embedded inputs, and prevents models.dev cache poisoning or boot-time hangs.
- Pre-push tracker check:
script/check-tracker-leaks.tsnow scans the refs actually being pushed (reads pre-push stdin) including source and destination ref names, commit messages ahead of base, and added diff lines only. Skips deletion-only pushes, tolerates unborn HEAD, warns when base is missing, validates--base, and uses shell-freegitcalls with a precise diff filter. Hook runs from.husky/pre-pushafter typecheck (bypass withSKIP_TRACKER_CHECK=1). - Build staleness guard:
packages/opencode/script/build.tswritesdist/<target>/bin/build-inputs.jsonwith sha256 for all embedded inputs (CHANGELOG, migrations, bundled skills, models snapshot, parser worker, per-target native prebuild,packages/*/srcincluding.mp3, each workspacepackage.json, workspace-rootpackage.json,bun.lock, andpackages/opencode/tsconfig.json). Paths are repo-root-relative and the stamp records walked roots andpackages/*/srcglobs. The smoke test rehashes these and re-enumerates the roots to catch newly added files; falls back to the old mtime walk if no stamp is present. Shared walker lives inpackages/opencode/script/stamp-inputs.ts. - Models cache: drop the eager import-time refresh; keep the hourly
.unref()refresh.ModelsDev.Data()parses and validates before caching, returns empty on non-2xx or invalid JSON, and rejects non-catalog objects; the disk cache is validated on read to avoid poisoning. - Tests/docs: the CLI retry scrubs
opencode*.db{,-wal,-shm}before a single retry and rethrows non-ENOENT errors; a deterministic unit test replaces the flaky PTY-based phase label test; end-to-end tests cover scanner behavior;CONTRIBUTING.mdnotes the pre-push scan and bypass.
Summary by CodeRabbit
-
New Features
- Added automated checks to detect sensitive tracker references before code is pushed.
- Added build integrity checks to identify stale or changed build inputs.
-
Bug Fixes
- Improved handling of unavailable, invalid, or incomplete model catalogs.
- Improved retry behavior when local database files are locked.
- Reduced unnecessary model-catalog refresh activity during startup.
-
Documentation
- Documented pre-push validation checks and the optional bypass.
-
Tests
- Added coverage for tracker detection, build freshness, database retries, and startup phase labels.