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

fix: handle fal privacy prompt before scene render

[._.]/ Adam Eivy55c1f3b9c592
diff --git a/docs/features/fableloom.md b/docs/features/fableloom.md
index 98cc048f07..4c13239a85 100644
--- a/docs/features/fableloom.md
+++ b/docs/features/fableloom.md
@@ -261,7 +261,7 @@ a final beat that hands cleanly to the next node.
For scenes utilizing fal.ai's free MiniMax H3 Max web tool, PortOS provides automated, serialized video production (`POST /api/fableloom/:id/episodes/:episodeId/nodes/:nodeId/fal-video`):
- **Serialized runner** (`server/services/fableLoom/falVideoAutomation.js`): jobs execute sequentially against PortOS's persistent Chrome CDP browser (`http://localhost:5556`) so concurrent triggers do not overwrite the single web form.
-- **Workflow**: Playwright fills the scene's prompt and camera direction, uploads the scene's current approved storyboard still, triggers generation, monitors progress, and downloads the finished MP4 via authenticated browser context requests.
+- **Workflow**: Playwright waits for fal.ai's asynchronously injected privacy choice, prefers the privacy-preserving **Reject All** choice when it is shown, then fills the scene's prompt and camera direction, uploads the scene's current approved storyboard still, triggers generation, monitors progress, and downloads the finished MP4 via authenticated browser context requests.
- **Durable attachment**: The downloaded clip is saved directly into PortOS Media History and attached to the scene node via `attachNodeVideo`. If the scene image changed while rendering, the video is safely preserved in Media History without overwriting the drifted scene.
- **Status & polling**: `GET /api/fableloom/:id/episodes/:episodeId/nodes/:nodeId/fal-video/:jobId` provides real-time progress, error diagnostics (such as CAPTCHA challenges or daily allowance limits requiring user action), and completion metadata.
diff --git a/server/services/fableLoom/falVideoAutomation.js b/server/services/fableLoom/falVideoAutomation.js
index d0dc790f5c..ab6e54e6e8 100644
--- a/server/services/fableLoom/falVideoAutomation.js
+++ b/server/services/fableLoom/falVideoAutomation.js
@@ -26,6 +26,8 @@ export const FAL_H3_MAX_FREE_URL = 'https://fal.ai/tools/minimax-h3-max';
const FAL_RENDER_TIMEOUT_MS = 20 * 60 * 1000;
const FAL_CONTROL_TIMEOUT_MS = 2 * 60 * 1000;
const FAL_RESULT_POLL_MS = 2000;
+const FAL_PRIVACY_SETTLE_MS = 1500;
+const FAL_PRIVACY_LATE_CHECK_MS = 250;
const FAL_JOB_TTL_MS = 24 * 60 * 60 * 1000;
const ACTIVE_STATUSES = new Set(['queued', 'running']);
const FAL_ASPECT_RATIOS = new Set(['16:9', '9:16', '1:1']);
@@ -83,6 +85,30 @@ const falAspectRatio = (requested) => {
return '16:9';
};
+/**
+ * Dismisses fal.ai's asynchronously injected privacy-choice modal when present.
+ *
+ * The persistent browser profile remembers a prior choice. When no choice is
+ * stored, fal.ai can render the tool controls before the modal arrives, so the
+ * caller gives the CMP a short settle window before touching the form. Reject
+ * All keeps this user-triggered automation from silently opting into tracking.
+ *
+ * @param {import('playwright-core').Page} page - Active Playwright page.
+ * @param {object} [options] - Visibility wait options.
+ * @param {number} [options.waitMs=0] - Maximum time to wait for the choice.
+ * @returns {Promise<boolean>} Whether a visible privacy prompt was dismissed.
+ */
+const dismissFalPrivacyConsent = async (page, { waitMs = 0 } = {}) => {
+ const rejectAll = page.getByRole('button', { name: 'Reject All', exact: true }).first();
+ const visible = waitMs > 0
+ ? await rejectAll.waitFor({ state: 'visible', timeout: waitMs }).then(() => true).catch(() => false)
+ : await rejectAll.isVisible().catch(() => false);
+ if (!visible) return false;
+ await rejectAll.click({ timeout: FAL_CONTROL_TIMEOUT_MS });
+ await rejectAll.waitFor({ state: 'hidden', timeout: FAL_CONTROL_TIMEOUT_MS });
+ return true;
+};
+
/**
* Resolves the active Chrome DevTools Protocol endpoint URL for the PortOS Browser.
*
@@ -300,6 +326,10 @@ const executeJob = async (job) => {
const imageInput = page.locator('input[type="file"][accept*="image"]').first();
setJobProgress(job, 'Waiting for fal.ai controls…', 0.12);
await promptInput.waitFor({ state: 'visible', timeout: FAL_CONTROL_TIMEOUT_MS });
+ // The privacy-choice UI is injected after the tool controls become
+ // visible. Let it settle before filling the form so its overlay cannot
+ // clear the prompt or intercept the eventual Generate click.
+ await dismissFalPrivacyConsent(page, { waitMs: FAL_PRIVACY_SETTLE_MS });
setJobProgress(job, 'Uploading the scene image to fal.ai…', 0.15);
await imageInput.setInputFiles(imagePath, { timeout: FAL_CONTROL_TIMEOUT_MS });
@@ -314,6 +344,9 @@ const executeJob = async (job) => {
// video. Snapshot it before submitting so that only a new result URL can
// satisfy this job.
const previousSourceUrl = await readVideoSource(resultVideo);
+ // Re-check immediately before submission in case the CMP appeared during
+ // the upload/fill sequence rather than during the initial settle window.
+ await dismissFalPrivacyConsent(page, { waitMs: FAL_PRIVACY_LATE_CHECK_MS });
await generate.click({ timeout: FAL_CONTROL_TIMEOUT_MS });
setJobProgress(job, 'Generating the scene video on fal.ai…', 0.3);
diff --git a/server/services/fableLoom/falVideoAutomation.test.js b/server/services/fableLoom/falVideoAutomation.test.js
index d5fb1bcaa8..a4206d5a3a 100644
--- a/server/services/fableLoom/falVideoAutomation.test.js
+++ b/server/services/fableLoom/falVideoAutomation.test.js
@@ -51,6 +51,7 @@ const makeBrowser = ({
errorTexts = [],
gotoError = null,
hiddenChallengeFrame = false,
+ privacyConsent = false,
previousVideoUrl = '',
resultVideoUrl = 'https://v3.fal.media/files/example.mp4',
} = {}) => {
@@ -73,6 +74,19 @@ const makeBrowser = ({
click: vi.fn(async () => {}),
waitFor: vi.fn(async () => {}),
}]));
+ let consentVisible = privacyConsent;
+ const privacy = {
+ click: vi.fn(async () => { consentVisible = false; }),
+ first: vi.fn(),
+ isVisible: vi.fn(async () => consentVisible),
+ waitFor: vi.fn(async ({ state }) => {
+ if ((state === 'visible' && !consentVisible) || (state === 'hidden' && consentVisible)) {
+ throw new Error(`privacy prompt is not ${state}`);
+ }
+ }),
+ };
+ privacy.first.mockReturnValue(privacy);
+ const setPrivacyConsent = (visible) => { consentVisible = visible; };
const apiResponse = {
body: vi.fn(async () => Buffer.from('example mp4 bytes')),
dispose: vi.fn(async () => {}),
@@ -83,7 +97,7 @@ const makeBrowser = ({
const request = { get: vi.fn(async () => apiResponse) };
const page = {
close: vi.fn(async () => {}),
- getByRole: vi.fn((_role, { name }) => controls.get(name)),
+ getByRole: vi.fn((_role, { name }) => name === 'Reject All' ? privacy : controls.get(name)),
goto: gotoError ? vi.fn(async () => { throw gotoError; }) : vi.fn(async () => {}),
locator: vi.fn((selector) => {
if (selector.startsWith('textarea')) return prompt;
@@ -107,7 +121,9 @@ const makeBrowser = ({
contexts: vi.fn(() => [context]),
};
mocks.connectOverCDP.mockResolvedValue(browser);
- return { apiResponse, browser, context, controls, image, page, prompt, request, video };
+ return {
+ apiResponse, browser, context, controls, image, page, privacy, prompt, request, setPrivacyConsent, video,
+ };
};
const waitForTerminalJob = async (job) => {
@@ -174,6 +190,23 @@ describe('FableLoom fal.ai browser automation', () => {
expect(mocks.browserClose).toHaveBeenCalledTimes(1);
});
+ it('dismisses a privacy prompt that appears after controls load before filling the scene', async () => {
+ const { page, privacy, prompt, setPrivacyConsent } = makeBrowser();
+ privacy.waitFor.mockImplementationOnce(async ({ state, timeout }) => {
+ expect(state).toBe('visible');
+ expect(timeout).toBe(1500);
+ setPrivacyConsent(true);
+ });
+ const queued = await startFalVideoAutomation('loom-1', 'ep-1', 'node-1', {
+ prompt: 'The example door opens.', aspectRatio: '16:9',
+ });
+
+ await expect(waitForTerminalJob(queued)).resolves.toMatchObject({ status: 'completed' });
+ expect(privacy.click).toHaveBeenCalledTimes(1);
+ expect(privacy.click.mock.invocationCallOrder[0]).toBeLessThan(prompt.fill.mock.invocationCallOrder[0]);
+ expect(page.getByRole).toHaveBeenCalledWith('button', { name: 'Reject All', exact: true });
+ });
+
it('coalesces repeated clicks for one scene instead of spending the free allowance twice', async () => {
makeBrowser();
let resolveLookup;