Skip to content

fix(utils): preserve JSON response boundaries and string literals - #1415

Merged
ulleo merged 2 commits into
mainfrom
fix/pr-1408-json-boundaries
Oct 26, 2026
Merged

ulleo merged 2 commits into
mainfrom
fix/pr-1408-json-boundaries

Conversation

@ulleo

@ulleo ulleo commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Summary

接续 #1408,修复 #1401:SQL 字符串中的 {、} 不再干扰 JSON 提取,同时避免把非法或截断回答中的子对象、子数组当成完整回答。

AI 回答(说明文字 / Markdown + JSON)
  → 跳过字符串内括号,识别完整外层候选
  → orjson 校验
  → 返回第一个合法候选;非法候选整体跳过

包含原作者 ExtremeNina 的提交 438a4ab7,以及补充回归修复 60d4a5a7。仓库禁用 merge commit,使用 rebase merge 保留两条独立提交的作者与提交说明;合并后的 SHA 会变化。

Evidence

  • Before: 在 fix(utils): ignore braces inside strings when extracting nested json (#1401) #1408 原提交上运行补充测试,12 项失败,例如 {"tables": [],} then {"success":true,"sql":"SELECT 1"} 错误返回 [],截断的预测数组错误返回内部对象。
    After: JSON 提取测试 34 项通过;原始花括号问题、转义字符、Markdown 包装、合法嵌套结构仍通过。

  • 将 60d4a5a7 与当前 main 的 b78354c5 在隔离 worktree 中合并验证,无冲突,以下命令从 backend/ 执行,57 passed:

    python -m pytest -q tests/test_extract_nested_json.py tests/test_data_format.py tests/test_codex_mcp_runtime.py tests/test_connection_pool_manager.py
  • 使用既有 Python 3.11.17 环境(pytest 7.4.4、orjson 3.11.9),未同步依赖;确认导入来自验证 worktree。测试文件 Ruff 检查与格式检查通过,修改的解析函数格式检查通过;utils 文件剩余 32 项 lint 告警及整体格式问题已与原 PR 基线对照,无新增告警。git diff --check 通过。

  • 未运行真实数据库、LLM、浏览器或镜像部署验收。

Merge Danger

Door: two-way

仅修改提取函数和离线回归测试,无依赖或数据库迁移变更,可通过代码回退恢复。

Blast Radius: Chat

影响复用该函数的 SQL、图表、预测及问题建议解析。保持返回第一个合法对象或数组的语义,不按业务字段筛选;描述中未闭合的括号可能导致后续 JSON 一并被拒绝。

@ulleo
ulleo merged commit 8bd2d6e into main Oct 26, 2026
3 checks passed
@ulleo
ulleo deleted the fix/pr-1408-json-boundaries branch October 26, 2026 06:22
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