#13412: fix(sessions): refresh allowAgents permissions after gateway restart
agents
stale
Cluster:
Skill and Session Management Fixes
#### Summary
After updating `agents.list[].subagents.allowAgents` in `openclaw.json` and restarting the gateway, existing sessions still use the old permissions snapshot. Newly added agents in the allowlist are invisible to `agents_list` and rejected by `sessions_spawn` until a completely new session is created.
This PR adds version-tracked `allowAgents` snapshots with dual-condition restart detection — the same pattern used for skill snapshots in PR #12209 — so that existing sessions pick up the current config on their next turn after a gateway restart.
Fixes #13377
#### Repro Steps
1. Start with one agent (`main`), add a second (`product-analyst`).
2. Edit `openclaw.json`: set `agents.list[0].subagents.allowAgents = ["product-analyst"]`.
3. Restart: `openclaw gateway restart`.
4. Message an existing session → `agents_list` returns only `main`.
5. Create a new session → `agents_list` correctly shows both.
#### Root Cause
Sessions snapshot `allowAgents` permissions at creation time and never refresh them — even after a full gateway restart. There is no version tracking or staleness detection for the `allowAgents` config, unlike skill snapshots which already have this mechanism.
#### Behavior Changes
- **Before:** `allowAgents` permissions were frozen at session creation. Gateway restarts did not refresh them.
- **After:** `allowAgents` permissions are version-tracked. On each turn, the session detects config staleness via dual-condition restart detection (`configVersion === 0 && persistedVersion > 0`) and rebuilds the snapshot from live config. Data drift (config changes without a version bump) is also detected via array comparison.
#### Codebase and GitHub Search
- Searched for existing `allowAgents` snapshot handling → none existed (only skills had version tracking).
- Reviewed PR #12209 for the skill snapshot refresh pattern to mirror the approach.
- Searched `agents-list-tool.ts` and `sessions-spawn-tool.ts` to verify where `allowAgents` is consumed.
#### Tests
6 new tests in `session-updates.test.ts` — all passing:
| # | Scenario | Status |
|---|----------|--------|
| 1 | Fresh snapshot creation (no prior snapshot) | ✅ |
| 2 | Snapshot reuse during normal operation (versions match) | ✅ |
| 3 | Stale snapshot detected after restart (version inversion) | ✅ |
| 4 | SessionStore fallback resolution | ✅ |
| 5 | Data drift detection (config changed without version bump) | ✅ |
| 6 | No session store (returns snapshot without persisting) | ✅ |
```
✓ src/auto-reply/reply/session-updates.test.ts (6 tests) 4ms
Test Files 1 passed (1)
Tests 6 passed (6)
```
Full suite: 993 test files, 6826 tests passed.
#### Files Changed
| File | Change |
|------|--------|
| `src/config/sessions/types.ts` | Add `AllowAgentsSnapshot` type + field on `SessionEntry` |
| `src/auto-reply/reply/session-updates.ts` | Version tracking + `ensureAllowAgentsSnapshot` with dual-condition restart detection |
| `src/auto-reply/reply/session-updates.test.ts` | 6 tests covering all snapshot lifecycle scenarios |
| `src/auto-reply/reply/get-reply-run.ts` | Wire `ensureAllowAgentsSnapshot` into the reply pipeline |
| `CHANGELOG.md` | Add fix entry |
lobster-biscuit
**Sign-Off**
- Models used: Claude
- Submitter effort (self-reported): high — investigated PR #12209 pattern, traced allowAgents usage through tools, implemented mirroring approach with tests
- Agent notes: Full test suite passes (993 files, 6826 tests). Lint, type-check, and format all clean.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds `allowAgentsSnapshot` to `SessionEntry` and introduces `ensureAllowAgentsSnapshot()` in `src/auto-reply/reply/session-updates.ts`, mirroring the existing skills snapshot refresh pattern. The reply pipeline (`src/auto-reply/reply/get-reply-run.ts`) calls this helper each turn to rebuild/persist the snapshot when it detects staleness (including a “version inversion” after restart) or config drift.
However, the two tools that actually gate and advertise allowed agents (`agents_list` and `sessions_spawn`) read `subagents.allowAgents` directly from `loadConfig()` and do not consult `SessionEntry.allowAgentsSnapshot`, so this snapshot refresh does not currently change their behavior after a gateway restart.
The new snapshot refresh logic also computes `dataChanged` only from `sessionEntry` (not the sessionStore fallback), which can force unnecessary rebuilds/writes (and version bumps) when `sessionEntry` is undefined but `sessionStore[sessionKey]` already has a matching snapshot.
<h3>Confidence Score: 2/5</h3>
- This PR likely does not fix the reported behavior and has a logic bug in snapshot drift detection.
- The allowAgents snapshot is refreshed and persisted, but the runtime enforcement surfaces (`agents_list` / `sessions_spawn`) still read live config via `loadConfig()` and never use the snapshot, so the stated post-restart session behavior is unlikely to change. Additionally, `dataChanged` ignores the sessionStore fallback snapshot, which can trigger unnecessary rebuilds and global version bumps when `sessionEntry` is absent.
- src/auto-reply/reply/session-updates.ts; also verify intended integration with src/agents/tools/agents-list-tool.ts and src/agents/tools/sessions-spawn-tool.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#22525: [Bug]: Session snapshot not reloading skills after gateway restart ...
by zwffff · 2026-02-21
83.5%
#22568: fix(gateway): bump skills snapshot version on startup so sessions r...
by zwffff · 2026-02-21
83.2%
#20072: feat(sessions_spawn): add sessionKey param to reuse sub-agent sessions
by Be1Human · 2026-02-18
80.7%
#16654: fix: refresh skills snapshot when managed skills change
by PhineasFleabottom · 2026-02-15
80.6%
#12209: fix(skills): refresh stale skill snapshot after gateway restart
by mcaxtr · 2026-02-09
80.0%
#14734: test(agents): guard against stale allowAgents in existing sessions
by davidahmann · 2026-02-12
79.9%
#15176: fix(sessions): allow channel-routed session IDs and cross-agent paths
by cathrynlavery · 2026-02-13
79.5%
#21679: fix: Mission Control dashboard issues for agent status, stale sessi...
by thejawdoc · 2026-02-20
79.3%
#10748: feat: Add sessions.spawn gateway method for direct subagent spawning
by fox-openclaw · 2026-02-06
78.9%
#11250: fix: expand skills watcher ignore list and improve session repair l...
by zhangzhefang-github · 2026-02-07
78.5%