fix(automation): poll artifact_glob after wait_for_idle settles (fixes #120) - #121
fix(automation): poll artifact_glob after wait_for_idle settles (fixes #120)#121bketelsen wants to merge 5 commits into
Conversation
The post-step artifact capture in the wait_for_idle = true branch was a single-shot check after a 2s sleep. wait_for_agent_idle can return as soon as the runtime adapter detects a completion signal (Claude Code emits this at end-of-turn), which can fire before the agent's last file write is flushed to disk — or before the agent has even started writing the file referenced in its final response. Replace the sleep+check with a bounded polling loop (1s cadence, window = max(wait_timeout_secs / 30, 5s)..60s). The artifact-polling mode branch (active when wait_for_idle = false) already uses this pattern at lines 1080-1255; this aligns the wait_for_idle = true path with that proven approach. Fixes nutthouse#120
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughPrompt-step post-idle artifact capture was changed from a fixed 2s sleep + single capture attempt to a bounded polling retry. A per-step poll window (clamped to 5–60s) is computed once and used across early-success and normal post-step capture paths; new tests cover polling and clamp behavior. ChangesPost-idle artifact polling
Sequence Diagram(s)sequenceDiagram
autonumber
actor Agent
participant Automation
participant Filesystem
note over Agent,Filesystem: Agent may emit completion before file is flushed
Agent->>Automation: runtime completion signal (wait_for_idle satisfied)
Automation->>Automation: compute post_idle_poll_secs
Automation->>Filesystem: attempt capture_artifact (via capture_artifact_with_poll)
alt artifact not present
Automation->>Filesystem: sleep 1s, retry capture
loop until deadline
Automation->>Filesystem: attempt capture_artifact
end
end
Filesystem-->>Automation: artifact path (on success) / error (on deadline)
Automation->>Automation: store artifact or mark step failed
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/automation/mod.rs`:
- Around line 1714-1745: The polling loop that retries capture_artifact with a
bounded deadline should be extracted into a small helper (e.g.,
poll_capture_artifact or try_capture_with_poll) that accepts (pre_snap,
expanded_pattern, art_name, post_idle_poll_secs, optionally poll_interval) and
returns Result<PathBuf, Error>; implement its logic using
step_wait_timeout-derived post_idle_poll_secs, a 1s poll_interval, poll_deadline
and poll_start as in the new block, retrying capture_artifact until success or
deadline. Replace the inline loop in the new post-idle block with a call to this
helper and also call the same helper from both early-success implement_code
artifact-capture branches (the places that currently do a single
capture_artifact() after a fixed 2s sleep) so all three paths use the same
bounded polling behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c126a42f-c5f0-4929-aeb6-80f6116cf794
📒 Files selected for processing (1)
src/automation/mod.rs
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/automation/mod.rs`:
- Around line 1565-1586: The current early-exit block uses chained `&& let
Ok(...)` patterns for `capture_artifact_with_poll` and `store_artifact_output`
(referenced symbols: artifact_pre_snapshot, artifact_name,
capture_artifact_with_poll, store_artifact_output, output_files, outputs) which
swallows failures and still lets the step be recorded as successful; change this
so that when an artifact is required (artifact_pre_snapshot and artifact_name
present) any error from `capture_artifact_with_poll` or `store_artifact_output`
is not ignored but causes the step to fail or the error to be returned: replace
the chained `&& let Ok(...)` with explicit match/if let handling that on Err
either returns/propagates the error or sets the step status to failure, and only
inserts into `output_files`/`outputs` when both calls succeed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b0d9f3e0-af4c-47de-97b0-05c3b9fa541a
📒 Files selected for processing (1)
src/automation/mod.rs
Closes #120.
What
Replaces the single-shot
sleep(2s) + capture_artifact()in thewait_for_idle = truepost-step block with a bounded polling loop (1s cadence, window =max(wait_timeout_secs / 30, 5s)..60s).Why
wait_for_agent_idlereturnscompletedas soon as the runtime adapter detects a completion signal (Claude Code emits this at end-of-turn). That can fire before the agent's last file write is flushed to disk — or before the agent has even started writing the file referenced in its final response. Two seconds of slack isn't always enough.The artifact-polling-mode branch (
wait_for_idle = false) already implements this pattern atsrc/automation/mod.rs:1080-1255. This PR aligns thewait_for_idle = truepath with that proven approach.Test
cargo check— greencargo test --bin tt automation::tests— 34/34 passDESIGN.mdshortly after the completion signal.Backward compatibility
Pure widening: anything that succeeded under the old 2s sleep still succeeds (the loop's first iteration is the same check). Anything that failed under the 2s sleep now gets up to 60s to materialize.
Repro details and root-cause writeup in #120.
Summary by CodeRabbit
Bug Fixes
Tests