Graceful Cancellation#
MassGen supports graceful cancellation, allowing you to interrupt a running session (Ctrl+C) while still preserving partial progress. This is useful when agents are going down the wrong path or taking too long.
How It Works#
When you press Ctrl+C during coordination:
MassGen captures the current state from all agents
Any answers that have been generated are saved
Agent workspaces are preserved
The session can be resumed later with
--continue
# Running a session
$ massgen --config my_config.yaml "Complex question..."
π€ Multi-Agent
Agents: agent_a, agent_b
Question: Complex question...
[Agent coordination in progress...]
^C
β οΈ Cancellation requested - saving partial progress...
β
Partial progress saved. Session can be resumed with --continue
π Goodbye!
What Gets Saved#
When you cancel mid-session, MassGen saves:
Partial answers - Any answers that agents have submitted
Agent workspaces - All files created or modified by each agent (separately)
Turn metadata - Phase, timestamp, and task information
Voting state - If voting was in progress
The partial turn is marked as βincompleteβ in the session directory.
What the Next Turn Sees#
When you resume a session with an incomplete turn, no information is lost:
Conversation History: All partial answers are combined into a single assistant message with clear attribution. Agents that were still working (have a workspace but no answer yet) get a placeholder:
[INCOMPLETE TURN - Session was cancelled before completion]
[Phase when cancelled: coordinating]
## agent_a's answer (voted for: agent_b):
First agent's partial answer...
[Workspace available at: /path/to/workspace]
## agent_b:
[No answer submitted - agent was still working]
[View workspace for current progress: /path/to/workspace]
Workspaces: All agent workspaces from the incomplete turn are provided as read-only context paths, allowing agents to see what each other was working on. This includes:
Agents that submitted partial answers
Agents that were still working (created files but no answer yet)
This ensures no files or progress is lost, even from agents that hadnβt finished their response.
Session Directory Structure#
After cancellation, your session directory will contain:
.massgen/sessions/session_20251205_120000/
βββ SESSION_SUMMARY.txt # Updated with incomplete turn info
βββ turn_1/ # Complete previous turn (if any)
β βββ metadata.json
β βββ answer.txt
β βββ workspace/
βββ turn_2/ # Incomplete turn
βββ metadata.json # status: "incomplete"
βββ partial_answers.json # All agent answers
βββ answer.txt # Best available answer
βββ workspaces/ # Per-agent workspaces
βββ agent_a/
βββ agent_b/
Resuming After Cancellation#
Resume your session with the --continue flag:
$ massgen --continue
π Restored session with 2 previous turn(s)
Starting turn 3
β οΈ Previous turn was incomplete (cancelled during coordinating phase)
Task: Complex question...
Partial answers saved from: agent_a, agent_b
The incomplete turn's partial progress is saved in the session directory.
When resuming:
MassGen shows you information about the incomplete turn
You can ask the same question again or move on to a new one
Previous complete turns provide context for agents
Partial answers from the cancelled turn are available for review in the session directory
Viewing Partial Results#
You can review the partial answers saved during cancellation:
# View the partial answers
cat .massgen/sessions/session_*/turn_*/partial_answers.json
# View the best partial answer
cat .massgen/sessions/session_*/turn_*/answer.txt
Force Exit#
If you need to exit immediately without saving:
First Ctrl+C: Graceful cancellation (saves partial progress)
Second Ctrl+C: Force exit (no saving)
Multi-Turn Mode Behavior#
In multi-turn (interactive) sessions, cancellation works slightly differently:
First Ctrl+C: Saves partial progress and returns to the prompt
Second Ctrl+C: Exits the session entirely
Queued runtime fallback prompts persist: If pending runtime-injection text is promoted to a new turn prompt and that turn is cancelled, the prompt is retained in conversation history for subsequent turns
This allows you to cancel a long-running turn without losing your entire session:
$ massgen --config my_config.yaml # Interactive mode
π€ Multi-Agent Session
> What is the meaning of life?
[Agent coordination in progress...]
^C
β οΈ Cancellation requested - saving partial progress...
β
Partial progress saved. Session can be resumed with --continue
βΈοΈ Turn cancelled. Partial progress saved.
Enter your next question or /quit to exit.
> Let's try a simpler question...
This behavior ensures you can:
Cancel a turn thatβs taking too long without losing the session
Review partial progress and decide how to proceed
Continue with a different question if needed
Use Cases#
Graceful cancellation is helpful when:
Wrong Direction - Agents are pursuing an incorrect approach
Too Long - Coordination is taking longer than expected
Debugging - You want to inspect partial state
Resource Management - You need to free up API calls or compute
Configuration#
Graceful cancellation is enabled by default. No configuration is required.
Note
Partial progress is only saved if at least one agent has submitted an answer. If cancelled before any answers are generated, only the task metadata is saved.