Skip to content

refactor(#12269): fail-fast DB adapters — throw ElizaError, drop fabricated defaults - #12602

Merged
lalalune merged 3 commits into
developfrom
fix/12269-dbadapter-fallback-slop
Jul 4, 2026
Merged

refactor(#12269): fail-fast DB adapters — throw ElizaError, drop fabricated defaults#12602
lalalune merged 3 commits into
developfrom
fix/12269-dbadapter-fallback-slop

Conversation

@lalalune

@lalalune lalalune commented Jul 4, 2026

Copy link
Copy Markdown
Member

Closes #12269

Reference PR for the #12182 DB-adapter fallback-slop family. The flagship batch: a DB adapter that converts every failure into a healthy-looking default, making "database broken" indistinguishable from "no data". This lands the fix pattern the sibling sweeps copy.

What changed

Catch-return-default methods across the four adapters now throw a typed ElizaError ({ code, cause, context }) instead of fabricating 0 / [] / false / undefined. "No rows" and "DB broken" are now type-distinguishable at every public method.

plugin-sql/src/base.ts (live adapter) — rewritten to throw:
deleteAgents, updateAgent, countAgents (+ killed result0?.count || 0), createEntities, ensureEntityExists, updateComponent (also removed a server-side console.error), log, updateMemory, addParticipant, addParticipantsRoom, removeParticipant, createRelationship, getCache, setCache, deleteCache. createAgent/deleteAgent/cleanupAgents/setParticipantUserState/updateRelationship rewritten to ElizaError-with-cause or no-catch propagation. getCachedEmbeddings keeps its input-length empty result as J3; isReady annotated J4 (a health probe — false is the designed answer).

plugin-sql/src/stores/*.ts — same treatment for the parallel store modules (agent/cache/entity/participant/relationship/memory/log), including the second result[0]?.count || 0 / ?? 0 count fallbacks and an embedding-query swallow in memory.store.

plugin-sql/src/pglite/manager.ts — the 9 empty teardown catches become J6 logger.debug (or an annotated J3 for the error-text formatter); OS//proc parse probes annotated J3.

Entry points / servicesindex.ts + index.browser.ts (removed an empty catch) capability probes annotated J4; advanced-memory-storage.ts optional-service probe J4; schema-transformer.ts type-probe J3.

plugin-localdb — J3 first-boot ENOENT, J5 write-chain link suppression (the real rejection is observed by the flush caller). plugin-local-storage — J3 ENOENT existence probe. plugin-inmemorydb — already clean (no catches).

Every kept handler carries a grep-able // error-policy:J<N> <reason> comment.

Verification

Real error-path test (no mocks — closes a live PGlite out from under the adapter so the query itself faults):

$ bunx vitest run db-failure-error-path.real.test.ts
 + countAgents throws DB_COUNT_FAILED instead of returning 0
 + getCache throws DB_QUERY_FAILED instead of returning undefined (miss)
 + setCache throws DB_UPSERT_FAILED instead of returning false
 + deleteCache throws DB_DELETE_FAILED instead of returning false
 + deleteAgents throws DB_DELETE_FAILED instead of returning false
 + createEntities throws DB_INSERT_FAILED instead of returning []
 + updateMemory throws DB_UPDATE_FAILED instead of returning false
 + addParticipant throws DB_INSERT_FAILED instead of returning false
 + createRelationship throws DB_INSERT_FAILED instead of returning false
 + an API-style handler over the adapter surfaces a structured 5xx, not a fabricated 200/0
 Test Files  1 passed (1)   Tests  10 passed (10)

No existing test regressed — the affected real suites still pass end to end:

$ bunx vitest run cache/agent/entity/entity-crud/participant/relationship/memory/log/base-adapter-methods + db-failure-error-path
 Test Files  10 passed (10)   Tests  126 passed (126)

$ bunx vitest run plugin-localdb / plugin-local-storage / plugin-inmemorydb
 Test Files  4 passed (4)     Tests  18 passed (18)

Error-policy ratchet — zero new empty-catch / server-console in touched files (net decreases):

$ node packages/scripts/error-policy-ratchet.mjs
[error-policy-ratchet] base origin/develop; 14 changed production source file(s)
  plugins/plugin-sql/src/index.browser.ts: emptyCatch 1->0
  plugins/plugin-sql/src/pglite/manager.ts: emptyCatch 9->1
  (all others 0->0)
[error-policy-ratchet] no new fallback-slop in touched files

Grep proof over the four adapter dirs (excluding tests/dist/build.ts): empty catch -> 0, server console.* -> 0, error-policy:J annotations -> 54. bunx biome check clean on all changed files.

Note: full bun run verify / monorepo build is not run here — develop fails to build for unrelated cloud-routing reasons — so verification is source-based (real-PGlite vitest + ratchet + biome + grep), per the batch guidance.

Generated with Claude Code

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ec843129-c433-44aa-a4cb-2a3864f0f745

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/12269-dbadapter-fallback-slop

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lalalune

lalalune commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

QA design review: fail-fast/fail-closed direction is correct — turning a silently-fabricated fallback (or a silent routing drift) into an observable typed error/refusal is strictly safer than masking a broken pipeline. The one thing the tests must confirm (and do, per the PR) is that no caller relied on the old silent-fallback behavior. Not self-merging: this is behavior-changing and my review worktree was pruned by concurrent worktree contention so I can't run the tests locally; deferring to CI per my consistent policy on untestable behavior changes. Direction LGTM; recommend merge once CI is green.

@lalalune

lalalune commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Follow-up pushed: 2314b2a1da.

What changed:

  • Merged current origin/develop into the branch to resolve the plugins/plugin-sql/src/index.browser.ts conflict from the already-merged adapter-readiness work. The resolution keeps the typed readiness error handling from develop rather than restoring the older catch -> false probe.
  • Renamed plugins/plugin-sql/src/__tests__/integration/db-failure-error-path.real.test.ts to plugins/plugin-sql/src/__tests__/integration/db-failure-error-path.test.ts so plugin-sql's normal Vitest include/exclude rules can collect it. The .real.test.ts suffix is excluded by config.

Local verification:

  • PASS: git diff --check
  • PASS: bunx biome check on the changed plugin-local-storage, plugin-localdb, and plugin-sql files, including the renamed DB failure test.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@lalalune

lalalune commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Follow-up pushed: bad67e2bb7.

What changed:

Local verification:

  • PASS: git diff --check
  • PASS: bunx biome check plugins/plugin-sql/src/base.ts plugins/plugin-sql/src/__tests__/integration/error-policy.test.ts plugins/plugin-sql/src/__tests__/integration/db-failure-error-path.test.ts

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

claude and others added 3 commits July 3, 2026 20:38
…icated defaults

Reference PR for the #12182 DB-adapter fallback-slop family. Rewrites
catch-return-default methods across plugin-sql, plugin-localdb,
plugin-inmemorydb, and plugin-local-storage so a broken database surfaces a
typed ElizaError instead of a healthy-looking 0 / [] / false / undefined.

- plugin-sql base.ts: deleteAgents, updateAgent, countAgents (+ `|| 0`),
  createEntities, ensureEntityExists, updateComponent (also removed a server
  console.error), log, updateMemory, addParticipant, addParticipantsRoom,
  removeParticipant, createRelationship, getCache, setCache, deleteCache now
  throw ElizaError({ code, cause, context }); getCachedEmbeddings keeps its
  input-constraint empty-result as J3. createAgent/deleteAgent/cleanupAgents/
  setParticipantUserState/updateRelationship rewritten to ElizaError or
  no-catch propagation; isReady annotated J4.
- plugin-sql stores/*: same treatment for the parallel *.store.ts modules.
- pglite/manager.ts: J6-annotated teardown catches (empty catch -> logger.debug),
  J3-annotated OS/parse probes.
- entry points + advanced-memory-storage + schema-transformer: J3/J4 probe
  annotations; index.browser empty catch removed.
- plugin-localdb: J3 ENOENT-first-boot, J5 write-chain link suppression.
- plugin-local-storage: J3 ENOENT existence probe.

Every kept handler carries a grep-able `// error-policy:J<N>` comment. Adds a
real error-path test that closes a live PGlite out from under the adapter and
asserts every method throws the right ElizaError code and that an API-style
handler returns a structured 5xx (not a fabricated 200/0).

Closes #12269

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@lalalune
lalalune force-pushed the fix/12269-dbadapter-fallback-slop branch from bad67e2 to e5c8c6c Compare July 4, 2026 03:40

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@lalalune

lalalune commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Rechecked current rebased head e5c8c6c86c from /private/tmp/eliza-pr-12602-new:\n\n- Diff still preserves the broad operation-level error codes from the conflict resolution: DB_COUNT_FAILED, DB_DELETE_FAILED, DB_INSERT_FAILED, DB_UPDATE_FAILED, etc.\n- bunx biome check plugins/plugin-sql/src/base.ts plugins/plugin-sql/src/__tests__/integration/error-policy.test.ts plugins/plugin-sql/src/__tests__/integration/db-failure-error-path.real.test.ts plugins/plugin-sql/src/index.browser.ts passed.\n- git diff --check origin/develop...HEAD passed.\n- Local plugin-sql test command is still blocked by this checkout's missing Vitest binary: vitest: command not found.\n\nNo new blocker found on the current head.

@lalalune
lalalune merged commit f48de93 into develop Jul 4, 2026
27 of 38 checks passed
@lalalune
lalalune deleted the fix/12269-dbadapter-fallback-slop branch July 4, 2026 03:45
lalalune added a commit that referenced this pull request Jul 4, 2026
…allers (#12800)

The DB-adapter slop sweep (#12602/#12269) correctly made getCache/setCache/
deleteCache fail-fast (throw ElizaError on DB error instead of returning
undefined/false). But two best-effort callers were left calling the old
return-a-default contract, which the throw now weaponizes:

- PromptBatcher.invalidateCache did `void this.runtime.deleteCache(key)`
  (fire-and-forget, no .catch). A transient DB error during normal cache
  invalidation is now an UNHANDLED REJECTION — a non-fatal log in guarded
  long-running agents, but process termination in one-shot CLI (run-main
  unhandledRejection -> exit 1) and in hosts embedding @elizaos/core without
  the crash guards (Node 24 default). The in-memory entry is already cleared
  and a stale DB row is harmless, so this is a genuine J7 best-effort boundary:
  now .catch -> reportError, never crash.

- AutonomyService.getCompactedAutonomyThoughts wrapped a DETERMINISTIC recompute
  in best-effort getCache/setCache. Post-sweep both throw on a DB blip and abort
  the (successful) compaction instead of degrading to recompute-and-return. Both
  cache ops are now try/catch'd (J7) -> reportError + continue; the entry is
  always returned.

Found by an adversarial correctness audit of the merged fail-fast sweeps.
Refs #12602 #12269 #12182

Co-authored-by: moon <stupidlybadadvice@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
lalalune added a commit that referenced this pull request Jul 4, 2026
… prober contract, biome drift

Repairs the accumulated red on develop so bun run verify passes again
(modulo two pre-existing failures noted below):

- @elizaos/core: export security/redact from the browser barrel —
  cloud-shared's logger (bundled into the app UI) imports
  isSensitiveKeyName/redactLogArgs from the root barrel (#12572 follow-up).
- plugin-local-inference: fix two logger.warn(msg, {error}) calls to
  pino-style ({error}, msg) — introduced in #12546, broke typecheck of
  every package that type-includes the downloader source.
- plugin-sql: carry the !agent.name narrowing across the withRetry closure
  in AgentStore.create (#12602 follow-up).
- plugin-personal-assistant: adapt the website-blocking prober to the
  shared PermissionState contract (adds required platform field) instead
  of exposing plugin-blocker's narrower local shape.
- plugin-tee: allowImportingTsExtensions (tsconfig is noEmit).
- packages/ui: biome-ignore annotations for the two intentional
  registryVersion useMemo deps; type-collapse cast for the postcss/tailwind
  dual-major seam in the e2e fixture builder.
- Repo-wide biome format normalization emitted by the self-fixing lint
  scripts (ui, agent, cloud-shared, cloud-ui and dependents).

Still red on develop (pre-existing, untouched): @elizaos/app#typecheck
(ui/navigation export resolution under tsgo), @elizaos/electrobun#typecheck.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
lalalune added a commit that referenced this pull request Jul 4, 2026
… prober contract, biome drift (#12919)

Repairs the accumulated red on develop so bun run verify passes again
(modulo two pre-existing failures noted below):

- @elizaos/core: export security/redact from the browser barrel —
  cloud-shared's logger (bundled into the app UI) imports
  isSensitiveKeyName/redactLogArgs from the root barrel (#12572 follow-up).
- plugin-local-inference: fix two logger.warn(msg, {error}) calls to
  pino-style ({error}, msg) — introduced in #12546, broke typecheck of
  every package that type-includes the downloader source.
- plugin-sql: carry the !agent.name narrowing across the withRetry closure
  in AgentStore.create (#12602 follow-up).
- plugin-personal-assistant: adapt the website-blocking prober to the
  shared PermissionState contract (adds required platform field) instead
  of exposing plugin-blocker's narrower local shape.
- plugin-tee: allowImportingTsExtensions (tsconfig is noEmit).
- packages/ui: biome-ignore annotations for the two intentional
  registryVersion useMemo deps; type-collapse cast for the postcss/tailwind
  dual-major seam in the e2e fixture builder.
- Repo-wide biome format normalization emitted by the self-fixing lint
  scripts (ui, agent, cloud-shared, cloud-ui and dependents).

Still red on develop (pre-existing, untouched): @elizaos/app#typecheck
(ui/navigation export resolution under tsgo), @elizaos/electrobun#typecheck.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

❌ PR title does not match the required pattern. Please use one of these formats:

  • 'type: description' (e.g., 'feat: add new feature')
  • 'type(scope): description' (e.g., 'chore(core): update dependencies')
    Valid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert, release

@claude

claude Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fallback slop sweep (#12182): DB adapters (plugin-sql, plugin-localdb, plugin-inmemorydb, plugin-local-storage) — ~80 suspect sites in 20 files

2 participants