Skip to content

fix(cli): preserve shell profiles when completion install fails - #117987

Merged
steipete merged 4 commits into
mainfrom
codex/autoqa-completion-profile-atomic-20260802
Aug 2, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/autoqa-completion-profile-atomic-20260802

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #117980

What Problem This Solves

Fixes an issue where users installing cached shell completions could lose unrelated zsh, Bash, Fish, or PowerShell profile contents when the final profile write failed. The command exited nonzero after the profile had already been truncated or partially replaced.

Why This Change Was Made

Completion profiles now publish through the same lightweight sibling-temp owner used by CLI media, with durable temp/parent sync, existing-mode preservation, and a profile-specific temp prefix. Existing profile symlinks are resolved to their referent, while missing profiles preserve shell symlink-before-.. traversal by creating and canonicalizing the lexical parent before publication.

The atomic publisher moved into output-file.runtime.ts so completion startup does not import the media store and media callers do not retain a parallel mode/cleanup policy.

This PR also repairs an inherited red-main env-var ratchet failure from #117205: a CUA driver constant contained the reserved OPENCLAW_ substring even though it was not an environment variable. The behavior-neutral rename restores the existing 515-name budget; the budget file is unchanged.

User Impact

Failed completion installation leaves an existing shell profile unchanged. Successful installation preserves unrelated profile lines, the prior file mode, and dotfile-manager symlinks. Missing profiles still use the shell-owned startup location and are created without an empty intermediate file.

Evidence

  • Current-main packaged repro: with an isolated HOME/state and deterministic zero-file-size limit, openclaw completion --shell zsh --install --yes exited 1 and truncated mode-0644 export IMPORTANT=keep to zero bytes.
  • Blacksmith Testbox tbx_01kz17806fyvy5ra9125fcjmpf, run https://github.com/openclaw/openclaw/actions/runs/30747948101:
    • 255/255 final focused assertions passed across completion runtime/write-state, infer media, node media, full node CLI, and the CUA driver owner.
    • Full unscoped check:changed passed across core and extension production/test typechecks, targeted lint, dependency/plugin boundaries, database/media guards, env ratchet 515/515, and zero runtime import cycles.
    • Full build passed and verified all 149 public Plugin SDK subpaths plus the production Control UI build.
    • Source-blind built-CLI contract passed three cases: normal install preserved unrelated content and mode 0640; forced failure exited 1 with prior contents/mode and no temp; symlinked .zshrc remained a symlink while its target received the completion block.
  • ClawSweeper identified a dangling relative profile symlink compatibility gap at confidence 0.94. The accepted correction passed 65/65 completion tests and a clean 0.96 autoreview.
  • Exact head 5436a1eee9927ddf7a5a55100d0a31bd2bd75c4d on Blacksmith Testbox tbx_01kz19f6t06t982hwzs9vh10zz, run https://github.com/openclaw/openclaw/actions/runs/30749316372: remote HEAD and clean tree verified before the full build passed, including all 149 public Plugin SDK subpaths and the production Control UI build.
  • Final source-blind built-CLI contract passed four cases: normal install preserved content/mode; forced failure preserved prior bytes/mode with no temp; a valid symlink remained intact; and a dangling relative symlink remained managed/zshrc while its target was created and populated.
  • Final head 0851909e5995a705b0b20bdcbd57da69cb941792 adds only the hosted-lint unknown catch narrowing; targeted type-aware lint passed and its autoreview was clean at 0.99.
  • Hosted final-head CI run https://github.com/openclaw/openclaw/actions/runs/30749679003 returned GREEN from the repository watcher, with no failed or pending PR check.
  • Final autoreviews: full candidate clean at correctness confidence 0.97; dangling-symlink correction clean at 0.96; lint-only correction clean at 0.99; no accepted/actionable finding remains.
  • git diff --check passed.
  • Public model identifier gate: PASS; the diff adds no model identifier.

Production delta: +95/-44 (net +51). Tests: +114/-9. Docs: +2/-0. The production growth is the lightweight shared publisher plus durable profile publication that preserves shell-specific parent traversal, valid symlinks, and dangling relative symlinks; the prior media-local publisher was removed rather than duplicated. No config, protocol, storage, migration, dependency, provider, Gateway, or completion-script format change.

AI-assisted: yes. No agent transcript attached by user preference.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes plugin: cua-computer size: M maintainer Maintainer-authored PR labels Aug 2, 2026
@steipete
steipete marked this pull request as ready for review August 2, 2026 12:54
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 9:34 AM ET / 13:34 UTC.

ClawSweeper review

What this changes

The branch makes shell-completion installation publish profile updates atomically, preserving existing profile bytes, permissions, and symlink targets if a write fails.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This PR is still necessary: current main retains the direct completion-profile write that can replace an existing profile before a write failure. The patch moves that publication onto the established sibling-temp owner, preserves modes and symlink-owned targets, and has no actionable correctness finding; the maintainer label keeps the final merge decision with a human reviewer.

Priority: P1
Reviewed head: 0851909e5995a705b0b20bdcbd57da69cb941792

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The repair has focused compatibility coverage, concrete built-CLI behavior proof, and no supported correctness or security finding.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body provides exact-head, source-blind built-CLI proof for successful installation, forced failure preservation, valid symlinks, and dangling relative symlinks, alongside a green hosted CI run.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body provides exact-head, source-blind built-CLI proof for successful installation, forced failure preservation, valid symlinks, and dangling relative symlinks, alongside a green hosted CI run.
Evidence reviewed 6 items Current-main gap: Current main has an atomic publisher for CLI media output, but completion installation is not a caller; the PR adds the completion caller and its profile-specific durable publication path.
Repair boundary: The proposed install path resolves the profile target before publication, writes through a sibling temporary file, enables durable sync, and only then replaces the target.
Compatibility coverage: Focused tests cover a forced publication failure without truncating the original profile or changing mode, an existing profile symlink, and a dangling relative profile symlink whose target must be created.
Findings None None.
Security None None.

How this fits together

The completion CLI reads a cached completion script and adds a managed source block to a shell startup profile. The new shared output publisher stages the updated profile beside its destination, then atomically replaces the resolved file so failures do not damage unrelated user shell configuration.

flowchart LR
  A[Completion command] --> B[Shell startup profile]
  B --> C[Completion block update]
  C --> D[Resolve profile target]
  D --> E[Sibling temporary file]
  E --> F[Atomic durable replacement]
  F --> G[Shell profile or symlink target]
  H[CLI media outputs] --> E
Loading

Before merge

  • Resolve merge risk (P1) - The branch is marked behind current main; although the inspected three-way merge has no conflict in the affected paths, merge-time validation must retain the four profile compatibility cases.
  • Resolve merge risk (P1) - This deliberately changes replacement semantics for existing shell profiles and symlink targets, so the maintainer should preserve the documented mode and symlink behavior when accepting it.
  • Complete next step (P2) - No mechanical repair is needed; the protected maintainer label requires an explicit maintainer merge decision after current-base integration confirmation.
Agent review details

Security

None.

PR surface

Source +51, Tests +105, Docs +2. Total +158 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 95 44 +51
Tests 2 114 9 +105
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 211 53 +158

Review metrics

Metric Value Why it matters
Profile compatibility cases 4 built-CLI cases The provided proof covers normal installation, failed publication, existing symlinks, and dangling relative symlinks—the compatibility surface changed by this PR.

Stored data model

Persistent data-model change detected: serialized state: src/cli/completion-runtime.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Accept the compatible atomic publication path (recommended)
    Merge after the current-base result confirms the four existing-profile and symlink cases remain covered, accepting the intentional preservation of modes and symlink-owned targets.
  2. Pause for a narrower shell-profile contract
    Pause only if maintainers do not want completion installation to preserve existing symlink targets and modes, then define that contract before changing profile replacement behavior.

Technical review

Best possible solution:

Land the shared atomic publisher after the current-base merge result retains the built-CLI cases for normal profiles, failed writes, valid symlinks, and dangling relative symlinks; keep shell-profile semantics centralized in the shared publisher rather than adding another completion-specific write path.

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

Yes, source-reproducible: current main writes the final completion profile directly, while the supplied deterministic built-CLI case shows a write failure can leave the prior profile truncated. I did not execute the reproduction because this review is read-only.

Is this the best way to solve the issue?

Yes. Reusing the existing sibling-temp publisher is the narrowest maintainable repair because it fixes the destructive write at its owner boundary while preserving established mode and cleanup behavior for other CLI outputs.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3748fcfd2c99.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: A failed completion installation can erase unrelated shell startup configuration, affecting a user-facing CLI workflow.
  • merge-risk: 🚨 compatibility: The patch changes replacement behavior for pre-existing profile files, modes, and symlink targets.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body provides exact-head, source-blind built-CLI proof for successful installation, forced failure preservation, valid symlinks, and dangling relative symlinks, alongside a green hosted CI run.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head, source-blind built-CLI proof for successful installation, forced failure preservation, valid symlinks, and dangling relative symlinks, alongside a green hosted CI run.

Evidence

