Skip to content

fix(config): refresh runtime snapshot from disk after write. Fixes #37175#37313

Merged
gumadeiras merged 7 commits intoopenclaw:mainfrom
bbblending:fix/37175-runtime-config-snapshot
Mar 8, 2026
Merged

fix(config): refresh runtime snapshot from disk after write. Fixes #37175#37313
gumadeiras merged 7 commits intoopenclaw:mainfrom
bbblending:fix/37175-runtime-config-snapshot

Conversation

@bbblending
Copy link
Contributor

@bbblending bbblending commented Mar 6, 2026

Summary

  • Problem: After agents.create on one WebSocket connection, agents.update on another fails with "agent not found" because the second connection's loadConfig() returns a stale in-memory snapshot.
  • Fix: After writeConfigFile, always clear the runtime snapshot. When the process had both snapshots before the write, refresh both from disk (loadConfig() + nextCfg) so follow-up reads get normalized config and subsequent writes keep secret-preservation. When it had no snapshot, do not set a new one so callers keep reading from disk/cache and external edits to openclaw.json remain visible.
  • Scope: src/config/io.ts and src/config/io.runtime-snapshot-write.test.ts; no API or config schema changes.

Change Type

  • Bug fix

Scope

  • Memory / storage

Linked Issue/PR

User-visible / Behavior Changes

Second connection's agents.update now sees the newly created agent without reload/restart.

Security Impact

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

None.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 6, 2026

Greptile Summary

This PR fixes a stale-snapshot race condition where a second WebSocket connection's agents.update would fail with "agent not found" because loadConfig() returned a cached in-memory snapshot that pre-dated a agents.create from another connection. The fix clears and refreshes the runtime snapshot from disk after each writeConfigFile, so any subsequent loadConfig() call (on the same process) sees the newly persisted state.

The approach taken — setRuntimeConfigSnapshot(fresh, nextCfg) — also resolves the previously flagged regression where runtimeConfigSourceSnapshot was left as null after a write, which would have caused subsequent writes to skip secret-preservation merge-patch and write plaintext secrets to disk.

Key changes:

  • writeConfigFile now unconditionally calls clearRuntimeConfigSnapshot() after a successful write, invalidating the stale in-memory cache.
  • When both snapshots previously existed (hadBothSnapshots), they are re-populated: fresh = loadConfig() (env-resolved config re-read from disk) becomes the new runtimeConfigSnapshot, and nextCfg (the source config written to disk, with secret refs intact) becomes the new runtimeConfigSourceSnapshot.
  • The new test covers both the initial write and a follow-up write, asserting that apiKey remains a source ref on disk across both writes — directly addressing the test gap called out in the prior review.

Confidence Score: 4/5

  • Safe to merge; the fix is logically sound and directly addresses both the stale-snapshot bug and the previously flagged secret-ref regression.
  • The core logic is correct: fresh = loadConfig() obtains the env-resolved config from disk (confirmed by resolveConfigForRead in the ConfigIO.loadConfig implementation), and nextCfg correctly carries the source refs written to disk. The new test validates secret-ref preservation through two consecutive writes. One residual edge case: if loadConfig() throws after a successful write (e.g., corrupted JSON on the re-read), the caller receives an exception even though the write itself succeeded — but this is pre-existing risk in any read-after-write pattern and is not introduced by this PR.
  • No files require special attention.

Last reviewed commit: 3df4457

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 166b536bd5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@bbblending bbblending force-pushed the fix/37175-runtime-config-snapshot branch from 166b536 to f43c88e Compare March 6, 2026 06:57
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: f43c88e9a3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@bbblending bbblending force-pushed the fix/37175-runtime-config-snapshot branch 2 times, most recently from 676a026 to 3df4457 Compare March 6, 2026 07:09
@bbblending
Copy link
Contributor Author

@greptile-apps review it

@bbblending
Copy link
Contributor Author

hi @gumadeiras , would you mind taking a look at this PR? Your feedback would be appreciated.

@gumadeiras gumadeiras self-assigned this Mar 8, 2026
@gumadeiras gumadeiras force-pushed the fix/37175-runtime-config-snapshot branch from 3df4457 to 4b59d66 Compare March 8, 2026 22:24
@openclaw-barnacle openclaw-barnacle bot added cli CLI command changes size: M and removed size: S labels Mar 8, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 4b59d66dad

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

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: fbbe40af2b

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

