fix(worker): ReadBulk never tears down a caller's item or subscription (#238)

ReadBulk sent every advised-but-uncached and added-but-not-advised tag
down the snapshot path. MXAccess returns the caller's existing handle for
a re-added address, so the snapshot's AddItem/Advise ran on the caller's
own item and the symmetric teardown then UnAdvised and RemoveItem'd it:
the subscription delivered one value and went silent.

Teardown is now ownership-scoped: it unadvises only advices the read's
own Advise created and removes only items the read's own AddItem created.
A tag the session already holds is read through the caller's handle with
no AddItem: advised-but-uncached waits on the existing subscription with
no COM call; added-but-not-advised is advised for the read and unadvised
afterwards (back to its prior state), never removed. A snapshot AddItem
that returns a handle the registry already tracks (differently spelled
address) is treated as the caller's item and never removed.

Adds MxAccessSessionTests regressions; updates gateway.md, Contracts,
DesignDecisions, MxAccessWorkerInstanceDesign.
This commit is contained in:
Joseph Doherty
2026-12-01 19:25:19 -05:00
parent 54367e7408
commit 7a41d9edea
8 changed files with 520 additions and 78 deletions
+13 -4
View File
@@ -355,10 +355,19 @@ timeout.
`ReadBulk` runs its snapshot lifecycle in phases so the STA is held for at most
one `timeout_ms` per command, not one per tag: (1) every tag is validated and
probed against the cached-and-advised fast path; (2) every remaining tag is
added and advised; (3) one wait with a shared deadline collects the first
`OnDataChange` per snapshot handle and returns as soon as all have delivered;
(4) every snapshot handle is unadvised and removed, best-effort. Per-tag
probed against the registry and the cached-and-advised fast path; (2) every
remaining tag gets an advised handle — a tag the session does not hold gets
the read's own `AddItem`, a tag it holds keeps the caller's item handle, and
the handle is advised only when nothing advises it yet; (3) one wait with a
shared deadline collects the first `OnDataChange` per handle and returns as
soon as all have delivered; (4) teardown, best-effort and ownership-scoped,
unadvises only the advices phase 2 created and removes only the items phase 2
added. The caller's items are therefore never removed and the caller's
subscriptions never unadvised: an advised-but-uncached caller tag is waited on
through the existing subscription with no COM call, and an added-only caller
item is advised for the read and unadvised afterwards, back to its prior
state (#238). A snapshot `AddItem` that returns a handle the registry already
tracks is treated as the caller's item for the same reason. Per-tag
results are unchanged: request order, the blank-address failure, the cached
result, an `AddItem` failure (item handle 0) or `Advise` failure (its own item
handle) failing only that tag, and the `ReadBulk timed out after <n> ms waiting