clawwork-ai / clawwork-ai/ClawWork

[Bug] getDebugLogger noop fallback silently drops events before initDebugLogger runs

Open
#412 3 comments 0 reactions 0 assignees View on GitHub
area/dx kind/bug
Dominant language
TypeScript
Stars
532
Forks
75
Avg merge
5h 31m
Merged PRs (30d)
1

Description

## Problem

The module-level `debugLogger` in `debug/index.ts` is initialized to a set of noop functions that return empty `DebugEvent` stubs. Any code that calls `getDebugLogger().error(...)` (or any other level) **before** `initDebugLogger(...)` runs has its event silently dropped — no warning, no console output, nothing. Given that `getDebugLogger` has 50+ call sites across the main process (gateway-client, auto-updater, tray, quick-launch, workspace init, etc.), it is easy for a module-level or early-startup error to disappear without a trace, making real incidents invisible during the window that matters most (app boot).

## Location

**File:** `packages/desktop/src/main/debug/index.ts:6-15`

```typescript
const noop = (): DebugEvent => ({ ts: '', level: 'debug', domain: 'app', event: '' }) as DebugEvent;
let debugLogger: DebugLogger = {
debug: noop,
info: noop,
warn: noop,
error: noop,
log: noop,
getRecentEvents: () => [],
currentFilePath: () => '',
};
```

## Fix Approach

Pick one of, in order of increasing investment:

1. **Minimum:** replace the noop stubs with variants that `console.warn` whenever called before init — `noop = (input) => { console.warn('[debug] logger not initialized, dropping event:', input); return stub; }`. The log won't end up in the ndjson file, but at least the developer sees it in the terminal.
2. **Better:** buffer events in an in-memory queue until `initDebugLogger` runs, then flush the queue into the real logger. Cap the queue at a small size (e.g. 256) to prevent unbounded pre-init allocation.

Option 2 is the fully correct fix; option 1 is a one-liner that catches the common case.

## Verification

1. Run `pnpm check` — must pass.
2. Unit test: call `getDebugLogger().error(...)` before `initDebugLogger`, then call init, then assert the earlier event appears in the real logger (option 2) or that a console warning was emitted (option 1).

## Context

- **WG:** Observability & DX
- **Priority:** Low (good first issue)
- **Estimated effort:** 15-30 minutes (option 1) / 1 hour (option 2)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.