I'm seeing this as part of the rebuild step of reconstruct and clone. I haven't tried "fossil rebuild". With "fossil clone", the stack nesting is deep enough to hit the stack limit. Backtrace starts with a few thousand content_get and ends with a few thousand of:

#14478 0x000000000040d6a0 in after_dephantomize (rid=25789, linkFlag=1) at content_.c:361

I can't share this repository, but the problematic part is a single file that has ~3000 commits, incrementally extending it. Think of a ChangeLog if you want.

I think the best approach here is to avoid deep recursions by limiting the length of a delta chain. What do you think about storing the start and depth of the delta chain with each delta and introducing an on-disk content cache to cut it when it reaches a specific limit. Phantoms could be processed as forward process without recursion by using a small todo bag.