Skip to content

feat(#689): persistent meal-planner session state to prevent RAG leakage#695

Closed
lokhor wants to merge 3 commits intomainfrom
feat/689-meal-planner-session
Closed

feat(#689): persistent meal-planner session state to prevent RAG leakage#695
lokhor wants to merge 3 commits intomainfrom
feat/689-meal-planner-session

Conversation

@lokhor
Copy link
Copy Markdown
Collaborator

@lokhor lokhor commented Apr 26, 2026

Summary

Add conversation-scoped, Room-backed meal-planner session state and wire it into the chat prompt pipeline. During active meal-planner turns, the model receives structured session context (preferences, plan, current day) instead of relying on chat history — and episodic/RAG context is suppressed to prevent stale memory leakage.

Changes

New files

  • MealPlanSessionEntity.kt — Room entity with conversationId PK, status, peopleCount, days, dietary/protein preferences (JSON), high-level plan, current day index, updatedAt
  • MealPlanSessionDao.kt — DAO with getByConversationId, upsert, deleteByConversationId, deleteAll
  • MealPlanSessionRepository.kt — Convenience layer: createOrReset, updateStatus, updatePreferences, saveHighLevelPlan, advanceDay, markCompleted

Modified files

  • KernelDatabase.kt — Added MealPlanSessionEntity, mealPlanSessionDao() abstract method, MIGRATION_23_24, bumped version to 24
  • MemoryModule.kt — Added DAO/repository providers, included MIGRATION_23_24 in migration list
  • ChatViewModel.kt — Added MealPlanSessionRepository injection, session detection block that:
    • Checks for active (non-completed) meal-planner session
    • Builds structured context block via buildMealPlanContext()
    • Suppresses RAG context (effectiveRagContextForPrompt)
    • Forces needsHistoryReplay = true to clear stale episodic KV cache
    • Injects meal-plan context into prompt before anaphora/system blocks
  • VerboseLoggingPreferenceUseCase.kt — Merge conflict resolution from bringing main up to date (added missing @ApplicationContext import)

Architecture

User query → ChatViewModel.sendMessage()
    │
    ▼
Check mealPlanSessionRepository.getSession(conversationId)
    │
    ├─ Active session? → Suppress RAG, inject session context, force replay
    │
    └─ No active session → Normal RAG + episodic flow

Session context block (injected into prompt)

[Meal Planner Session]
Status: collecting_preferences
People: 4
Days: 3
Dietary: ["vegetarian","gluten-free"]
Proteins: ["chicken","fish"]
Plan: [{"day1":"..."},{"day2":"..."}]
Current day: 1
[End Meal Planner Session]

Testing

  • ./gradlew assembleDebug — builds clean
  • Unit tests pass (pre-existing failures in MemoryRepositoryImplTest and LatexConversionTest are unrelated)
  • Lint failures in core:inference are pre-existing (unrelated)

Next steps (out of scope for this PR)

  • Session transition updates in MealPlannerSkill (stage 4 of the plan)
  • MealPlannerSkill instruction updates (stage 5)
  • Regression tests for repository and prompt injection (stage 6)

Closes #689

lokhor and others added 3 commits April 21, 2026 06:55
…ed DataStore

Prevents IllegalStateException by sharing the AboutPreferencesModule DataStore
instead of creating a duplicate instance. Multiple active DataStore instances
on the same file cause crashes.

Fixes crash when toggling verbose logging in About screen on PR #649.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…leakage

Add conversation-scoped Room-backed session store for meal-planner state,
wire it into ChatViewModel to inject structured session context into prompts
and suppress episodic/RAG injection during active meal-planner turns.

New files:
- MealPlanSessionEntity: Room entity with conversationId PK, status,
  preferences, plan, and day tracking fields
- MealPlanSessionDao: DAO with getByConversationId, upsert, delete methods
- MealPlanSessionRepository: Convenience layer with createOrReset,
  updateStatus, updatePreferences, saveHighLevelPlan, advanceDay,
  markCompleted

Changes to existing files:
- KernelDatabase: add MealPlanSessionEntity, MIGRATION_23_24, version 24
- MemoryModule: add DAO/repository providers, include MIGRATION_23_24
- ChatViewModel: detect active meal-planner turns, suppress RAG context,
  inject structured meal-plan context block, force history replay

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

Debug APK ready

Download app-debug.apk

Commit: fece906 - Build #1061

Updated on each push. Removed when PR is merged or closed.

@lokhor lokhor closed this Apr 28, 2026
@lokhor
Copy link
Copy Markdown
Collaborator Author

lokhor commented Apr 28, 2026

Rebased and addressed code review: #698

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: add minimal meal planner session store to resolve #687 (not full #235)

1 participant