Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): a local pin strips any backend token from the video mode, and a grok pin translates the clip length

[._.]/ Adam Eivy1632ee05a12f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 9a93f50964..2abb6af4ea 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -117,5 +117,6 @@
- **[issue-3135] A creative commission can now pin the backend that actually renders it — local diffusion, Codex, or Grok — instead of taking whatever the planner happened to pick.** Which backend a scheduled image/video commission rendered on used to be an accidental side effect: the Creative Director's planner LLM writes the render job's parameters freehand, it never set a backend, and so every commission silently landed on local diffusion no matter what you wanted. Image commissions now carry an **Image backend** picker (Auto / Local diffusion / Codex / Grok), video commissions a **Video backend** picker (Auto / Local / Grok), and a music video carries both; pinning Local also lets you name the model to render with. The pin travels to the render itself and overrides the planner, so "this one always renders on Grok" actually holds.
- **Auto is the default and changes nothing.** Every existing commission reads as Auto and resolves your install's Image Gen default exactly as before — same backend, same parameters, byte for byte. Nothing needs migrating and no commission starts spending remote quota it wasn't already spending. Enabling Grok for *images* likewise never redirects your unpinned *video* renders to it, since a Grok clip costs remote quota and only comes in 6- or 10-second lengths.
- A pin is re-checked against your live settings each run rather than trusted blindly: if you later turn off the Codex or Grok toggle in Settings, the affected commission quietly falls back to a backend that works instead of failing every nightly fire. The form says so too — a pin whose backend is currently disabled is flagged in place rather than silently dropped, so you can see why your choice stopped applying.
+- The pin genuinely overrides the planner rather than politely deferring to it: a model you named for Local rendering wins over whatever model the planner wrote, and a backend the planner tried to name is discarded in favour of yours. A Grok-pinned video also gets its clip length translated to a length Grok actually delivers, rounding up — so a 10-second commission renders a 10-second clip instead of silently falling to Grok's 6-second minimum.
- Commissions federate, so the pin syncs across your machines; the commission sync version was raised to keep an older peer from silently stripping the field and pushing the un-pinned version back.
>>>>>>> f8a772e60 (feat: let a creative commission pin the backend that renders it (#3135))
diff --git a/server/lib/README.md b/server/lib/README.md
index fd704d9c5b..0059e28b87 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -106,7 +106,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `cliProviderArgs.js` | Per-CLI argv conventions (`buildCliArgs`) for stdin prompt delivery — dependency-light extraction from runner.js so out-of-process callers (autofixer) can import it. |
| `cliProviderRun.js` | One-shot CLI provider invocation (`pickCliProvider` + `runCliProviderPrompt`) — lightweight path for the autofixer + calendar MCP sync to honor the configured provider/model. |
| `grok.js` | xAI Grok Build (`grok`) provider helpers — id/endpoint constants (`GROK_API_ID`/`GROK_CLI_ID`/`GROK_TUI_ID`/`GROK_API_ENDPOINT`), `isGrokCommand`/`isGrokCliProvider`/`isGrokTuiProvider` predicates, `ensureGrokHeadlessArgs`/`ensureGrokTuiArgs` argv builders (grok reads its prompt from `--prompt-file /dev/stdin`, not raw stdin; model selection uses the `GROK_CONFIGURED_DEFAULT` sentinel in `providerModels.js` so PortOS omits `--model` like Antigravity), and `prepareGrokPromptFile` (Windows temp-file delivery fallback). |
-| `grokVideoClip.js` | Clip lengths grok's `image_to_video` actually delivers — `GROK_VIDEO_DURATIONS` (`[6, 10]`, measured in #3022: a 2s/3s request returns the same 6.04s clip), `GROK_VIDEO_DEFAULT_DURATION`, and `resolveGrokDuration()`. Dependency-free so `validation.js` / `routes/videoGen.js` can derive their schemas from the same list the services gate on. |
+| `grokVideoClip.js` | Clip lengths grok's `image_to_video` actually delivers — `GROK_VIDEO_DURATIONS` (`[6, 10]`, measured in #3022: a 2s/3s request returns the same 6.04s clip), `GROK_VIDEO_DEFAULT_DURATION`, `resolveGrokDuration()` (validate an already-grok-shaped request, else default), and `nearestGrokDuration()` (round a length authored against another backend's continuous contract UP to the shortest clip that covers it — for translating a CD/commission `targetDurationSeconds`). Dependency-free so `validation.js` / `routes/videoGen.js` can derive their schemas from the same list the services gate on. |
| `kimi.js` | Moonshot AI Kimi Code (`kimi`) provider helpers — id constants (`KIMI_CLI_ID`/`KIMI_TUI_ID`), `isKimiCommand`/`isKimiCliProvider`/`isKimiTuiProvider` predicates, `ensureKimiHeadlessArgs` (`--print`, implies `--afk`) / `ensureKimiTuiArgs` (`--yolo`) argv builders (model selection uses the `KIMI_CONFIGURED_DEFAULT` sentinel in `providerModels.js` so PortOS omits `--model` like Grok/Antigravity), and `prepareKimiPrompt` (delivers the prompt as the `--prompt <value>` argv, not stdin). |
| `runners.js` | Image-runner family constants. |
| `codexAssistantExtract.js` | Strip Codex CLI banner + echoed metadata from session transcript. |
diff --git a/server/lib/grokVideoClip.js b/server/lib/grokVideoClip.js
index 41fce9c050..44c2d9d683 100644
--- a/server/lib/grokVideoClip.js
+++ b/server/lib/grokVideoClip.js
@@ -52,3 +52,25 @@ export const resolveGrokDuration = (requested) => {
const n = Number(requested);
return GROK_VIDEO_DURATIONS.includes(n) ? n : GROK_VIDEO_DEFAULT_DURATION;
};
+
+/**
+ * The shortest deliverable length that still COVERS `requested`, for callers
+ * translating a target duration authored against another backend's contract
+ * (#3135: the Creative Director planner and the commission's
+ * `targetDurationSeconds` are written in local-lane seconds, which are
+ * continuous).
+ *
+ * Distinct from `resolveGrokDuration`, which validates an ALREADY-grok-shaped
+ * request and defaults anything else to 6s: that's correct at the route boundary
+ * (the picker only offers 6/10, so a third value is bad input), but wrong when
+ * translating — an 8-second brief would silently become 6s and truncate the
+ * beat. Rounds UP because there is no cost or render-time saving at a shorter
+ * clip (see the measurement note above), so covering the request is free; a
+ * request beyond the longest clip clamps to that longest.
+ */
+export const nearestGrokDuration = (requested) => {
+ if (typeof requested !== 'number' && typeof requested !== 'string') return GROK_VIDEO_DEFAULT_DURATION;
+ const n = Number(requested);
+ if (!Number.isFinite(n) || n <= 0) return GROK_VIDEO_DEFAULT_DURATION;
+ return GROK_VIDEO_DURATIONS.find((d) => d >= n) ?? GROK_VIDEO_DURATIONS[GROK_VIDEO_DURATIONS.length - 1];
+};
diff --git a/server/lib/grokVideoClip.test.js b/server/lib/grokVideoClip.test.js
index 97ea9f4350..94eeee1f66 100644
--- a/server/lib/grokVideoClip.test.js
+++ b/server/lib/grokVideoClip.test.js
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';
import {
- GROK_VIDEO_DURATIONS, GROK_VIDEO_DEFAULT_DURATION, resolveGrokDuration,
+ GROK_VIDEO_DURATIONS, GROK_VIDEO_DEFAULT_DURATION, resolveGrokDuration, nearestGrokDuration,
} from './grokVideoClip.js';
describe('grokVideoClip', () => {
@@ -43,6 +43,43 @@ describe('grokVideoClip', () => {
});
});
+describe('nearestGrokDuration — translating another backend\'s continuous length (#3135)', () => {
+ it('rounds UP to the shortest clip that covers the request', () => {
+ // Rounding down would truncate the beat, and there is no render-time or cost
+ // saving at a shorter clip, so covering the request is free.
+ expect(nearestGrokDuration(1)).toBe(6);
+ expect(nearestGrokDuration(6)).toBe(6);
+ expect(nearestGrokDuration(7)).toBe(10);
+ expect(nearestGrokDuration(8)).toBe(10);
+ expect(nearestGrokDuration(10)).toBe(10);
+ });
+
+ it('clamps a request longer than the longest clip', () => {
+ expect(nearestGrokDuration(30)).toBe(10);
+ expect(nearestGrokDuration(600)).toBe(10);
+ });
+
+ it('accepts a numeric string', () => {
+ expect(nearestGrokDuration('8')).toBe(10);
+ });
+
+ it.each([
+ ['zero', 0], ['a negative', -6], ['a non-numeric string', 'six'],
+ ['null', null], ['undefined', undefined], ['NaN', NaN],
+ ['a non-scalar', [8]],
+ ])('falls back to the default for %s', (_label, input) => {
+ expect(nearestGrokDuration(input)).toBe(GROK_VIDEO_DEFAULT_DURATION);
+ });
+
+ it('differs from resolveGrokDuration exactly where it should', () => {
+ // resolveGrokDuration VALIDATES an already-grok-shaped request (a third value
+ // is bad input at the route boundary); nearestGrokDuration TRANSLATES a
+ // continuous one. 8s must not silently become 6s.
+ expect(resolveGrokDuration(8)).toBe(6);
+ expect(nearestGrokDuration(8)).toBe(10);
+ });
+});
+
describe('grokVideoClip client mirror', () => {
it('matches client/src/lib/grokVideoClip.js', async () => {
// The walk workflow's Clip picker builds its options from the client mirror,
diff --git a/server/services/creative/tools/media.js b/server/services/creative/tools/media.js
index a6bab28fba..33070f80de 100644
--- a/server/services/creative/tools/media.js
+++ b/server/services/creative/tools/media.js
@@ -10,7 +10,8 @@ import { ASPECT_PRESETS, QUALITY_PRESETS, presetToRenderParams } from '../../../
import { getSettings } from '../../settings.js';
import { IMAGE_GEN_MODE, resolveQueueImageMode } from '../../imageGen/modes.js';
import { resolveCloudProviderConfig } from '../../imageGen/cloudProviderConfig.js';
-import { VIDEO_GEN_MODE, resolveVideoMode } from '../../videoGen/modes.js';
+import { VIDEO_GEN_MODE, VIDEO_GEN_MODES, resolveVideoMode } from '../../videoGen/modes.js';
+import { nearestGrokDuration } from '../../../lib/grokVideoClip.js';
import { COST_RENDER, resolveOwner } from './shared.js';
const paramsSchema = z.object({ params: z.record(z.any()).default({}), owner: z.string().optional() });
@@ -127,16 +128,21 @@ async function enforceRenderBackendPin(kind, params, project) {
const mode = resolveVideoMode(pin.mode, settings);
if (mode !== VIDEO_GEN_MODE.GROK) {
// Local video: `params.mode` is the t2v/i2v SEMANTIC for this lane (see
- // videoGen/modes.js), so it must NOT be stamped with the backend name —
- // the absence of the 'grok' discriminator IS "render locally", and
- // overwriting a real semantic ('fflf', 'a2v', 'extend', an IC-LoRA id)
- // would silently drop the caller's keyframes/audio. But the discriminator
- // and the semantic share this one key, so a planner-authored `mode: 'grok'`
- // must be STRIPPED or the queue would dispatch to grok in defiance of the
- // pin (and of the grok-disabled fallback). Dropping it lets local.js infer
- // the semantic from `sourceImagePath`, which is what an unset mode means.
- const { mode: authored, ...rest } = params || {};
- const base = authored === VIDEO_GEN_MODE.GROK ? rest : (params || {});
+ // videoGen/modes.js), so a local pin must NOT stamp the backend name over
+ // it — overwriting a real semantic ('fflf', 'a2v', 'extend', an IC-LoRA id)
+ // would silently drop the caller's keyframes/audio.
+ //
+ // But the backend discriminator and the semantic SHARE this one key, so a
+ // planner-authored BACKEND token has to go: 'grok' would dispatch to grok
+ // in defiance of the pin (and defeat the grok-disabled fallback), and
+ // 'local' is worse than useless — local.js treats an unrecognized non-empty
+ // mode as plain text-to-video, so it would silently ignore the step's
+ // sourceImagePath/keyframes. Dropping the key entirely is the correct
+ // repair for both: an unset mode makes local.js INFER the semantic from
+ // keyframes → sourceImagePath → text.
+ const base = VIDEO_GEN_MODES.includes(params?.mode)
+ ? (({ mode: _backendToken, ...rest }) => rest)(params)
+ : (params || {});
// The user's pinned model wins over the planner's freehand guess — that
// asymmetry is the whole point of a pin.
return pin.modelId ? { ...base, modelId: pin.modelId } : base;
@@ -145,11 +151,23 @@ async function enforceRenderBackendPin(kind, params, project) {
// videoGen/grok.js reads the same `imageGen.grok` slice the image path does
// (one CLI, one config). `videoMode` carries the semantic the local lane
// keeps in `mode`, matching what routes/videoGen.js enqueues.
+ //
+ // Clip length crosses a contract boundary here: the local lane derives frame
+ // count from `durationSeconds` (which is what the planner writes and what
+ // enforceVideoRenderPreset reconciles), while grok's worker reads `duration`
+ // and silently falls back to 6s for anything absent or undeliverable. Without
+ // the translation a 10s commission would quietly render a 6s clip. Prefer an
+ // explicit `duration` if some caller already set one; else map the step's
+ // durationSeconds, else the project's target, through grok's own
+ // 6/10-only normalization (lib/grokVideoClip.js) so we snap the same way the
+ // provider would rather than passing a length it can't deliver.
+ const requestedSeconds = params?.duration ?? params?.durationSeconds ?? project?.targetDurationSeconds;
return {
...params,
mode: VIDEO_GEN_MODE.GROK,
videoMode: params?.sourceImagePath ? 'image' : 'text',
grokPath: grok.grokPath,
+ duration: nearestGrokDuration(requestedSeconds),
...(grok.aspectRatio ? { aspectRatio: grok.aspectRatio } : {}),
};
}
diff --git a/server/services/creative/tools/media.test.js b/server/services/creative/tools/media.test.js
index 8ac6d94c16..7e03d45d4b 100644
--- a/server/services/creative/tools/media.test.js
+++ b/server/services/creative/tools/media.test.js
@@ -143,14 +143,19 @@ describe('render-backend pin — video (#3135)', () => {
expect(enqueued().params.modelId).toBe('pinned-video-model');
});
- it('STRIPS a planner-authored grok discriminator when the pin says local', async () => {
- // The discriminator and the t2v/i2v semantic share `params.mode`, so leaving
- // a planner-written 'grok' in place would dispatch to grok in defiance of the
- // pin. Dropping it lets local.js infer the semantic (= what an unset mode means).
+ it('STRIPS a planner-authored BACKEND token from `mode` when the pin says local', async () => {
+ // The discriminator and the t2v/i2v semantic share `params.mode`. A leftover
+ // 'grok' would dispatch to grok in defiance of the pin; a leftover 'local' is
+ // worse than useless — local.js reads an unrecognized non-empty mode as plain
+ // text-to-video and would silently ignore the step's sourceImagePath. Dropping
+ // the key lets local.js INFER the semantic, which is what an unset mode means.
getSettings.mockResolvedValue({ imageGen: {} });
getProject.mockResolvedValue(projectWithPin({ video: { mode: 'local' } }));
- await run('media_enqueueVideoJob', { prompt: 'p', mode: 'grok' }, { projectId: 'cd-1' });
- expect(enqueued().params).toEqual({ prompt: 'p' });
+
+ for (const backendToken of ['grok', 'local']) {
+ await run('media_enqueueVideoJob', { prompt: 'p', mode: backendToken, sourceImagePath: '/tmp/f.png' }, { projectId: 'cd-1' });
+ expect(enqueued().params).toEqual({ prompt: 'p', sourceImagePath: '/tmp/f.png' });
+ }
});
it('degrades a grok video pin to local when the grok toggle is off — and strips the discriminator', async () => {
@@ -172,6 +177,41 @@ describe('render-backend pin — video (#3135)', () => {
expect(enqueued().params.modelId).toBe('pinned-video-model');
});
+ describe('grok clip length crosses a contract boundary', () => {
+ // The local lane derives frames from `durationSeconds`; grok's worker reads
+ // `duration` and silently falls back to 6s for anything absent. Without the
+ // translation a 10s commission would quietly render a 6s clip.
+ beforeEach(() => {
+ getSettings.mockResolvedValue({ imageGen: { grok: { enabled: true, grokPath: '/bin/grok' } } });
+ });
+
+ it('translates the step durationSeconds, rounding up to a deliverable clip', async () => {
+ getProject.mockResolvedValue(projectWithPin({ video: { mode: 'grok' } }));
+ await run('media_enqueueVideoJob', { prompt: 'p', durationSeconds: 8 }, { projectId: 'cd-1' });
+ // 8s isn't deliverable; rounding DOWN to 6 would truncate the beat, and a
+ // longer clip costs nothing extra.
+ expect(enqueued().params.duration).toBe(10);
+ });
+
+ it("falls back to the project's target duration when the step names none", async () => {
+ getProject.mockResolvedValue({ id: 'cd-1', targetDurationSeconds: 10, renderBackend: { video: { mode: 'grok' } } });
+ await run('media_enqueueVideoJob', { prompt: 'p' }, { projectId: 'cd-1' });
+ expect(enqueued().params.duration).toBe(10);
+ });
+
+ it('prefers an explicit grok-shaped duration a caller already set', async () => {
+ getProject.mockResolvedValue({ id: 'cd-1', targetDurationSeconds: 10, renderBackend: { video: { mode: 'grok' } } });
+ await run('media_enqueueVideoJob', { prompt: 'p', duration: 6, durationSeconds: 10 }, { projectId: 'cd-1' });
+ expect(enqueued().params.duration).toBe(6);
+ });
+
+ it('defaults to the shortest clip when nothing names a length', async () => {
+ getProject.mockResolvedValue(projectWithPin({ video: { mode: 'grok' } }));
+ await run('media_enqueueVideoJob', { prompt: 'p' }, { projectId: 'cd-1' });
+ expect(enqueued().params.duration).toBe(6);
+ });
+ });
+
it('applies the video pin alongside the locked geometry preset', async () => {
getSettings.mockResolvedValue({ imageGen: { grok: { enabled: true, grokPath: '/bin/grok' } } });
getProject.mockResolvedValue({