<!-- llms-explorer concept facts · https://llms-explorer.com/tree/pinned-event-mongodb-lifecycle-record-identity-and-worker-ownership-observations/ · pack 2026-11-02 · ~2076 tokens -->

# Pinned event-mongodb lifecycle record identity and worker ownership observations

> Source-anchored research for Pinned event-mongodb lifecycle record identity and worker ownership observations. Run status: COMPLETED.

Parent: [Change Data Capture Patterns](https://llms-explorer.com/tree/change-data-capture-patterns/) · 5 facets · 13 facts · page: https://llms-explorer.com/tree/pinned-event-mongodb-lifecycle-record-identity-and-worker-ownership-observations/

## Definitions

- The MongoDB monitor identity is the compound pair `event_id` and `subscription_id`: `Indexes` requests a unique index on that pair and `Record` uses it as the upsert filter. Neither `bus_id` nor `worker_group` participates in that identity, even though both are stored as fields. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/mongodb.go)

## How it works

- `RecordComplete` delegates to `UpdateStatus` with the supplied `EventID` and `SubscriptionID` unchanged. Because `fromEntry` clears the WorkerPool subscription at record time, a caller completing that stored worker record must address the empty subscription key; this completion path does not repeat the mode-dependent normalization. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/mongodb.go)
- The integration setup creates a store over a unique database and calls `store.EnsureIndexes`; its source comment says the tests skip when MongoDB is unavailable or short mode is selected. This fixture source defines store setup and assertions. The quoted source is not an execution-result report, so it does not establish that an integration run occurred. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/integration_test.go)

## Problems, failure modes and limitations

- The `Broadcast` branch of `Record` uses `$set` for per-delivery fields, including timing, trace identifiers, status and error, and reserves `$setOnInsert` for the identity fields. `TestIntegrationMonitorRecordUpsert` re-records the same broadcast key with completed status and asserts one document with that updated status; these assertions are fixture content. (medium confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/mongodb.go) · [also](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/integration_test.go)
- `UpdateStatus` filters only by event and subscription identifiers, sets status, elapsed milliseconds and the current completion time, and writes the error only when the supplied error is non-nil. It supplies no instance, owner token or generation predicate and discards the update result. Thus this monitor update cannot by itself demonstrate winning-worker fencing or report that a record actually matched. A nil error does not explicitly clear a previously stored error. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/mongodb.go)
- `TestIntegrationMonitorRecordStartComplete` directly calls the lifecycle store methods: its success case expects pending then completed with the supplied duration, and its failure case expects failed status, the supplied error and a failed-entry query result. The fixture body does not invoke a business handler or coordinate competing workers; those execution and ownership guarantees are outside these assertions. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/integration_test.go)

## Comparisons and alternatives

- In the `WorkerPool` branch, `Record` places all listed values in `$setOnInsert`, including `instance_id`, `started_at`, `trace_id`, `span_id`, metadata, status, error, retry count and worker group. On a matching existing record, this branch supplies no `$set` replacement of those values. The preservation applies to the first inserted record, rather than proving which worker acquired processing ownership. The nearby comment describes the first recorder as most likely to win acquisition; the executable write does not itself acquire a processing claim. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/mongodb.go)

## Facts and statements

- `fromEntry` replaces `SubscriptionID` with an empty string for `WorkerPool`, while preserving `WorkerGroup` as a field. The coverage fixture `TestEntryRoundTrip_WorkerPoolClearsSubscriptionID` explicitly expects the cleared subscription after conversion; this is a source observation, not an executed test result. (medium confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/mongodb.go) · [also](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/coverage_test.go)
- The fromEntry conversion copies `e.InstanceID` into the stored InstanceID field. By contrast, the entry literal constructed by `RecordStart` does not assign InstanceID. `RecordStart` selects Broadcast unless the WorkerPool parameter is true, constructs a pending entry with the current start time and the supplied subscriber, event, bus, metadata, trace, span and worker-group fields, then returns `s.Record(ctx, entry)`. The Record method persists the resulting entry. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/mongodb.go)
- `RecordStart`, `RecordComplete` and `RecordPublish` converge on the same `MongoStore` collection through `Record` or `UpdateStatus`. The package documentation identifies this store as per-event lifecycle storage and as an implementation of the publish audit interface. (medium confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/mongodb.go) · [also](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/doc.go)
- `RecordPublish` constructs a `Broadcast` entry keyed by `EventID` and `PublishMarker`, with published status, `params.BusName` mapped to `InstanceID`, copied metadata and trace identifiers, and the same timestamp assigned to start and completion. It delegates to `Record`, so another publish record for that key follows the Broadcast replacement branch. The source comment distinguishes the marker key from the empty WorkerPool subscription key. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/mongodb.go)
- `GetByEventID` reads every document matching the event identifier and sorts by start time ascending. `TestIntegrationMonitorRecordPublish` writes a publish milestone and then directly records a completed subscriber entry; it asserts that the event lookup returns both entries. The fixture supports marker/subscriber coexistence in the store, without demonstrating a business handler execution. (medium confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/mongodb.go) · [also](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/integration_test.go)
- `TestEntryRoundTrip` supplies trace and span strings in a constructed broadcast entry and checks conversion through `assertEntryEqual`, whose assertions compare those strings. `RecordStart` and `RecordPublish` likewise copy supplied trace identifiers. These source observations establish identifier storage paths and fixture expectations, but do not establish complete distributed tracing across real processing. (medium confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/coverage_test.go) · [also](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/monitor/mongodb.go)
