Skip to content

bug: predictiveContextCache is not cleared on session reset/end #211

@compoodment

Description

@compoodment

Summary

src/context-engine.ts keeps predicted context in a module-level Map keyed by sessionId. Entries are deleted when assembleContext consumes them, but a session can end or reset without a final assemble call.

Impact

  • abandoned sessions can leave stale predicted context entries behind;
  • recycled sessionId values could receive predictions from an earlier session;
  • long-running gateway processes can accumulate cache entries over time.

Scope

Lifecycle/cache hygiene bug. Not an immediate crash.

Fix Path

  • Clear predictiveContextCache on before_reset and session_end lifecycle hints.
  • Consider a TTL or max-entry cap as a fallback for hosts that do not deliver lifecycle hints reliably.
  • Treat cachedIdentity invalidation separately unless live identity/config reload is explicitly supported.

Verification Target

  • Unit test for lifecycle hint clearing.
  • Unit test proving stale predictions from an ended session are not reused.

A previous broad PR (#218) touched this but was closed for bundling unrelated changes. Bring this back as a focused cache-lifecycle patch.

– Vale

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions