Skip to content

[integrations] entity-extraction-worker: fix fence parsing + misleading provider error - #440

Open
eazene wants to merge 1 commit into
NateBJones-Projects:mainfrom
eazene:contrib/eazene/worker-fence-and-error-fix
Open

[integrations] entity-extraction-worker: fix fence parsing + misleading provider error#440
eazene wants to merge 1 commit into
NateBJones-Projects:mainfrom
eazene:contrib/eazene/worker-fence-and-error-fix

Conversation

@eazene

@eazene eazene commented Jul 12, 2026

Copy link
Copy Markdown

What

Two production bugs in the entity-extraction worker that together created invisible poison-pill queue items.

The bugs

1. Anchored fence regex misses real LLM output. stripCodeFences used /^\``(?:json)?\s*\n?([\s\S]?)\n?\s```$/— anchored at both ends. A```jsonfence with trailing prose after the close, or an unterminated fence, falls through toJSON.parse` and throws. It's content-dependent: thoughts about formatting rules nudge the model into markdown mode, so the same queue items failed on every retry (to dead-letter) while 270+ others succeeded.

2. Misleading fall-through error. When every configured provider fails transiently, extractEntities threw 'No LLM API key configured' — even though keys were configured and the real failure was the parse error above. That masking survived four separate debugging attempts; the real cause was only visible after making the error honest.

The fix

  • Fence stripper: try the anchored match first; if it misses but the text starts with a fence, strip the opening fence and cut at the next closing fence (both index.ts and _shared/helpers.ts).
  • Track lastProviderError through the provider chain; the fall-through now throws 'All configured LLM providers failed — last error: …' and reserves the no-key message for when no key is actually set.

Verification (live)

Deployed against a production queue: the honest error immediately revealed the fence bug; after the fence fix, the stuck item (4/5 attempts, one retry from permanent failed) parsed and completed. Queue went to 279/279 complete.

🤖 Generated with Claude Code

…ng provider error

Two production bugs that together created invisible poison-pill queue items:

1. stripCodeFences used a fully-anchored regex, so a ```json fence with
   trailing prose (or an unterminated fence) fell through to JSON.parse
   and failed. Content-dependent: thoughts ABOUT formatting rules nudge
   the model into markdown mode, so the same items failed on every retry
   while everything else succeeded. Now strips the opening fence and cuts
   at the next closing fence when the anchored match misses.

2. When all configured providers failed transiently, the fall-through
   threw 'No LLM API key configured' — masking the real error (the fence
   parse failure above survived four investigations behind it). The
   fall-through now reports the last actual provider error.

After deploying both fixes live, the stuck items (4/5 retries, one from
permanent dead-letter) parsed and completed on the next attempt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S9FUbMiGenJMFguwQsQYZa
@github-actions github-actions Bot added the integration Contribution: MCP extension or capture source label Jul 12, 2026
@github-actions

Copy link
Copy Markdown

OB1 PR Gate

Folder structure — All files are in allowed directories
Required files — README.md and metadata.json found in all contribution folders
Metadata valid — All metadata.json files passed JSON Schema validation
No credentials — No API keys, tokens, or secrets detected
SQL safety — No destructive SQL or core table modifications
Category artifacts — Required file types present for each category
PR format — Title follows [category] Description format
No binary blobs — No oversized or binary files
README completeness — All READMEs include Prerequisites, Steps, and Expected Outcome
Contribution dependencies — All declared skill and primitive dependencies exist and are linked in README
LLM clarity review — Covered by Claude PR Review workflow
Remote MCP pattern — No local MCP server patterns detected — uses remote MCP correctly
Tool audit link — Extensions/integrations link to the MCP Tool Audit guide
Scope check — All changes are within the contribution folder(s)
Internal links — All relative links in READMEs resolve to existing files

Result: All 15 checks passed! Ready for human review.


Post-Merge Tasks

These don't block merge — they're reminders for admins after this PR lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration Contribution: MCP extension or capture source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant