Files
substrate/cmd/ateapi/internal/workercache
shrutiyam-glitch a30645f9fe ateapi: apply a replica's own worker writes to its cache at commit (#1583)
Fixes #1370

**Summary**
`atepg` keeps a registry of the live `WatchWorkers` channels and
publishes each committed worker event onto them at commit, about one
poll interval ahead of the outbox row carrying the same event. Replicas
see their own writes sooner without a second notification API.

**Why**
Replicas previously learned of their own writes only from the outbox
watch, ~50ms later. In that window the scheduler re-picks a worker it
just assigned and retries on the precondition check, and capacity a
replica just freed stays invisible to its own placement. Cross-replica
propagation is unchanged.

**Key changes**
- `WatchWorkers` enrolls its channel; the poller deregisters before
closing it, which is what makes a send on a closed channel impossible.
- `writeAndAppendEvent` publishes only after `tx.Commit` returns.
- The commit-time copy is decoded from the same payload the outbox
stores, so both deliveries are identical, including unknown-field
pruning.
- Sends are non-blocking and never advance the poll cursor, so a full
buffer costs a watcher nothing and gap-free delivery is unchanged.
- Consumers now also see their own writes out of xid order and again on
the poll. `workercache` already fences creates and updates on version,
so duplicates and stale events are no-ops.

**Testing**
`TestLocalPublishReachesWatchers`, `TestLocalPublishSurvivesWatchClose`,
and `TestCache_WatchEventsAreFenced` are new.
`TestWatchWorkers_DeliveryFencedByOldestTransaction` now consumes the
commit-time copy first and asserts the xmin fence on the outbox copy;
the fence governs the poll, and a local publish bypasses it by
construction.

Full `atepg` and `workercache` suites pass under `-race`.

- [X] Tests pass
- [X] Appropriate changes to documentation are included in the PR
2026-09-15 12:56:50 -04:00
..