Repository navigation
fix(systemd): apply dotenv changes on gateway restart - #119441
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 7, 2026, 9:48 AM ET / 13:48 UTC. ClawSweeper reviewWhat this changesThis PR stops systemd service staging from snapshotting state-directory dotenv values so managed credential edits take effect on gateway restart while operator-owned service values remain preserved. Merge readinessNo blocking patch finding: current main still snapshots state dotenv values into systemd environment files, while this PR removes that stale owner boundary and scopes refresh to recorded systemd-managed keys. The protected maintainer label and intentional credential-precedence change require maintainer approval before merge. Priority: P1 Review scores
Verification
How this fits togetherSystemd starts the gateway with an inherited service environment, then gateway bootstrap loads the state-directory dotenv and configuration secrets. The change moves state-dotenv ownership out of generated systemd environment files and applies a narrow startup override for recorded managed keys. flowchart LR
A[State directory dotenv] --> B[Systemd service staging]
B --> C[Gateway process environment]
A --> D[Gateway bootstrap]
C --> D
D --> E[Managed key decision]
E --> F[Gateway runtime]
Decision needed
Why: This is a deliberate upgrade-visible credential-precedence contract, not a mechanical correctness question, and the PR carries the protected maintainer label. Before merge
Agent review detailsSecurityNone. PR surfaceSource +106, Tests +192, Docs 0. Total +298 across 12 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Approve the documented systemd-only, marker-scoped dotenv refresh contract, then rebase or refresh the exact merge result and retain the focused ownership regressions. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main serializes state dotenv values into systemd service environment files and gateway startup then retains those inherited values instead of later dotenv edits. Is this the best way to solve the issue? Yes, conditionally: removing the stale snapshot at service staging and allowing override only for recorded systemd-managed keys is cleaner than restaging on every restart, subject to maintainer acceptance of the precedence contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 01cc71060d6c. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (12 earlier review cycles; latest 8 shown)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
5149a74 to
a6f6c98
Compare
b8b10e8 to
940bbba
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
940bbba to
5aed188
Compare
Signed-off-by: sallyom <[email protected]>
Signed-off-by: sallyom <[email protected]>
Signed-off-by: sallyom <[email protected]>
Signed-off-by: sallyom <[email protected]>
Signed-off-by: sallyom <[email protected]>
5aed188 to
9808269
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Merged via squash.
|
* fix(systemd): load state dotenv at gateway startup Signed-off-by: sallyom <[email protected]> * fix(systemd): refresh managed dotenv values on restart Signed-off-by: sallyom <[email protected]> * fix(gateway): clear removed managed dotenv values Signed-off-by: sallyom <[email protected]> * fix(dotenv): canonicalize managed override keys Signed-off-by: sallyom <[email protected]> * fix(secrets): preserve providerless env refs Signed-off-by: sallyom <[email protected]> --------- Signed-off-by: sallyom <[email protected]>
Closes #118503
What Problem This Solves
Fixes an issue where operators editing a managed value in the state-directory
.envwould continue to get the old value after restarting a systemd-managed gateway. The generated systemd environment file captured a snapshot during installation, so later.envchanges could not take effect without reinstalling or restaging the service.Why This Change Was Made
The gateway already loads the state-directory
.envwhen it starts. This change keeps those values owned by that startup path instead of copying them into the generated systemd environment file, while preserving operator-owned environment-file values and shell-backed secret references.For services installed before this fix, gateway bootstrap now lets the state
.envreplace only inherited keys explicitly recorded inOPENCLAW_SERVICE_MANAGED_ENV_KEYS. Restaging also carries forward the prior ownership record, so deleting a managed dotenv key cannot reclassify its stale generated-file value as operator-owned.User Impact
Edits to managed values in
~/.openclaw/.env, including rotated credentials, take effect on the next gateway restart without requiring the service to be reinstalled. A later install/restage removes deleted legacy managed values while preserving operator-owned environment-file entries.Evidence
node scripts/run-vitest.mjs src/infra/dotenv.test.ts— 30 passednode scripts/run-vitest.mjs src/daemon/systemd.test.ts— 142 passednode scripts/run-vitest.mjs src/cli/gateway-cli/run.option-collisions.test.ts— 71 passednode scripts/run-vitest.mjs src/config/types.secrets.test.ts— 7 passedgit diff --check— cleanpnpm tsgo:core— passednode scripts/run-oxlint.mjsacross all 9 changed files — passedautoreview --mode branch --base origin/main --engine codex— clean; patch correct (0.98 confidence)Exact-head Linux/systemd behavior proof: Crabbox run
run_d80913a0dff8, provideraws, clean exact head980826939c206cc14a2a9bd7a2b6ed02ab767d9f. The run used genuine PID 1 and user systemd, with manager-generated invocation IDs. Each scenario ran in a separate transient unit and fresh Node process through the exact builtselectGatewayRunEnvironmentowner path.Proof limitation: the live systemd scenarios used
--setenv, not a literalEnvironmentFile; focused tests cover systemd staging and restaging. A providerless raw{source,id}SecretRef has no schema-valid runtime location, so that case is covered by the focused collector regression rather than live runtime proof. This is focused owner-path behavior proof, not a literal installed-service end-to-end test.Current-main merge-result proof
01cc71060d6c57eff142cfc210685c651ccb6397980826939c206cc14a2a9bd7a2b6ed02ab767d9f4ee78a08c104fb695b6c63674a1bacba8d388d71(parents exactly the base and source above); merge completed without conflicts and was never pushed.node scripts/run-vitest.mjs src/infra/supervisor-markers.test.ts src/daemon/systemd.test.ts src/daemon/launchd.test.ts src/daemon/schtasks.install.test.ts src/cli/gateway-cli/run.option-collisions.test.ts src/infra/dotenv.test.ts src/config/types.secrets.test.ts— 7 files, 417 tests passed across 5 shards in 40.31s.autoreview --mode branch --base origin/main --engine codex --model gpt-5.6-sol --thinking high— clean; no accepted/actionable findings, patch correct (0.98 confidence).Maintainer decision: accept the documented systemd-only restart-time dotenv precedence and compatibility contract, including managed credential values. This does not change public API, config, or protocol contracts; launchd and Scheduled Tasks retain their documented reinstall behavior.