Skip to content

fix(ci): add missing src/alpaca_account_lock and src/trading_server modules#79

Open
lee101 wants to merge 2 commits intomainfrom
ci-fix/stock-prediction
Open

fix(ci): add missing src/alpaca_account_lock and src/trading_server modules#79
lee101 wants to merge 2 commits intomainfrom
ci-fix/stock-prediction

Conversation

@lee101
Copy link
Copy Markdown
Owner

@lee101 lee101 commented Mar 29, 2026

Summary

  • The fast-unit-tests CI job was aborting with a collection error: ModuleNotFoundError: No module named 'src.alpaca_account_lock'
  • trade_daily_stock_prod.py imports acquire_alpaca_account_lock and require_explicit_live_trading_enable from src.alpaca_account_lock at module level (line 36)
  • pytest failed to collect tests/test_trade_daily_stock_prod.py because this module did not exist, causing the entire test run to abort with exit code 2
  • The next module-level import (from src.trading_server.client import TradingServerClient, line 37) would have caused a second collection error once the first was fixed

Changes

  • src/alpaca_account_lock.py – advisory file-lock (acquire_alpaca_account_lock) and live-trading guardrail (require_explicit_live_trading_enable) following the same pattern as bagsfm/utils.py::require_live_trading_enabled
  • src/trading_server/__init__.py – package init
  • src/trading_server/client.py – HTTP REST client (TradingServerClient) wrapping the trading server API
  • src/trading_server/server.py – in-process paper trading engine (TradingServerEngine) for deterministic backtests, matching the interface used by InMemoryTradingServerClient in trade_daily_stock_prod.py

Test plan

  • src.alpaca_account_lock imports successfully
  • src.trading_server.client.TradingServerClient imports successfully
  • src.trading_server.server.TradingServerEngine imports successfully
  • CI fast-unit-tests job collects tests/test_trade_daily_stock_prod.py without error
  • All selected unit tests pass

🤖 Generated with Claude Code

…odules

The fast-unit-tests CI job was failing with:

  ModuleNotFoundError: No module named 'src.alpaca_account_lock'

trade_daily_stock_prod.py imports `acquire_alpaca_account_lock` and
`require_explicit_live_trading_enable` from `src.alpaca_account_lock` at
module level. pytest failed to collect tests/test_trade_daily_stock_prod.py
because this module did not exist, causing the entire test run to abort.

Additionally, trade_daily_stock_prod.py imports `TradingServerClient` from
`src.trading_server.client` at module level (next import after the one that
was failing). Created the full trading_server package to prevent a second
collection error.

Changes:
- src/alpaca_account_lock.py: advisory file-lock + live-trading guardrail
- src/trading_server/__init__.py: package init
- src/trading_server/client.py: HTTP REST client (TradingServerClient)
- src/trading_server/server.py: in-process paper trading engine (TradingServerEngine)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codex-infinite
Copy link
Copy Markdown

Codex Infinity
Hi! I'm Codex Infinity, your coding agent for this repo.

Start a task on this PR's branch by commenting:

Tasks and logs: https://codex-infinity.com

Copy link
Copy Markdown

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

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: 29a5b5d801

ℹ️ 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 on lines +135 to +137
state = self._get_account(account)
state.writer_bot_id = bot_id
state.writer_session_id = session_id
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 Enforce exclusive writer claims per account

claim_writer currently just overwrites writer_bot_id/writer_session_id and always returns success, so a second process can claim the same account immediately after the first one and both will believe they have exclusive write access. In concurrent runs (the exact scenario this API is meant to guard), this allows conflicting order flows and breaks the intended single-writer safety guarantee.

Useful? React with 👍 / 👎.

"id": order_id,
"symbol": symbol,
"side": side,
"qty": qty,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Record filled sell quantity instead of requested size

The order record stores qty from the request even though sell execution may be capped to the held position (sell_qty = min(qty, existing_qty)). When callers submit a sell larger than holdings, history reports a larger filled size than what was actually executed, which can corrupt downstream reconciliation and analytics based on order_history.

Useful? React with 👍 / 👎.

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