Skip to content

Commit 927f44e

Browse files
committed
fix(cloud): read the plan audio artifact name from the producer contract
The aws-lambda and gcp-cloud-run adapters each restated the plan's audio filename in five places, so renaming it in the producer left them looking for a file that is no longer written. CI caught it: the gcp dispatch test asserting a plan has no audio artifact started seeing one. Export the name from `@hyperframes/producer/distributed` and consume it in both adapters. This is the same failure the constant exists to prevent, one package boundary further out: a literal that drifts from the writer's is a silently missing audio track rather than a loud error, because both call sites only ever ask whether the file exists.
1 parent fbfaa75 commit 927f44e

6 files changed

Lines changed: 30 additions & 15 deletions

File tree

‎packages/aws-lambda/src/events.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ interface AssembleEventBase {
117117
Action: "assemble";
118118
/** S3 URIs of every chunk, ordered by chunk index. Length must equal `chunkCount`. */
119119
ChunkS3Uris: string[];
120-
/** S3 URI of the planDir's `audio.aac` if the composition has audio; `null` otherwise. */
120+
/** S3 URI of the planDir's audio artifact if the composition has audio; `null` otherwise. */
121121
AudioS3Uri: string | null;
122122
/** Final output S3 URI (`s3://bucket/key.mp4`). */
123123
OutputS3Uri: string;

‎packages/aws-lambda/src/handler.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ describe("handler dispatch", () => {
563563
);
564564
const renderChunkMock = mock(
565565
async (planDir: string, _chunkIndex: number, outputPath: string): Promise<ChunkResult> => {
566-
expect(existsSync(join(planDir, "audio.aac"))).toBe(false);
566+
expect(existsSync(join(planDir, "audio.m4a"))).toBe(false);
567567
writeFileSync(outputPath, "V2-CHUNK");
568568
return {
569569
outputPath,
@@ -818,7 +818,7 @@ function makeMinimalV1PlanDir(dir: string, withAudio: boolean): void {
818818
JSON.stringify([{ index: 0, startFrame: 0, endFrame: 30 }]),
819819
);
820820
writeFileSync(join(dir, "meta", "encoder.json"), "{}");
821-
if (withAudio) writeFileSync(join(dir, "audio.aac"), "AAC");
821+
if (withAudio) writeFileSync(join(dir, "audio.m4a"), "AAC");
822822
planJson.planHash = recomputePlanHashFromPlanDir(dir);
823823
writeFileSync(join(dir, "plan.json"), JSON.stringify(planJson));
824824
}

‎packages/aws-lambda/src/handler.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
listPlanV2ArtifactsForTarget,
2525
materializePlanV2Target,
2626
plan,
27+
PLAN_AUDIO_RELATIVE_PATH,
2728
planV2WithPublisher,
2829
type PlanResult,
2930
type PlanV2Artifact,
@@ -318,9 +319,11 @@ async function handlePlan(event: PlanEvent, deps?: HandlerDeps): Promise<PlanLam
318319
const planTar = join(work, "plan.tar.gz");
319320
await tarDirectory(planDir, planTar);
320321
const planTarUri = `${trimTrailingSlash(event.PlanOutputS3Prefix)}/plan.tar.gz`;
321-
const audioPath = join(planDir, "audio.aac");
322+
const audioPath = join(planDir, PLAN_AUDIO_RELATIVE_PATH);
322323
const hasAudio = existsSync(audioPath) && statSync(audioPath).size > 0;
323-
const audioUri = hasAudio ? `${trimTrailingSlash(event.PlanOutputS3Prefix)}/audio.aac` : null;
324+
const audioUri = hasAudio
325+
? `${trimTrailingSlash(event.PlanOutputS3Prefix)}/${PLAN_AUDIO_RELATIVE_PATH}`
326+
: null;
324327
// Plan and audio are independent S3 PUTs; run them in parallel so
325328
// the response returns as soon as the slower of the two completes.
326329
await Promise.all([
@@ -390,7 +393,7 @@ async function handlePlanV2(
390393
Width: manifest.width,
391394
Height: manifest.height,
392395
Format: manifest.format,
393-
HasAudio: manifest.artifacts.some((artifact) => artifact.path === "audio.aac"),
396+
HasAudio: manifest.artifacts.some((artifact) => artifact.path === PLAN_AUDIO_RELATIVE_PATH),
394397
AudioS3Uri: null,
395398
FfmpegVersion: manifest.ffmpegVersion,
396399
ProducerVersion: manifest.producerVersion,
@@ -568,7 +571,7 @@ async function handleAssemble(
568571

569572
let audioPath: string | null = null;
570573
if (event.AudioS3Uri) {
571-
audioPath = join(planDir, "audio.aac");
574+
audioPath = join(planDir, PLAN_AUDIO_RELATIVE_PATH);
572575
await downloadS3ObjectToFile(s3, event.AudioS3Uri, audioPath);
573576
}
574577

@@ -616,7 +619,9 @@ async function handleAssembleV2(
616619
const planDir = await downloadAndMaterializePlanV2(s3, event, { role: "assembler" }, work);
617620
// `downloadAndMaterializePlanV2` materializes atomically. Audio is
618621
// assembler-only and lives at the familiar v1-compatible location.
619-
const audioPath = existsSync(join(planDir, "audio.aac")) ? join(planDir, "audio.aac") : null;
622+
const audioPath = existsSync(join(planDir, PLAN_AUDIO_RELATIVE_PATH))
623+
? join(planDir, PLAN_AUDIO_RELATIVE_PATH)
624+
: null;
620625
const chunkPaths = await downloadChunkObjects(s3, event.ChunkS3Uris, work, event.Format);
621626
const finalOutput =
622627
event.Format === "png-sequence"

‎packages/gcp-cloud-run/src/server.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function makeMinimalV1PlanDir(dir: string, withAudio: boolean): void {
8787
JSON.stringify([{ index: 0, startFrame: 0, endFrame: 30 }]),
8888
);
8989
writeFileSync(join(dir, "meta", "encoder.json"), "{}");
90-
if (withAudio) writeFileSync(join(dir, "audio.aac"), "AAC");
90+
if (withAudio) writeFileSync(join(dir, "audio.m4a"), "AAC");
9191
planJson.planHash = recomputePlanHashFromPlanDir(dir);
9292
writeFileSync(join(dir, "plan.json"), JSON.stringify(planJson));
9393
}
@@ -273,7 +273,7 @@ describe("dispatch", () => {
273273
chunkIndex: number,
274274
outputBase: string,
275275
): Promise<ChunkResult> => {
276-
expect(existsSync(join(planDir, "audio.aac"))).toBe(false);
276+
expect(existsSync(join(planDir, "audio.m4a"))).toBe(false);
277277
writeFileSync(outputBase, `chunk-${chunkIndex}`);
278278
return {
279279
outputPath: outputBase,

‎packages/gcp-cloud-run/src/server.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
listPlanV2ArtifactsForTarget,
3333
materializePlanV2Target,
3434
plan,
35+
PLAN_AUDIO_RELATIVE_PATH,
3536
planV2WithPublisher,
3637
type PlanResult,
3738
type PlanV2Artifact,
@@ -322,7 +323,7 @@ async function handlePlan(event: PlanEvent, deps?: HandlerDeps): Promise<PlanRes
322323

323324
// Upload the planDir as a single tarball. The workflow cannot pass a
324325
// directory-shaped artifact between steps; we serialize and rely on the
325-
// consumer (renderChunk / assemble) to untar. `audio.aac` lives inside
326+
// consumer (renderChunk / assemble) to untar. The audio artifact lives inside
326327
// planDir, so it already rides along in this tarball — every consumer
327328
// (including assemble) gets it from the untar. We deliberately do NOT
328329
// upload a separate audio object: it would duplicate the bytes on every
@@ -331,7 +332,7 @@ async function handlePlan(event: PlanEvent, deps?: HandlerDeps): Promise<PlanRes
331332
const planTar = join(work, "plan.tar.gz");
332333
await tarDirectory(planDir, planTar);
333334
const planTarUri = `${trimTrailingSlash(event.PlanOutputGcsPrefix)}/plan.tar.gz`;
334-
const audioPath = join(planDir, "audio.aac");
335+
const audioPath = join(planDir, PLAN_AUDIO_RELATIVE_PATH);
335336
const hasAudio = existsSync(audioPath) && statSync(audioPath).size > 0;
336337
await uploadFileToGcs(storage, planTar, planTarUri, "application/gzip");
337338

@@ -397,7 +398,7 @@ async function handlePlanV2(
397398
Width: manifest.width,
398399
Height: manifest.height,
399400
Format: manifest.format,
400-
HasAudio: manifest.artifacts.some((artifact) => artifact.path === "audio.aac"),
401+
HasAudio: manifest.artifacts.some((artifact) => artifact.path === PLAN_AUDIO_RELATIVE_PATH),
401402
AudioGcsUri: null,
402403
FfmpegVersion: manifest.ffmpegVersion,
403404
ProducerVersion: manifest.producerVersion,
@@ -567,7 +568,7 @@ async function handleAssemble(
567568
// only for backward compatibility with an older Plan that uploaded it
568569
// standalone.
569570
let audioPath: string | null = null;
570-
const planAudio = join(planDir, "audio.aac");
571+
const planAudio = join(planDir, PLAN_AUDIO_RELATIVE_PATH);
571572
if (existsSync(planAudio) && statSync(planAudio).size > 0) {
572573
audioPath = planAudio;
573574
} else if (event.AudioGcsUri) {
@@ -619,7 +620,9 @@ async function handleAssembleV2(
619620
const work = mkdtempSync(join(deps?.tmpRoot ?? tmpdir(), "hf-cr-assemble-v2-"));
620621
try {
621622
const planDir = await downloadAndMaterializePlanV2(storage, event, { role: "assembler" }, work);
622-
const audioPath = existsSync(join(planDir, "audio.aac")) ? join(planDir, "audio.aac") : null;
623+
const audioPath = existsSync(join(planDir, PLAN_AUDIO_RELATIVE_PATH))
624+
? join(planDir, PLAN_AUDIO_RELATIVE_PATH)
625+
: null;
623626
const chunkPaths = await downloadChunkObjects(storage, event.ChunkGcsUris, work, event.Format);
624627
const finalOutput =
625628
event.Format === "png-sequence"

‎packages/producer/src/distributed.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ export {
149149
// CLI / adopter SDKs can derive runtime allowlists from one source.
150150
export { PlanVideosMetadataError, type DistributedFormat } from "./services/distributed/shared.js";
151151

152+
// ── Plan artifact names ─────────────────────────────────────────────────────
153+
// The cloud adapters locate and publish the plan's audio artifact by name. Its
154+
// extension selects the container, so they must read it from here rather than
155+
// restate it: a literal that drifts from the writer's is a silently missing
156+
// audio track, not a loud failure.
157+
export { PLAN_AUDIO_RELATIVE_PATH } from "./services/distributed/shared.js";
158+
152159
// ── Plan-time shared types from `freezePlan` ───────────────────────────────
153160
// Re-exported so adopters that deserialize a planDir's `meta/encoder.json`
154161
// or `meta/chunks.json` see the same shapes the producer wrote them as.

0 commit comments

Comments
 (0)