Repository navigation
fix(yield): rescue sessions whose branch shipped past the session's window - #1476
Conversation
iamtoruk
left a comment
There was a problem hiding this comment.
Thanks for the careful writeup — the squash-merge half of this is a real gap and the tree-equality rule is the right shape for it. But the ancestry half misattributes badly on a real corpus, so I can't take it as it stands.
Your smoke run found no category changes because that corpus carries no branch metadata. Mine does. codeburn yield on 9,503 sessions, before → after:
Lifetime
- productive: $7,177.48 / 344 sessions → $14,147.11 / 944 sessions
- abandoned: $12,033.88 / 5,336 → $5,843.00 / 4,772
- ambiguous: $3,555.17 / 3,823 → $2,776.60 / 3,787
- 600 sessions rescued, $6,969.63 moved
30 days
- abandoned: $6,291.95 / 2,673 sessions → $602.11 / 2,228 — 90% of abandoned spend disappears
- productive: $4,815.90 / 197 → $10,647.29 / 659
The problem: 567 of the 600 rescues, $6,705.84 of the $6,970, come from one branch
exp/extraction-arms in one repo. Its ref:
- tip
973611ed, committed 2026-08-15 merge-basewith main IS the tip, so 0 commits of its own- the tip is a plain commit on main's first-parent line
It is a branch that was created (or left) pointing at an old main commit and never advanced. git branch --merged lists it, so the ancestry rule fires, so every session that ever recorded gitBranch: exp/extraction-arms becomes productive — forever, and regardless of when it ran.
All 567 of those sessions started after the branch's last commit, spanning 2026-08-17 to 2026-09-17. That repo's main tip is 12d52676, 2026-08-19 — main has not moved in a month. Five by cost:
| session | ran | cost | verdict |
|---|---|---|---|
| 56dea73b | 2026-08-29 → 09-02 | $1,584.46 | abandoned → productive |
| 8ce4b74e | 2026-09-02 → 09-17 | $893.49 | abandoned → productive |
| a2d08318 | 2026-08-17 → 08-19 | $458.54 | ambiguous → productive |
| 32e82536 | 2026-08-22 → 08-24 | $407.68 | abandoned → productive |
| 8dddb2e2 | 2026-08-19 → 08-22 | $395.49 | abandoned → productive |
Four of the five ran entirely after main stopped moving. Nothing they did could have shipped. $3,739.66 of dead work reported as shipped, from those five alone.
A smaller instance of the same thing in this repo: main-baseline, 0 own commits, tip c9ad778c on main's mainline — a ref someone parked for a before/after comparison. It rescues too.
Why the guard doesn't hold
sessionBranchShipped guards the squash rule with refOwnCommits and tree !== baseTree, and those guards are good. The ancestry rule has neither, and the comment reasons the guard away:
a merged branch and a ref parked inside main's history are the same topological object
Topologically yes. Semantically no. A merged branch contributed commits that are in main; a never-advanced branch contributed nothing and its tip is just an old main commit. Both have an empty base..ref, which is exactly why refOwnCommits can't separate them — but "indistinguishable by this metric" is not "equivalent".
tests/yield-branch-rescue.test.ts:147 pins this as intended: it creates feature-parked from main with no commits and asserts a rescue. That test asserts the bug.
The second issue, which survives even a perfect branch signal
The rule is per-branch, not per-session. One branch that shipped makes every session that ever touched it productive: the one that did the work, the one that opened the branch and did nothing, and the ten that ran on it months later. There is nothing tying a rescued session to the shipped work — no overlap between the session's window and the branch's commits, no check that the session predates the merge, nothing. The report even keeps commitCount: 0 on the rescued rows, so yield ends up claiming 944 productive sessions of which 600 have no commit behind them.
That's the part I'd want settled before the mechanism lands at all. Some evidence the session actually contributed — its turns overlapping commits that are on the branch, or at minimum the session ending before the branch's last commit — would cut both this and most of the parked-ref damage.
Smaller things
buildMergedBranchIndextakes the first matching candidate ref andbreaks. If a local ref exists but doesn't qualify, the remote-tracking ref is never examined, so a local stale copy of a branch whoseorigin/ref did merge silently loses the rescue. Collect the candidates instead of breaking.mainBranchis skipped twice, once in the builder and once insessionBranchShipped. One of them is dead.git log <main> --format=%Twalks all of main's history on every repo group that has any branch metadata. Fine here, worth knowing on a large monorepo.- Lifetime total drifts $22,766.53 → $22,766.71. Float accumulation order, harmless, but it means the total isn't bit-stable across this change.
What I'd keep
The tree-equality rule with its two guards is sound and it's the half that actually fixes #1442 — the reporter's case is a squash merge. If you dropped the ancestry rule entirely and shipped only tree equality plus a per-session contribution check, I think that lands.
Not a blocker, for the record: 6 cursor sessions flip abandoned → ambiguous between runs. I reproduced that main-against-main, so it's pre-existing, not yours.
Infra: tsc --noEmit clean, the 7 new tests and the existing yield suites pass on your branch.
87204ea to
03a5579
Compare
|
Reworked exactly on your line: ancestry is gone, and what remains is tree equality plus the per-session cut you asked for. The rule is now three conditions, all required:
Condition 3 is the one that kills both failure classes from your corpus:
On your read of the reporter's case: the squash half is what their workflow needs, and it's unchanged in substance from the version you reviewed (same two guards). The smaller findings, all fixed:
One honest limitation, stated rather than hidden: a session whose work was committed to the branch between sessions (work done in session A, The PR body still describes the old two-rule shape — I'll leave the thread as the record unless you want the body rewritten. 19/19 across the yield suites (7 fixture tests now: squash, parked-ref-no-rescue, late-session-no-rescue, window-overlap true-merge, multi-candidate refs, master repo, no-metadata), root |
…the window missed Sessions were labeled abandoned when no commit credited to them landed on main, but commits are credited by timestamp window, so a feature branch merged after the session ended - or merged as a GitHub squash, which lands the work under a brand-new SHA the window can never see - left fully shipped sessions reading as dead (getagentseal#1442). When the session logs record the git branch it ran on (Claude Code captures this per turn; most providers do not), yield now checks whether that branch demonstrably reached main, whenever that happened: - ancestry: everything at or below the branch ref is on main. A fully merged branch and a ref parked inside main's history are the same topological object post-merge, and both mean the state the session worked toward shipped; - tree equality: the branch carries commits of its own and its tip tree matches a main commit's tree - the squash signature - with the tip different from its base so an untouched or self-reverted branch cannot match. Abandoned and ambiguous sessions rescue to productive; reverted keeps its verdict, which already describes shipped-then-undone work. The rescue is confined to computeYield: sync attribution records keep the pure timestamp-window methodology, and the JSON methodology field is unchanged for compat. The CLI footer and README document the extension. Fixture tests cover squash, true merge after the window, unmerged branches, main itself, parked refs, master-based repos, and metadata-less sessions.
…idence plus a window-overlap cut Review on a 9,503-session corpus showed the ancestry half misattributing badly: 567 of 600 rescues (,705 of ,970) came from one parked ref whose tip is an old main commit - dead work reported as shipped - and the rule was per-branch, so any session that ever touched a shipped branch flipped productive with nothing tying it to the work. The ancestry rule is dropped entirely. The rescue is now the squash-merge tree signature alone, with the reviewer's per-session contribution cut: the branch must carry commits of its own, its tip tree must match a commit on main, and at least one of the branch's own commits must land inside the session's window. The parked-ref test now asserts no rescue; a late session on a shipped branch stays abandoned; a true-merge session whose window overlaps the branch's commits still rescues (the merge commit's tree is the branch tip's tree). Every matching ref becomes evidence instead of first-wins, so a stale local copy can no longer hide a merged remote-tracking ref, and the doubled main-branch skip is gone.
03a5579 to
3731d8a
Compare
Fixes #1442.
codeburn yieldlabeled a session abandoned when no commit credited to it landed on main — but commits are credited by timestamp window, so two completely normal workflows read as dead work:inMainis false forever.The fix: merged-branch evidence, on top of the window
When a session's logs record the git branch it ran on (per-turn
gitBranch— Claude Code captures this; most providers don't, and those sessions are simply unchanged), yield checks whether that branch demonstrably reached main, whenever that happened:git branch --merged). A fully merged branch and a ref parked inside main's history are the same topological object post-merge; both mean the state the session worked toward shipped.rev-list base..ref > 0) and its tip tree matches a main commit's tree; the squashed tree is byte-identical to the branch tip. The tip must differ from the branch's base tree, so an untouched branch or one that reverted itself back to its base cannot match.Scope guards, each pinned by a fixture test:
origin/<branch>) matches, so an unrelatedtopic/<branch>cannot;computeYield: sync attribution records (computeAttributionRecords) keep the pure timestamp-window methodology, and the JSONmethodology: "timestamp-window"field is unchanged for compat (sync OTLP sends it; the desktop mirror type pins it). The CLI footer and README document the extension honestly.Evidence
tests/yield-branch-rescue.test.tsdrive real temp git repos through the actual scenarios: squash-merge rescue (the reporter's case), true merge after the window, unmerged branch stays abandoned, main-branch exclusion, parked-ref semantics, amaster-based repository (main-branch resolution path), and metadata-less sessions untouched.tsc --noEmitclean.Known limits, stated rather than hidden: a branch deleted and pruned after merge leaves no ref to examine (no rescue); a squash-merged commit later reverted out is beyond what tree evidence can see. Both are documented in the tests/comments.