Repository navigation
Conversation
…#703) A remoteStrategy satisfies the existing strategy interface by sending each frame to a worker as length-prefixed encoding/json and reading its answer. The trader stops the run when a strategy reports a failure (failer), so a dead worker ends the backtest instead of hanging it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
rustyeddy
left a comment
There was a problem hiding this comment.
Review of 1438b74: Good simplification—existing runSeries and trader.onFrame are reused, JSON is standard-library, and the remote/in-process bar parity test is useful. Before merging, please address:
- Blocking: silent worker can hang forever.
remoteStrategy.onBarsignores itsctx, and the connection has no read/write deadline. A worker that stays connected but does not respond blocks the backtest indefinitely (including cancellation). Add a modest response deadline and/or cancellation-triggered connection deadline; test a worker that accepts bars then remains silent. Keep this small—no new session framework. - Blocking: TCP writes need full-frame handling.
writeMessageand example workerwriteassume oneio.Writer.Writesends the complete length-prefixed frame. Handlen < len(buf)withio.ErrShortWrite(or write the remainder) and test with a short-writing writer.readMessagealready usesio.ReadFullcorrectly. Also cap the example worker's inbound frame length before allocation (currently an arbitrary uint32 can allocate up to ~4 GiB). - Package ownership (Rusty's preference): Move transport/framing and the remote socket client into a small
strategysubpackage, not the root trading domain, if it can be done without making a second Order model or import cycle. The existing rootstrategyinterface returns private*orderand has privateonBars, so a full move of that interface requires a separately agreed public API refactor. For this no-orders increment, a tiny root adapter can remain; don't force a broad refactor in #710.
The optional failer.err() works as a temporary bridge, but should not become a permanent interface. Eventually OnBars(ctx, bars) (orders, error) is cleaner. I have not independently run Go tests. Please keep changes within #703's first empty-orders increment; no registration/journal framework.
|
Owner decision on package layout for this PR: option 1. Put the minimal TCP/JSON transport in a new The root |
…e deadline (#703) strategy.Dial/Remote is the trader's end and strategy.Serve the worker's. OnBars waits at most Timeout (30 s by default) and returns when its context ends, so a silent worker cannot hang a run. writeMessage reports a short write; the worker reads through the same size-capped readMessage. The root keeps a tiny adapter. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Revised in 5db2903 (not merged; waiting for your review). Package layout (option 1)
Review findings
Checks on |
rustyeddy
left a comment
There was a problem hiding this comment.
Re-reviewed updated commit 5db2903 against the minimal scope for #703.
Previous blockers resolved:
- Remote exchange now has a response timeout and honors context cancellation/deadlines; tests cover a silent worker.
- Shared framing detects short writes and caps incoming message size before allocating; tests cover both.
- TCP/JSON framing and worker server are in the sibling
strategy/package. Root retains only the small adapter and existing engine integration—no registry or extra lifecycle machinery.
Repeated OnBars, empty orders, disconnect handling, and backtest integration are covered. Looks ready to merge from my review, assuming normal CI is green. Minor non-blocking housekeeping: PR description still says there is no reply deadline and describes the old file layout; update to reflect the latest implementation. Registration, RunID, and actual order replies should stay outside this increment.
(GitHub does not permit this account to formally approve its own PR, so posting the recommendation as a comment review.)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Follow-up for Claude on PR #710. The rename
Please update the PR description to match the current |
…703) The engine's strategy interface is now onBars(ctx, bars) ([]*order, error) and trader.onFrame stops on the error before using any order, so failer, the adapter's failed field and err() are gone. The root adapter moves to strategy_remote.go. strategy.ListenAndServe replaces the listener/accept boilerplate in the example worker. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Closes #703. Part of #690.
What
strategy/(new package, does not importtrader; a test checks that):strategy.go: package doc and the two message types,{"bars":[marketdata.Bar…]}and{"orders":[]}.frame.go: standardencoding/jsonwith a 4-byte big-endian length prefix. A short write isio.ErrShortWrite; a message over 16 MiB is refused before it is allocated.client.go:Dial(loopback addresses only) andClient.OnBars, which waits at mostClient.Timeout(30 s by default, or the context deadline if sooner) and returns at once when the context is cancelled. An answer with orders is an error.server.go: the worker's end.Serve(conn, onBars)answers each group with no orders until the trader closes the connection;ListenAndServe(addr, ready, onBars)listens on a loopback address, accepts one connection and serves it.ready(may be nil) is told the bound address.strategy_remote.go: a small adapter that implements the engine's privatestrategyinterface and delegates tostrategy.Client. The rootstrategy.go, EMAX,order.goand the engine are not moved, and there is no new order type.examples/remote-strategy: a standalone worker built onstrategy.ListenAndServe.runSeriesandtrader.onFramedrive the remote strategy.The one interface change
The engine's private interface is now
onBars(ctx, bars) ([]*order, error).trader.onFramechecks the error before it looks at any order and stops the run.eachBarreturns a nil error, so EMAX and the other bar-by-bar strategies only changed their signatures. There is no second failure mechanism (failer,failedanderr()are gone). The six-summary md5 is unchanged (195e457a…).Behaviour
Run the example
Then
strategy.Dial("127.0.0.1:9100")and run a backtest with it as the trader's strategy, as the tests do. There is no CLI flag yet.Tests (
go test -race -count=1 . ./strategy/ ./examples/... ./cmd/...)strategy:ListenAndServe(bound address, nilready, non-loopback and in-use addresses refused); framing round-trip, short write, oversize, truncated and non-JSON messages; loopback-only dial;Clientagainst a silent worker (timeout), a cancelled context, a shorter context deadline, a hang-up and an answer with orders;Serve;ClientagainstServeover TCP.trader.onFramestops on a strategy error and uses none of its orders; a backtest over TCP delivers the same groups in the same order as an in-process recorder, with no trades; a worker that hangs up mid-run fails the run; the real example binary, built and run as a separate process, exits cleanly.Also run on
.,./strategy,./examples/...,./cmd/...: golangci-lint (0 issues) andgo mod tidy -diff(clean).make checkpasses locally on the full module.🤖 Generated with Claude Code