Skip to content

fix: improve agent runtime correctness from upstream Pi#99949

Merged
steipete merged 3 commits into
mainfrom
codex/adopt-pi-runtime-fixes
Jul 4, 2026
Merged

fix: improve agent runtime correctness from upstream Pi#99949
steipete merged 3 commits into
mainfrom
codex/adopt-pi-runtime-fixes

Conversation

@steipete

@steipete steipete commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Closes #99924

What Problem This Solves

The agent runtime snapshot internalized in #85341 had drifted behind several correctness fixes in current earendil-works/pi. The gaps could lose untouched whitespace during fuzzy edits, truncate late descendant output, accept progress after tool completion, run split compaction summaries concurrently, miss provider overflow/retry signals, reject BMP inputs, and mishandle newer ChatGPT/Codex transport behavior.

Why This Change Was Made

This adopts the audited fixes at OpenClaw's existing owner boundaries instead of importing Pi's architecture wholesale:

  • preserves untouched file bytes during fuzzy multi-edit and strips model-added edit metadata before strict validation;
  • respects nested Git boundaries in find, drains finite descendant output with an absolute deadline, and ignores late tool progress;
  • serializes split-turn compaction summaries and makes the prompt provider-neutral;
  • aligns configured-context overflow and transient-provider retry classification;
  • aligns the ChatGPT transport with current Codex: synchronous first-request user agent, OpenAI-only zstd SSE bodies, websocket connection-limit reconnect, and proactive socket rotation;
  • validates BMP headers and pixel limits, then lazily converts BMP to PNG through Photon only when Rastermill rejects the format;
  • updates @earendil-works/pi-tui from 0.78.0 to 0.80.3.

No compatibility shim, parallel runtime path, config key, or environment variable was added. Pi model-registry, orchestrator/RPC, and project-trust changes were intentionally not adopted because OpenClaw owns those surfaces differently.

Direct dependency inspection:

  • ../codex/codex-rs/codex-client/src/request.rs:180-225 — zstd level 3 and content-encoding ownership.
  • ../codex/codex-rs/core/src/client.rs:1329-1337 — compression requires Codex-backend auth and an OpenAI provider.
  • ../codex/codex-rs/features/src/lib.rs:1010-1014 — compression is stable and default-enabled.
  • ../codex/codex-rs/codex-api/src/endpoint/responses_websocket.rs:156-161,578-588 — 60-minute connection-limit code and retry mapping.
  • ../codex/codex-rs/core/tests/suite/client_websockets.rs:1521-1565 — reconnect behavior.
  • ../codex/codex-rs/login/src/auth/default_client.rs:138-161 — synchronous OS-specific user-agent generation.

User Impact

Agent edits preserve unrelated formatting, long-lived/background commands retain their finite output without hanging forever, compaction and retry behavior are deterministic, BMP attachments work, the TUI picks up current upstream fixes, and ChatGPT sessions use the current Codex transport contract without changing custom relay request bodies.

Evidence

  • Final rebased Testbox focused suite: 15 files, 183 tests passed.
  • Final rebased TUI PTY lane: 13/13 passed.
  • Final rebased pnpm check:changed: all-project typecheck, core/extensions/scripts lint, lock/ownership guards, and runtime cycle check passed with no temp-directory warnings.
  • Final rebased pnpm build: passed; lazy runtime boundary and packaged surfaces verified.
  • Testbox: blacksmith-testbox, lease tbx_01kwpawtc0xts08q74g94skyqy (silver-lobster), initial run 28703395131.
  • Real tool scenario on Testbox: REAL_TOOL_SCENARIO_OK edit find bash bmp.
  • Live OpenAI API gpt-5.5: LIVE_OPENAI_API_OK input=28 output=12.
  • ChatGPT-subscription SSE reached the backend but the available service token was expired: Provided authentication token is expired. Please try signing in again. The transport behavior is covered by focused tests and the direct Codex source contract above; this remains the explicit live-proof gap.
  • Autoreview: four rounds with all six actionable P2 findings accepted and fixed (bounded drain, retry false positives, lazy Photon, dependency ownership, transient quota handling, OpenAI-only zstd). Final command .agents/skills/autoreview/scripts/autoreview --mode local --prompt-file /tmp/openclaw-pi-autoreview.md --stream-engine-output returned no findings and patch is correct at 0.93 confidence.

AI-assisted implementation and review; maintainer-directed upstream audit and landing workflow.

@steipete
steipete requested a review from a team as a code owner July 4, 2026 11:57
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Jul 4, 2026
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

  • npm-shrinkwrap.json
  • package.json
  • pnpm-lock.yaml

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfile, shrinkwrap, or workspace dependency policy changes are present.
  • Treat package-lock.json and npm-shrinkwrap.json diffs as security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Jul 4, 2026
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Dependency graph changes noted

This PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin or a member of @openclaw/openclaw-secops.

  • Current SHA: 96be40767b03f0a9e0b8ba0a5952012936999738
  • Trusted actor: @steipete
  • Trusted role: pull request author; openclaw-secops

Security review is still recommended before merge when the dependency graph change is intentional.

@clawsweeper

clawsweeper Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 17d92fa9c81e2ae738b704fce6799a7300f0e3c7, but the PR head is now 96be40767b03f0a9e0b8ba0a5952012936999738. Its old verdict and PR readiness labels are no longer current.

Next step
Run or wait for a fresh ClawSweeper review on the current PR head.

Review history (3 earlier review cycles)
  • reviewed 2026-07-04T12:04:37.313Z sha 0d4b190 :: needs real behavior proof before merge. :: [P1] Preserve untouched spans inside fuzzy-matched lines
  • reviewed 2026-07-04T12:35:02.052Z sha 5c951db :: needs real behavior proof before merge. :: [P1] Gate zstd compression to native ChatGPT URLs | [P1] Preserve untouched spans inside fuzzy-matched lines
  • reviewed 2026-07-04T12:41:39.313Z sha 5c951db :: needs real behavior proof before merge. :: [P1] Gate zstd compression to native ChatGPT URLs | [P1] Preserve untouched spans inside fuzzy-matched lines

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 4, 2026

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

Copy link
Copy Markdown
Contributor

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: 0d4b19019c

ℹ️ 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 +372 to +375
const canCompressSseBody = model.provider === "openai" && !sseHeaders.has("content-encoding");
const compressedBody = canCompressSseBody ? compressRequestBodyZstd(bodyJson) : null;
if (compressedBody) {
sseHeaders.set("content-encoding", "zstd");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Gate zstd compression to native ChatGPT

When models.providers.openai or an OpenAI model entry uses a custom baseUrl, the provider remains openai, so this branch now compresses the SSE request and sets content-encoding: zstd before the fetch goes to resolveCodexUrl(model.baseUrl). Generic ChatGPT-compatible relays and custom OpenAI base URLs previously received plain JSON unless they explicitly set an encoding, and many will reject or misread zstd bodies. Please restrict compression to the native ChatGPT backend (empty/default baseUrl or chatgpt.com) rather than the provider id alone.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. label Jul 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: slack Channel integration: slack gateway Gateway runtime commands Command implementations labels Jul 4, 2026
@steipete
steipete force-pushed the codex/adopt-pi-runtime-fixes branch from 17d92fa to 96be407 Compare July 4, 2026 12:58
@openclaw-barnacle openclaw-barnacle Bot removed docs Improvements or additions to documentation channel: slack Channel integration: slack gateway Gateway runtime commands Command implementations labels Jul 4, 2026
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 4, 2026
@clawsweeper clawsweeper Bot removed the status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. label Jul 4, 2026
@steipete

steipete commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 96be40767b03f0a9e0b8ba0a5952012936999738:

  • Upstream audit: compared earendil-works/pi v0.80.3/current source and adopted the applicable correctness improvements for OpenClaw's agent tools, process lifecycle, compaction/overflow/retry handling, ChatGPT Responses transport, BMP input, and Pi TUI dependency.
  • Focused Testbox: 15 files / 183 tests passed on Blacksmith Testbox tbx_01kwpawtc0xts08q74g94skyqy (silver-lobster).
  • Local focused follow-up: node scripts/run-vitest.mjs src/scripts/test-projects.test.ts src/agents/sessions/tools/find.fd.test.ts src/agents/sessions/tools/read.test.ts passed (93 tests).
  • Post-rebase changed-surface proof: 13 files / 224 tests passed against main 3706c2b3bd9; the manual conflict preserved main's shared path helper plus this PR's Git-boundary behavior. Fresh resolved-surface autoreview was clean (0.78 confidence).
  • Static/package proof: pnpm check:changed passed; Testbox pnpm build passed; TUI PTY suite passed 13/13.
  • Real tool scenario: edit, find, bash, and BMP read paths passed end to end.
  • Live provider proof: OpenAI API gpt-5.5 completed successfully (input=28, output=12). ChatGPT subscription SSE reached the backend but the available subscription token was expired; subscription-auth live proof remains the only known gap.
  • Autoreview: four Codex rounds resolved all findings; final full-patch review clean (0.93 confidence). The later two-line test-routing follow-up also received a clean $autoreview report (Copilot engine, 0.95 confidence) after nested Codex review processes stopped before emitting a report.
  • Native PR prepare: build and full check passed. Its broad local test run found one PR-caused routing expectation, now fixed and covered above. The remaining 20 failing files all reproduce individually on current origin/main at 706443c79b1, outside this PR's diff.
  • Hosted exact-head CI: all relevant checks green.

No changelog entry: repository policy reserves CHANGELOG.md for releases.

@steipete
steipete merged commit 5ea80c8 into main Jul 4, 2026
108 of 116 checks passed
@steipete
steipete deleted the codex/adopt-pi-runtime-fixes branch July 4, 2026 13:08
@steipete

steipete commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 5, 2026
* fix: improve agent runtime correctness

* test: track agent tool temp directories

* test: update helper routing expectation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling dependencies-changed PR changes dependency-related files maintainer Maintainer-authored PR P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve agent runtime correctness from upstream Pi audit

1 participant