Conversation
6 tasks
Owner
Author
|
Review guide for this PR: This PR contains the external Postgres sync / cross-machine resume implementation. The paired OpenCode core-hook PR is anomalyco/opencode#21001. Please focus review on:
Fresh verification on this repo:
Real distributed smoke was exercised against current host + |
e4109e4 to
73da380
Compare
62df0a1 to
c5f39da
Compare
…ooks
- Add replayBus()/routeBus() to projectors.ts for bus event shape { type, properties }
- Rewrite index.ts: route all events through hooks.event() → replayBus()
- Inline consumer methods (todo/metadata/ensure/status/checkpoint) from local.ts
- Add 30s metadata sync timer with .unref()
- Remove consumer.ts (SSE stream loop, open(), reconnection logic)
- Remove serverUrl/env var config (OPENCODE_SHARED_DB, OPENCODE_SYNC_MACHINE)
- Plugin config now exclusively via PluginOptions (options.url, options.machine)
- Keep old replay() for backfill compatibility (reads local SQLite EventTable)
- 22 tests pass, typecheck clean
…fix test mock - Add void backfill(sql, machine) fire-and-forget call on plugin init - Collapse meta/tick duplicate functions into single sync() - Fix index.check.ts mock: add backfill.js mock, add info() to log mock - All 22 tests pass, typecheck clean, format clean
c5f39da to
0be6308
Compare
… inserts - Accept options.db (SQLite path) and options.backfill (max days) from plugin config - Remove globalDb() auto-discovery — never guess which database to use - backfill=0 skips backfill, backfill=-1 (default) backfills everything - Filter sessions by time_created when maxDays > 0 - Scope messages/parts/todos/events to filtered session IDs - Insert projects individually with try/catch so one failure doesn't block others - 24 tests pass, typecheck clean
Ablation tested against 48GB database (22K sessions, 20K events): - root_session_id: recursive parent_id CTE is same speed (73ms vs 80ms) - event.origin: never read from Postgres, only written. Removed. - origin_machine: caused 2s full scans on hot paths. Remote sessions now detected by diffing Postgres IDs against local SQLite IDs (18ms). All three columns removed from Postgres schema, projectors, backfill, and local sync. parent_id is the canonical tree relationship.
- Set name to @sjawhar/opencode-postgres-sync - Set main to dist/index.js, add types and files fields - Remove private: true - Add prepublishOnly build step
…b), publish 0.1.1
…t insert (#4) - Module-level singleton pool keyed by URL — drops from N connections (one per directory) to a single shared pool with max 3 connections - ensureMessage stub before part insert — prevents FK violation when part event arrives before its parent message - Published as @sjawhar/opencode-postgres-sync@0.1.2
…-machine resume All SQLite opens now set PRAGMA busy_timeout = 5000 (5s wait before SQLITE_BUSY). Fixes pullSession failing with 'database is locked' when multiple processes access the 51GB global DB. Published as 0.1.3.
…Db() auto-discovery Root cause of cross-machine resume failure: globalDb() picked opencode-.db (dev binary) while OpenCode uses opencode.db (release binary). pullSession wrote to the wrong file. Now all local.ts functions accept the db path from config. No auto-discovery. Published as 0.1.5.
Plugin fetches /global/health to get the version string, parses the channel (e.g., 1.3.13-sami.xxx → channel 'sami' → opencode-sami.db), and computes the correct DB path. No config field needed for any build. The db option still works as an override but is no longer required. Published as 0.1.6.
- Check OPENCODE_DISABLE_CHANNEL_DB env var - Handle empty channel (opencode-.db) - Handle beta channel (opencode.db, not opencode-beta.db) - Sanitize channel same as core: [^a-zA-Z0-9._-] → '-' - Published as 0.1.7
- Runs CI (typecheck, format, test) first via workflow_call - Publishes to npm with OIDC auth (id-token: write, no NPM_TOKEN secret) - Only publishes when package.json version differs from npm registry - Added workflow_call trigger to ci.yml for reuse
fbcbaf0 to
9fc4baf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why
This keeps Postgres sync and cross-machine resume logic out of the OpenCode monorepo while still validating the distributed workflow as an external plugin.