Repository navigation
feat(strategies): persist generator state so warm starts resume streams - #1121
Open
bilhokista wants to merge 1 commit into
Open
bilhokista wants to merge 1 commit into
bilhokista wants to merge 1 commit into
Conversation
XorShift64 gains getState() and fromState(), and RunReport records each generator stream's start and end state as decimal strings in the wire format. buildWarmStartContext hands the end states to the continuation, and mergeReports rejects a continuation whose streams did not start where the base run stopped. REPORT_FORMAT_VERSION moves to 2, so a version 1 report, which carries no state, is rejected on read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Someone is attempting to deploy a commit to the Collins' projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@bilhokista Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This branch has not been deployed
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.
Summary
XorShift64state access (rng.ts):getState(): bigintreads the state without advancing the stream.static fromState(state)builds a generator at a given state. It goes through the existing constructor, so behaviour is unchanged.fromStaterejects anything outside1..2^64-1instead of masking it. No generator can hold such a state, so masking would quietly resume a different stream.42n, recorded frommainbefore this change.RunReport.generators: { start, end }(report.ts). Each side is aRecord<streamId, bigint>, one entry per stream (e.g.price:USDC, or one perderivePathSeedpath index), so every state says which stream it belongs to.startis the seeded state for a fresh run, or the base report'sendfor a continuation.endis the state atfinalState.starthas to match where the base stopped, andendis where the next continuation resumes from.FixedPointDecimalstroops, so the 64-bit values survive JSON. On read, a malformed value throwsTypeErrorand an out-of-range value throwsRangeError. A missinggeneratorsblock is also rejected.WarmStartContext.generatorStatescarries the base'sendstates. The newrestoreGenerators(ctx)turns them intoXorShift64instances keyed by stream id.mergeReportsthrowsRangeErrornaming the stream whencontinuation.generators.startdoesn't matchbase.generators.end: a differing value, a missing or extra stream, or states swapped between paths. The merged report gets{ start: base.start, end: continuation.end }.REPORT_FORMAT_VERSION1 → 2. Reading a v1 report (no state) throwsUnknownReportVersionError.RunReportdoc comment, as the issue suggests.Breaking
The run-report wire format gains
generatorsand the version goes up. Code that builds aRunReportby hand now has to supplygenerators({ start: {}, end: {} }for a run that draws nothing). Within the monorepo, onlyreport.tsand its tests build reports.Out of scope / follow-up
scenarioPriceFeedstill builds its path frommarket.startPricewith a freshXorShift64(seedToBigInt(seed)), andgenerateGbmPathdoesn't accept an existing generator. This PR gives reports and warm starts what they need to resume a stream. Switching the GBM scenario feed to resume from a stored state plus the last price is a separate change to the feed's API, and I've kept it out of this PR so it stays limited to the issue's five steps. I can open a follow-up if you want it.Test plan
pnpm lint && pnpm typecheck && pnpm testinpackages/strategies: lint/typecheck clean, 36 files / 714 tests passrng.test.ts:42nis unchangedreport.test.ts:restoreGenerators) gives exactly the holdings, total value and generator states of an uninterrupted T0→T3 run.mergeReportsnow refuses it"18364758544493064721"UnknownReportVersionErrorpnpm turbo run typecheck build --filter='!@meridian/contracts'passes.@meridian/contracts#buildfails the same way onmainlocally because I don't have the Soroban toolchain.apitests: 80/80 pass when run on their own, on bothmainand this branch. Under the combined turbotestrun,@meridian/api#testfailed for me with no Upstash/Redis env set. I haven't rerun the combined turbo run onmain, but this PR doesn't touchapi.Closes #1018
🤖 Generated with Claude Code