Skip to content

fix(daemon): explain unsafe service publication failures - #132279

Merged
steipete merged 2 commits into
mainfrom
steipete/admiring-gates-745021
Aug 29, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/admiring-gates-745021

Conversation

@steipete

@steipete steipete commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #132278 — unsafe service-directory permissions are hidden behind a generic installation error.

Additional instructions

This is a same-repository branch; maintainers can push fixes directly.

What Problem This Solves

Fixes an issue where users installing a managed Gateway would receive only SERVICE_DEFINITION_UNKNOWN when an account-owned service-publication directory or existing ancestor was group/world-writable. The guard correctly refused the operation, but the CLI hid the reason needed to repair the directory. Start/restart repair discarded the same information.

Why This Change Was Made

The publication owner now returns closed reason codes and redacted artifact categories, and the shared assertion renders allowlisted explanations and next actions. This removes free-form detail from the contract and the duplicate CLI detail-replacement paths without forwarding private paths, config/environment contents, or native errors. Existing SERVICE_DEFINITION_SEALED: / SERVICE_DEFINITION_UNKNOWN: prefixes remain unchanged because definition-preserving update recovery recognizes them.

Authority classification, owner checks, mode checks, mount/symlink protection, publication locking, and pre-config/token ordering are unchanged. There is no parser/import change, new option, dependency change, persistence/schema change, timeout increase, or guard bypass.

Production LOC: +82/-52 (net +30). Tests: +184/-76 (net +108). The production growth is the bounded diagnostic vocabulary and shared recovery renderer; the owner and CLI paths otherwise shrink. Documentation: +22/-1.

User Impact

Operators can distinguish unsafe permissions from foreign ownership, a sealed mount, a symlink, unexpected file types, or failed inspection. For unsafe permissions, the message identifies the artifact category, explains how to inspect ownership/mode locally, and permits repair guidance only for an owned, nonshared path. It does not recommend recursive chmod, taking ownership, or bypassing the check with sudo/--force.

The recovery steps are documented in Gateway install identity. This is an AI-assisted, maintainer-requested diagnostics follow-up.

Evidence

Behavior regression and sibling coverage

The new JSON and text regression cases fail on the pre-fix source because the permission reason and next action are absent, then pass with this change. All 269 tests in six files passed, covering failure/recovery, config/token non-mutation, unsafe mode bits, foreign ownership, symlinks, mounts, publication races/rollback, safe directory creation, start/restart repair, and definition-preserving update activation (including the macOS sibling).

node scripts/run-vitest.mjs src/cli/daemon-cli/install.integration.test.ts src/cli/daemon-cli/start-repair.test.ts src/daemon/systemd-definition-mutation.test.ts src/daemon/systemd-definition-mutation.creation.test.ts src/daemon/service.test.ts src/cli/update-cli/update-command-service.integration.test.ts
node scripts/check-changed.mjs
pnpm docs:check-mdx
pnpm docs:check-links

All commands passed; the changed gate included core/test typechecks, scoped lint, dead exports, import cycles, and applicable guards. Docs: 6,975 internal links checked, zero broken links. Fresh Codex autoreview completed at the configured P0 threshold with no accepted/actionable findings.

CI-discovered sibling assertion correction

The initial PR CI run caught five system-scope ownership cases that still expected the retired raw detail field. Those assertions now require the exact typed system-owned / system-ownership-unverified reasons; the secret-canary and no-user-inspection assertions remain intact. This was a test-only correction, not a change to authority behavior.

The expanded local run passed 1,302 tests across 39 files, with 5 platform skips, including the full daemon suite and CLI recovery siblings:

node scripts/run-vitest.mjs src/daemon src/cli/daemon-cli/install.integration.test.ts src/cli/daemon-cli/start-repair.test.ts src/cli/update-cli/update-command-service.integration.test.ts

Targeted lint passed, and fresh Codex autoreview of the complete PR candidate was scoped-clean at the configured P0 threshold. Production inputs are unchanged from the native proof below. Exact-head CI is rerun for the corrected head.

Native Linux before/after proof

Provider: Blacksmith Testbox, lease tbx_01m15hv19h0qzkts4w70y1dqne, run 33226287496. This used the real disposable OS account/home, native systemd user manager, an allowlisted process environment, and a fresh named profile—not service-manager shims.

The initial prerequisite probe lacked the non-login-shell user-bus environment; correcting only that proof setup made the native query work. No manager/service was started to bypass it. The candidate was rebuilt with pnpm build; hashes of 14 scoped owner/dependency inputs matched the local candidate before and after the build. The fingerprint was 16f1947ff2f6f0b298c235d8cac3c53479899994fc6044f64eb94a1fcdc046ec; the Testbox mirror's synthetic Git SHA is not used as candidate identity.

node openclaw.mjs --profile <fresh-proof-profile> gateway install --force --json

Sanitized observed result:

{
  "before": { "typedPermissionReason": false, "safeNextAction": false },
  "afterAt0777": {
    "reason": "unsafe-permissions",
    "artifact": "service-directory",
    "safeNextAction": true,
    "noPrivatePathInDiagnostic": true,
    "blockedBeforeConfigOrServiceWrites": true,
    "cliExitCode": 1
  },
  "sameInvocationAfter0700": {
    "authorityBlockCleared": true,
    "expectedUnresolvedSyntheticSecretRefReached": true,
    "persistedGatewayModeLocal": true,
    "secretRefPreserved": true,
    "noServiceArtifacts": true,
    "cliExitCode": 1
  },
  "proofPassed": true,
  "ownedProfileRemoved": true,
  "originalDirectoryModeRestored": true,
  "testboxStopped": true
}

The recovered CLI still exits 1 intentionally: recovery means reaching the genuine unresolved-SecretRef rejection, not creating a service. Testbox wrapper exit was 0; the linked long-running hydration Actions job is cancelled because the owned lease was explicitly stopped after proof. It is behavior evidence, not the PR's CI gate. Exact-head PR CI is tracked separately.

Replace free-form definition mutation details with typed, redacted reasons
and shared recovery guidance for install and start/restart repair. Keep all
ownership checks and stable update-recovery denial prefixes unchanged.

Cover unsafe directory failure and permission-repair recovery without
config or service publication before denial or SecretRef bypass afterward.

Fixes #132278.
@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: M maintainer Maintainer-authored PR labels Aug 29, 2026
@steipete
steipete marked this pull request as ready for review August 29, 2026 02:10
@steipete steipete self-assigned this Aug 29, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Aug 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 10:30 PM ET / August 29, 2026, 02:30 UTC.

ClawSweeper review

What this changes

The PR replaces generic Linux Gateway service-publication failures with typed, redacted reason tags and safe recovery guidance for install and start/restart repair.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: the PR remains necessary, and no introduced correctness defect was found. It needs normal maintainer handling after exact-head checks complete because it is maintainer-authored and carries the protected maintainer label.

Likely related people: steipete (high, current diagnostic-contract contributor); Vincent Koc (medium, recent owner-boundary contributor).

Priority: P2
Reviewed head: 1b6b70c8bde14961f76bfd8b767b1e5cd66d7d3d
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A well-scoped, source-verified diagnostic fix with strong native behavior evidence and no actionable review findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The changed production owner is the Linux service-definition inspector, reached by Gateway install; supplied native Linux before/after evidence shows the unsafe-permissions denial before writes and the expected post-permission recovery path without secret or private-path disclosure.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The changed production owner is the Linux service-definition inspector, reached by Gateway install; supplied native Linux before/after evidence shows the unsafe-permissions denial before writes and the expected post-permission recovery path without secret or private-path disclosure.
Evidence reviewed 8 items Current main still has the reported diagnostic gap: The fetched main revision retains the { kind, detail } capability contract and generic renderer, while the PR introduces typed reasons and artifact categories; the PR is therefore not implemented or superseded on main.
Owner-boundary repair: The Linux systemd owner classifies unsafe permissions, foreign ownership, invalid artifacts, symlinks, sealed mounts, and failed inspection as closed reason codes before returning to callers.
Redaction and caller preservation: The shared renderer accepts only allowlisted reason and artifact values; install preserves the capability before any config/token work, and start/restart performs the same check before repair planning.
Findings None None.
Security None None.

How this fits together

Gateway install and repair inspect the native service definition before configuration, token, or service-file writes. That inspection determines whether publication may proceed or must return a safe operator-facing diagnostic.

flowchart LR
  A[Gateway install or repair] --> B[Service definition inspection]
  B --> C{Safe to modify?}
  C -->|Yes| D[Config and service publication]
  C -->|No| E[Typed redacted reason]
  E --> F[CLI recovery guidance]
Loading

Decision needed

Question Recommendation
Should this maintainer-authored Gateway diagnostics fix land once its exact-head checks are green? Land after exact-head checks: Accept the centralized typed diagnostic contract once the in-progress checks complete successfully.

Why: The protected maintainer label and member authorship require explicit maintainer handling even though the patch and native proof are otherwise review-clean.

Before merge

  • Resolve merge risk (P1) - Production code grows by 30 net lines for the closed diagnostic vocabulary and renderer; review found this is the centralized way to retain actionable distinctions without forwarding raw inspection details.
Agent review details

Security

None.

PR surface

Source +30, Tests +108, Docs +21. Total +159 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 5 82 52 +30
Tests 6 184 76 +108
Docs 1 22 1 +21
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 288 129 +159

Review metrics

Metric Value Why it matters
Production versus test delta production +82/-52 (net +30); tests +184/-76 (net +108); docs +22/-1 The production growth is concentrated in one bounded reason/artifact vocabulary and its redacted renderer; the remaining changes remove duplicated caller replacement logic.

Stored data model

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

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #132278
Summary: This PR is the candidate fix for the linked Gateway installation diagnostics bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the single typed, allowlisted diagnostic renderer; no net-neutral alternative would preserve the required reason and artifact distinctions while eliminating free-form inspection detail.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the single typed, allowlisted diagnostic renderer; no net-neutral alternative would preserve the required reason and artifact distinctions while eliminating free-form inspection detail.

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

Yes—source-reproducible with high confidence: current main still collapses unsafe mode bits into the generic diagnostic, and the supplied disposable native-Linux scenario exercises that path.

Is this the best way to solve the issue?

Yes: the fix records the safe, closed reason at the systemd publication owner and passes it unchanged to one redacted renderer, rather than restoring unsafe free-form error forwarding in each CLI caller.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0f054bb3df51.

Labels

Label justifications:

  • P2: This fixes a bounded but user-blocking Gateway installation diagnostic rather than a runtime outage or security bypass.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed production owner is the Linux service-definition inspector, reached by Gateway install; supplied native Linux before/after evidence shows the unsafe-permissions denial before writes and the expected post-permission recovery path without secret or private-path disclosure.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the Linux service-definition inspector, reached by Gateway install; supplied native Linux before/after evidence shows the unsafe-permissions denial before writes and the expected post-permission recovery path without secret or private-path disclosure.

Evidence

What I checked:

  • Current main still has the reported diagnostic gap: The fetched main revision retains the { kind, detail } capability contract and generic renderer, while the PR introduces typed reasons and artifact categories; the PR is therefore not implemented or superseded on main. (src/daemon/service-types.ts:96, 0f054bb3df51)
  • Owner-boundary repair: The Linux systemd owner classifies unsafe permissions, foreign ownership, invalid artifacts, symlinks, sealed mounts, and failed inspection as closed reason codes before returning to callers. (src/daemon/systemd-definition-mutation.ts:95, 1b6b70c8bde1)
  • Redaction and caller preservation: The shared renderer accepts only allowlisted reason and artifact values; install preserves the capability before any config/token work, and start/restart performs the same check before repair planning. (src/daemon/service-types.ts:132, 1b6b70c8bde1)
  • Update-recovery sibling remains compatible: Update activation continues to recognize the unchanged SERVICE_DEFINITION_SEALED and SERVICE_DEFINITION_UNKNOWN prefixes rather than relying on the replaced free-form detail. (src/cli/update-cli/update-command-service.ts:84, 1b6b70c8bde1)
  • Regression coverage: Focused tests cover unsafe mode bits, symlinks, failed inspection, no publication, secret-canary redaction, and pre-config/token denial across install and start/restart. (src/daemon/systemd-definition-mutation.test.ts:744, 1b6b70c8bde1)
  • Follow-up review continuity: The only change since the prior reviewed commit is the system-ownership test assertion updated from retired raw detail to typed reasons; there were no prior findings to re-raise. (src/daemon/systemd-system.test.ts:130, 1b6b70c8bde1)

Likely related people:

  • steipete: Authored both PR commits and the typed diagnostic/redaction contract introduced at the current owner boundary. (role: current diagnostic-contract contributor; confidence: high; commits: 0ed777c69833, 1b6b70c8bde1; files: src/daemon/service-types.ts, src/daemon/systemd-definition-mutation.ts, src/cli/daemon-cli/install.ts)
  • Vincent Koc: Blame identifies the shallow-boundary commit as owning the underlying systemd inspection loop that this PR extends. (role: recent owner-boundary contributor; confidence: medium; commits: fae557490851; files: src/daemon/systemd-definition-mutation.ts, src/daemon/service-types.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 (1 earlier review cycle)
  • reviewed 2026-08-29T02:18:52.354Z sha 0ed777c :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Pre-merge verification for head 1b6b70c8bde14961f76bfd8b767b1e5cd66d7d3d.

Maintainer decision: land this diagnostics-only repair. Exact-head CI run 33228776765 passed, including the required openclaw/ci-gate. The live head matches, the PR is mergeable/clean, and no failing check or changes-requested review remains.

The initial compact-shard failure was five systemd-system.test.ts assertions still expecting the retired raw detail property. The corrected head changes only that assertion to the exact typed system-ownership reasons; strict equality, secret-canary protection, and no-user-inspection checks are retained. The expanded local run passed 1,302 tests across 39 files, with 5 platform skips:

node scripts/run-vitest.mjs src/daemon src/cli/daemon-cli/install.integration.test.ts src/cli/daemon-cli/start-repair.test.ts src/cli/update-cli/update-command-service.integration.test.ts

The original candidate also passed node scripts/check-changed.mjs (core/test types, lint, dead exports, import cycles and guards), pnpm docs:check-mdx, and pnpm docs:check-links. The assertion-only correction passed targeted core lint and git diff --check. Fresh Codex autoreview of the complete corrected candidate is scoped-clean at the configured P0 threshold.

Native behavior proof remains valid because production inputs are unchanged: Blacksmith Testbox run 33226287496, lease tbx_01m15hv19h0qzkts4w70y1dqne, successful pnpm build, 14 matching scoped owner/dependency hashes before and after build. On the real disposable account with a native systemd user manager, mode 0777 rejects with safe actionable diagnostics before writes; changing only that directory to 0700 reaches the intentional unresolved-SecretRef rejection, preserves the reference, persists gateway.mode=local, and creates no service. Profile cleanup, original mode restoration, and Testbox shutdown were verified. The cancelled hydration job is cleanup; the proof wrapper exited 0, and it is not substituted for PR CI.

Disposition of the latest ClawSweeper review:

  • Accept the bounded +30 production LOC tradeoff: the shared closed diagnostic vocabulary supplies actionable distinctions without forwarding unsafe free-form data; the native owner and CLI consumers otherwise shrink. Tests are +108 net. No further code growth or guard relaxation is needed.
  • The prior review's CI rank-up move is complete: the stale system-scope assertions are corrected and all required exact-head checks are green. The current-head review has no code/security finding; this explicit maintainer handling resolves its maintainer-authored decision gate.
  • The stored-data-model flag does not identify a store change: this patch changes an in-memory daemon capability and error rendering only. There are no SQLite/schema, persisted config/data, migration, or upgrade-shape changes. Existing external error prefixes remain intact and their update-preservation consumers are covered.

No accepted actionable review finding remains. No native macOS/Windows installation behavior changes; shared adapter and macOS definition-preserving activation regressions passed. The separate parser-import repair is untouched. The related Doctor preflight-ordering question remains a separately recorded investigation, not scope added to this PR.

@steipete
steipete merged commit 5d8ef65 into main Aug 29, 2026
238 checks passed
@steipete
steipete deleted the steipete/admiring-gates-745021 branch August 29, 2026 02:48
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 29, 2026
…2279)

* fix(daemon): explain service publication authority failures

Replace free-form definition mutation details with typed, redacted reasons
and shared recovery guidance for install and start/restart repair. Keep all
ownership checks and stable update-recovery denial prefixes unchanged.

Cover unsafe directory failure and permission-repair recovery without
config or service publication before denial or SecretRef bypass afterward.

Fixes openclaw#132278.

* test(daemon): assert typed system ownership diagnostics
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 gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

[Bug]: gateway install hides unsafe service directory permissions

1 participant