From f2ad799eecb633905ce8648e2a04c2b8dd99bcdb Mon Sep 17 00:00:00 2001 From: goodboy Date: Thu, 3 Dec 2026 12:43:11 -0500 Subject: [PATCH] Track history repair and broker qualification in Taken Record the shared IB quote restore and two-consumer restart test without marking either accepted. Separate the Dec 1 Kraken test baseline from the current branches and defer debugger-pause removal until parity lands on `main`. Track interrupted backfills, split-adjusted bars and Kraken history repair from public trades. Link the trade-rate probe and record the paper order routing and MarketStore retirement follow-ups. (this patch was generated in some part by `pi` using `gpt-6.2-astra` (`openai-codex`)) --- .taken/current.org | 369 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 364 insertions(+), 5 deletions(-) diff --git a/.taken/current.org b/.taken/current.org index 996414e8..72fb1d11 100644 --- a/.taken/current.org +++ b/.taken/current.org @@ -994,6 +994,37 @@ sequence still needs its first run. - Decide on automation after the first baseline. Prefer a separate paper login and Gateway instance for recurring restart jobs. +**** TODO Qualify shared IB quote ownership across consumer exit and restart +:PROPERTIES: +:ID: piker-ib-quote-channel-ownership +:CREATED: [2026-11-29] +:CARRIED: 0 +:REPO: /home/goodboy/repos/piker +:TAKEN_APPEND_OP: ib-quote-ownership-20261129 +:TAKEN_APPEND_REQUEST: 9f4f7056b7f40e3a0f10cc49176212c721e8093cc35bf1bba7113708cfff78ea +:END: +On =wkt/land_feed_endpoint_reuse=, =a4d83e2a= restored shared IB +quote ownership from =4af885d9= (INUSE =eb0514c3=). The earlier +replay =635314c7= was backed out by =72d0bdad= after quote restart +killed the broker actor. The restore uses Tractor =8fe574c1=, pinned +by piker =cb5e81d4=. Keep this review separate from venue/history. + +Commit =1cc15352= adds the offline two-consumer restart regression +in =tests/providers/test_ib_shared_quote_probe.py=. Review the +committed restore and regression against the acceptance checks below. + +- [ ] Compare the direct-owner baseline with the restored shared + channel using the same offline scenario. Record the observed + outcomes and the piker and Tractor revisions. +- [ ] Open two consumers for one symbol. Count one upstream + subscription, deliver a quote to both, close either consumer first, + and deliver another quote to the survivor. Verify last-consumer + cleanup and a clean restart with fresh quote delivery. +- [ ] Issue a second RPC to the same actor after restart and capture + asyncio callback errors independently of actor survival. Check for + lingering tasks and subscriptions. No live Gateway is needed. +- [ ] Record which behavior the restore fixes and any remaining + teardown regression for the maintainer's acceptance decision. *** Chart lifecycle, E2E and order-bootstrap ownership :PROPERTIES: :ID: piker-workstream-chart-lifecycle @@ -1035,8 +1066,22 @@ and human-daemon access remain separately authorized operations. :END: Objective: qualify durable history repair without shifting published rows, persisting synthetic observations or publishing stale FSP data. -Next action: review the staged and unstaged segment-refill work in -=wkt/ib_history_request_bounds@eed58566= before treating it as landed. +Resume after the INUSE parity core lands on upstream main. Port from +the index of =wkt/history_segment_refill= (renamed from +=wkt/ib_history_request_bounds=), based at =179a8c81= as of Nov 29. +The branch ref alone omits the implementation. Inspect both +=git diff --cached= and =git diff= before selecting individual hunks. + +The staged work includes the IB opt-in, datad RPC registration, +=Refiller=, NativeDB journaling, store CLI, chart invalidation, tests, +docs and prompt records. Review the staged =code-docs= skill on its +own merits. Preserve the source index while qualifying the port. +In =piker/brokers/ib/feed.py= only the =segment_repair= opt-in is +staged. The unstaged wire/normalization and sampler tracing, including +untracked helpers, tests and docs, belongs with +[[id:piker-ib-startup-history-reconciliation][IB startup quote reconciliation]]. +Account for the local dependency overrides, websocket logging edit and +review artifacts separately when reconciling the source checkout. **** Context and prerequisites @@ -1044,8 +1089,8 @@ This checkout has staged segment-refill/storage/CLI/history changes, additional unstaged IB feed changes, and boot-trace/sampler tests. Its history plan explicitly distinguishes implemented paths from proposed contexts and deferred consumer behavior. -[[file:/home/goodboy/repos/piker/wkts/ib_history_request_bounds/docs/history_segment_backfill.rst][docs/history_segment_backfill.rst (original source)]] -[[file:/home/goodboy/repos/piker/wkts/ib_history_request_bounds/docs/ib_boot_trace.rst][docs/ib_boot_trace.rst (original source)]] +[[file:/home/goodboy/repos/piker/wkts/history_segment_refill/docs/history_segment_backfill.rst][docs/history_segment_backfill.rst (original source)]] +[[file:/home/goodboy/repos/piker/wkts/history_segment_refill/docs/ib_boot_trace.rst][docs/ib_boot_trace.rst (original source)]] [[file:../plans/opencode/gap-checker-backfiller-repair.md][plans/opencode/gap-checker-backfiller-repair.md (original source)]] [[file:../plans/opencode/known-fqme-backfill-qualification.md][plans/opencode/known-fqme-backfill-qualification.md (original source)]] [[file:/home/goodboy/repos/piker/todo/backtester_deep_fixes.md][todo/backtester_deep_fixes.md (original source)]] @@ -1060,6 +1105,13 @@ case and runtime; do not silently use the human's production storage. **** Execution, concerns and verification +- [ ] Reproduce an interrupted initial MNQ 1s backfill using disposable + storage. Persist a newer frame, cancel before the older interval is + fetched, then restart. The newest stored timestamp can satisfy the + startup target while the internal gap survives. Detect the candidate + interval, account for venue closures, and verify any returned bars + reach Parquet and SHM. Journal replay covers previously submitted + refill requests; automatic discovery must also cover unsubmitted gaps. - [ ] Review schedule coverage, unknown/no-data classification, bounded queries, cancellation and real MNQ coverage separately. - [ ] Qualify journal restart/idempotence, partial repair and CLI-owner @@ -1076,6 +1128,171 @@ case and runtime; do not silently use the human's production storage. Return results to this task and the original known-FQME subtree. Do not equate an IB adapter-only #94 backport with the storage repair. +**** TODO Reconcile split-adjusted history and annotate share splits +:PROPERTIES: +:ID: piker-history-split-adjustments +:CREATED: [2026-12-01] +:CARRIED: 0 +:REPO: /home/goodboy/repos/piker +:TAKEN_APPEND_OP: zcsh-split-basis-20261201 +:TAKEN_APPEND_REQUEST: a8675e31ee5b6ed6563a8c96f496742f8059c9db933d63eae74a2d80b8e25eb9 +:END: +Keep each NativeDB series on a documented price and share-volume +basis when a provider revises history after a split. Expose the +split to chart and dataset consumers even when timestamps are +continuous. Start with a disposable copy of the ZCSH 60s boundary. + +On Sep 29 at 20:00 UTC, the existing =zcsh.arca.ib= minute closed +at 111.00 on 1,527 shares. A fresh IB TRADES query for that same +minute returned 37.00 on 4,581 shares. At 20:01 UTC, the first +refilled minute and the fresh query both closed at 37.00. ZCSH's +3-for-1 forward split took effect before the Sep 30 NYSE Arca open. +The Sep 29 refill boundary and Sep 30 split date are distinct. +[[https://www.sec.gov/Archives/edgar/data/1720265/000119312526408382/zcsh-20260930.htm][ZCSH Form 8-K, Item 8.01]] +[[file:/home/goodboy/images/screenshots/2026-12-01T11:41:39,041582289-05:00.png][ZCSH chart after partial refill]] + +- [ ] Check which backend supplies verified split events. Record the + instrument, ratio, effective session/date and source with the + history, and expose the adjustment basis to dataset consumers. +- [ ] Compare overlapping stored and provider bars to bound the + stale segment. Qualify replacing existing timestamps on a copy. + Verify OHLC and share volume, preserving indexes, real gaps and + already-adjusted rows across a second run and a reload. +- [ ] Reuse the chart annotation layer to mark the effective session + with the split ratio, including on a fully adjusted chart. Cover + continuous timestamps and a split coinciding with a time gap. +- [ ] Keep the 188 residual SHM reservations from this batch + identifiable. Correcting their carried close is separate from + reconciling actual stored bars. Record before/after evidence for + the Sep 29 boundary and the Sep 30 marker here. + +[[id:piker-workstream-gap-display][Existing chart overlay and annotation work]] +[[https://github.com/pikers/piker/issues/510][Related position-accounting split events]] + +**** TODO Repair Kraken spot history gaps from public trades +:PROPERTIES: +:ID: piker-kraken-trade-history-refill +:CREATED: [2026-12-01] +:CARRIED: 0 +:REPO: /home/goodboy/repos/piker +:END: +Recover the missing XRP/USDC 60s observations in NativeDB. Start with +the nine-minute slice below on a disposable copy. Once that agrees +with the trade tape, extend it to the full gap using a resumable +request. Give the chart and its indicators a consistent view on reload. + +***** What the chart showed on December 1 + +=xrpusdc.spot.kraken.ohlcv60s.parquet= contained 1,442 rows in two +blocks of 721. UTC bounds were Nov 8 04:38–16:38 and Dec 1 +05:26–17:26, 2026. All timestamps were unique, increasing and +minute-aligned. Consecutive row indexes span three weeks on screen. + +| Row | UTC | Fixed EST | Close | XRP volume | +| 720 | Nov 8 16:38 | Nov 8 11:38 | 1.15723 | 0 | +| 721 | Dec 1 05:26 | Dec 1 00:26 | 0.95211 | 76.253595 | + +From Nov 8 16:39 UTC inclusive to Dec 1 05:26 UTC exclusive there +are 32,447 absent minute timestamps. How many had trades requires +reading the tape. The zero-volume left boundary already exists and +must survive the repair. Use the Kraken spot pair throughout. + +The Kraken history adapter permits one recent 60s OHLC query per open +history client. Kraken limits that endpoint to 720 recent entries +regardless of the requested start. Its last candle is still in progress. +At startup Piker prepends older stored rows directly beside the first +provider sample in shared memory (SHM). This explains the one-step +chart move even though wall-clock time jumped. Today's refill worker +requires existing reserved SHM slots. This join has none in between. +[[file:../../history_segment_refill/piker/brokers/kraken/feed.py::206][Kraken history adapter]] +[[file:../../history_segment_refill/piker/tsp/_history.py::1260][Placement of stored rows in SHM]] +[[https://docs.kraken.com/api-reference/market-data/get-ohlc-data][Kraken spot OHLC contract]] + +***** Reproduce the recoverable and no-trade minutes + +The Dec 1 read-only public Trades query started one nanosecond before +the first missing minute. The first 1,000 prints covered 93 distinct +minutes, from 16:46 through 21:57 UTC on Nov 8. The first page proves +recoverable data inside the gap. Its final minute may span a second +page. The full 32,447-minute interval has not been reconstructed. + +Use [16:39,16:48) UTC on Nov 8 (11:39–11:48 fixed EST). The tape +crossed the right boundary. Seven fully covered minutes, 16:39 +through 16:45, had no prints. Two minutes have recoverable bars. + +| UTC | Trades | Open | High | Low | Close | Volume (XRP) | +| 16:46 | 2 | 1.15561 | 1.15561 | 1.15552 | 1.15552 | 1,178.66942840 | +| 16:47 | 1 | 1.15331 | 1.15331 | 1.15331 | 1.15331 | 24.98858945 | + +[[https://api.kraken.com/0/public/Trades?pair=XRPUSDC&since=1794155939999999999&count=1000][Exact public XRP/USDC trade-page request]] +[[https://support.kraken.com/articles/advanced-api-faq][Kraken historical trade pagination]] + +***** Fetch, sample and checkpoint by event time + +- [ ] Reuse the IB refill workflow for preview, bounds, submission, + request ID, progress, retry and terminal status. Let the Kraken + backend page public market trades forward. Advance with Kraken's + returned =last= cursor at its original precision. Persist the cursor, + proven time coverage and any unfinished minute together so retrying + or restarting cannot drop or double-count trades. +- [ ] Build UTC half-open minute buckets from exchange execution time. + Preserve exchange trade order for equal timestamps. First/last + trade prices give open/close, extrema give high/low, summed XRP + size gives base volume. Retain the number of prints for validation. + Deduplicate repeated trades by exchange identity and keep distinct + prints that share a timestamp. Check for reusable OHLCV arithmetic + in the live sampler. Historical replay must run at event time + independently of the live sampling clock. +- [ ] Hold the page's trailing minute open across page boundaries. + Mark no-trade minutes only inside proven complete coverage. An + empty response, repeated cursor, timeout or rate limit needs an + explicit continuation or unresolved range. Report recovered bars, + verified no-trade minutes and still-unknown intervals separately. +- [ ] For older quarters, consider Kraken's downloadable OHLCVT or + time-and-sales archives. Check pair, resolution and published date + coverage. The published full OHLCVT archive checked on Dec 1 ends + Sep 30, before this case. Start this reproduction with public Trades. +[[file:../../history_segment_refill/piker/data/_sampling.py::594][Live trade sampling implementation]] +[[https://support.kraken.com/articles/360047124832-downloadable-historical-ohlcvt-open-high-low-close-volume-trades-data][Kraken OHLCVT archive and no-trade convention]] +[[https://support.kraken.com/articles/360047543791-downloadable-historical-market-data-time-and-sales-][Kraken trade archives]] + +***** Publish to NativeDB, then refresh chart history + +- [ ] Merge completed bars into the selected pair and period by UTC + timestamp. Preserve stored observations on overlap, including both + boundary bars; surface conflicting OHLCV for review. Preserve newer + live appends during the merge. Keep no-trade coverage as metadata + and any copied-close display placeholders explicitly synthetic. +- [ ] First qualify repair on disk and reload the chart from NativeDB. + In the current SHM layout inserting a row between 720 and 721 would + shift published indexes. For a future live update, rebuild history + in coordination with the chart and FSP readers, remap by timestamp, + invalidate cached graphics and derived values, then publish the + new history together. Reuse in-place replacement for actual reserved + slots where existing row positions can be preserved. +- [ ] Show the elapsed UTC interval on the compressed chart with the + existing gap annotation mechanism. Distinguish unresolved history, + recovered trade bars and verified no-trade coverage after reload. +[[file:../../history_segment_refill/docs/history_segment_backfill.rst][IB refill workflow, durability and SHM constraints]] +[[id:piker-workstream-gap-display][Chart gap annotations]] +[[id:piker-fsp-backfill-sync-review-and-commit][FSP synchronization on history changes]] + +***** Verification and handback + +- [ ] Use the nine-minute fixture to prove exactly two inserts, seven + covered no-trade minutes and no outstanding coverage in the slice. + Check the full OHLCV above, unique increasing timestamps, canonical + row indexes and unchanged pre-existing observations by timestamp. +- [ ] Split a minute across two trade pages, repeat a boundary trade, + interrupt before and after persistence, then resume. A rerun must + converge to identical bars and volume. Compare against an overlapping + Kraken finalized OHLC candle where both sources are available. +- [ ] For the full gap, record source bounds, last cursor, and counts + of recovered, no-trade and unresolved minutes. Reconcile their sum + to 32,447. Hand back before/after Parquet audits and a chart reload + at the two original boundary timestamps. Report any remaining + unknown ranges and the chart/FSP live-rebuild work separately. + *** FSP synchronization, sampling and cumulative volume :PROPERTIES: :ID: piker-workstream-fsp @@ -1157,6 +1374,11 @@ Use the recorded bounds and values for an offscreen regression. :TAKEN_APPEND_OP: rate-probe-handoff-20261127 :TAKEN_APPEND_REQUEST: 7f5b2f840309cb37f112e9648c44a1e115c7677fbc1be2cbeb1082257911649a :END: +The follow-up copy is in =wkt/trade_rate_axis_probe=, opened from +the pre-restack Kraken replay tip =3889ab4d=. +[[file:../../trade_rate_axis_probe/scripts/trace_rate_view.py][Open the probe in the follow-up worktree]]. +Move this worktree onto the rewritten landing tip after the restack. + - [ ] Carry the [[file:../../land_feed_endpoint_reuse/scripts/trace_rate_view.py][chart probe and its launch examples]] into the follow-up worktree. Commit it with the diagnostic work and record the commit here before retiring its current worktree. The source copy is currently untracked. @@ -1367,6 +1589,70 @@ transport EOF and direction/phase validation. Resolve duplicate pytest second-chart resurrection reproducer to the canonical E2E task; do not claim a schema foundation fixes that observed race by itself. +**** TODO Route order-pane paper trades to the paper engine +:PROPERTIES: +:ID: piker-order-pane-paper-routing +:CREATED: [2026-12-01] +:CARRIED: 0 +:REPO: /home/goodboy/repos/piker +:TAKEN_APPEND_OP: piker-order-pane-paper-routing-20261201 +:TAKEN_APPEND_REQUEST: dbe49bf5d1ee675535823d5237c24fdf95f15227fc3054a5ddb44baf6242fcad +:END: +Selecting =paper= in a chart with a live EMS session should send new +paper orders to =paperboi.=. Existing orders should remain +editable and cancellable through the executor that accepted them. + +Reproduction and cause + +On 2026-12-01 at 11:18:26 Toronto time, the human selected =paper= +in a credentialed XBT/USD chart and submitted a buy on the Kraken +replay (=wkt/land_kraken_parity_replay= at =cc9f827f=). EMS received +=account='paper'= and =exec_mode='live'= and sent the request to +=brokerd.kraken=. Kraken rejected the account locally before sending +an exchange request. The paper engine never received the buy. + +The chart opens one =open_ems()= session. The account selector changes +the active position tracker and allocator. EMS keeps sending commands +through the relay selected at session startup. Both immediate order +modes use that same stream. Changing the order's =exec_mode= field +alone therefore cannot switch executors. This path is shared across +providers. Kraken supplied the observed rejection. + +Commit =49e67d5f= added the paper entry so a live chart could track +paper orders from other clients. The Qtractor change in =5c17419c= +selects an EMS mode at chart startup. Preserve both use cases. +[[id:piker-typed-clearing-migration][Related clearing protocol work]] + +Design note (2026-12-01): acquire the paper relay on the first +explicit switch to =paper=. Loading live accounts alone should start +zero paper actors. Reuse =open_paperboi()= to find or start one +=paperboi.= service and attach the selected market's trade +dialog. Enable paper submission once that relay is ready. If it fails +to open, report the failure without forwarding the order to live. + +Check repeated selections and two charts on the same broker: one +actor should serve both. Switching back to live must preserve the +original route for resting paper orders and other clients. Check +=Router.relays= (currently keyed by broker) and the spawning +context's =cancel_actor()= on exit when qualifying shared ownership. + +Next action and verification + +- [ ] Reproduce the account switch offline with a simulated live + executor and a paper engine on the same market. Observe both + destinations. Run this as a shared UI/EMS change after the parity + landing. +- [ ] Submit a paper buy and drive its fill with a synthetic quote. + Require a paper acknowledgement, fill and position update, and zero + order messages at the live executor. Exercise the reverse switch + with a simulated live order as a control. +- [ ] Keep a resting order on each executor. Switch selections, edit + and cancel by the original order ID, including cancel before ack. + Check that each update reaches the owning dialog once and the other + order remains active. Preserve dark-trigger routing to its owner. +- [ ] Bring back the failing and passing test cases and the observed + executor for each order. Identify any remaining manual chart check. + *** Provider correctness, symbols and bounded older candidates :PROPERTIES: :ID: piker-workstream-providers @@ -1394,10 +1680,49 @@ portable-skill tasks remain canonical. **** Kraken provider parity for the upstream main landing +As of Dec 3, the landing replay is =wkt/land_kraken_parity_replay= +at =30a4fb13=; the offline tests are on =wkt/kraken_order_regressions= +at =b14a45c3=. Their common base, =3889ab4d=, already checks buy, +sell and cancel against the configured account alias and revises +private subscription diagnostics. Verify that behavior rather than +porting it again. The regression tip adds diagnostic coverage; it is +not the landing tip. +[[file:../../kraken_order_regressions/tests/providers/test_kraken_order_control.py][Kraken account, subscription and order tests]] + +On Dec 1 the operator confirmed live XBT/USD ticks after history +loaded and a working order pane. The first console capture showed +both public subscriptions and positive =ownTrades= and =openOrders= +acks. Test commit =06b12d67= records 7 passing and 13 failing cases +against the Dec 1 replay at =cc9f827f=. These were the findings on +that revision, not results for either Dec 3 tip: + +- A custom alias reaches EMS startup but its buy is rejected. Missing + and malformed account tables raise =AttributeError=. +- After a stale-token rejection, the handshake admits order control + without both acks. INFO diagnostics expose synthetic test tokens. +- An early cancel reads a missing =symbol=. An early edit records a + local reqid as a txid. Duplicate opens send the same cancel twice. + Even after both acks, editing order A can use order B's pair. + +Next action: from the regression worktree, run the full offline file +with the replay's =py313=. Record the tested SHA, counts and failing +node IDs here before assigning fixes. No Dec 3 result is verified. +#+begin_src xonsh +../land_kraken_parity/py313/bin/python -m pytest -p no:xonsh -q tests/providers/test_kraken_order_control.py +#+end_src + Review against landing base =88608f12= and =kraken_stale_ws_token= at =8299c658=. Select behavior by hunk. The intervening UI commit =8cefc1bd= and IB ledger commit =170c95da= have separate owners. +- [ ] On resuming the Kraken fixes, maintainer to review the test + helper names and layering in =test_kraken_order_control.py=. + Trace one edit/cancel through =OrderSession.requests()= and + =OrderSession.opened()=, and one token renewal through + =private_peer()=. Check whether each test makes clear who sends + the EMS command, who supplies Kraken's reply, and which broker + behavior the assertion proves. Decide which helpers to keep, + rename or simplify before building more cases on them. - [ ] Account configuration (=ebc5bbd4=). Port the sample config and authenticated startup checks together. Verify a matched key description and account alias yields the expected Kraken EMS account. @@ -1421,7 +1746,18 @@ at =8299c658=. Select behavior by hunk. The intervening UI commit cancel for the intended Kraken txid, cleared pending state and an unaffected second order. Check normal acknowledged edit/cancel too. -Use one Kraken worktree and one review after the IB ledger fallback. +Post-landing follow-up: after Kraken parity lands on =main=, remove +and test the active =tractor.pause()= calls. This work does not gate +that merge. On early edit, exercise the case where the +exchange txid is still unknown and require one deferred cancel for +that order. On stale-token renewal, require both private subscription +acks before admitting orders. Both tests must reach their +=pause.assert_not_awaited()= checks. The older =Client.get_xfers()= +pause predates this slice. Cover a nonempty =WithdrawStatus= result +and verify the transfer is normalized without debugger entry. + +Keep one Kraken landing review after the IB ledger fallback; the +separate regression worktree supplies its offline test evidence. Qualify all three behaviors offline against the current EMS protocol. Record results and residual differences before claiming Kraken parity. @@ -3134,3 +3470,26 @@ source inspection and the human's trace; no search, broker connection, application test or implementation change ran during logging. Preserve all existing task/checklist states and unrelated worktree edits. +* TODO Retire the deprecated MarketStore backend +:PROPERTIES: +:ID: piker-retire-marketstore +:CREATED: [2026-12-01] +:CARRIED: 0 +:REPO: /home/goodboy/repos/piker +:CATEGORY: piker.storage +:TAKEN_APPEND_OP: piker-retire-marketstore-20261201 +:TAKEN_APPEND_REQUEST: 22e6176735d1d73440073d85cbcca167e5b77ff2aa81eaf39a0bfe7e10c13605 +:END: +Schedule removal after the =INUSE= parity landing. NativeDB is the +default. The three shared import hunks from =f210a478= can land with +Kraken independently of this cleanup. + +- [ ] Remove the MarketStore service, storage adapter and legacy ingest + selection. Review CLI choices, setup docs and the Docker service test. +- [ ] Verify NativeDB discovery and history I/O, generic container + supervision and test collection without =anyio_marketstore=. +- [ ] Document what happens to a config selecting =marketstore=. + Leave existing on-disk data under the operator's control. +- [ ] Link the retirement issue when published. The earlier + [[https://github.com/pikers/piker/issues/93][MarketStore integration issue]] + records the original integration.