Repository navigation
Context length: the champion chooses CONTEXT_DAYS, from backtests to the live miner - #91
Merged
Merged
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
Thykof
force-pushed
the
feat/context-days
branch
from
November 9, 2026 10:50
cf17d55 to
29dc9af
Compare
…he verdict A champion sets CONTEXT_DAYS, a plain int from 3 to 30, at module level in its modeling.py; a module without it gets 7. generate_predictions.py reads it through one helper, context_days_of, which raises on any other value (the check is type(v) is int, so True and 14.0 fail too). predict.py reads it at import, so an invalid value fails the first backtest, and prints it on each summary line. The verdict's generator loads the module before the prices, writes context_days into each day's index, and run_verdict checks that every (competition, asset) run reports the same value and writes it as a top-level context_days in verdict.json. Both offline contexts are one slice, context_slice: from CONTEXT_DAYS before the prompt to context_end (predict.py took the last N rows, which started a minute or two early). The days before an asset's first partition are NaN on every minute, as a live context holds them; a missing partition after the first still raises, and predict.py's coverage check no longer counts the former as missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
…med per format The probe builds its synthetic context at the champion's CONTEXT_DAYS and fails the check, with the usual hand-back, on a value outside 3 to 30. On success the BUDGET.md note reads "ok (24h + 1h), CONTEXT_DAYS 14, one call 2.1 s (24h) and 0.3 s (1h)": the value as the working tree sets it, and the wall time of one call of each format at that length. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
…n, one context per prompt ChampionMiner gains context_days, 7 by default for a miner.py that does not set it; the generated miner sets it from modeling.py, and the miner logs it at startup. Each request builds a context of that length, and the warm-up and the background refresh cover CONTEXT_DAYS + 1 date partitions. The warm-up now goes through refresh_recent, so it stops at the venue's retention as the refresh does instead of asking Hyperliquid for days it no longer serves, and it logs the share of each asset's context that holds a real close. Built contexts are kept per (asset, time_length, start_time), the newest 32, so validators sending the same prompt share one. The format is in the key because a crypto-24h and a crypto-1h prompt for the same asset can share a start_time. simulate() gets a copy of the cached frame. The unpack contract gate runs on a synthetic context of CONTEXT_DAYS + 1 days and PROVENANCE.md records the value. black 26 reformats unpack_champion.py's templates and test_champion_serving.py, as the lint check on changed files requires. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
…rter models Rule 7 says the context spans CONTEXT_DAYS, a plain int from 3 to 30 at module level in modeling.py (7 without it), which predict.py, the interface check, the scoring and the live miner all read, and that whole days before an asset's first trade are NaN. The lessons that said 7 days and "contexts rougher than the snapshot" follow. Both starter modeling.py files set CONTEXT_DAYS = 7. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
check_snapshot_coverage takes the first prompt's time. A missing day is a hole when it is on or after the asset's first partition, or on or after the first prompt's day, so a window whose prompts start before the snapshot's first day stops with the coverage error again, before any generation, instead of handing those prompts an empty context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
…about A context that reaches back before an asset's first partition starts with NaN, and the store's first day is not always the market's first trade: a snapshot or a host store that starts late shortens every context the same way. That is now visible. - Each day index records context_head_nan_minutes, the most minutes one of the day's contexts runs before its first real close (generate_predictions.nan_head_minutes). - run_verdict prints, per asset, how long its contexts start with NaN, and verdict.json records it as context_head_nan_minutes (assets whose contexts all start on a real close are left out). - run_verdict warns when an asset's first partition in the data root is after the day its first context begins, and names the cache directory to delete once the missing days are ingested: the day files keep the contexts they were generated with. - predict.py prints one warning line when a context starts with NaN. - DATA.md, the constitution and predict.py's docstring say a missing file is before the market's first trade, or before the snapshot's first day. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
…t shape probe_all_shapes loads the champion's module once and hands it to probe_simulate for both formats, so a module that does heavy work at import pays for it once inside the probe's timeout. The synthetic context spans [start - CONTEXT_DAYS, start] and goes through context_slice, so the champion gets the shape predict.py and the verdict hand it: CONTEXT_DAYS * 1440 - 2 rows for 24h and - 1 for 1h, ending before the bar labelled start_time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
…oves on ContextCache kept the context the first validator's request built, so a store refresh, or a fresh tail holding a newer bar, that landed before a later validator asked the same prompt never reached it. The key now holds the tail's newest bar (None when the tail is empty), and the cache adds the number of store refreshes marked before the build: ChampionMiner marks one after each refresh pass. Validators asking a prompt within one snapshot of the store and the tail still share one build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
On a cold volume the background refresh started only once every asset had warmed up, and a long context makes each Binance asset's warm-up fetch a month of partitions: the assets served first aged meanwhile. After each asset's warm-up, the warm-up thread now refreshes today's partition of the assets already ready (refresh_recent(days=1) on a snapshot of the ready set, each in its own try), never one still warming up, and marks the refresh for the cached contexts like the background pass does. The refresh test's stdlib imports form one group. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
…once Hyperliquid serves its last 5000 minutes, so the oldest day a refresh asks it for can start before that edge and come back partial. ingest_day stored it as settled, so neither the miner nor a later archive ingest, which skips settled partitions, ever completed it. A past day that starts before the client's retention_minutes is now stored with is_final False, and once a partition for it exists it is not fetched again (unless force_refresh), so the per-minute refresh does not ask for it every pass. The stored > fresh guard is unchanged, and a client without retention (Binance) is too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
ingest_day writes the partition through write_atomic, a temporary file in the same directory replaced into place, so a write cut short (a killed pod mid-refresh) leaves the previous partition whole instead of a truncated file that later reads take for the day. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
refresh_recent(days=D + 1) covers today-(D + 1) through today, the context's D + 1 date partitions and the day before them. The warm_up and _refresh_once docstrings and the refresh test's name said D + 1 partitions. warm_up's docstring also says the oldest day Hyperliquid holds in part is stored unsettled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
…e is mkstemp creates its file owner-only, so every atomically written partition was 0600. It is now 0644. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh
Thykof
force-pushed
the
feat/context-days
branch
from
November 9, 2026 10:52
29dc9af to
d1a92d2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #90, which is stacked on #89: merge those first.
Why
Every champion got the 7 days of minute candles before the prompt: in its backtests, in the verdict and live. That length was a harness constant that nobody had measured. A model that wants a month of history for its volatility level, or three days for crypto-1h, could not ask for it. An agent could edit
predict.py's own constant, but the verdict and the miner still passed 7 days, so its backtests measured a model that would never be served.With this PR the champion chooses its context length the way it chooses any other parameter: by measuring it. It sets one value, and every consumer reads that same value.
What
The value.
CONTEXT_DAYSis a module-level int in the champion'smodeling.py, from 3 to 30. A module without it gets 7, so every archived champion keeps its context. All consumers read it through one helper,generate_predictions.context_days_of. Any other value raises everywhere. The check istype(v) is int, soTrueand14.0fail too. One value serves every competition.agent/predict.py(scaffold)CONTEXT_MINUTESis gone.context_daysandcontext_head_nan_minutes(the most minutes one of the day's contexts runs before its first real close) into each day's index JSON.run_verdictcontext_daysinverdict.json, andcontext_head_nan_minutesfor each asset whose contexts start with NaN, which it also prints. An index written before these fields reads as 7 and 0.context_sliceoverCONTEXT_DAYS), and fails the check on an invalid value, with the usual hand-back. BUDGET.md readsok (24h + 1h), CONTEXT_DAYS 14, one call 2.1 s (24h) and 0.3 s (1h).CONTEXT_DAYS + 1days (8 for every archived champion, as before). PROVENANCE.md records the value.ChampionMinercontext_daysclass attribute, 7 for a copiedminer.pythat does not set it. The generated miner sets it frommodeling.py. Logged at startup.serve_requestbuild_context, which now takescontext_days.One slice offline.
predict.pyused to take the last N rows, which started a minute or two early. It, the generator and the interface probe now sharecontext_slice, fromt − CONTEXT_DAYStocontext_end:CONTEXT_DAYS × 1440 − 2rows for 24h and− 1for 1h, ending before the bar labelledstart_time. Serving already started its grid att − CONTEXT_DAYS.History shorter than the context.
load_minute_pricesnow makes the days before an asset's first partition NaN on every minute, which is how a live context holds them. A missing partition after the first one still raises.predict.py's coverage check exempts only that head: a missing day on or after the asset's first partition, or on or after the first prompt's day, still stops the run before any generation. Its message points at DATA.md's first and last day per asset.run_verdictprints and records it per asset over the window's own day files, and it warns when an asset's first partition in the data root is after the day its first context begins. The warning names the cache directory to delete once those days are ingested: cached day files keep the contexts they were generated with.predict.py's docstring say a missing file is before the market's first trade, or before the snapshot's first day.Live store and requests.
refresh_recent(days=CONTEXT_DAYS + 1), which covers today − (CONTEXT_DAYS+ 1) through today: the context's date partitions and the day before them.WARMUP_DAYSis gone.warm_upnow goes throughrefresh_recent, so it stops at each venue's retention as the refresh already did. Before, a cold 30-day warm-up would have asked Hyperliquid for about 27 days it no longer serves, on every restart.write_atomicgives the file mode 0644, as a plain write did;mkstempalone left it owner-only.ContextCachekeeps the newest 32 built contexts, so validators sending the same prompt share one. Its key is(asset, time_length, start_time), the fresh tail's newest bar (None when the tail is empty) and the number of store refreshes marked before the build;ChampionMinermarks one after each refresh pass. A refresh or a newer tail bar landing between two validators therefore reaches the second, and validators within one snapshot still share one build. The format is in the key because a crypto-24h prompt and a crypto-1h prompt for the same asset can share astart_time, and only the 1h one carries the fresh tail.simulate()receives a copy, so a champion that mutates its input cannot change the context the next validator gets.Text. Constitution rule 7 now describes
CONTEXT_DAYS: its bounds, its default, who reads it, and the NaN days before a first trade or the snapshot's first day. The lessons that said 7 days and "contexts rougher than the snapshot" are updated to match. Both startermodeling.pyfiles setCONTEXT_DAYS = 7.Not in this PR.
verdict/generate.pyandverdict/generate_cli.pyare untouched. Nothing calls them, and they will be removed in a separate PR.nomination.load_simulatestays becausegenerate_cli.pyimports it.--context-daysoverride inrun_verdict, because it would need its own cache key.CONTEXT_DAYSis invalid at verdict time fails every generation run, andrun_verdictstill writes averdict.jsonwithscoreandcontext_daysnull; the reason is only in the console log.predict.pyand the interface probe refuse such a value long before nomination.simulate()receives it; live,build_contextraises "no usable closes" and the request fails. Both startermodeling.pyfiles raise on such a context.generate_predictions.CONTEXT_MINUTESis removed. A downstream script that imports it (autoquant'sscripts/measure_issuance_lead.py) moves to the champion's own length when its synth-lib pin moves past this branch.Formatting. black 26 reformats the templates in
unpack_champion.pyand two helpers intest_champion_serving.py. The lint check runs on every changed file, so these files must pass it whole.Tests
CONTEXT_DAYS = 14gets 14 days from the probe,predict.py, the verdict's generator,serve_request, and the generated miner'sforward_miner. The contract gate gives it 15 days.2,31,Trueand14.0raise in the helper,predict.py, the generator (before it reads any price), the probe (okFalse, with a message naming the bounds), the contract gate and the generated miner.D × 1440 − 2rows for 24h andD × 1440 − 1for 1h.predict.py's coverage check, and so does a prompt on a day before the first partition.run_verdictreads the per-asset maximum over the window's own day files (another window's files in the shared cache are ignored, an index without the field reads as 0) and records it inverdict.json. It flags a store whose first partition is after the day the first context begins, and not one that covers it.predict.pyprints its warning on a context that reaches before the snapshot.ContextCachereturns the same object for the same key, builds once for three identical requests, builds again for the other format, and evicts the oldest key. A store refresh or a newer tail bar between two requests for the same prompt reaches the second, a repeated tail does not rebuild, and each refresh pass marks the cache.run_verdictreads one value across the runs, raises when runs disagree, reads an index without the field as 7, and returns None when no index exists.CONTEXT_MINUTES,WARMUP_DAYS, the probe'sok (24h + 1h), the probe's context length,check_snapshot_coverage's arguments and the generated miner's import are updated.Commands:
uv run pytest -q: 577 passed, 1 skipped. The skip is the unpacked-champions gate, which has nochampions/directory to parametrize over.uvx black@26.5.1 --checkanduvx --with flake8-pyproject==1.2.3 flake8@7.1.2on the 22 changed Python files, as CI runs them: both clean.🤖 Generated with Claude Code
https://claude.ai/code/session_016kmUsyYSEMPGiwbSuvR9hh