Skip to content

refactor(outbound): inline agent result envelope - #138332

Merged
steipete merged 1 commit into
mainfrom
codex/outbound-envelope73-mainc86-20260904
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/outbound-envelope73-mainc86-20260904

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The agent CLI JSON result path retained a one-caller envelope abstraction after payload planning and JSON projection had already moved into the delivery owner. That split ownership made copy and wire-format guarantees harder to follow without providing another supported behavior.

Why This Change Was Made

Build the result envelope at the existing emission boundary, using a shallow copy of already-canonical payloads and a single metadata snapshot. Preserve conditional metadata/status fields, property order and delivery/error/callback sequencing. Remove the unused envelope owner, delivery JSON type, redundant normalization wrapper and obsolete assertion-baseline row; move useful checks to the real owners.

Production: +3/-76 (net -73). Tests: +92/-104 (net -12). Tooling: 0/-1.

User Impact

No intended change to CLI output, channel delivery, public SDK behavior, configuration, storage schema, migration or protocol. The canonical payload planner/projector and delivery policy remain unchanged. This diff does not change dependencies.

Evidence

Reviewed integration head: 4944a0367b014c88a5e00c2dc03996491401cfa0, based on 8f986e0ea83969b3d0543b6fdc857ce7ff3ae6bc. The actual conflict was an adjacent assertion-baseline edit; the resolution preserves the upstream storage count and removes only the retired envelope row.

  • On the integrated head: normal frozen install, the full 16-phase build, and 164/164 focused delivery/payload/format/message-format cases passed. The current build includes the final test source and upstream dependency/tooling changes.
  • The built CLI passed the same sequential success → invalid-channel flow in a fresh isolated fixture: success exited 0, invalid preflight exited 1, success made one synthetic loopback Responses request, and invalid preflight made no additional request. All ancillary requests were accounted for. This is real CLI execution with a synthetic provider, not authenticated external-provider or live-channel proof.
  • All 30/30 normal configured changed checks passed on the integrated candidate. The ordinary invocation retained origin/main at c86d5b2d270eb2eb2a98cf5070f5efe19eb068c3 for transport/ratchets; explicit changed paths selected the lanes. This is not a claim that exact-head hosted PR CI has passed.
  • The resolved precommit review and the exact signed-head Codex review each completed six passes with no actionable P0–P2 findings. Source, index/config/refs and all 12,245 built output entries remained unchanged through the exact-head review.
  • Retained tests-first proof on the original base: 168 original → 169 characterized → 164 candidate/restored cases passed. Deliberate array-alias, missing-metadata and missing-status controls produced the intended 2/2/3 failures and were restored exactly. Original and candidate builds also passed the same sequential CLI comparison.

Three earlier original standalone invalid-channel attempts timed out after 30 seconds; their cause remains unexplained. Successful same-order comparisons do not erase those observations or establish a cache/timing explanation. Earlier formatting/lint gate failures were corrected and retained before the passing complete gate.

One integration-save guard reported a raw-index mismatch before the signed continuation completed. The resulting parent, tree, source and index semantics were independently verified; the raw-index producer remains unknown. That guard is not reported as passed.

Hosted CI: exact-4944a0367b01 CI run 33916318683 passed on attempt 1. Final fresh GitHub mergeability/review checks and native landing remain pending. The completed integration proof is tied to the named base/head, not every later change on moving main.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 14:42

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

Inlining this at the emission boundary makes the ownership much clearer: payload normalization is already complete, so the JSON path only needs to snapshot the array and append optional metadata/status in the established order. The array copy is the important compatibility detail because writeJson is an external runtime boundary and must not be able to splice the delivered result. Removing the second normalization owner also reduces the chance that CLI JSON and delivery drift again.

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 7:51 PM ET / 23:51 UTC.

ClawSweeper review

What this changes

The PR assembles agent CLI JSON results at the delivery boundary, removes unused envelope helpers and types, and moves retained checks to the delivery and payload tests.

Merge readiness

✅ Ready for maintainer review

This remains useful, distinct cleanup: fetched main still retains the abstraction, while the reviewed patch preserves the documented JSON contract without a blocking correctness or security finding.

Priority: P3
Reviewed head: 4944a0367b014c88a5e00c2dc03996491401cfa0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-supported cleanup preserves the output contract and strengthens owner-boundary checks without an identified merge blocker.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this maintainer-authored, behavior-neutral refactor. The captured body reports built-CLI success and invalid-channel execution through the delivery/output path with a synthetic provider, supplemented by focused tests; it does not claim authenticated provider or live-channel proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer-authored, behavior-neutral refactor. The captured body reports built-CLI success and invalid-channel execution through the delivery/output path with a synthetic provider, supplemented by focused tests; it does not claim authenticated provider or live-channel proof.
Evidence reviewed 11 items Pinned patch ownership: The verified origin is openclaw/openclaw, and the checkout matches original head 4944a03 with raw parent 8f986e0. The introduced delta matches the supplied eight-path patch; endpoint drift was not attributed to this PR.
JSON emission preserves the existing contract: The owner constructs normalizedPayloads through the canonical JSON projector before emission. The replacement preserves the separate payload array, truthy metadata inclusion, optional deliveryStatus, field order, and emission-before-callback-before-rethrow sequencing. Every projected payload already has mediaUrl, so the removed helper's raw-payload normalization branch was not needed by this caller.
Current main still retains the cleanup target: Fetched main retains buildOutboundResultEnvelope and the redundant normalization wrapper. Comparing its three surviving production files against the reviewed head yields only this PR's narrow production changes, rather than unrelated base-branch reversions.
Findings None None.
Security None None.

How this fits together

Agent-command delivery converts completed agent replies into canonical payloads, optionally sends them to a channel, and reports the outcome. Its JSON output feeds CLI consumers, while a separate result callback records delivery evidence.

flowchart TD
  A[Completed agent reply] --> B[Canonical payload planning]
  B --> C[Optional channel delivery]
  B --> D[JSON result assembly]
  C --> D
  D --> E[Runtime JSON writer]
  E --> F[CLI stdout]
  D --> G[Delivery result callback]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -73, Tests -12, Other -1. Total -86 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 3 76 -73
Tests 3 92 104 -12
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 8 95 181 -86

Review metrics

Metric Value Why it matters
Production versus test footprint Production net −73 lines; tests net −12; tooling net −1 The reduction removes a single-caller abstraction and redundant coverage while retaining output guarantees at the real owners.

Technical review

Best possible solution:

Keep envelope assembly at its sole emission owner, preserve canonical payload planning and callback ordering, and remove the unused parallel abstraction without adding compatibility shims.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR does not claim to fix a user-visible defect; review checks behavioral equivalence of the existing JSON output contract.

Is this the best way to solve the issue?

Yes. The sole caller already owns canonical JSON projection, so local assembly removes unnecessary branching without duplicating normalization or changing the supported SDK; retaining the generic helper offers no remaining production behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 66fa0bd2be4f.

Labels

Label justifications:

  • P3: This is behavior-preserving internal cleanup with no new user-facing capability, configuration, or identified regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored, behavior-neutral refactor. The captured body reports built-CLI success and invalid-channel execution through the delivery/output path with a synthetic provider, supplemented by focused tests; it does not claim authenticated provider or live-channel proof.

Evidence

What I checked:

  • Pinned patch ownership: The verified origin is openclaw/openclaw, and the checkout matches original head 4944a03 with raw parent 8f986e0. The introduced delta matches the supplied eight-path patch; endpoint drift was not attributed to this PR. (4944a0367b01)
  • JSON emission preserves the existing contract: The owner constructs normalizedPayloads through the canonical JSON projector before emission. The replacement preserves the separate payload array, truthy metadata inclusion, optional deliveryStatus, field order, and emission-before-callback-before-rethrow sequencing. Every projected payload already has mediaUrl, so the removed helper's raw-payload normalization branch was not needed by this caller. (src/agents/command/delivery.ts:882, 4944a0367b01)
  • Current main still retains the cleanup target: Fetched main retains buildOutboundResultEnvelope and the redundant normalization wrapper. Comparing its three surviving production files against the reviewed head yields only this PR's narrow production changes, rather than unrelated base-branch reversions. (src/infra/outbound/envelope.ts:27, 66fa0bd2be4f)
  • Release baseline: The supplied latest release, v2026.9.1, resolves locally to ad6fe23 and contains the same envelope helper. Its array-copy and conditional metadata behavior agree with the replacement; this cleanup is not already present in that release. (src/infra/outbound/envelope.ts:27, ad6fe23aecb9)
  • Documented CLI output: The CLI documentation defines payloads, meta, and top-level deliveryStatus, including sent, suppressed, partial_failed, and failed outcomes. The patch retains this shape and does not change delivery policy or exit sequencing. Public docs: docs/cli/agent.md. (docs/cli/agent.md:197, 4944a0367b01)
  • Caller and sibling boundaries: Post-run processing passes the completed result into the delivery owner and separately records callback evidence; ACP execution uses the same delivery owner. Gateway CLI output independently projects result.deliveryStatus. These paths and the runtime JSON writer remain unchanged. The modified contract is OpenClaw-owned output assembly, with no affirmative dependency on Codex protocol or runtime semantics. (src/agents/command/post-run.ts:563, 4944a0367b01)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-04T15:42:51.418Z sha 37642d2 :: blocked before merge. :: none
  • reviewed 2026-09-04T16:53:56.993Z sha 37642d2 :: blocked before merge. :: none
  • reviewed 2026-09-04T17:42:04.955Z sha 37642d2 :: blocked before merge. :: none
  • reviewed 2026-09-04T20:42:51.960Z sha 4944a03 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot closed this Sep 4, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Sep 4, 2026
@openclaw-barnacle openclaw-barnacle Bot closed this Sep 4, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Sep 4, 2026
@steipete
steipete force-pushed the codex/outbound-envelope73-mainc86-20260904 branch from 37642d2 to 4944a03 Compare September 4, 2026 20:27
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 4, 2026
@steipete steipete self-assigned this Sep 4, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 4, 2026
@steipete
steipete merged commit dcdbd05 into main Sep 5, 2026
195 checks passed
@steipete
steipete deleted the codex/outbound-envelope73-mainc86-20260904 branch September 5, 2026 01:16
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants