Skip to content

fix: add defensive optional chaining for remaining .info.time.created accesses#5

Open
Milofax wants to merge 1 commit intoPlutarch01:masterfrom
Milofax:fix/malformed-message-time-crash
Open

fix: add defensive optional chaining for remaining .info.time.created accesses#5
Milofax wants to merge 1 commit intoPlutarch01:masterfrom
Milofax:fix/malformed-message-time-crash

Conversation

@Milofax
Copy link
Copy Markdown

@Milofax Milofax commented Apr 8, 2026

Summary

  • Adds ?. optional chaining + ?? 0 fallback to all 13 remaining occurrences of .info.time.created across store.ts, store-artifacts.ts, and store-search.ts
  • Prevents TypeError: undefined is not an object crash in ensureSummaryGraphSync and related code paths when messages have malformed or missing info.time metadata

Problem

v0.13.2 introduced getValidMessageInfo() and filterValidConversationMessages() to guard upstream entry points (#4), but 13 downstream access sites still use bare property chains and crash when a malformed message slips through:

TypeError: undefined is not an object
  (evaluating 'archivedMessages.at(-1)?.info.time.created')
  at ensureSummaryGraphSync (store.js)
  at transformMessages (store.js)

Changes

File Sites Fixed
src/store.ts 7 — diagnoseSummarySession, shouldSyncDerived ×3, buildArchivedSignature, ensureSummaryGraphSync ×2
src/store-artifacts.ts 3 — externalizeMessage ×2, writeStoredSession
src/store-search.ts 3 — searchSync, rebuildSessionFtsRowsSync, replaceMessageSearchRowSync

Verification

  • npm run typecheck
  • npm run lint
  • npm run build
  • npm test168/168 pass
  • Zero remaining bare .info.time.created patterns in source

All 13 remaining occurrences of `.info.time.created` across store.ts,
store-artifacts.ts, and store-search.ts crash with TypeError when a
message has malformed or missing `info.time` metadata.

v0.13.2 introduced `getValidMessageInfo()` and
`filterValidConversationMessages()` to guard upstream entry points,
but 13 downstream access sites still use bare property chains.

Replace every bare `.info.time.created` access with
`.info?.time?.created ?? 0` so a single malformed message cannot
crash the entire plugin.

Reproducer: any session containing a message where `info.time` is
undefined triggers:
  TypeError: undefined is not an object
    (evaluating 'archivedMessages.at(-1)?.info.time.created')
    at ensureSummaryGraphSync
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