Context dump/load for session isolation #136

Closed
opened 2026-04-05 04:36:07 +02:00 by shoko · 0 comments
Owner

Overview

Implement explicit context dump/load mechanism to prevent session context bleeding between different projects.

Problem

When running parallel agents on different repositories (e.g., kugetsu and jigaido), sessions occasionally get mixed up:

  • Agents working on jigaido get redirected to kugetsu
  • PM context from one project bleeds into another
  • Session ID alone is not reliable for context isolation

Solution

Store full conversation history in files tied to issue-ref (not opencode session ID).

Directory Structure

~/.kugetsu/context/
  github.com-shoko-kugetsu-14.json   # Full conversation history for issue #14
  github.com-shoko-jigaido-2.json    # Full conversation history for jigaido #2

~/.kugetsu/context-meta/
  github.com-shoko-kugetsu-14.json    # Quick metadata (state, branch, etc.)

Context File Format

{
  "issue_ref": "github.com/shoko/kugetsu#14",
  "created_at": "2026-04-01T10:00:00Z",
  "updated_at": "2026-04-05T14:30:00Z",
  "current_branch": "fix/issue-14",
  "last_message": "I've fixed the login bug and pushed the changes...",
  "conversation_history": [
    {"role": "user", "content": "Fix the login bug", "timestamp": "..."},
    {"role": "assistant", "content": "I'll start working on this...", "timestamp": "..."}
  ]
}

Flow

  1. kugetsu start <issue> <msg>:

    • Load context from ~/.kugetsu/context/<issue-ref>.json
    • Prepend to opencode session context
    • If no context file, start fresh
  2. kugetsu continue <issue> <msg>:

    • Load context, inject into session
    • Continue conversation
  3. Session ends (after each command):

    • Dump current conversation to context file
    • Update updated_at timestamp

Implementation

  • Add kugetsu_context_load() function
  • Add kugetsu_context_dump() function
  • Hook into cmd_start and cmd_continue
  • Hook into session end (after opencode command completes)

Configuration

# Context directory (default: ~/.kugetsu/context)
CONTEXT_DIR="$KUETSU_DIR/context"

# Enable context dump/load (default: true)
ENABLE_CONTEXT_DUMP=true

Rationale

By tying context to issue-ref instead of session ID:

  • Same issue always resumes with same context
  • Different issues have isolated contexts
  • Even if opencode session gets "poisoned", context remains correct
## Overview Implement explicit context dump/load mechanism to prevent session context bleeding between different projects. ## Problem When running parallel agents on different repositories (e.g., kugetsu and jigaido), sessions occasionally get mixed up: - Agents working on jigaido get redirected to kugetsu - PM context from one project bleeds into another - Session ID alone is not reliable for context isolation ## Solution Store full conversation history in files tied to issue-ref (not opencode session ID). ### Directory Structure ``` ~/.kugetsu/context/ github.com-shoko-kugetsu-14.json # Full conversation history for issue #14 github.com-shoko-jigaido-2.json # Full conversation history for jigaido #2 ~/.kugetsu/context-meta/ github.com-shoko-kugetsu-14.json # Quick metadata (state, branch, etc.) ``` ### Context File Format ```json { "issue_ref": "github.com/shoko/kugetsu#14", "created_at": "2026-04-01T10:00:00Z", "updated_at": "2026-04-05T14:30:00Z", "current_branch": "fix/issue-14", "last_message": "I've fixed the login bug and pushed the changes...", "conversation_history": [ {"role": "user", "content": "Fix the login bug", "timestamp": "..."}, {"role": "assistant", "content": "I'll start working on this...", "timestamp": "..."} ] } ``` ### Flow 1. **`kugetsu start <issue> <msg>`**: - Load context from `~/.kugetsu/context/<issue-ref>.json` - Prepend to opencode session context - If no context file, start fresh 2. **`kugetsu continue <issue> <msg>`**: - Load context, inject into session - Continue conversation 3. **Session ends** (after each command): - Dump current conversation to context file - Update `updated_at` timestamp ### Implementation - Add `kugetsu_context_load()` function - Add `kugetsu_context_dump()` function - Hook into `cmd_start` and `cmd_continue` - Hook into session end (after opencode command completes) ### Configuration ```bash # Context directory (default: ~/.kugetsu/context) CONTEXT_DIR="$KUETSU_DIR/context" # Enable context dump/load (default: true) ENABLE_CONTEXT_DUMP=true ``` ## Rationale By tying context to issue-ref instead of session ID: - Same issue always resumes with same context - Different issues have isolated contexts - Even if opencode session gets "poisoned", context remains correct ## Related Issues - Meta issue: #133
han was assigned by shoko 2026-04-05 04:45:02 +02:00
shoko added this to the v0.1.0 milestone 2026-04-05 04:45:02 +02:00
shoko closed this issue 2026-04-05 06:23:40 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shoko/kugetsu#136