8000 docs: SESSION-mode README rewrite + IndexedDB upgrade-hang fix by johannboehme · Pull Request #28 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .github/screenshots/01-upload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/screenshots/02-jobs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/screenshots/03-job-detail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/screenshots/04-editor-sync.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/screenshots/05-editor-options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/screenshots/06-editor-overlays.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/screenshots/07-editor-export.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/screenshots/08-editor-help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/screenshots/09-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/screenshots/arrange-filmstrip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/screenshots/editor-sync.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/screenshots/fx-hardware-panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/screenshots/triage-rack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
333 changes: 194 additions & 139 deletions README.md

Large diffs are not rendered by default.

124 changes: 98 additions & 26 deletions frontend/scripts/readme-screenshots.mjs
10BC8
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// One-shot script that drives a real Chromium and captures the README screenshots.
// Uses the bundled test fixtures to create a real synced job, then walks every panel.
// Used only for repo asset generation; not part of the build.
// Uses the bundled test fixtures to create a real long-form session job, then
// walks every panel referenced from the README. Used only for repo asset
// generation; not part of the build.
//
// Usage:
// npm run dev # in another terminal
// node scripts/readme-screenshots.mjs # writes to ../.github/screenshots/
import { chromium } from "playwright";
import { mkdir } from "node:fs/promises";
import { dirname, join, resolve } from "node:path";
Expand All @@ -27,11 +32,11 @@ const base = process.env.VAS_BASE_URL ?? "http://localhost:5173";
const browser = await chromium.launch({
args: ["--enable-features=SharedArrayBuffer"],
});
// PNGs are kept ≤ 2000 px on the long side so chat tools that have an
// image-dimension cap can read them. Viewport drives PNG width directly
// when deviceScaleFactor = 1.
// Viewport tall enough that the upload page's DIRECT/SESSION routing
// cards land in-frame for the hero shot. PNGs stay ≤ 2000 px on the long
// side so chat tools that have an image-dimension cap can read them.
const ctx = await browser.newContext({
viewport: { width: 1440, height: 900 },
viewport: { width: 1440, height: 1100 },
deviceScaleFactor: 1,
});

Expand All @@ -53,11 +58,20 @@ await ctx.addInitScript(() => {
}
});

// Force the legacy `<input type=file>` picker path so Playwright's
// `filechooser` event can intercept the upload dialog. The native
// `showOpenFilePicker()` opens an OS file dialog that can't be controlled
// from automation. file-picker.ts already has a clean fallback when this
// global is absent.
await ctx.addInitScript(() => {
delete window.showOpenFilePicker;
});

const page = await ctx.newPage();

async function shot(path, { wait = 600 } = {}) {
async function shot(path, { wait = 600, fullPage = false } = {}) {
await page.waitForTimeout(wait);
await page.screenshot({ path: join(outDir, path), type: "png", fullPage: false });
await page.screenshot({ path: join(outDir, path), type: "png", fullPage });
console.log("✓", path);
}

Expand All @@ -66,49 +80,107 @@ async function gotoShot(path, url, opts) {
await shot(path, opts);
}

// ─── empty pages ───────────────────────────────────────────────────────────
await gotoShot("01-upload.png", "/");

// ─── upload + sync to create a real job ────────────────────────────────────
// ─── empty hero ────────────────────────────────────────────────────────────
// Upload page in its empty state, full page so the DIRECT / SESSION routing
// cards land in-frame underneath the dropzones.
await gotoShot("01-upload.png", "/", { fullPage: true });

// ─── upload + sync via the SESSION (longform) routing card ─────────────────
// SESSION builds a real long-form job so /triage and /arrange render with
// chunks/Polaroids instead of empty states. (DIRECT mode still works the
// same — handleSubmit just sets job.mode and sync runs either way.)
//
// The picker is now capability-aware: it dispatches a real `<input>` click
// (we forced that path above by deleting `showOpenFilePicker`), so we use
// Playwright's `filechooser` event to intercept and set the files.
console.log("uploading fixtures…");
await page.setInputFiles("#picker-audio", audioPath);
await page.setInputFiles("#picker-videos", videoPaths);
const audioChooser = page.waitForEvent("filechooser");
await page.locator("#picker-audio").click();
await (await audioChooser).setFiles(audioPath);

const videoChooser = page.waitForEvent("filechooser");
await page.locator("#picker-videos").click();
await (await videoChooser).setFiles(videoPaths);
await page.waitForTimeout(300);
await page.getByRole("button", { name: /sync.*open editor/i }).click();

// Wait for sync to complete — JobPage renders quick-render/open-editor buttons.
console.log("entering SESSION mode…");
await page.getByRole("button", { name: /Have an hour/i }).click();

// JobPage shows up first; sync runs there. The 5-stage pipeline can take
// a while on first run (vite dev cold-cache + WASM init + envelope/chroma/
// PHAT/consensus/drift); give it a generous window. We wait for the post-
// sync action buttons ("Quick render", "Continue → Triage", or "Open editor")
// since those only render once `hasSyncData` flips true.
console.log("waiting for sync…");
await page.waitForURL(/\/job\/[^/]+$/, { timeout: 30_000 });
await page.waitForSelector("text=/quick render/i", { timeout: 30_000 });
// LongformStageButtons surfaces stage names (TRIAGE / ARRANGE / EDITOR)
// directly; DIRECT mode shows "Quick render" + "Open editor". Match either.
await page.waitForSelector(
"text=/quick render|^triage$|^arrange$|^editor$|open editor/i",
{ timeout: 120_000 },
);
const jobUrl = page.url();
const jobId = jobUrl.match(/\/job\/([^/?#]+)/)[1];
console.log("synced →", jobId);

// History (now has one job)
// History (now has the long-form job)
await gotoShot("02-jobs.png", "/jobs");

// Job detail (sync results)
// Job detail (sync results — confidence + sharpness numbers + per-cam offsets)
await gotoShot("03-job-detail.png", `/job/${jobId}`);

// Editor — sync tuner with knob (after picking CAM 1)
// ─── Triage rack ───────────────────────────────────────────────────────────
// Chunk detection runs on Triage mount; wait for the ChunksList to populate
// before screenshotting the rack.
console.log("opening triage…");
await page.goto(`${base}/job/${jobId}/triage`, { waitUntil: "networkidle" });
await page.waitForSelector("text=/CHUNKS/i", { timeout: 30_000 });
await page.waitForTimeout(2_000); // let detection settle + waveform render
await shot("triage-rack.png");

// ─── Arrange film strip ────────────────────────────────────────────────────
// First-mount of Arrange seeds arrangement = triage.kept, which gives the
// FilmStrip + ContactSheet content to render.
console.log("opening arrange…");
await page.goto(`${base}/job/${jobId}/arrange`, { waitUntil: "networkidle" });
await page.waitForSelector("text=/CHUNKS/i", { timeout: 15_000 });
await page.waitForTimeout(2_000); // let Polaroids develop
await shot("arrange-filmstrip.png");

// ─── Editor — SYNC tab (USER OVERRIDE knob, NUDGE MS row, MATCH lane) ─────
console.log("opening editor…");
await page.goto(`${base}/job/${jobId}/edit`, { waitUntil: "networkidle" });
await page.waitForTimeout(2000);
await page.waitForTimeout(2_500);
await page.getByRole("button", { name: /^cam 1$/i }).first().click().catch(() => {});
await shot("04-editor-sync.png", { wait: 600 });
await shot("editor-sync.png", { wait: 600 });
// Keep legacy filename for backwards-compat with any external links.
await shot("04-editor-sync.png", { wait: 0 });

// Options
// Options tab — per-clip viewport / rotate / flip
await page.getByRole("tab", { name: /options/i }).click().catch(() => {});
await shot("05-editor-options.png", { wait: 500 });

// Overlays
// Overlays tab
await page.getByRole("tab", { name: /overlays/i }).click().catch(() => {});
await shot("06-editor-overlays.png", { wait: 500 });

// Export
// Export tab — Stage presets (WEB / MOBILE / ARCHIVE / CUSTOM) + quality slider
await page.getByRole("tab", { name: /export/i }).click().catch(() => {});
await shot("07-editor-export.png", { wait: 500 });

// Help overlay (Shift+/ -> "?")
// ─── FX hardware panel + ADSR envelope ────────────────────────────────────
// Re-show the SYNC tab so the right rail doesn't dominate the frame, then
// expand the FX panel and flip the LCD into envelope mode so the phosphor
// trapezoid + four knots are visible.
console.log("opening FX panel…");
await page.getByRole("tab", { name: /sync/i }).click().catch(() => {});
await page.waitForTimeout(300);
await page.getByRole("button", { name: /show fx panel/i }).click().catch(() => {});
await page.waitForTimeout(600);
await page.getByRole("button", { name: /show envelope/i }).click().catch(() => {});
await shot("fx-hardware-panel.png", { wait: 800 });

// Help overlay (Shift+/ → "?")
await page.locator("body").click({ position: { x: 400, y: 400 } });
await page.keyboard.press("Shift+/");
await shot("08-editor-help.png", { wait: 500 });
Expand Down
75 changes: 74 additions & 1 deletion frontend/src/storage/jobs-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,28 @@ const CHUNK_THUMBS_STORE = "chunk-thumbnails";
const CHUNK_MELS_STORE = "chunk-mel-specs";

let dbPromise: Promise<IDBPDatabase> | null = null;
let dbInstance: IDBPDatabase | null = null;

// Safety net for the IndexedDB upgrade-blocked deadlock: when an older TK-1
// tab without `blocking`/`blocked` handlers holds the previous schema version
// open, a fresh tab on a newer DB_VERSION can sit on `openDB(...)` forever
// because the older connection never responds to `versionchange`. We give the
// browser a few seconds to fire `blocked`, and if even that doesn't surface
// (some older Chromium builds), the timeout below ensures we reject with an
// actionable message rather than an infinite "Loading…".
const OPEN_TIMEOUT_MS = 5000;

function db(): Promise<IDBPDatabase> {
if (!dbPromise) {
dbPromise = openDB(DB_NAME, DB_VERSION, {
let externalReject: ((err: Error) => void) | null = null;
let cancelled = false;
let timeoutId: ReturnType<typeof setTimeout> | null = null;

const externalFailure = new Promise<never>((_, reject) => {
externalReject = reject;
});

const openPromise = openDB(DB_NAME, DB_VERSION, {
async upgrade(database, oldVersion, _newVersion, tx) {
if (!database.objectStoreNames.contains(STORE)) {
const store = database.createObjectStore(STORE, { keyPath: "id" });
Expand Down Expand Up @@ -602,7 +620,62 @@ function db(): Promise<IDBPDatabase> {
}
}
},
blocked(currentVersion, blockedVersion) {
cancelled = true;
dbPromise = null;
if (timeoutId !== null) clearTimeout(timeoutId);
externalReject?.(
new Error(
`TK-1 needs to upgrade its local store from v${currentVersion} to ` +
`v${blockedVersion ?? DB_VERSION}, but another TK-1 tab is still open ` +
`at the older version. Close every other TK-1 tab and reload.`,
),
);
},
blocking() {
// Another tab wants to upgrade to a newer schema. Drop our connection
// so its `openDB(...)` can proceed; the next `db()` call here will
// re-open at the new version.
dbInstance?.close();
dbInstance = null;
dbPromise = null;
},
terminated() {
// Browser-side close (DB deleted, storage quota, etc.). Reset so the
// next call opens a fresh connection.
dbInstance = null;
dbPromise = null;
},
});

timeoutId = setTimeout(() => {
cancelled = true;
dbPromise = null;
externalReject?.(
new Error(
`TK-1 couldn't open its local store within ${OPEN_TIMEOUT_MS}ms. ` +
`If you have other TK-1 tabs open, close them and reload.`,
),
);
}, OPEN_TIMEOUT_MS);

openPromise.then(
(d) => {
if (timeoutId !== null) clearTimeout(timeoutId);
if (cancelled) {
// Race already lost — close the orphan so future opens land cleanly.
d.close();
} else {
dbInstance = d;
}
},
() => {
if (timeoutId !== null) clearTimeout(timeoutId);
dbPromise = null;
},
);

dbPromise = Promise.race([openPromise, externalFailure]);
}
return dbPromise;
}
Expand Down
Loading
0