Skip to content

fix: harden Crestodian maintenance flows - #105153

Merged
steipete merged 3 commits into
mainfrom
codex/crestodian-cli-soak
Jul 12, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/crestodian-cli-soak

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Closes #105109 and #105111.

  • Managed gateway restart could keep the installed LaunchAgent's stale port after gateway.port changed, so status targeted the new port while the service still launched on the old port.
  • Crestodian's auxiliary configured-model plan persisted trajectory events against a derived session target that has no durable session row, producing FOREIGN KEY constraint failed during otherwise successful CLI and TUI requests.

Why This Change Was Made

  • Treat the installed command arguments as the effective managed-service port, detect a config/service port mismatch, and repair the service before restart. Preserve intentional install-time port overrides when config does not explicitly own the port.
  • Carry restart intent through repair so the restarted process retains the original restart semantics and does not restart twice.
  • Add a request-scoped trajectory opt-out for auxiliary embedded runs with no durable session owner, and enable it for Crestodian planning.

User Impact

  • Changing gateway.port and restarting the managed gateway now repairs the LaunchAgent to the configured port instead of leaving the gateway unavailable.
  • Crestodian CLI and TUI questions no longer emit trajectory foreign-key cleanup errors.
  • Existing install-time gateway port overrides remain authoritative until gateway.port is explicitly configured.

Evidence

  • node scripts/run-vitest.mjs src/crestodian/assistant.configured.test.ts src/agents/embedded-agent-runner/run.before-agent-reply-cron.test.ts — 15 tests passed.
  • Focused daemon/CLI/plugin regression shards on the rebased branch — 119 tests passed.
  • Fresh structured autoreview — clean, no accepted/actionable findings.
  • Golden Gate pristine-snapshot package smoke at 8a37459464f: install/version, gateway RPC, Control UI, and real OpenAI agent turn passed. Artifact: .artifacts/parallels/openclaw-parallels-macos.iOJf6w.
  • Exact-head Crestodian CLI: fuzzy config inspection, typed config read/write, invalid-value refusal, and live RPC inspection passed without loader or trajectory errors.
  • Exact-head Crestodian TUI under expect: returned TUI_CONFIG_OK 18789; no loader or trajectory errors.
  • Current pristine snapshot is at the login window and no approved Golden Gate console credential exists, so this run could not repeat the managed LaunchAgent restart from a real gui/501 session. The restart behavior is covered by focused service/lifecycle regression tests; the headless foreground-gateway fallback was not misrepresented as LaunchAgent proof.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Jul 12, 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: 8a37459464

ℹ️ 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".

recoveredLoadedState = handledRecovery.loaded ?? null;
}

if (loaded && params.repairLoadedService) {

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 Repair unloaded services before restart recovery

When the managed service is installed but currently stopped/unloaded, this loaded gate skips the new port-drift repair entirely. In that scenario a user who changes gateway.port and then runs openclaw gateway restart (or start) can still re-bootstrap/kickstart the stale service definition on the old port: macOS takes the onNotLoaded LaunchAgent recovery path before this repair block, and the generic start path's repair collector also returns no issues unless the service is loaded. The result is the same unreachable-gateway state this change is trying to prevent whenever the stale service is not already loaded.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 12, 2026
@clawsweeper

clawsweeper Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 12, 2026, 4:40 AM ET / 08:40 UTC.

Summary
The PR repairs managed gateway port drift during start/restart and disables trajectory persistence for ephemeral Crestodian planning runs.

PR surface: Source +130, Tests +123. Total +253 across 16 files.

Reproducibility: yes. The linked reports provide exact-main user reproductions, and current-head source ordering gives a high-confidence reproduction of the remaining installed-but-unloaded LaunchAgent failure.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: migration/backfill/repair: src/cli/daemon-cli/start-repair.ts, migration/backfill/repair: src/daemon/service.test.ts, unknown-data-model-change: src/cli/daemon-cli/start-repair.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦐 gold shrimp
Patch quality: 🦐 gold shrimp
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Repair installed-but-unloaded LaunchAgent ordering and add start/restart regression coverage.
  • Post redacted real managed LaunchAgent stale-port proof.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: Exact-head Crestodian CLI and TUI output demonstrates the trajectory fix, but the PR explicitly lacks a real after-fix managed LaunchAgent stale-port start or restart; add redacted terminal output or a recording, then update the PR body to trigger a fresh review or ask a maintainer to comment @clawsweeper re-review.

Risk before merge

  • [P1] An installed-but-unloaded macOS LaunchAgent can still be bootstrapped with its stale port, leaving the configured gateway unreachable despite a successful start or restart message.
  • [P1] The gateway repair has not been demonstrated in the real managed LaunchAgent environment that originally exposed the bug.

Maintainer options:

  1. Complete unloaded-state repair (recommended)
    Repair installed-but-unloaded service definitions before LaunchAgent recovery, add focused regression coverage, and provide real macOS managed-service proof.
  2. Split the independently proven fix
    Separate the Crestodian trajectory fix if the gateway lifecycle change cannot be completed and proven promptly.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Inspect and repair explicit gateway.port drift before any installed-but-unloaded LaunchAgent recovery; preserve unset-config install overrides and restart intent, add start/restart regression tests, and leave real macOS proof as a contributor or maintainer merge gate.

Next step before merge

  • [P1] The blocking lifecycle defect is bounded and mechanically repairable on the PR branch; real managed LaunchAgent evidence remains a separate contributor or maintainer proof gate.

Security
Cleared: The internal runtime-and-test diff introduces no concrete dependency, workflow, permission, secret-handling, downloaded-code, or supply-chain concern.

Review findings

  • [P2] Repair unloaded services before restart recovery — src/cli/daemon-cli/lifecycle-core.ts:292-306
Review details

Best possible solution:

Inspect installed service definitions regardless of loaded state, repair explicit port drift before bootstrap or kickstart, preserve install-time overrides when gateway.port is unset, and prove real macOS start and restart behavior; retain the request-scoped Crestodian trajectory opt-out for its ephemeral planner.

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

Yes. The linked reports provide exact-main user reproductions, and current-head source ordering gives a high-confidence reproduction of the remaining installed-but-unloaded LaunchAgent failure.

Is this the best way to solve the issue?

No. The gateway fix handles loaded definitions but allows macOS recovery to launch an installed, unloaded stale definition before drift inspection; repair must occur before recovery. The Crestodian trajectory opt-out is otherwise a narrow OpenClaw-owned fix.

Full review comments:

  • [P2] Repair unloaded services before restart recovery — src/cli/daemon-cli/lifecycle-core.ts:292-306
    When the installed LaunchAgent is unloaded, onNotLoaded re-bootstraps the existing plist and returns before expected-port inspection; the repair collector also ignores unloaded state. Changing gateway.port can therefore still launch the stale port. Inspect and repair the installed definition before recovery, with both start and restart coverage.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9cf4f03afe1d.

Label changes

Label changes:

  • add P1: The central managed gateway start/restart workflow remains broken for a concrete installed-but-unloaded service state.
  • add merge-risk: 🚨 availability: Merging the incomplete lifecycle repair can still launch a stale-port service and leave the configured gateway unavailable.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Exact-head Crestodian CLI and TUI output demonstrates the trajectory fix, but the PR explicitly lacks a real after-fix managed LaunchAgent stale-port start or restart; add redacted terminal output or a recording, then update the PR body to trigger a fresh review or ask a maintainer to comment @clawsweeper re-review.

Label justifications:

  • P1: The central managed gateway start/restart workflow remains broken for a concrete installed-but-unloaded service state.
  • merge-risk: 🚨 availability: Merging the incomplete lifecycle repair can still launch a stale-port service and leave the configured gateway unavailable.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Exact-head Crestodian CLI and TUI output demonstrates the trajectory fix, but the PR explicitly lacks a real after-fix managed LaunchAgent stale-port start or restart; add redacted terminal output or a recording, then update the PR body to trigger a fresh review or ask a maintainer to comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +130, Tests +123. Total +253 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 11 198 68 +130
Tests 5 126 3 +123
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 324 71 +253

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/cli/daemon-cli/lifecycle-core.test.ts src/cli/daemon-cli/lifecycle.test.ts src/cli/daemon-cli/launchd-recovery.test.ts src/daemon/service.test.ts.
  • [P1] node scripts/run-vitest.mjs src/crestodian/assistant.configured.test.ts src/agents/embedded-agent-runner/run.before-agent-reply-cron.test.ts.

What I checked:

  • Recovery precedes inspection: On the PR head, runServiceStart invokes the platform-specific not-loaded recovery and returns when it succeeds, before startGatewayService can inspect the expected configured port. (src/cli/daemon-cli/lifecycle-core.ts:292, 8a37459464f8)
  • Recovery preserves stale definition: The macOS recovery helper re-bootstraps the existing LaunchAgent plist and reports success without inspecting or reinstalling its gateway port. (src/cli/daemon-cli/launchd-recovery.ts:19, 8a37459464f8)
  • Repair collector excludes unloaded services: The PR's service-definition collector returns no repair issues whenever state.loaded is false, even when an installed command contains a stale port. (src/daemon/service.ts:143, 8a37459464f8)
  • Real behavior proof gap: The PR body reports successful exact-head Crestodian CLI and TUI runs, but explicitly states that the managed LaunchAgent restart could not be repeated from a real gui/501 session. (8a37459464f8)
  • Direct Codex contract inspection: Sibling Codex source contains its own session identifiers and telemetry but no OpenClaw trajectory-persistence API; disabling the OpenClaw recorder for this ephemeral planner is an internal OpenClaw ownership decision. (9e552e9d15ba)
  • Gateway feature history: Live path history shows repeated gateway lifecycle ownership by steipete, including stale-service repair, LaunchAgent recovery, lifecycle centralization, and restart-intent work. (src/cli/daemon-cli/lifecycle-core.ts:257, 3b1a020ebaec)

Likely related people:

  • steipete: Prior merged history shows repeated ownership of gateway lifecycle, stale-service repair, LaunchAgent recovery, restart intent, and Crestodian planning—not merely authorship of this PR. (role: feature owner and recent area contributor; confidence: high; commits: 3b1a020ebaec, 6369bf64cd2b, aa497e9c52d7; files: src/cli/daemon-cli/lifecycle-core.ts, src/cli/daemon-cli/launchd-recovery.ts, src/daemon/service.ts)
  • TurboTheTurtle: Recent merged work changed generated-wrapper and service-status diagnostics on the same lifecycle surface, making this a useful adjacent reviewer for service-definition handling. (role: recent gateway lifecycle contributor; confidence: medium; commits: ca2f4c0d6772, 3fea2196923b; files: src/cli/daemon-cli/lifecycle-core.ts, src/daemon/service.ts)
  • fuller-stack-dev: Recent merged work changed headless LaunchAgent state handling in the recovery helper directly involved in the remaining defect. (role: recent LaunchAgent contributor; confidence: medium; commits: 40aad24e8a7b; files: src/cli/daemon-cli/launchd-recovery.ts)
  • jalehman: The recent SQLite session/transcript migration is directly relevant to trajectory foreign-key ownership and durable-session assumptions. (role: session-storage refactor author; confidence: medium; commits: 0a8e3604ba24; files: src/trajectory/runtime.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 948aeb6e9ecfcbbb1996f89956b3ea5807116fe4:

  • Hosted exact-head CI is green, including check-lint, check-test-types, and build-artifacts (run 29186277585).
  • Blacksmith Testbox tbx_01kxapvyk5x70fsxpxj4jh3rnv: 83 focused Crestodian, embedded-agent, daemon-service, and lifecycle tests passed.
  • Same Testbox: pnpm check:test-types, pnpm tsgo:scripts, pnpm tsgo:test:root, pnpm lint --threads=8, pnpm format:check, and pnpm build:ci-artifacts passed.
  • Fresh structured autoreview: clean, correctness 0.98.
  • Golden Gate exact-head package smoke passed install/version, gateway RPC, Control UI, and a real OpenAI agent turn.
  • Crestodian CLI read config, answered a fuzzy config question, applied and restored a gateway-port update, and rejected forbidden writes without loader, trajectory, or internal assertion errors. The TUI independently returned TUI_CONFIG_OK 18789.
  • Repo-native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 105153 passed at the exact PR head.

Known proof gap: the pristine Golden Gate snapshot has no approved console-password locator, so the managed LaunchAgent restart branch could not be repeated inside a live gui/501 console session. Focused lifecycle tests cover that branch; foreground gateway restart/RPC behavior and the packaged CLI/TUI paths are green.

@steipete
steipete merged commit ae14fc1 into main Jul 12, 2026
104 checks passed
@steipete
steipete deleted the codex/crestodian-cli-soak branch July 12, 2026 08:51
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 13, 2026
* fix: harden Crestodian maintenance flows

* fix: skip trajectories for ephemeral Crestodian plans

* test: satisfy Crestodian CI gates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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.

[Bug]: Managed Gateway restart keeps stale installed port

1 participant