TradingAgents/docs/agent/decisions
ahmet guzererler 6b3dd4172a
feat: finalise storage layout, run history loading & phase-level re-run (#121)
* feat: introduce flow_id with timestamp-based report versioning

Replace run_id with flow_id as the primary grouping concept (one flow =
one user analysis intent spanning scan + pipeline + portfolio). Reports
are now written as {timestamp}_{name}.json so load methods always return
the latest version by lexicographic sort, eliminating the latest.json
pointer pattern for new flows.

Key changes:
- report_paths.py: add generate_flow_id(), ts_now() (ms precision),
  flow_id kwarg on all path helpers; keep run_id / pointer helpers for
  backward compatibility
- ReportStore: dual-mode save/load — flow_id uses timestamped layout,
  run_id uses legacy runs/{id}/ layout with latest.json
- MongoReportStore: add flow_id field and index; run_id stays for compat
- DualReportStore: expose flow_id property
- store_factory: accept flow_id as primary param, run_id as alias
- runs.py / langgraph_engine.py: generate and thread flow_id through all
  trigger endpoints and run methods
- Tests: add flow_id coverage for all layers; 905 tests pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: finalise storage layout, run history loading & phase-level re-run

Storage / persistence
- flow_id (8-char hex) replaces run_id as the disk storage key; all
  sub-phases of one auto run share the same flow_id directory
- Startup hydration: hydrate_runs_from_disk() rebuilds in-memory run
  store from run_meta.json on server restart (events lazy-loaded)

WebSocket / run history fixes
- Lazy-load events from run_events.jsonl on first WS connect; fixes
  blank terminal when clicking a historical run after restart
- Orphaned "running" runs (server restarted mid-run) auto-detected and
  marked "failed" with partial events replayed correctly

Phase re-run fixes
- Analysts checkpoint: use any() instead of all() — Social Analyst is
  optional; all() silently blocked checkpoint saves in typical runs
- Checkpoint lookup: pass original flow_id through rerun_params so
  _date_root() resolves to the correct flow_id subdirectory
- Selective event filtering on re-run: preserves scan nodes and other
  tickers; only removes stale events for the re-run phase+ticker
- Frontend graph now shows full auto-flow context during phase re-runs

Documentation
- ADR 018: canonical reference for storage layout, event schema,
  WebSocket streaming flows, checkpoint structure, MongoDB vs local
- ADR 013 updated: reflects background-task + lazy-loading evolution
- ADR 015 marked superseded by ADR 018
- CLAUDE.md: AgentOS storage section + 4 new critical patterns
- CURRENT_STATE.md updated

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-26 11:12:16 +01:00
..
.gitkeep feat: add agentic memory scaffold and migrate tracking files to docs/agent/ 2026-03-17 17:14:11 +01:00
001-hybrid-llm-setup.md feat: add agentic memory scaffold and migrate tracking files to docs/agent/ 2026-03-17 17:14:11 +01:00
002-data-vendor-fallback.md feat: opt-in vendor fallback — fail-fast by default (#18) 2026-03-18 14:25:38 +01:00
003-yfinance-etf-proxies.md feat: add agentic memory scaffold and migrate tracking files to docs/agent/ 2026-03-17 17:14:11 +01:00
004-inline-tool-execution.md feat: add agentic memory scaffold and migrate tracking files to docs/agent/ 2026-03-17 17:14:11 +01:00
005-langgraph-parallel-reducers.md feat: add agentic memory scaffold and migrate tracking files to docs/agent/ 2026-03-17 17:14:11 +01:00
006-env-var-config-overrides.md feat: add agentic memory scaffold and migrate tracking files to docs/agent/ 2026-03-17 17:14:11 +01:00
007-thread-safe-rate-limiter.md feat: add agentic memory scaffold and migrate tracking files to docs/agent/ 2026-03-17 17:14:11 +01:00
008-lessons-learned.md feat: opt-in vendor fallback — fail-fast by default (#18) 2026-03-18 14:25:38 +01:00
009-industry-deep-dive-quality.md docs: update memory files after PR #13 (Industry Deep Dive quality fix) 2026-03-17 20:20:39 +01:00
010-finnhub-vendor-integration.md feat: opt-in vendor fallback — fail-fast by default (#18) 2026-03-18 14:25:38 +01:00
011-opt-in-vendor-fallback.md feat: opt-in vendor fallback — fail-fast by default (#18) 2026-03-18 14:25:38 +01:00
012-portfolio-no-orm.md docs: ADR-012 — raw supabase-py over Prisma/SQLAlchemy for portfolio data layer 2026-03-20 10:48:40 +00:00
013-agentos-websocket-streaming.md feat: finalise storage layout, run history loading & phase-level re-run (#121) 2026-03-26 11:12:16 +01:00
014-finviz-smart-money-scanner.md feat(scanner): Finviz smart money scanner + Golden Overlap strategy 2026-03-24 16:03:17 +01:00
015-mongodb-report-store-reflexion.md feat: finalise storage layout, run history loading & phase-level re-run (#121) 2026-03-26 11:12:16 +01:00
016-pr106-review-findings.md fix: graceful LLM 404 handling + per-tier fallback model config (#108) 2026-03-25 11:19:08 +01:00
017-llm-policy-fallback.md fix: graceful LLM 404 handling + per-tier fallback model config (#108) 2026-03-25 11:19:08 +01:00
018-storage-events-checkpoints.md feat: finalise storage layout, run history loading & phase-level re-run (#121) 2026-03-26 11:12:16 +01:00