[integrations] entity-extraction-worker: fix prerequisites, document safe pg_cron scheduling - #421
Open
hadolphs wants to merge 1 commit into
Conversation
…safe pg_cron scheduling The prerequisites were wrong in two ways: - schemas/knowledge-graph does not exist. The tables this worker needs (entities, edges, thought_entities, entity_extraction_queue) come from schemas/entity-extraction. - schemas/enhanced-thoughts was listed as required, but index.ts reads only 'id, content, metadata' from thoughts and references none of its columns. Scheduling was undocumented, and following the repo's existing pg_cron pattern fails silently in three separate ways, each logging 'succeeded' in cron.job_run_details while processing zero thoughts: - net.http_post() defaults to timeout_milliseconds=5000, but the worker takes tens of seconds (one LLM call per thought), so every call is abandoned mid-flight (measured elapsed_ms: 26280 / 57569 / 58332). - A trailing space in the Vault secret's NAME makes the lookup return NULL, sending 'x-brain-key: null' and yielding a 401. - net.http_post() only enqueues the request, so pg_cron never sees the HTTP result; the cron log cannot distinguish success from total failure. Adds a hardened schedule (explicit timeout + raise-on-null guard), documents the queries that are real health signals (entity_extraction_queue status counts and net._http_response status_code/body), and adds a troubleshooting entry.
hadolphs
force-pushed
the
contrib/hadolphs/entity-worker-scheduling
branch
from
September 3, 2026 00:20
4a6b95f to
19ecc8c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two independent problems with
integrations/entity-extraction-worker/, both found while actually deploying and scheduling it.1. The prerequisites are wrong
schemas/knowledge-graphdoes not exist in this repo. The tables the worker needs (entities,edges,thought_entities,entity_extraction_queue) are created byschemas/entity-extraction/.schemas/enhanced-thoughtsis not required.index.tsreads onlyid, content, metadatafromthoughts:sensitivity_tier/source_type/quality_score. Listing it as a prerequisite sends people to install a schema they don't need.2. Scheduling this worker fails silently, in three separate ways
The README recommends running the worker but never shows how to schedule it. Following the repo's existing pg_cron pattern (
recipes/editorial-policy/schedule.sql) produces a job that reportssucceededevery single run while processing zero thoughts:net.http_post()defaults totimeout_milliseconds = 5000. This worker makes one LLM call per queued thought and takes tens of seconds — measuredelapsed_msof 26,280 (3 thoughts), 57,569 (12), 58,332 (10). Every scheduled call is abandoned mid-flight at 5 s, so nothing is ever committed.where name = 'mcp_access_key'match nothing. The sub-select returnsNULL, the job sendsx-brain-key: null, and the worker replies401.net.http_post()only enqueues the request and returns a request id. pg_cron never observes the HTTP response, socron.job_run_detailslogssucceededregardless. The cron log cannot distinguish success from total failure.Stacked together, these are near-undiagnosable. In our case the knowledge graph sat frozen for days behind a wall of green "successful" cron runs. The giveaway was that
completeinentity_extraction_queueexactly matched the count from manual worker invocations — the cron had never processed a single thought.Evidence from
net._http_response, in order:status_code = null, "Timeout of 5000 ms reached"status_code = 401x-brain-key: nullstatus_code = 200,{"processed": 0, ...}Fix
Docs only — no code changes.
entity-extraction, notknowledge-graph; note thatenhanced-thoughtsis not required).pg_cron+pg_netjob: explicittimeout_milliseconds, araise exceptionguard so a missing/renamed Vault secret becomes a visible cron failure rather than a phantom success, and alimitsized to finish inside the timeout.entity_extraction_queuestatus counts andnet._http_response.status_code(whosecontentcolumn holds the worker's real JSON reply) — and state plainly thatcron.job_run_detailsis not one.Verification
All three claims were checked against the code on
mainbefore writing:grep -n -A1 '\.from("thoughts")' index.ts→.select("id, content, metadata")grep -nE 'sensitivity_tier|source_type|quality_score' index.ts→ no matchesls schemas/knowledge-graph→ does not existThe hardened schedule in this PR is the one now running against a live brain:
status_code = 200, body{"processed": 0, ...}, queuepending = 0.