Skip to content

Deliver native Codex generated images - #762

Open
sol-kami-bot wants to merge 3 commits into
ClickHouse:mainfrom
sol-kami-bot:agents/eugene-kami/codex-native-image-delivery
Open

sol-kami-bot wants to merge 3 commits into
ClickHouse:mainfrom
sol-kami-bot:agents/eugene-kami/codex-native-image-delivery

Conversation

@sol-kami-bot

@sol-kami-bot sol-kami-bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codex app-server emits a native completed image item when a generated image is available. Nerve currently drops the image unless the assistant explicitly sends the resulting file itself.

Normalize the completed inline image event, import it as a workspace artifact, and reuse the existing active-channel file delivery path. Record the outcome on the tool card and deduplicate repeated completion events within a turn. Leave file references and unsupported payloads to the existing explicit file flow.


Note

Medium Risk
Changes file delivery, workspace write policy, and per-turn channel routing (hosted connections and Telegram topics), though bounded inline data and git/path checks limit exposure.

Overview
Adds automatic delivery for native Codex imageGeneration results when the runtime returns bounded inline PNG/JPEG/WebP bytes. The Codex backend maps completion items to a new GeneratedImage agent event (not savedPath/fileId), and backend notes steer the model away from duplicating delivery with send_file.

The engine validates and saves images via store_generated_image under output/generated-images/ (hashed paths, git exclusion checks, symlink-safe writes), surfaces them as ordinary send_file cards in web history, dedupes repeat completions per turn, and async-uploads validated bytes to the originating channel when post_answer and SEND_FILES apply—without blocking the Codex turn on slow uploads.

Channel/router work binds reply destinations per inbound turn (hosted connection_id, Telegram forum message_thread_id), supports optional in-memory content on send_file, and splits batched messages by actor and destination so attachments stay with the right chat/topic. files.exclude is centralized in nerve.utils.workspace_paths and applied consistently to downloads, generated-image cards, and explicit send_file results; the web UI shows a text-only status when download is blocked but channel send may still succeed.

Config-repo .gitignore documents the new runtime output directory; extensive tests cover protocol mapping, storage hardening, engine/upload lifecycle, and routing edge cases.

Reviewed by Cursor Bugbot for commit 521ae72. Bugbot is set up for automated code reviews on this repo. Configure here.

@cla-assistant

cla-assistant Bot commented Nov 28, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread nerve/agent/engine.py Resolved
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

AI review gate — Cursor Bugbot found issues

  • Cursor Bugbot found issues that are not resolved (check concluded 'neutral').

Unresolved findings (2):

What to do:

  • Fix the findings and push. The reviewer re-reviews the new commit and the gate re-runs by itself.
  • A finding you think is wrong: a maintainer of the repository (maintain or admin role, the author included) replies in its thread with why and resolves it, then re-run the gate.
  • Finding wrong, or reviewer stuck? Ask a human with write access who is not the PR author to approve this exact commit, then re-run the gate. Their approval stands in for the AI review (a new push needs a new approval).

Re-run the gate with “Re-run jobs” after an approval or a finished review. A push re-runs it automatically.

@nerveai

nerveai commented Nov 28, 2026 •

Copy link
Copy Markdown

Nerve PR review · ✅ Ready to merge

Updated for 521ae72: this "merge upstream main" commit also adds about 570 lines of new work beyond the conflict fixes (git show --remerge-diff 521ae72). Reviewers should know it is there. The new work is sound and tested:

  • an explicit send_file in a channel turn now goes to that turn's own topic or hosted connection, not the last inbound message (nerve/channels/router.py:400-434, :537-542);
  • a path hidden by files.exclude now shows a "Web download unavailable" status instead of a card whose download returns 404 (nerve/agent/tools/handlers/notifications.py:469-495, nerve/agent/engine.py:3780, SendFileBlock.tsx:43);
  • the exclusion helpers moved to nerve/utils/workspace_paths.py.

Inline Codex images still become normal send_file cards and are uploaded to the channel the turn came from. This is a real gain for Codex users.

Completeness: tests cover the topic and connection races, symlinked workspaces and excluded paths; docs updated; no config or migration needed.

Worth considering:

  • The two Bugbot findings that hold gate look like false positives. slack-sdk 3.46.0 files_upload_v2 accepts bytes (slack_sdk/web/internal_utils.py:343). An enclosing repo also applies the nested generated-images/.gitignore * rule (nerve/agent/generated_images.py:38), and plain git confirms check-ignore returns 0 there.
  • Telegram topics: a session per topic, notifications in the topic, rich messages, and auto topics #728 (Telegram topics) still conflicts in nerve/channels/telegram.py. Whichever PR lands second should switch to the other's topic addressing (telegram.py:1586).

Checked: full suite in an offline sandbox at 521ae72 (3 chunks): 12091 passed, 41 skipped; test_slack_integration.py excluded (hangs offline on main too). Web sandbox: build OK, 193 files / 3248 tests passed. Merges cleanly with main. CI is waiting for maintainer approval, CLA pending · automated review by nerveai — mention @nerveai to ask a follow-up.

@alex-clickhouse

Copy link
Copy Markdown
Collaborator

The runtime never learns that the image went out: the card is engine-side only (nerve/agent/engine.py:3556), and no prompt or TOOLS.md line says so. An agent that copies savedPath into the workspace and calls send_file (the only route until now) posts the image twice.

This actually seems like it might happen and be quite annoying, is there a good way to inform the agent that the image went out and not to use send_file? (Or maybe a codex-specific instruction in the system prompt?)

@sol-kami-bot

Copy link
Copy Markdown
Author

@alex-clickhouse I added a Codex-only developer instruction in c98b35f. It tells Codex that Nerve handles inline generated images and to avoid copying or resending the same image by default. The instruction describes automatic channel delivery as best-effort, so Codex should not report delivery as confirmed.

On the durable result question from @nerveai, this change handles inline results. For a file-ID-only result, explicit delivery remains available if the runtime already has a verified workspace file it is allowed to share. Nerve does not fetch the ID or interpret it as a path.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 521ae72. Configure here.

except subprocess.TimeoutExpired:
raise ValueError("Could not verify Git exclusion for generated image") from None
if result.returncode != 0:
raise ValueError("Generated image path must be ignored and untracked by Git")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ancestor git repos block image saves

High Severity

_verify_git_exclusion runs git check-ignore for every ancestor that contains .git and aborts the save on any non-zero exit. After the nearest worktree already ignores the image, a higher repository (a project repo or a home dotfiles repo) still vetoes the write even though it does not track files inside the inner worktree. The import then fails and the image is never stored or delivered.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 521ae72. Configure here.

Comment thread nerve/channels/slack.py
await self._web.files_upload_v2(
channel=channel_id,
file=str(path),
file=str(path) if content is None else content,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Slack uploads reject in-memory bytes

Medium Severity

Generated-image delivery calls Slack files_upload_v2 with the validated content bytes as file. That parameter is a filesystem path or a file object, not raw bytes, so the client raises and the handler returns False. The image stays in the workspace, but it is not posted to Slack.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 521ae72. Configure here.

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.

3 participants