← Back to PRs

#21731: Fix: clear stale session runtime model on /new, /reset, and session_status default

by AIflow-Labs open 2026-02-20 09:06 View on GitHub →
gateway agents size: S
## 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