Skip to content

fix(first-agent): surface bounded subprocess stderr on failure - #1581

Merged
freeqaz merged 2 commits into
openclaw:mainfrom
goutamadwant:fix/first-agent-stderr-diagnostics
Oct 10, 2026
Merged

freeqaz merged 2 commits into
openclaw:mainfrom
goutamadwant:fix/first-agent-stderr-diagnostics

Conversation

@goutamadwant

Copy link
Copy Markdown
Contributor

Problem

Closes #1524. The local first-Agent helper drained subprocess stderr without retaining it, so a failed docker or kubectl command reported only an exit code and a generic hint.

Change

Retain at most 8 KiB of stderr in the existing subprocess runner. On failure, show the captured diagnostic after removing terminal control characters, mark truncated output, and keep the existing hint when stderr is empty. Successful stdout and subprocess arguments are unchanged.

Verification

The startup integration fixture now makes docker emit a concrete failure followed by oversized stderr. On the pre-fix source, its new assertion failed because the CLI showed only the generic exit message. With this change, all four startup tests pass; they also cover the empty-stderr fallback, bounded output, and terminal-control removal.

  • node --test tests/integration/first-agent-startup.test.mjs (4 passed)
  • pnpm lint
  • pnpm format:check
  • pnpm check:workspace
  • pnpm build
  • git diff --check

Risks

Verification uses isolated local subprocess fixtures, not a live Docker or Kubernetes installation. The diagnostic is capped and rendered on one line; subprocess timeout and termination behavior is unchanged.

Disclosure: AI was used to understand the codebase and review the fix.

@goutamadwant
goutamadwant requested a review from a team as a code owner October 7, 2026 03:31
@clawsweeper

clawsweeper Bot commented Oct 7, 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.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR includes up to 8 KiB of subprocess stderr in first-Agent failure messages.

Example: Docker exits 23 after writing “controller container is unavailable” to stderr.

  • Before: The helper reports exit 23 and a generic availability hint.
  • After: The helper reports exit 23 and the container-unavailable diagnostic.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and source-correct, but fixture-only evidence does not satisfy the required real-behavior proof gate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A failed local setup command hides the underlying tool error, forcing the user to repeat commands to discover the cause.
Reason: The linked report establishes a concrete diagnostic defect, and every introduced hunk serves its focused repair.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it provides a focused repair for diagnostic loss still present on main, and repository policy reserves closure for maintainer triage.

Priority: P2
Reviewed head: 53bc7d0eb926b24451aea2d17374bccec77abf50

Before merge

  • Add real behavior proof - The actual first-Agent runner is exercised by startup tests using stand-in Docker and kubectl executables, and the body reports a base failure followed by four passing tests. The body and discussion provide no real-tool after-fix diagnostic, so the previous proof request remains unresolved; add a terminal screenshot, transcript, or redacted logs identifying the revision and local environment, excluding API keys, IPs, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Findings

None.

Tests

  • Missing end-to-end proof: A redacted after-fix transcript must show the actual first-Agent command surfacing a real Docker or kubectl failure diagnostic in a local Enterprise installation.
Agent review details

How this fits together

The checkout-local first-Agent helper loads the recorded development installation, invokes container-engine and Kubernetes commands through one runner, and returns stdout or prints a failure diagnostic.

flowchart TD
  A[First Agent command] --> B[Recorded local installation]
  B --> C[Shared subprocess runner]
  C --> D[Docker or kubectl]
  D --> E[Captured process output]
  E --> F[Successful stdout]
  E --> G[Bounded failure diagnostic]
Loading

Technical review

Best possible solution:

Retain bounded failure diagnostics in the existing runner while preserving successful output, credential handling, and subprocess lifecycle.

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

Main source directly shows that a subprocess writing stderr and exiting nonzero loses its diagnostic; no target code or tests were executed during this read-only review.

Is this the best way to solve the issue?

Capturing bounded stderr in the existing shared runner addresses the reported cause without adding another execution path or changing command arguments.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against dc895d85e345.

Provenance checked

  • Shared subprocess failure reporting changes intended behavior with a stated reason (44c9c40: The original helper supported persistent local Agent deployment and model verification; its PR records no requirement to discard tool diagnostics.)
  • Existing startup fixture keeps the original intent (9681977: Startup coverage verifies current development-state admission; subsequent repairs add PostgreSQL targeting and local Docker environment checks, which this PR preserves.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • kevinlin-openai: Raw commit 44c9c40 adds scripts/first-agent.mjs:264 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 44c9c40c2fdd; files: scripts/first-agent.mjs)
  • Derek Carr: Raw commit dd2b058 adds scripts/first-agent.mjs:155 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: dd2b05871579; files: scripts/first-agent.mjs)
  • freeqaz: Raw commit 147d9fb adds scripts/first-agent.mjs:260 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 147d9fbc051e; files: scripts/first-agent.mjs)

Review metrics

Metric Value Why it matters
Change size Production +21/-2 lines; tests +13/-2 lines The small production addition stays within the existing runner, and the fixture extension protects observable failure output.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P2: This improves troubleshooting of a bounded local-development failure without changing deployment or runtime availability.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Supply the previously requested after-fix terminal evidence from real Docker or kubectl execution through the first-Agent command.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-07T03:34:46.207Z sha dcf83af :: needs real behavior proof before merge. :: none

Reviewed October 9, 2026, 10:19 PM ET / October 10, 2026, 02:19 UTC (Revision 2).

@freeqaz

freeqaz commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Free's clanker here (an AI agent reviewing on Free's behalf).

I reviewed dcf83af and approved its CI runs (a local helper script and its test, nothing CI-sensitive). This is a useful fix: an exit code with a generic hint was hard to act on.

What I checked:

  • Bounds. The 8 KiB stderr bound is enforced per chunk, the truncation marker is set correctly when a chunk straddles the limit, and stdout handling and the success path are unchanged.
  • No secrets in stdin. The only callers that feed stdin are the two psql paths in first-agent-database.mjs. Their SQL carries Namespace, Agent and Secret IDs, not secret values, so a psql error echoed through stderr can't expose credential material.
  • Empty stderr. It still falls back to the old hint.

Non-blocking nits:

  1. Escape remnants. \p{Cc} removes the ESC byte but leaves the rest of the sequence, so the fixture's \033[31m prints as controller container is unavailable [31m. Stripping whole escape sequences first, for example .replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "") before the \p{Cc} pass, keeps real tool output (kubectl and docker both colour some errors) readable. A test assertion that [31m is absent would pin it.
  2. Bidi and format characters. \p{Cc} doesn't cover Unicode format characters such as U+202E (right-to-left override), which can visually reorder terminal text. Adding \p{Cf} to the class closes that for a few characters' cost.
  3. UTF-8 split. Cutting at exactly 8 KiB can split a multi-byte UTF-8 character and leave a trailing U+FFFD. It's harmless; mentioning it only so nobody is surprised.

Ready to land once CI Required is green, with or without the nits.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 10, 2026
@freeqaz
freeqaz merged commit c01552e into openclaw:main Oct 10, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

first-Agent: run() helper discards subprocess stderr, hiding failure causes

2 participants