mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: harden install queue/dispatcher lifecycle and repair review-sweep regressions (#395)
Fixes 15 defects found by a max-effort multi-agent review of the last 6 merged PRs (#388, #390, #391, #392, #393, #394), all adversarially verified before fixing. Install queue + dispatcher (the serious cluster): - features.ts: finalize the installer child exactly once. A failed spawn fires both "error" and "close", and the second event released the file lock and active slot that pump() had just handed to the next queued bundle, letting two pip processes write the same venv concurrently. Outcome recording now happens before pump() so the next bundle's first progress frame cannot race the previous install's bookkeeping. - feature-status.ts: keep failed-install errors in a per-bundle map instead of the single progress slot. With the queue auto-starting the next install, the slot was overwritten within seconds and a failed install vanished without ever surfacing to GET /features. - bridge.ts: scope child lifecycle per process (stopped-children set + request generation tags) instead of an instance-wide shuttingDown flag that the next spawn reset. A stale SIGTERMed child's late close event could record a phantom crash (5 of which permanently disable the dispatcher), null out the freshly spawned child, and reject the new child's pending requests. The request-timeout kill path still counts as a real crash. - install_feature.py: the pre-write disk re-check measured ai_dir's filesystem even when budgeting the cross-filesystem copy that lands on the venv's disk; now each budget is checked against the filesystem the bytes actually land on, so ENOSPC cannot strike mid-write and leave site-packages half overwritten. Behavior regressions: - embed-subtitles: preserve pre-existing subtitle tracks (0:s?) and MKV attachments (0:t?) that the -map 0:v:0/0:a? rewrite silently dropped; data streams stay unmapped on purpose (the actual MPEG remux fix). The new subtitle maps first so the language tag hits the right stream. - usage-survey-overlay: fail closed when the settings fetch fails; the fail-open path rendered the blocking survey against an unhealthy API and soft-locked admins, the lock-out class #392 fixed. - features-store: queued bundles poll instead of each holding an SSE connection (Install All could pin 7 EventSources and exhaust the browser's 6-per-origin HTTP/1.1 limit, hanging the whole app); listenToProgress closes any prior stream and stops any poll before subscribing; installAll skips bundles already installing or queued. Contracts, tests, i18n: - openapi.yaml: add "queued" to the features status enum and document downloadBytes/installedBytes (Schemathesis conformance). - feature-lifecycle e2e: queue transcription (~0.5 GB) instead of ocr (~6 GB) and give the test a budget that covers both install drains (the stacked waits exceeded the old 900s timeout). - docker-compose.qa.yml: parameterize the host port (QA_APP_PORT) so QA_PROJECT_NAME concurrent stacks can actually bind. - compare + watermark-image: restore per-input error attribution ("Invalid first/second image", "Invalid watermark image") lost in the shared-handler migration. - ai-features-section: the "{size} on disk" suffix now goes through i18n; key added to all 21 locales. - watermark-image + content-aware-resize: migrate to the shared inputHandlerFor("image") chain like compare/vectorize/compose, fixing drift in the inline copies (no SVG sanitize, no RAW extension hint, no AVIF probe). Verified: typecheck across 9 workspaces, Biome clean on all changed files, 584 targeted unit tests and 249 integration tests green (including real-ffmpeg embed-subtitles runs). One unit test updated to the new poll-while-queued contract with a single-EventSource assertion. Claude-Session: https://claude.ai/code/session_017mR1HiHaf3a1BmUtrHX4j3
This commit is contained in:
@@ -67,7 +67,13 @@ export function UsageSurveyOverlay() {
|
||||
if (!eligibleAuthState || !eligibleRoute) return;
|
||||
apiGet<{ settings: Record<string, string> }>("/v1/settings")
|
||||
.then((data) => setSettings(data.settings))
|
||||
.catch(() => setSettings({}));
|
||||
.catch(() => {
|
||||
// Fail closed: without settings we cannot know whether the admin
|
||||
// already answered, and showing the full-screen overlay while the
|
||||
// API is unhealthy would soft-lock them (the dismiss/continue
|
||||
// writes would fail against the same unhealthy API). Skipping the
|
||||
// survey for this load is the cheap, recoverable outcome.
|
||||
});
|
||||
}, [eligibleAuthState, eligibleRoute]);
|
||||
|
||||
const visible =
|
||||
|
||||
@@ -285,7 +285,12 @@ function BundleCard({
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{bundle.description} (~
|
||||
{bundle.downloadBytes ? formatFileSize(bundle.downloadBytes) : bundle.estimatedSize}
|
||||
{bundle.installedBytes ? `, ${formatFileSize(bundle.installedBytes)} on disk` : ""})
|
||||
{bundle.installedBytes
|
||||
? `, ${format(t.settings.aiFeatures.sizeOnDisk, {
|
||||
size: formatFileSize(bundle.installedBytes),
|
||||
})}`
|
||||
: ""}
|
||||
)
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 shrink-0 ms-4">
|
||||
|
||||
@@ -96,6 +96,14 @@ export const useFeaturesStore = create<FeaturesState>((set, get) => {
|
||||
maybeFinishInstallAll();
|
||||
};
|
||||
|
||||
const stopPolling = (bundleId: string) => {
|
||||
const ref = pollRefs[bundleId];
|
||||
if (ref) {
|
||||
clearInterval(ref);
|
||||
delete pollRefs[bundleId];
|
||||
}
|
||||
};
|
||||
|
||||
const startPolling = (bundleId: string) => {
|
||||
if (pollRefs[bundleId]) return;
|
||||
pollRefs[bundleId] = setInterval(async () => {
|
||||
@@ -126,8 +134,7 @@ export const useFeaturesStore = create<FeaturesState>((set, get) => {
|
||||
}
|
||||
|
||||
// Terminal: installed / error / not_installed.
|
||||
clearInterval(pollRefs[bundleId]);
|
||||
delete pollRefs[bundleId];
|
||||
stopPolling(bundleId);
|
||||
stopTracking(bundleId);
|
||||
onInstallSettled(
|
||||
bundleId,
|
||||
@@ -138,6 +145,13 @@ export const useFeaturesStore = create<FeaturesState>((set, get) => {
|
||||
};
|
||||
|
||||
const listenToProgress = (bundleId: string, jobId: string) => {
|
||||
// One tracker per bundle: close any previous stream and stop any poll so
|
||||
// a re-POST (which the server dedups to the same job) can never leave two
|
||||
// live subscriptions whose terminal events each run the settle logic.
|
||||
esRefs[bundleId]?.close();
|
||||
delete esRefs[bundleId];
|
||||
stopPolling(bundleId);
|
||||
|
||||
const es = new EventSource(`/api/v1/jobs/${jobId}/progress`);
|
||||
esRefs[bundleId] = es;
|
||||
|
||||
@@ -277,7 +291,7 @@ export const useFeaturesStore = create<FeaturesState>((set, get) => {
|
||||
},
|
||||
|
||||
installBundle: async (bundleId: string) => {
|
||||
// Always POST immediately -- the server owns the queue now, so a POST is
|
||||
// Always POST immediately: the server owns the queue now, so a POST is
|
||||
// durable even if this tab closes. Optimistically show "installing"; the
|
||||
// response tells us whether it actually started or got queued.
|
||||
const errors = { ...get().errors };
|
||||
@@ -294,16 +308,21 @@ export const useFeaturesStore = create<FeaturesState>((set, get) => {
|
||||
{},
|
||||
);
|
||||
if (result.queued) {
|
||||
// Server queued it behind an active install; show the pill instead of
|
||||
// a progress bar until the first progress frame arrives.
|
||||
// Server queued it behind an active install; show the pill and poll
|
||||
// for the transition instead of holding an SSE connection open. An
|
||||
// EventSource per queued bundle would let Install All pin up to 7
|
||||
// connections for the whole run, exhausting the browser's
|
||||
// per-origin limit on HTTP/1.1 and starving every other request.
|
||||
const installing = { ...get().installing };
|
||||
delete installing[bundleId];
|
||||
set({
|
||||
installing,
|
||||
queued: get().queued.includes(bundleId) ? get().queued : [...get().queued, bundleId],
|
||||
});
|
||||
startPolling(bundleId);
|
||||
} else {
|
||||
listenToProgress(bundleId, result.jobId);
|
||||
}
|
||||
listenToProgress(bundleId, result.jobId);
|
||||
} catch (err) {
|
||||
stopTracking(bundleId);
|
||||
|
||||
@@ -344,7 +363,12 @@ export const useFeaturesStore = create<FeaturesState>((set, get) => {
|
||||
},
|
||||
|
||||
installAll: async () => {
|
||||
const pending = get().bundles.filter((b) => b.status !== "installed");
|
||||
// Skip bundles the server is already installing or holding in its
|
||||
// queue: re-POSTing them just dedups server-side and used to leave a
|
||||
// second progress subscription racing the first one's terminal events.
|
||||
const pending = get().bundles.filter(
|
||||
(b) => b.status !== "installed" && b.status !== "installing" && b.status !== "queued",
|
||||
);
|
||||
if (pending.length === 0) return;
|
||||
|
||||
// Mark every pending bundle up front so the run never looks "drained"
|
||||
|
||||
Reference in New Issue
Block a user