Skip to content

fix: brain never reaches 'ready' status + console.warn → app.log #149

Description

@four-bytes-robby

Symptoms

  1. Brain plugin status never transitions to 'ready' during initialization — stays at 'init' or 'busy' indefinitely
  2. Bus publish failure errors written to console.warn instead of OpenCode app.log

Root Cause

Issue A (status stuck): In _serverPlugin (src/four-opencode-brain.ts lines 213-216), updateStatus('ready') is only called when !autoIngest. Since BRAIN_AUTO_INGEST defaults to true, the status stays at 'init' until the fire-and-forget runAutoIngest() completes (which could be minutes later, or never if the bus is broken).

Issue B (console.warn): In src/status.ts, two places use console.warn for bus errors (line 53 in getBus(), line 113 in write()). These should use _client?.app?.log(...) like the rest of the codebase does (startStatusServer() already uses this pattern correctly).

Fix Plan

1. src/status.ts — Replace console.warn with _client?.app?.log()

Location 1 — getBus() line 53:
BEFORE:

console.warn('[brain] BusClient connect failed:', (err as Error).message);

AFTER:

_client?.app?.log({ body: { service: 'brain', level: 'warn', message: 'BusClient connect failed', extra: { error: String(err) } } }).catch(() => {});

Location 2 — write() line 113:
BEFORE:

console.warn('[brain] Bus publish failed:', (err as Error).message);

AFTER:

_client?.app?.log({ body: { service: 'brain', level: 'warn', message: 'Bus publish failed', extra: { error: String(err) } } }).catch(() => {});

2. src/four-opencode-brain.ts — Always set 'ready' at init completion

Lines 213-216:
BEFORE:

  // Init complete — only set idle if NOT auto-ingesting
  if (!autoIngest) {
    updateStatus('ready'); // init complete, no auto-ingest
  }

AFTER:

  // Init complete — plugin is ready for tool calls. Auto-ingest (if any) runs in background and
  // will transition to 'busy' → 'ready' on its own.
  updateStatus('ready');

Verification

  • After fix, brain plugin status should transition init → ready immediately on startup
  • If auto-ingest is enabled, status will then go ready → busy → ready as ingest runs
  • Bus errors should appear in OpenCode logs via app.log, not raw console.warn

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions