← Back to PRs

#13412: fix(sessions): refresh allowAgents permissions after gateway restart

by arun-dev-des open 2026-02-10 13:47 View on GitHub →
agents stale
#### 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