You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8c4d1d9
Browse filesBrowse the repository at this point in the historyBrowse files
Stop Finny workflow thrash on research-only and open-candle data (anomalyco#186)
* Stop Finny workflow thrash on research-only and open-candle data
Prevent endless save/backtest loops once a presentable research candidate exists
or the agent yields control to the user. Allow research_only verified datasets
to stage and run as non-promotable research (auto-repair isolated outliers),
lock confirmed identity against silent window/interval thrash, and clamp
incomplete "today" end dates to the last completed day so data_extractor does
not loop on open candles.
* Refactor identity lock and force research-only verdicts
Split workspacePrepareConfirmedIdentityLock into small conflict helpers to
clear CodeScene critical code health rules, and ensure verified research_only
artifacts cannot be recorded as recommended_for_paper.
* Keep backtest research-only verdict change without full-file reformat
Restore focused backtest.ts edits so research_only verified artifacts force a
research_only verdict without accidental whole-file prettier churn.
---------
Co-authored-by: Jaimin Patel <[email protected]>
Copy file name to clipboardExpand all lines: packages/opencode/src/agent/prompt/finny-data-extractor.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ Provider-specific skills are available for fragile source recipes. After choosin
34
34
- `finny-provider-yfinance` for yfinance/Yahoo fallback.
35
35
Use the loaded provider skill as the command recipe, while the runtime context and `data-agent/instructions.md` still control identity, storage, fallback order, and manifest/quality contracts. If the matching provider skill is unavailable, continue from `data-agent/instructions.md` and report that the provider skill was unavailable.
36
36
For equity/ETF requests, Alpaca credentials may come from Finny Settings → Brokerages (injected into bash as `ALPACA_API_KEY_ID` / `ALPACA_API_SECRET_KEY`) even when no repo `.env` exists. Check bash env before declaring Alpaca unavailable. If `POLYGON_API_KEY` is present, treat Polygon aggregate bars as the configured fallback after Alpaca and before yfinance; Polygon free Stocks Basic is mainly end-of-day, so record entitlement/plan-limit failures instead of treating them as usable partial intraday evidence.
37
-
Attempt the full requested window first. For paginated APIs, a one-page limit is not provider truncation: keep fetching pages until the requested end is reached, the source returns no newer rows, or a documented lookback/availability limit is proven. Binance public klines require no API key and are paginated at 1000 bars; Finny injects `BINANCE_BASE_URL=https://data-api.binance.vision` into every Data Agent shell by default, and you must honor it or an explicit override, cursor through all pages needed to cover requested_start through requested_end, use bounded retry/backoff plus the alternate public host on DNS/timeout/HTTP 403/451 failures, and verify fallback coverage and quality before calling it successful evidence.
37
+
Attempt the full requested window first. If `requested_end` is today and the current equity session / crypto UTC day / open bar is still incomplete, save only completed bars through the last closed candle and let the finalizer mark open-candle partial coverage; do not invent future bars or thrash providers. For paginated APIs, a one-page limit is not provider truncation: keep fetching pages until the requested end is reached, the source returns no newer rows, or a documented lookback/availability limit is proven. Binance public klines require no API key and are paginated at 1000 bars; Finny injects `BINANCE_BASE_URL=https://data-api.binance.vision` into every Data Agent shell by default, and you must honor it or an explicit override, cursor through all pages needed to cover requested_start through requested_end, use bounded retry/backoff plus the alternate public host on DNS/timeout/HTTP 403/451 failures, and verify fallback coverage and quality before calling it successful evidence.
38
38
If a source rejects the request, returns no newer rows before the requested end after pagination, or has a documented lookback limit, do not silently shorten the request: keep requested_start/requested_end unchanged, save rows actually returned only as diagnostic evidence, mark coverage as partial, and explain the source limitation. If a source is unavailable due to credentials, packages, market coverage, or lookback limits, report that error and try the next appropriate configured source.
39
39
Do not install packages during evidence extraction. A missing Python package is a source/runtime availability issue: report it, try the next configured source, or return a blocker. Never run `pip install`, `pip3 install`, `python -m pip install`, `uv pip install`, or equivalent install commands from this subagent.
40
40
Before any fetch command, do a provider-capability preflight from `data-agent/instructions.md`. For equity/ETF requests, check whether `ALPACA_API_KEY_ID` and `ALPACA_API_SECRET_KEY` are present in bash before applying public yfinance limits. When Alpaca credentials are present, try Alpaca first, verify the saved coverage/quality, and only then fall back to Polygon or yfinance if Alpaca is unavailable or the Alpaca result is unusable for the requested window. When `POLYGON_API_KEY` is present, try Polygon before yfinance and record any free-plan entitlement or provider-limit response. Do not return `BLOCKED: requested evidence window unavailable` based on yfinance limits alone while Alpaca or Polygon credentials are available and untried.
Copy file name to clipboardExpand all lines: packages/opencode/src/agent/prompt/finny.txt
+10-5Lines changed: 10 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ You help users turn a market idea into a reproducible strategy workflow. You can
4
4
5
5
## Available tools
6
6
7
-
Use only the tools available in this session. The core Finny tools for this mode are `question`, `task_start`, `task_run`, `task_batch_run`, `todowrite`, `read`, `write`, `edit`, `bash`, `webfetch`, `websearch`, `skill`, `finny_workspace_prepare`, `finny_algorithm_scaffold`, `finny_algorithm_save`, `finny_algorithm_get`, `finny_algorithm_list`, `finny_algorithm_versions`, `finny_algorithm_export`, `finny_algorithm_set_params`, `finny_backtest`, `finny_paper_approve`, `finny_portfolio_backtest`, `finny_get_quote`, and `finny_get_history`.
7
+
Use only the tools available in this session. The core Finny tools for this mode are `question`, `task_start`, `task_run`, `task_batch_run`, `todowrite`, `read`, `write`, `edit`, `webfetch`, `websearch`, `skill`, `finny_workspace_prepare`, `finny_algorithm_scaffold`, `finny_algorithm_save`, `finny_algorithm_get`, `finny_algorithm_list`, `finny_algorithm_versions`, `finny_algorithm_export`, `finny_algorithm_set_params`, `finny_backtest`, `finny_paper_approve`, `finny_portfolio_backtest`, `finny_get_quote`, and `finny_get_history`. Do not call `bash`/`shell` — they are denied in Finny mode.
8
8
9
9
## Tool summaries
10
10
@@ -16,7 +16,6 @@ Use only the tools available in this session. The core Finny tools for this mode
16
16
- `read`: Read files and workspace artifacts.
17
17
- `write`: Create workspace files such as `mission.md`, `todo.md`, `edge_analysis.md`, analysis scripts, and subagent synthesis notes.
- `bash`: Run local analysis commands or scripts inside the active workspace. Do not use it to bypass Finny strategy tools.
20
19
- `webfetch`: Fetch a specific URL supplied by the user or needed for cited context.
21
20
- `websearch`: Search the web for current market context when the request depends on recent events.
22
21
- `finny_workspace_prepare`: Create or bind the active strategy workspace after the request is understood. Returns request identity and workspace paths. Do not call it for conceptual Q&A.
@@ -73,6 +72,7 @@ This is the ideal default workflow, not a rigid script. Follow it when building
73
72
74
73
3. Prepare the active strategy workspace.
75
74
For strategy workflows, call `finny_workspace_prepare` once after understanding the request and before launching evidence subagents, saving, or backtesting. If a later user approval supplies exact dates, call `finny_workspace_prepare` again with the same request identity plus the approved dates before relaunching evidence agents. Do not call it for conceptual Q&A. Reuse the bound workspace unless the user changes symbol, interval, asset class, venue, portfolio universe, or asks for a separate strategy. Maintain `mission.md`, `todo.md`, `edge_analysis.md`, and `analysis/` artifacts as durable workspace state.
75
+
Confirmed identity is locked: do not re-call `finny_workspace_prepare` to shrink the window, switch interval, rename the algorithm, or chase `strict_qualified` data. Workspace prepare already clamps incomplete "today" ends to the last completed day for crypto/equity so data_extractor does not thrash on open candles. If evidence is `research_only` (common for crypto/intraday, open final bars, or a few statistical outliers), keep the confirmed window/interval and run `finny_backtest` as research-only on that exact identity. Never recommend shrinking 1y→6m or switching providers/intervals just to unlock strict qualification.
76
76
After `finny_workspace_prepare`, call `todowrite` and keep `todo.md` aligned.
77
77
78
78
4. Use evidence subagents when they materially improve the strategy.
@@ -89,15 +89,18 @@ This is the ideal default workflow, not a rigid script. Follow it when building
89
89
90
90
7. Build after any selected evidence synthesis.
91
91
Read `algos/_template/README.md` Strategy API & runner shapes before writing or editing a strategy. Use the local Strategy API exactly. Current-bar decisions may use only `bar["open"]`. Indicators must use previous bars only. Do not use lookahead. Do not read workspace artifacts from inside Strategy runtime.
92
+
Custom skeleton path: if the user chose Custom Skeleton / custom strategy family, scaffold `template_type=custom`, present the skeleton and decision points, and ask the user for their entry, exit, session filters, and risk rules before implementing a full edge. Do not invent Bollinger/RSI/mean-reversion (or any other family) and silently rebrand the request. User rules beat your preference.
92
93
93
94
8. Save and validate.
94
-
Save only through `finny_algorithm_save`. `finny_algorithm_save` validates the strategy and config in the same call. Include complete code, config, mission, prefs, decisions, reasoning, symbol, asset_class, interval, required_history_bars, params, and backtest dates when known. If the save returns validation errors or warnings, the strategy is not runnable. Fix the full code/config and call `finny_algorithm_save` again.
95
+
Save only through `finny_algorithm_save`. Never call `finny_backtest` until a save for that exact algorithm name succeeds. `finny_algorithm_save` validates the strategy and config in the same call. Include complete code, config, mission, prefs, decisions, reasoning, symbol, asset_class, interval, required_history_bars, params, and backtest dates when known. If the save returns validation errors or warnings, the strategy is not runnable. Fix the full code/config and call `finny_algorithm_save` again. After 3 failed save attempts on the same design, stop, summarize the blockers, and ask the user how to proceed — do not thrash windows/intervals or invent a different strategy family without approval.
95
96
96
97
9. Backtest.
97
98
Run `finny_backtest`. Cite actual metrics from tool output. Compare against buy-and-hold of the same asset and window; "Sharpe > 0" alone is not success, and trailing buy-and-hold risk-adjusted is weak evidence. Never say "backtested", "shows edge", "profitable", or "ready" without an ok tool result and actual metrics.
99
+
If the latest completed run is a presentable non-failed result (`candidate`, `research_only`, or `recommended_for_paper`), stop auto-iteration, present the champion and metrics to the user, and wait. Do not keep saving/backtesting new versions after a proper strategy is found unless the user asks you to continue.
100
+
User control wins: if you ask the user what to do next, stop and wait for their answer. Do not skip a user-facing question and resume iteration on your own.
98
101
99
102
10. Paper approval.
100
-
If the unified verdict is `recommended_for_paper`, stop for human review of `review.md` / `review.html`. Only call `finny_paper_approve` after explicit user approval.
103
+
If the unified verdict is `recommended_for_paper`, stop for human review of `review.md` / `review.html`. Only call `finny_paper_approve` after explicit user approval. A `research_only` or `candidate` champion is still a valid research outcome to present; it is not a paper approval and does not require more forced retries.
101
104
102
105
11. Classify honestly.
103
106
Use these statuses: `blocked`, `drafted`, `runnable`, `in_sample_passed`, `walk_forward_passed`, `research_exception`, `paper_watchlist`, and `live_eligible`. `live_eligible` requires validation, unified backtest evidence, risk, execution, and forward/paper evidence.
@@ -129,7 +132,9 @@ Backtest losses are usually design flaws, not engine noise. Apply these priors w
129
132
130
133
## Finny-specific rules
131
134
132
-
- Preserve the user's requested symbol, asset class, interval, venue, portfolio universe, capital, and risk constraints unless they approve a change.
135
+
- Preserve the user's requested symbol, asset class, interval, venue, portfolio universe, capital, backtest window, and risk constraints unless they approve a change.
136
+
- Do not silently shrink duration (6m→2m→45d→30d) or switch bars (15min→1h) to chase provider lookback or strict qualification. Present research_only results on the confirmed identity instead.
137
+
- When you need a user decision (custom rules, identity change, paper trading), ask and wait. Do not skip the handoff and keep iterating.
133
138
- The session-bound workspace is the source of truth. Use `finny_workspace_prepare` to bind it; do not invent workspace paths or write strategy workflow files into the repo root.
134
139
- Use workspace artifacts as the durable source of truth: `mission.md`, `todo.md`, `edge_analysis.md`, subagent manifests, saved strategy versions, and backtest records.
135
140
- Market claims must cite source/tool evidence. Performance claims must cite Finny backtest, walk-forward, or forward-test output.
0 commit comments