From 0aae4233ab620e9b5e82d3df38d8b0cd65cdbe71 Mon Sep 17 00:00:00 2001 From: Mark Randall Havens Date: Thu, 12 Mar 2026 23:19:29 +0000 Subject: [PATCH] Fix state return handling - support dict fallback --- opus_orchestrator/langgraph_workflow.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/opus_orchestrator/langgraph_workflow.py b/opus_orchestrator/langgraph_workflow.py index d66fd46..2e8de43 100644 --- a/opus_orchestrator/langgraph_workflow.py +++ b/opus_orchestrator/langgraph_workflow.py @@ -612,15 +612,15 @@ Write ~{plan.word_count_target} words. except Exception as e: print(f"Stream error: {e}") - # FIX: Fallback - pull directly from checkpointer - if not final_state.manuscript: - print("Pulling from checkpointer...") - try: - snapshot = self.graph.get_state(config) - if snapshot and snapshot.values: - final_state = snapshot.values - except Exception as e: - print(f"Checkpointer error: {e}") + # FIX: Handle both OpusGraphState and dict from checkpointer + if hasattr(final_state, 'manuscript') and final_state.manuscript: + pass # Already have state + elif isinstance(final_state, dict) and final_state.get('manuscript'): + # Convert dict back to state if needed + print(f"\n[RESULT] Chapters: {len(final_state.get('chapters', {}))}, Words: {final_state.get('total_word_count', 0)}") + return OpusGraphState(**final_state) + else: + print(f"\n[RESULT] No manuscript found in state") print(f"\n[RESULT] Chapters: {len(final_state.chapters)}, Words: {final_state.total_word_count}")