Files
momentum devandClaude Opus 4.8 d54a2a930c Review sweep: money-path fixes + security + delete 805MB dead weight
Consolidated 4-tool review (2 correctness agents + Codex + over-eng audit).

Money-path (regression-tested):
- _flatten_all: moved the fresh-broker close from close_session INTO the
  shared function + added a broker-held guard on entry cancellation, so
  the daily-loss CIRCUIT BREAKER (which called _flatten_all raw) no
  longer strips a just-filled bracket's legs or leaves a sync-gap fill
  naked. One guard, all callers.
- restart state rebuild: _fresh_entries cap, _requested_symbols dedup,
  and losing benches now rebuild from today's events on boot — a
  mid-session restart no longer resets the cap to 0 or re-fires a
  resting order into a duplicate (the 2026-07-06 incident).
- POST /orders no longer retries a lost-response URLError (was
  re-sending duplicate live orders); GET/DELETE still retry.
- expire_stale_entries now @_locked (raced the trigger thread).
- _session_open: ET conversion instead of a hardcoded 13:30-13:33Z
  window that only matched EDT — the fast path armed nothing all winter.

Security:
- admin panel fail-CLOSED on empty ADMIN_TOKEN (was fail-open on a panel
  fronting the docker socket); header-only token, constant-time compare.
- admin API responses redact secret override VALUES (live keys would
  have echoed after a paper->live switch).
- dashboard: removed wildcard CORS (cross-origin drive-by could drive
  trade actions); optional DASHBOARD_TOKEN gate on POST.

Deletions (~805MB + dead code shipped in the prod image): momentum-
rebuilt.zip, archive venv/htmlcov, and schwab/ core/ telemetry/ models/
runtime/providers/ storage/replay.py controlroom/ + three dead
evaluation stubs + package.json — all verified zero-importer.

+4 regression tests. 99 money-path/trigger/exit tests green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 13:00:10 -04:00
..

Local deployment (systemd user services)

Unit templates for running the stack from a git checkout + venv (the original production shape; now the development shape). Paths inside the units assume /mnt/c/code/momentum + /home/philip/.venvs/momentum — adjust to your box.

cp deploy/systemd/momentum-*.service ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable --now momentum-loop momentum-dashboard momentum-qabot momentum-transcripts
systemctl --user enable --now momentum-premarket-eval.timer   # 20:00 ET weekdays
loginctl enable-linger $USER   # start on boot without login
Unit What
momentum-loop trading loop (run_live_paper.py --no-dashboard)
momentum-dashboard web dashboard :8765 (dashboard_api.py)
momentum-qabot Telegram Q&A bot (read-only)
momentum-transcripts YouTube → transcript → claims pipeline
momentum-premarket-eval(.timer) nightly SIP refetch + housekeeping + shadow-track re-validation
momentum-testpg local Postgres for test isolation (/home/philip/pgrun socket) — keep even when production is elsewhere
momentum-controlroom NiceGUI control room :8766 — disabled by owner preference; kept for reference

Config comes from .env in the repo root (see .env.example). The same behavior-flag warnings as compose apply (TRADING_AUTO_APPROVE=1 etc. — see deploy/README.md).

Never run these enabled while the compose stack owns production — two loops on one Alpaca account duplicate orders.