fix: return digest from attestation state save for OCC support#2909
Merged
migmartri merged 5 commits intoMar 21, 2026
Merged
Conversation
The remote state manager was not receiving the digest of newly saved attestation state, causing subsequent writes during the same initialization to fail with OCC conflict errors. Fixes chainloop-dev#2908 Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
migmartri
commented
Mar 21, 2026
| type AttestationStateRepo interface { | ||
| Initialized(ctx context.Context, workflowRunID uuid.UUID) (bool, error) | ||
| Save(ctx context.Context, workflowRunID uuid.UUID, state []byte, baseDigest string) error | ||
| Save(ctx context.Context, workflowRunID uuid.UUID, state []byte, baseDigest string) (string, error) |
Member
Author
There was a problem hiding this comment.
this is the intersting bit
| } | ||
|
|
||
| // Update the checksum so subsequent writes use the correct base digest | ||
| state.UpdateCheckSum = resp.GetDigest() |
Member
Author
There was a problem hiding this comment.
and this is the key, now the local state after writing has the updated checksum so it doesn't need to load it again
Servers that don't return digests in Save responses leave the client with a stale UpdateCheckSum. Reloading state after all collectors run ensures the local digest matches the server, preventing OCC conflicts on subsequent writes. Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
Compare the digest before and after collectors run. If it changed, writes happened and the local checksum may be stale, so reload from the server. If unchanged, no writes occurred and reload is skipped. Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
migmartri
commented
Mar 21, 2026
| // Reload state if collectors modified it and the local digest may be stale. | ||
| // When the digest changed, writes happened but we can't be sure the checksum | ||
| // reflects the true server-side state (e.g. old servers don't return digests). | ||
| if c.CraftingState.UpdateCheckSum != digestBeforeCollectors { |
Member
Author
There was a problem hiding this comment.
@jiparis technically the problem could be fixed by just adding this code. But I've added a better mechanism for new servers that refresh the just updated digest.
Returning and updating the digest also fixes the problem, but only for new servers
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
Old servers don't return digests in Save responses. Guard against overwriting a valid checksum with an empty string, which would break OCC protection on subsequent writes. Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
jiparis
approved these changes
Mar 21, 2026
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
AttestationStateServiceSaveResponseso the remote state manager can track the current server-side stateFixes #2908