Repository navigation
fix: keep conversation notes when the model leaves quotes unescaped - #21139
Git-on-my-level merged 3 commits into
Conversation
JsonOutputParser drops the whole summary when a notes completion quotes a phrase inside a JSON string. Co-authored-by: Cursor <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c480f88de8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if follower >= length or text[follower] in _JSON_STRING_CLOSER_FOLLOWERS: | ||
| out.append(char) | ||
| in_string = False | ||
| else: | ||
| out.append('\\"') |
There was a problem hiding this comment.
Escape prose quotes followed by JSON-like punctuation
When an unescaped quoted phrase is followed by a comma, colon, bracket, or the end of the field—for example, "overview":"He said "hi", then left"—this condition mistakes the interior closing quote for the JSON string boundary. The repair consequently produces malformed JSON such as "He said \"hi", then left", so the retry can still fail or the partial JSON parser can silently return a truncated overview. Quoted phrases ending a sentence or preceding punctuation are common model output, so this still loses or corrupts conversation notes in the scenario the change is intended to recover.
Useful? React with 👍 / 👎.
| except OutputParserException: | ||
| repaired = _escape_interior_json_quotes(text) |
There was a problem hiding this comment.
Record successful quote-repair fallbacks
Whenever the initial parse fails but the repair succeeds, this new fail-open branch changes correctness without calling utils.observability.fallback.record_fallback. That makes recovered malformed model responses invisible to fallback telemetry, preventing operators from measuring recurrence or detecting when the repair path starts masking a provider regression.
AGENTS.md reference: backend/AGENTS.md:L312-L312
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb25d1426c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if char == '"': | ||
| in_string = True |
There was a problem hiding this comment.
Limit quote scanning to the JSON payload
When the model wraps the malformed object in a fenced response with a quoted preamble, such as Here is the "requested" JSON:, this branch treats the preamble's first quote as the start of a JSON string. It then escapes structural quotes inside the fenced object (for example, turning its opening key into \{"title...), so the retry still raises and the conversation loses its notes even though PydanticOutputParser normally accepts fenced JSON. Extract the fenced/object payload before applying this repair, or otherwise avoid tracking quotes in surrounding prose.
Useful? React with 👍 / 👎.
Unit tests replace langchain_core with a non-package stub, so a module-level exceptions import prevents conversation routers from loading. Co-authored-by: Cursor <[email protected]>
|
errfix finisher: this PR has been open >3 days without merging — escalating to a human. |
What changed and why
Conversation notes failed closed when the structure model left prose quotes unescaped inside an otherwise complete JSON object.
JsonOutputParserraisedOutputParserExceptionfromlangchain_core/output_parsers/json.py:91, and_get_structuredturned that into a processing failure, so the conversation never got a summary.Error group (source: gcp):
{"source": "gcp", "service": "backend", "group": "json.py:91 | langchain_core.exceptions.OutputParserException: Invalid json output: {"title": "Fish identification", "overvi", "count": 1, "id": "gcp:backend-json-py-91-langchain-core-exceptions-outputparserexception-invalid-json-output-title-fish-identificati"}
Root cause
The traceback is
process_conversation.py_get_structured→conversation_processing.py_get_shaped_conversation_notes→extraction_parser.parse. The completion is aStructuredExtractionobject (title,overview,sections, …) whose string values contain raw"characters. Langchain's partial JSON repair cannot recover that shape (Expecting ',' delimiterimmediately after the interior quote), so the strict parser raises and the notes call fails.Fix
_parse_notes_model_outputstill parses withPydanticOutputParser. Only after that raises does it escape interior quotes whose next non-space character is not a JSON closer (, } ] : "), then parse again. Valid JSON, already-escaped quotes, and a missing comma between fields are unchanged.Product invariants affected
none
How it was verified
The logged Fish identification completion still raises on the strict parser and now parses through
_parse_notes_model_outputasStructuredExtractionwith that title, a non-empty overview, and one section.Tests
backend/tests/unit/test_conversation_notes_json_quotes.pycovers unescaped quotes inoverviewand in a section body, already-escaped quotes, and a missing comma that must still raise.UI evidence
UI-Evidence: none -- backend notes parser only
Failure class (fixes)
Failure-Class: none