fix: graceful error handling for /undo#1
Open
wjiuxing wants to merge 4 commits into
Open
Conversation
added 3 commits
May 14, 2026 20:12
Replace raw console.error in all hooks with a configurable Logger that respects config.logLevel (default: warn). Hook errors are classified as warn (operational) or debug (cosmetic), so at default settings most noise disappears after /undo. - Add Logger utility (src/utils/logger.ts) with debug/info/warn/error - Add PendingMessageRepository.deleteBySessionId() for future undo cleanup - Wire logger through all 5 hooks and PlatformIngestionRuntime - Update all affected tests Closes clopca#17
- Logger: debug/info → console.log (stdout), warn → console.warn, error → console.error - Tests: pass Logger to all hook call sites (was made required) - Tests: capture console.log/warn/error for Logger verification - Fix extra bracket in crud.test.ts
Address review feedback — deleteBySessionId is now called in: - session.created: cleanup stale pending/failed from previous session lifecycle - session.idle: cleanup orphaned messages (covers /undo scenario) - session.completed/ended: final cleanup after processing Also updated session-events test mock to include deleteBySessionId.
wjiuxing
force-pushed
the
fix/undo-error-handling
branch
from
May 15, 2026 02:40
ab933c7 to
85d2b39
Compare
- Add message_id column to observations table (migration v2) - Store messageID from chat.message hook in observations - Add ObservationRepository.softDeleteByMessageId() for undo handling - Handle message.removed events in createEventHandler to soft-delete observations tied to the removed message - Remove deleteBySessionId from session.idle (message.removed is more precise, avoids aggressive pending message cleanup) - Update schema idempotency test for 2 migrations - Add 8 tests for message.removed handling (repository + event handler)
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
Fixes clopca#17 — error logs appearing after
/undoin opencode.Root Cause
open-mem's hooks assume "write = permanent" with no undo/cleanup path. After
/undo, opencode deletes messages but continues triggering hooks (e.g.session.idle), causing open-mem to error when referencing deleted data.Changes
Logger utility (
src/utils/logger.ts)Loggerclass with level-gated output (debug→console.log,warn→console.warn,error→console.error)OPEN_MEM_LOG_LEVELenv var (default:warn)Error handling (all hooks)
console.errorwithLoggerinstance — errors now properly categorizedCleanup mechanism (
src/db/pending.ts)deleteBySessionId()toPendingMessageRepository— removes pending/failed messages for a sessionTests (970 pass, 0 fail)
deleteBySessionIdtests: 3 tests covering status filtering, cross-session isolationLoggerparameter (now required)Files Changed (18 files, +451/-34)
src/utils/logger.tssrc/db/pending.tsdeleteBySessionIdmethodchat-capture.ts,compaction.ts,context-inject.ts,session-events.ts,tool-capture.tsconsole.errorwith Loggersrc/index.ts,src/platform-worker.ts,src/adapters/platform/runtime.tsVerification
tsc --noEmit— 0 errorsdebug/info→ stdout,warn→ stderr (distinct),error→ stderr