fix(devshard): let a node replay its own pre-floor diffs on startup - #1595
Open
qdanik wants to merge 2 commits into
Open
fix(devshard): let a node replay its own pre-floor diffs on startup#1595qdanik wants to merge 2 commits into
qdanik wants to merge 2 commits into
Conversation
…m, so a node whose history predates the max_tokens floor can start
a-kuprin
reviewed
Aug 16, 2026
a-kuprin
reviewed
Aug 16, 2026
|
|
||
| // ApplyPersisted replays a diff this node already accepted. A diff is part of a recorded state root, | ||
| // so a rule that tightened since it was written cannot undo it by refusing it, only fail to start. | ||
| func (sm *StateMachine) ApplyPersisted(nonce uint64, txs []*types.DevshardTx) ([]byte, error) { |
Collaborator
There was a problem hiding this comment.
I would better name it ApplyLocalPersisted to keep some mental link with ApplyLocal
and keep the comment from ApplyLocal:
// ApplyLocal applies txs without signature verification. Used by the user
// to compute the post_state_root before signing the diff.
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.
Problem
enforce inference tokens floor (#1391)added aMinTokensFloorcheck toapplyStartInference. That check also runs on replay, so a node that served inferences before the floor landed cannot restart — it re-runs a rule written after its own diffs were made:Refusing the diff undoes nothing. It is already part of a recorded state root; the refusal only keeps the node down.
Fix
Separate authoring new work from replaying work already accepted.
state.ApplyPersistedsetsreplayingPersistedunder the same mutex as the apply and clears it viadeferuser/recover.go(gateway) andcmd/devshardd/session/manager.go(host daemon)Exactly one check is relaxed, and only the one guarding creation of new work. Live traffic still has to meet the floor.
Tests
TestApplyPersisted_ReplaysAStartWrittenBeforeTheFloorstateTestRecoverSession_ReplaysADiffWrittenBeforeTheMaxTokensFlooruserTestRecoverSessions_ReplaysADiffWrittenBeforeTheMaxTokensFloorcmd/devshardd/sessionEach fixture asserts
ApplyLocalstill rejects the diff before seeding it, so the test cannot silently stop reproducing the failure.Mutation-tested — 4/4 killed, each verified to compile first: floor ignores the replay flag; flag never cleared; each replay site reverted to
ApplyLocal.state,userandcmd/devshardd/sessionpass in full.