Skip to content

Consolidate broker CI and audit fixes - #1122

Closed
mpelteshki wants to merge 10 commits into
devfrom
fix/audit-followups-july
Closed

Consolidate broker CI and audit fixes#1122
mpelteshki wants to merge 10 commits into
devfrom
fix/audit-followups-july

Conversation

@mpelteshki

@mpelteshki mpelteshki commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Why

Three related broker changes were split across stale branches. Audit found missing fork and Dependabot secret guards, cancellation cleanup gaps, stale-data validation gaps, and unsupported acceptance relaxations.

Impact

Live broker jobs remain credential-gated, skip untrusted pull requests, serialize shared paper-account access, and retry cancellation to terminal state. Standard unit and backtest shards remain deterministic.

Excluded unsupported changes: backdoor_smartlimit tolerance 700, runtime gates 900 and 1020, and LEAPS queue allowance 5. #1107 and #1108 are not included.

Validation

  • Targeted broker, data, Tradovate, Alpaca, MCP, and agent tests: 151 passed, 5 credential-gated skips.
  • actionlint passed; known Blacksmith runner label configured as custom.
  • JSON and diff checks passed.
  • Real paper-broker paths remain GitHub-secret-gated and run in CI.

Summary by CodeRabbit

  • New Features

    • Added opt-in GitHub Actions coverage for live Alpaca paper-broker testing, including broker + strategy execution and options-chain scenarios.
  • Bug Fixes

    • Improved Alpaca multi-leg bracket exits (credit/debit limit price handling) and stricter stop-loss validation.
    • Strengthened native bar request validation for strict end checks and sparse history.
    • Updated Tradovate polling to begin only after successful authentication.
  • Documentation

    • Added live-broker CI and strict live-testing guidance, plus Alpaca credential environment variable docs and a Coinbase key placeholder update.
  • Tests / CI

    • Expanded Alpaca credential gating, refined sharded test execution, added live broker and live strategy apitests (including cancellation safety), and updated pytest markers.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds opt-in Alpaca paper-account CI and live broker strategy tests, improves Alpaca multi-leg order payloads, defers Tradovate stream startup until authentication, validates native data requests earlier, updates dependencies, and refreshes related documentation.

Changes

Live broker CI and test coverage

Layer / File(s) Summary
Live CI workflows and test gating
.github/workflows/*.yml, tests/conftest.py, setup.cfg
Adds secret-gated Alpaca workflows, isolates live strategy tests from standard shards, and registers Alpaca markers and credential checks.
Live broker and news test flows
tests/test_*alpaca*, tests/test_broker_live_strategy_run_*
Adds live Alpaca data, options-chain, news, and broker order lifecycle coverage with polling, cancellation, cleanup, and credential-based skips.
Live CI documentation
docs/ALPACA_LIVE_BROKER_CI.md, docs/SMART_LIMIT_LIVE_TESTING.md, docsrc/environment_variables.rst
Documents credentials, workflow behavior, local commands, concurrency, skip behavior, and strict strategy-run testing.

Broker and data runtime changes

Layer / File(s) Summary
Alpaca multi-leg order payloads
lumibot/brokers/alpaca.py, tests/test_alpaca_multileg_fix.py
Signs credit/debit limit prices, formats bracket exits, validates exit fields, and tests the resulting payloads.
Tradovate authenticated stream startup
lumibot/brokers/tradovate.py, tests/test_tradovate.py
Defers polling-stream creation until authentication and verifies disabled-stream behavior.
Native bar request validation
lumibot/entities/data.py, tests/test_data_entity.py
Validates native requests before fast-path slicing, reuses iteration counts, and tests strict boundaries, sparse data, timezone handling, and normalization.

Packaging and deployment configuration

Layer / File(s) Summary
Runtime dependency declarations
requirements.txt, setup.py
Removes obsolete dependencies and updates the declared data and broker package set.
Deployment secret example
docsrc/deployment.rst
Replaces an embedded Coinbase private-key example with a secret-manager placeholder.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CI
  participant Pytest
  participant Alpaca
  CI->>Pytest: run live broker strategy tests
  Pytest->>Alpaca: authenticate and submit paper order
  Alpaca-->>Pytest: return order status
  Pytest->>Alpaca: poll and cancel order
  Alpaca-->>Pytest: return terminal cancellation status
Loading

Possibly related PRs

Suggested reviewers: grzesir

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the PR’s main theme: consolidating broker CI and related audit/fix work.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/audit-followups-july

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 4

🧹 Nitpick comments (2)
.github/workflows/cicd.yaml (1)

285-285: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Concurrency group name has misleading -unit-tests suffix.

The broker-live-strategy-tests job's concurrency group is broker-live-strategy-tests-${{ github.repository }}-unit-tests. The -unit-tests suffix is misleading since this is a live broker test job, not a unit-test job. This appears to be a copy-paste artifact. It's functionally harmless but could cause confusion when debugging concurrency issues.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/cicd.yaml at line 285, Rename the concurrency group for
the broker-live-strategy-tests job to remove the misleading “-unit-tests”
suffix, preserving the existing broker-live-strategy-tests and repository
identifiers.
tests/test_alpaca_live_broker_apitest.py (1)

15-35: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Pass start_orders_thread=False in _require_alpaca()
connect_stream=False is enough for this path, and Broker.cleanup_streams() already stops and joins the orders thread if it starts. Matching tests/test_broker_live_strategy_run_apitest.py keeps the fixture lighter and avoids an unused background thread.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_alpaca_live_broker_apitest.py` around lines 15 - 35, Update the
Alpaca constructor call in _require_alpaca() to pass start_orders_thread=False
alongside connect_stream=False, matching the configuration used by
tests/test_broker_live_strategy_run_apitest.py and avoiding an unnecessary
background orders thread.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/alpaca-live-broker.yml:
- Around line 63-65: Use a shared concurrency group keyed only by
github.repository for alpaca-live-broker.yml and the broker-live-strategy-tests
job in cicd.yaml, replacing their independent group names so all paper-account
tests serialize across workflows while preserving cancel-in-progress: false.

In @.github/workflows/cicd.yaml:
- Line 58: Set persist-credentials: false on every actions/checkout@v4 step in
the workflow, covering the lint, unit-tests, backtest-tests, and
broker-live-strategy-tests jobs.
- Around line 352-359: Replace direct GitHub expression interpolation in the
bash conditions within the broker-live-strategy-tests result check with
environment variables. Define env vars for github.event_name,
github.event.pull_request.head.repo.full_name, and github.actor, then reference
those quoted variables in the conditional logic while preserving the existing
skip and failure behavior.

In `@tests/test_broker_live_strategy_run_apitest.py`:
- Around line 248-255: Update the finally-block safety-net around
strategy.submitted_order to invoke _cancel_order_until_terminal only when the
order is not already terminal, and preserve any existing strategy.cancel_error
from _cancel_submitted_order. Remove the unconditional assignment of
cancel_error = None, ensuring successful cleanup does not mask prior
cancellation failures; use the existing terminal-status representation and
strategy fields to perform the check.

---

Nitpick comments:
In @.github/workflows/cicd.yaml:
- Line 285: Rename the concurrency group for the broker-live-strategy-tests job
to remove the misleading “-unit-tests” suffix, preserving the existing
broker-live-strategy-tests and repository identifiers.

In `@tests/test_alpaca_live_broker_apitest.py`:
- Around line 15-35: Update the Alpaca constructor call in _require_alpaca() to
pass start_orders_thread=False alongside connect_stream=False, matching the
configuration used by tests/test_broker_live_strategy_run_apitest.py and
avoiding an unnecessary background orders thread.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 81f35670-482e-468b-ad16-dc71aff01b3a

📥 Commits

Reviewing files that changed from the base of the PR and between b618afa and eba56f5.

📒 Files selected for processing (21)
  • .github/workflows/alpaca-live-broker.yml
  • .github/workflows/cicd.yaml
  • docs/ALPACA_LIVE_BROKER_CI.md
  • docs/SMART_LIMIT_LIVE_TESTING.md
  • docsrc/deployment.rst
  • docsrc/environment_variables.rst
  • lumibot/brokers/alpaca.py
  • lumibot/brokers/tradovate.py
  • lumibot/entities/data.py
  • requirements.txt
  • setup.cfg
  • setup.py
  • tests/conftest.py
  • tests/test_agent_alpaca_news_live_apitest.py
  • tests/test_alpaca_live_broker_apitest.py
  • tests/test_alpaca_multileg_fix.py
  • tests/test_broker_live_strategy_run_apitest.py
  • tests/test_broker_live_strategy_run_safety.py
  • tests/test_data_entity.py
  • tests/test_ibkr_futures_daily_series.py
  • tests/test_tradovate.py
💤 Files with no reviewable changes (2)
  • requirements.txt
  • setup.py

Comment on lines +63 to +65
concurrency:
group: alpaca-live-broker-${{ github.repository }}
cancel-in-progress: false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Cross-workflow paper-account concurrency risk.

Both alpaca-live-broker.yml (concurrency group alpaca-live-broker-*) and cicd.yaml's broker-live-strategy-tests job (concurrency group broker-live-strategy-tests-*-unit-tests) can trigger on PRs to dev/main. They use independent concurrency groups, so both can run simultaneously against the same Alpaca paper account, potentially interfering with each other's order lifecycle tests.

Consider a shared concurrency group (e.g., keyed on github.repository alone) across both workflows to serialize all paper-account access.

Also applies to: 284-286

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/alpaca-live-broker.yml around lines 63 - 65, Use a shared
concurrency group keyed only by github.repository for alpaca-live-broker.yml and
the broker-live-strategy-tests job in cicd.yaml, replacing their independent
group names so all paper-account tests serialize across workflows while
preserving cancel-in-progress: false.

Comment thread .github/workflows/cicd.yaml
Comment thread .github/workflows/cicd.yaml Outdated
Comment thread tests/test_broker_live_strategy_run_apitest.py Outdated

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
lumibot/entities/data.py (1)

1259-1442: 🗄️ Data Integrity & Integration | 🔵 Trivial | 🏗️ Heavy lift

Keep the native request guards aligned with check_data
_validate_native_bars_request still duplicates the end-boundary and insufficient-history checks from check_data. The intraday stale-bar check is already shared, so the remaining risk is divergence in date-range handling between the two paths. Consider extracting the shared boundary logic or adding a parity test that exercises both entry points.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lumibot/entities/data.py` around lines 1259 - 1442, Keep
_validate_native_bars_request aligned with check_data by extracting the shared
end-boundary and insufficient-history validation into reusable helpers, then
invoke those helpers from both entry points; alternatively, add parity tests
covering before-start, after-end, and insufficient-history requests to ensure
both paths produce identical behavior and diagnostics.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lumibot/entities/data.py`:
- Around line 1259-1442: Keep _validate_native_bars_request aligned with
check_data by extracting the shared end-boundary and insufficient-history
validation into reusable helpers, then invoke those helpers from both entry
points; alternatively, add parity tests covering before-start, after-end, and
insufficient-history requests to ensure both paths produce identical behavior
and diagnostics.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3388f7c0-c07b-4c1c-8297-e251a445845d

📥 Commits

Reviewing files that changed from the base of the PR and between 8e4fcea and 77871c6.

📒 Files selected for processing (2)
  • lumibot/entities/data.py
  • tests/test_data_entity.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant