← Back to PRs

#11872: Add Pre-Reset Hook

by scomma open 2026-02-08 13:16 View on GitHub →
gateway stale size: S
The agent isn't very vigilant about committing things to memory, and it's unnatural to force them to write to memory while they are still working. It also leads to a journal littered with exploration dead ends. A more productive way would be to ask them to summarize notable things after the session breaks. It's possible to do this for implicit breaks using heartbeats, but for explicit `/reset` initiated by user, the context is immediately wiped. A pre-reset hook allows the agent to be prompted to commit important bits they have learned, and/or unfinished businesses, to memory, in order that they will make future sessions more relevant. This is an optional setting which has no effect if unset. Fully tested, has been running in my local instance for almost a week. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Adds an optional `session.preReset` config (types + zod schema) and wires a new `runPreResetHook()` into both chat-triggered resets (`initSessionState` on `/reset`-style triggers) and the gateway `sessions.reset` endpoint. The hook performs a best-effort agent turn (non-delivered) with a configurable prompt and timeout, intended to let the agent write wrap-up notes to memory before the session is cleared. <h3>Confidence Score: 4/5</h3> - Mostly safe to merge, but there is at least one correctness issue in the gateway reset hook wiring that can cause the hook to be skipped unexpectedly. - The feature is isolated and guarded by config, but the gateway `sessions.reset` path appears to load the session entry using the raw request key rather than the resolved canonical key, which can yield an undefined entry and cause `skipIfEmpty` to skip incorrectly. Aside from that, the hook is best-effort and failures are contained/logged. - src/gateway/server-methods/sessions.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs