Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
6ed633f
chore: start acceptance tracking
Eternal-Wanderer-Vegetable Nov 15, 2026
68f5801
test: prepare text acceptance diagnostics
Eternal-Wanderer-Vegetable Nov 15, 2026
a1929a7
docs: record text acceptance field results
Eternal-Wanderer-Vegetable Nov 15, 2026
54b6a5a
docs: close text receive acceptance
Eternal-Wanderer-Vegetable Nov 15, 2026
e21aaf9
fix: preserve unknown text send outcomes
Eternal-Wanderer-Vegetable Nov 15, 2026
d757ac5
fix: preserve ambiguous send evidence
Eternal-Wanderer-Vegetable Nov 15, 2026
7d919b8
fix: keep early send result codes uncertain
Eternal-Wanderer-Vegetable Nov 15, 2026
2bc0eaa
docs: record delivery acceptance policy
Eternal-Wanderer-Vegetable Nov 15, 2026
496cc4a
docs: record callback dispatch and lifetime evidence
Eternal-Wanderer-Vegetable Nov 15, 2026
04ae7f8
fix: ignore late messages after listener stop
Eternal-Wanderer-Vegetable Nov 15, 2026
3a2ab95
docs: record listener stop field verification
Eternal-Wanderer-Vegetable Nov 15, 2026
491221e
feat(research): correlate bounded send diagnostics
Eternal-Wanderer-Vegetable Nov 15, 2026
e5bd754
docs: record scoped trace field verification
Eternal-Wanderer-Vegetable Nov 15, 2026
089c613
fix(research): parse bounded send trace reports
Eternal-Wanderer-Vegetable Nov 15, 2026
519b7ac
docs: record scoped group trace verification
Eternal-Wanderer-Vegetable Nov 15, 2026
99a9b3d
docs: trace fixed-build send callback ownership
Eternal-Wanderer-Vegetable Nov 15, 2026
0430563
docs: record read-only runtime descriptor check
Eternal-Wanderer-Vegetable Nov 15, 2026
b5282de
docs: prepare sampled callback observation lab
Eternal-Wanderer-Vegetable Nov 15, 2026
f00dd1a
docs: define sampled observation lab boundaries
Eternal-Wanderer-Vegetable Nov 15, 2026
6c76d9c
test(research): model safe tracing session lifecycle
Eternal-Wanderer-Vegetable Nov 15, 2026
95f934c
docs: record private ETW ownership experiment
Eternal-Wanderer-Vegetable Nov 15, 2026
36929f9
docs: record system logger access boundary
Eternal-Wanderer-Vegetable Nov 15, 2026
8e61343
docs: record private session child-exit checks
Eternal-Wanderer-Vegetable Nov 15, 2026
fdc3b63
docs: record private ETW handle reuse evidence
Eternal-Wanderer-Vegetable Nov 15, 2026
32ed378
docs: verify private ETW query identity limits
Eternal-Wanderer-Vegetable Nov 15, 2026
03d3272
docs: compare private ETW session query fields
Eternal-Wanderer-Vegetable Nov 16, 2026
a8b1da4
fix: reject in-flight text cookie collisions
Eternal-Wanderer-Vegetable Nov 16, 2026
a32f59d
docs: record cookie guard field regression
Eternal-Wanderer-Vegetable Nov 16, 2026
997e92b
fix: guard retired text cookies
Eternal-Wanderer-Vegetable Nov 16, 2026
65196b8
docs: record retired cookie field regression
Eternal-Wanderer-Vegetable Nov 16, 2026
b537355
fix: guard retired image cookies
Eternal-Wanderer-Vegetable Nov 16, 2026
981b7dd
fix: guard retired voice cookies
Eternal-Wanderer-Vegetable Nov 16, 2026
89154c8
docs: record voice cookie field send
Eternal-Wanderer-Vegetable Nov 16, 2026
c10b56c
docs: record voice message readback
Eternal-Wanderer-Vegetable Nov 16, 2026
fe2f5ac
docs: record image cookie field validation
Eternal-Wanderer-Vegetable Nov 16, 2026
de251e3
fix: read accepted HTTP streams in blocking mode
Eternal-Wanderer-Vegetable Nov 16, 2026
e6c2f22
docs: record HTTP zero-send field checks
Eternal-Wanderer-Vegetable Nov 16, 2026
ac2ca6a
docs: record HTTP send and readback field check
Eternal-Wanderer-Vegetable Nov 16, 2026
e1998fd
docs: record image send and readback field check
Eternal-Wanderer-Vegetable Nov 16, 2026
bccef3e
docs: record voice send and readback field check
Eternal-Wanderer-Vegetable Nov 16, 2026
7b8b732
fix: preserve uncertain media send results
Eternal-Wanderer-Vegetable Nov 16, 2026
a3ea48c
docs: record media result image field check
Eternal-Wanderer-Vegetable Nov 16, 2026
b80291f
docs: record media result voice field check
Eternal-Wanderer-Vegetable Nov 16, 2026
60a03f2
fix: retain unsent poll results
Eternal-Wanderer-Vegetable Nov 16, 2026
1b29ff8
docs: record poll admission loss boundary
Eternal-Wanderer-Vegetable Nov 16, 2026
03f4c36
test: model poll result acknowledgements
Eternal-Wanderer-Vegetable Nov 16, 2026
1793c5e
fix: bound retained send results
Eternal-Wanderer-Vegetable Nov 16, 2026
919e724
fix: deduplicate identity pending notices
Eternal-Wanderer-Vegetable Nov 16, 2026
ebd3379
fix: validate listener session before polling
Eternal-Wanderer-Vegetable Nov 16, 2026
76e2966
fix: validate poll batch before clearing state
Eternal-Wanderer-Vegetable Nov 16, 2026
401b42c
fix: acknowledge polled send result snapshots
Eternal-Wanderer-Vegetable Nov 17, 2026
2c05f57
fix: acknowledge only matched send results
Eternal-Wanderer-Vegetable Nov 17, 2026
bb26384
fix: back off unmatched result polling
Eternal-Wanderer-Vegetable Nov 17, 2026
f9be5af
feat: report retained result table pressure
Eternal-Wanderer-Vegetable Nov 17, 2026
0e63770
fix: retain notices when worker channel closes
Eternal-Wanderer-Vegetable Nov 17, 2026
c784de2
test: document worker notice loss boundary
Eternal-Wanderer-Vegetable Nov 17, 2026
b10cf2f
fix: match result acknowledgements to sent notice kind
Eternal-Wanderer-Vegetable Nov 17, 2026
a153464
fix: retain unacked unknown capacity after grace period
Eternal-Wanderer-Vegetable Nov 17, 2026
2fe9a6e
fix: bind result acknowledgements to notice sequence
Eternal-Wanderer-Vegetable Nov 17, 2026
31b79ef
fix: retain notices across bridge worker reconstruction
Eternal-Wanderer-Vegetable Nov 17, 2026
5139445
fix: resume resident handoff after backpressure
Eternal-Wanderer-Vegetable Nov 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
- name: Verify docs and formal bridge workspace contracts
run: ./.github/scripts/run-tests.ps1
- name: Test capability tooling
run: node --test scripts/check-snowcat-coverage.test.mjs scripts/extract-snowcat-capabilities.test.mjs
run: node --test scripts/check-snowcat-coverage.test.mjs scripts/extract-snowcat-capabilities.test.mjs scripts/analyze-text-send-trace.test.mjs scripts/lbr-session-model.test.mjs scripts/poll-result-ack-model.test.mjs
121 changes: 98 additions & 23 deletions crates/caligo-bridge/src/daemon_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ const EVENT_WINDOW_MAX_BYTES: usize = 8 * 1024 * 1024;
const RESULT_OUTBOX_MAX_ITEMS: usize = 256;

struct PendingNotice {
notice_id: u64,
notice: ResidentNotice,
sent_epoch: Option<u64>,
}
Expand All @@ -299,7 +300,27 @@ fn notice_request_id(notice: &ResidentNotice) -> &str {
}
}

fn notice_message(notice: &ResidentNotice) -> (BridgeMsg, bool) {
// Match an ACK to its exact sent outbox entry in this resident lifetime.
fn take_acked_result(
outbox: &mut VecDeque<PendingNotice>,
request_id: &str,
terminal: bool,
epoch: u64,
notice_id: u64,
) -> Option<ResidentNotice> {
let index = outbox.iter().position(|item| {
let kind_matches = match &item.notice {
ResidentNotice::Outcome(SendOutcome::AcceptedUnconfirmed { .. }) => !terminal,
ResidentNotice::Outcome(_) => terminal,
ResidentNotice::NativeStarted { .. } => false,
};
notice_id != 0 && item.notice_id == notice_id && kind_matches
&& item.sent_epoch == Some(epoch) && notice_request_id(&item.notice) == request_id
})?;
outbox.remove(index).map(|item| item.notice)
}

fn notice_message(notice: &ResidentNotice, notice_id: u64) -> (BridgeMsg, bool) {
match notice {
ResidentNotice::NativeStarted { request_id } => (
BridgeMsg::NativeStarted {
Expand All @@ -313,16 +334,19 @@ fn notice_message(notice: &ResidentNotice) -> (BridgeMsg, bool) {
request_id,
native_id,
} => BridgeMsg::SendResult {
notice_id,
request_id: request_id.clone(),
outcome: OutcomePayload::Success {
native_id: native_id.clone(),
},
},
SendOutcome::AcceptedUnconfirmed { request_id } => BridgeMsg::SendResult {
notice_id,
request_id: request_id.clone(),
outcome: OutcomePayload::AcceptedUnconfirmed,
},
SendOutcome::Failure { request_id, reason } => BridgeMsg::SendResult {
notice_id,
request_id: request_id.clone(),
outcome: OutcomePayload::Failure {
reason: reason.clone(),
Expand All @@ -331,6 +355,7 @@ fn notice_message(notice: &ResidentNotice) -> (BridgeMsg, bool) {
SendOutcome::Unknown {
request_id, reason, ..
} => BridgeMsg::SendResult {
notice_id,
request_id: request_id.clone(),
outcome: OutcomePayload::Unknown {
reason: reason.clone(),
Expand Down Expand Up @@ -653,7 +678,7 @@ pub fn run_worker<A: crate::host_adapter::HostAdapter>(
cfg: DaemonClientConfig,
resident: Arc<Resident<A>>,
wake: &dyn Fn() -> bool,
result_rx: mpsc::Receiver<ResidentNotice>,
result_rx: mpsc::Receiver<crate::resident::RetainedNotice>,
events_rx: mpsc::Receiver<crate::resident::OwnedEvent>,
stop: Arc<AtomicBool>,
) -> (WorkerCounters, WorkerExit) {
Expand All @@ -668,7 +693,12 @@ pub fn run_worker<A: crate::host_adapter::HostAdapter>(
let mut unacked_bytes: usize = 0;
// Native lifecycle notices survive connection teardown until the core
// confirms durable application. Resident reserves at most two slots/send.
let mut result_outbox: VecDeque<PendingNotice> = VecDeque::new();
// Reconstruct from resident before accepting channel hints. The resident
// owns IDs and payloads independently of any one worker lifetime.
let mut result_outbox: VecDeque<PendingNotice> = resident.retained_notices()
.into_iter()
.map(|item| PendingNotice { notice_id: item.notice_id, notice: item.notice, sent_epoch: None })
.collect();
macro_rules! publish {
() => {
c.publish();
Expand Down Expand Up @@ -884,7 +914,7 @@ fn session_loop<A: crate::host_adapter::HostAdapter>(
cfg: &DaemonClientConfig,
resident: &Arc<Resident<A>>,
wake: &dyn Fn() -> bool,
result_rx: &mpsc::Receiver<ResidentNotice>,
result_rx: &mpsc::Receiver<crate::resident::RetainedNotice>,
events_rx: &mpsc::Receiver<crate::resident::OwnedEvent>,
tick: &Arc<AtomicBool>,
stop: &Arc<AtomicBool>,
Expand Down Expand Up @@ -977,8 +1007,9 @@ fn session_loop<A: crate::host_adapter::HostAdapter>(
_ => break, // 仍未就绪:保留队列,下轮再试
}
}
// 1) 收入有界 outbox。其上限与 Resident 的默认预留结果槽对齐;
// 已满则不再消费源队列,结果仍由 Resident 保留。
// 1) Move notices from the owner channel into the worker's bounded outbox.
// Channel items are hints; resident holds the authoritative copies.
// Resident memory still does not survive host exit.
for (request_id, scope, outcome) in resident.take_query_results() {
if scope.connection_epoch != connection_epoch
|| scope.account != cfg.account
Expand All @@ -1001,20 +1032,21 @@ fn session_loop<A: crate::host_adapter::HostAdapter>(
}
}
while result_outbox.len() < RESULT_OUTBOX_MAX_ITEMS {
match result_rx.try_recv() {
Ok(notice) => result_outbox.push_back(PendingNotice {
notice,
sent_epoch: None,
}),
Err(_) => break,
let Ok(item) = result_rx.try_recv() else { break };
if !resident.contains_retained_notice(&item)
|| result_outbox.iter().any(|pending| pending.notice_id == item.notice_id) {
continue;
}
result_outbox.push_back(PendingNotice {
notice_id: item.notice_id, notice: item.notice, sent_epoch: None,
});
}
// 首次发送或新连接重放。FIFO 保证 NativeStarted 排在终态之前。
for pending in result_outbox.iter_mut() {
if pending.sent_epoch == Some(connection_epoch) {
continue;
}
let (msg, is_result) = notice_message(&pending.notice);
let (msg, is_result) = notice_message(&pending.notice, pending.notice_id);
if send_json(conn, &msg).is_err() {
return SessionEnd::Broken;
}
Expand Down Expand Up @@ -1152,7 +1184,7 @@ fn session_loop<A: crate::host_adapter::HostAdapter>(
request_id:request_id.clone(),wire_seq,scope,peer_uin,chat_type,png,
deadline:Instant::now()+Duration::from_millis(timeout_ms),
}) == crate::resident::SubmitVerdict::Accepted { wake(); }
else if send_json(conn,&BridgeMsg::SendResult {request_id,
else if send_json(conn,&BridgeMsg::SendResult {request_id, notice_id: 0,
outcome:OutcomePayload::Failure {reason:"image dispatch rejected before submission".into()},
}).is_err() {return SessionEnd::Broken;}
}
Expand All @@ -1177,6 +1209,7 @@ fn session_loop<A: crate::host_adapter::HostAdapter>(
wake();
} else if send_json(conn, &BridgeMsg::SendResult {
request_id,
notice_id: 0,
outcome: OutcomePayload::Failure { reason: "voice dispatch rejected before submission".into() },
}).is_err() {
return SessionEnd::Broken;
Expand Down Expand Up @@ -1233,24 +1266,25 @@ fn session_loop<A: crate::host_adapter::HostAdapter>(
heartbeat_misses = 0;
}
Ok(CoreToBridgeMsg::NativeStartedAck { request_id }) => {
resident.ack_notice(&request_id, true);
if let Some(index) = result_outbox.iter().position(|item| {
matches!(&item.notice, ResidentNotice::NativeStarted { request_id: id } if id == &request_id)
item.sent_epoch == Some(connection_epoch)
&& matches!(&item.notice, ResidentNotice::NativeStarted { request_id: id } if id == &request_id)
}) {
result_outbox.remove(index);
if let Some(item) = result_outbox.remove(index) {
resident.ack_retained_notice(&crate::resident::RetainedNotice {
notice_id: item.notice_id, notice: item.notice,
});
}
}
heartbeat_misses = 0;
}
Ok(CoreToBridgeMsg::SendResultAck {
request_id,
notice_id,
terminal,
}) => {
resident.ack_result_notice(&request_id, terminal);
if let Some(index) = result_outbox.iter().position(|item| {
matches!(&item.notice, ResidentNotice::Outcome(_))
&& notice_request_id(&item.notice) == request_id
}) {
result_outbox.remove(index);
if let Some(notice) = take_acked_result(result_outbox, &request_id, terminal, connection_epoch, notice_id) {
resident.ack_retained_notice(&crate::resident::RetainedNotice { notice_id, notice });
}
heartbeat_misses = 0;
}
Expand Down Expand Up @@ -1295,6 +1329,47 @@ fn peer_uid_from_target(v: &serde_json::Value) -> String {
mod tests {
use super::*;

fn result_notice(outcome: SendOutcome, epoch: Option<u64>, notice_id: u64) -> PendingNotice {
PendingNotice { notice_id, notice: ResidentNotice::Outcome(outcome), sent_epoch: epoch }
}

#[test]
fn result_ack_rejects_old_kind_and_unsent_or_old_epoch() {
let success = SendOutcome::Success { request_id: "r".into(), native_id: "n".into() };
let mut outbox = VecDeque::from([result_notice(success, Some(7), 2)]);
assert!(take_acked_result(&mut outbox, "r", false, 7, 2).is_none());
assert!(take_acked_result(&mut outbox, "r", true, 8, 2).is_none());
outbox[0].sent_epoch = None;
assert!(take_acked_result(&mut outbox, "r", true, 7, 2).is_none());
assert_eq!(outbox.len(), 1);
outbox[0].sent_epoch = Some(7);
assert!(take_acked_result(&mut outbox, "r", true, 7, 2).is_some());
assert!(take_acked_result(&mut outbox, "r", true, 7, 2).is_none());
}

#[test]
fn result_ack_removes_only_matching_result_kind() {
let mid = SendOutcome::AcceptedUnconfirmed { request_id: "r".into() };
let success = SendOutcome::Success { request_id: "r".into(), native_id: "n".into() };
let mut outbox = VecDeque::from([result_notice(mid.clone(), Some(7), 1), result_notice(success.clone(), Some(7), 2)]);
assert_eq!(take_acked_result(&mut outbox, "r", true, 7, 2), Some(ResidentNotice::Outcome(success)));
assert_eq!(take_acked_result(&mut outbox, "r", false, 7, 1), Some(ResidentNotice::Outcome(mid)));
assert!(outbox.is_empty());
}

#[test]
fn old_same_class_ack_must_not_remove_a_newer_result() {
let unknown = SendOutcome::Unknown { request_id: "r".into(), reason: None, late_receipt_possible: true };
let success = SendOutcome::Success { request_id: "r".into(), native_id: "n".into() };
let mut outbox = VecDeque::from([result_notice(success.clone(), Some(7), 2)]);
// Simulate an old terminal ACK for the already removed unknown.
let stale_ack_result = take_acked_result(&mut outbox, "r", true, 7, 1);
assert!(stale_ack_result.is_none(), "old terminal ACK must not consume newer success; old notice: {unknown:?}");
assert!(take_acked_result(&mut outbox, "r", true, 7, 0).is_none());
assert_eq!(outbox.len(), 1);
assert_eq!(take_acked_result(&mut outbox, "r", true, 7, 2), Some(ResidentNotice::Outcome(success)));
}

#[test]
fn event_window_releases_the_popped_record_with_different_sizes() {
let event = EventPayload {
Expand Down
Loading