Commit Graph

314 Commits

Author SHA1 Message Date
Celes Renata ee5fd30398 fix: backtest force-closes open positions at end + uses real market prices for exits 2026-04-18 00:03:51 +00:00
Celes Renata 6136a767da docs: add Windows Docker Desktop local dev setup guide 2026-04-17 23:47:51 +00:00
Celes Renata 82da8af02b fix: dedup recommendation queue at aggregation level — prevent duplicate ticker+window flooding 2026-04-17 22:11:59 +00:00
Celes Renata a6189fce6b fix: skip LLM thesis rewrite for informational/suppressed recs to prevent queue buildup 2026-04-17 19:29:41 +00:00
Celes Renata 7736554988 fix: recommendation worker now respects thesis-rewriter active=false toggle 2026-04-17 19:22:31 +00:00
Celes Renata d8f1b615c8 fix: add order status sync loop to broker adapter — pending orders now update to filled/cancelled 2026-04-17 17:38:10 +00:00
Celes Renata 7a541aa693 fix: trend_windows.id missing gen_random_uuid() default 2026-04-17 17:27:41 +00:00
Celes Renata 84b3c06b2f fix: sync agent DB prompts with code defaults + update model to qwen3.5:9b-fast 2026-04-17 17:12:09 +00:00
Celes Renata aa67523acd fix: ensure JSON output instruction in system prompt override + retry on ValueError 2026-04-17 17:03:58 +00:00
Celes Renata 523d3ea749 fix: catch ValueError in classification retry loop + add debug logging for raw output 2026-04-17 17:00:32 +00:00
Celes Renata f054e97b5b fix: event classifier unwraps single-element list from model output
Model sometimes returns [{...}] instead of {...}. Now unwraps
single-element lists before parsing the event fields.
2026-04-17 16:44:57 +00:00
Celes Renata 630837070a chore: add ruff lint to steering docs and auto-lint hook
- Steering: emphasize running ruff before committing Python changes
- Hook: auto-runs ruff check --fix on services/**/*.py when files are edited
2026-04-17 16:38:54 +00:00
Celes Renata 76ff7ae00a fix: ruff import sort order 2026-04-17 16:37:30 +00:00
Celes Renata 1394e6168b fix: event classifier now strips markdown fences and repairs JSON
_parse_classification_response receives raw model output (with thinking
tags, markdown fences, etc.) but was calling json.loads directly.
Now uses _strip_markdown_fences + _repair_json from the client module
before parsing, matching what _call_ollama does for extractions.
2026-04-17 16:35:13 +00:00
Celes Renata 759d868e3b fix: event classifier was blocked by extraction schema validation
_call_ollama validates against the document extraction schema, which
doesn't match event classification output. The event classifier was
checking 'if attempt.error is None' before trying its own parsing,
so it never got to parse the valid event JSON — 956 consecutive
failures.

Now tries _parse_classification_response whenever raw_output exists,
regardless of the extraction validation error.
2026-04-17 16:28:39 +00:00
Celes Renata 678072e96b fix: build Redis URL from REDIS_HOST/PORT/PASSWORD/DB env vars
Redis uses separate env vars, not a single REDIS_URL. Script now
builds the connection string from REDIS_HOST, REDIS_PORT, REDIS_DB,
and REDIS_PASSWORD — matching how services/shared/config.py does it.
2026-04-17 08:21:16 +00:00
Celes Renata 06e1e7ea0f fix: reclassify script reads DB/Redis creds from pod env vars
No more hardcoded passwords — pulls POSTGRES_HOST, POSTGRES_USER,
POSTGRES_PASSWORD, POSTGRES_DB, and REDIS_URL from the pod's
environment (injected by k8s secrets).
2026-04-17 08:19:23 +00:00
Celes Renata 9c4118c0e7 fix: force-recreate GHCR pull secret on every deploy
The repo is now private (BSL license), so pods need valid GHCR
credentials to pull images. runmefirst.sh now:
- Verifies the token can authenticate with GHCR
- Force-recreates the ghcr-credentials secret before Helm deploy
- Warns if the token is expired or missing scopes
2026-04-17 08:10:34 +00:00
Celes Renata 1842b2039c ops: add SQL query test script and macro reclassify/reaggregate runner
- scripts/test_saved_queries.py: tests all 24 saved SQL explorer queries
  against the live Trino API (all 24 pass)
- scripts/run_reclassify_and_reaggregate.sh: self-contained script to
  re-classify macro events with updated prompts and re-aggregate all
  tickers. Scales aggregation to 16 pods, monitors queues, scales back.
2026-04-17 08:03:14 +00:00
Celes Renata 98de4ee7c9 chore: add BSL 1.1 license and copyright notice
Licensed under Business Source License 1.1.
Copyright (c) 2025-2026 Celes Hillyerd. All rights reserved.
Production use requires written approval from the author.
Change Date: 2030-04-17 (converts to GPL v2+ after that).
2026-04-17 07:45:30 +00:00
Celes Renata c5b7bddadb fix: backfill recommendation evidence for existing recommendations
Migration 028: For each recommendation with no evidence rows, finds
the closest matching trend_window (by ticker + time_horizon + timestamp)
and re-inserts evidence from top_supporting/opposing_evidence arrays.
Filters out non-UUID pattern IDs and verifies documents exist.

This fixes 'No evidence linked' on recommendations created before the
UUID filtering fix in persist_recommendation.
2026-04-17 07:37:14 +00:00
Celes Renata 5efccb1e03 fix: deduplicate evidence refs in trend summaries
Backend: assemble_trend_with_evidence now deduplicates document IDs
via dict.fromkeys() (the rollup code already did this, but the base
assembly didn't — same doc could appear multiple times from different
intelligence extractions).

Frontend: Trends.tsx deduplicates via Set before rendering as a safety
net for existing data already stored with duplicates.
2026-04-17 07:25:32 +00:00
Celes Renata d243142705 fix: trend evidence shows document titles instead of truncated UUIDs
- EvidenceRef component now fetches document details via useDocument()
  hook and displays the title instead of 'doc:43156423…'
- TanStack Query deduplicates and caches lookups for repeated doc IDs
- Pattern IDs still render as before (e.g. 'pattern META other (1d)')
- Override Trade button changed from brand-600 to red-600
2026-04-17 07:18:41 +00:00
Celes Renata e53b9fc1bf fix: macro tab MSW mock returns wrong response shape
The handler for /api/macro/impacts/:ticker was returning the impacts
array directly instead of { exposure_profile, impacts }. The frontend
destructures macroData.impacts which was undefined, falling back to
an empty array — so the Macro tab always showed 'No active macro impacts'
even with mock data present.
2026-04-17 07:14:50 +00:00
Celes Renata 419cf7558a fix: evidence articles missing on recommendations + Lucide title prop CI failure
- recommendation worker: filter out non-UUID document IDs (synthetic
  pattern:* IDs from competitive signals) before inserting into
  recommendation_evidence table — the uuid cast was failing and
  silently dropping all evidence rows
- wrap executemany in try/except so partial failures don't lose all evidence
- SqlExplorer: wrap Lucide icons in <span title=...> instead of passing
  title prop directly (not supported by lucide-react, broke CI build)
2026-04-17 07:10:21 +00:00
Celes Renata 913fe8b0b3 feat: override trade tab — manual order entry with auto-registration
Backend:
- OverrideOrderRequest/Response Pydantic models with ticker, quantity, price validators
- POST /api/trading/override/order endpoint (enqueue to Redis broker queue)
- auto_register_symbol() module for untracked ticker registration via Symbol Registry
- Unit tests (17) and property-based tests (3 x 100 examples)

Frontend:
- OverrideTradePanel component (order form + positions display)
- Override tab in TradingEngine page with URL search param navigation
- Override Trade button on Trading Controls page
- useSubmitOverrideOrder mutation hook
- MSW handler and 13 component/integration tests

Steering:
- Updated steering docs for Ubuntu dev machine with nvm/Node 24
2026-04-17 07:02:30 +00:00
Celes Renata 7f67725ec8 fix: mock handler returns 'impacts' to match frontend GlobalEventDetail type 2026-04-17 06:25:05 +00:00
Celes Renata cbe3fbe8b4 feat: enrich SQL explorer schema browser with PK/FK, row counts, search, collapsible tables 2026-04-17 06:22:04 +00:00
Celes Renata bbf7a6ee7b fix: sort imports in api/app.py to fix ruff lint 2026-04-17 06:19:03 +00:00
Celes Renata b149f70507 fix: operator approval workflow — add approval toggle, lockout CRUD, and PBT tests
- Add GET/PUT /api/admin/trading/approval-config endpoints
- Add POST/DELETE /api/admin/trading/lockouts endpoints
- Add useApprovalConfig, useUpdateApprovalConfig, useCreateLockout, useDeleteLockout hooks
- Add Paper Order Approval toggle card with confirmation dialog
- Add lockout creation form and delete button to Active Lockouts card
- Add MSW handlers for all new endpoints
- Add property-based tests for bug condition exploration and preservation
2026-04-17 06:14:46 +00:00
Celes Renata 3b7ded37cc fix: global event detail returns 'impacts' field to match frontend type
API was returning 'affected_companies' but frontend GlobalEventDetail
type expects 'impacts'. Renamed the response field.
2026-04-17 05:30:36 +00:00
Celes Renata bb3060c3b7 fix: render trend evidence as readable labels instead of raw UUIDs
- Pattern IDs (pattern:META:other:1d) shown as 'pattern META other (1d)'
- Document UUIDs shown as clickable 'doc:43156423…' links to document detail
- Unknown formats shown truncated as fallback
2026-04-17 05:29:00 +00:00
Celes Renata 62769c9b7e fix: macro impacts API returns {exposure_profile, impacts} to match frontend type
API was returning a flat array but frontend expects CompanyMacroImpacts
wrapper with exposure_profile and impacts fields. Also queries the
exposure_profiles table for the company's active profile.
2026-04-17 05:26:08 +00:00
Celes Renata d712d6b118 chore: gitignore .hypothesis/ cache directory 2026-04-17 05:16:47 +00:00
Celes Renata 7c23c044d7 feat: agent variants — migration, API, service integration, frontend, tests
- Migration 027: agent_variants table with single-active enforcement,
  variant_id column on agent_performance_log
- API: full CRUD, clone from agent/variant, activate/deactivate,
  per-variant performance metrics and history endpoints
- Services: extractor, event classifier, thesis rewriter all wired
  to AgentConfigResolver with variant override support
- Frontend: variant list, comparison view, create/edit/clone forms,
  activate/delete actions on Agents page
- Tests: API tests + 5 property-based tests (single-active invariant,
  clone preservation, config resolution, slug determinism, update idempotence)
- Spec files for agent-variants feature
2026-04-17 05:15:42 +00:00
Celes Renata 734bf001a7 feat: risk tier selector on Trading page + confidence filter on Recommendations
- Trading page: added conservative/moderate/aggressive selector that
  updates the trading engine config via PUT /api/trading/config
- Recommendations page: added risk tier dropdown that defaults to the
  engine's current tier and filters recs by the tier's min_confidence
- Backend: added min_confidence query param to GET /api/recommendations
- Risk tier thresholds: conservative ≥0.75, moderate ≥0.55, aggressive ≥0.40
2026-04-17 05:08:54 +00:00
Celes Renata 49e3955fab fix: add missing agent_config.py — was untracked, causing extractor crash in cluster 2026-04-17 04:41:58 +00:00
Celes Renata 0f06cf8971 docs: update README, runbook, and steering files for today's changes
- README: added AI agent management section, updated paper trading
  description (no manual capital controls, broker-synced reset)
- Steering: migration numbers updated to 027 (next: 028), added
  trading engine endpoint, ruff pinning and isort config notes
- Runbook: already had reset/Alpaca sections from earlier commits
2026-04-17 04:37:44 +00:00
Celes Renata fde819ec09 docs: update README and runbook for broker-synced reset, confidence dampener, paper account workflow 2026-04-17 04:32:49 +00:00
Celes Renata fd862da29e fix: remove broken capital controls, reset now queries broker for real balance
- Removed PUT /api/trading/capital (set capital) — only touched in-memory state
- Removed POST /api/trading/capital/adjust (add/withdraw) — same problem
- Reset endpoint now: liquidates Alpaca positions, cancels orders, clears DB,
  then queries Alpaca for real portfolio_value to set engine capital
