Skip to content

Add page-memory VLM capacity gate#208

Merged
suguanYang merged 4 commits into
mainfrom
perf/wangbinqi/page-memory-vlm-gated-optimization
Jul 7, 2026
Merged

Add page-memory VLM capacity gate#208
suguanYang merged 4 commits into
mainfrom
perf/wangbinqi/page-memory-vlm-gated-optimization

Conversation

@suguanYang

@suguanYang suguanYang commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a Redis-backed global page-memory VLM in-flight limiter so page-memory capacity pressure becomes retryable UnavailableException backpressure instead of degraded empty OCR/title/summary output.
  • Gate only usage_task values prefixed with page_memory. in the shared OpenAI-compatible sync client; non-page-memory LLM calls keep existing behavior.
  • Add env-backed page-memory local concurrency defaults for scope processing, page tagging, title detection, and node assembly. Title detection and node OCR/summary now default to concurrency 3; existing scope/tag defaults remain 5/4 but are tunable through settings.
  • Add ordered local parallelism for page title detection and node OCR/summary assembly, preserving page/row order and failing stages on greenlet exceptions.
  • Add page-memory sub-stage timers for title render, node OCR, node summary, and node rows.
  • No public API, SDK, OpenAPI, or DB schema changes. Existing job metadata carries the resolved page_memory_config.

Verification

  • uv run pytest packages/shared-python/shared/tests/test_page_memory_config.py packages/shared-python/shared/tests/test_page_memory_vlm_limiter.py apps/worker/tests/contract/test_page_memory_page_tagger_contract.py apps/worker/tests/contract/test_page_memory_node_assembler_contract.py
  • uv run pytest apps/worker/tests/contract/test_page_memory_*.py packages/shared-python/shared/tests/test_page_memory_config.py packages/shared-python/shared/tests/test_page_memory_vlm_limiter.py
  • uv run pytest apps/worker/tests/contract/test_page_memory_*.py
  • uv run pytest apps/worker/tests/contract
  • make check
  • Local API health: curl -sS http://localhost:5005/health
  • Real v2 parse, text-heavy PDF: job_c5bd6e3f7b34, TSLA 35-page PDF, completed done, parse_track=page_memory, result ZIP /tmp/tsla-page-memory-real-parse.zip.
  • Real v2 parse, scanned/image-only PDF: job_af2bc76242f3, synthetic 8-page scanned PDF, completed done, produced 8 non-empty page chunks, result ZIP /tmp/scanned-page-memory-real-parse-with-env.zip.
  • Worker logs for job_af2bc76242f3 showed page_memory.vlm_gate.acquired for page_memory.title_detection, page_memory.hierarchy, page_memory.tag, and page_memory.node_ocr; observed in-flight counts up to 4. This real parse was run before the final concurrency default bump, so it observed OCR concurrency 2.
  • Redis page_memory:vlm:inflight was empty after completion.

Deployment Notes

  • New internal settings with defaults: PAGE_MEMORY_VLM_MAX_INFLIGHT=16, PAGE_MEMORY_VLM_LEASE_TTL_SECONDS=600, PAGE_MEMORY_VLM_WAIT_TIMEOUT_SECONDS=120, PAGE_MEMORY_SCOPE_CONCURRENCY=5, PAGE_MEMORY_TAG_CONCURRENCY=4, PAGE_MEMORY_TITLE_DETECTION_CONCURRENCY=3, PAGE_MEMORY_NODE_ASSEMBLY_CONCURRENCY=3.
  • Worker processes must have IMAGE_MODEL exported for page-memory page-level VLM tagging/OCR. During local testing, a worker started without apps/worker/.env skipped page VLM calls; restarting with .env sourced exercised the limiter.
  • No migrations, queue changes, storage changes, or public contract changes.
  • Rollback is the branch revert; stale Redis in-flight counters are bounded by the lease TTL.

Checklist

  • Tests were added or updated when behavior changed
  • Public docs, examples, or OpenAPI contracts were updated when needed
  • Database migrations are idempotent and safe to deploy
  • Logs, errors, and validation paths avoid leaking secrets or user data
  • The pull request description explains any breaking or user-visible change

Comment thread packages/shared-python/shared/tests/test_page_memory_vlm_limiter.py Fixed
Comment thread packages/shared-python/shared/tests/test_page_memory_vlm_limiter.py Fixed
Comment thread packages/shared-python/shared/tests/test_page_memory_vlm_limiter.py Fixed
@suguanYang suguanYang merged commit a2aa805 into main Jul 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants