Skip to content

fix(opencode): a missing opencode database no longer warns on every binder round - #23928

Closed
drakeo338 wants to merge 1 commit into
stablyai:mainfrom
drakeo338:claude/23926-fix
Closed

drakeo338 wants to merge 1 commit into
stablyai:mainfrom
drakeo338:claude/23926-fix

Conversation

@drakeo338

Copy link
Copy Markdown
Contributor

ELI5

If OpenCode has never run, its database file does not exist yet, and Orca logged a warning about that on every session lookup. Now it stays quiet until the file appears.

What Changed

listOpenCodeDbSessions opened the database even when the file was missing, so the open threw and the catch warned on every binder round. It now returns an empty list when the file does not exist; real read failures still warn.

Why

A missing store is an expected state, not an error.

Linked Issue

Fixes #23926.

Visual Proof

N/A, no UI change; only a log warning is removed.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

The new test fails without the fix and passes with it. Unticked boxes were not run by me.

AI Disclosure

Written with Claude (Anthropic) via Claude Code.

Review

Two reviews found no blockers.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

No security, cross-platform, SSH or performance impact.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Fixes spurious warnings when an opencode database does not yet exist.

The PR appears safe to merge, though the existing unreadable-store diagnostic concern remains.

Findings

  1. P2 Unreadable store appears missing ▶

Summary

The PR skips OpenCode database reads when the file has not yet been created.

  • Adds tests for quiet repeated lookups, detection after creation, and warnings for an existing unreadable database.

Reviews (2) · Last reviewed commit: "fix(opencode): a missing opencode databa..."

Comment on lines +238 to +240
if (!existsSync(dbPath)) {
return []
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Unreadable store appears missing

If the database exists but its parent directory cannot be searched, existsSync can return false. This returns an empty list before the read can report the access failure. The binder then skips that round without a warning, making unbound OpenCode sessions harder to diagnose.

Knowledge Base Used: Agent integrations and hooks

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 28de0690-d42d-4806-9df4-f175aecfcb00

📥 Commits

Reviewing files that changed from the base of the PR and between 0001f188c376d1a725ce9309f502dc2c55324121 and 5e1aaef.

📒 Files selected for processing (2)
  • src/main/agent-hooks/server-opencode-binder.test.ts
  • src/main/opencode/opencode-session-binder.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The OpenCode session binder now checks whether the database exists before attempting to read it. Tests verify that repeated reads of a missing database produce no warnings, that the binder reads the database if it appears later, and that an existing unreadable database still produces a warning.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to 5e1aa

Permission-related database failures may be treated as absence, suppressing warnings. Session listing remains safe, but diagnostics may be lost.

Architecture Summary

Architecture risk: 🔵 Low · up to 5e1aa

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/main/agent-hooks/server-opencode-binder.test.ts: The test file additionally imports writeFileSync for creating an unreadable database fixture.
  • observed — Modified behavior in src/main/agent-hooks/server-opencode-binder.test.ts: Adds tests for missing-database reads remaining warning-free before and after the database is created, and for an existing unreadable database returning an empty result while emitting one warning.
  • observed — Modified behavior in src/main/opencode/opencode-session-binder.ts: Imports existsSync from node:fs for the database-path existence check.
  • observed — Modified behavior in src/main/opencode/opencode-session-binder.ts: listOpenCodeDbSessions now returns an empty list when dbPath does not exist, before attempting the database read.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing repeated warnings when the OpenCode database is missing.
Description check ✅ Passed The description covers the required sections, explains the user-visible behavior and mechanism, links issue #23926, documents testing and AI use, and marks visual proof as not applicable. Some checkli…
Linked Issues check ✅ Passed The change satisfies issue #23926. listOpenCodeDbSessions returns an empty list before it reads an absent database, so repeated binder polls stay quiet. The tests cover repeated absence, detection a…
Out of Scope Changes check ✅ Passed The changes stay within issue #23926. The production change handles the absent OpenCode database. The tests verify quiet absence, later database detection, and preserved warnings for unreadable data. …
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

  • Missing store is now silent — listOpenCodeDbSessions returns [] before the read-only open when existsSync(dbPath) is false, so a host that has never run OpenCode no longer emits a warning stack trace every binder round.
  • Real read failures still warn — the existing catch is untouched, so an existing-but-unreadable database keeps its console.warn.
  • Tests pin both directions — one test asserts two consecutive missing-DB reads stay quiet and detection resumes once the file appears; a second asserts an invalid SQLite file still warns exactly once.

I ran npx vitest run src/main/agent-hooks/server-opencode-binder.test.ts (14 passed) and confirmed the new quiet-path test fails with the guard removed (2 warns), so it is a genuine regression test rather than a passing-by-construction one. The approach matches the issue's stated contract (quiet while absent, detect on appearance, warn on genuine failure) and reuses the existing fail-open contract.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 3ac2bc2b-5995-46ee-8393-82a4aacf0509

📥 Commits

Reviewing files that changed from the base of the PR and between 5c59a2d and 0001f188c376d1a725ce9309f502dc2c55324121.

📒 Files selected for processing (2)
  • src/main/agent-hooks/server-opencode-binder.test.ts
  • src/main/opencode/opencode-session-binder.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment on lines +238 to +239
if (!existsSync(dbPath)) {
return []

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

git diff 5c59a2dfec9c5f935a4a38e5fbb03324150f707c 0001f188c376d1a725ce9309f502dc2c55324121 -- src/main/opencode/opencode-session-binder.ts src/main/agent-hooks/server-opencode-binder.test.ts
sed -n '190,290p' src/main/opencode/opencode-session-binder.ts
rg -n '"engines"|"node"|"electron"|listOpenCodeDbSessions' package.json src/main/opencode/opencode-session-binder.ts

Repository: stablyai/orca

Length of output: 6445


🌐 Web query:

Official Node.js v24 documentation for fs.existsSync and fs.statSync throwIfNoEntry false behavior, including how filesystem errors are handled

💡 Result:

The official **Node.js v24.20.0** docs say:

- **`fs.existsSync(path)`** returns `true` if the path exists and `false` otherwise. It has no `throwIfNoEntry` option. The docs do not specify in this entry how individual filesystem errors are mapped to the boolean result. ([nodejs.org](https://nodejs.org/download/release/v24.20.0/docs/api/fs.html))
- **`fs.statSync(path[, options])`** defaults `throwIfNoEntry` to `true`. Set it to `false` to return `undefined` when the entry does not exist; otherwise, `statSync` returns an `fs.Stats` object. ([nodejs.org](https://nodejs.org/download/release/v24.20.0/docs/api/fs.html))
- **Other filesystem errors:** The option is specifically about a missing entry; the docs do not say it suppresses other filesystem errors. Treat `throwIfNoEntry: false` as handling the missing-entry case, not as a general “ignore errors” switch. For synchronous calls, catch errors that may still be thrown. The docs’ error-code note is stated for asynchronous `stat()`, not explicitly for `statSync()`. ([nodejs.org](https://nodejs.org/download/release/v24.20.0/docs/api/fs.html))

```js
const stats = fs.statSync(path, { throwIfNoEntry: false });
// stats is undefined if the entry is missing
```

The cited v24 docs establish that option’s behavior, but do not enumerate precisely which OS/filesystem errors count as “no entry.”

Citations:

- 1: https://nodejs.org/download/release/v24.20.0/docs/api/fs.html
- 2: https://nodejs.org/download/release/v24.20.0/docs/api/fs.html
- 3: https://nodejs.org/download/release/v24.20.0/docs/api/fs.html

🌐 Web query:

site:github.com/nodejs/node v24.0.0 src/node_file.cc existsSync err == 0 fs.existsSync implementation

💡 Result:

In **Node.js v24.0.0**, `fs.existsSync()` is a JavaScript wrapper in `lib/fs.js`: it validates the path, returns `false` if validation fails, then calls `binding.existsSync(path)`. ([github.com](https://github.com/nodejs/node/blob/v24.0.0/lib/fs.js))

The tagged `src/node_file.cc` source is present, but the GitHub-rendered page doesn’t expose a matching `existsSync` symbol or the `err == 0` check. So the wrapper behavior is established by the source; the specific C++ implementation detail isn’t confirmed by the available page. ([github.com](https://github.com/nodejs/node/blob/v24.0.0/src/node_file.cc))

Citations:

- 1: https://github.com/nodejs/node/blob/v24.0.0/lib/fs.js
- 2: https://github.com/nodejs/node/blob/v24.0.0/src/node_file.cc

🏁 Script executed:

set -o pipefail
curl -fsSL https://raw.githubusercontent.com/nodejs/node/v24.0.0/src/node_file.cc |
  rg -n -C 10 'ExistsSync|existsSync|err == 0|uv_fs_stat' || true
curl -fsSL https://raw.githubusercontent.com/nodejs/node/v24.0.0/lib/fs.js |
  rg -n -C 8 'function existsSync|existsSync' | head -80

Repository: stablyai/orca

Length of output: 11816


Preserve warnings for filesystem inspection failures.

Node 24 maps any failed uv_fs_access call, including EACCES, to false in existsSync. Because this check is outside the try, an unreadable database bypasses the warning handler. The session result is already []; the material impact is lost diagnostics, not an additional session-discovery failure.

Use statSync inside the existing try. Return [] only when it returns undefined, and let other errors reach the warning handler.

Suggested fix
-import { existsSync } from 'node:fs'
+import { statSync } from 'node:fs'
...
-  if (!existsSync(dbPath)) {
-    return []
-  }
   try {
+    if (statSync(dbPath, { throwIfNoEntry: false }) === undefined) {
+      return []
+    }
     return readOpenCodeDatabase({

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

  • Rebased onto current main — the fix itself is unchanged: listOpenCodeDbSessions returns [] before the read-only open when existsSync(dbPath) is false, so a host that has never run OpenCode stays quiet.
  • Real read failures still warn — the catch is untouched, so an existing-but-unreadable store still logs exactly once.
  • Tests realigned to the current store layout — main now reads the session table only, so the quiet-path test seeds session instead of session_v2. Both new tests (quiet-when-absent, warn-when-unreadable) remain and I reran the suite locally (16 passed).

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

nwparker commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Superseded by merged #24577. The original missing-store fix is credited to @drakeo338 in that PR and its commits. Real hidden-app before/after validation confirms absent stores are quiet; permission and corrupt-store failures still warn. Thank you for the original fix.

@nwparker nwparker closed this Oct 2, 2026
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.

OpenCode binder logs a full missing-database warning every minute when OpenCode is unused

2 participants