Repository navigation
feat(config): journal every config change with source labels and manual-edit detection - #111147
Conversation
…al-edit detection
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4247cd3cdc
ℹ️ 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".
| const observedRawHash = snapshot.hash ?? null; | ||
| const previousObservedRawHash = lastObservedRawHash; | ||
| const newObservedRawHash = observedRawHash !== previousObservedRawHash; | ||
| lastObservedRawHash = observedRawHash; |
There was a problem hiding this comment.
Journal live config deletion before returning
When the watched config is deleted while the gateway is running, handleMissingSnapshot(snapshot) at src/gateway/config-reload.ts:881 returns before this newly added observation logic executes. Even after the missing-file retry budget is exhausted it still returns, so lastObservedRawHash is never advanced to null and no config.external deletion record is written; deletion is only discovered if the gateway later restarts.
Useful? React with 👍 / 👎.
| initialSnapshotRawHash: startupLastGoodSnapshot.exists | ||
| ? (startupLastGoodSnapshot.hash ?? null) | ||
| : null, | ||
| initialAuthoredConfig: startupLastGoodSnapshot.parsed, | ||
| initialSnapshotValid: startupLastGoodSnapshot.valid, | ||
| initialSnapshotIssues: startupLastGoodSnapshot.issues, |
There was a problem hiding this comment.
Journal invalid config before startup validation aborts
These startup reconciliation fields cannot represent an existing invalid file in the real gateway flow: loadGatewayStartupConfigSnapshot() calls assertValidGatewayStartupConfigSnapshot() at src/gateway/server-startup-config-helpers.ts:101-103, which throws before startManagedGatewayConfigReloader() is reached. Consequently, an invalid manual edit made while the gateway is stopped causes startup to fail without producing the promised config.external record; the direct reloader test bypasses this production ordering.
Useful? React with 👍 / 👎.
| export type ConfigWriteOptions = { | ||
| /** Semantic writer label recorded in the config audit journal. */ | ||
| auditOrigin?: ConfigWriteAuditOrigin; |
There was a problem hiding this comment.
Require an origin for every internal config write
Keeping auditOrigin optional leaves many production writes without the source label this change promises. For example, openclaw pairing approve forwards the unlabeled snapshot options at src/cli/pairing-cli.ts:70-84, while openclaw agents set-identity calls replaceConfigFile() without write options at src/commands/agents.commands.identity.ts:195-198; both produce config.write records with no origin. Attribution needs a mandatory/default origin at the writer boundary or complete propagation through all callers.
Useful? React with 👍 / 👎.
| await appendConfigAuditRecord({ | ||
| env: deps.env, | ||
| homedir: deps.homedir, | ||
| record: { | ||
| ts: new Date().toISOString(), | ||
| source: "config-io", | ||
| event: "config.external", |
There was a problem hiding this comment.
Record the offline edit before the replacing write
When an offline manual edit is reconciled by a later internal write, the successful config.write record is appended first at src/config/io.write.ts:420-424, and this prior config.external record is appended afterward with a later timestamp and sequence. Thus the journal deterministically reports the replacement before the edit it replaced, breaking chronological diagnostics even without the acknowledged cross-process race; append the external observation before the successful write record.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 53fdac4260
ℹ️ 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".
| // Install work may outlive its config read. Keep only mutation-start ownership | ||
| // and conflict facts; plugin metadata must come from the commit-time read. | ||
| return { | ||
| auditOrigin: "plugin-install", |
There was a problem hiding this comment.
Journal writes to top-level include files
When plugins or hooks uses the supported single-top-level $include path, this origin is passed into tryWriteSingleTopLevelIncludeMutation, but that path writes the included file directly (src/config/mutate.ts:589-615) without calling writeConfigFileFromContext or appendConfigAuditRecord; the gateway also watches only the root watchPath (src/gateway/config-reload.ts:1127). Consequently, plugin install/uninstall and other include-owned mutations produce neither a config.write nor a config.external record, so the new journal omits an entire supported config-write surface.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d2af8c8d34
ℹ️ 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".
| nextConfig: params.nextConfig, | ||
| writeOptions: { | ||
| ...params.writeOptions, | ||
| auditOrigin: "config-rpc", |
There was a problem hiding this comment.
Propagate the audit origin into the low-level write
When a normal Gateway config RPC follows this default replaceConfigFile() path, the origin is lost before journaling: the public writeConfigFile() reconstructs the options passed to io.writeConfigFile() at src/config/io.runtime.ts:280-302 but omits auditOrigin, so writeConfigFileFromContext() receives undefined. Fresh evidence beyond the earlier optional-origin concern is that even newly labeled Gateway, CLI, doctor, plugin-install, and system-agent calls using the default mutation path cannot produce the intended source label; the direct createConfigIO() audit test bypasses this production route.
Useful? React with 👍 / 👎.
|
Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 11:56 PM ET / July 19, 2026, 03:56 UTC. Summary PR surface: Source +619, Tests +1100. Total +1719 across 31 files. Reproducibility: yes. from source inspection: follow a normal Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Copy recommended automerge instructionNext step before merge
Maintainer decision needed
Security Review findings
Review detailsBest possible solution: Preserve one canonical journal chokepoint that receives origin metadata on every config-writing route, explicitly journal supported include-owned mutations, and record invalid offline observations before startup validation aborts. Do we have a high-confidence way to reproduce the issue? Yes from source inspection: follow a normal Is this the best way to solve the issue? No: a low-level optional label plus selected caller propagation is not the best durable solution while ordinary runtime writes and include-owned mutations can bypass it. The better design centralizes attribution and journaling at the canonical persisted-write boundary. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 63f8b8454b75. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +619, Tests +1100. Total +1719 across 31 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
|
|
Merged via squash.
|
…al-edit detection (openclaw#111147) * feat(config): journal every config change with source labels and manual-edit detection * fix(config): narrow journal exports and align plugin-write test expectations * refactor(config): split journal snapshot store out of io.audit * chore(config): keep journal snapshot context helpers module-local
…al-edit detection (openclaw#111147) * feat(config): journal every config change with source labels and manual-edit detection * fix(config): narrow journal exports and align plugin-write test expectations * refactor(config): split journal snapshot store out of io.audit * chore(config): keep journal snapshot context helpers module-local
Related: #110896
What Problem This Solves
Operators cannot answer "what changed in my config, when, by whom." The write path already kept a forensic
config-audittrail (hashes, redacted argv), but it recorded only a changed-path count, had no semantic writer attribution, and manual edits toopenclaw.json— including edits made while the gateway was stopped — left no trace at all. "Who broke the config" is the single most common ops mystery.Why This Change Was Made
Phase 2 of #110896. Extends the existing
config-auditSQLite scope (no schema change, scope reuse):changedPathslist (paths only, never values;explicitSetPaths/unsetPathsare unioned in so writes that equal runtime defaults still attribute) and a semanticoriginfrom a closed union —doctor,system-agent,config-rpc,plugin-install,cli— threaded through the write-options chokepoint.config.externalrecords): the gateway watcher classifies filesystem changes with no matching internal-write hash as external edits, with key-path diffs, invalid-edit records ("who broke it": capped validation issues), and mtime-touch dedupe."1"→1) fingerprint distinctly.User Impact
The journal now captures every config mutation — system-agent operations, doctor migrations, Settings-UI writes, CLI edits, plugin installs, and hand edits (live or offline) — as structured, redacted records in the state DB, bounded at 50k rows. The follow-up reader RPC + "Recent changes" UI (#110896 phase 3) surfaces them in Ask OpenClaw.
Known limits, deliberately deferred to the successor PR (atomic journal primitive + include-closure identity, #110896 phase 2b):
$includefiles are invisible to both hot-reload and the journal today (the watcher only watches the root file); the successor extends identity to the include closure.Evidence
node scripts/run-vitest.mjs src/config/io.write-config.test.ts— 117 tests pass (includes real-store cross-producer hash identity, offline-edit reconcile at write time, capped paths + origin, blanket fingerprints, post-commit rollback slot restore).node scripts/run-vitest.mjs src/gateway/config-reload.test.ts— 159 tests pass (watch/startup/invalid external records, internal-write exclusion, cross-process suppression, invalid-observation dedupe, cross-path slot handover).node scripts/run-vitest.mjs src/config/io.audit.test.ts— 33 tests pass (HMAC fingerprints + 0600 key, type-distinct fingerprints, unfiltered CAS token path transfer, sanitizer for external records).