Skip to content

fix: worktree stale-registration bug + item-pipeline metadata panic - #550

Merged
getappz merged 3 commits into
masterfrom
fix/511-worktree-prune-stale-registration
Aug 18, 2026
Merged

fix: worktree stale-registration bug + item-pipeline metadata panic#550
getappz merged 3 commits into
masterfrom
fix/511-worktree-prune-stale-registration

Conversation

@getappz

@getappz getappz commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • create_worktree never pruned stale/broken git worktree registrations before reusing an existing branch — any item whose worktree was removed out-of-band (crash, manual cleanup) got permanently stuck: every dispatch attempt regenerated the identical "already checked out" failure forever. Now prunes before reuse, and execute_work_impl surfaces the real worktree_error instead of a hardcoded generic message.
  • persist_run_id panicked (cannot access key "workflow_run_id" in JSON string) whenever an item's metadata field was a non-object JSON value (confirmed live on item feat: migrate artifact storage onto agentflare-store documents+blobs + vent: origin routing, throttle, batched filing, judge-prompt hook #331 — a double-JSON-encoded string). Now coerces to an empty object defensively instead of trusting the caller-supplied value's shape.

Both root-caused and reproduced live against item #331 today, which hit both bugs back-to-back across ~10 dispatch attempts.

Test plan

  • cargo test -p flare-git-core — 190 passed
  • cargo test --bin agentflare worktree — 17 passed
  • cargo test --bin agentflare work_item_pipeline — 53 passed, 2 pre-existing unrelated ignores
  • Both new regression tests verified red (reproduce the exact live failure) without their fix, green with it
  • cargo fmt --check clean
  • cargo clippy --all-targets -- -A unsafe_code -A clippy::pedantic clean
  • Live-verified: rebuilt + installed the fixed binary, restarted the daemon, redispatched item feat: migrate artifact storage onto agentflare-store documents+blobs + vent: origin routing, throttle, batched filing, judge-prompt hook #331 — worktree creation now succeeds cleanly (previously failed deterministically every time)

Summary by CodeRabbit

  • Bug Fixes

    • Improved worktree recovery when stale Git registrations remain after a directory is removed.
    • Error messages for missing worktrees now include specific failure details when available.
    • Run IDs can now be saved even when existing metadata is not in the expected object format.
  • Tests

    • Added coverage for stale worktree recovery and non-object metadata handling.

…anch

create_worktree() only checked worktree_already_checked_out(), which
requires the on-disk directory to still exist. If a worktree dir was
removed out-of-band (crash, manual cleanup) while git's own
.git/worktrees/<slug>/ registration survived, the branch stayed
git-internally tied to the missing path, so git worktree add refused
to reuse it, and the failed add itself regenerated a fresh broken
registration -- every dispatch attempt reproduced the same failure
forever (confirmed live on item #331: three consecutive dispatches,
three identical failures).

Prune before reusing an existing branch so a stale registration never
survives to block it. Also surface the real worktree_error in
execute_work_impl instead of a hardcoded generic message, since the
underlying git failure was already captured but silently dropped.

Agentflare-Agent: claude-code_2-1-234_agent
Agentflare-Branch: fix/511-worktree-prune-stale-registration
…tem metadata

persist_run_id blindly cloned the item's existing metadata Value and
assigned a key into it via IndexMut. When metadata was corrupted into
a double-JSON-encoded string (confirmed live on item #331 -- the
literal string "{\"size\": \"M\"}" stored instead of the object
{"size": "M"}), parsing it produced Value::String(...), and IndexMut
panics assigning a key into anything that isn't already an object --
crashing the whole job with "cannot access key workflow_run_id in
JSON string" on every single dispatch attempt.

Coerce to an empty object when the existing value isn't already one,
instead of trusting its shape. Regression test verified red (exact
panic reproduced) without the fix, green with it.

Agentflare-Agent: claude-code_2-1-234_agent
Agentflare-Branch: fix/511-worktree-prune-stale-registration
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b6445955-5e9c-46ab-b259-4dd2cccef12c

📥 Commits

Reviewing files that changed from the base of the PR and between 167a91e and 111c046.

📒 Files selected for processing (1)
  • src/cli/work.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cli/work.rs

Included review availability: 0 reviews are currently available. Based on recent review activity, included reviews refill at 1 per hour.


📝 Walkthrough

Walkthrough

The PR prunes stale Git worktree registrations before branch checkout, includes detailed worktree errors in failure messages, and normalizes non-object metadata before persisting workflow run IDs. Regression tests cover worktree recreation and metadata persistence.

Changes

Worktree and metadata recovery

Layer / File(s) Summary
Stale worktree recovery
crates/flare-git-core/src/worktree.rs, crates/flare-git-core/src/worktree_tests.rs
create_worktree prunes stale registrations before checkout. The regression test verifies recreation after direct directory deletion.
Workflow metadata normalization
src/work_item_pipeline.rs, src/work_item_pipeline/tests.rs
persist_run_id converts non-object metadata to an empty object before storing workflow_run_id. The regression test verifies successful persistence.
Worktree error reporting
src/cli/work.rs
Missing-worktree failures now include worktree_error when available. Claim release, reporting, and fatal classification remain unchanged.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 111c0

The PR fixes two localized failure modes with regression coverage, and no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes both primary fixes: stale Git worktree registrations and item-pipeline metadata panics.
Description check ✅ Passed The description provides a detailed summary and test results, but it omits the optional Notes for reviewers section.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/511-worktree-prune-stale-registration

Comment @coderabbitai help to get the list of available commands.

…une-stale-registration

Agentflare-Agent: claude-code_2-1-234_agent
Agentflare-Branch: fix/511-worktree-prune-stale-registration
@getappz
getappz merged commit f4167ab into master Aug 18, 2026
17 checks passed
@getappz
getappz deleted the fix/511-worktree-prune-stale-registration branch August 18, 2026 12:20
getappz added a commit that referenced this pull request Aug 18, 2026
…554)

Fix #550 landed the claim["worktree_error"] handling in execute_work_impl
but shipped without a regression test at that call site. Add one that
drives execute_work_impl end-to-end through a real claim against a non-git
repo_root and asserts the posted comment carries the server's detail
instead of falling back to the generic "(bad git state?)" message.

Split into a sibling file (work.rs is frozen at the LOC gate's limit).

Agentflare-Agent: claude-code
Agentflare-Branch: task/154-execute-work-impl-worktree-error-test
Agentflare-Item: 154

Co-authored-by: shiva <shiva@gosysinfo.tech>
getappz pushed a commit that referenced this pull request Aug 22, 2026
… returns None

item::get failing to read the item back immediately after its own claim
acquired it left worktree_error unset, so execute_work_impl (already
fixed in #550/#554 to display worktree_error) had nothing to show and
fell back to the generic "bad git state?" guess for this one case.
resolve_target_branch is infallible, so this arm is only reachable via
that item::get failure.

Agentflare-Agent: claude-code
Agentflare-Branch: task/153-execute-work-impl-discards-claim-s-workt
Agentflare-Item: 153
getappz added a commit that referenced this pull request Aug 22, 2026
… returns None (#586)

item::get failing to read the item back immediately after its own claim
acquired it left worktree_error unset, so execute_work_impl (already
fixed in #550/#554 to display worktree_error) had nothing to show and
fell back to the generic "bad git state?" guess for this one case.
resolve_target_branch is infallible, so this arm is only reachable via
that item::get failure.

Agentflare-Agent: claude-code
Agentflare-Branch: task/153-execute-work-impl-discards-claim-s-workt
Agentflare-Item: 153

Co-authored-by: shiva <shiva@gosysinfo.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant