Skip to content

Commit 6966393

Browse files
authored
fix(preview): version Files bridge URLs (#154)
## What changed - add the deployed Worker release SHA to every code-server Files URL - expose the validated release identity through the sandbox runtime - document why the release-specific cache key is required ## Why The preview proxy already marks workbench HTML `private, no-store`, but code-server's registered service worker can retain an older workbench document. That leaves an old injected parent bridge active after a Worker deployment. A release-specific URL guarantees the current bridge is loaded without disabling code-server's useful static caching. ## Verification - `pnpm turbo typecheck lint build` (55/55 tasks) - production iframe reproduced the stale bridge while a cache-busted production workbench loaded the current bridge - final product-level production verification will run after deployment
1 parent 03de59c commit 6966393

4 files changed

Lines changed: 9 additions & 2 deletions

File tree

apps/agent-worker/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ enumerate the project first, so dependency trees and large generated projects ar
199199
start critical path. After an idle stop, a current tracked code-server session is relaunched from its
200200
durable command instead of repeating installation and cleanup probes. A project with no tracked
201201
app-preview record returns the terminal `none` state without starting Daytona or entering the
202-
preview wake polling loop.
202+
preview wake polling loop. Files URLs include the Worker release SHA so code-server's service worker
203+
cannot reuse a workbench document containing an older injected parent bridge after a deployment.
203204

204205
AgentRun does not count, persist, bill, or emit model-token or model-cost data,
205206
and it does not apply per-run or daily dollar caps. Provider usage remains an

apps/agent-worker/src/durable-objects/project-sandbox-code-server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ export const CODE_SERVER_START_TIMEOUT_MS = 120_000;
1010
export function codeServerFolderUrl(
1111
rawUrl: string,
1212
folderPath: string,
13+
bridgeRelease: string,
1314
initialFilePath?: string,
1415
): string {
1516
const url = new URL(rawUrl);
17+
url.searchParams.set("cc_bridge", bridgeRelease);
1618
url.searchParams.set("folder", folderPath);
1719
if (initialFilePath) {
1820
url.searchParams.set("cc_open_file", initialFilePath);

apps/agent-worker/src/durable-objects/project-sandbox-content.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type ContentRuntime = Pick<
117117
| "ensureSandbox"
118118
| "previewHostname"
119119
| "previewSecret"
120+
| "releaseSha"
120121
| "toUpstreamError"
121122
>;
122123

@@ -429,10 +430,11 @@ async function exposeCodeServer(
429430
secret: await context.runtime.previewSecret(),
430431
useSubdomain: true,
431432
});
433+
const bridgeRelease = context.runtime.releaseSha();
432434
return {
433435
expiresAt: built.expiresAt,
434436
port: CODE_SERVER_PORT,
435-
url: codeServerFolderUrl(built.url, displayFolder, parsed.initialFilePath),
437+
url: codeServerFolderUrl(built.url, displayFolder, bridgeRelease, parsed.initialFilePath),
436438
workspacePath: parsed.workspacePath,
437439
};
438440
}

apps/agent-worker/src/durable-objects/project-sandbox-runtime-handle.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export interface SandboxRuntime {
9494
readonly ownerUserId: () => string;
9595
readonly previewHostname: () => string;
9696
readonly previewSecret: () => Promise<string>;
97+
readonly releaseSha: () => string;
9798
readonly registerOwner: (userId: string, sandboxName?: string) => Promise<void>;
9899
readonly restartSandboxForWorkspaceRecovery: (sandboxId: string) => Promise<void>;
99100
readonly sandboxName: () => string;
@@ -162,6 +163,7 @@ function runtimeHandle(state: RuntimeState): SandboxRuntime {
162163
previewHostname: () =>
163164
previewHostnameForWorker(state.env.CHEATCODE_ENVIRONMENT, state.env.PREVIEW_HOSTNAME),
164165
previewSecret: () => previewSecret(state),
166+
releaseSha: () => state.env.CHEATCODE_RELEASE_SHA ?? "development",
165167
registerOwner: (userId, sandboxName) => state.identity.registerOwner(userId, sandboxName),
166168
restartSandboxForWorkspaceRecovery: (sandboxId) =>
167169
restartSandboxForWorkspaceRecovery(state, sandboxId),

0 commit comments

Comments
 (0)