Repository navigation
feat(admin): trace detail in the Backtest panel's shape - #644
Conversation
The trace page now reads like the Backtest panel: run config on the left,
the chart with its benchmarks and comparison table in the middle, the
trading log on the right, and the timeline below the table.
- New GET /api/admin/traces/{id}/chart-data: the same chart payload the
Backtest panel uses (agent, DJIA, Nasdaq-100, stored Buy & Hold), looked
up by the trace's exact run across owners. A run with no stored equity
answers available: false, and the chart falls back to decision snapshots.
- Chart and comparison reuse BacktestComparison for columns and Best.
Sharpe stays out until the engine computes it (2026-10-14 direction).
- Timeline shows the process only: one row per step, holds and setup folded,
All / Errors filters, tool and failure status per event. Symbols and
reasoning live in the trading log alone; a trade row links to its orders.
- Trading log groups orders by decision, prints a shared reason once, lists
rejected orders, and filters by side or rejection.
- Two-way jumps with a highlight between timeline rows, log groups and chart
markers; a sticky Back button that follows the entry point, and Esc.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2817038ddc
ℹ️ 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".
| // Bars per US session at hourly cadence; the range buttons count bars, not | ||
| // calendar time, because the x axis skips closed hours like Backtest's. | ||
| const RANGE_BARS = { '1D': 7, '1W': 35, ALL: Infinity }; |
There was a problem hiding this comment.
Derive chart ranges from timestamps instead of fixed bar counts
For current Alpaca runs, the backtest engine records equity at the 5-minute valuation cadence, so slicing the last 7 or 35 array entries makes the controls display roughly 35 minutes and 175 minutes rather than the advertised 1D and 1W periods. The same constants are also unsuitable for markets with different session lengths; calculate the cutoff from the supplied timestamps and market sessions instead of assuming seven hourly bars per day.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 73ecb52. Ranges now count the trading days present in the series (1D = last session, 1W = last 5 sessions) instead of fixed bar counts, so 5-minute runs and other session lengths work. Covered by test_chart_ranges_count_trading_days_not_bars (78 bars/session).
| if (envelope.status !== state.chartStatus) { | ||
| state.chartData = await loadChartData(traceId); | ||
| state.chartStatus = envelope.status; |
There was a problem hiding this comment.
Validate the poll before updating shared chart state
When a running trace finishes while the administrator navigates to another trace, this poll awaits the old trace's chart request and writes its result into global state before checking seq and state.traceId. If the new trace has already loaded, the stale response can overwrite its chartData and chartStatus, causing a later rerender or poll to show the previous run's comparison chart. Keep the loaded chart data local until the current-request check passes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 73ecb52. The poll now keeps the chart response local and writes chartData/chartStatus only after the seq / traceId check passes. test_a_stale_poll_does_not_write_its_chart_into_the_next_trace holds the old trace’s chart request open across a navigation; it fails on the previous code (shows the old run) and passes now.
Codex review on #644: - 1D/1W counted 7 and 35 bars, which assumed hourly bars. A 5-minute Alpaca run showed about 35 minutes for "1D". Ranges now count the trading days present in the series, so any cadence or session length works. - A poll for a trace the admin had left wrote that trace's chart into shared state before the current-request check. A late response could then replace the next trace's comparison chart. The response is now held locally until the check passes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
The admin trace page now follows the Backtest panel's layout: run config on the left, the chart with benchmarks and the comparison table in the middle, the trading log on the right, and the timeline below the table. The timeline and the trading log no longer repeat each other.
Backend
GET /api/admin/traces/{trace_id}/chart-data(admin-only). It returns the same payload as/api/backtest/{run_id}/chart-data(agent, DJIA, Nasdaq-100, stored Buy & Hold) and uses the same builder and market-hour filter. The run is looked up by the trace's exact run ID across owners. When a run has no stored equity, the endpoint answersavailable: false, and the chart falls back to the decision snapshots.Frontend
BacktestComparison(now loaded on/admin) for its columns and Best values. Sharpe is left out until the engine computes it with its interval (2026-10-14 direction).N orders (x filled, y rejected) · durationand has a button that jumps to its orders.← Agent traces/← User analyticsbutton follows where the admin came from, and Esc goes back as well.Testing
test_admin_trace_chart_data.py: exact-run series, unavailable states, 404, and the admin dependency.test_admin_traces_frontend.pywas updated for the new rendering: the timeline never shows symbols or reasoning, reasons in the log are grouped, quiet rows fold, the Errors filter keeps a failed trade, and the Back target follows the entry point. The tests that pin script and CSS versions were bumped.backtesting/test_indicator_lookahead.py::test_fallbacks_reproduce_the_library_once_a_window_is_full[missing|exception]) also fail on unmodifiedmainin my environment, and this PR does not touch that code.Not in this PR
🤖 Generated with Claude Code