Skip to content

fix(session_exec): stop duplicate session:start for raw sessions — emit session:config instead - #79

Merged
Brian Krabach (bkrabach) merged 1 commit into
mainfrom
fix/dedup-session-start-raw-emit
May 18, 2026
Merged

fix(session_exec): stop duplicate session:start for raw sessions — emit session:config instead#79
Brian Krabach (bkrabach) merged 1 commit into
mainfrom
fix/dedup-session-start-raw-emit

Conversation

@bkrabach

Copy link
Copy Markdown
Collaborator

Summary

Bug 2 from session lifecycle investigation: when session.raw=True, every call to execute() was emitting two session:start events separated by 7–13 seconds:

  1. Rust kernel emits base session:start (small payload, no raw config)
  2. Python helper emit_raw_field_if_configured() emits a second session:start with the full 900KB+ raw config

The 13s gap is the time for redact_secrets(config) on a massive config + hook dispatch overhead.

Root Cause

_session_exec.py::emit_raw_field_if_configured() was designed to emit the raw config on the base session event name (session:start, session:resume). But the Rust kernel already emitted the base event synchronously before calling this helper, so both emits hit the same session:start event type.

Fix

Change emit_raw_field_if_configured() to emit session:config instead of re-emitting session:start. The raw mount plan is now in a dedicated event.

API compatibility: The event_base parameter is retained in the function signature but is no longer used as the event name.

Migration

Downstream consumers that read raw config from session:start must subscribe to session:config instead. Known affected systems:

  • hook-context-intelligence — reads raw session config for graph enrichment (separate PR needed)

Evidence

Observed in sessions 3dca44c1 and 69ab20de from behavior-provenance workspace:

+0.000s  session:start     ← Rust kernel emit
+7.727s  session:start     ← duplicate from emit_raw_field_if_configured()  
+14.649s prompt:submit

After fix: single session:start + separate session:config event.

TDD Red-Green Cycle

RED (before fix):

  • test_session_start_emitted_exactly_once_for_raw_mode → FAILED (count=2)
  • test_raw_config_captured_in_session_config_event → FAILED (no session:config event)

GREEN (after fix):

  • Both tests PASS

Files Changed

File Change
python/amplifier_core/_session_exec.py Changed event from event_base to "session:config"
bindings/python/tests/test_session_start_dedup.py NEW — 4 tests for deduplication

Test Results

347 passed (+ 4 new), 19 pre-existing failures (unchanged)

…tart for raw mode

Root cause (Bug 2):
  When session.raw=True, the Rust kernel emits session:start once (the
  base event), then calls emit_raw_field_if_configured() which emitted
  session:start a SECOND TIME with the raw config payload. Every session
  with raw=True got two session:start events per execute() call, separated
  by 13+ seconds (the time for redact_secrets() on a 900KB+ config and
  hook dispatch overhead).

Fix:
  Change emit_raw_field_if_configured() to emit 'session:config' instead
  of re-emitting the base event (session:start or session:resume). The
  raw config payload is now in a dedicated event. Consumers that need the
  raw mount plan should subscribe to 'session:config'.

  The 'event_base' parameter is retained for API compatibility but is no
  longer used as the emitted event name.

Performance impact:
  The 13s startup delay (observed in sessions 98320ded and 69ab20de) came
  from hook chains processing a 900KB session:start payload twice. With
  this fix, the raw config is emitted as session:config (still slow for
  large configs, but at least it's not mistaken for a lifecycle event).

Migration:
  Downstream consumers (e.g. hook-context-intelligence) that read the raw
  config from session:start must now subscribe to session:config.

Tests:
  - test_session_start_dedup.py (new): 4 tests asserting
    1. session:start emitted exactly once for raw sessions
    2. session:config emitted with raw payload
    3. session:start still emitted (guard against over-correction)
    4. non-raw sessions unaffected (still emit session:start exactly once)
@bkrabach
Brian Krabach (bkrabach) force-pushed the fix/dedup-session-start-raw-emit branch from ee16758 to 6d56a7e Compare May 18, 2026 10:49
@bkrabach
Brian Krabach (bkrabach) merged commit ffaa1b5 into main May 18, 2026
1 of 11 checks passed
@bkrabach
Brian Krabach (bkrabach) deleted the fix/dedup-session-start-raw-emit branch May 18, 2026 11:07
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.

1 participant