Skip to content

Let the Environment own its lifecycle - #930

Merged
SaladDay merged 9 commits into
mainfrom
feat/environment-owns-lifecycle
Nov 5, 2026
Merged

SaladDay merged 9 commits into
mainfrom
feat/environment-owns-lifecycle

Conversation

@SaladDay

@SaladDay SaladDay commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The Environment now owns its lifecycle. This prepares standalone, reusable Environments; the public API follows in a later PR.

  • Storage (migration 000014_first_class_environments):
    • environments gains tenant_id, its frozen configuration and session_owned, plus the creation-identity columns and constraints that standalone Environments will use.
    • sessions.environment_id names the Environment. The unique index sessions_attached_environment allows at most one live Session per Environment.
    • Preparation input (environment_setups, initial_environment_files) is keyed by environment_id.
    • Existing data is carried forward. A migration test seeds a version-13 database and checks every read after the upgrade.
  • Queries: every query that joined environments to sessions now reads the Environment's own tenant, configuration and attachment. The two views are recreated.
  • Lock: sessionpg.WithEnvironment locks the attached Session, if any, then the Environment, and re-checks the attachment. Workspace work uses the same lock.
  • Domain types:
    • sessions.Environment gains TenantID, SessionOwned and AttachedSessionID.
    • deployment.Allocation uses AttachedSessionID and Reclaimed.
    • EnvironmentInitialization no longer carries a Session or Harness.
  • Session reads: a Session's configuration.environment is composed from its Environment's row.
  • Preparation without a Harness check: initialization no longer reads the Session's Harness. If the Runtime lacks the Session's Harness, the Session's input fails with runtime_preparation_failed, and the Environment is unaffected. This is the only behavior change. sessions.ProvisioningHarness is deleted.
  • Egress by ownership: Session-owned Environments keep exactly today's Egress.

Docs updated in EN and zh: services/core/IMPLEMENTATION.md, contracts/agents-api/environments.md, docs/sandbox-provider.md and the diagnostics text.

Checks

  • go vet ./services/core/... and scripts/check-sqlc.py.
  • Unit tests for sessions, deployment, execution, api, runtimehistory and runtimeenrollment.
  • Every Postgres store package.
  • The integration suite, plus the new migration and Harness-availability tests.
  • The official-client suite on a fresh database.
  • The migration in a rolled-back transaction on a copy of a populated test database: 533 Environments, setups and files carried forward.
  • pnpm --dir website check-translations.

This PR and the standalone Environments API PR get one combined blind review.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@blacksmith-sh

This comment has been minimized.

@SaladDay
SaladDay merged commit 1207eca into main Nov 5, 2026
19 checks passed
@SaladDay
SaladDay deleted the feat/environment-owns-lifecycle branch November 5, 2026 11:19
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