Skip to content

Studio: only strip a valid trailing __IMAGES__/__RAG_SOURCES__ envelope - #10668

Merged
Lyxot merged 9 commits into
unslothai:mainfrom
NilayYadav:fix-tool-result-sentinel-anchor
Sep 10, 2026
Merged

Lyxot merged 9 commits into
unslothai:mainfrom
NilayYadav:fix-tool-result-sentinel-anchor

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

A tool result that merely mentions __IMAGES__: or __RAG_SOURCES__:, even mid-line, gets cut off there before the model sees it. The tool card still shows the full output, so nothing looks wrong. Grepping this repo or reading a file that contains the marker triggers it.

The two markers are now handled like __FILES__ next to them: the marker has to start a line and be followed by a real JSON list, only the tools that emit the envelope have it removed, and every trailing envelope goes, not just the last one. Test fixtures that used shapes no tool produces are updated.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-10T05:05:14.848867Z d779666 Manual request
🔒 Security Review ✅ Completed 2026-09-10T05:11:24.444739Z d779666 Manual request

Security findings

Advisory findings (2)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: d8aa3be1f2

ℹ️ 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".

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@NilayYadav

NilayYadav commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator Author

Reproduction and before/after evidence

1. The defect on Actions. Two branches off the same fresh main, byte-identical probe and workflow, only the implementation differs.

implementation probe run
main (unvalidated split) 4 passed, 3 failed 34409601233
this PR 7 passed, 0 failed 34409590306

What the model loses on main, measured:

TRUNCATION: A1 grep hits survive whole (terminal):     model lost 101 of 225 chars
TRUNCATION: A2 grep hits survive whole (no tool name): model lost 101 of 225 chars
TRUNCATION: B1 retrieved chunk survives whole (rag):   model lost 111 of 175 chars

Four cases pass on both sides, so the envelope is still being stripped: the sandbox __FILES__+__IMAGES__ pair, the rag_search source map, a hosted code_execution image, and a stacked two-figure envelope.

2. What it looks like in Studio. Two isolated installs, merge base fcaad20ef against head c365d6660, a real stdio MCP tool returning a four-line build log whose second line quotes __IMAGES__: in the middle of a line.

before and after

The tool card is identical on both halves — all four lines, artifact URL and sha256 plainly visible. That is the point: nothing looks wrong on screen while the model answers from a log cut at the quoted marker.

fact before after
model_received_chars 43 155
chars_lost_before_model 112 0
model_received_lines 2 4
model_received_artifact_url false true
model_received_checksum false true

Held on both sides: mcp_tool_returned_chars 155, card_shows_artifact_url true, card_shows_checksum true, provider_completions 2, and the two card texts byte-identical.

3. Follow-up commit d8aa3be1f. _strip_images_sentinel peeled only the last envelope. A Gemini code_execution turn that draws two figures stacks one envelope per inlineData part — external_provider.py re-assigns last_code_exec_result_text = updated_result after emitting — so the first plot's whole base64 data URI would have been replayed to the model, which the old unanchored split happened to prevent. It is now peeled in a loop, with a regression test that fails on the previous head.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits strip_result_for_model in studio/backend/core/inference/tool_loop_controller.py, where an unanchored split still cuts any tool result that merely quotes the marker while the card shows the whole thing, and the stacked code_execution case is covered too. Will get this reviewed.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: c365d66603

ℹ️ 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".

@NilayYadav

NilayYadav commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator Author

Follow-up on the security review item, and the A/B re-run on the final head.

c365d6660 — the stacked-envelope peel is now linear. Reproduced the report before changing anything, on the same 1.36 MB / 80,000-marker input:

implementation 1.36 MB 2.72 MB
main (single split) 0.0002 s 0.0002 s
d8aa3be1f (re-partition per marker) 2.06 s 6.14 s
c365d6660 (backward walk, one cut) 0.049 s 0.098 s

Re-partitioning copied the shortened string once per marker, so the cost was quadratic in the marker count even though the search itself was not. It now records the leftmost valid envelope by index and slices once.

The regression test asserts the scaling rather than a wall-clock budget, so it means the same thing on a loaded runner as on a laptop: quadrupling the markers must cost under 10x the time. On d8aa3be1f that ratio is 22.7x and the test fails; on c365d6660 it is about 4x.

A/B re-run on c365d6660, same probe and workflow as before:

implementation probe run
main 4 passed, 3 failed 34409601233
this PR 7 passed, 0 failed 34416973243

The before/after Studio evidence above has been re-shot against c365d6660 (BEFORE reused at the unchanged merge base, AFTER rebuilt), and every fact reads the same as it did on d8aa3be1f: model_received_chars 43 -> 155, chars_lost_before_model 112 -> 0, controls held on both sides.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 8dd96291d0

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 34e5ee3d4b

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56e2b63d76

ℹ️ 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".

Comment on lines +957 to +958
if tool_name is None or tool_name in _IMAGE_SENTINEL_TOOLS:
result = _strip_images_sentinel(result)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate frontend image parsing by the emitting tool

When an MCP or fetch result ends with a valid line such as __IMAGES__:["icon.png"]—the exact case this new allowlist preserves—the frontend still finds the marker for every tool and converts the suffix into an image result without checking toolName (chat-adapter.ts:6742-6743, 6801-6815). Consequently the model receives the complete document while the user's card hides its final line and attempts to load icon.png from the sandbox, contrary to the consistency this change relies on; apply the same emitter gate in the frontend parser.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d779666. Checked the adapter first: it already gates FILES on SANDBOX_FILE_TOOLS and WEB_IMAGES on SEARCH_IMAGE_TOOL, each with a comment that elsewhere the line is content, and the IMAGES slice right below them was the one left ungated. It is now gated on IMAGE_SENTINEL_TOOLS, exported next to SANDBOX_FILE_TOOLS in sandbox-files.ts and matching the backend set exactly: python, terminal, and the hosted code_execution. A document an MCP tool read that ends in a well-formed line now stays on the card as text, and the card no longer asks the sandbox route for a file nobody wrote. Test asserts the set and, like the other chat-adapter tests, the source: it fails on the previous head with 'the IMAGES slice is no longer gated'. Frontend suite: 208 pre-existing failures on this box before and after, none new. The search index (use-chat-search-index.ts) still slices the marker for every tool, but it has no tool name in scope and only decides what text is searchable, so I left it.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 56e2b63d76

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: d7796669d2

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: d7796669d2

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@Lyxot Lyxot self-assigned this Sep 10, 2026

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduced the truncation on the merge base (a terminal grep hit quoting __IMAGES__: reached the model as tools.py:16134: out += f"\n) and confirmed the head keeps the full result while still stripping the sandbox, stacked Gemini code_execution, and retrieval envelopes. The anchored, validated strippers mirror _strip_files_sentinel and _strip_mcp_image_suffix beside them, the emitter allowlists match every producer of both markers, and the frontend gate keeps the card and the model in agreement. Touched backend tests and the new frontend test pass locally. LGTM.

@Lyxot

Lyxot commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: d7796669d2

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: d7796669d2

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@Lyxot
Lyxot merged commit d4ef69f into unslothai:main Sep 10, 2026
38 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants