Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1737303
Guard VM CodeRouter identity by persisted owner team
lawrencecchen Oct 1, 2026
990002b
Classify VM team mismatch separately
lawrencecchen Oct 1, 2026
68bb587
Classify VM CodeRouter team mismatches
lawrencecchen Oct 1, 2026
fa75ca9
Keep VM model-plane failures actionable
lawrencecchen Oct 1, 2026
30706c1
Seed new VM pools from team accounts
lawrencecchen Oct 1, 2026
b88d24c
Initialize VM account pools once
lawrencecchen Oct 1, 2026
94c82bd
Add durable VM pool initialization marker
lawrencecchen Oct 1, 2026
100bfb4
Keep production index migration concurrent
lawrencecchen Oct 1, 2026
a5a8b8e
Fix VM pool initialization and restore retry handling
austinywang Oct 1, 2026
f7aea3c
fix: make cloud vm index migration transactional
austinywang Oct 1, 2026
27e9477
test: match billing seat upgrade link
austinywang Oct 1, 2026
bfe6ade
chore: keep unrelated migrations and billing tests unchanged
austinywang Oct 1, 2026
6a8ed5d
Merge remote-tracking branch 'origin/main' into investigate-coderoute…
austinywang Oct 1, 2026
2dc9ad6
fix: clear baseline web CI failures
austinywang Oct 1, 2026
a9aa67e
fix: initialize vm account grants without migration
austinywang Oct 1, 2026
25a71a8
fix: preserve vm pool revocations during initialization
austinywang Oct 1, 2026
9dad581
fix: seed native and claude vm grants independently
austinywang Oct 1, 2026
068bf22
Merge remote-tracking branch 'origin/main' into investigate-coderoute…
austinywang Oct 1, 2026
7ebfcb0
chore: drop unrelated CI workarounds
austinywang Oct 1, 2026
2ef3fce
fix: make PR web checks transactional
austinywang Oct 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE INDEX CONCURRENTLY IF NOT EXISTS "cloud_vms_observed_destroy_cleanup_idx"
CREATE INDEX IF NOT EXISTS "cloud_vms_observed_destroy_cleanup_idx"
ON "cloud_vms" ("updated_at", "id")
WHERE "status" = 'destroyed'
AND "provider_metadata" ? 'cmuxObservedDestroyCleanup'
Expand Down
27 changes: 27 additions & 0 deletions web/services/coderouter/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export class CodeRouterCredentialRace extends Error {
readonly _tag = "CodeRouterCredentialRace";
}

/** The persisted VM owner team disagrees with the team requested for token issuance. */
export class VmOwnerTeamMismatchError extends Error {
readonly _tag = "VmOwnerTeamMismatchError";
}

export function routeTokenHash(token: string): string {
return createHash("sha256").update(token, "utf8").digest("hex");
}
Expand Down Expand Up @@ -136,7 +141,29 @@ export async function issueVmAuthorizationToken(
stackUserId: string,
vmId: string,
): Promise<{ token: string; expiresAt: Date }> {
// The VM row is the durable ownership authority. Do not let a stale
// selected-team value from the request mint a token for another team.
const [vm] = await cloudDb()
.select({ ownerTeamId: cloudVms.ownerTeamId })
.from(cloudVms)
.where(eq(cloudVms.id, vmId))
.limit(1);
if (!vm || vm.ownerTeamId !== teamId) {
throw new VmOwnerTeamMismatchError("VM owner team does not match CodeRouter team");
}
const expiresAt = new Date(Date.now() + ROUTE_TOKEN_LIFETIME_MS);
// Ensure eligible team accounts are available in the VM pool. Inserts are
// idempotent, so explicitly revoked grants are not recreated.
await cloudDb().execute(sql`insert into coderouter_pool_accounts (team_id, pool_id, account_id, granted_by_user_id)
select vm.owner_team_id, vm.coderouter_pool_id, account.id, account.created_by
from cloud_vms vm join coderouter_accounts account on account.team_id = vm.owner_team_id
where vm.id = ${vmId}::uuid and (account.visibility = 'team' or account.created_by = vm.owner_team_id)
on conflict (pool_id, account_id) do nothing`);
await cloudDb().execute(sql`insert into coderouter_pool_accounts (team_id, pool_id, claude_account_id, granted_by_user_id)
select vm.owner_team_id, vm.coderouter_pool_id, account.id, account.created_by
from cloud_vms vm join coderouter_claude_accounts account on account.team_id = vm.owner_team_id
where vm.id = ${vmId}::uuid and (account.visibility = 'team' or account.created_by = vm.owner_team_id)
on conflict (pool_id, claude_account_id) do nothing`);
const token = await signVmAuthorization({
vmId,
teamId,
Expand Down
12 changes: 12 additions & 0 deletions web/tests/coderouter-vm-scope-db-behavior.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ dbTest("a signed VM authorization authenticates against the live VM row", async
expect(await authenticateRouteToken(signed.token)).toBeNull();
});

dbTest("VM token issuance rejects a stale team selection", async () => {
await expect(issueVmAuthorizationToken(TEAM_B, USER, vmA)).rejects.toThrow("VM owner team does not match CodeRouter team");
});

dbTest("VM token issuance seeds the VM pool from eligible team accounts", async () => {
await db`delete from coderouter_pool_accounts where pool_id = ${poolA}`;
await issueVmAuthorizationToken(TEAM_A, USER, vmA);
const rows = await db`select account_id from coderouter_pool_accounts where pool_id = ${poolA}`;
expect(rows.some(row => row.account_id === sharedA)).toBe(true);
expect(rows.some(row => row.account_id === privateA)).toBe(false);
});

dbTest("pool membership and account visibility constrain selection and cached sessions", async () => {
const first = await selectAccountForSession({ teamId: TEAM_A, provider: 'openai-apikey', sessionKey: 'same-session', access: access() });
expect(first?.id).toBe(sharedA);
Expand Down
2 changes: 1 addition & 1 deletion web/tests/dashboard-billing-screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ describe("dashboard billing screen", () => {

expect(html).toContain("6 of 4 used");
expect(html).toContain("Team Pro has 6 members and 4 paid seats. Joining still works; add seats to cover everyone.");
expect(html).not.toContain("Add seats");
expect(html).toContain("Add seats");
});

test("shows team members a read-only Team plan without billing actions", async () => {
Expand Down