Skip to content

fix: retry a feedback setup failure instead of ending the run (#164) - #168

Merged
mohammadp1001 merged 1 commit into
mainfrom
fix/164-feedback-failure-resilience
Aug 9, 2026
Merged

fix: retry a feedback setup failure instead of ending the run (#164)#168
mohammadp1001 merged 1 commit into
mainfrom
fix/164-feedback-failure-resilience

Conversation

@mohammadp1001

Copy link
Copy Markdown
Owner

Fixes #164.

FR-016a says a failed evaluation is retried up to 3 times and then marked failed, which
unblocks the ticker, and the run carries on. Two steps ran before the retry loop and
got none of that protection: reading the entry report and fetching the evaluation price.

Both touch the outside world, so a missing report file or an unreachable Alpaca raised
straight out of evaluate(), travelled up through _process_session and stopped the whole
run - leaving the position blocked forever, which is exactly what FR-016a and FR-017 exist
to prevent.

This is not a hypothetical path. The entry session may legitimately carry no report path;
_run_feedback already passes html_report_path or "" for that case, so _extract_thesis
opening "" and raising FileNotFoundError is a path the code expects to reach.

What changed

  • The thesis read and the price fetch moved inside the retry loop, so they are retried
    like any other failure and, after 3 attempts, end in the normal EVALUATION_FAILED path
    that unblocks the ticker.
  • _write_failure now works when no price was ever fetched. candle_close_price is
    NOT NULL, so the position's own exit price stands in - a real price for this position -
    and the reasoning text records that the evaluation price could not be fetched, so the row
    is not mistaken for a genuine candle close.
  • Scheduler._run_feedback wraps each position. One that still blows up is logged, echoed,
    and emitted as EVALUATION_FAILED, and the loop moves on to the next position and to the
    session.

Tests

Nine added. Five of them fail against the old code:

  • test_a_missing_report_file_does_not_escape_evaluate
  • test_a_price_fetch_failure_does_not_escape_evaluate
  • test_a_price_fetch_is_retried_three_times
  • test_a_price_fetch_that_recovers_on_the_second_attempt_succeeds
  • test_failure_without_a_price_records_the_exit_price_instead

The rest pin the scheduler safety net and confirm a successful price fetch is still the
price recorded on an LLM-side failure.

Verification

603 passed in 137.73s (0:02:17)
Required test coverage of 100% reached. Total coverage: 100.00%
ruff check alphoryn/ tests/ -> All checks passed!

FR-016a says a failed evaluation is retried up to 3 times and then marked
failed, unblocking the ticker, with the run carrying on. Two steps ran before
the retry loop and got none of that: reading the entry report and fetching the
evaluation price. Both touch the outside world, so a missing report file or an
unreachable Alpaca escaped evaluate(), travelled up through _process_session
and stopped the run - leaving the position blocked forever, which is what
FR-016a and FR-017 exist to prevent.

The entry session may legitimately carry no report path; _run_feedback already
passes `html_report_path or ""` for that case, so _extract_thesis opening ""
and raising FileNotFoundError is a path the code expects to reach.

- Both steps moved inside the retry loop, so they retry like any other failure
  and end in the normal EVALUATION_FAILED path that unblocks the ticker.
- _write_failure accepts no price. candle_close_price is NOT NULL, so the
  position's own exit price stands in and the reasoning text records that the
  evaluation price was never obtained, so the row is not mistaken for a real
  candle close.
- Scheduler._run_feedback wraps each position: one that still blows up is
  logged and emitted as EVALUATION_FAILED, and the loop moves to the next.

Nine tests added; five fail against the old code.

Closes #164
@mohammadp1001
mohammadp1001 merged commit 7e9407e into main Aug 9, 2026
3 checks passed
@mohammadp1001
mohammadp1001 deleted the fix/164-feedback-failure-resilience branch August 9, 2026 13:08
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.

fix: a feedback failure crashes the whole run instead of retrying (FR-016a)

1 participant