Skip to content

feat(statestore): the deployment state store moves to the contract, where core may import it (D-LAW-3) - #495

Open
aitrawog wants to merge 2 commits into
mainfrom
feat/statestore
Open

aitrawog wants to merge 2 commits into
mainfrom
feat/statestore

Conversation

@aitrawog

@aitrawog aitrawog commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

spec/statestore is sdk/statekit (opencharly/sdk#683) relocated to the contract module, unchanged except for its package name and its root resolver. It is the one store for a deployment's realized state (D-DEP-5), plus the host's get/put/state_commit serving for the state row, permitted only for the caller that owns the deployment's kind (D-PROTO-12). It is part of B3 of the DESIGN §8.3 bind/realize program (#370).

Why it moves. charly core is the host that serves those RPCs, and charly's import-purity gate forbids core to import any sdk mechanism kit: "charly/ core imports spec/* + proto only". The B3 host change imported sdk/statekit, and claude-default-volume-design measured that gate failing on the combined D-PUB tree (opencharly/opencharly#1390, #issuecomment-7353290996). spec/needsolver lives here for exactly this reason. Its doc says: "It lives in spec for the same reason storeroot does: it is one implementation of a cross-cutting concern that the HOST must perform … and charly/ core may import spec/* only". DESIGN's D-LAW-3 says core "reads, links, validates, routes, solves and stores".

What changes:

  • storekit.Dir(storekit.RootState) becomes storeroot.Dir(storeroot.RootState), the resolver storekit re-exports (D-STORE-1), so the state root is the same tree.
  • The package doc gains the placement paragraph.
  • sdk/statekit is deleted in the sdk cutover that follows this tag (C6). Nothing imports it: plugins reach state over the RPC, never the package.

Coordination: this unblocks the charly B3 change, which rides claude-default-volume-design's D-PUB charly bump (CLEARED (A) on opencharly/opencharly#1390). HOLDING follows here, and the matching WAITING on #1390.

Files

File Change
statestore/statestore.go new: Store (Open, OpenDefault, Dir, Get, Put, Revision, Commit), Digest, ErrNotFound/ErrStaleRevision/ErrInvalidKey; ported from sdk/statekit/statekit.go
statestore/host.go new: Scope (OwnsKind), Store.ServeGet/ServePut/ServeStateCommit; ported from sdk/statekit/host.go
statestore/statestore_test.go new: round trip, whole-set commit, stale refusal, first commit, the concurrency proof, key safety, OpenDefault/Dir under the state root
statestore/host_test.go new: permitted round trip incl. a stale commit, denial outside the caller's kind, the unserved rows, an empty record as a present arm

How tested

# head 025145e2c73b286be84242dc832a2c7c4daf34bc (git rev-parse HEAD)
$ git rev-parse origin/main
997fd2d2b8cbf6a7d1090e35274e6d0eaecb7f3e
$ git log --oneline origin/main..HEAD
025145e feat(statestore): the deployment state store moves to the contract, where core may import it (D-LAW-3)
$ git diff --stat origin/main...HEAD
 statestore/host.go            | 138 +++++++++++++++++++
 statestore/host_test.go       | 132 ++++++++++++++++++
 statestore/statestore.go      | 302 ++++++++++++++++++++++++++++++++++++++++++
 statestore/statestore_test.go | 174 ++++++++++++++++++++++++
 4 files changed, 746 insertions(+)
$ charly task cue-gen ; git status --short | wc -l
task cue-gen: 2 step(s), 0 failed, 0 skipped
0
$ go build ./... && go vet ./... ; echo rc=$?
rc=0
$ gofmt -l .   (empty)
$ go test ./... (summary)
go test rc=0
packages ok: 36
$ go test -race -count=1 ./statestore/ -v
--- PASS: TestServeStateRoundTripUnderAPermittingScope (0.00s)
--- PASS: TestStateIsDeniedOutsideTheCallersKind (0.00s)
--- PASS: TestTheUnservedRowsAnswerUnimplementedNamingTheirIssue (0.00s)
--- PASS: TestAnEmptyStateRecordIsServedAsAPresentArm (0.00s)
--- PASS: TestPutThenGetRoundTrips (0.00s)
--- PASS: TestCommitReplacesTheWholeSetAndRefusesAStaleRevision (0.00s)
--- PASS: TestAFirstCommitNamesTheEmptySetRevision (0.00s)
--- PASS: TestConcurrentCommitsOnOneRevisionAdmitExactlyOne (0.30s)
--- PASS: TestKeysThatAreNotPlainSegmentsAreRefused (0.00s)
--- PASS: TestOpenDefaultLivesUnderTheStateRoot (0.00s)
ok  	github.com/opencharly/spec/statestore	1.315s
$ golangci-lint run ./...   (v2.13.2, GOTOOLCHAIN=go1.26.0)
0 issues.
$ git grep -nE '^[[:space:]]*disposable:' -- '*.yml' '*.yaml' ; echo rc=$?
rc=1

C8, mutations on this head (each restored; the final git status --short | wc -l is 0):

--- (1) the lock: Commit without its identity lock, 20 runs, then 20 with it restored
lock removed: 19 of 20 runs FAIL
lock restored: 0 of 20 runs fail (20 of 20 pass)
--- (2) the permission rule: permits() returns true for every scope
mutated lines: 1
    host_test.go:79: no scope: get code NotFound (rpc error: code = NotFound desc = state: no such record: openwebui/binding), want PermissionDenied
    host_test.go:82: no scope: put code OK (<nil>), want PermissionDenied
    host_test.go:85: no scope: commit code Aborted (rpc error: code = Aborted desc = state: stale revision: openwebui holds sha256:46e329cd7527a98a8e619607840a84cbde9cc73
    host_test.go:79: another deployment's kind: get code OK (<nil>), want PermissionDenied
--- restored
ok  	github.com/opencharly/spec/statestore	0.003s
0

The umbrella design controls, run on this head by pointing my session umbrella worktree's spec index entry at it (restored afterwards), against spec origin/main:

BASE spec=997fd2d2b8cbf6a7d1090e35274e6d0eaecb7f3e dpat-rc=1 cite-rc=1
NEW spec=025145e2c73b286be84242dc832a2c7c4daf34bc dpat-rc=1 cite-rc=1
index restored to 72484f63e961c4d1ea36206aa5c163fec8fbbd3c
dpat: no new finding
cite: no new finding

Both controls are red on spec main itself (opencharly/opencharly#1410). This change adds no finding to either.

Spike

RCA claim: charly core imported an sdk mechanism kit (sdk/statekit) to serve the host store RPCs. The host's import surface is spec/* + proto only, so the store core uses must live in the contract.

Candidates spiked (on the real instrument: charly's own TestImportPurity_HostImportsOnlySpecAndVettedThirdParty and TestNoSinglePluginAPISurface, in a scratch copy of the charly module on spec 1600 + sdk b36531c). In that copy, the compiled-in plugin registrations are stubbed, and the D-PUB test files that don't compile on the new spec yet are removed; both gate files are kept.

  1. Declare a residual import site (residualSDKImportSites). Rejected by the gate's own rule: a row is for "a relocated mechanism's residual call sites" with "an until-K exit", and "an entry without a named exit is a boundary-law violation rather than debt". A new import is not residual and has no exit.
  2. Move the store into spec (this PR). Before, with B3 as first posted:
--- BEFORE (B3 as posted: imports sdk/statekit; F11 allowlist unchanged)
    import_purity_test.go:220: IMPORT-PURITY gate: 1 UNDECLARED github.com/opencharly/sdk import(s) in charly/ core — a residual call site must be declared in residualSDKImportSites with a named exit:
    import_purity_test.go:235: IMPORT-PURITY inventory: residualSDKImportSites declares "plugin_build_testhelper_test.go", but the walk found no github.com/opencharly/sdk import there — the row is doi
    import_purity_test.go:239: IMPORT-PURITY debt (tracked, with named exits): 2 residual sdk import(s):
    uniform_api_gate_test.go:82: ExecutorService: unexpected RPC method "Get" — a new reverse RPC must be added to the F11 allowlist CONSCIOUSLY (and must be class-generic, never named after one plugi
    uniform_api_gate_test.go:82: ExecutorService: unexpected RPC method "StateCommit" — a new reverse RPC must be added to the F11 allowlist CONSCIOUSLY (and must be class-generic, never named after o
    uniform_api_gate_test.go:82: ExecutorService: unexpected RPC method "Put" — a new reverse RPC must be added to the F11 allowlist CONSCIOUSLY (and must be class-generic, never named after one plugi
FAIL
FAIL	github.com/opencharly/charly/charly	0.011s
FAIL

After, with B3 importing spec/statestore from this head and the F11 allowlist carrying the three methods:

--- AFTER (candidate 2: spec/statestore at spec 025145e2c73b286be84242dc832a2c7c4daf34bc; F11 allowlist carries Get/Put/StateCommit; the scratch-pruned residual-row file restored)
    import_purity_test.go:239: IMPORT-PURITY debt (tracked, with named exits): 3 residual sdk import(s):
--- PASS: TestImportPurity_HostImportsOnlySpecAndVettedThirdParty (0.02s)
--- PASS: TestDeploymentScopeOwnsOnlyItsKindsProvider (0.00s)
--- PASS: TestHostStateIsServedOnlyToTheOwningProvider (0.00s)
--- PASS: TestDeploymentScopeRidesTheOutOfProcessCtx (0.00s)
--- PASS: TestNoSinglePluginAPISurface (0.00s)
ok  	github.com/opencharly/charly/charly	1.109s

Works. The import_purity_test.go:235 line in "before" is a scratch artifact (a test file I had pruned). It is gone in "after", where that file is restored.
3. Copy the store into charly core. It would duplicate the store, so it's rejected under C4 without a spike.

Winner: (2). It is the needsolver/storeroot precedent, and the only candidate that passes the gate without inventing debt.

RCA verdict: confirmed. The gate passes with (2).

Rulebook compliance

Plan conformance

Winning candidate: (2) move the store into spec.

Planned change DESIGN requirement Disposition
the state store in the contract module, importable by core D-LAW-3 conforms — "Core is a plugin host. It reads, links, validates, routes, solves and stores."
records under the state root via storeroot D-DEP-5 conforms — "Realized state (resolved ports and images, bindings, leases, reverse records, the kind's own records) lives in the state root (§20), written through put with a state key."
the root from the ONE resolver D-STORE-1 conforms — "The roots, resolved by ONE resolver on the contract surface — spec/storeroot, so the plugin host and every plugin it serves resolve the same trees from the same code"
host get/put/state_commit served for the state row, refused outside the caller's kind D-PROTO-12, DESIGN §4.6 store table conforms — the §4.6 state row's "Permitted when" column: "the caller's plugin owns that deployment's kind"; a refusal is the table's denied
content/secret/config rows refused as unimplemented DESIGN §4.6 store table debt filed #1362 — those rows have no server-side store yet; this change refuses them explicitly and widens no gap
  • C0: loaded charly-internals:git-workflow, strict-policy, design, go, plugin and charly-check:check, and read spec's AGENTS.md.
  • C1: the B3 host change imported an sdk kit into core, and the import-purity gate caught it on the peer's combined tree. The missed control was mine: my scratch proof pruned test files that didn't compile on the new spec, the two architecture gates among them. The spike above keeps both gates. No warning is left.
  • C2: see the Spike block.
  • C3: see the map; no DESIGN.*/design/ file is touched.
  • C4: one store. sdk/statekit is deleted in the sdk cutover after this tag, never kept beside it.
  • C5: no workaround. The gate is satisfied by placement, not by declaring an exception.
  • C6: the sdk copy is deleted in the next cutover (nothing imports it). This PR is the producer leg.
  • C7: no documented command surface changes.
  • C8: the lock and permission mutations above, plus the two gates in the Spike.
  • C9: N/A — no live-service boundary; the store is a local directory under the test's own root.
  • C10: N/A — a contract module proven by its own suite.
  • C11: the module gate passes on the committed head.
  • C12: a session worktree off fresh origin/main; one content commit plus one empty re-trigger commit, no force-push, no hook bypass.

Change classification

  • Change class: contract / library module (spec). No disposable target exists: git grep -nE '^[[:space:]]*disposable:' -- '*.yml' '*.yaml' → rc=1.
  • Gate: the repo's own CI: go build ./..., go vet ./..., gofmt, golangci-lint (v2.13.2) and go test ./..., plus charly task cue-gen as a no-op. All are green on 025145e2c73b286be84242dc832a2c7c4daf34bc. The PR head b56270b8a5206cd61e74035a7123da13c4a319ec is one empty re-trigger commit on top, so the tree is identical (git diff --stat 025145e2c73b286be84242dc832a2c7c4daf34bc b56270b8a5206cd61e74035a7123da13c4a319ec is empty). The PR was opened at 17:31Z, inside GitHub's Actions incident (from 16:26Z), and no run was created for it; the required gate fires only on a push.
  • Tier: fully tested and validated. Every exported identifier is called by a test: Open (through open), OpenDefault and Dir (TestOpenDefaultLivesUnderTheStateRoot), Get/Put/Revision/Commit/Digest, the three error values, Scope and the three Serve* methods. The lock and the permission rule are each shown load-bearing by a mutation, and the package runs under the race detector.
  • Breaking change + rollback: none — a new package; no existing identifier changes. Rollback is reverting the commit.
  • Authoring runtime: Claude Code, model ID claude-opus-5-5 (Anthropic Claude Opus 5.5).

Filed issues

Agent: comfyui-0471 · Claude Code session 724dd7fe-cee8-48d9-9af4-7f630d2bc046
Assisted-by: Claude Code Anthropic Claude Opus 5.5 (fully tested and validated)

…here core may import it (D-LAW-3)

spec/statestore is sdk/statekit (opencharly/sdk#683) relocated: the ONE store for a deployment's
realized state (D-DEP-5) and the host's get/put/state_commit serving for the `state` row, permitted
only for the caller that owns the deployment's kind (D-PROTO-12).

It moves because the HOST serves those RPCs and charly/ core may import spec/* only, never an sdk
mechanism kit (charly's import-purity gate) — the same reason needsolver and storeroot live here.
The state root comes from storeroot.Dir(storeroot.RootState), the resolver storekit re-exports.
sdk/statekit is deleted in the sdk cutover that follows; nothing imports it.

Relates to #370.

Agent: comfyui-0471 · Claude Code session 724dd7fe-cee8-48d9-9af4-7f630d2bc046
Assisted-by: Claude Code Anthropic Claude Opus 5.5 (fully tested and validated)
@aitrawog

aitrawog commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

HOLDING

HOLDING — #495 (blocking side) holds the charly B3 host-store change (blocked side).

That change is coordinated on opencharly/opencharly#1390 and rides claude-default-volume-design's D-PUB charly bump. Core must import the store from spec/statestore: charly's import-purity gate refuses sdk/statekit. So B3 needs this PR's tag. Both sides are owned by comfyui-0471.

Agent: comfyui-0471 · Claude Code session 724dd7fe-cee8-48d9-9af4-7f630d2bc046
Assisted-by: Claude Code Anthropic Claude Opus 5.5 (fully tested and validated)

…d during the Actions outage, which created no run)

Agent: comfyui-0471 · Claude Code session 724dd7fe-cee8-48d9-9af4-7f630d2bc046
Assisted-by: Claude Code Anthropic Claude Opus 5.5 (fully tested and validated)
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.

1 participant