pika-news: fix stuck pending tasks and improve reliability#411
pika-news: fix stuck pending tasks and improve reliability#411justinmoon merged 1 commit intomasterfrom
Conversation
Three root causes were making generation tasks get stuck: 1. Stale `generating` artifacts after service restart had no recovery logic — add `recover_stale_generating()` called on startup. 2. Claude CLI invoked without `-p` and without `--tools ""`, so the model used tools, hit `--max-turns 1`, and returned `error_max_turns` with no `result` field — make `result` optional via `#[serde(default)]`, detect the subtype, and disable tools. 3. `extract_json_payload` only handled output starting with triple backticks, but the model often prefixes with prose — search for fenced blocks and bare JSON objects anywhere in the output. Also adds structured poll/worker logging and better error diagnostics that include stdout/result prefixes in error messages. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe changes introduce a startup recovery mechanism to reset artifacts stuck in a "generating" state from unclean shutdowns, enhance Claude CLI resilience with improved error handling and JSON extraction logic, and refactor logging in the web worker loop with pattern matching and conditional output. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/pika-news/src/model.rs (1)
112-121:⚠️ Potential issue | 🟠 MajorDisable tools in
chat_with_sessionto match behavior ingenerate_tutorial.The
generate_tutorialfunction uses--tools ""to disable tools, butchat_with_sessionomits this flag entirely. This inconsistency means the two code paths will behave differently—one with tools disabled, the other with tools enabled by default. This divergence can cause tool-related failures to manifest unpredictably in chat responses.Proposed fix
let stdout = run_claude_cli( &[ "-p", "-r", base_session_id, + "--tools", + "", "--output-format", "json", "--max-turns", "1", ],🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/pika-news/src/model.rs` around lines 112 - 121, chat_with_session is calling run_claude_cli without the --tools "" flag, causing tools to be enabled by default and diverging from generate_tutorial; update the chat_with_session call site (the run_claude_cli invocation) to include the --tools and empty-string arguments (i.e. "--tools", "") so tools are explicitly disabled, ensuring consistent behavior with generate_tutorial and preventing tool-related differences in chat responses.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@crates/pika-news/src/model.rs`:
- Around line 112-121: chat_with_session is calling run_claude_cli without the
--tools "" flag, causing tools to be enabled by default and diverging from
generate_tutorial; update the chat_with_session call site (the run_claude_cli
invocation) to include the --tools and empty-string arguments (i.e. "--tools",
"") so tools are explicitly disabled, ensuring consistent behavior with
generate_tutorial and preventing tool-related differences in chat responses.
ℹ️ Review info
Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5aa95897-2f82-4c5e-b6bc-ac5ac589f5a6
📒 Files selected for processing (4)
crates/pika-news/src/main.rscrates/pika-news/src/model.rscrates/pika-news/src/storage.rscrates/pika-news/src/web.rs
Summary
generatingartifacts never recovering after service restart by adding startup recoveryerror_max_turnsby passing--tools ""and-pTest plan
ready=1, failed=0, retry=0🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Chores