Skip to content

fix: Claude DAG fork detection traverses full subtree#231

Merged
wesm merged 2 commits intomainfrom
fix-dag-fork-undercount
Mar 25, 2026
Merged

fix: Claude DAG fork detection traverses full subtree#231
wesm merged 2 commits intomainfrom
fix-dag-fork-undercount

Conversation

@wesm
Copy link
Copy Markdown
Owner

@wesm wesm commented Mar 25, 2026

Summary

  • countUserTurns now traverses the full subtree (stack-based DFS) instead of following only the first child at each node. The old approach undercounted user turns in sessions with nested forks, causing the fork heuristic to discard large conversation branches as "small retries."
  • Bumps dataVersion to 6 so existing databases trigger a full resync on upgrade.

Context

Sessions with many nested fork points (e.g. 17 in the reported case) would have their main conversation branch dropped entirely. The first-child-only traversal would dead-end after 0-1 user turns at nested forks, making a 124-entry branch look like a trivial retry. Result: a session with 110 real messages would show only 11.

Test plan

  • New regression test TestForkDetection_NestedForkCountsFullSubtree covers the specific scenario
  • All existing fork detection tests pass
  • Full test suite passes (go test -tags fts5 ./... -short)
  • Manual test: verify the affected session displays all messages after upgrade

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

wesm and others added 2 commits March 25, 2026 06:32
countUserTurns previously followed only the first child at each node
to count user turns. In sessions with nested forks, the first-child
path could dead-end quickly (e.g. after 0-1 user turns), making the
algorithm treat large conversation branches as small retries and
discarding them.

Now uses a stack-based traversal to count all reachable user entries
in the subtree, correctly identifying large branches that should be
preserved as the main conversation path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The countUserTurns fix changes how forked sessions are parsed,
so existing databases need a full resync to pick up the corrected
message content.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@roborev-ci
Copy link
Copy Markdown

roborev-ci bot commented Mar 25, 2026

roborev: Combined Review (162c5fb)

Summary Verdict: All
reviews passed successfully with no medium or higher severity issues found.


Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

@wesm wesm changed the title fix: DAG fork detection traverses full subtree fix: Claude DAG fork detection traverses full subtree Mar 25, 2026
@wesm wesm merged commit aa9440c into main Mar 25, 2026
7 checks passed
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