fix(party-mode): add return protocol to prevent lost-in-the-middle failures#1569
Conversation
…ilures After Party Mode completes within a parent workflow, the LLM fails to re-present the parent workflow's completion menu due to lost-in-the-middle effect at 50-100K tokens. The parent workflow instructions get pushed into mid-context where they are no longer proactively recalled. Add a Return Protocol section to step-03-graceful-exit.md that instructs the LLM to: 1. Identify the parent workflow that invoked party-mode 2. Re-read that file to restore context 3. Resume from the invocation point 4. Present required menus/options This is platform-independent prompt engineering that forces proactive re-reading rather than relying on mid-context recall. Fixes #1319
📝 WalkthroughWalkthroughAdded a Return Protocol section to Party Mode's graceful exit step that instructs the LLM to identify parent workflows, re-read their instructions, resume execution at the correct point, and explicitly return control instead of continuing conversationally. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/core/workflows/party-mode/steps/step-03-graceful-exit.md (1)
111-117:⚠️ Potential issue | 🟠 MajorPossible contradiction between “Exit Workflow” and Return Protocol.
Lines 111-117 instruct final workflow termination, but the new RETURN PROTOCOL requires resuming the parent workflow and presenting menus. Please reconcile the ordering/wording so the model doesn’t terminate before returning control.
Also applies to: 145-155
Re: CodeRabbit's Ordering ConcernCodeRabbit flagged a valid structural issue:
The concern is legitimate. The LLM reads sequentially through the numbered steps (1-6). By the time it reaches step 6 ("Exit Workflow") and sees However, the current implementation matches your exact specification from #1319. I don't want to deviate from your design without your input. Suggested Variation (if you want it)Integrate the Return Protocol into step 6 with conditional logic: ### 6. Return to Parent or Exit
**If Party Mode was invoked from within a parent workflow:**
1. Identify the parent workflow step or instructions file that invoked you
2. Re-read that file now to restore context
3. Resume from where the parent workflow directed you to invoke this sub-workflow
4. Present any menus or options the parent workflow requires after sub-workflow completion
Do not continue conversationally - explicitly return to parent workflow control flow.
**If Party Mode was invoked standalone (no parent workflow):**
"[PARTY MODE WORKFLOW COMPLETE]
Thank you for using BMAD Party Mode for collaborative multi-agent discussions!"Then remove the separate Your Call
Let me know your preference. |
|
(Reposting with improved contrast) Visual: Expected Flow vs. Potential Short-CircuitCurrent Structure (CodeRabbit's Concern)flowchart TD
subgraph "Numbered Execution Steps"
S1["Step 1: Acknowledge"] --> S2["Step 2: Farewells"]
S2 --> S3["Step 3: Highlights"]
S3 --> S4["Step 4: Conclusion"]
S4 --> S5["Step 5: Frontmatter"]
S5 --> S6["Step 6: Exit Workflow<br/>⚠️ PARTY MODE WORKFLOW COMPLETE"]
end
subgraph "Reference Sections (below steps)"
RP["RETURN PROTOCOL:<br/>If parent workflow exists...<br/>re-read and resume"]
end
S6 -->|"LLM may stop here"| DONE["🛑 Done"]
S6 -.->|"Should continue to"| RP
RP -->|"Return to parent"| PARENT["Parent Workflow Menu"]
style S6 fill:#8b0000,color:#ffffff
style DONE fill:#660000,color:#ffffff
style RP fill:#006400,color:#ffffff
style PARENT fill:#004d00,color:#ffffff
Risk: LLM sees "WORKFLOW COMPLETE" at step 6 and considers itself done before reaching the RETURN PROTOCOL section. Proposed Integrated Structureflowchart TD
subgraph "Numbered Execution Steps"
S1["Step 1: Acknowledge"] --> S2["Step 2: Farewells"]
S2 --> S3["Step 3: Highlights"]
S3 --> S4["Step 4: Conclusion"]
S4 --> S5["Step 5: Frontmatter"]
S5 --> S6{"Step 6: Return or Exit"}
end
S6 -->|"Has parent workflow?"| RETURN["Re-read parent file<br/>Resume at invocation point<br/>Present parent's menu"]
S6 -->|"Standalone"| EXIT["PARTY MODE COMPLETE"]
RETURN --> PARENT["Parent Workflow Menu"]
EXIT --> DONE["🛑 Done"]
style S6 fill:#006400,color:#ffffff
style RETURN fill:#004d00,color:#ffffff
style PARENT fill:#003300,color:#ffffff
style EXIT fill:#333333,color:#ffffff
style DONE fill:#333333,color:#ffffff
Benefit: The decision point is inside the execution flow, not in a separate reference section the LLM might skip. |
Summary
Adds a Return Protocol section to Party Mode's graceful exit step to prevent lost-in-the-middle context failures when Party Mode is invoked from a parent workflow.
Fixes #1319
Problem
After Party Mode completes within a parent workflow (e.g., step-02-discovery in agent creation), the LLM fails to re-present the parent workflow's completion menu. The user has to explicitly ask for it.
Root cause: Party Mode often runs into the 50-100K token range, pushing the parent workflow's instructions into mid-context where they are no longer proactively recalled.
Solution
Add explicit instructions to
step-03-graceful-exit.mdthat force the LLM to:This is platform-independent prompt engineering — it works for both sharded workflows (
steps/step-XX-name.md) and standard workflows (instructions.md).Changes
## RETURN PROTOCOL:section tosrc/core/workflows/party-mode/steps/step-03-graceful-exit.mdTesting
Re-run a workflow that invokes Party Mode (e.g., Doc agent creation through step-02-discovery) and confirm menu presentation after Party Mode completes.
Adversarial Analysis: Limitations of This Approach
While offering this code, I perceived (you be the judge) some potential improvements:
The Circular Dependency Problem
The Return Protocol asks an LLM to:
But the root cause of #1319 is that the LLM has already forgotten that mid-context information due to lost-in-the-middle effect. We're asking it to recall the very thing it forgot.
Why It May Still Help
When It Will Likely Fail
Proposed Enhancement: Workflow State Tracking
A more robust solution might be to use explicit state instead of relying on LLM recall:
Option A: Frontmatter Variable
When a parent workflow invokes Party Mode, it could set:
Then the Return Protocol becomes a lookup instead of a recall:
Option B: Workflow Stack
For nested sub-workflow invocations:
Pop the stack on return. This mirrors how programming languages handle function calls.
Or if you have another idea, I am option to direction.
Request for Maintainers
Three paths forward:
Merge this as v1 — The Return Protocol matches Add Return Protocol to Party Mode to prevent lost-in-the-middle workflow failures #1319's specification exactly. It's a reasonable first-step mitigation that may help in many cases. We can iterate based on real-world feedback.
Implement state tracking now — If you agree the enhancement is valuable, I can implement Option A (frontmatter variable, or examine another other option) in this PR before merging. This may require changes to:
step-02-discovery.md(setparentWorkflowwhen invoking Party Mode)step-03-graceful-exit.md(readparentWorkflowinstead of asking LLM to recall)Implement coderabbitai-variation - See below and/or state tracking now.
Let me know which direction you prefer, merge and ignore, merge and pursue second step, or adopt one of these perceived improvements now.