[codex] Upgrade Effect and Alchemy betas #4643
Mergedjuliusmarmingemerged 4 commits into
main fromrefs/pull/4643/headmerged by juliusmarminge View on GitHubjuliusmarminge changed the title
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
juliusmarminge merged this108e017
juliusmarminge closed this
- @@ -0,0 +116,21 @@116+ uses: dopplerhq/cli-action@4819d808ab99e5cde19a0637a16536a4038fad73 # v4117+118+ - name: Install dependencies119+ run: bun install120+121+ - name: Safety Check122+ run: |-123+ if [ "${{ env.STAGE }}" = "prod" ]; then124+ echo "ERROR: Cannot destroy prod environment in cleanup job"125+ exit 1126+ fi127+128+ - name: Destroy Preview Environment129+ working-directory: website130+ run: >-131+ doppler run --project "$DOPPLER_PROJECT" --config "$DOPPLER_CONFIG"132+ -- bun alchemy destroy --stage "$STAGE" --yes133+ env:134+ DOPPLER_TOKEN: ${{ secrets.DOPPLER_TOKEN }}135+ PULL_REQUEST: ${{ github.event.number }}136+ GITHUB_TOKEN: ${{ steps.bot-token.outputs.token }}@@ -0,0 +6,21 @@6+ branches:7+ - main8+ paths:9+ - "website/**"10+ - "packages/alchemy/**"11+ - "bun.lock"12+ - ".github/workflows/deploy.yml"13+ pull_request:14+ # `labeled` so adding `deploy-website` on an open PR triggers a15+ # deploy without needing another push.16+ types:17+ - opened18+ - reopened19+ - synchronize20+ - labeled21+ - closed22+ paths:23+ - "website/**"24+ - "packages/alchemy/**"25+ - "bun.lock"26+ - ".github/workflows/deploy.yml"@@ -0,0 +69,21 @@69+ client-id: ${{ secrets.ALCHEMY_VERSION_BOT_ID }}70+ private-key: ${{ secrets.ALCHEMY_VERSION_BOT_PRIVATE_KEY }}71+72+ - name: Setup Bun73+ uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.074+75+ - name: Install dependencies76+ run: bun install77+78+ # Secrets (Cloudflare credentials, etc.) are injected by79+ # `doppler run` from the `alchemy-v2` project — `prod` config on80+ # main, `dev` config everywhere else.81+ - name: Deploy82+ working-directory: website83+ run: bun alchemy deploy --stage "$STAGE" --yes84+ env:85+ PULL_REQUEST: ${{ github.event.number }}86+ CLOUDFLARE_API_TOKEN: ${{ startsWith(env.STAGE, 'prod') && secrets.PROD_CLOUDFLARE_API_TOKEN || secrets.TEST_CLOUDFLARE_API_TOKEN }}87+ CLOUDFLARE_ACCOUNT_ID: ${{ startsWith(env.STAGE, 'prod') && secrets.PROD_CLOUDFLARE_ACCOUNT_ID || secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}88+ BUILD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}89+ GITHUB_TOKEN: ${{ steps.bot-token.outputs.token }}@@ -13,12 +6,13 @@13- - beta14- - alpha15- - tag16- spec:6+ version:177 description: >-18- Channel-specific value. tag: REQUIRED, the explicit full version (e.g.19- 2.0.0-experimental.1). release: REQUIRED, patch|minor|major or an20- explicit x.y.z. beta|alpha: optional, an integer N to force21- 2.0.0-<channel>.N; leave blank to auto-increment.8+ Release spec. Empty = next beta. `patch|minor|major` or `x.y.z`9+ for a stable release. `beta` / `beta.N` / `alpha` / `alpha.N`10+ for a prerelease. Anything else = tag release on11+ `0.0.0-<name>`.2212 required: false2313 type: string14+ default: ""241516+concurrency:17+ group: release-${{ github.ref }}18+ cancel-in-progress: true
- @@ -0,0 +184,21 @@184+ autoResumeEnabled: true,185+ },186+ });187+ return yield* Effect.gen(function* () {188+ yield* v.get({ microvmIdentifier: vm.microvmId }).pipe(189+ Effect.flatMap((m) =>190+ m.state === "RUNNING"191+ ? Effect.void192+ : Effect.fail(new Error(`microvm ${m.state}`)),193+ ),194+ Effect.retry({195+ schedule: Schedule.spaced("500 millis"),196+ times: 180,197+ }),198+ );199+ const { authToken } = yield* v.auth({200+ microvmIdentifier: vm.microvmId,201+ expirationInMinutes: 5,202+ allowedPorts: [{ port: 8080 }],203+ });204+ yield* v.reachable(vm.endpoint, authToken).pipe(@@ -0,0 +209,21 @@209+ );210+ const readyMs = (yield* Effect.sync(() => Date.now())) - start;211+ return yield* HttpServerResponse.json({ id: vm.microvmId, readyMs });212+ }).pipe(213+ Effect.onError(() =>214+ v.term({ microvmIdentifier: vm.microvmId }).pipe(Effect.ignore),215+ ),216+ Effect.provide(FetchHttpClient.layer),217+ );218+ });219+220+ return {221+ fetch: Effect.gen(function* () {222+ const request = yield* HttpServerRequest;223+ const url = new URL(request.url, "http://microvm");224+ const v = pick(url.searchParams.get("variant"));225+226+ if (url.pathname === "/boot") {227+ return yield* boot(v);228+ }229+ if (url.pathname === "/shutdown") {@@ -0,0 +276,21 @@276+ const workspaceId = output?.workspaceId ?? olds?.workspaceId;277+ if (!workspaceId) return undefined;278+ const detector =279+ output?.anomalyDetectorId !== undefined280+ ? yield* describe(workspaceId, output.anomalyDetectorId)281+ : olds?.alias !== undefined282+ ? yield* findByAlias(workspaceId, olds.alias)283+ : undefined;284+ if (detector === undefined) return undefined;285+ const attrs = toAttrs(workspaceId, detector);286+ const tags = toTagRecord(detector.tags);287+ return (yield* hasAlchemyTags(id, tags)) ? attrs : Unowned(attrs);288+ }),289+290+ reconcile: Effect.fn(function* ({ id, news, output, session }) {291+ const workspaceId = news!.workspaceId;292+ const internalTags = yield* createInternalTags(id);293+ const desiredTags = { ...internalTags, ...news!.tags };294+295+ // 1. Observe — by cached id, falling back to the alias.296+ let detector =@@ -0,0 +179,21 @@179+ read: Effect.fn(function* ({ id, olds, output }) {180+ const name =181+ output?.analyzerName ?? (yield* createName(id, olds ?? {}));182+ const analyzer = yield* observe(name);183+ if (analyzer === undefined) return undefined;184+ const attrs = {185+ analyzerName: analyzer.name,186+ analyzerArn: analyzer.arn,187+ type: analyzer.type,188+ status: analyzer.status,189+ };190+ const tags = analyzer.tags ?? {};191+ return (yield* hasAlchemyTags(id, tags)) ? attrs : Unowned(attrs);192+ }),193+194+ diff: Effect.fn(function* ({ id, news, olds }) {195+ if (!isResolved(news)) return undefined;196+ const oldName = yield* createName(id, olds);197+ const newName = yield* createName(id, news);198+ if (oldName !== newName) {199+ return { action: "replace" } as const;@@ -0,0 +149,21 @@149+ return toAttrs(config);150+ }),151+152+ reconcile: Effect.fn(function* ({ news, session }) {153+ const scraperId = news!.scraperId;154+ const desiredArn = normalizeAmpLogGroupArn(news!.logGroupArn);155+ const desiredComponents = toWireComponents(news!.components);156+157+ // 1. Observe — the live configuration is authoritative.158+ const observed = yield* describe(scraperId);159+160+ // 2/3. Ensure + sync — `updateScraperLoggingConfiguration` is an161+ // upsert (there is no separate create operation); apply it only162+ // when the destination or components drift.163+ const drifts =164+ observed === undefined ||165+ observed.loggingDestination.cloudWatchLogs.logGroupArn !==166+ desiredArn ||167+ (desiredComponents !== undefined &&168+ canonicalComponents(desiredComponents) !==169+ canonicalComponents(observed.scraperComponents));@@ -0,0 +221,21 @@221+ );222+ const readyMs = (yield* Effect.sync(() => Date.now())) - start;223+ return yield* HttpServerResponse.json({ id: vm.microvmId, readyMs });224+ }).pipe(225+ Effect.onError(() =>226+ v.term({ microvmIdentifier: vm.microvmId }).pipe(Effect.ignore),227+ ),228+ Effect.provide(FetchHttpClient.layer),229+ );230+ });231+232+ return {233+ fetch: Effect.gen(function* () {234+ const request = yield* HttpServerRequest;235+ const url = new URL(request.originalUrl);236+ const v = pick(url.searchParams.get("variant"));237+238+ if (request.method === "GET" && url.pathname === "/boot") {239+ return yield* boot(v);240+ }241+ if (request.method === "GET" && url.pathname === "/shutdown") {@@ -0,0 +206,21 @@206+ schedule: Schedule.exponential("250 millis"),207+ times: 14,208+ }),209+ );210+ const readyMs = (yield* Effect.sync(() => Date.now())) - start;211+ return yield* HttpServerResponse.json({ id: vm.microvmId, readyMs });212+ }).pipe(213+ Effect.onError(() =>214+ v.term({ microvmIdentifier: vm.microvmId }).pipe(Effect.ignore),215+ ),216+ Effect.provide(FetchHttpClient.layer),217+ );218+ });219+220+ return {221+ fetch: Effect.gen(function* () {222+ const request = yield* HttpServerRequest;223+ const url = new URL(request.url, "http://microvm");224+ const v = pick(url.searchParams.get("variant"));225+226+ if (url.pathname === "/boot") {@@ -0,0 +74,21 @@74+ random.seed(7)75+ for i, (label, key, color) in enumerate(reversed(rows)):76+ xs = by_key[key]77+ ys = [i + random.uniform(-0.16, 0.16) for _ in xs]78+ ax.scatter(xs, ys, s=26, color=color, alpha=0.75, linewidths=0)79+ ax.set_yticks(range(len(rows)))80+ ax.set_yticklabels([label for label, _, _ in reversed(rows)])81+ ax.set_xlabel("time to usable service (seconds) — every boot in the run")82+ if logx:83+ ax.set_xscale("log")84+ ax.set_xticks([1, 2, 3, 5, 10, 20, 40, 60])85+ ax.set_xticklabels(["1s", "2s", "3s", "5s", "10s", "20s", "40s", "60s"])86+ elif xmax:87+ ax.set_xlim(0, xmax)88+ style(ax)89+ fig.tight_layout()90+ fig.savefig(f"{outdir}/{fname}", dpi=200)91+ plt.close(fig)92+93+94+all_max = max(max(by_key[k]) for _, k, _ in series)@@ -0,0 +62,21 @@62+ * @resource63+ * @section Deploying a Configuration64+ * @example Deploy a Hosted Version65+ * ```typescript66+ * const deployment = yield* AppConfig.Deployment("Rollout", {67+ * applicationId: app.applicationId,68+ * environmentId: env.environmentId,69+ * deploymentStrategyId: strategy.deploymentStrategyId,70+ * configurationProfileId: profile.configurationProfileId,71+ * configurationVersion: String(version.versionNumber),72+ * });73+ * ```74+ */75+export const Deployment = Resource<Deployment>("AWS.AppConfig.Deployment");76+77+class DeploymentNotSettled extends Data.TaggedError("DeploymentNotSettled")<{78+ readonly deploymentNumber: number;79+ readonly state: string;80+}> {}81+82+const TERMINAL_STATES = new Set(["COMPLETE", "ROLLED_BACK", "REVERTED"]);@@ -0,0 +218,21 @@218+ schedule: Schedule.exponential("250 millis"),219+ times: 14,220+ }),221+ );222+ const readyMs = (yield* Effect.sync(() => Date.now())) - start;223+ return yield* HttpServerResponse.json({ id: vm.microvmId, readyMs });224+ }).pipe(225+ Effect.onError(() =>226+ v.term({ microvmIdentifier: vm.microvmId }).pipe(Effect.ignore),227+ ),228+ Effect.provide(FetchHttpClient.layer),229+ );230+ });231+232+ return {233+ fetch: Effect.gen(function* () {234+ const request = yield* HttpServerRequest;235+ const url = new URL(request.originalUrl);236+ const v = pick(url.searchParams.get("variant"));237+238+ if (request.method === "GET" && url.pathname === "/boot") {@@ -0,0 +236,21 @@236+ ? undefined237+ : String(toWireSeconds(news.ttl));238+239+ const settings = {240+ description: news.description,241+ displayName: news.displayName,242+ stage: news.stage,243+ framework: news.framework,244+ enableAutoBuild: news.enableAutoBuild,245+ enableSkewProtection: news.enableSkewProtection,246+ enablePerformanceMode: news.enablePerformanceMode,247+ environmentVariables: news.environmentVariables,248+ enableBasicAuth: news.enableBasicAuth,249+ basicAuthCredentials: news.basicAuthCredentials,250+ buildSpec: news.buildSpec,251+ ttl,252+ enablePullRequestPreview: news.enablePullRequestPreview,253+ pullRequestEnvironmentName: news.pullRequestEnvironmentName,254+ };255+256+ let branch = yield* observe(news.appId, branchName);@@ -0,0 +227,21 @@227+ // 1. OBSERVE — cloud state is authoritative228+ let analyzer = yield* observe(name);229+230+ // 2. ENSURE — createAnalyzer, tolerating a concurrent create race231+ if (analyzer === undefined) {232+ yield* aa233+ .createAnalyzer({234+ analyzerName: name,235+ type,236+ tags: desiredTags,237+ configuration:238+ desiredUnusedAccessAge !== undefined239+ ? {240+ unusedAccess: {241+ unusedAccessAge: desiredUnusedAccessAge,242+ },243+ }244+ : undefined,245+ })246+ .pipe(Effect.catchTag("ConflictException", () => Effect.void));247+ analyzer = yield* observe(name);@@ -0,0 +196,21 @@196+ autoResumeEnabled: true,197+ },198+ });199+ return yield* Effect.gen(function* () {200+ yield* v.get({ microvmIdentifier: vm.microvmId }).pipe(201+ Effect.flatMap((m) =>202+ m.state === "RUNNING"203+ ? Effect.void204+ : Effect.fail(new Error(`microvm ${m.state}`)),205+ ),206+ Effect.retry({207+ schedule: Schedule.spaced("500 millis"),208+ times: 180,209+ }),210+ );211+ const { authToken } = yield* v.auth({212+ microvmIdentifier: vm.microvmId,213+ expirationInMinutes: 5,214+ allowedPorts: [{ port: 8080 }],215+ });216+ yield* v.reachable(vm.endpoint, authToken).pipe(@@ -0,0 +140,21 @@140+ .join(" "),141+ );142+ };143+ }144+ restores.push(() => {145+ for (const [method, fn] of original) {146+ (console as unknown as Record<string, unknown>)[method] = fn;147+ }148+ });149+ } catch {150+ // best-effort151+ }152+153+ // -------------------------------------------------------------------------154+ // 3. fs.writeSync / fs.write to fds 1 and 2 (bypasses the stream objects)155+ // -------------------------------------------------------------------------156+ try {157+ const realWriteSync = fs.writeSync;158+ const realWrite = fs.write;159+ const fsModule = fs as unknown as Record<string, unknown>;160+ fsModule.writeSync = ((@@ -0,0 +95,21 @@95+ encodingOrCb?: BufferEncoding | ((err?: Error | null) => void),96+ cb?: (err?: Error | null) => void,97+ ): boolean => {98+ const callback = typeof encodingOrCb === "function" ? encodingOrCb : cb;99+ sink(prefix, chunk);100+ callback?.(null);101+ return true;102+ };103+ process.stdout.write = divertStream("stray stdout");104+ process.stderr.write = divertStream("stray stderr");105+ restores.push(() => {106+ process.stdout.write = realStdoutWrite!;107+ process.stderr.write = realStderrWrite;108+ realStdoutWrite = undefined;109+ });110+111+ // -------------------------------------------------------------------------112+ // 2. global console — bun's console writes natively, NOT via stdout.write113+ // -------------------------------------------------------------------------114+ try {115+ const methods = [
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
6ec76659-e867-4046-ad77-449cb1013344You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.