Skip to content

fix(sessionapi): erase the context-guru plugin's saved state on DELETE (#1962) - #2155

Draft
boazdavid wants to merge 2 commits into
mainfrom
fix/1962-erase-plugin-state
Draft

boazdavid wants to merge 2 commits into
mainfrom
fix/1962-erase-plugin-state

Conversation

@boazdavid

@boazdavid boazdavid commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

BEHAVIOR CHANGE: needs a human's yes before merge

This comes from the context-guru update, not from the erase fix.

  • Who it affects: every keep-alive user.
  • Old behavior: a keep-alive ping was refused when its projected cost was above a flat $0.50.
  • New behavior (context-guru Add a coding-agent demo with cpex policy enforcement #1428, approved there): no flat cap by default. The planned pings of one idle span run when they cost less than the cache miss they protect. A miss costs 9 to 11 times a ping. A chain that costs more is refused with the reason not worth it.
  • Side effect: pings on very large prompts that the old cap refused now run. For example, the cap blocked GPT-5.5 above about 500K tokens.
  • How to keep the old cap: set keepalive_max_usd_per_ping: 0.5 in the plugin's engine.cache block.
  • Cortex has no ping-cap setting of its own. It passes context-guru's value through, and no Cortex doc mentions $0.50.

Summary

DELETE /v1/sessions/{id} and DELETE /v1/sessions now erase the context-guru plugin's data too. Before, the session's summary text stayed in ~/.cortex/context-guru-state.db for 30 days, and a restarted plugin loaded it back. Fixes #1962.

Draft: blocked on one more context-guru tag. The erase calls store.Memory.EraseSession and EraseAll from rossoctl/context-guru#1471. The branch pins v0.7.10, which was tagged 15 minutes before #1471 merged. So CI cannot build core/plugins/contextguru/erase.go yet. When the next tag exists, only the version number changes in 3 go.mod files.

What we found

  • The two DELETE handlers (core/sessionapi/clear.go) cleared only the session store, the archive and the timelines.
  • No plugin had a way to hear about an erase.
  • Repro: write a summary through the real plugin, call the real route, then start a new plugin instance. The row was still in session_state, and LoadSession loaded the summary back. The new test TestErase_RoutesRemoveSavedState is that repro, and it now passes.

What changed

The erase (commit 4d3fdf905)

  • New optional interface pipeline.SessionEraser (EraseSession, EraseAllSessions). The wrapper of a configured plugin (configuredPlugin) forwards it, as it forwards Shutdowner.
  • Both DELETE routes call it on every plugin of the live pipelines, after the store and the archive.
    • A failure is a 500 with a new field, pluginErrors ("<plugin>: <error>"). The rest of the erase stands.
    • DELETE /v1/sessions/{id} calls the plugins even when it answers 404. After a restart, the plugin's file can hold a session that neither the store nor the archive holds.
  • The context-guru plugin erases, in every live instance:
    • its session state, in memory, in the pending writes and in the state file, plus the rewind payloads that only that session stashed;
    • its forwarded-body stash (sentStash);
    • its keep-alive entries, which hold the masked credential and the last request body. So the erased session gets no more pings.
  • "Every live instance" includes an instance that a config reload left draining. Without that, its last flush wrote the erased rows back. A small registry (liveInstances) holds each instance from Init to Shutdown.
  • Docs: docs/session-api.md, docs/context-guru-plugin.md and CLAUDE.md now say what the erase removes and what it keeps.

The context-guru update to v0.7.10 (commit a8fd976d6)

What the erase keeps

  • The accountant's per-session state: ids, hashes and a billing mode, no content. This is out of scope, as the issue says.
  • The incoming-model credential holds. One hold is shared by every session on a credential, so the erase cannot target one session.
  • The thread tracker: hashes and counts, no text.
  • For a one-session erase only: the engine results keyed by content, not by session. DELETE /v1/sessions removes them.

How it was tested

  • core/plugins/contextguru/erase_test.go, with 3 tests:
    • both routes through a real pipeline, then a restart;
    • a draining instance;
    • the forwarded-body stash.
  • core/sessionapi/erase_plugins_test.go, with 3 tests: both routes reach an eraser, a 404 still erases, and a plugin error gives a 500 with pluginErrors.
  • core/pipeline/configured_test.go: the wrapper forwards both calls.
  • The draining test fails without the registry. The old instance kept the session and wrote it back.
  • I ran the tests with a temporary GOWORK file that points at the merged context-guru main (dd0c46d: v0.7.10 plus 5 commits, Feat: Add the Python SDK for script plugins, with replay #1471 among them). I committed no replace directive.
    • accounting, plugins/contextguru, sessionapi and pipeline pass (-tags include_plugin_contextguru).
    • cmd/cortex and cmd/cortex-envoy build with the plugin.
    • gofmt -l core and go vet are clean.

Open questions

Assisted-By: Claude (Anthropic AI) noreply@anthropic.com

@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

#1962)

DELETE /v1/sessions/{id} and DELETE /v1/sessions cleared the session store
and the archive only. The context-guru plugin kept the session's summary
text in context-guru-state.db for 30 days, and its forwarded-body stash and
keep-alive entries (which hold the conversation) in memory.

- New optional interface pipeline.SessionEraser. The wrapper of a
  Configurable plugin forwards it.
- Both DELETE routes call it on every plugin of the live pipelines, after
  the store and the archive. A failure is a 500 with pluginErrors; the rest
  of the erase stands. DELETE /v1/sessions/{id} calls it even on a 404.
- The context-guru plugin erases, in every live instance (a draining one
  too): its session state (store.Memory.EraseSession / EraseAll), its
  sentStash entries and its keeper entries.
- docs/session-api.md, docs/context-guru-plugin.md and CLAUDE.md describe
  what the erase now removes and keeps.

Needs a context-guru release with rossoctl/context-guru#1471.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: DAVID BOAZ <DAVIDBO@il.ibm.com>
- Pin context-guru v0.7.10 in core, cmd/cortex and cmd/cortex-envoy.
- keepalive.Record lost its Agent field (context-guru #1506). Pass the
  client as Identity, from agent.Identify of the request headers, as the
  context-guru proxy does.
- TestAPanicInOnFinishStillDeparts got its panic from a store write that
  context-guru now recovers itself (#1513). It now panics in stashSent,
  which runs in this plugin before Record.
- TestPolicyDefaults expects no flat per-ping cap: since context-guru
  #1428 a value rule decides, and an operator opts in to a cap with
  keepalive_max_usd_per_ping.

Behavior change: a keep-alive ping is no longer refused at a flat $0.50.
It runs when the planned pings cost less than the cache miss they protect.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: DAVID BOAZ <DAVIDBO@il.ibm.com>
@boazdavid
boazdavid force-pushed the fix/1962-erase-plugin-state branch from a8fd976 to 65fadde Compare November 29, 2026 07:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New/ToDo

Development

Successfully merging this pull request may close these issues.

Deleting a session leaves the context-guru plugin's saved state, which holds conversation text

1 participant