Skip to content

feat(cli): give every preview lifecycle op one JSON document - #3309

Merged
miguel-heygen merged 1 commit into
mainfrom
cli-preview-json-lifecycle
Aug 19, 2026
Merged

feat(cli): give every preview lifecycle op one JSON document#3309
miguel-heygen merged 1 commit into
mainfrom
cli-preview-json-lifecycle

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

--status, --stop, --list and --kill-all emit a schema-versioned envelope with an ok discriminant under --json, from one writer and one failure-payload builder. Human output is unchanged; the JSON path is additive.

{"schemaVersion":1,"operation":"status","ok":true,"result":{"state":"running","mode":"background","port":3002,"pid":1234,...}}
{"schemaVersion":1,"operation":"stop","ok":false,"error":{"code":"preview-stop-failed","message":"..."}}

Why the failure paths are the point

An agent that gets a bare error line on stderr and an empty stdout cannot tell a crash from a "not running". Every failure is a document too — including a missing project, which under --json resolves through the throwing resolver rather than the human-shaped nudge.

Verifying

Start a background preview, then run each of --status, --list, --stop with --json and pipe stdout through a JSON parser: one document each, with the matching operation and state.

Stack

Based on u4b-preview-session-ownership. Retarget to main before merging.

@miguel-heygen
miguel-heygen force-pushed the cli-preview-session-ownership branch from d982ef5 to f68c19a Compare August 18, 2026 05:24
@miguel-heygen
miguel-heygen force-pushed the cli-preview-json-lifecycle branch from 3a42f81 to eea3af8 Compare August 18, 2026 05:26
@miguel-heygen
miguel-heygen force-pushed the cli-preview-session-ownership branch from f68c19a to f8020d2 Compare August 18, 2026 20:46
@miguel-heygen
miguel-heygen force-pushed the cli-preview-json-lifecycle branch from eea3af8 to ff4de31 Compare August 18, 2026 20:46
@miguel-heygen
miguel-heygen force-pushed the cli-preview-session-ownership branch from f8020d2 to 9c7fd17 Compare August 18, 2026 21:43
@miguel-heygen
miguel-heygen force-pushed the cli-preview-json-lifecycle branch from ff4de31 to bd5489b Compare August 18, 2026 22:25
Base automatically changed from cli-preview-session-ownership to main August 18, 2026 23:50
`--status`, `--stop`, `--list` and `--kill-all` emit a schema-versioned
envelope with an `ok` discriminant under `--json`, from one writer and one
failure-payload builder. Human output is unchanged; the JSON path is additive.

The value is in the failure paths. An agent that gets a bare error line on
stderr and an empty stdout cannot tell a crash from a "not running", so every
failure is a document too — including a missing project, which under `--json`
resolves through the throwing resolver rather than the human-shaped nudge.
@miguel-heygen
miguel-heygen marked this pull request as ready for review August 18, 2026 23:50
@miguel-heygen
miguel-heygen force-pushed the cli-preview-json-lifecycle branch from bd5489b to d382a3c Compare August 18, 2026 23:50
@miguel-heygen
miguel-heygen merged commit 0e3c5f6 into main Aug 19, 2026
48 checks passed
@miguel-heygen
miguel-heygen deleted the cli-preview-json-lifecycle branch August 19, 2026 00:07
miguel-heygen added a commit that referenced this pull request Aug 20, 2026
…x bridge (#3349)

Authoring a clip above unity gain throws at runtime today.

## What breaks

`MAX_AUDIO_GAIN_DB = 12` makes `data-volume` legal up to ~3.98. The sandbox runtime's volume bridge assigns the product straight to the element:

```ts
el.volume = clipVolume * volume;   // init.ts, onSetVolume
```

`HTMLMediaElement.volume` is spec-pinned to [0,1] and **throws `IndexSizeError`** outside it — verified in Chrome, and the test DOM agrees:

```
el.volume = 2  →  IndexSizeError: Failed to set the 'volume' property...
```

The throw lands inside a `for` loop over every media element, so it takes the rest of the loop with it: every clip after the boosted one keeps whatever volume it already had, while `state.bridgeVolume` says the change was applied. A composition with one boosted clip stops responding to the volume control for every clip authored after it.

## The fix

Clamp what the element receives. That is not lossy, because the element was never where the boost lived — the transport gets the authored gain unclamped, and this PR pins that half too:

- `syncRuntimeMedia` hands `onElementVolume` both the element's clamped volume **and** the authored gain, so the transport can have the boost the element cannot hold.
- `setElementVolume` keeps that gain on the per-element node, clamped only to `MAX_AUDIO_GAIN`.

Those two paths already worked; they were untested, and they are the reason clamping the element is the right half to clamp.

## Tests

- `init.test.ts` — a boosted clip followed by a quieter one, both seeded with sentinels, then the real `set-volume` control message. Asserts the boosted element lands at 1 **and** that the clip after it still gets its own volume, which is what a throw mid-loop strands.
- `media.test.ts` — the transport receives the authored gain while the element stays legal.
- `webAudioTransport.test.ts` — the per-element gain node keeps a boost above unity.

All three mutation-checked: removing the clamp reds the first, and clamping the gain at either transport seam reds the others.

## Provenance

This is the last unlanded piece of #3280. That PR was rebased onto current `main` and collapsed from +3050 to +944, of which everything except these lines is either already merged (#3308, #3309, #3333, #3339) or duplicated by the open #3306 and #3310. Cutting it out separately because the throw is live on `main` now and shouldn't wait behind a PR that is otherwise redundant.
felipecaldas pushed a commit to felipecaldas/hyperframes that referenced this pull request Aug 20, 2026
…x bridge (heygen-com#3349)

Authoring a clip above unity gain throws at runtime today.

## What breaks

`MAX_AUDIO_GAIN_DB = 12` makes `data-volume` legal up to ~3.98. The sandbox runtime's volume bridge assigns the product straight to the element:

```ts
el.volume = clipVolume * volume;   // init.ts, onSetVolume
```

`HTMLMediaElement.volume` is spec-pinned to [0,1] and **throws `IndexSizeError`** outside it — verified in Chrome, and the test DOM agrees:

```
el.volume = 2  →  IndexSizeError: Failed to set the 'volume' property...
```

The throw lands inside a `for` loop over every media element, so it takes the rest of the loop with it: every clip after the boosted one keeps whatever volume it already had, while `state.bridgeVolume` says the change was applied. A composition with one boosted clip stops responding to the volume control for every clip authored after it.

## The fix

Clamp what the element receives. That is not lossy, because the element was never where the boost lived — the transport gets the authored gain unclamped, and this PR pins that half too:

- `syncRuntimeMedia` hands `onElementVolume` both the element's clamped volume **and** the authored gain, so the transport can have the boost the element cannot hold.
- `setElementVolume` keeps that gain on the per-element node, clamped only to `MAX_AUDIO_GAIN`.

Those two paths already worked; they were untested, and they are the reason clamping the element is the right half to clamp.

## Tests

- `init.test.ts` — a boosted clip followed by a quieter one, both seeded with sentinels, then the real `set-volume` control message. Asserts the boosted element lands at 1 **and** that the clip after it still gets its own volume, which is what a throw mid-loop strands.
- `media.test.ts` — the transport receives the authored gain while the element stays legal.
- `webAudioTransport.test.ts` — the per-element gain node keeps a boost above unity.

All three mutation-checked: removing the clamp reds the first, and clamping the gain at either transport seam reds the others.

## Provenance

This is the last unlanded piece of heygen-com#3280. That PR was rebased onto current `main` and collapsed from +3050 to +944, of which everything except these lines is either already merged (heygen-com#3308, heygen-com#3309, heygen-com#3333, heygen-com#3339) or duplicated by the open heygen-com#3306 and heygen-com#3310. Cutting it out separately because the throw is live on `main` now and shouldn't wait behind a PR that is otherwise redundant.

(cherry picked from commit 9140c0e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant