Skip to content

Keep post-turn compaction pending while idle - #1542

Merged
ymichael merged 2 commits into
mainfrom
bb/investigate-thread-timeline-issue-thr_3fidu4qwcd
Aug 18, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/investigate-thread-timeline-issue-thr_3fidu4qwcd

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Summary

  • keep Pi-style automatic compaction pending after its owning turn completes while the thread is idle
  • allow the later explicit compaction event to settle the row as completed
  • preserve interruption behavior when the thread receives a real interruption event

Testing

  • pnpm exec turbo run test --filter=@bb/thread-view --force
  • pnpm exec turbo run typecheck --filter=@bb/thread-view
  • pnpm exec prettier --check packages/thread-view/src/event-projection-state.ts packages/thread-view/test/timeline-interruption.test.ts
  • git diff --check

AGENT GENERATED: by GPT-5

@bb-slop-cop

bb-slop-cop Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am SlopCop. I am reviewing this pull request now.

I will check security, code quality, performance, architecture, duplication, and relevant tests. I will post one final review after the checks finish.

// interruption settles it.
if (
args.options?.threadStatus === "idle" &&
args.state.threadInterruptedAt === null &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — A past interruption stops a later compaction

threadInterruptedAt records all prior interruptions and never clears. After any old interruption, this condition stays false for later turns. The finalizer then changes a valid later compaction from pending to interrupted. I reproduced this with interrupted turn A, completed turn B, and turn B compaction. Track the event order, and add a two-turn regression test.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

ELI5

The code remembers an old stop sign forever. It then stops a new cleanup job. It is like ending today’s game because yesterday’s game ended.

Finding

  • Medium — An old interruption stops a later compaction. threadInterruptedAt remains set after an earlier interruption. A later valid compaction then fails the new condition and becomes interrupted. I reproduced this with interrupted turn A, completed turn B, and turn B compaction. Track the event order, and add this two-turn regression test.

Review results

  • The security and quality reviews found the same state defect.
  • The performance review proposed a timer risk. The final gate rejected it because no production path proved repeated missing terminal events.
  • The architecture scan found no duplicate compaction rule to reuse. The central finalizer is the correct location, but the condition needs interruption order.
  • All 370 @bb/thread-view tests passed. The Turbo type check, Prettier check, and git diff --check passed.
  • The dev app loaded in Chromium without page errors. The clean dev database had no Pi event history, so the browser check could not reproduce this event sequence.

The GPT-5.6 review gate did not clear the change because of the medium defect. I posted this as a comment-only review.

Settle open compactions when the interruption event is processed instead of consulting sticky thread interruption state during finalization. This keeps later post-turn compactions pending and records the real interruption completion time.

Builds on Michael Yong's original post-turn compaction fix in 1da548c.
@ymichael
ymichael force-pushed the bb/investigate-thread-timeline-issue-thr_3fidu4qwcd branch from 1da548c to f1efed2 Compare August 18, 2026 06:51
@ymichael
ymichael merged commit a108fa7 into main Aug 18, 2026
10 checks passed
@ymichael
ymichael deleted the bb/investigate-thread-timeline-issue-thr_3fidu4qwcd branch August 18, 2026 06:58
SawyerHood added a commit that referenced this pull request Aug 21, 2026
Pi's threshold compaction runs after agent_end and attaches its
contextCompaction item to the turn that just closed, with no second
turn/completed (#1542). isRootTurnWorkItem counted it as root work, so
every compacted pi thread flipped active and stayed there until a stop.
Compaction is provider maintenance, not agent work; exclude it at the
one shared rule so the server status, the daemon grammar, and the
runtime active-turn state all agree.

The server reopen check memoizes thread rows per event batch and evicts
a row whenever the loop applies a lifecycle change, so root items on an
active thread cost one lookup per thread rather than one per item. The
root turn/started lookup is inlined because main removed the unused
@bb/db helper in #2140.

Co-Authored-By: Claude <[email protected]>
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