Skip to content
TypeScript

fix(server): dev database copies drop links to other environments (#27313)

maria4fb9e5d34e83
diff --git a/AGENTS.md b/AGENTS.md
index 493f7fc0be7..d99f1b5fa96 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -91,7 +91,7 @@ The most common defect in this repo is a change that works on the path you teste
An empty database is a bad test. Seed your worktree's `.t3` with a copy of real data instead of pointing at live state:
- The first `vp run dev` in a worktree does this for you when its database is missing and the source is at most 500 MiB. Larger sources warn and dev starts with an empty database. `--no-seed` or `T3CODE_DEV_SEED=0` skips seeding. Manual migration still accepts larger sources and may use substantial disk space before pruning.
-- Run `vp run migrate-dev-db` with your dev server stopped to refresh. It rebuilds `<worktree>/.t3/userdata/statev2.sqlite` from a read-only snapshot of `~/.t3/userdata/statev2.sqlite`, the developer's real data. It keeps recent projects and their stopped threads, and drops scheduled tasks, pending work, and auth sessions, so your dev server never runs the developer's agents. Raise `--projects` and `--threads-per-project` for more data.
+- Run `vp run migrate-dev-db` with your dev server stopped to refresh. It rebuilds `<worktree>/.t3/userdata/statev2.sqlite` from a read-only snapshot of `~/.t3/userdata/statev2.sqlite`, the developer's real data. It keeps recent projects and their stopped threads, and drops scheduled tasks, pending work, auth sessions, and links to other environments, so your dev server never runs the developer's agents or reaches their other machines. Raise `--projects` and `--threads-per-project` for more data.
- Refresh `statev2.sqlite`, not `state.sqlite`. The server copies the V1 `state.sqlite` only when `statev2.sqlite` is missing.
- Bring `secrets` and `settings.json` only if the flow under test needs them.
- Copy in, never symlink. Data flows one way: into your sandbox, never back out.
diff --git a/apps/server/scripts/migrate-dev-db.test.ts b/apps/server/scripts/migrate-dev-db.test.ts
index c9a8f801755..2b56111a98b 100644
--- a/apps/server/scripts/migrate-dev-db.test.ts
+++ b/apps/server/scripts/migrate-dev-db.test.ts
@@ -95,6 +95,10 @@ const createFixtureSource = Effect.fn("createMigrateDevDbFixtureSource")(functio
VALUES ('delivery-1', 'task-1', 'key-1', 1900000000000, '{}', '{}', '[]')`;
yield* sql`INSERT INTO auth_sessions (session_id, subject, scopes, method, issued_at, expires_at)
VALUES ('session-1', 'user', '[]', 'pairing', '2026-08-01', '2027-08-01')`;
+ yield* sql`INSERT INTO peer_environment_links
+ (environment_id, secret_name, label, urls_json, access, linked_at, expires_at)
+ VALUES ('environment-box', 'peer-link-box', 'Box', '["https://box.example"]', 'auto',
+ '2026-08-01', '2027-08-01')`;
}),
);
return databasePath;
@@ -130,13 +134,15 @@ it.layer(NodeServices.layer)("migrate-dev-db", (it) => {
tasks: number;
webhooks: number;
transfers: number;
+ links: number;
}>`
SELECT
(SELECT COUNT(*) FROM auth_sessions) AS auth,
(SELECT COUNT(*) FROM scheduled_tasks) AS tasks,
(SELECT COUNT(*) FROM scheduled_task_webhook_replay_keys) +
(SELECT COUNT(*) FROM scheduled_task_webhook_pending) AS webhooks,
- (SELECT COUNT(*) FROM orchestration_v2_projection_context_transfers) AS transfers`;
+ (SELECT COUNT(*) FROM orchestration_v2_projection_context_transfers) AS transfers,
+ (SELECT COUNT(*) FROM peer_environment_links) AS links`;
return { threads, events, sessions, leftovers };
}),
);
@@ -152,7 +158,13 @@ it.layer(NodeServices.layer)("migrate-dev-db", (it) => {
kept.sessions.map((row) => row.provider_session_id),
["session-shared"],
);
- assert.deepStrictEqual(kept.leftovers, { auth: 0, tasks: 0, webhooks: 0, transfers: 0 });
+ assert.deepStrictEqual(kept.leftovers, {
+ auth: 0,
+ tasks: 0,
+ webhooks: 0,
+ transfers: 0,
+ links: 0,
+ });
}),
);
diff --git a/apps/server/scripts/migrate-dev-db.ts b/apps/server/scripts/migrate-dev-db.ts
index 2a22a6040a8..5d1446a8c07 100644
--- a/apps/server/scripts/migrate-dev-db.ts
+++ b/apps/server/scripts/migrate-dev-db.ts
@@ -211,6 +211,7 @@ const CLEARED_TABLES: ReadonlyArray<string> = [
"provider_session_runtime",
"auth_sessions",
"auth_pairing_links",
+ "peer_environment_links",
];
const PROVIDER_SESSIONS_TABLE = "orchestration_v2_projection_provider_sessions";