fix(dashboard): PUT the handoff bundle through the app's API base (#9)
The backend's upload_url embeds the request host; behind the dev proxy that is the Docker-internal backend:8000, which the browser cannot resolve, so the ZIP PUT died as a bare 'Failed to fetch' and aborted the job. Use /api/uploads/<id> via the app's own base instead, and label handoff failures clearly so they are not mistaken for a process error. Reviewed-on: #9 Co-authored-by: pedro-bento <mail@pbento.pt> Co-committed-by: pedro-bento <mail@pbento.pt>
This commit is contained in:
parent
2dc1ba1eea
commit
9823e8fe69
5 changed files with 90 additions and 18 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
import os
|
||||
from clipwright.pipeline import llm_backend, profiles
|
||||
import re
|
||||
|
|
@ -1470,6 +1471,25 @@ async def lifespan(app: FastAPI):
|
|||
yield
|
||||
# Cleanup (optional: cancel worker)
|
||||
|
||||
# Health probes (Docker, every 5 s) and the dashboard's 2 s job-status poll would
|
||||
# otherwise fill uvicorn's access log with thousands of identical lines and bury
|
||||
# the real job output. Drop those from the access logger only: the requests are
|
||||
# still served normally, just not echoed to the console.
|
||||
_QUIET_ACCESS_PREFIXES = ("/health", "/api/status/")
|
||||
|
||||
|
||||
class _QuietAccessPaths(logging.Filter):
|
||||
"""Suppress access-log lines for health checks and job-status polling."""
|
||||
|
||||
def filter(self, record: logging.LogRecord) -> bool:
|
||||
args = record.args
|
||||
path = args[2] if isinstance(args, tuple) and len(args) >= 3 else ""
|
||||
return not str(path).startswith(_QUIET_ACCESS_PREFIXES)
|
||||
|
||||
|
||||
logging.getLogger("uvicorn.access").addFilter(_QuietAccessPaths())
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
# Free public tools behind the /tools SEO pages: YouTube transcript (existing
|
||||
|
|
|
|||
|
|
@ -106,7 +106,9 @@ def _detect_transnetv2(video_path):
|
|||
threshold = float(os.environ.get("TRANSNETV2_THRESHOLD", "0.5"))
|
||||
|
||||
with _TN2_LOCK, torch.no_grad():
|
||||
tensor = torch.from_numpy(np.ascontiguousarray(frames)).to(model.device)
|
||||
# frombuffer() yields a read-only array; copy so torch stops warning and
|
||||
# writing to the tensor is well-defined.
|
||||
tensor = torch.from_numpy(np.array(frames, copy=True)).to(model.device)
|
||||
single_frame_pred, _ = model.predict_frames(tensor, quiet=True)
|
||||
single_frame_pred = single_frame_pred.cpu()
|
||||
del tensor
|
||||
|
|
|
|||
33
dashboard/package-lock.json
generated
33
dashboard/package-lock.json
generated
|
|
@ -1469,12 +1469,16 @@
|
|||
"dev": true
|
||||
},
|
||||
"node_modules/baseline-browser-mapping": {
|
||||
"version": "2.9.11",
|
||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.9.11.tgz",
|
||||
"integrity": "sha512-Sg0xJUNDU1sJNGdfGWhVHX0kkZ+HWcvmVymJbj6NSgZZmW/8S9Y2HQ5euytnIgakgxN6papOAWiwDo1ctFDcoQ==",
|
||||
"version": "2.11.27",
|
||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.27.tgz",
|
||||
"integrity": "sha512-ElY12DaROGuan+lMmZ8Cvo/ZUbXPe7Enc/9VU/b1T3Kp4dwytRcNdR8DoSJN5SNJT/CuvcCA0DHDVmMOCePdRQ==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"baseline-browser-mapping": "dist/cli.js"
|
||||
"baseline-browser-mapping": "dist/cli.cjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/binary-extensions": {
|
||||
|
|
@ -1614,9 +1618,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/caniuse-lite": {
|
||||
"version": "1.0.30001761",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001761.tgz",
|
||||
"integrity": "sha512-JF9ptu1vP2coz98+5051jZ4PwQgd2ni8A+gYSN7EA7dPKIMf0pDlSUxhdmVOaV3/fYK5uWBkgSXJaRLr4+3A6g==",
|
||||
"version": "1.0.30001814",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001814.tgz",
|
||||
"integrity": "sha512-/Uaf1lAzr59XcMpW0o96WoEfr+VXK2OX4U9AgFoiSHsVJ4HppnIFUjtYzsyDH2+tgANaQb2/oxYGwCPapN1FpA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
|
|
@ -1631,7 +1635,8 @@
|
|||
"type": "github",
|
||||
"url": "https://github.com/sponsors/ai"
|
||||
}
|
||||
]
|
||||
],
|
||||
"license": "CC-BY-4.0"
|
||||
},
|
||||
"node_modules/chalk": {
|
||||
"version": "4.1.2",
|
||||
|
|
@ -6174,9 +6179,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"baseline-browser-mapping": {
|
||||
"version": "2.9.11",
|
||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.9.11.tgz",
|
||||
"integrity": "sha512-Sg0xJUNDU1sJNGdfGWhVHX0kkZ+HWcvmVymJbj6NSgZZmW/8S9Y2HQ5euytnIgakgxN6papOAWiwDo1ctFDcoQ==",
|
||||
"version": "2.11.27",
|
||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.27.tgz",
|
||||
"integrity": "sha512-ElY12DaROGuan+lMmZ8Cvo/ZUbXPe7Enc/9VU/b1T3Kp4dwytRcNdR8DoSJN5SNJT/CuvcCA0DHDVmMOCePdRQ==",
|
||||
"dev": true
|
||||
},
|
||||
"binary-extensions": {
|
||||
|
|
@ -6262,9 +6267,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"caniuse-lite": {
|
||||
"version": "1.0.30001761",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001761.tgz",
|
||||
"integrity": "sha512-JF9ptu1vP2coz98+5051jZ4PwQgd2ni8A+gYSN7EA7dPKIMf0pDlSUxhdmVOaV3/fYK5uWBkgSXJaRLr4+3A6g==",
|
||||
"version": "1.0.30001814",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001814.tgz",
|
||||
"integrity": "sha512-/Uaf1lAzr59XcMpW0o96WoEfr+VXK2OX4U9AgFoiSHsVJ4HppnIFUjtYzsyDH2+tgANaQb2/oxYGwCPapN1FpA==",
|
||||
"dev": true
|
||||
},
|
||||
"chalk": {
|
||||
|
|
|
|||
|
|
@ -474,9 +474,11 @@ function App() {
|
|||
let interval;
|
||||
if ((status === 'processing' || status === 'completed') && jobId) {
|
||||
interval = setInterval(async () => {
|
||||
// Skip a backgrounded tab: with the dashboard open in several tabs the
|
||||
// hidden ones kept polling /api/status and flooding the access log.
|
||||
if (document.hidden) return;
|
||||
try {
|
||||
const data = await pollJob(jobId);
|
||||
console.log("Job status:", data);
|
||||
|
||||
// Update results if available (real-time)
|
||||
if (data.result) {
|
||||
|
|
@ -705,8 +707,12 @@ function App() {
|
|||
});
|
||||
if (!createRes.ok) throw new Error(`Handoff upload failed: ${readableError(await createRes.text())}`);
|
||||
const slot = await createRes.json();
|
||||
if (!slot?.upload_url) throw new Error('Handoff upload failed: the server returned no upload URL.');
|
||||
const putRes = await apiFetch(slot.upload_url, {
|
||||
if (!slot?.upload_id) throw new Error('Handoff upload failed: the server returned no upload id.');
|
||||
// PUT through the app's own API base rather than the absolute
|
||||
// `upload_url` the server returns: behind the dev proxy that URL's host
|
||||
// is the Docker-internal `backend:8000`, which the browser cannot
|
||||
// resolve, so the request dies with a bare "Failed to fetch".
|
||||
const putRes = await apiFetch(`/api/uploads/${encodeURIComponent(slot.upload_id)}`, {
|
||||
method: slot.method || 'PUT',
|
||||
headers: { 'Content-Type': 'application/zip' },
|
||||
body: data.handoffFile,
|
||||
|
|
@ -716,6 +722,11 @@ function App() {
|
|||
handoffId = putData.upload_id || slot.upload_id || null;
|
||||
if (!handoffId) throw new Error('Handoff upload failed: the server returned no upload id.');
|
||||
setLogs((l) => [...l, 'Handoff bundle attached — transcription will be skipped.']);
|
||||
} catch (e) {
|
||||
const msg = e?.message || String(e);
|
||||
throw new Error(
|
||||
msg.startsWith('Handoff upload failed') ? msg : `Handoff upload failed: ${msg}`,
|
||||
);
|
||||
} finally {
|
||||
setHandoffUploading(false);
|
||||
}
|
||||
|
|
|
|||
34
tests/test_access_log_filter.py
Normal file
34
tests/test_access_log_filter.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
"""The access-log filter that hides health checks and job-status polling."""
|
||||
|
||||
import logging
|
||||
|
||||
from clipwright.api.app import _QuietAccessPaths
|
||||
|
||||
|
||||
def _record(path):
|
||||
return logging.LogRecord(
|
||||
"uvicorn.access", logging.INFO, __file__, 1, "msg",
|
||||
("1.2.3.4", "GET", path, "HTTP/1.1", 200), None,
|
||||
)
|
||||
|
||||
|
||||
def test_drops_health_and_status_lines():
|
||||
f = _QuietAccessPaths()
|
||||
assert f.filter(_record("/health")) is False
|
||||
assert f.filter(_record("/health/ready")) is False
|
||||
assert f.filter(_record("/api/status/4c533b81-ef05-4b51-80a3-137046577888")) is False
|
||||
|
||||
|
||||
def test_keeps_real_requests():
|
||||
f = _QuietAccessPaths()
|
||||
assert f.filter(_record("/api/config")) is True
|
||||
assert f.filter(_record("/api/uploads/abc")) is True
|
||||
assert f.filter(_record("/videos/job/clip.mp4")) is True
|
||||
|
||||
|
||||
def test_survives_unexpected_record_args():
|
||||
# uvicorn access records always carry the args tuple, but a filter must never
|
||||
# raise on a differently-shaped record.
|
||||
f = _QuietAccessPaths()
|
||||
rec = logging.LogRecord("uvicorn.access", logging.INFO, __file__, 1, "msg", None, None)
|
||||
assert f.filter(rec) is True
|
||||
Loading…
Reference in a new issue