Surface tool failures; timeout discipline; call logging; cache-hit honesty

1. mcp shim: anticipate OSError/RequestException/JSON errors and raise
   ToolError with 'Type: message' - the SDK strips ALL text from bare
   exceptions ('Error executing tool omniparse' with zero detail)
2. shim HTTP timeout 300s -> 100s, below the harness's 120s: harness
   aborts are detailless, ours say why (documented)
3. shim file logging to ~/.cache/omniparse/mcp.log (harnesses discard
   stdio stderr): every call's args/status/duration + full tracebacks
4. warm-up 503 sends Retry-After: 10 (429 already did)
5. cache hits no longer replay original timings as live: timings become
   {served_from_cache, original_parse}, fresh served_ms on every response
6. token filename canonicalized on omniparse_token (deployed file real,
   not a symlink; harness config updated)
7. GET / points at /healthz and /docs instead of bare 404
This commit is contained in:
plean committed 2026-11-18 03:00:17 +00:00
1 parent 5bc1815ebc
commit 46ae7046ea
2 files changed
+81 -18

No files matched your search

+16 -2
View File
@@ -95,6 +95,7 @@ def _cache_key(raw: bytes, req) -> str:
def _run_cached(key: str, raw: bytes, req) -> dict:
t0 = time.perf_counter()
eng: ParseEngine = STATE['engine']
cached = STATE['cache'].get(key)
hit = cached is not None
@@ -119,7 +120,13 @@ def _run_cached(key: str, raw: bytes, req) -> dict:
STATE['cache'].popitem(last=False)
res = dict(res)
out = {'image_size': res['image_size'], 'n_elements': len(res['elements']),
'timings': res['timings'], 'cache_hit': hit}
# a cache hit must never replay the original parse's timings as if
# they were computed now - report them as history + fresh served_ms
'timings': ({'served_from_cache': True,
'original_parse': res['timings']}
if hit else res['timings']),
'served_ms': round((time.perf_counter() - t0) * 1000, 1),
'cache_hit': hit}
if req.format in ('full', 'both'):
out['elements'] = res['elements']
if req.format in ('view', 'both'):
@@ -129,11 +136,18 @@ def _run_cached(key: str, raw: bytes, req) -> dict:
return out
@app.get('/', include_in_schema=False)
async def root():
return {'service': 'omniparse', 'health': '/healthz', 'docs': '/docs',
'parse': 'POST /parse'}
@app.post('/parse')
async def parse(req: ParseReq, authorization: str | None = Header(None)):
_auth(authorization)
if not STATE['ready']:
raise HTTPException(503, 'models still loading - see /healthz')
raise HTTPException(503, 'models still loading - see /healthz',
headers={'Retry-After': '10'})
if isinstance(STATE['engine'], Exception):
raise HTTPException(500, f'model load failed: {STATE["engine"]}')
raw = req.image_b64.split(',', 1)[-1]