@gumadeiras gumadeiras force-pushed the fix/37175-runtime-config-snapshot branch from 27594ac to 69e1861 Compare March 8, 2026 23:48
@gumadeiras gumadeiras merged commit 4ff4ed7 into openclaw:main Mar 8, 2026
11 of 12 checks passed
@gumadeiras
Copy link
Member

Merged via squash.

Thanks @bbblending!

@bbblending
Copy link
Contributor Author

Thanks @gumadeiras for building on this and hardening the fix — really appreciate it.

GordonSH-oss pushed a commit to GordonSH-oss/openclaw that referenced this pull request Mar 9, 2026
…enclaw#37175 (openclaw#37313)

Merged via squash.

Prepared head SHA: 69e1861
Co-authored-by: bbblending <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
vincentkoc pushed a commit that referenced this pull request Mar 9, 2026
…7175 (#37313)

Merged via squash.

Prepared head SHA: 69e1861
Co-authored-by: bbblending <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
…enclaw#37175 (openclaw#37313)

Merged via squash.

Prepared head SHA: 69e1861
Co-authored-by: bbblending <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
Get-windy pushed a commit to Get-windy/JieZi-ai-PS that referenced this pull request Mar 10, 2026
上游更新摘要(abb8f6310 → bda63c3,164 commits):

### 新功能
- ACP: 新增 resumeSessionId 支持 ACP session 恢复(openclaw#41847)
- CLI: 新增 openclaw backup create/verify 本地状态归档命令(openclaw#40163)
- Talk: 新增 talk.silenceTimeoutMs 配置项,可自定义静默超时(openclaw#39607)
- ACP Provenance: 新增 ACP 入站溯源元数据和回执注入(openclaw#40473)
- Brave 搜索: 新增 llm-context 模式,返回 AI 精炼摘要(openclaw#33383)
- browser.relayBindHost: Chrome relay 可绑定非 loopback 地址(WSL2 支持)(openclaw#39364)
- node-pending-work: 新增 node.pending.pull/ack RPC 接口
- Telegram: 新增 exec-approvals 处理器,支持 Telegram 内命令执行审批
- Mattermost: 新增 target-resolution,修复 markdown 保留和 DM media 上传
- MS Teams: 修复 Bot Framework General channel 对话 ID 兼容性(openclaw#41838)
- secrets/runtime-web-tools: 全新 web runtime secrets 工具模块
- cron: 新增 store-migration,isolated-agent 直送核心通道,delivery failure notify
- TUI: 自动检测浅色终端主题(COLORFGBG),支持 OPENCLAW_THEME 覆盖(openclaw#38636)

### 修复
- macOS: launchd 重启前重启已禁用服务,修复 openclaw update 卡死问题
- Telegram DM: 按 agent 去重入站 DM,防止同一条消息触发重复回复(openclaw#40519)
- Matrix DM: 修复 m.direct homeserver 检测,保留房间绑定优先级(openclaw#19736)
- 飞书: 清理插件发现缓存,修复 onboarding 安装后重复弹窗(openclaw#39642)
- config/runtime snapshots: 修复 config 写入后 secret 快照丢失问题(openclaw#37313)
- browser/CDP: 修复 ws:// CDP URL 反向代理和 wildcard 地址重写
- agents/failover: 识别 Bedrock tokens per day 限额为 rate limit

### 版本
- ACPX 0.1.16
- iOS/macOS 版本号更新
- Android: 精简后台权限

构建验证:待执行
sauerdaniel pushed a commit to sauerdaniel/openclaw that referenced this pull request Mar 11, 2026
…enclaw#37175 (openclaw#37313)

Merged via squash.

Prepared head SHA: 69e1861
Co-authored-by: bbblending <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
Moshiii pushed a commit to Moshiii/openclaw that referenced this pull request Mar 11, 2026
…enclaw#37175 (openclaw#37313)

Merged via squash.

Prepared head SHA: 69e1861
Co-authored-by: bbblending <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
Moshiii pushed a commit to Moshiii/openclaw that referenced this pull request Mar 11, 2026
…enclaw#37175 (openclaw#37313)

Merged via squash.

Prepared head SHA: 69e1861
Co-authored-by: bbblending <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
…enclaw#37175 (openclaw#37313)

Merged via squash.

Prepared head SHA: 69e1861
Co-authored-by: bbblending <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
Taskle pushed a commit to Taskle/openclaw that referenced this pull request Mar 14, 2026
…enclaw#37175 (openclaw#37313)

Merged via squash.

Prepared head SHA: 69e1861
Co-authored-by: bbblending <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race condition in agents.create: runtimeConfigSnapshot not invalidated, causing agents.update to fail on second WebSocket connection

2 participants