Skip to content

fix(threads): keep a read bot read through compactions and stops - #982

Queued
klNuno wants to merge 1 commit into
mainfrom
boite/wt-nchkkcx6
Queued

klNuno wants to merge 1 commit into
mainfrom
boite/wt-nchkkcx6

Conversation

@klNuno

@klNuno klNuno commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Problem

A bot the owner had read lit up again as "1 new answer" with nothing new in it. In a live journal, over 3 days, 14 of 77 read-to-unread flips on bot threads came from compact turns: the cache-expiry compaction about an hour after the bot's last answer. 3 more came from turns stopped by a core restart.

Turn settlement treated only keepalives and quiet wakes as silent. The bot unread count (countUnread) and notifiesOnFinish already ignored compactions, keepalives and turns that were neither done nor failed, so the row showed max(1, 0) = 1 for a thread marked unread by housekeeping.

Change

  • turnIsNews in packages/contracts/src/turns.ts: a done or failed turn, not a compaction or keepalive, not a quiet done wake.
  • Turn settlement marks a thread unread only for news; countUnread, notifiesOnFinish (same results as before) and the fake client use the same rule.
  • docs/bots.md says what counts as unread.

Coordination, delegation, routine and event answers still count as news.

Verified

  • New test a thread read before its compaction or a stop stays read: neither is news in packages/core/test/compact.test.ts fails on main at both its compaction and stop assertions, passes here.
  • bun run check: exit 0.
  • 71 core test files that touch unread, stops or notifiesOnFinish, one process each: 70 pass. In compact.test.ts, resolved driver and idle policies... hits the 5 s timeout on the loaded dev box the same way on main, and passes with --timeout 30000.
  • 25 UI vitest files that touch unread: 499 pass.
  • Reviewed by GPT-6.1 Sol: 1 round, approved.

No visual change.

Turn settlement marked a thread unread after any turn but a keepalive or a quiet wake, so the cache-expiry compaction an hour after a bot's answer lit it up again with nothing new. turnIsNews now decides unread, the bot unread count and notifications alike: an answer or a failure, never a compaction, a keepalive, a quiet wake or a stop.
@github-actions github-actions Bot added documentation Improvements or additions to documentation core packages/core and packages/contracts ui packages/ui labels Nov 7, 2026
@klNuno
klNuno marked this pull request as ready for review November 7, 2026 22:41

@mtsu-patrol mtsu-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

@mtsu-patrol

mtsu-patrol Bot commented Nov 8, 2026

Copy link
Copy Markdown

This pull request stops read bot threads from flipping back to unread after hourly cache compactions, keepalives, quiet wakes, or stopped turns. Only a finished answer or failure now marks a thread unread, matching what the unread count already ignored.

No comments posted: the reviewers raised no finding.

Review details
  • Model: muse-spark-1.3-contributor
  • Compared commits: 71745c4 to 66882c8
  • Execution: tests could run in a disposable Linux sandbox
  • Files reviewed: 6 of 6
  • Duration: 3 min 53 s
Commands run (11)

Installed deps (bun install exit 0). Attempted core compact.test.ts via bun test runner but it was killed/timed out under the 3-min/1GB sandbox limit, so the PR's new regression test and full core/UI suites could not be verified here. Inspected changed files: turnIsNews in packages/contracts/src/turns.ts now gates unread/notification on done/error excluding compact/keepalive and quiet done wakes, with store.ts, turn-settlement.ts and fake-client wired to it; no failure attributable to the change was reproduced.

passed · exit 0 · 0 s

ls -R /work | head -n 100; echo "---"; cat /work/package.json | head -n 120

passed · exit 0 · 0 s

cat /work/packages/core/package.json; echo "---CORE_SCRIPTS---"; cat /work/packages/contracts/package.json; echo "---UI---"; cat /work/packages/ui/package.json | head -n 80

passed · exit 0 · 5 s

bun install --frozen-lockfile 2>&1 | tail -n 20
echo "EXIT:$?"

timed out · 3 min

bun run --cwd packages/core test test/compact.test.ts 2>&1 | tail -n 80; echo "EXIT:${PIPESTATUS[0]}"
signal: killed

passed · exit 0 · 0 s

cat packages/core/package.json | head -n 60; echo "---"; ls packages/core/test/compact* 2>&1; echo "---"; wc -l packages/core/test/compact.test.ts packages/contracts/src/turns.ts packages/core/src/threads/turn-settlement.ts
timeout 10 bun --version; echo OK

passed · exit 0 · 1 s

git diff HEAD~1 --stat 2>&1 | head -n 30; echo "==="; git log --oneline -5 2>&1 | head -n 10
echo "---TEST_RUNNER---"; head -n 80 packages/core/bin/test.ts
echo "---TURNS---"; cat packages/contracts/src/turns.ts

passed · exit 0 · 0 s

git log --oneline -5; echo "==="; git diff HEAD~1 --stat
echo "===runner==="; wc -l packages/core/bin/test.ts; head -n 120 packages/core/bin/test.ts

passed · exit 0 · 0 s

git diff HEAD~1 -- packages/contracts/src/turns.ts packages/core/src/threads/turn-settlement.ts packages/core/src/agents/store.ts packages/ui/src/lib/fake-client/turns.ts docs/bots.md
echo "===NEWTEST==="; git diff HEAD~1 -- packages/core/test/compact.test.ts

passed · exit 0 · 0 s

cat packages/contracts/src/turns.ts | head -n 140
echo "===DOC==="; git diff HEAD~1 -- docs/bots.md

passed · exit 0 · 0 s

cat packages/contracts/src/turns.ts | tail -n +135 | head -n 100
echo "===SETTLE==="; cat packages/core/src/threads/turn-settlement.ts
echo "===FAKE==="; cat packages/ui/src/lib/fake-client/turns.ts | head -n 120

passed · exit 0 · 0 s

grep -n "turnIsNews\|notifiesOnFinish\|countUnread" packages/contracts/src/turns.ts; echo "==="; sed -n '130,219p' packages/contracts/src/turns.ts
echo "===SETTLE_HEAD==="; sed -n '1,90p' packages/core/src/threads/turn-settlement.ts

@klNuno
klNuno added this pull request to the merge queue Nov 8, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 8, 2026
@mtsu-patrol
mtsu-patrol Bot added this pull request to the merge queue Nov 8, 2026
Any commits made after this event will not be merged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core packages/core and packages/contracts documentation Improvements or additions to documentation ui packages/ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant