You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1f0337f
Browse filesBrowse the repository at this point in the historyBrowse files
function_storage: add unified state_* API alongside existing methods (Turn 1)
This is Turn 1 of a 5-turn refactor to collapse 4 RMW method families
(worker_*, stream_state_*, aggregate_state_*, aggregate_window_partition_*)
plus transaction_state_* into one composite-key state_* API. The new API
takes (scope_id: bytes, ns: bytes, key: bytes) so callers — not the
storage — pick the namespace.
Turn 1 introduces the new methods alongside the old ones; nothing
existing is removed, no callers are migrated. Subsequent turns migrate
fixtures (Turn 2-3), extend to cloud backends (Turn 4), and delete
the deprecated families (Turn 5).
API surface added:
- state_get_many(scope, ns, keys) -> list[bytes | None]
- state_put_many(scope, ns, items) — atomic per-call
- state_scan(scope, ns) — non-destructive
- state_drain(scope, ns) — atomic scan-and-tombstone
- state_delete(scope, ns, keys=None) — naturally idempotent
- execution_clear(scope) — wipes all namespaces + future log table
- BoundStorage facade wrappers (state_get/put singular convenience,
state_scan/drain/delete pass-through, pack_int_key sugar)
New tables:
- function_state(scope_id, ns, key, value, last_attempt_id, drained_at,
drained_by_attempt, created_at)
- function_state_log(id AUTOINCREMENT, scope_id, ns, key, value,
attempt_id, created_at) — used in Turn 6 (state_append)
Idempotency: SQLite generates an internal attempt_id per call (mirrors
the CfDo HTTP retry-resume pattern). Replay-detection on state_put_many
checks last_attempt_id of the first item; replay-detection on state_drain
checks drained_by_attempt and returns the prior tombstoned values.
state_delete and execution_clear are naturally idempotent.
cleanup_old_entries now sweeps function_state and function_state_log past
the retention horizon (matches existing per-table behavior).
Tests: 17 new unit tests covering put/get/scan/drain/delete/clear
roundtrip, namespace isolation, scope isolation, non-destructive scan,
empty-input edge cases, facade wrappers, pack_int_key encoding. All 31
tests pass (14 existing + 17 new).
Verified the C++ integration suite (vgi/test/sql/integration/*) still
passes — 152 tests green, semantic of existing fixtures unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments