Repository navigation
[release/0.24] Backport #142: Add SQLite state store - #152
Merged
Karol Zadora-Przylecki (karolz-ms) merged 1 commit intoMay 14, 2026
Merged
Conversation
* Add SQLite state store for persistent resources Add a local SQLite-backed state store for persistent process metadata and cross-instance resource leases. Wire the store into controller startup and persistent executable/container/network coordination, and manage schema updates through embedded golang-migrate migrations with compatibility authoring guidance.\n\nCo-authored-by: Copilot <[email protected]> * Improve persistent executable lifecycle handling Co-authored-by: Copilot <[email protected]> * Preserve process identity times in state store Co-authored-by: Copilot <[email protected]> * Update dependency notices Co-authored-by: Copilot <[email protected]> * Use structured executable lifecycle key hashing Co-authored-by: Copilot <[email protected]> * Simplify container startup retry handling Co-authored-by: Copilot <[email protected]> * Refactor container startup orchestration Co-authored-by: Copilot <[email protected]> * Handle persistent executable adoption before start gating Co-authored-by: Copilot <[email protected]> * Simplify resource lease persistence Remove persisted lease expiration state and use updated-at only for leaseholder revalidation. Also make SQLite file DSNs compatible with Windows drive-letter paths. Co-authored-by: Copilot <[email protected]> * Require leasable resources for resource leases Add a GetLeaseKey interface for resource lease operations and implement it on Container and ContainerNetwork. Remove the redundant statestore key helpers and normalize touched file headers. Co-authored-by: Copilot <[email protected]> * Clarify persistence API documentation Describe persistent executable API and state-store behavior at a high level instead of copying source declarations into docs. Co-authored-by: Copilot <[email protected]> * Describe executable persistence as feature docs Remove branch-oriented change wording so the documentation describes executable persistence as stable behavior. Co-authored-by: Copilot <[email protected]> * Use resource leases for persistent executables Coordinate persistent Executable reconciliation through resource leases, use Executable.GetLeaseKey for process records, and add interface guards for leasable API resources. Co-authored-by: Copilot <[email protected]> * Extract executable persistence helpers Co-authored-by: Copilot <[email protected]> * Clarify resource lease contention logs Co-authored-by: Copilot <[email protected]> * Preserve reusable persistent executable records Co-authored-by: Copilot <[email protected]> * Configure state store WAL checkpointing Co-authored-by: Copilot <[email protected]> * Use executable spec lifecycle keys for persistence Co-authored-by: Copilot <[email protected]> * Require lease ownership on release Co-authored-by: Copilot <[email protected]> * Use effective executable lifecycle inputs Co-authored-by: Copilot <[email protected]> * Store process PID for adopted runs Co-authored-by: Copilot <[email protected]> * Guard persistent container setup with leases Co-authored-by: Copilot <[email protected]> * Flush shutdown response before stopping apiserver Co-authored-by: Copilot <[email protected]> * Gate persistent container startup with leases Co-authored-by: Copilot <[email protected]> * Close state store migration runner Co-authored-by: Copilot <[email protected]> * Align persistent executable lease handling Co-authored-by: Copilot <[email protected]> * Fix persistent container lease retries Co-authored-by: Copilot <[email protected]> * Format process identity values safely Co-authored-by: Copilot <[email protected]> * Harden persistent resource cleanup Treat persistent network lease configuration failures as terminal startup errors instead of retrying indefinitely, and close process run output files when persistent runs are released. Co-authored-by: Copilot <[email protected]> * Simplify state store file setup Remove the point-in-time SQLite file restriction pass and let SQLite own database and sidecar file creation. The state store now only ensures the parent directory exists before opening the database. Co-authored-by: Copilot <[email protected]> * Trim persistent state metadata Remove unused metadata from resource leases and persistent process records while this schema is still in draft. Persistent process records now keep only durable process state, and lifecycle diagnostics sort changed executable environment names for stable logs. Co-authored-by: Copilot <[email protected]> * Clarify lease owner identity logging Rename the lease contention log field from LeaseOwnerStartTime to LeaseOwnerIdentityTime because the value is a process identity discriminator and is not necessarily a wall-clock start time. Co-authored-by: Copilot <[email protected]> * Persist executable output files Co-authored-by: Copilot <[email protected]> * Skip timestamp pipe for persistent output Co-authored-by: Copilot <[email protected]> * Release persistent container lease after reuse Co-authored-by: Copilot <[email protected]> * Harden persistent output directory setup Co-authored-by: Copilot <[email protected]> * Format io platform files Co-authored-by: Copilot <[email protected]> * Simplify persistent process PID check Co-authored-by: Copilot <[email protected]> * Release persistent executable leases on stable states Co-authored-by: Copilot <[email protected]> * Use process abstraction for executable stop Co-authored-by: Copilot <[email protected]> * Release persistent resource leases on stable states Co-authored-by: Copilot <[email protected]> * Validate restricted directory owners on Windows Co-authored-by: Copilot <[email protected]> * Release executable leases for unknown state Co-authored-by: Copilot <[email protected]> * Add lifecycle-bound persistent monitors Co-authored-by: Copilot <[email protected]> * Fix restricted directory test on Windows Co-authored-by: Copilot <[email protected]> * Validate monitor timestamp in dcpproc helper Co-authored-by: Copilot <[email protected]> * Remove duplicate executable display start time Co-authored-by: Copilot <[email protected]> * Refine persistent lease release handling Co-authored-by: Copilot <[email protected]> * Respect state store migration busy timeout Co-authored-by: Copilot <[email protected]> * Use test contexts in lease tests Co-authored-by: Copilot <[email protected]> * Move persistent lease coverage to integration tests Co-authored-by: Copilot <[email protected]> * Remove unused container lease helper Co-authored-by: Copilot <[email protected]> * Return lifecycle env file read errors Co-authored-by: Copilot <[email protected]> * Use computed executable lease owner in tests Co-authored-by: Copilot <[email protected]> * Avoid chmodding explicit state store parents Co-authored-by: Copilot <[email protected]> * Use restricted integration state store dirs Co-authored-by: Copilot <[email protected]> * Guard adopted process watcher cleanup Co-authored-by: Copilot <[email protected]> * Validate restricted directory ACLs on Windows Co-authored-by: Copilot <[email protected]> * Secure statestore test directories on Windows Co-authored-by: Copilot <[email protected]> * Clean invalid persistent executable records on startup Co-authored-by: Copilot <[email protected]> * Reject deny ACEs in restricted directory validation Co-authored-by: Copilot <[email protected]> * Relax Windows restricted directory validation Co-authored-by: Copilot <[email protected]> * Separate elevated state store directory Co-authored-by: Copilot <[email protected]> * Rename comparable sync map Co-authored-by: Copilot <[email protected]> * Run invalid persistent cleanup asynchronously Co-authored-by: Copilot <[email protected]> * Simplify persistent cleanup lease skip Co-authored-by: Copilot <[email protected]> * Reload persistent record before cleanup Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Backports the SQLite-backed local state store and persistent Executable/process coordination features from #142 into the release/0.24 branch.
Changes:
- Introduces
internal/statestore(SQLite DB, migrations, resource leases, persistent process records) and wires it into controllers and test environments. - Adds persistent Executable support improvements (lifecycle monitoring, run adoption/release, process identity time) and additional integration/unit tests.
- Adds cross-platform “restricted directory” helpers and associated tests to securely create/validate directories for state/log storage.
Reviewed changes
Copilot reviewed 83 out of 89 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/integration/test_env_common.go | Adds helper to create/cleanup an isolated state store for integration tests. |
| test/integration/standard_test_env.go | Wires state store + lease owner into standard integration environment and controller configs. |
| test/integration/service_controller_test_not_darwin.go | Fixes build tag placement / header cleanup. |
| test/integration/network_controller_test.go | Waits for persistent network resource lease release in test. |
| test/integration/executable_controller_test.go | Adds integration tests for persistent Executable start delay and record-update failure behavior. |
| test/integration/controllers_common_test.go | Adds shared helper to wait for resource lease release via state store. |
| test/integration/container_controller_test.go | Waits for persistent container resource lease release in test. |
| test/integration/advanced_test_env.go | Wires state store + lease owner into advanced integration environment. |
| pkg/syncmap/syncmap_test.go | Adds unit test for new ComparableValueMap CompareAndDelete behavior. |
| pkg/syncmap/syncmap.go | Adds ComparableValueMap wrapper exposing sync.Map.CompareAndDelete. |
| pkg/security/certstore_windows_test.go | Fixes build tag placement / header cleanup. |
| pkg/security/certstore_windows.go | Header cleanup. |
| pkg/security/certstore_notwindows_test.go | Fixes build tag placement / header cleanup. |
| pkg/security/certstore_notwindows.go | Fixes build tag placement / header cleanup. |
| pkg/process/process_windows_test.go | Fixes build tag placement / header cleanup. |
| pkg/process/process_util_windows.go | Fixes build tag placement / header cleanup. |
| pkg/process/process_util_unix.go | Fixes build tag placement / header cleanup. |
| pkg/process/process_util_other.go | Adds identity-time formatting helper for non-Linux. |
| pkg/process/process_util_linux_test.go | Adds unit test for Linux identity-time formatting. |
| pkg/process/process_util_linux.go | Adds Linux identity-time formatting helper and imports fmt. |
| pkg/process/process_util.go | Adds exported FormatIdentityTime wrapper. |
| pkg/process/process_unix_test.go | Fixes build tag placement / header cleanup. |
| pkg/process/os_executor_windows.go | Fixes build tag placement / header cleanup. |
| pkg/process/os_executor_unix.go | Fixes build tag placement / header cleanup. |
| pkg/osutil/osutil_windows.go | Fixes build tag placement / header cleanup. |
| pkg/osutil/osutil_unix.go | Fixes build tag placement / header cleanup. |
| pkg/io/restricted_directory_windows_test.go | Adds Windows tests validating DACL-based restricted directory behavior. |
| pkg/io/restricted_directory_windows.go | Implements Windows restricted directory owner + DACL restriction/validation. |
| pkg/io/restricted_directory_unix.go | Implements Unix restricted directory owner + mode restriction/validation. |
| pkg/io/restricted_directory_test.go | Adds cross-platform tests (incl. symlink rejection, chmod-only path). |
| pkg/io/restricted_directory.go | Adds EnsureRestrictedDirectory / ValidateRestrictedDirectory API. |
| pkg/io/file_windows.go | Build tag/header cleanup and minor comment wording. |
| pkg/io/file_unix.go | Fixes build tag placement / header cleanup. |
| pkg/generated/openapi/zz_generated.openapi.go | Regenerates OpenAPI schema for new spec fields (monitor fields, start/persistent/lifecycleKey). |
| internal/testutil/ctrlutil/test_process_executable_runner.go | Adds persistent runner adoption APIs + test hook + ReleaseRun delegation. |
| internal/testutil/ctrlutil/test_ide_runner.go | Adds ReleaseRun support for IDE test runner. |
| internal/testutil/ctrlutil/apiserver_start.go | Sets DCP_STATE_STORE_PATH for spawned API server process in test env. |
| internal/statestore/store.go | Adds SQLite store open/config/migrate, secure dir setup, helpers. |
| internal/statestore/schema.go | Adds embedded migrations + migration locking + legacy table cleanup. |
| internal/statestore/processes.go | Adds persistent process CRUD for adoption/cleanup. |
| internal/statestore/migrations/README.md | Documents migration authoring/compatibility rules. |
| internal/statestore/migrations/000001_initial.up.sql | Adds initial schema (resource_locks, persistent_processes). |
| internal/statestore/leases.go | Adds resource lease acquisition/verification/release/cleanup logic. |
| internal/statestore/lease_owner.go | Adds current lease owner identity + normalization helpers. |
| internal/proxy/network_stream_windows.go | Fixes build tag placement / header cleanup. |
| internal/proxy/network_stream_unix.go | Fixes build tag placement / header cleanup. |
| internal/networking/networking_windows.go | Fixes build tag placement / header cleanup. |
| internal/networking/networking_linux.go | Fixes build tag placement / header cleanup. |
| internal/networking/networking_darwin.go | Fixes build tag placement / header cleanup. |
| internal/lockfile/lockfile_windows.go | Fixes build tag placement / header cleanup. |
| internal/lockfile/lockfile_unix.go | Fixes build tag placement / header cleanup. |
| internal/exerunners/process_executable_runner_test.go | Adds tests for persistent output, monitor behavior, adopt/stop/release behavior. |
| internal/exerunners/process_executable_runner.go | Adds persistent runner functionality (output dir, adopt/release, monitor scoping, pid identity). |
| internal/exerunners/ide_executable_runner.go | Implements ReleaseRun to drop run tracking without stopping. |
| internal/dcpproc/dcpproc_api_test.go | Adds tests for MonitorTargetFromFields + monitor-scoped watcher helpers. |
| internal/dcpproc/dcpproc_api.go | Adds monitor-target parsing and monitor-scoped watcher helpers. |
| internal/dcpctrl/commands/run_controllers.go | Opens state store in controller process, cleans inactive leases, starts persistent record cleanup, passes store into reconcilers. |
| internal/dcpctrl/commands/persistent_process_cleanup_test.go | Adds tests for async cleanup and record deletion behavior. |
| internal/dcpctrl/commands/persistent_process_cleanup.go | Adds cleanup job for invalid persistent process records (with leases). |
| internal/apiserver/admin_http_handler.go | Flushes response before triggering shutdown. |
| hack/boilerplate.go.txt | Updates Go boilerplate header text. |
| go.sum | Adds checksums for migrate/sqlite and transitive deps. |
| go.mod | Adds golang-migrate and modernc SQLite deps. |
| doc/executable-persistence-api.md | Adds documentation for new Executable persistence and state store behavior. |
| controllers/service_controller_metrics.go | Normalizes formatting (removes stray CRLF/indent issues). |
| controllers/resource_lease_logging.go | Adds helper logging for held/not-held lease scenarios. |
| controllers/network_controller.go | Adds persistent network lease coordination using state store. |
| controllers/executable_start_result.go | Adds process identity time to runner result and propagates it. |
| controllers/executable_runner.go | Extends runner API with ReleaseRun + persistent adoption interface. |
| controllers/executable_run_info.go | Stores process identity time in run info. |
| controllers/executable_controller.go | Adds persistent Executable behavior: leasing, adoption, state store record persistence/cleanup. |
| controllers/controller_common.go | Adds shared resourceLeaseRevalidationInterval constant. |
| api/v1/executable_types_test.go | Adds tests for start flag, lifecycle key behavior, monitor validation, lease key. |
| api/v1/executable_types.go | Adds persistent/start/lifecycle/monitor fields, lifecycle key computation, validation, lease key. |
| api/v1/container_types_test.go | Adds monitor and lease key tests for containers/networks. |
| api/v1/container_types.go | Adds container monitor fields, lifecycle key inclusion, validation, lease key. |
| api/v1/container_network_types.go | Adds lease key for ContainerNetwork. |
| api/v1/common_types.go | Centralizes gob lifecycle-hash encoder initialization for deterministic hashing. |
| README.md | Documents DCP_STATE_STORE_PATH env var. |
| NOTICE | Updates third-party notices for newly added deps. |
| Makefile | Refactors stdlib ignore list for go-licenses generation. |
Files not reviewed (2)
- api/v1/zz_generated.deepcopy.go: Language not supported
- api/v1/zz_generated.model_name.go: Language not supported
Comments suppressed due to low confidence (3)
internal/exerunners/process_executable_runner.go:1
- AdoptRun ignores the provided context and starts a watcher goroutine that is only stopped via StopRun/ReleaseRun. If the caller cancels the adoption context (e.g., controller shutdown) but does not explicitly stop/release the run, the watcher can leak and keep polling indefinitely. Consider honoring ctx.Done() by (a) accepting ctx (do not discard it), and (b) wiring ctx cancellation into stopWatching (e.g., select on ctx.Done() in watchAdoptedProcess, or derive stopWatching from a context.WithCancel stored in runState and cancel it on ReleaseRun/StopRun).
internal/statestore/leases.go:1 - AcquireResourceLease runs resourceLeaseOwnerIsActive (process lookup via process.FindProcess) inside a BEGIN IMMEDIATE transaction. That holds a write lock while doing potentially slow syscalls, increasing contention and the likelihood of SQLite busy timeouts under concurrent controllers. Consider restructuring to keep the write transaction strictly DB-bound (e.g., read lease owner+timestamp in the txn, commit, check process liveness outside the txn, then perform a conditional update/delete in a second short txn using updated_at_unix_nano to avoid races).
internal/statestore/leases.go:1 - DeleteInactiveResourceLeases is safety-critical (it can delete coordination leases). The PR adds tests exercising leases indirectly, but there’s no direct unit coverage showing (1) active leases are not deleted, (2) races are avoided via updated_at_unix_nano, and (3) error paths are handled as expected. Adding focused tests around DeleteInactiveResourceLeases / inactiveResourceLeaseCandidates would reduce the risk of accidentally deleting valid leases.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+426
to
+427
| lifecycleKey := fmt.Sprintf("%x", fnvHash.Sum(nil)) | ||
| return lifecycleKey, true, hashErr |
Karol Zadora-Przylecki (karolz-ms)
approved these changes
May 14, 2026
Karol Zadora-Przylecki (karolz-ms)
merged commit May 14, 2026
8b93907
into
release/0.24
13 checks passed
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.
Backports #142 to release/0.24.