Skip to content

Enforce EventLog idempotency for envelopes without a session id #49

@nficano

Description

@nficano

The event log promises duplicate-envelope rejection for (session_id, message_id), but SQLite treats NULL values in a unique constraint as distinct. The schema at lib/src/main/resources/arcp/store/schema.sql:22 declares UNIQUE (session_id, message_id), and EventLog.bindEnvelope at lib/src/main/kotlin/dev/arcp/store/EventLog.kt:71 writes null for envelopes that do not yet have a session id. That means duplicate pre-session envelopes such as repeated session.open messages with the same MessageId can be appended multiple times, contradicting the KDoc at lib/src/main/kotlin/dev/arcp/store/EventLog.kt:25 and the schema comment at lib/src/main/resources/arcp/store/schema.sql:3. The existing duplicate test at lib/src/test/kotlin/dev/arcp/store/EventLogTest.kt:35 only covers non-null session ids.

Fix prompt: Decide how null-session envelopes should be scoped, then encode that decision in the schema and tests. The narrow fix is a unique index over COALESCE(session_id, '') and message_id, or storing a sentinel session id for pre-session envelopes before insertion. Add a regression test that appends two envelopes with the same MessageId and sessionId = null and expects ARCPException.AlreadyExists, and keep the existing non-null session duplicate test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingseverity:mediumMedium severity issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions