Skip to content

fix(update): stop the managed systemd Gateway with the same bounded sequence as gateway stop - #167040

Merged
steipete merged 1 commit into
mainfrom
upd/upd-systemd-stop-same-sequence
Oct 8, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/upd-systemd-stop-same-sequence

Conversation

@steipete

@steipete steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes native Linux package updates that fail with managed-service-stop-failed when systemd routing inspection spends its five-second deadline on update custody checks, even though a later standalone Gateway stop succeeds.

Closes #166663. Thanks @jlapenna for the detailed failure and recovery report.

User Impact

Managed updates and standalone openclaw gateway stop use the same stop sequence. Slow manager inspection has a separate 60-second allowance and one timeout-only retry, with the warning retained in update history. A repeated inspection timeout names the stalled check and leaves the original Gateway running. Ownership refusals still prevent the stop.

This repair belongs to the installed updater: a candidate cannot change the stop logic of an older updater already running. No new configuration, environment variables, CLI options, dependencies, or database schema changes are introduced.

Why This Change Was Made

Both callers already reach the systemd lifecycle owner. The updater additionally supplies a custody guard whose lease/database checks were repeated inside transport discovery, including cached-route reads. One database busy wait can itself consume the entire ordinary five-second inspection budget.

The shared stop path now resolves the manager route with its own budget, then checks the supplied custody guard immediately before dispatch. It drops the redundant status preflight. Inherited native admission/completion guards remain intact, as do the existing start/restart fences. Only inspection is retried; the stop command and its graceful drainage are never replayed. Discovery starts after its deadline timer is armed, and ownership refusals or unresolved native cleanup retain priority over deadline expiry and later custody loss. Timeout diagnostics distinguish the manager route/check from custody or native-command admission.

Evidence

  • The initial six-case regression fails 5 cases on the original production code. Four additional refusal/cleanup cases fail before the error-priority fix; all 10 cases pass on the final patch. It exercises standalone and update contexts, slow manager/custody work, a cached route, transient timeout recovery, bounded repeated failure without a stop, and custody refusal.
  • Touched regression/owner suites passed three times. The final correction run also passed the existing native-start revocation test, after preserving its original post-reset-failed guard.
  • Selected 96 importer test files using the production basenames and their immediate barrels. The final full run covered every selected file: 2,335 passing test executions, 27 existing skips, 9 passing Vitest shards, exit 0, 1,926.26 s wall. The initial importer run exposed the start-guard omission; the original guard was restored before the final run. No skips or test-framework retries were added.
  • Local Linux-systemd boundary proof uses isolated state directories, real lifecycle/routing code, and a fake native manager with a controlled clock. This is not a live Linux host claim.
  • node scripts/check-changed.mjs passed on the final source (exit 0). The first run passed typechecks and other completed guards, then caught a fixture parameter reassignment; the fixture now uses a local counter.
  • Targeted docs MDX validation and git diff --check passed. The retired transport-deadline singleton has no remaining references.
  • Automated P1 review was attempted twice, but the reviewer returned HTTP 401 Unauthorized and produced no verdict. Maintainer review remains necessary; a separate source review found no P1 issue in the final production diff.

Single-worker cost (pnpm test <file> --maxWorkers=1):

Changed test file Wall time Reported test time
src/daemon/systemd-stop.test.ts 4.10 s under 0.2 s
src/daemon/systemd.test.ts 79.55 s about 4.8 s
src/daemon/service-stop-fence.test.ts 27.60 s about 0.33 s

Most wall time in the existing daemon suites was transform/compiler preparation. Existing importer process fixtures were slower: the final Docker helper suite took 201.17 s and the update/rollback process group took 821.91 s wall (1,192.72 s in the earlier run); individual Windows/Doctor recovery cases reached 43.10 s and 45.86 s in earlier runs. These timings are recorded without increasing timeouts or weakening assertions. CI timings are pending at author handoff.

Production: +107 / -30 LOC. Tests: +189 / -13 LOC. Documentation: +8 / -0 LOC.

Keep update and standalone stops at the shared lifecycle owner, with a
separate manager-inspection budget and one timeout-only retry. Check the
supplied custody guard after routing and preserve inherited native guards,
start/restart fences, and graceful stop behavior. Record retry warnings and
name the stalled inspection without stopping the original Gateway.

The installed updater owns this behavior; an older running updater cannot
obtain the repair from its candidate.

Closes #166663. Reported by @jlapenna.
@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: M labels Oct 8, 2026
@steipete
steipete marked this pull request as ready for review October 8, 2026 07:47
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 8, 2026, 3:53 AM ET / 07:53 UTC.

ClawSweeper review

What this changes

This PR gives managed Linux Gateway stops a separate 60-second routing-inspection budget, one timeout-only retry, and retained warning diagnostics.

Example: An update encounters a six-second manager probe

  • Before: The five-second inspection deadline can fail the update with managed-service-stop-failed.
  • After: Inspection can complete within the separate allowance, and current custody is checked before stopping the Gateway.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, useful repair with no concrete defect found, supported by controlled regressions but lacking required native upgrade evidence.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: The verified repository administrator is outside the ordinary external-contributor proof gate. Supplied after-fix evidence exercises the production lifecycle and routing code with a mocked native manager; it does not satisfy the separate repository-required native upgrade check. No stored-data format changes occur.
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 managed Linux package update fails while the original Gateway remains healthy, requiring a separate stop command.
Reason: The change repairs an established update contract through the existing service owner. Prior merged area work establishes owner direction without introducing configuration or storage surface.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this is a useful owner-backed repair absent from current main, with no concrete introduced defect found. Required upgrade validation remains incomplete.

Priority: P2
Reviewed head: f7d324998992b246735123345647732246dc2a00

Before merge

  • Resolve merge risk (P1) - The repository-required published-driver × candidate upgrade check is absent; the supplied mock-manager evidence does not verify real Linux stop/restart behavior or the first update from an older installed driver.
  • Complete next step (P2) - Supply the repository-required published-driver × candidate upgrade evidence and real Linux systemd after-fix stop result.

Findings

None.

Tests

  • Missing end-to-end proof: No real systemd after-fix stop or required published-driver × candidate upgrade result is supplied; reported base-fail/head-pass regressions use mocked native execution and were not rerun during this read-only review.
Agent review details

How this fits together

The updater asks the native service owner to stop the managed Gateway before replacing its package. On Linux, that owner selects a systemd user-manager route and dispatches the stop while preserving live update custody.

flowchart TD
  A[Package update or Gateway stop] --> B[Shared Linux service owner]
  B --> C[Inspect systemd manager route]
  C --> D{Inspection timed out?}
  D -->|Once| C
  D -->|Repeated timeout| E[Report diagnostic and keep Gateway running]
  D -->|Route selected| F[Check current custody]
  F --> G[Dispatch native stop]
Loading

Technical review

Best possible solution:

Keep the shared service owner and final custody fences, and establish native upgrade compatibility while documenting that older installed updaters retain their own stop logic.

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

Yes for the deadline mechanism: source shows custody checks can consume the five-second routing allowance, and the PR reports failing controlled regressions. The exact reported native incident has not been reproduced on current main.

Is this the best way to solve the issue?

Yes: repairing the shared stop owner avoids a competing updater path and preserves final custody checks; real upgrade validation is still needed.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Establish native upgrade compatibility (recommended)
    Supply the required published-driver × candidate result and after-fix real systemd stop evidence before merging.

Provenance checked

Testing

Proof path: unit tests only. Added test files: 3.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ccd3fbb adds src/daemon/systemd-exec.ts:193 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ccd3fbb9181e; files: src/daemon/systemd-exec.ts)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

PR surface

Source +77, Tests +176, Docs +8. Total +261 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 107 30 +77
Tests 3 189 13 +176
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 304 43 +261

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #166663
Summary: This PR is the candidate repair for the linked native-update stop failure.

Members:

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

Labels

Label changes:

  • add P2: A concrete Linux package-update failure has limited demonstrated blast radius, and the original Gateway remains healthy.
  • add merge-risk: 🚨 compatibility: The stop-routing change affects existing managed installations, while real native upgrade compatibility remains unverified.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A concrete Linux package-update failure has limited demonstrated blast radius, and the original Gateway remains healthy.
  • merge-risk: 🚨 compatibility: The stop-routing change affects existing managed installations, while real native upgrade compatibility remains unverified.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Add a redacted published-driver × candidate compatibility result and real systemd after-fix stop evidence.

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.

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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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]: Native package update fails owned systemd stop on inspection deadline; standalone CLI stop succeeds

1 participant