feat(relay): add opt-in newest-first thread windows - #7823
Conversation
🔐 Codex Security Review
|
wpfleger96
left a comment
There was a problem hiding this comment.
🤖 hey @kalvinnchau, thanks for this. We did two independent source reviews plus a local E2E run against a real relay at 54c472a. Most of it held up well: strict opt-in parsing, legacy isolation, the mixed-direction cursor math, predicates applied before limit + 1, raw scan cursors surviving reconstruction failures, the replica upper-bound check plus two-hop restart, and the bounded migration with concurrent prebuild validation. The live run passed all four reply kinds, same-second ties across four pages with concurrent edits/deletes/new replies, independent verification of the 39007 signature and binding, the depth limits, and legacy compatibility.
I think three things need fixing before merge, and there are a few smaller items. Details are inline:
- A batched
/querycan still return an earlier window's private rows and signed bounds after a later window in the same request has seen the reader's access revoked. We reproduced this live three times. - The aux byte budget only applies after
fetch_all()has already loaded up to 1,001 full payloads (this is allocation math from the source, not a measured OOM). - A root whose kind isn't in
ROW_KINDSgets a signedhas_more: falsewith no rows, even when replies exist.
Smaller items: @> tag matching ignores position, budget exhaustion returns an opaque 500, and NIP-CW still doesn't document the legacy oldest-first thread path.
Not covered by the live run: physical replica lag/failover, a production-scale migration/load test, and any desktop/mobile adoption.
Keep legacy traversal isolated; bind signed bounds to normalized requests, authorize metadata before selection, and fail closed on incomplete auxiliary closure. Preserve reader sessions and bounded writer degradation. Add a validated mixed-direction index and deployment/rollback guidance. Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
Bypass write-conflicting index creation on the validated prebuild path. Compare complete access sets across auxiliary closure, preserve ordered exact-key lookups under stale statistics, and classify production database timeouts as retryable. Add falsifiable regressions and document measured costs and validation limits. Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
Remove the diagnostic-only timing test and duplicated corruption/setup paths. Keep the authenticated router, production-pool timeouts, migration locks and replica/access transition controls. Strengthen predicate-before-limit coverage with dense rejected candidates and reduce protocol documentation repetition. Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
Consolidate the newest-first thread-window contract under NIP-CW thread mode while preserving channel mode, legacy thread behavior, kind 39007, and all production paths. Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
Clarify protocol fallback versus shipped client scope, correct channel-mode references and checklist requirements, restore ordinary relay-only kind coverage, and preserve migration 0048 bytes from the prior candidate. Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
Reduce the thread-mode addition to its wire contract, relay algorithm, compatibility rules, bounded consistency model, and migration requirement. Remove review-era implementation detail while preserving normative behavior. Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
Retain relay processing because it defines the window response semantics. Remove replica, resource-budget, and deployment procedures from the protocol while preserving the frozen migration-reference note. Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
Point the unshipped migration at NIP-CW and remove the checksum-history note. The migration has never been merged or deployed, so no candidate checksum compatibility is required. Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
Update the embedded migration regression after origin/main claimed version 48 and the thread-window migration moved to version 49. Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
Authorize thread-window batches before releasing any accumulated output. Stream auxiliary rows under a shared payload budget, require positional target tags, distinguish exhaustion from corruption, and suppress bounds for unsupported roots. Cover the review cases and document legacy paging. Co-authored-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: Kalvin Chau <kalvin@block.xyz> Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
54c472a to
d572708
Compare
Share the raw payload allowance across replies, auxiliary scans and retries. Charge reply probes before reconstruction and cover maximum-size signed replies, early rejection, smaller-page recovery and batch accounting. Signed-off-by: cid <d9f92a72922bf45c17379a47d64dae84b6020397c2d5a52b5317d512068cd9d3@buzz.block.builderlab.xyz>
wpfleger96
left a comment
There was a problem hiding this comment.
🤖 Re-reviewed at 0964ed71fe605daf9a700013a41eae8c6fc429ab. All six earlier comments are addressed, so I'm approving.
We checked it two ways again. There was an independent source pass over d57270876 and 0964ed71f and the paths they touch. There was also a live rerun against an isolated relay built from this head, using only signed network operations. In the batch-revocation race, 36 attempts across the same-channel and different-channel variants came back as 11 clean 503s and 25 complete two-bounds 200s. None returned a partial response. The live run also covered the 40008 root (no bounds, with or without aux), 40 edits at exactly 256 KiB (a 503 with the reduce-work message, and aux-off recovers), both positional-tag lookalikes excluded, the shared reply/aux/batch budget, and the earlier journey/boundary regressions. CI at this head is green.
One small thing: the PR body still says 54c472a is the current head, so the runtime receipts there describe the old revision. It's worth refreshing before merge.
…rcement * origin/main: fix: route databricks claude fqns to anthropic messages (#7829) feat(relay): add opt-in newest-first thread windows (#7823) refactor: move agent Git bootstrap into ACP harness (#7819) Use worker snapshots for relay storage metrics (#7845) Signed-off-by: Hayt <211b96e6a2b7f45fd4047988976c7bbbeeda0c15f3ae7b32eec20834b5a55118@buzz.block.builderlab.xyz>
…erative-labels * origin/main: fix: route databricks claude fqns to anthropic messages (#7829) feat(relay): add opt-in newest-first thread windows (#7823) refactor: move agent Git bootstrap into ACP harness (#7819) Use worker snapshots for relay storage metrics (#7845) fix(hooks): strip repo-local git env from pre-push test lanes (#7841) Signed-off-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
…in-gate * origin/main: (30 commits) feat(agents): humanize uncurated Databricks model ids with a label grammar (#7844) fix: route databricks claude fqns to anthropic messages (#7829) feat(relay): add opt-in newest-first thread windows (#7823) refactor: move agent Git bootstrap into ACP harness (#7819) Use worker snapshots for relay storage metrics (#7845) fix(hooks): strip repo-local git env from pre-push test lanes (#7841) fix(mobile-infra): render push grant lifetimes as decimal in chart 0.3.2 (#7820) fix(agent): preserve Databricks Opus UC reasoning and tool continuation (#7840) feat(canvas): add version history with atomic restore (#6780) chore(release): release Buzz Desktop version 0.5.24 (#7817) test(desktop): stabilize unread and audio release smoke fixtures (#7821) fix(desktop): remember Inbox unread-only choice (#7672) feat(mobile-infra): support development App Attest (#7744) docs(nip-fi): clarify federated identity amendments (#7803) fix(desktop): refresh channels after access-revoked closure (#7784) fix(desktop): bound startup request bursts and recover quota refusals (#7790) fix(audit): frame hash inputs with TLV (#7492) fix(admin): allow cold storage worker DB startup (#7770) feat(relay): add admin HTTP routes for member restriction management (#7302) fix(relay): fire kick live side effects at convergence; persist target; fence re-add race with held lock (#7298) ... Signed-off-by: coder 1 <a93f3b1decd199cec83848f116ff60c20776cdd03861b9bba2610acae7c9eeeb@buzz.block.builderlab.xyz>
* origin/main: feat(agents): humanize uncurated Databricks model ids with a label grammar (#7844) fix: route databricks claude fqns to anthropic messages (#7829) feat(relay): add opt-in newest-first thread windows (#7823) refactor: move agent Git bootstrap into ACP harness (#7819) Use worker snapshots for relay storage metrics (#7845) fix(hooks): strip repo-local git env from pre-push test lanes (#7841) fix(mobile-infra): render push grant lifetimes as decimal in chart 0.3.2 (#7820) fix(agent): preserve Databricks Opus UC reasoning and tool continuation (#7840) feat(canvas): add version history with atomic restore (#6780) chore(release): release Buzz Desktop version 0.5.24 (#7817) test(desktop): stabilize unread and audio release smoke fixtures (#7821) fix(desktop): remember Inbox unread-only choice (#7672) feat(mobile-infra): support development App Attest (#7744) docs(nip-fi): clarify federated identity amendments (#7803) fix(desktop): refresh channels after access-revoked closure (#7784) fix(desktop): bound startup request bursts and recover quota refusals (#7790) fix(audit): frame hash inputs with TLV (#7492) fix(admin): allow cold storage worker DB startup (#7770) Signed-off-by: Michael Neale <michael.neale@gmail.com>
…n-surface * origin/main: fix(ci): consume the published MinIO image (#7870) fix(mobile): converge sidebar managers on relay head with resume re-read (#7806) fix(ci): bootstrap the reusable MinIO image in GHCR (#7869) Discover alternate Buzz ACP commands (#6948) fix(hooks): surface nextest failures and stale pnpm deps in pre-push (#7850) feat(acp): run one prepared task from a file or stdin (#7851) Fix mobile heart and warning emoji with native font fallback (#7842) chore(mesh): upgrade MeshLLM to 0.76.2 (#7559) feat(agents): humanize uncurated Databricks model ids with a label grammar (#7844) fix: route databricks claude fqns to anthropic messages (#7829) feat(relay): add opt-in newest-first thread windows (#7823) refactor: move agent Git bootstrap into ACP harness (#7819) Use worker snapshots for relay storage metrics (#7845) fix(hooks): strip repo-local git env from pre-push test lanes (#7841) fix(mobile-infra): render push grant lifetimes as decimal in chart 0.3.2 (#7820) Signed-off-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
…undation-local * origin/main: (50 commits) feat(desktop): relay admin console for the /api/admin/v1 operator surface (#4768) fix(mobile): keep retired sections manager out of successor cache (#7873) Select one feature flag provider at compile time (#7677) chore(release): release Buzz Desktop version 0.5.25 (#7867) fix(ci): consume the published MinIO image (#7870) fix(mobile): converge sidebar managers on relay head with resume re-read (#7806) fix(ci): bootstrap the reusable MinIO image in GHCR (#7869) Discover alternate Buzz ACP commands (#6948) fix(hooks): surface nextest failures and stale pnpm deps in pre-push (#7850) feat(acp): run one prepared task from a file or stdin (#7851) Fix mobile heart and warning emoji with native font fallback (#7842) chore(mesh): upgrade MeshLLM to 0.76.2 (#7559) feat(agents): humanize uncurated Databricks model ids with a label grammar (#7844) fix: route databricks claude fqns to anthropic messages (#7829) feat(relay): add opt-in newest-first thread windows (#7823) refactor: move agent Git bootstrap into ACP harness (#7819) Use worker snapshots for relay storage metrics (#7845) fix(hooks): strip repo-local git env from pre-push test lanes (#7841) fix(mobile-infra): render push grant lifetimes as decimal in chart 0.3.2 (#7820) fix(agent): preserve Databricks Opus UC reasoning and tool continuation (#7840) ... Signed-off-by: tornquist <tornquist@squareup.com>
…t/osc-event-write-chokepoint * commit 'a6a3032e446e6e66e8e41a229ef655ea79f36202': (50 commits) feat(desktop): relay admin console for the /api/admin/v1 operator surface (#4768) fix(mobile): keep retired sections manager out of successor cache (#7873) Select one feature flag provider at compile time (#7677) chore(release): release Buzz Desktop version 0.5.25 (#7867) fix(ci): consume the published MinIO image (#7870) fix(mobile): converge sidebar managers on relay head with resume re-read (#7806) fix(ci): bootstrap the reusable MinIO image in GHCR (#7869) Discover alternate Buzz ACP commands (#6948) fix(hooks): surface nextest failures and stale pnpm deps in pre-push (#7850) feat(acp): run one prepared task from a file or stdin (#7851) Fix mobile heart and warning emoji with native font fallback (#7842) chore(mesh): upgrade MeshLLM to 0.76.2 (#7559) feat(agents): humanize uncurated Databricks model ids with a label grammar (#7844) fix: route databricks claude fqns to anthropic messages (#7829) feat(relay): add opt-in newest-first thread windows (#7823) refactor: move agent Git bootstrap into ACP harness (#7819) Use worker snapshots for relay storage metrics (#7845) fix(hooks): strip repo-local git env from pre-push test lanes (#7841) fix(mobile-infra): render push grant lifetimes as decimal in chart 0.3.2 (#7820) fix(agent): preserve Databricks Opus UC reasoning and tool continuation (#7840) ... Signed-off-by: tornquist <tornquist@squareup.com> # Conflicts: # crates/buzz-db/src/store/event.rs
…ction * origin/main: (21 commits) docs(vision): add /buzz/v1 read endpoints to the protocol contract (#7879) 🤖 fix(justfile): point just staging at the current staging relay (#7881) fix(relay-admin): make thread deletions atomic and fence expired action leases under row lock (#7853) feat(desktop): relay admin console for the /api/admin/v1 operator surface (#4768) fix(mobile): keep retired sections manager out of successor cache (#7873) Select one feature flag provider at compile time (#7677) chore(release): release Buzz Desktop version 0.5.25 (#7867) fix(ci): consume the published MinIO image (#7870) fix(mobile): converge sidebar managers on relay head with resume re-read (#7806) fix(ci): bootstrap the reusable MinIO image in GHCR (#7869) Discover alternate Buzz ACP commands (#6948) fix(hooks): surface nextest failures and stale pnpm deps in pre-push (#7850) feat(acp): run one prepared task from a file or stdin (#7851) Fix mobile heart and warning emoji with native font fallback (#7842) chore(mesh): upgrade MeshLLM to 0.76.2 (#7559) feat(agents): humanize uncurated Databricks model ids with a label grammar (#7844) fix: route databricks claude fqns to anthropic messages (#7829) feat(relay): add opt-in newest-first thread windows (#7823) refactor: move agent Git bootstrap into ACP harness (#7819) Use worker snapshots for relay storage metrics (#7845) ... Signed-off-by: Tom Brow <tomb@block.xyz>
Summary
Add an opt-in, newest-first thread window to the authenticated HTTP query path.
A filter with
thread_window: truereturns:(created_at DESC, id ASC)with an exact composite cursor;kind:39007bounds event bound to the normalized host, authenticated reader, channel, root, request cursor, kinds, depth, limit, and aux choice.Filters without the flag keep the existing oldest-first thread behavior. Channel windows and
kind:39006are unchanged. No client opts into this mode in this PR.Why extend NIP-CW
NIP-CW already defines relay-computed, cursor-paged conversation views over extended NIP-01 filters. Thread windows use the same protocol ideas: ordinary signed rows, composite keyset pagination, optional aux closure, and relay-signed bounds. Adding a thread mode keeps those related wire contracts together instead of creating a second NIP with duplicated terminology and compatibility rules.
Extending a draft, optional NIP with an additive mode is normal protocol evolution. Existing fields and meanings are not reinterpreted:
top_level: trueremains channel mode;kind:39006remains channel-window bounds;thread_window: trueselects the new mode;kind:39007has a distinct identity and root/request binding;NIP-CW documents only the wire contract and relay semantics. Database plans, replica internals, and rollout procedures remain implementation concerns.
Why thread windows use independent modules
The implementation deliberately keeps
thread_window.rsseparate inbuzz-core,buzz-db, andbuzz-relayrather than adding branches throughout the existing channel-window path.The modes share pagination concepts, but their invariants differ:
1..=depth_limit;Forcing these rules into channel-window code would create a mode flag across parsing, SQL predicates, bounds construction, authorization, replica fallback, and tests. That abstraction would not remove complexity. It would distribute it. Separate modules keep each contract local and leave the established channel and legacy paths untouched.
Technical design
limit + 1.503rather than signing an incomplete page.0049_thread_window_index.sqladds the mixed-direction index used by newest-first scans. It validates a prebuilt index and bounds startup lock/build time.Tradeoffs
Related issue
No existing issue found. This work follows the thread-loading design and review discussion.
Testing
cargo test -p buzz-core: 258 unit tests and 2 doctests passed.cargo check --workspace --all-targets: passed at the rebased implementation head.cargo test -p buzz-db: 131 non-PostgreSQL tests passed; 275 infrastructure tests were ignored as declared.cargo fmt --all --check: passed.git diff --check; no runtime receipts were relabeled to the new SHA.Known unrelated baseline behavior remains: the mesh-demo echo test can return 504, and same-second archive → unarchive can deduplicate its membership notification. Neither path is changed here.