#21731: Fix: clear stale session runtime model on /new, /reset, and session_status default
gateway
agents
size: S
Cluster:
Session Management Improvements
## Summary
Resolves stale runtime model leakage after reset flows by ensuring session runtime model metadata is fully cleared when users reset model state to defaults.
## What changed
- Updated shared model override helper (`src/sessions/model-overrides.ts`) to clear persisted runtime fields (`model` and `modelProvider`) when `model=default` is applied.
- Updated `sessions.reset` handler (`src/gateway/server-methods/sessions.ts`) to avoid carrying forward `model` from the old session when creating a new session entry.
- Added/extended tests to enforce behavior:
- `src/sessions/model-overrides.test.ts`: verifies default reset clears model/runtime metadata and overrides.
- `src/agents/openclaw-tools.session-status.e2e.test.ts`: verifies `session_status(model=default)` persists model cleanup.
- `src/gateway/server.sessions.gateway-server-sessions-a.e2e.test.ts`: verifies `sessions.reset` response clears runtime model metadata.
## Why this fixes it
`session_status(model=default)` and `/new`/`/reset` paths used shared model override behavior, but runtime `model` and `modelProvider` were not being reset, so gateway resume logic kept reusing stale override values. This update makes the reset semantics explicit and consistent:
- session scoped live model resolves from store state after reset.
- default model resets remove runtime leftovers instead of leaving stale values.
## Validation
- `pnpm check`
- `pnpm test`
- `pnpm vitest run src/sessions/model-overrides.test.ts`
- `pnpm vitest run --config vitest.e2e.config.ts src/agents/openclaw-tools.session-status.e2e.test.ts src/gateway/server.sessions.gateway-server-sessions-a.e2e.test.ts`
## Related issue
Closes #21725
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Clears runtime model state (`model` and `modelProvider`) when resetting to default model configuration. Updated `applyModelOverrideToSessionEntry` to delete runtime fields when `isDefault=true`, removed `model` field copying in `sessions.reset`, and added tests to verify the cleanup behavior persists across `session_status(model=default)` and `/new`/`/reset` flows.
<h3>Confidence Score: 5/5</h3>
- 5/5 because behavior change is tightly scoped and deterministic: exactly the two reset pathways that rehydrate runtime model metadata were updated, with no API contract changes.
- The implementation is minimal and symmetry-driven:
- `applyModelOverrideToSessionEntry` now removes stale persisted model values when users choose `model=default`.
- `sessions.reset` no longer copies `model` forward when building the replacement session entry.
- Verification is direct and targeted:
- New unit tests enforce nulling `model`/`modelProvider` in the shared helper path.
- e2E coverage validates both command-based (`session_status`) and protocol-level (`sessions.reset`) reset semantics.
- Full suite checks (`pnpm check`, `pnpm test`) passed after the change, reducing risk of unrelated regressions.
- Rollback cost is low (revert one focused commit if needed); there is no schema migration and no dependency change.
- No files require special attention, and there are no observed side-effects for non-default model usage.
<sub>Last reviewed commit: d4f828f</sub>
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#11613: fix: clear stale model metadata on /new and /reset
by mcaxtr · 2026-02-08
88.5%
#21876: fix(session): clear model override on /new and /reset
by sauerdaniel · 2026-02-20
86.3%
#21847: fix(session): /new and /reset no longer carry over model overrides
by hydro13 · 2026-02-20
85.8%
#21849: fix(session): clear model/provider overrides on /new and /reset
by widingmarcus-cyber · 2026-02-20
85.4%
#17375: fix(session): don't carry stale model info into reset welcome message
by BinHPdev · 2026-02-15
85.0%
#20185: fix(model): recognize default/reset/clear keywords to clear session...
by yxshee · 2026-02-18
84.6%
#17011: fix(/new /reset): clear model override for reset turn
by Limitless2023 · 2026-02-15
83.2%
#20770: fix: prevent stale session-entry overwrite during reset-model persi...
by coygeek · 2026-02-19
83.2%
#23299: fix(status): show runtime model context limit instead of stale sess...
by SidQin-cyber · 2026-02-22
79.9%
#14358: fix: preserve session overrides (verbose, model) across /new or /rese…
by WyattSanders · 2026-02-12
79.6%