Acceptance criteria:

  • [P1] Preserve the exact-head built-CLI cases for normal installation, forced publication failure, valid profile symlink, and dangling relative profile symlink.
  • [P1] Confirm the merge result against current main remains clean and retains focused completion-runtime coverage.

What I checked:

  • Current-main gap: Current main has an atomic publisher for CLI media output, but completion installation is not a caller; the PR adds the completion caller and its profile-specific durable publication path. (src/cli/media-output.ts:20, 3748fcfd2c99)
  • Repair boundary: The proposed install path resolves the profile target before publication, writes through a sibling temporary file, enables durable sync, and only then replaces the target. (src/cli/completion-runtime.ts:466, 0851909e5995)
  • Compatibility coverage: Focused tests cover a forced publication failure without truncating the original profile or changing mode, an existing profile symlink, and a dangling relative profile symlink whose target must be created. (src/cli/completion-runtime.test.ts:345, 0851909e5995)
  • Shared-owner provenance: The current main history identifies the existing atomic output behavior as a recent CLI/node failure-preservation repair, so extracting its publisher rather than introducing a parallel completion-only writer follows the established owner boundary. (src/cli/media-output.ts:20, 5739f42c4877)
  • Integration state: No current-main changes touch the proposed completion, media-output, node-camera, file-publication, docs, or CUA-driver paths after the PR base; a three-way merge-tree check showed no conflict markers. GitHub nevertheless reports the branch as behind, so final merge machinery should use the current merge result. (src/cli/completion-runtime.ts:466, 0851909e5995)
  • Real behavior proof: The PR body records exact-head built-CLI proof for normal installation, forced failure, valid symlinks, and dangling relative symlinks, plus a green hosted CI run for the final head. (src/cli/completion-runtime.test.ts:345, 0851909e5995)

Likely related people:

  • steipete: Current main attributes the adjacent screen-output write-failure repair to this person, and the current branch continues that shared atomic-publication boundary. (role: recent CLI filesystem-safety contributor; confidence: high; commits: 5739f42c4877, 9148c4906178, 5436a1eee992; files: src/cli/media-output.ts, src/cli/completion-runtime.ts, src/cli/output-file.runtime.ts)
  • Sarah Fortune: History shows a prior completion-profile source-line guard repair, making this person a useful adjacent owner for shell-profile semantics. (role: prior completion-profile behavior contributor; confidence: medium; commits: f91de52f0d23, 5ff283cfbba8, 3b6ec521d5e5; files: src/cli/completion-runtime.ts, src/cli/completion-runtime.test.ts)

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 (3 earlier review cycles)
  • reviewed 2026-08-02T12:59:48.782Z sha bb990d5 :: found issues before merge. :: [P1] Preserve dangling profile symlinks
  • reviewed 2026-08-02T13:14:15.803Z sha 5436a1e :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T13:25:55.977Z sha 0851909 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 2, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 2, 2026
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head 0851909e5995a705b0b20bdcbd57da69cb941792.

Root cause: completion installation read the complete shell profile, built its replacement text, then called fs.writeFile(profilePath, update.next) on the final user-owned profile. A disk, quota, abort, or filesystem failure after open could therefore erase unrelated zsh, Bash, Fish, or PowerShell configuration before the CLI reported failure.

Provenance (clear): current blame traces the direct final-profile write to 0e54440ecc393ce0461835b1c479856833d7c192 (fix(cycles): remove browser cli and tlon runtime seams), authored by @vincentkoc on April 10, 2026, which extracted the existing completion runtime with the raw write intact. The inherited env-ratchet break came from #117205, whose CUA constant accidentally contained the reserved OPENCLAW_ substring despite not being an environment variable.

Canonical repair: completion profiles now publish through a lightweight shared CLI output owner with durable sibling-temp/parent sync and existing-mode preservation. Completion-specific resolution keeps shell symlink-before-.. traversal, existing dotfile-manager symlinks, and dangling relative symlinks intact; missing profiles use the same single publication flow without an empty intermediate file. Existing media callers reuse the lightweight owner without importing completion or adding a parallel policy. The CUA constant rename restores the existing 515-name env budget without changing runtime behavior or the budget file.

Proof:

  • Baseline packaged CLI with current-main-identical completion runtime: under an isolated HOME/state and deterministic zero-file-size limit, completion --shell zsh --install --yes exited 1 and truncated mode-0644 export IMPORTANT=keep to zero bytes.
  • Blacksmith Testbox tbx_01kz17806fyvy5ra9125fcjmpf, run https://github.com/openclaw/openclaw/actions/runs/30747948101: 255/255 final focused assertions passed across completion runtime/write-state, infer media, node media, full node CLI, and the CUA driver owner; full unscoped check:changed passed across core and extension typechecks/lint, env ratchet 515/515, database/media guards, and zero runtime cycles; full build passed with all 149 Plugin SDK subpaths and Control UI.
  • ClawSweeper identified one dangling-profile-symlink compatibility gap at confidence 0.94. The accepted fix passed 65/65 completion tests and a clean 0.96 autoreview.
  • Fresh exact behavior head 5436a1eee9927ddf7a5a55100d0a31bd2bd75c4d on Testbox tbx_01kz19f6t06t982hwzs9vh10zz, run https://github.com/openclaw/openclaw/actions/runs/30749316372: remote HEAD and clean tree verified before the full build passed, including all 149 SDK subpaths and Control UI.
  • Source-blind built CLI passed four cases: normal install preserved unrelated content and mode 0640; forced failure exited 1 with original bytes/mode and no temp; a valid symlink remained intact; a dangling relative symlink remained managed/zshrc while its target was created and populated.
  • The first final-head hosted run https://github.com/openclaw/openclaw/actions/runs/30749307204 exposed one lint-only catch-variable type error. The final commit narrows that value through unknown; targeted type-aware lint and a 0.99 autoreview passed.
  • Hosted exact final-head run https://github.com/openclaw/openclaw/actions/runs/30749679003 returned GREEN from the repository watcher, with no failed or pending PR check.
  • Final autoreviews: full candidate clean at correctness confidence 0.97; dangling-symlink correction clean at 0.96; lint-only correction clean at 0.99; no accepted/actionable finding.
  • ClawSweeper refreshed the exact head at 4/6 for readiness, proof, and patch quality with no finding. Its required-check/compatibility moves are resolved by the four-case built CLI contract, exact-head hosted green, and explicit maintainer decision to land.
  • Current origin/main is 3748fcfd2c99b355b60847931ccb6533992c33ee; local merge-tree construction succeeded and GitHub reports MERGEABLE.
  • Repo-native review artifacts validate READY FOR /prepare-pr with zero findings. OPENCLAW_TESTBOX=1 scripts/pr prepare-run 117987 completed without changing the head.
  • Public model identifier gate: PASS; the diff adds no model identifier.

Scope: 8 files; production +95/-44 (net +51), tests +114/-9, docs +2/-0. No config, protocol, storage, migration, dependency, provider, Gateway, completion-script-format, or CUA authorization behavior change. Residual risk is low and confined to local profile/output publication. No known proof gaps.

@steipete
steipete merged commit d720d78 into main Aug 2, 2026
143 of 153 checks passed
@steipete
steipete deleted the codex/autoqa-completion-profile-atomic-20260802 branch August 2, 2026 13:36
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 2, 2026
* origin/main:
  fix(ui): label Gateway connection settings for accessibility (#118000)
  ci(qa): extend profile evidence timeout (#117999)
  fix(googlechat): report a blocked account instead of a webhook path that was never bound (#117986)
  fix(line): preserve semantic indentation in fenced code (#117996)
  fix(plugins): contain rejected synchronous hook results (#117988)
  fix(cli): preserve shell profiles when completion install fails (#117987)
  fix(tui): preserve legitimate consecutive backspaces (#117989)
  fix: preserve queued messages during /compact (#117840)
  fix(talk): enforce relay lifecycle bounds
  fix(talk): enforce relay terminal precedence
  test(talk): cover relay tool-call retention overflow
  fix(talk): bound relay tool-call lifecycle state
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
…claw#117987)

* fix(cli): publish completion profiles atomically

Closes openclaw#117980

* fix(ci): restore environment variable budget

* fix(cli): preserve dangling completion profile symlinks

* fix(cli): narrow completion readlink failures
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
* origin/main:
  fix(ui): label Gateway connection settings for accessibility (openclaw#118000)
  ci(qa): extend profile evidence timeout (openclaw#117999)
  fix(googlechat): report a blocked account instead of a webhook path that was never bound (openclaw#117986)
  fix(line): preserve semantic indentation in fenced code (openclaw#117996)
  fix(plugins): contain rejected synchronous hook results (openclaw#117988)
  fix(cli): preserve shell profiles when completion install fails (openclaw#117987)
  fix(tui): preserve legitimate consecutive backspaces (openclaw#117989)
  fix: preserve queued messages during /compact (openclaw#117840)
  fix(talk): enforce relay lifecycle bounds
  fix(talk): enforce relay terminal precedence
  test(talk): cover relay tool-call retention overflow
  fix(talk): bound relay tool-call lifecycle state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. plugin: cua-computer proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

[Bug]: Completion install can erase shell profiles on write failure

1 participant