buzz icon indicating copy to clipboard operation
buzz copied to clipboard

fix(acp): preserve truncated thread context

Open cameronhotchkies opened this issue 4 months ago • 0 comments

Why

Long Buzz threads were rendered as [Thread Context (13 of 13 messages)] because the harness counted only the already-limited query result. That hid older context and could also hide the agent's own prior reply in busy threads.

What

  • Fetch one extra thread reply as a sentinel so truncated context is labeled correctly.
  • Use a best-effort /count call for improved truncated totals when available, clamped to the sentinel-proven minimum so racy counts cannot render impossible labels.
  • Keep the /count path single-attempt with a short timeout and only add the root to exact totals when the root was actually fetched.
  • Fetch and preserve the agent's newest prior reply when it falls outside the recent window, with exact event-id matching for the pin/dedup boundary.
  • Add parser and fetch-boundary tests for truncation, exact count, missing root, count-below-minimum clamping, count failure fallback, distinct fetched-reply lower bounds, agent-reply dedup/pinning, and serialized query/count filter semantics.

Risk Assessment

Low-to-medium — limited to buzz-acp prompt context fetching and a small RestClient helper. If /count fails or times out, the code falls back to the sentinel-derived minimum total rather than failing the prompt. The synchronous /count happens only for truncated thread contexts and is bounded to one short best-effort attempt.

References

  • Buzz thread: chotchkies-buzz-bombing-flakes / 7ef71407f1c7a642382c7e48e0c80fb6ca66948890e04d1eb6f1408c3b7278b1
  • Validation at c1cfd1b16a04a3ac1d1d0d3cf43e1a08508f3532:
    • cargo fmt -p buzz-acp ✅
    • cargo test -p buzz-acp test_fetch_thread_context -- --nocapture ✅ (6 tests)
    • cargo test -p buzz-acp parse_nostr_thread_response ✅
    • cargo test -p buzz-acp ✅ (649 unit + 9 lifecycle tests)
    • git diff --check ✅
    • Push was completed with --no-verify after pre-push hooks reached non-code local environment failures: flutter missing for mobile-test; Node.js v20.20.2 too old for pnpm/node:sqlite in desktop-check and desktop-test. Earlier hook stages passed: check-push-org, branch-skew, rust-tests, test, desktop-tauri-checks.
  • Earlier full ./bin/just ci at 622ed7eb8807d64e06209101569b1013414af091 ⚠️ passed Rust/desktop/web stages, then failed in mobile-test on unrelated existing mobile test ChannelDetailPage keeps follow mode off while a tall newest message stays visible; rerunning that single mobile test reproduced the same failure without touching mobile code.

Generated with Codex

cameronhotchkies avatar Jul 28 '26 17:07 cameronhotchkies