Repository navigation
refactor(process): consolidate command diagnostic tails - #134607
Conversation
Reuse the canonical output normalizer and suffix fitter for mixed-stream command errors, preserving terminal sanitation, shared budgets, Unicode boundaries, termination reasons, and independent result-output limits. Follow up on #134428 without reintroducing the Git facade consolidation owned by #132180. Production shrinks by 42 lines, offsetting the original repair's 42-line increase. Add focused behavioral controls; the landed original already passes the 22-case formatter baseline. Co-authored-by: Vincent Koc <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 31, 2026, 9:29 PM ET / September 1, 2026, 01:29 UTC. ClawSweeper reviewWhat this changesThe branch consolidates terminal-output normalization and tail fitting so command errors and result summaries use the same bounded formatter. Merge readinessNo discrete introduced correctness or security defect was found in this focused refactor. It remains open for normal maintainer handling because it is maintainer-owned and carries the protected Priority: P3 Review scores
Verification
How this fits togetherProcess execution captures stdout and stderr, then the command-error formatter turns failed results into safe, bounded diagnostics. Those diagnostics feed managed-worktree setup, Git operations, and Gmail setup errors that tell operators how to recover. flowchart LR
A[Command execution] --> B[Captured stdout and stderr]
B --> C[Command diagnostic formatter]
C --> D[Bounded safe tails]
D --> E[Worktree and Git failures]
D --> F[Gmail setup failures]
E --> G[Operator recovery guidance]
F --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource -42, Tests +91. Total +49 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the single shared formatter and land this refactor only after the normal maintainer review refresh confirms it remains equivalent on current main. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR is a behavior-preserving refactor, and no local execution was performed in the read-only review environment. Is this the best way to solve the issue? Yes for the reviewed branch: placing normalization and tail fitting in the shared formatter removes the parallel path while preserving the caller-facing diagnostic contract; current-main equivalence still needs refresh. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 3b758df6cb30. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
) Reuse the canonical output normalizer and suffix fitter for mixed-stream command errors, preserving terminal sanitation, shared budgets, Unicode boundaries, termination reasons, and independent result-output limits. Follow up on openclaw#134428 without reintroducing the Git facade consolidation owned by openclaw#132180. Production shrinks by 42 lines, offsetting the original repair's 42-line increase. Add focused behavioral controls; the landed original already passes the 22-case formatter baseline. Co-authored-by: Vincent Koc <[email protected]>
Related: #134607 ## What Problem This Solves Git snapshot backup failures lost useful operator diagnostics. - Failed push kept stderr or stdout, but not both. - Failed history exposed raw Git errors. - Empty history depended on one English Git message. - Persisted diagnostics could split a UTF-16 surrogate pair. ## Why This Change Was Made The Git snapshot owner now formats every failed Git result through one bounded path. That path redacts each output line before it reserves space for both streams. This keeps multi-line URL query credentials from consuming later diagnostics. Unborn repositories are detected from symbolic `HEAD` and exact branch-ref state. Corrupt refs and missing non-branch refs remain visible failures. The generic process formatter is unchanged. The backup record keeps the same 1,200 UTF-16-unit storage contract. ## User Impact Operators keep recent stderr and stdout details after a failed push or history read. Diagnostics remain bounded and remove URL user information and sensitive query values. Empty repositories still show an empty history. Successful create, push, history, and restore behavior is unchanged. ## Evidence - Current main `4fc24e6e0f81121cef0fb4395db29fb87700e7f6`: real `openclaw backup git create --push` lost stdout, and corrupt `backup git log` returned raw repeated Git errors. - Repaired tree: a real rejected `git push` retained both stream tails and persisted exactly 1,200 UTF-16 units with all synthetic URL credentials removed. - Repaired tree: real unborn history returned no commits; corrupt history returned a structured redacted error; successful push, log, and restore passed against a local bare remote. - Focused tests: 59 passed across process, snapshot, state, and command owners. - Final test-audit run: 28 snapshot and persistence tests passed with an emoji placed on the actual formatter cut boundary. - Packaged CLI E2E test: real init, failed push, unborn history, and corrupt history passed through `openclaw.mjs`. - Formatting and `git diff --check` passed. ### Redacted exact-head terminal trace ```text Git backup committed: <backup-commit> Warning: Git backup committed, but push failed: git push failed (code=1, termination=exit) stderr: … stderr-old-89 https://***:***@example.invalid/backup.git?access_token=*** stderr-tail-🦞 https://***:***@example.invalid/backup.git?access_token=*** error: failed to push some refs to '<temp>/remote.git' stdout: … stdout-old-89 https://***:***@example.invalid/backup.git?access_token=*** stdout-tail-🐚 https://***:***@example.invalid/backup.git?access_token=*** PASS failed-push persisted warning length=1200 UTF-16 units TRACE freshness equals create warning: true ``` Co-authored-by: Ayaan Zaidi <[email protected]>
Related: openclaw#134607 ## What Problem This Solves Git snapshot backup failures lost useful operator diagnostics. - Failed push kept stderr or stdout, but not both. - Failed history exposed raw Git errors. - Empty history depended on one English Git message. - Persisted diagnostics could split a UTF-16 surrogate pair. ## Why This Change Was Made The Git snapshot owner now formats every failed Git result through one bounded path. That path redacts each output line before it reserves space for both streams. This keeps multi-line URL query credentials from consuming later diagnostics. Unborn repositories are detected from symbolic `HEAD` and exact branch-ref state. Corrupt refs and missing non-branch refs remain visible failures. The generic process formatter is unchanged. The backup record keeps the same 1,200 UTF-16-unit storage contract. ## User Impact Operators keep recent stderr and stdout details after a failed push or history read. Diagnostics remain bounded and remove URL user information and sensitive query values. Empty repositories still show an empty history. Successful create, push, history, and restore behavior is unchanged. ## Evidence - Current main `6c0543988388bb12f47c3aedbb10e6342dbc4f6f`: real `openclaw backup git create --push` lost stdout, and corrupt `backup git log` returned raw repeated Git errors. - Repaired tree: a real rejected `git push` retained both stream tails and persisted exactly 1,200 UTF-16 units with all synthetic URL credentials removed. - Repaired tree: real unborn history returned no commits; corrupt history returned a structured redacted error; successful push, log, and restore passed against a local bare remote. - Focused tests: 59 passed across process, snapshot, state, and command owners. - Final test-audit run: 28 snapshot and persistence tests passed with an emoji placed on the actual formatter cut boundary. - Packaged CLI E2E test: real init, failed push, unborn history, and corrupt history passed through `openclaw.mjs`. - Formatting and `git diff --check` passed. ### Redacted exact-head terminal trace ```text Git backup committed: <backup-commit> Warning: Git backup committed, but push failed: git push failed (code=1, termination=exit) stderr: … stderr-old-89 https://***:***@example.invalid/backup.git?access_token=*** stderr-tail-🦞 https://***:***@example.invalid/backup.git?access_token=*** error: failed to push some refs to '<temp>/remote.git' stdout: … stdout-old-89 https://***:***@example.invalid/backup.git?access_token=*** stdout-tail-🐚 https://***:***@example.invalid/backup.git?access_token=*** PASS failed-push persisted warning length=1200 UTF-16 units TRACE freshness equals create warning: true ``` Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Follow-up to #134428, which fixed lost stdout diagnostics when failed commands also wrote stderr. That repair was merged separately and added a second normalization and allocation path in the command-error formatter. This PR consolidates that ownership while retaining both useful diagnostic tails and their shared output budget.
Why This Change Was Made
Reuse
formatCommandOutputfor terminal sanitation, carriage-return progress frames, line tails, and UTF-16 boundaries, then fit the prepared suffixes within the mixed-stream budget. This removes the parallel formatter and allocation machinery while preserving timeout, output-limit, signal, and buffered-error reasons. Result summaries retain their separate 800-unit per-stream limits.Production changes are +38/−80 (net −42); tests are +92/−1. Together with the original repair's +42 production lines, the pair is production-neutral. Vincent Koc's diagnostic and sanitation work is preserved and credited. The Git facade changes owned by #132180 remain outside this PR.
User Impact
Failed commands continue to show both stdout and stderr recovery information, including uneven stream lengths, without exceeding the shared diagnostic budget or splitting surrogate pairs. This is a consolidation of the landed behavior, not a claim that the new controls fail on the original repair. No configuration, storage, setup-capacity, or public API change is intended.
Evidence
check-changedprocess. Its outer protection check then failed because the unrelated primary checkout's index bytes changed. That failure is retained; a separate audit verified unchanged product, dependencies, hooks, protected checkout semantics, and process closure. No cause is attributed and the gate process was not replayed.Local proof used Node 26.8.1 and pnpm 12.1.0 on macOS. An earlier service attempt failed the real disk-capacity prerequisite; it remains recorded, and the same 14 cases later passed after available space recovered. This follow-up does not claim a new released-package, Windows, live-provider, or native Codex run. The original repair's separate CLI evidence remains historical.
The nearby snapshot/git-backup stderr-or-stdout paths remain a named follow-up: their 500-unit prefix cap, URL-userinfo redaction before slicing, and no-commit semantics need their own repair and proof.
Related: #134427. Thanks @vincentkoc for the original repair and terminal-safety work.