Skip to content

feat(state): scoped state serializer preserving sibling components on concurrent writes - #508

Merged
joshua-temple merged 2 commits into
mainfrom
feat/scoped-state
Jul 8, 2026
Merged

joshua-temple merged 2 commits into
mainfrom
feat/scoped-state

Conversation

@joshua-temple

Copy link
Copy Markdown
Collaborator

Problem

Multi-component state must let each component's finalizer write its own (component, env) state without dropping a sibling component's state under concurrency. Today the whole state node is replaced from a typed map, so a writer that does not model a sibling would erase it.

Fix

  • Add WriteScopedState: node-patches only the addressed (component, env) leaf (state.components.<name>.<env>, a full EnvState) and preserves every sibling subtree as a verbatim YAML node. On a 409, CommitWithRetry re-applies against re-fetched bytes and the node-disjoint leaf write gives sibling survival.
  • Reimplement WriteManifestState as a delete-aware single-component wrapper: reconcile to the map (patch present keys, emit an explicit node delete for keys present in the fetched bytes but absent from the map, plus latest_release when nil). This keeps the publish transition dropping the prerelease marker and single-component output byte-identical.
  • Widen the reserved ComponentState to the full EnvState the lifecycle needs.

Single-component behavior is byte-identical. Per-component workflow generation and the release shape land in #283.

Verification

go build ./..., go test ./... (2554 pass), go test ./... -race (2554 pass), golangci-lint run ./... clean. A publish-delete byte-identical test fails against a naive patch-only wrapper and passes with the delete-aware one; a concurrent two-component finalize test asserts neither loses state.

Refs #282.

… concurrent writes

Add WriteScopedState, which node-patches only the addressed (component, env) leaf and preserves every sibling subtree as a verbatim YAML node, so a concurrent finalizer cannot drop another component's state. Reimplement WriteManifestState as a delete-aware single-component wrapper (reconcile to the map: patch present keys, delete keys present in the fetched bytes but absent from the map) so the publish transition still drops the prerelease marker and single-component output stays byte-identical. Widen the reserved ComponentState to the full EnvState the lifecycle needs.

Refs #282.

Signed-off-by: Joshua Temple <joshua.temple@stablekernel.com>
Comment thread internal/config/statemerge.go Fixed
…State

CodeQL go/allocation-size-overflow flagged the len(state)+1 make capacity. The delete loop and latest write append past that hint regardless, so size the slice to len(state) and drop the arithmetic.

Signed-off-by: Joshua Temple <joshua.temple@stablekernel.com>
@joshua-temple
joshua-temple merged commit 191948e into main Jul 8, 2026
20 checks passed
@joshua-temple
joshua-temple deleted the feat/scoped-state branch July 8, 2026 02:46
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.

2 participants