Skip to content

[BUG] Session deleted while still active - race condition in compaction/archive #9

Description

@bk1man

Issue Summary

A webchat session was deleted by archiveSessionTranscripts(reason: "deleted") while it still had active tool execution in progress. The deletion occurred at 2026-03-22 19:00:26.270Z (UTC).

Environment

  • Platform: WSL2 (Ubuntu 24.04)
  • OPENAEON version: main branch (commit: fd7bac3)
  • Session compaction mode: safeguard
  • Node: v24.14.0

Timeline (UTC)

Time Event
2026-03-22 17:58:26 Session created and begins processing
2026-03-22 19:00:02 Session still active — tool execution begins
2026-03-22 19:00:26 abort failed: reason=no_active_run
2026-03-22 19:00:26.270 Session file deleted via archiveSessionTranscripts(reason: "deleted")

Evidence

Gateway Logs

// 19:00:02 - Session actively executing tool
{"subsystem":"agent/embedded","1":"embedded run tool start: tool=exec"}

// 19:00:26 - abort returns "no_active_run" (contradiction!)
{"subsystem":"diagnostic","1":"abort failed: sessionId=... reason=no_active_run"}

// 19:00:26.270 - Session file renamed to .deleted.*

Session File Deletion

-rw------- 1 feike feike 524288 Mar 23 01:38  
cdf2cf1a-736e-433c-9e3e-2ed9ef66cdd6.jsonl.deleted.2026-03-22T19-00-26.270Z

Root Cause Hypothesis

The session deletion appears to be triggered by compaction, but:

  1. Compaction mode is safeguard — should NOT auto-delete sessions
  2. The session was in active=true state
  3. No sessions.delete RPC call was logged
  4. Session file was renamed to .deleted.* by archiveSessionTranscripts()

Possible cause: A race condition where:

  1. Session compaction runs and decides to reset/archive the session
  2. The session simultaneously receives new work (tool execution)
  3. Compaction deletes the session file while work is in progress
  4. abort fails because compaction already removed the session state

Expected Behavior

  • Active sessions should NOT be deleted or archived
  • archiveSessionTranscripts should verify entry.active === false before deletion
  • Compaction in safeguard mode should preserve active sessions

Suggested Fixes

  1. Add active-check before archive: Verify entry.active === false before calling archiveSessionTranscripts
  2. Add session lock: Prevent compaction from removing sessions with recent activity (e.g., last 5 minutes)
  3. Fix abort race condition: Investigate why abort returns no_active_run when session is clearly processing
  4. Log the trigger: Add logging for who called archiveSessionTranscripts with reason: "deleted"

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