piker/ai/prompt-io/opencode/20260811T205826Z_06d5ea5d_p...

2.8 KiB

The user reported that certain IB order entries might have broken and provided a live failure for a first NVDA sell order. EMS delivered the request to brokerd.ib, but lazy get_mkt_info('nvda.nasdaq') contract qualification failed in MethodProxy._run_method() with:

tractor.trionics._broadcast.Lagged:
Task `piker.brokers.ib.broker.handle_order_requests` overrun and
dropped `0` values

The user suspected a cancelled symbol-search task might have left stale asyncio state. Cancellation can leave an orphaned method response, but the observed failure was stale Trio broadcast state. open_client_proxy() broadcast a one-slot LinkedTaskChannel to an always-running IB status relay and an idle method receiver. Status traffic advanced only the relay, so the first method call for an uncached symbol entered an already-lagged receiver. Orders for eagerly cached contracts bypassed this path.

The immediately preceding sparse-history commit did not modify IB order, symbol, or proxy code; it exposed no direct dependency on this failure.

git diff HEAD~1..HEAD -- piker/brokers/ib/api.py

Generated a sole-reader message demultiplexer for each IB client proxy. relay_client_proxy_messages() owns every asyncio-to-Trio receive, handles status/error traffic, and dispatches mid-tagged responses into per-call MethodProxy wait slots. Cancelled calls remove their pending slot, causing late responses to be logged and dropped without skewing later calls. Clean channel EOF is accepted during normal proxy teardown.

Follow-up review restored the masked reconnect TODO and per-message case rationale, documented the one-reader/many-writer task hierarchy and separate per-proxy channels, and added a warning with request method metadata when the bounded unresolved-request diagnostic table evicts its oldest entry.

git diff HEAD~1..HEAD -- tests/test_ib_method_proxy.py

Generated deterministic regressions for idle status traffic before first qualification, two concurrent calls with reverse-order responses, cancelled calls with late responses followed by a successful call, and graceful channel EOF. Every synchronization wait is timeout-bounded.

git diff HEAD~1..HEAD -- .claude/skills/run-tests/test-harness-reference.md

Registered the deterministic IB method-proxy target and source mapping.

Verification output:

........................                                                 [100%]
25 passed, 4 warnings in 3.44s

The warnings are existing Tractor/Trio deprecations from the EMS test. Adversarial review drove a clean-EOF guard and bounded polling. Final review found no actionable issues. Live IB order validation remains pending and requires restarting brokerd.ib.