Skip to content

CouchbaseChatMessageHistory reports a failed write as written, reads as empty on any error, and clear() swallows a failed DELETE #44

Closed

Description

@ericdelorefice

Problem

CouchbaseChatMessageHistory.add_messages writes with Collection.insert_multi, which by the SDK's default returns per-document failures in its MultiMutationResult instead of raising. The result is never read, so a write that failed is reported to the caller as written. In the same package, CouchbaseVectorStore.add_texts checks result.all_ok and raises; the chat history is the odd one out.

Two related swallows in the same class: the read path returns an empty conversation on any error, which is the same answer as a new conversation, and clear() logs and swallows a failed DELETE, so a cleared conversation can survive while the caller is told it is gone. For an agent built on this history, a turn can be lost or a whole history read as empty with nothing in the logs.

Reproduction

The failures are injected: a MultiMutationResult built the way the SDK builds it with return_exceptions=True (a control checks all_ok is False and the exception is present), and an AmbiguousTimeoutException on the read and the delete. I have not reproduced this against a live cluster. On the current code, add_messages returns normally with a failed result, messages returns [] on the read failure, and clear() returns normally on the delete failure.

Expected: a failed write, read or delete raises, the way add_texts raises on a failed write. Actual: each returns normally, as above.

Environment

Tested on main at 5f3c36d (langchain-couchbase 1.1.1), Python 3.12.14, couchbase SDK 4.6.3, langchain-core 1.6.6.

Proposed change

Small and mostly re-indentation: remove the three handlers so errors propagate, check all_ok in add_messages and raise the way add_texts already does, and let clear()'s DELETE failure propagate. The intended behaviour change is that a failed read now raises instead of returning an empty list. Seven tests fail on the current code, six controls pass, and all thirteen pass with the change. I have the fix and tests ready and am glad to open a pull request if that is welcome.

This issue was written with AI assistance (Claude Code); the tests above were run before filing.

Activity

  1. deniswsrosa commented on Oct 26, 2026

    @deniswsrosa

    @dex-the-ai could you please take a look?

  2. self-assigned this
    on Oct 26, 2026
  3. dex-the-ai commented on Oct 26, 2026

    @dex-the-ai
    Contributor

    Opened #45 for this. add_messages now checks all_ok and raises the way add_texts does. The handlers in add_message, messages and clear() are removed, so SDK errors propagate. It includes 14 unit tests using the injected-MultiMutationResult approach you described, plus a live repro on Couchbase Server 8.0.1: after dropping the collection, main returns normally on all four calls, and #45 raises on all four. Thanks for the clear report, @ericdelorefice.

  4. nithishr commented on Oct 29, 2026

    @nithishr
    Contributor

    This has been released as part of 1.2.0.
    Thank you, @ericdelorefice for raising the issue!

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions