Skip to content

Refresh workspace context (ENTITY TYPES) per turn, not per session #1062

Description

@malibio

Problem

build_workspace_context (which includes ENTITY TYPES, collections, and playbooks) is called once at session creation and cached in session.dynamic_context. If the user creates a new schema type mid-session (e.g., "Project"), the system prompt still shows the old type list for the rest of that session.

This means:

  • The model doesn't know "Project" is a valid type until a new chat session is started
  • The model can't create instances of newly-defined types within the same conversation
  • The ENTITY TYPES section becomes stale immediately after any schema CRUD

Current Flow

create_session → build_workspace_context() → cache in session.dynamic_context
send_message(turn 1) → reads cached context ← types: [task, text]
user creates "Project" schema via create_schema tool
send_message(turn 2) → reads cached context ← types: [task, text] ❌ stale!

Desired Flow

create_session
send_message(turn 1) → build_workspace_context() → types: [task, text]
user creates "Project" schema via create_schema tool
send_message(turn 2) → build_workspace_context() → types: [task, text, project] ✅ fresh!

Proposed Solution

Rebuild the workspace context per turn instead of per session. Two options:

Option A (simplest): Refresh context in the Tauri command layer before each send_message call:

// In local_agent_send_message command:
let context = build_workspace_context(&ns).await.unwrap_or_default();
service.set_session_context(&session_id, context.format_for_prompt(1500)).await;
// Then proceed with send_message

Option B: Pass a context provider into the agent loop so run_turn can fetch fresh context itself, without depending on external refresh.

Option A is minimal and keeps the agent loop dependency-free. The cost is one get_all_schemas query per turn (~1ms with cached schemas).

Acceptance Criteria

  • ENTITY TYPES in system prompt reflects current schemas on every turn
  • Creating a schema in turn N makes it available in turn N+1 within the same session
  • Collections and playbooks also refresh per turn
  • No significant latency increase (schema query is fast)

Activity

  1. malibio commented on Apr 7, 2026

    @malibio
    CollaboratorAuthor

    Baseline: 128 test files passed, 3918 tests passed

  2. self-assigned this
    on Apr 7, 2026
  3. added 3 commits that reference this issue on Apr 7, 2026
    b6c06b0
    59298d4
    8bb960b
  4. added 4 commits that reference this issue on Apr 7, 2026
    0800732
    42c601a
    212734a
    6d3b904
  5. added 2 commits that reference this issue on Jun 22, 2026
    47616f7
    e6fabe8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions