#6489·gsd-2

GSD context lost after conversation compaction — missing session_compact hook

Author: aj-normanCreated Aug 12, 2026Updated Aug 12, 2026

Problem

After planning or discussion reaches the context window limit and pi compacts the conversation, the compaction summary degrades to a generic "It looks like you're starting a fresh conversation" message. This loses all GSD context (active milestone, slice, task, phase) and forces the user to re-explain what they were working on.

Root Cause

File: extensions/gsd/register-hooks.js (between the session_before_compact handler ~line 504 and the message_update handler ~line 559)

GSD registers a session_before_compact hook that writes a snapshot to .gsd/last-snapshot.md, but does not register a session_compact handler to re-inject that state after compaction completes.

The before_agent_start hook re-injects the GSD system prompt on every turn, but the misleading compaction summary is already baked into the conversation history. The buildGuidedExecuteContextInjection context injection only fires for explicit task-execution prompts during phase === "executing" — it doesn't cover discussion or planning phases.

Other extensions (e.g., bg-shell) already use session_compact successfully to queue alerts that survive compaction via pushAlert.

javascript
// Current: only before_compact exists
pi.on("session_before_compact", async () => {
  // writes snapshot to .gsd/last-snapshot.md
});

// Missing: no session_compact handler to re-inject context
// pi.on("session_compact", async () => { ... });

Expected Behavior

GSD should register a session_compact handler that:

  1. Reads the just-written .gsd/last-snapshot.md snapshot
  2. Queues a context notification (via pushAlert or equivalent) that re-injects the active milestone/slice/task state, phase, and key decisions into the post-compaction context

This ensures the agent resumes with full GSD awareness after compaction, regardless of which phase (discussion, planning, or execution) was active.

Alternative approach: Detect recent compaction in before_agent_start (snapshot file age < 30s) and inject the snapshot content directly into the system context message.

Environment

  • GSD version: 3.0.0
  • Trigger: Context compaction during discussion/planning phase
  • Active milestone at time of issue: M001
  • Active slice at time of issue: S06

Reproduction Steps

  1. Start a GSD session with an active milestone
  2. Have a long discussion or planning conversation that approaches the context limit
  3. When pi compacts the conversation, observe the summary loses all GSD context
  4. The agent behaves as if starting fresh, unaware of active work

Forensic Evidence

  • No anomalies in activity logs or journal — the issue is in the compaction recovery path, not in auto-mode dispatch
  • session_before_compact hook exists and writes the snapshot correctly
  • session_compact hook is absent — no mechanism to re-inject the snapshot
  • bg-shell extension demonstrates the working pattern: session_compactpushAlert → context survives

Auto-generated by /gsd forensics