Skip to content

Fix sprint-critical runtime issues and add benchmarks workspace - #1

Merged
Ashutosh0x merged 8 commits into
mainfrom
codex/fix-all-bugs-and-improve-codebase
Mar 15, 2026
Merged

Fix sprint-critical runtime issues and add benchmarks workspace#1
Ashutosh0x merged 8 commits into
mainfrom
codex/fix-all-bugs-and-improve-codebase

Conversation

@Ashutosh0x

Copy link
Copy Markdown
Owner

Motivation

  • Address multiple sprint-critical failures across the daemon, execution, risk, FIX and backtest areas so the workspace compiles and runtime paths behave sensibly.
  • Move benchmarks out of the virtual workspace manifest into a dedicated crate so benchmark tooling and CI can run without violating Cargo workspace rules.
  • Harden runtime behavior for shutdown, kill-switch, and execution configuration to avoid panics and incorrect persisted fill data.

Description

  • Added a dedicated benchmarks/ workspace crate and removed illegal [[bench]] sections from the top-level Cargo.toml so Cargo can parse the virtual manifest; copied existing bench sources into benchmarks/benches/ and added benchmarks/Cargo.toml.
  • Cached the execution mode using OnceLock in crates/execution/src/router.rs to avoid repeated env lookups at runtime (EXECUTION_MODE).
  • Removed the panic-prone Clone implementation path for ShutdownReceiver in crates/daemon/src/shutdown.rs and require callers to use ShutdownController::subscribe() for new receivers.
  • Implemented a simple FIX serializer encode() in crates/fix/src/lib.rs that emits SOH-delimited tag=value bytes and synthesizes tag 35 when missing.
  • Enhanced crates/feature/src/lib.rs to track last_price and added a 5-minute buy_count_5m auto-reset timestamp to keep short-window counters accurate.
  • Fixed multi-symbol mark-to-market in crates/backtest/src/engine.rs by tracking last_prices per symbol and using them for non-current-symbol valuation.
  • Replaced kill-switch active boolean with an AtomicBool in crates/risk/src/kill_switch.rs to allow cheap atomic inspection in hot paths while leaving lock-protected metadata under RwLock.
  • Added Sell handling to the executor success path and removed persisting a fill_price = 0.0 sentinel in crates/daemon/src/main.rs (temporary non-zero estimate used until execution returns fills).
  • Cached an RpcClient inside ExecutorService in crates/executor/src/lib.rs and reuse it for pre-trade balance checks and send/confirm paths to reduce allocation/lookup overhead.

Testing

  • Ran cargo check --workspace; this was attempted but failed due to environment network restrictions when contacting crates.io so the workspace could not be fully validated in this environment.
  • Ran cargo check --workspace --offline; this failed because required dependencies are not available in the local offline cache.
  • Ran cargo bench -p benchmarks --no-run; the bench invocation failed for the same crates.io access limitation, but the benchmarks/ crate and sources were created and copied successfully.
  • Ran cargo fmt --all; this failed because rustfmt is not installed in the current toolchain environment.

Full compile, test and benchmark runs should be executed in a network-enabled CI environment to validate end-to-end build and runtime behavior.


Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a17244baa5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/executor/src/lib.rs Outdated
Comment on lines +29 to +33
let rpc_url = "https://api.mainnet-beta.solana.com".to_string();
Self {
selector,
signer: signer.map(Arc::new),
rpc_client: Arc::new(RpcClient::new(rpc_url)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Honor NodeSelector when initializing executor RPC client

The cached RpcClient is now always created with https://api.mainnet-beta.solana.com, so the executor no longer uses NodeSelector output (or the SOL_RPC value wired in daemon/main.rs) for balance checks and transaction submission. Any deployment configured for a different cluster or private RPC will send trades to the wrong endpoint, which can cause balance checks to fail and submitted signatures to be invalid for the intended environment.

Useful? React with 👍 / 👎.

Comment thread crates/fix/src/lib.rs Outdated
};
fields.push((35, msg_type.to_string()));
}
fields.sort_by_key(|(tag, _)| *tag);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve FIX header/trailer order in message encoding

Sorting all tags numerically produces invalid FIX framing for session messages (for example, tag 34 will precede 35, and no explicit trailer construction is performed), and FixSession writes this output directly to the socket for logon/heartbeat/logout. In a real FIX counterparty this format is rejected, so the new serializer can break all outbound session traffic instead of producing interoperable FIX 4.4 messages.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses several runtime/compilation issues across the trading workspace and introduces a dedicated benchmarks/ crate so benchmark tooling can coexist with a virtual workspace manifest.

Changes:

  • Added a benchmarks/ crate to host Criterion benches and removed top-level virtual-manifest bench configuration.
  • Hardened/adjusted runtime behavior across risk (kill switch), execution routing, daemon shutdown, and daemon persistence/execution paths.
  • Improved backtest multi-symbol mark-to-market and feature-engine short-window metrics handling.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
Cargo.toml Adds benchmarks as a workspace member and removes illegal top-level bench config.
crates/risk/src/kill_switch.rs Swaps kill-switch active flag to AtomicBool while keeping metadata behind RwLock.
crates/execution/src/router.rs Caches EXECUTION_MODE via OnceLock to avoid repeated env lookups.
crates/daemon/src/shutdown.rs Removes panic-prone Clone path for ShutdownReceiver; promotes subscribe().
crates/fix/src/lib.rs Implements a basic FIX serializer encode() (tag=value SOH-delimited bytes).
crates/feature/src/lib.rs Tracks last_price and adds 5-minute buy-count auto-reset timestamping.
crates/backtest/src/engine.rs Tracks last_prices per symbol for correct multi-symbol mark-to-market.
crates/executor/src/lib.rs Caches an RpcClient inside ExecutorService to reuse it across calls.
crates/daemon/src/main.rs Adds Sell handling on executor success path and changes persisted fill-price handling.
benchmarks/Cargo.toml New benchmarks crate manifest with Criterion benches.
benchmarks/src/lib.rs New crate root for the benchmarks harness.
benchmarks/ci_regression.json Adds benchmark baseline/threshold configuration for CI regression tracking.
benchmarks/benches/01_tick_pipeline.rs Adds tick-pipeline performance benchmarks.
benchmarks/benches/03_risk_checks.rs Adds risk-check microbenchmarks (kill switch, branchless check, GARCH).
benchmarks/benches/05_fix_serializer.rs Adds FIX serializer encoding benchmark.
benchmarks/benches/09_memory_layout.rs Adds memory layout / false sharing / SPSC microbenchmarks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread crates/executor/src/lib.rs Outdated
Comment thread crates/fix/src/lib.rs
Comment thread crates/fix/src/lib.rs
Comment on lines +46 to +50
let mut out = String::new();
for (tag, val) in fields {
out.push_str(&format!("{}={}", tag, val));
}
out.into_bytes()
Comment thread crates/daemon/src/main.rs Outdated
Comment thread benchmarks/benches/03_risk_checks.rs Outdated
Comment thread benchmarks/benches/09_memory_layout.rs Outdated
Comment on lines 324 to +326
pub async fn check(&self) -> Result<(), String> {
let ks = self.kill_switch.read().await;
if ks.active {
if ks.active.load(Ordering::Relaxed) {
Comment thread crates/daemon/src/shutdown.rs
@Ashutosh0x

Copy link
Copy Markdown
Owner Author

@copilot open a new pull request to apply changes based on the comments in this thread and also fix the ci

Copilot AI commented Mar 15, 2026

Copy link
Copy Markdown

@Ashutosh0x I've opened a new pull request, #2, to work on those changes. Once the pull request is ready, I'll request review from you.

Ashutosh0x and others added 6 commits March 15, 2026 22:01
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Ashutosh0x
Ashutosh0x merged commit 36f9877 into main Mar 15, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants