dita_v2(zinc): account-truth plane API — publish/read/wait_on/notify_account

Formalizes the CEX-010 E-feed account plane (protocol + InMemoryZincPlane +
real plane). This code flew 33h on UV-PRIME flight-1 via the vendored copy
(T0-DEVIATION mid-edit vendoring) but was never committed upstream — the
2026-07-11 clean vendor_sync regressed it and broke the E-feed at boot
(AttributeError publish_account). Committing the flight-proven bytes closes
the vendor-law gap. Authorship: pre-existing WIP in /mnt working tree
(T0-era, likely codex), committed verbatim by Fable for vendor integrity.
This commit is contained in:
Codex
2026-07-11 22:46:33 +02:00
parent 7a512544b7
commit df40e62104
2 changed files with 99 additions and 10 deletions

View File

@@ -12,7 +12,10 @@ from typing import Any, Dict, Iterable, List, Mapping, Optional, Protocol
import threading
import time
from .contracts import KernelIntent, TradeSlot, VenueTelemetrySnapshot
from .contracts import AccountStateSnapshot, KernelIntent, TradeSlot, VenueTelemetrySnapshot
from .double_buffer import DoubleBufferRegion, SingleSlotRegion
from .control import KernelControlSnapshot
from .control import KernelControlSnapshot
from .control import KernelControlSnapshot
@@ -64,23 +67,44 @@ class ZincPlane(Protocol):
def notify_venue(self) -> None:
...
def publish_account(self, snapshot: "AccountStateSnapshot") -> None:
...
def read_account(self) -> "AccountStateSnapshot":
...
def wait_on_account(self, timeout_ms: int = 1000) -> bool:
...
def notify_account(self) -> None:
...
@dataclass
class InMemoryZincPlane:
"""Simple in-memory Zinc lookalike for Python prototype tests."""
"""In-memory Zinc lookalike with double-buffer regions — torn-read impossible."""
intent_region: List[KernelIntent] = field(default_factory=list)
state_region: Dict[int, TradeSlot] = field(default_factory=dict)
control_region: Optional[KernelControlSnapshot] = None
venue_region: VenueTelemetrySnapshot = field(default_factory=VenueTelemetrySnapshot)
control_region: SingleSlotRegion[Optional[KernelControlSnapshot]] = field(
default_factory=lambda: SingleSlotRegion(lambda: None)
)
venue_region: SingleSlotRegion[VenueTelemetrySnapshot] = field(
default_factory=lambda: SingleSlotRegion(lambda: VenueTelemetrySnapshot())
)
account_region: SingleSlotRegion[AccountStateSnapshot] = field(
default_factory=lambda: SingleSlotRegion(lambda: AccountStateSnapshot())
)
_intent_seq: int = field(default=0, init=False, repr=False)
_state_seq: int = field(default=0, init=False, repr=False)
_control_seq: int = field(default=0, init=False, repr=False)
_venue_seq: int = field(default=0, init=False, repr=False)
_account_seq: int = field(default=0, init=False, repr=False)
_intent_observed_seq: int = field(default=0, init=False, repr=False)
_state_observed_seq: int = field(default=0, init=False, repr=False)
_control_observed_seq: int = field(default=0, init=False, repr=False)
_venue_observed_seq: int = field(default=0, init=False, repr=False)
_account_observed_seq: int = field(default=0, init=False, repr=False)
_signal: threading.Condition = field(default_factory=threading.Condition, init=False, repr=False)
def publish_intent(self, intent: KernelIntent) -> None:
@@ -100,14 +124,15 @@ class InMemoryZincPlane:
def update_control(self, control: KernelControlSnapshot) -> None:
with self._signal:
self.control_region = control
self.control_region.write(control)
self._control_seq += 1
self._signal.notify_all()
def read_control(self) -> KernelControlSnapshot:
if self.control_region is None:
val = self.control_region.read()
if val is None:
return KernelControlSnapshot()
return self.control_region
return val
def wait_on_intent(self, timeout_ms: int = 1000) -> bool:
return self._wait_for_change("_intent_seq", "_intent_observed_seq", timeout_ms)
@@ -135,12 +160,12 @@ class InMemoryZincPlane:
def publish_venue(self, telemetry: VenueTelemetrySnapshot) -> None:
with self._signal:
self.venue_region = telemetry
self.venue_region.write(telemetry)
self._venue_seq += 1
self._signal.notify_all()
def read_venue(self) -> VenueTelemetrySnapshot:
return self.venue_region
return self.venue_region.read()
def wait_on_venue(self, timeout_ms: int = 1000) -> bool:
return self._wait_for_change("_venue_seq", "_venue_observed_seq", timeout_ms)
@@ -150,6 +175,23 @@ class InMemoryZincPlane:
self._venue_seq += 1
self._signal.notify_all()
def publish_account(self, snapshot: AccountStateSnapshot) -> None:
with self._signal:
self.account_region.write(snapshot)
self._account_seq += 1
self._signal.notify_all()
def read_account(self) -> AccountStateSnapshot:
return self.account_region.read()
def wait_on_account(self, timeout_ms: int = 1000) -> bool:
return self._wait_for_change("_account_seq", "_account_observed_seq", timeout_ms)
def notify_account(self) -> None:
with self._signal:
self._account_seq += 1
self._signal.notify_all()
def _wait_for_change(self, seq_attr: str, observed_attr: str, timeout_ms: int) -> bool:
timeout_s = None if timeout_ms is None or timeout_ms < 0 else max(0.0, timeout_ms / 1000.0)
deadline = None if timeout_s is None else time.monotonic() + timeout_s