Skip to content

fix(hackathon-llm): parse diagnostics and tolerant JSON extraction - #36

Merged
TOMOKI977 merged 3 commits into
mainfrom
fix/hackathon-llm-parse-diagnostics
Sep 29, 2026
Merged

TOMOKI977 merged 3 commits into
mainfrom
fix/hackathon-llm-parse-diagnostics

Conversation

@TOMOKI977

Copy link
Copy Markdown
Contributor

Summary

This is the fourth production smoke-test follow-up for change 3, hackathon-analysis. After #35, tokenized-stocks still failed. The new diagnostics showed that both models' outputs failed to parse:

attempts: [{ model: glm-4.7-flash, parsed: false }, { model: qwen3-30b, parsed: false }]

Neither the validator nor snippet matching was involved. The same page parses fine locally, even through the real createWorkersAiExtractor with a REST-backed run. So the cause only occurs in production, either in the Worker's page text or in the binding output, and it can't be seen because content is never logged.

Changes

  • Parse diagnostics (src/domain/ports.ts, src/adapters/llm/workers-ai-extractor.ts, src/domain/usecases/analyze-hackathon.ts, src/domain/errors.ts, src/adapters/log/safe-logger.ts):
    • LlmExtractor.extract now returns { value, meta }.
    • meta holds:
      • finishReason: a short token, otherwise other.
      • contentLength.
      • parseFailure: one of no-content, unterminated, prose-around, not-json, non-object.
      • recovered.
    • meta is added to each attempt in the hackathon-job failure log.
    • The safe logger re-validates every key, so no model content can leak.
  • Tolerant parsing (src/adapters/llm/workers-ai-extractor.ts):
    • When the direct parse fails after fence stripping, the first balanced {...} is extracted, respecting strings and escapes.
    • This is reported as prose-around with recovered: true.
    • The recovered value still goes through the unchanged validateExtraction.
  • Docs: design.md (Extraction) and apply-progress.md.

Review

A bounded review ran at medium risk, with the reliability lens over all 11 changed paths. It found no severe findings.

Deferred warning (R3-001): recovery tries only the first balanced span. Prose such as Here is {the result}: {...} yields not-json instead of recovering the later object, and no test covers it. If it happens in production, the new diagnostics will show it.

Tests

  • Strict TDD.
  • The full suite passes (764 tests), and typecheck is clean.

🤖 Generated with Claude Code

… output

LlmExtractor now returns { value, meta } so the adapter can report the
finish reason, content length and a fixed parse-failure code per attempt
without ever exposing model content. The safe logger re-validates them.
…pped output

When a direct parse fails, scan for the first balanced object (respecting
strings and escapes) and use it, reporting parseFailure prose-around with
recovered true. The value still goes through validateExtraction unchanged.
@TOMOKI977
TOMOKI977 merged commit 7cebda4 into main Sep 29, 2026
2 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.

1 participant