Skip to content

fix(openai): bound native shell output#507

Open
jdchawla29 wants to merge 1 commit into
mainfrom
jaideep/hud-2204-openai-shell-max-output-length
Open

fix(openai): bound native shell output#507
jdchawla29 wants to merge 1 commit into
mainfrom
jaideep/hud-2204-openai-shell-max-output-length

Conversation

@jdchawla29

@jdchawla29 jdchawla29 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • enforce the OpenAI shell call's effective max_output_length for each command
  • apply the same bounded stdout/stderr data to structured output and display content
  • preserve deterministic output prefixes and suffixes with an explicit truncation marker
  • reject malformed or unusably small limits before executing commands
  • cap missing or oversized limits at the Responses API's 10 MiB text-field ceiling

Root cause

The native OpenAI shell adapter returned max_output_length as metadata but copied the complete command result into display content and structured stdout/stderr. No execution-boundary truncation occurred, so noisy output could exceed the Responses API field limit and terminate the rollout before grading.

Validation

  • uv run --no-sync pytest -q hud/agents/openai/tools/tests hud/agents/tests/test_provider_native_tools.py hud/agents/tests/test_openai_agent.py hud/agents/tests/test_tool_agent.py (68 passed)
  • Ruff format and lint checks
  • Pyright on the touched implementation and tests

Linear: HUD-2204


Note

Medium Risk
Changes agent tool execution and result shaping on a critical path; behavior is well-tested but affects all native OpenAI shell calls.

Overview
OpenAI native shell now honors max_output_length instead of echoing full command output while only storing the limit as metadata—fixing rollouts that blew past Responses API text limits on noisy commands.

Execution parses and validates max_output_length (integer ≥ minimum, capped at 10 MiB); bad values return an error without running commands. Each command runs via conn.run with separate stdout/stderr, then _bound_output trims combined length per command using a truncation marker while keeping head/tail. Structured output and MCP text content both use the same bounded streams (one text block per command).

Tests cover huge stderr truncation, per-command limits, invalid limits, and default/ceiling effective limits; the fake SSH client now supports stderr.

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

@jdchawla29
jdchawla29 marked this pull request as ready for review July 23, 2026 10:27

@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: 109b6ca105

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

elif (
isinstance(requested_limit, bool)
or not isinstance(requested_limit, int)
or requested_limit < MIN_SHELL_OUTPUT_LENGTH

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 Honor valid small shell output limits

When OpenAI supplies a positive max_output_length below 28 (for example, 10), this rejects the entire shell call instead of executing it. The pinned OpenAI Action contract defines this value simply as the maximum characters returned per command and imposes no marker-sized minimum, so these are valid provider-generated limits; moreover, the resulting error text itself exceeds the requested limit. Accept small nonnegative limits and truncate the marker as necessary rather than failing the command.

AGENTS.md reference: AGENTS.md:L134-L135

Useful? React with 👍 / 👎.

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