Skip to content

Python: [Bug]: CosmosHistoryProvider generates an orphan GUID for empty session_id #9975

Open

Description

@lisry-1

Observed Behavior

CosmosHistoryProvider._session_partition_key generates a fresh random GUID on every call when session_id is None/empty. Because save_messages, get_messages, and clear each call it independently, saving with an empty session id writes to one partition while later reads/clears target different partitions. The stored messages become silently unreachable (orphaned) and can never be listed or cleared.

Expected Behavior

A missing/empty session_id should raise ValueError, aligning with the Redis (scoped) and VectorStore providers, instead of silently writing orphaned data.

Steps to Reproduce

  1. Configure CosmosHistoryProvider.
  2. Save messages with an empty session_id.
  3. Attempt to read/clear with the same empty session_id.

Minimal Reproduction

# save_messages(session_id=None, ...) writes to partition A
# get_messages(session_id=None, ...) reads from partition B -> empty

Additional Context

Fix PR: #9908

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Nov 2, 2026
  2. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Nov 2, 2026
  3. github-actions commented on Nov 2, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    The bug occurs in python/packages/azure-cosmos/agent_framework_azure_cosmos/_history_provider.py::_session_partition_key at lines 301-311 when session_id is None or empty. save_messages, get_messages, and clear independently generate different partition GUIDs. Minimal repro: construct the provider with a mocked container and assert that get_messages(None) and get_messages("") raise ValueError; both currently proceed and log generated GUIDs.

    • Failing test: python/packages/azure-cosmos/tests/test_cosmos_history_provider.py
    • Files examined: python/packages/azure-cosmos/agent_framework_azure_cosmos/_history_provider.py, python/packages/azure-cosmos/tests/test_cosmos_history_provider.py, python/packages/azure-cosmos/pyproject.toml
    • Tests run: test_none_session_id_generates_guid_partition_key, test_missing_session_id_raises_value_error
    • Current version: 1.0.0b261030
  4. added
    memoryUsage: [Issues, PRs], Target: memory related features
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Nov 2, 2026
  5. Wilson0511 commented on Nov 9, 2026

    @Wilson0511
    Contributor

    Cross-referencing the sibling census while this awaits triage — the data supports the proposed ValueError direction:

    Provider empty session_id behavior
    InMemoryHistoryProvider ignores session_id entirely (state-keyed)
    FileHistoryProvider stable shared bucket (_session_file_stem: session_id or DEFAULT_SESSION_FILE_STEM)
    Redis history, legacy key format stable shared bucket (_redis_key: session_id or 'default')
    Redis history, scoped key format raises ValueError("session_id must be a non-empty string...")
    VectorStoreHistoryProvider raises via _validate_session_id ("must be a non-empty string")
    CosmosHistoryProvider fresh GUID per call (this issue)

    Two notes for the decision:

    1. The two "shared default bucket" siblings are the legacy-shaped ones; both current-generation providers (Redis scoped, VectorStore) reject an empty id, so Python: fix(azure-cosmos): reject empty session_id instead of generating an orphan GUID #9908's ValueError aligns with where the family has converged.
    2. The existing pinned test test_none_session_id_generates_guid_partition_key explicitly asserts the generated key != "default" — a shared default partition is already encoded as not-the-intended-direction for Cosmos; what is left undecided is what empty-id writes should do. Rejecting closes the read/write incoherence described here (durable RU-billed writes to a partition no later call can ever address).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

memoryUsage: [Issues, PRs], Target: memory related featurespythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions