Skip to content

Commit 81c797e

Browse files
committed
Merge remote-tracking branch 'origin/main' into jm/git-formal-assurance
Signed-off-by: Jordan Mecom <[email protected]>
2 parents 56fe89b + 642ce41 commit 81c797e

153 files changed

Lines changed: 10737 additions & 1124 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.config/nextest.toml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,14 @@ fail-fast = false
5353

5454
[profile.flake.junit]
5555
path = "junit.xml"
56+
57+
[test-groups.desktop-same-user-check]
58+
# Most of buzz-cli's `desktop_provider::` tests reach the real same-user
59+
# check, which runs `lsof` with a 5-second limit. Run all at once on a busy
60+
# Mac, they starve each other past that limit, so the whole module takes
61+
# turns; the few that never reach the check run serially too.
62+
max-threads = 1
63+
64+
[[profile.default.overrides]]
65+
filter = "package(buzz-cli) and test(/^desktop_provider::/)"
66+
test-group = "desktop-same-user-check"

‎.github/workflows/_ci-clients.yml‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,14 @@ jobs:
133133
run: cd mobile && flutter analyze
134134
- name: Test
135135
if: matrix.lane == 'test'
136-
run: /bin/bash scripts/mobile-test-shard.sh ${{ matrix.shard }} 3 --dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example
136+
run: /bin/bash scripts/mobile-test-shard.sh ${{ matrix.shard }} 3
137137
- name: Test native secp256k1 package
138138
if: matrix.lane == 'checks'
139139
run: cd mobile/packages/buzz_secp256k1 && dart pub get && dart test
140140
- name: Test internal build
141141
if: matrix.lane == 'checks'
142142
run: >-
143143
cd mobile && flutter test
144-
--dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example
145144
--dart-define=BUZZ_DISTRIBUTION=internal
146145
--dart-define=BUZZ_BUILDERLAB_URL=https://id.example.org
147146
--dart-define=BUZZ_BUILDERLAB_RELAYS=buzz.example.org
@@ -150,7 +149,6 @@ jobs:
150149
if: matrix.lane == 'checks'
151150
run: >-
152151
cd mobile && flutter test
153-
--dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example
154152
--dart-define=BUZZ_DISTRIBUTION=public
155153
--dart-define=BUZZ_BUILDERLAB_URL=https://app.builderlab.xyz
156154
--dart-define=BUZZ_BUILDERLAB_RELAYS=communities.buzz.xyz
@@ -170,9 +168,6 @@ jobs:
170168
test/features/pairing/pairing_hosted_handoff_test.dart
171169
test/shared/agents/remote_agents_test.dart
172170
test/features/agents
173-
- name: Test mobile without push configuration
174-
if: matrix.lane == 'checks'
175-
run: cd mobile && flutter test test/shared/push/push_unconfigured_build_test.dart
176171
- name: Test mobile recipe argument forwarding
177172
if: matrix.lane == 'checks'
178173
run: /bin/bash scripts/test-mobile-gateway-recipes.sh

‎.release/desktop-candidate.json‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"schema": 2,
3-
"version": "0.5.28",
4-
"base_sha": "5142cf6b2a0f44686eeda1ed07905ee3560fd78e",
5-
"previous_tag": "desktop-v0.5.27",
6-
"previous_base_sha": "af5bb0af488784c3707e99c87e0675a729711a6e",
7-
"previous_merge_sha": "001290a34d4b854f0b5d354ae848163b43e6ff85",
8-
"tag": "desktop-v0.5.28",
9-
"commit_count": 41
3+
"version": "0.5.29",
4+
"base_sha": "41587e0284f277d13e5d3a40b169c1dcd54d2894",
5+
"previous_tag": "desktop-v0.5.28",
6+
"previous_base_sha": "5142cf6b2a0f44686eeda1ed07905ee3560fd78e",
7+
"previous_merge_sha": "c1370cc6547c16829ecc8ea2fdaf337c4a5ef464",
8+
"tag": "desktop-v0.5.29",
9+
"commit_count": 589
1010
}

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ which buzz-app also uses), even where a payload is documented only in code.
796796
cd mobile
797797
dart format --output=none --set-exit-if-changed .
798798
flutter analyze
799-
flutter test --dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example
799+
flutter test
800800
```
801801

802802
Or from repo root: `just mobile-fmt` (auto-fix), `just mobile-check` (lint + fmt check), `just mobile-test` (tests).

‎CHANGELOG.md‎

Lines changed: 599 additions & 0 deletions
Large diffs are not rendered by default.

‎CONTEXT.md‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Buzz domain language
22

3-
Shared terminology for Buzz product behavior. This glossary currently covers mobile [push suppression](#push-suppression), the [notification body](#notification-body) and [mobile builds](#mobile-builds); it is not a complete model of Buzz.
3+
Shared terminology for Buzz product behavior. This glossary currently covers mobile [push suppression](#push-suppression), the [notification body](#notification-body), [mobile builds](#mobile-builds) and [sharing](#sharing); it is not a complete model of Buzz.
44

55
## Notifications
66

@@ -69,3 +69,17 @@ _Avoid_: Dogfood build, enterprise build, org build
6969
The mobile app distributed through the App Store and TestFlight. It uses only the public Builderlab and cannot reach any organization's community.
7070

7171
_Avoid_: App Store build, external build
72+
73+
## Sharing
74+
75+
### Share
76+
77+
Bringing content such as a screenshot, screen recording, URL or text from another app into a Buzz conversation through the system share sheet. A share ends in that conversation's composer, where the person adds their own text and sends it.
78+
79+
_Avoid_: Forward, post
80+
81+
### Share target
82+
83+
A conversation offered among the share sheet's suggested destinations: an existing channel or DM, or a new Solo chat. Share targets are learned from top-level messages a person sends in a conversation; thread replies and incoming messages never count.
84+
85+
_Avoid_: Recipient, contact, suggestion

‎Cargo.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ buzz-ws-client = { path = "crates/buzz-ws-client" }
158158
buzz-relay-mesh = { path = "crates/buzz-relay-mesh" }
159159
buzz-datastore-tracing = { path = "crates/buzz-datastore-tracing" }
160160

161+
[profile.release]
162+
lto = "thin"
163+
codegen-units = 4
164+
161165
# CI profile — builds the relay for desktop e2e. Dependencies keep full
162166
# release optimization (warm from main's cache; they carry the runtime hot
163167
# path: tokio/sqlx/axum). Workspace crates build at opt-level 1 — enough for
@@ -167,6 +171,7 @@ buzz-datastore-tracing = { path = "crates/buzz-datastore-tracing" }
167171
[profile.ci]
168172
inherits = "release"
169173
lto = false
174+
codegen-units = 16
170175
opt-level = 1
171176

172177
[profile.ci.package."*"]

‎Justfile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,7 @@ mobile-check:
10721072
# Run mobile tests
10731073
mobile-test:
10741074
/bin/bash ./scripts/test-mobile-gateway-recipes.sh
1075-
unset GIT_DIR GIT_WORK_TREE; cd {{mobile_dir}} && flutter test --dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example
1076-
unset GIT_DIR GIT_WORK_TREE; cd {{mobile_dir}} && flutter test test/shared/push/push_unconfigured_build_test.dart
1075+
unset GIT_DIR GIT_WORK_TREE; cd {{mobile_dir}} && flutter test
10771076
unset GIT_DIR GIT_WORK_TREE; cd {{mobile_dir}}/packages/buzz_secp256k1 && dart pub get && dart test
10781077

10791078
# Regenerate the emoji dataset asset from desktop's emoji-mart install.

‎crates/buzz-acp/TESTING.md‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,52 @@ BUZZ_TEST_PI_ACP=/absolute/buzz-pi-acp/dist/index.js \
4040
cargo test -p buzz-acp real_pi_preserves -- --ignored
4141
```
4242

43+
## Observer retention measurement
44+
45+
The observer has deterministic regression tests for replay byte/count limits,
46+
oversized payloads and envelopes, and a stalled live subscriber. Run them with:
47+
48+
```sh
49+
cargo test -p buzz-acp --lib observer::tests -- --test-threads=1
50+
```
51+
52+
An ignored local probe measures the actual `ObserverHandle::emit`, `snapshot`
53+
and broadcast paths without a relay or agent. It defaults to the #7987 workload:
54+
1,000 events with a 1 MiB ASCII string each and a subscriber that does not drain
55+
until after emission. It prints JSON with `emitMs`, replay/live serialized byte
56+
totals and event counts, and the subscriber's lag count.
57+
58+
```sh
59+
cargo test --release -p buzz-acp --lib observer::tests::retention_probe -- \
60+
--exact --ignored --nocapture
61+
62+
# Small-event throughput control, including ordinary count-based eviction:
63+
BUZZ_OBSERVER_PROBE_EVENTS=10000 BUZZ_OBSERVER_PROBE_BYTES=1024 \
64+
cargo test --release -p buzz-acp --lib observer::tests::retention_probe -- \
65+
--exact --ignored --nocapture
66+
```
67+
68+
Use fresh processes, the same profile and workload, an idle machine, and repeated
69+
alternating baseline/candidate runs for timing comparisons. There is no timing
70+
threshold. `emitMs` includes payload construction and excludes the later snapshot
71+
and receive/serialization measurement. Serialized byte totals are not heap/RSS
72+
measurements. On macOS, `/usr/bin/time -l` around the test executable printed by
73+
`cargo test --release -p buzz-acp --lib --no-run` can additionally measure peak
74+
RSS; do not time Cargo compilation as part of the memory workload. The probe's
75+
snapshot and receive measurements allocate their own copies, so its peak RSS
76+
includes measurement overhead.
77+
78+
Replay keeps the newest suffix within both 1,000 events and 4 MiB of serialized
79+
JSON. Events are fitted with the existing relay payload elision before either
80+
store retains them. Large-payload preparation and snapshot copies stay outside
81+
the replay lock. Publication finalizes the sequence and timestamp together, and
82+
byte accounting uses that finalized envelope. The live ring preserves its requested 1,000-event capacity
83+
(Tokio rounds it to 1,024 slots); its per-event relay-size cap bounds retained
84+
serialized JSON to less than 64 MiB. These are JSON budgets, not exact allocator
85+
limits. Oversized telemetry carries the existing elision markers; an envelope
86+
that cannot fit even after payload elision is dropped with a warning and sequence
87+
gap. A lagging receiver continues to report its dropped-event count.
88+
4389
## Git bootstrap
4490

4591
`cargo test -p buzz-acp --test git_bootstrap` starts the actual harness with a

‎crates/buzz-acp/src/observer.rs‎

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ use tokio::sync::broadcast;
1717

1818
#[cfg(test)]
1919
mod perf_tests;
20+
#[cfg(test)]
21+
mod tests;
2022

2123
const OBSERVER_BUFFER_CAP: usize = 1_000;
24+
const OBSERVER_REPLAY_MAX_BYTES: usize = 4 * 1024 * 1024;
2225

2326
/// Best-effort metadata attached to observer events.
2427
#[derive(Clone, Debug, Default)]
@@ -40,17 +43,25 @@ pub struct ObserverHandle {
4043
}
4144

4245
struct ObserverInner {
46+
// Fit events before either buffer retains them. Tokio rounds 1,000 slots
47+
// up to 1,024, so the per-event cap bounds live JSON below 64 MiB.
4348
tx: broadcast::Sender<ObserverEvent>,
44-
buffer: Mutex<VecDeque<Arc<ObserverEvent>>>,
49+
buffer: Mutex<ReplayBuffer>,
4550
seq: AtomicU64,
4651
}
4752

53+
#[derive(Default)]
54+
struct ReplayBuffer {
55+
events: VecDeque<(usize, Arc<ObserverEvent>)>,
56+
bytes: usize,
57+
}
58+
4859
fn new_observer_handle() -> ObserverHandle {
4960
let (tx, _) = broadcast::channel(OBSERVER_BUFFER_CAP);
5061
ObserverHandle {
5162
inner: Arc::new(ObserverInner {
5263
tx,
53-
buffer: Mutex::new(VecDeque::with_capacity(OBSERVER_BUFFER_CAP)),
64+
buffer: Mutex::new(ReplayBuffer::default()),
5465
seq: AtomicU64::new(1),
5566
}),
5667
}
@@ -92,11 +103,15 @@ impl ObserverHandle {
92103
self.inner.tx.subscribe()
93104
}
94105

95-
/// Return the current replay buffer.
106+
/// Return the newest events within the 1,000-event and 4 MiB JSON budgets.
96107
pub fn snapshot(&self) -> Vec<ObserverEvent> {
97108
// Pin the replay window under the lock, then copy JSON after releasing it.
98109
let events: Vec<_> = match self.inner.buffer.lock() {
99-
Ok(buffer) => buffer.iter().cloned().collect(),
110+
Ok(buffer) => buffer
111+
.events
112+
.iter()
113+
.map(|(_, event)| event.clone())
114+
.collect(),
100115
Err(error) => {
101116
tracing::warn!(target: "observer", "observer replay buffer lock poisoned: {error}");
102117
Vec::new()
@@ -105,7 +120,7 @@ impl ObserverHandle {
105120
events.into_iter().map(|event| (*event).clone()).collect()
106121
}
107122

108-
/// Emit a local observer event.
123+
/// Emit a local observer event, fitting telemetry before retaining it.
109124
pub fn emit(
110125
&self,
111126
kind: impl Into<String>,
@@ -114,8 +129,8 @@ impl ObserverHandle {
114129
payload: serde_json::Value,
115130
) {
116131
let mut event = ObserverEvent {
117-
seq: 0,
118-
timestamp: String::new(),
132+
seq: self.inner.seq.load(Ordering::Relaxed),
133+
timestamp: chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Nanos, false),
119134
kind: kind.into(),
120135
agent_index,
121136
channel_id: context.channel_id.clone(),
@@ -125,7 +140,12 @@ impl ObserverHandle {
125140
payload,
126141
};
127142

128-
// Copy the payload before locking so other emitters can proceed.
143+
// Fit and copy before locking so large inputs do not stall other
144+
// emitters. Fixed timestamp precision keeps metadata width stable;
145+
// account for the final publication metadata below without a JSON walk.
146+
let prepared_metadata_bytes = event.seq.to_string().len() + event.timestamp.len();
147+
let mut bytes = super::fit_observer_event_to_budget(&mut event);
148+
let prepared_within_budget = bytes <= super::OBSERVER_MAX_PLAINTEXT_LEN;
129149
let mut replay = event.clone();
130150
let mut buffer = match self.inner.buffer.lock() {
131151
Ok(buffer) => buffer,
@@ -137,13 +157,32 @@ impl ObserverHandle {
137157
// Assign both fields with publication: desktop sorts by timestamp,
138158
// and the publisher deduplicates snapshots by sequence high-water mark.
139159
event.seq = self.inner.seq.fetch_add(1, Ordering::Relaxed);
140-
event.timestamp = chrono::Utc::now().to_rfc3339();
160+
event.timestamp = chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Nanos, false);
161+
bytes =
162+
bytes - prepared_metadata_bytes + event.seq.to_string().len() + event.timestamp.len();
163+
if prepared_within_budget && bytes > super::OBSERVER_MAX_PLAINTEXT_LEN {
164+
// A sequence-width boundary can grow a frame prepared just below
165+
// the cap. Only an already-bounded frame can need this final fit.
166+
bytes = super::fit_observer_event_to_budget(&mut event);
167+
replay = event.clone();
168+
}
169+
if bytes > super::OBSERVER_MAX_PLAINTEXT_LEN {
170+
tracing::warn!(target: "observer", seq = event.seq, bytes, dropped = 1,
171+
"observer envelope exceeds byte budget; dropped event");
172+
return;
173+
}
141174
replay.seq = event.seq;
142175
replay.timestamp.clone_from(&event.timestamp);
143-
if buffer.len() >= OBSERVER_BUFFER_CAP {
144-
buffer.pop_front();
176+
while buffer.events.len() >= OBSERVER_BUFFER_CAP
177+
|| buffer.bytes + bytes > OBSERVER_REPLAY_MAX_BYTES
178+
{
179+
let Some((old_bytes, _)) = buffer.events.pop_front() else {
180+
break;
181+
};
182+
buffer.bytes -= old_bytes;
145183
}
146-
buffer.push_back(Arc::new(replay));
184+
buffer.bytes += bytes;
185+
buffer.events.push_back((bytes, Arc::new(replay)));
147186

148187
let _ = self.inner.tx.send(event);
149188
}

0 commit comments

Comments
 (0)