Skip to content

fix: idempotent register guard + governance detail logging#365

Open
jlin53882 wants to merge 1 commit intoCortexReach:masterfrom
jlin53882:fix/init-reentrancy-governance-logging
Open

fix: idempotent register guard + governance detail logging#365
jlin53882 wants to merge 1 commit intoCortexReach:masterfrom
jlin53882:fix/init-reentrancy-governance-logging

Conversation

@jlin53882
Copy link
Copy Markdown
Contributor

Summary

Two fixes for memory-lancedb-pro plugin:

1. Idempotent register() guard

Problem: During gateway boot, OpenClaw calls register() multiple times (once per agent session). Without a guard, the expensive initialization (MemoryStore, embedder, hooks) runs every time, causing redundant initialization blocks in logs.

Fix: Add let _initialized = false module-level flag. On repeated register() calls, log a debug message and return early.

let _initialized = false;

register(api: OpenClawPluginApi) {
  if (_initialized) {
    api.logger.debug("memory-lancedb-pro: register() called again — skipping re-init (idempotent)");
    return;
  }
  _initialized = true;
  // ...
}

Export _resetInitialized() for test harness reset.

2. Governance filter observability

Problem: Governance filter decisions were only logged as aggregate counts (stateFiltered=N), making it impossible to trace which entries were filtered and why without replaying.

Fix: Add per-entry debug log with id, reason, score, and text snippet:

api.logger.debug(`memory-lancedb-pro: governance: filtered id=${r.entry.id} reason=state(${meta.state}) score=${r.score?.toFixed(3)} text=${r.entry.text.slice(0, 50)}`);

Testing

  • Regression tests: ✅ All pass (All regression tests passed!)
  • Local extensions: ✅ Gateway starts with initialized successfully only once

Files changed

  • index.ts: +14 lines (guard + logging + export)

- Add _initialized singleton flag to prevent re-initialization
  when register() is called multiple times during gateway boot
- Add per-entry debug logging for governance filter decisions
  (id, reason, score, text snippet) for observability
- Export _resetInitialized() for test harness reset
- Fixes initialization block repeated N times on startup
- Fixes governance filter decisions not observable in logs
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.

1 participant