Skip to content

fix: resolve MetaCollection initialization error and add CI typecheck#188

Merged
snomiao merged 4 commits into
mainfrom
sno-fix-gh-tasks
Apr 3, 2026
Merged

fix: resolve MetaCollection initialization error and add CI typecheck#188
snomiao merged 4 commits into
mainfrom
sno-fix-gh-tasks

Conversation

@snomiao

@snomiao snomiao commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Problem

bun app/tasks/run-gh-tasks.ts crashes with:

ReferenceError: Cannot access 'MetaCollection' before initialization.
  at /run/gh-bugcop/gh-bugcop.tsx:107:37

Root Cause

src/db/TaskMeta.ts had a top-level await _TaskMeta.createIndex(...) that blocked module initialization. When gh-bugcop.tsx imports MetaCollection, the export is still in the temporal dead zone because the top-level await hasn't resolved yet.

Fix

  1. src/db/TaskMeta.ts: Replace top-level await createIndex() with lazy initialization — the index is created on first $upsert/save call instead of at import time.
  2. app/tasks/gh-design/gh-design.ts: Fix pre-existing type error (task._id on union type).

Prevention

  1. .husky/pre-commit: Fix shebang (sh instead of bun) and run bun run typecheck (tsgo) before every commit.
  2. .github/workflows/test.yaml: Add bun run check (tsgo + oxlint + oxfmt) step to CI so PRs are checked.

…check

- Remove top-level await in TaskMeta.ts that blocked MetaCollection export
  initialization, causing 'Cannot access MetaCollection before initialization'
  in gh-bugcop.tsx and other importers
- Make createIndex lazy (called on first $upsert/save) instead of at import time
- Fix type error in gh-design.ts (task._id access in union type)
- Add 'bun run check' (tsgo + oxlint + oxfmt) to CI test workflow
- Fix husky pre-commit shebang (sh instead of bun) and run typecheck

Amp-Thread-ID: https://ampcode.com/threads/T-019d5268-b3d3-73db-8560-91bd9404fe73
Co-authored-by: Amp <amp@ampcode.com>
Copilot AI review requested due to automatic review settings April 3, 2026 08:19
@vercel

vercel Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comfy-pr Ready Ready Preview, Comment Apr 3, 2026 8:34am

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a runtime crash caused by a top-level await in the TaskMeta module and adds typecheck/check enforcement in local hooks and CI to prevent similar regressions.

Changes:

  • Replaced await createIndex() at module import time with lazy index initialization inside TaskMeta $upsert/save.
  • Fixed a TypeScript error in gh-design by adjusting _id access typing.
  • Added bun run check to CI and updated the pre-commit hook to run bun run typecheck.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/db/TaskMeta.ts Removes top-level await by lazily creating the unique coll index on first use.
app/tasks/gh-design/gh-design.ts Adjusts formatting and changes _id access typing to resolve a type error.
.husky/pre-commit Updates hook interpreter and adds a typecheck step before lint-staged.
.github/workflows/test.yaml Adds a bun run check step to CI prior to running tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/db/TaskMeta.ts Outdated
Comment thread app/tasks/gh-design/gh-design.ts
Comment thread .husky/pre-commit
snomiao and others added 2 commits April 3, 2026 17:29
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@snomiao
snomiao enabled auto-merge (squash) April 3, 2026 08:30
- scripts/cleanup-slack-dupes.ts: replace 'as any' with proper types
- slackPendingLock.spec.ts: add error field to LockState type

Amp-Thread-ID: https://ampcode.com/threads/T-019d5268-b3d3-73db-8560-91bd9404fe73
Co-authored-by: Amp <amp@ampcode.com>
@snomiao
snomiao merged commit 4c6a728 into main Apr 3, 2026
6 checks passed
@snomiao
snomiao deleted the sno-fix-gh-tasks branch April 3, 2026 08:34
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.

3 participants