Skip to content

Move Environments and devices into sessions and sessionpg - #336

Merged
SaladDay merged 1 commit into
mainfrom
refactor/sessions-environments
Sep 30, 2026
Merged

SaladDay merged 1 commit into
mainfrom
refactor/sessions-environments

Conversation

@SaladDay

@SaladDay SaladDay commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Environment initialization, connections, enrollment and devices, plus the reads of frozen Session data, move out of store into sessions and sessionpg.

What changes

  • Execution use cases: sessions gains the lease-bound EnvironmentExecution family on sessionpg.Execution:

    • Environment initialization claim, completion and failure;
    • connection replacement, observation and reconciliation;
    • Session device binding.

    Each is Load → pure Decide → Apply, and the rules have table tests. Environment failure and termination reuse the 11c procedures.

  • Reads: Environments, Session Environments, devices, the frozen setup, the initial files, the skill references and executor credential authentication go through the sessions reader, implemented by sessionpg.Store. api and the runtime enrollment handler take the reader directly.

  • Frozen data: sessionpg.Store opens the frozen setup, the initial files and the skill references with the credential cipher and the Session binding. The bindings and ciphertext are unchanged.

  • Runtime gateway: runtime.NewGateway takes the archived-cancellation dependency explicitly. The type-assertion discovery is gone.

  • Device registration: CreateDevice, RevokeDevice and device registration validation move with the devices.

  • Removed from store: the moved Environment, connection, enrollment and device files, the Worker forwarding file, and the no-op MarkRuntimeOffline.

  • Test fixtures: they build the Session adapter from the pool and cipher, not from *store.Store.

  • Docs: IMPLEMENTATION.md names the new owners.

Behavior

  • A frozen setup, initial file or skill reference that fails to decode is now an internal error (500), not invalid input (400). Stored frozen data is written by Core, so a decode failure is corruption, not a client error. A missing key is still credentialcrypto.ErrUnavailable (503). PostgreSQL tests cover both.
  • BindSessionDevice rejects a malformed or nil device ID before any storage call, as before.
  • Everything else keeps its lock order, error precedence and events: initialization, connections, enrollment and device binding.

Checks

  • go build ./..., go vet ./services/core/..., make openapi (no diff) and scripts/check-names.py.
  • sessions and sessionpg in full.
  • store -run on the 194 tests in the store test files this PR touches: 187 pass, and 7 are gated on the environment. Five of those seven also passed with the official Python SDK and the environment key binary. The other two need a native daemon binary.
  • api -run (14 tests), execution -run (20 tests), cmd/server and runtimeenrollment in full.

A blind review found no blockers or majors. Three minor findings are fixed in this commit: the test fixtures reached into store internals, the device ID was checked in the wrong order, and a line of IMPLEMENTATION.md was missing. The fourth, an adapter export, is handled in the follow-up PR.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@SaladDay
SaladDay merged commit 68c5446 into main Sep 30, 2026
1 check passed
@SaladDay
SaladDay deleted the refactor/sessions-environments branch September 30, 2026 22:21
Environment and device reads, the initialization list and the frozen
setup and initial files join sessions.Reader on the pooled
sessionpg.Store, which sessionpg.New(units, cipher) builds with the
credential key. Frozen data that does not open or validate is an
internal error, and a missing key is credentialcrypto.ErrUnavailable.
Device creation, revocation, heartbeats and Runtime enrollment are
sessions.Service use cases; the device registration rule and
RuntimeTypeAgentDaemon move to sessions and runtimedevice.

The EnvironmentExecution family joins sessions.ExecutionOperations on
sessionpg.NewExecution(lease): initialization claim, completion and
failure, connection replacement, observation and reconciliation, and
Session device binding each run a Load, Decide and Apply transaction
under the Session lock. sessionpg.LoadEnvironment,
LoadSessionEnvironment and CreateSessionEnvironment are participants
of other Session transactions. The Worker, runtime manager and
lifecycle receive the Session operations and reader explicitly.

The daemon gateway takes its credential, heartbeat and archived
cancellation dependencies separately, so draining a receipt no longer
depends on a type assertion on the heartbeat store, and
MarkRuntimeOffline is deleted. api gains the required
EnvironmentsReader, and cmd/device provisions devices through
sessions.Service. The store Environment, initialization, connection
recovery, local device and enrollment files are deleted.
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