- Frontend: replaced CapitalCard with simple ResetCard (one button)
- Removed useSetTradingCapital and useAdjustCapital hooks
2026-04-17 04:24:10 +00:00
Celes Renata 5fb59b379c feat: reset endpoint now liquidates Alpaca positions and cancels orders
- Added cancel_all_orders() and close_all_positions() to AlpacaBrokerAdapter
- Reset endpoint creates a temporary adapter to call Alpaca DELETE /v2/orders
  and DELETE /v2/positions before clearing DB and engine state
- Also clears positions table and processed_recommendation_ids on reset
- Broker reset is best-effort — DB/engine reset proceeds even if Alpaca fails
2026-04-17 04:03:31 +00:00
Celes Renata 5fc78bd9b4 feat: add 7 tests for confidence agreement dampener — sample-size boundary coverage 2026-04-17 03:48:08 +00:00
Celes Renata e21f162e48 fix: dampen agreement factor by sample size in trend confidence to prevent low-evidence inflation
Agreement of 1-2 signals was inflating confidence to paper-eligible
levels (0.575) even with low credibility sources. Added log2-based
dampener that scales agreement contribution by unique source count,
saturating at n=7. Single signals now cap at 0.39 confidence,
2 signals at 0.49 — both correctly below paper threshold (0.50).
2026-04-17 03:41:39 +00:00
Celes Renata d80d44e2fc fix: update stale tests — 50 companies, normalization defaults, low-confidence thresholds 2026-04-17 03:28:22 +00:00
Celes Renata 8ac2c1ea7a fix: declare services as known-first-party in ruff isort config for CI parity 2026-04-17 03:18:26 +00:00
Celes Renata 3084463c78 fix: pin ruff==0.15.10 to match local version and fix CI I001 failures 2026-04-17 03:16:28 +00:00
Celes Renata 376d961a08 ci: add ruff version + diff output to lint step for debugging 2026-04-17 03:11:21 +00:00
Celes Renata 6179382d1e feat: wire all 3 agents to DB config resolver
- Recommendation worker now resolves thesis-rewriter config from DB
  and passes ollama_config to generate_recommendation. Thesis rewriting
  is now active when the thesis-rewriter agent exists in ai_agents.
  Refreshes config every 50 jobs.

- Event classifier now resolves its own config separately from the
  document extractor via 'event-classifier' slug. Uses a separate
  OllamaClient when the model differs from the extractor. Refreshes
  alongside the extractor every 100 jobs.

- Document extractor was already wired (existing code).

- Added 8 unit tests for AgentConfigResolver covering: DB resolution,
  variant override, not-found, DB errors, TTL caching, cache refresh,
  and invalidation.
2026-04-17 02:59:40 +00:00
Celes Renata c501ccea40 fix: default model to qwen3.5:9b + improve event classifier prompt
- Migration 026 and OllamaConfig now default to qwen3.5:9b instead of
  llama3.1:8b. Existing deployments keep their current model (qwen3.5:9b-fast)
  since the migration uses WHERE NOT EXISTS on slug.

- Event classifier system prompt expanded with macro-vs-company filtering:
  explicitly instructs the model to NOT classify single-company news
  (lawsuits, earnings, management changes, debt crises) as macro events.
  Sets severity=low and confidence<0.3 for company-specific articles.
  Reserves 'critical' severity for multi-country/global market events.
  Prevents over-tagging event_types by requiring direct description.

- Updated test_system_prompt_is_concise threshold to accommodate the
  expanded prompt (300 → 1000 chars).
2026-04-17 02:53:38 +00:00
Celes Renata 90614dd7bb feat: paper trading capital controls — add, withdraw, and full reset
Three distinct capital operations on the Trading Controls page:

- Set Capital: overwrites pool balances to a new amount (existing)
- Add/Withdraw: adjusts active pool by a delta without touching
  positions, orders, or history. Validates sufficient balance for
  withdrawals. Logged to reserve_pool_ledger as manual_adjustment.
- Reset Everything: nuclear option — deletes all positions, orders,
  trading decisions, stop levels, snapshots, backtests, notifications,
  and circuit breaker events, then resets capital fresh. Red button
  with double-confirmation dialog.

Backend: POST /api/trading/capital/adjust and POST /api/trading/reset
Frontend: CapitalCard rebuilt with three sections and confirmation UIs
2026-04-17 02:23:26 +00:00