Repository navigation
backfill sandbox environment where it is undefined #1400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+156
−8
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@truefoundry/trueforge-sdk": patch | ||
| --- | ||
|
|
||
| Regenerate SDK from updated OpenAPI spec. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@truefoundry/trueforge': patch | ||
| '@truefoundry/trueforge-core': patch | ||
| --- | ||
|
|
||
| Backfill missing `config.sandbox.environment_name` on saved agents and inline session specs that have sandbox enabled, pinning each to the tenant default environment (or `trueforge-sandbox-env` when no default is set). Docs now require the field when sandbox is enabled instead of documenting omit-as-default. |
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
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
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
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
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
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
69 changes: 69 additions & 0 deletions
69
...trueforge/src/db/postgres/migrations/20261116_000001_sandbox_environment_name_backfill.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { sql, type Kysely } from 'kysely'; | ||
|
|
||
| /** | ||
| * Pin missing `config.sandbox.environment_name` on saved agents and inline | ||
| * session specs when sandbox is enabled. | ||
| * | ||
| * Before 2026-11-10 the field was optional (omit meant "tenant default"). | ||
| * Validation now requires it for Daytona, which 422s those legacy rows at | ||
| * session create. Prefer the tenant `is_default` environment; fall back to the | ||
| * reserved `trueforge-sandbox-env` when that row exists and no default is set. | ||
| */ | ||
| export async function up(db: Kysely<unknown>): Promise<void> { | ||
| await sql`SET LOCAL lock_timeout = '5s'`.execute(db); | ||
|
|
||
| await sql` | ||
| UPDATE agent AS agent | ||
| SET manifest = jsonb_set( | ||
| agent.manifest, | ||
| '{config,sandbox,environment_name}', | ||
| to_jsonb(pin.name) | ||
| ) | ||
| FROM ( | ||
| SELECT | ||
| tenant_id, | ||
| COALESCE( | ||
| MAX(name) FILTER (WHERE is_default), | ||
| MAX(name) FILTER (WHERE name = 'trueforge-sandbox-env') | ||
| ) AS name | ||
| FROM sandbox_environment | ||
| WHERE lifecycle_stage = 'active' | ||
|
heerambavi1998 marked this conversation as resolved.
Resolved
heerambavi1998 marked this conversation as resolved.
Resolved
|
||
| GROUP BY tenant_id | ||
|
heerambavi1998 marked this conversation as resolved.
Resolved
|
||
| ) AS pin | ||
| WHERE pin.tenant_id = agent.tenant_id | ||
| AND pin.name IS NOT NULL | ||
| AND (agent.manifest #>> '{config,sandbox,enabled}') = 'true' | ||
| AND nullif(agent.manifest #>> '{config,sandbox,environment_name}', '') IS NULL | ||
| `.execute(db); | ||
|
heerambavi1998 marked this conversation as resolved.
Resolved
|
||
|
|
||
| await sql` | ||
| UPDATE session AS session | ||
| SET agent_spec = jsonb_set( | ||
| session.agent_spec, | ||
| '{config,sandbox,environment_name}', | ||
| to_jsonb(pin.name) | ||
| ) | ||
| FROM ( | ||
| SELECT | ||
| tenant_id, | ||
| COALESCE( | ||
| MAX(name) FILTER (WHERE is_default), | ||
| MAX(name) FILTER (WHERE name = 'trueforge-sandbox-env') | ||
| ) AS name | ||
| FROM sandbox_environment | ||
| WHERE lifecycle_stage = 'active' | ||
| GROUP BY tenant_id | ||
| ) AS pin | ||
| WHERE pin.tenant_id = session.tenant_id | ||
| AND pin.name IS NOT NULL | ||
| AND session.agent_spec IS NOT NULL | ||
| AND (session.agent_spec #>> '{config,sandbox,enabled}') = 'true' | ||
| AND nullif(session.agent_spec #>> '{config,sandbox,environment_name}', '') IS NULL | ||
| `.execute(db); | ||
| } | ||
|
|
||
| /** Irreversible: backfilled names are indistinguishable from user-pinned ones. */ | ||
| export function down(db: Kysely<unknown>): Promise<void> { | ||
| void db; | ||
| return Promise.reject(new Error('20261116_000001_sandbox_environment_name_backfill is irreversible')); | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
...s/trueforge/src/db/sqlite/migrations/20261116_000001_sandbox_environment_name_backfill.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { sql, type Kysely } from 'kysely'; | ||
|
|
||
| /** | ||
| * SQLite mirror of postgres/20261116_000001_sandbox_environment_name_backfill.ts. | ||
| * Pin missing sandbox environment names on agents and inline session specs. | ||
| */ | ||
| export async function up(db: Kysely<unknown>): Promise<void> { | ||
| await db.transaction().execute(async trx => { | ||
| await sql` | ||
| UPDATE agent | ||
| SET manifest = jsonb_set( | ||
| manifest, | ||
| '$.config.sandbox.environment_name', | ||
| jsonb(json_quote(pin.name)) | ||
| ) | ||
| FROM ( | ||
| SELECT | ||
| tenant_id, | ||
| COALESCE( | ||
| MAX(CASE WHEN is_default = 1 THEN name END), | ||
| MAX(CASE WHEN name = 'trueforge-sandbox-env' THEN name END) | ||
| ) AS name | ||
| FROM sandbox_environment | ||
| WHERE lifecycle_stage = 'active' | ||
| GROUP BY tenant_id | ||
| ) AS pin | ||
| WHERE pin.tenant_id = agent.tenant_id | ||
| AND pin.name IS NOT NULL | ||
| AND json_extract(agent.manifest, '$.config.sandbox.enabled') IN (1, 'true') | ||
| AND nullif(json_extract(agent.manifest, '$.config.sandbox.environment_name'), '') IS NULL | ||
| `.execute(trx); | ||
|
|
||
| await sql` | ||
| UPDATE session | ||
| SET agent_spec = jsonb_set( | ||
| agent_spec, | ||
| '$.config.sandbox.environment_name', | ||
| jsonb(json_quote(pin.name)) | ||
| ) | ||
| FROM ( | ||
| SELECT | ||
| tenant_id, | ||
| COALESCE( | ||
| MAX(CASE WHEN is_default = 1 THEN name END), | ||
| MAX(CASE WHEN name = 'trueforge-sandbox-env' THEN name END) | ||
| ) AS name | ||
| FROM sandbox_environment | ||
| WHERE lifecycle_stage = 'active' | ||
| GROUP BY tenant_id | ||
| ) AS pin | ||
| WHERE pin.tenant_id = session.tenant_id | ||
| AND pin.name IS NOT NULL | ||
| AND session.agent_spec IS NOT NULL | ||
| AND json_extract(session.agent_spec, '$.config.sandbox.enabled') IN (1, 'true') | ||
| AND nullif(json_extract(session.agent_spec, '$.config.sandbox.environment_name'), '') IS NULL | ||
| `.execute(trx); | ||
| }); | ||
| } | ||
|
|
||
| /** Irreversible: backfilled names are indistinguishable from user-pinned ones. */ | ||
| export function down(db: Kysely<unknown>): Promise<void> { | ||
| void db; | ||
| return Promise.reject(new Error('20261116_000001_sandbox_environment_name_backfill is irreversible')); | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.