Skip to content

Add SQLite state store for persistent resources - #142

Merged
Karol Zadora-Przylecki (karolz-ms) merged 69 commits into
mainfrom
dev/danegsta/sqlite
May 14, 2026
Merged

Karol Zadora-Przylecki (karolz-ms) merged 69 commits into
mainfrom
dev/danegsta/sqlite

Conversation

@danegsta

@danegsta David Negstad (danegsta) commented May 6, 2026 •

Copy link
Copy Markdown
Member
  • 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.
  • Add support for persistent executable resources using the state store to persist metadata.

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]>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still reviewing, but I thought I will share this with you now

Comment thread api/v1/executable_types.go Resolved
Comment thread controllers/container_controller.go Resolved
Comment thread controllers/container_controller.go Resolved
Comment thread controllers/executable_controller.go Resolved
Comment thread controllers/executable_controller.go Resolved
Comment thread doc/executable-persistence-api.md Resolved
Comment thread doc/executable-persistence-api.md Resolved
Comment thread internal/statestore/keys.go Resolved
David Negstad (danegsta) and others added 11 commits May 7, 2026 12:02
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]>
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]>
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]>
Remove branch-oriented change wording so the documentation describes executable persistence as stable behavior.

Co-authored-by: Copilot <[email protected]>
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]>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that was a lot. 😆 Looks awesome overall

Comment thread internal/statestore/store.go Resolved
Comment thread internal/statestore/leases.go Resolved
@danegsta
David Negstad (danegsta) marked this pull request as ready for review May 8, 2026 01:13
Copilot AI review requested due to automatic review settings May 8, 2026 01:13
@danegsta

Copy link
Copy Markdown
Member Author

Only thing that's missing for now that we'll likely end up wanting is a setting to allow a persistent resource to be cleaned up when a process with a given PID exits. That'll let us handle cases where we want a semi-long lived process or container that's still cleaned up automatically when some parent resource exits (such as cleaning up when the IDE exits or dotnet watch exits).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a local SQLite-backed state store to persist DCP coordination metadata (persistent process records + cross-instance resource leases) and wires it into controller startup plus persistent Executable/Container/Network reconciliation.

Changes:

  • Introduce internal/statestore (SQLite open/config, embedded golang-migrate migrations, persistent process records, and resource leases with stale-lease cleanup).
  • Add Executable persistence support (new API fields, adoption flow, runner adoption interface, and controller logic to persist/adopt/stop stale records).
  • Coordinate persistent Container/Network creation via state-store-backed leases; update integration test environments to provision isolated state stores.

Reviewed changes

Copilot reviewed 44 out of 48 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/integration/test_env_common.go Adds helper to create/cleanup an isolated SQLite state store for integration tests.
test/integration/standard_test_env.go Wires state store + lease owner into standard integration controller startup.
test/integration/service_controller_test_not_darwin.go Normalizes build tag/header placement (no functional change).
test/integration/advanced_test_env.go Wires state store + lease owner into advanced integration controller startup.
README.md Documents DCP_STATE_STORE_PATH environment variable.
pkg/generated/openapi/zz_generated.openapi.go Regenerates OpenAPI schema to include new ExecutableSpec fields.
internal/testutil/ctrlutil/test_process_executable_runner.go Adds AdoptRun passthrough to support persistent run adoption in tests.
internal/testutil/ctrlutil/apiserver_start.go Sets DCP_STATE_STORE_PATH for test-started apiserver instances.
internal/statestore/store.go Implements SQLite store open/configure (WAL, busy timeout, restricted perms) and helpers.
internal/statestore/store_test.go Adds coverage for DSN formatting, migrations, leases, and persistent process CRUD.
internal/statestore/schema.go Embeds migrations and applies them with golang-migrate under a lockfile.
internal/statestore/processes.go Implements persistent process record upsert/get/delete.
internal/statestore/migrations/README.md Adds authoring/compatibility rules for SQLite migrations.
internal/statestore/migrations/000001_initial.up.sql Initial schema for resource_locks and persistent_processes.
internal/statestore/leases.go Implements cross-process resource leases, held-lease errors, and stale cleanup.
internal/statestore/lease_owner.go Defines resource lease owner identity based on PID + identity time.
internal/proxy/network_stream_windows.go Normalizes build tag/header placement (no functional change).
internal/proxy/network_stream_unix.go Normalizes build tag/header placement (no functional change).
internal/networking/networking_windows.go Normalizes build tag/header placement (no functional change).
internal/networking/networking_linux.go Normalizes build tag/header placement (no functional change).
internal/networking/networking_darwin.go Normalizes build tag/header placement (no functional change).
internal/exerunners/process_executable_runner.go Updates process runner to support persistent runs (no monitor/kill-on-dispose) + AdoptRun.
internal/exerunners/process_executable_runner_test.go Adds test ensuring persistent executables skip process monitoring.
internal/dcpctrl/commands/run_controllers.go Opens state store at controller startup, cleans stale leases, passes store/config into reconcilers.
go.mod Adds dependencies for golang-migrate and modernc SQLite.
go.sum Updates module sums for new dependencies.
doc/executable-persistence-api.md Adds API/documentation for start, persistent, lifecycle keys, and state store behavior.
controllers/service_controller_metrics.go Formatting/header normalization (no functional change).
controllers/resource_lease_logging.go Adds helper to log held-lease details consistently.
controllers/network_controller.go Adds NetworkReconciler config + uses resource leases for persistent network operations.
controllers/executable_start_result.go Adds process identity/display start timestamps to startup results and run info propagation.
controllers/executable_runner.go Introduces PersistentExecutableRunner + adoption info contract.
controllers/executable_run_info.go Stores process identity/display start timestamps on run info.
controllers/executable_persistence.go Implements persistence lifecycle key computation, record upsert/delete, and adoption logic.
controllers/executable_controller.go Wraps persistent reconciles in a resource lease; adopts/persists/deletes records for persistent executables.
controllers/executable_controller_test.go Adds unit tests for lifecycle key behavior and adoption flows.
controllers/endpoint_common.go Formatting/header normalization (no functional change).
controllers/controller_common.go Adds shared resourceLeaseRevalidationInterval constant.
controllers/container_controller.go Refactors startup flow; uses state-store resource leases to coordinate persistent container creation/reuse.
api/v1/zz_generated.deepcopy.go Regenerates deepcopy for new ExecutableSpec fields.
api/v1/executable_types.go Adds start, persistent, lifecycleKey, lifecycle-key helper, validation, ShouldStart, and lease key.
api/v1/executable_types_test.go Adds tests for Start semantics, lease keys, and update validation.
api/v1/container_types.go Adds lease key support for persistent container coordination.
api/v1/container_types_test.go Adds tests for Container/ContainerNetwork lease keys.
api/v1/container_network_types.go Adds lease key support for persistent network coordination.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/v1/executable_types.go Resolved
Comment thread controllers/executable_controller.go Resolved
Comment thread internal/statestore/leases.go Resolved
Copilot AI review requested due to automatic review settings May 8, 2026 02:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 44 out of 48 changed files in this pull request and generated 2 comments.

Comment thread api/v1/executable_types.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 78 out of 83 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • api/v1/zz_generated.deepcopy.go: Language not supported

Comment thread pkg/io/restricted_directory_windows.go Resolved
Copilot AI review requested due to automatic review settings May 13, 2026 20:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 79 out of 84 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • api/v1/zz_generated.deepcopy.go: Language not supported

Comment thread pkg/syncmap/syncmap.go Resolved
Comment thread controllers/executable_controller.go Resolved
Copilot AI review requested due to automatic review settings May 13, 2026 21:40

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as "changes requested" to ensure you look at my comments re stale record cleanup before this PR is merged

Comment thread pkg/syncmap/syncmap.go Resolved
@karolz-ms
Karol Zadora-Przylecki (karolz-ms) merged commit 18b977c into main May 14, 2026
11 checks passed
@karolz-ms
Karol Zadora-Przylecki (karolz-ms) deleted the dev/danegsta/sqlite branch May 14, 2026 18:07
@danegsta

Copy link
Copy Markdown
Member Author

/backport to release/0.24

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

David Negstad (@danegsta) backporting to release/0.24 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Add SQLite state store for persistent resources
Using index info to reconstruct a base tree...
M	go.mod
M	go.sum
M	pkg/generated/openapi/zz_generated.openapi.go
Falling back to patching base and 3-way merge...
Auto-merging go.mod
CONFLICT (content): Merge conflict in go.mod
Auto-merging go.sum
CONFLICT (content): Merge conflict in go.sum
Auto-merging pkg/generated/openapi/zz_generated.openapi.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Add SQLite state store for persistent resources
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

Karol Zadora-Przylecki (karolz-ms) pushed a commit that referenced this pull request May 14, 2026
* 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



* Preserve process identity times in state store



* Update dependency notices



* Use structured executable lifecycle key hashing



* Simplify container startup retry handling



* Refactor container startup orchestration



* Handle persistent executable adoption before start gating



* 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.



* 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.



* Clarify persistence API documentation

Describe persistent executable API and state-store behavior at a high level instead of copying source declarations into docs.



* Describe executable persistence as feature docs

Remove branch-oriented change wording so the documentation describes executable persistence as stable behavior.



* 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.



* Extract executable persistence helpers



* Clarify resource lease contention logs



* Preserve reusable persistent executable records



* Configure state store WAL checkpointing



* Use executable spec lifecycle keys for persistence



* Require lease ownership on release



* Use effective executable lifecycle inputs



* Store process PID for adopted runs



* Guard persistent container setup with leases



* Flush shutdown response before stopping apiserver



* Gate persistent container startup with leases



* Close state store migration runner



* Align persistent executable lease handling



* Fix persistent container lease retries



* Format process identity values safely



* 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.



* 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.



* 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.



* 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.



* Persist executable output files



* Skip timestamp pipe for persistent output



* Release persistent container lease after reuse



* Harden persistent output directory setup



* Format io platform files



* Simplify persistent process PID check



* Release persistent executable leases on stable states



* Use process abstraction for executable stop



* Release persistent resource leases on stable states



* Validate restricted directory owners on Windows



* Release executable leases for unknown state



* Add lifecycle-bound persistent monitors



* Fix restricted directory test on Windows



* Validate monitor timestamp in dcpproc helper



* Remove duplicate executable display start time



* Refine persistent lease release handling



* Respect state store migration busy timeout



* Use test contexts in lease tests



* Move persistent lease coverage to integration tests



* Remove unused container lease helper



* Return lifecycle env file read errors



* Use computed executable lease owner in tests



* Avoid chmodding explicit state store parents



* Use restricted integration state store dirs



* Guard adopted process watcher cleanup



* Validate restricted directory ACLs on Windows



* Secure statestore test directories on Windows



* Clean invalid persistent executable records on startup



* Reject deny ACEs in restricted directory validation



* Relax Windows restricted directory validation



* Separate elevated state store directory



* Rename comparable sync map



* Run invalid persistent cleanup asynchronously



* Simplify persistent cleanup lease skip



* Reload persistent record before cleanup



---------

Co-authored-by: Copilot <[email protected]>
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.

3 participants