Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
de9f213
fix(stack): compact settled signal payloads
ScriptedAlchemy Nov 9, 2026
b44f0c9
test(stack): cover terminal cleanup and replay
ScriptedAlchemy Nov 9, 2026
fedc7b6
fix(stack): expose retention bounds
ScriptedAlchemy Nov 9, 2026
a87c241
fix(daemon): schedule bounded signal retirement
ScriptedAlchemy Nov 9, 2026
7aa8feb
fix(daemon): retire signals without active automation jobs
ScriptedAlchemy Nov 9, 2026
83614c4
style(stack): format delivery retention exports and tests
ScriptedAlchemy Nov 9, 2026
c249be7
fix(stack): bound terminal retention scans with a durable cursor
ScriptedAlchemy Nov 9, 2026
448dba6
test(stack): settle the tail outside the saturated recipient
ScriptedAlchemy Nov 9, 2026
4ed539a
fix(stack): bind scalar timestamps in retention cursor queries
ScriptedAlchemy Nov 9, 2026
7bc1993
fix(retention): release daemon writer between stack pages
ScriptedAlchemy Nov 9, 2026
d4ae086
fix(retention): report progress when stack cleanup yields
ScriptedAlchemy Nov 9, 2026
bce6cb7
fix(stack): recognize canonical retirement identity across JSON forms
ScriptedAlchemy Nov 9, 2026
55b9548
fix(stack): recognize escaped retired JSON keys
ScriptedAlchemy Nov 9, 2026
5adbcec
style(stack): format retired signal identity tests
ScriptedAlchemy Nov 9, 2026
e5387f2
fix(stack): reject ambiguous retired signal JSON
ScriptedAlchemy Nov 9, 2026
185a279
style(stack): format the retired signal checkpoint assertion
ScriptedAlchemy Nov 9, 2026
43f2a83
fix(stack): enforce UTF-8 byte cap on durable signal JSON
ScriptedAlchemy Nov 9, 2026
95b5337
fix(stack): enforce byte limits in existing registered stores
ScriptedAlchemy Nov 9, 2026
6975944
fix(stack): refuse forged retired identities on insert
ScriptedAlchemy Nov 9, 2026
78da97f
fix(stack): enforce terminal inspection age in SQL
ScriptedAlchemy Nov 9, 2026
1bbba11
Merge master into fix/4445-stack-terminal-retention
ScriptedAlchemy Nov 9, 2026
daa0bb5
fix(stack): isolate bounded retention and remove inert test drops
ScriptedAlchemy Nov 10, 2026
5df9b1a
fix(stack): retire terminal deliveries in store retention
ScriptedAlchemy Nov 10, 2026
e8392ce
fix(stack): run terminal cleanup without optional retention
ScriptedAlchemy Nov 10, 2026
6091533
Merge prerequisite admission work into terminal retention
ScriptedAlchemy Nov 10, 2026
4baadf2
fix(retention): admit terminal pages through shared store jobs
ScriptedAlchemy Nov 10, 2026
6b33c86
fix(maintenance): release queued retention resources
ScriptedAlchemy Nov 10, 2026
ad34560
Merge commit 'a166fb847bacbb78d08ad5333d0e4122a1f89b33' into fix/4826…
ScriptedAlchemy Nov 10, 2026
15b60a1
test(global-db): batch published fixture assembly
ScriptedAlchemy Nov 10, 2026
c2d184d
test(hooks): expose retained-stop admission timing
ScriptedAlchemy Nov 11, 2026
1626719
fix(hooks): settle delivered stop intent retries
ScriptedAlchemy Nov 11, 2026
846a2f2
Merge commit 'c2d184df87a5bf46e509d85671fe6577d79cf08c' into HEAD
ScriptedAlchemy Nov 11, 2026
40429e9
fix(hooks): bind Stop retries to exact intent receipts
ScriptedAlchemy Nov 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -966,21 +966,27 @@ fn intent_candidate(
})
}

/// Envelope identity of the pass's suggestion. Derived from the boundary so a
/// stop boundary's intent suggestion never shares the feedback suggestion's
/// envelope identity.
fn intent_envelope_id(hook: &AdmittedContextScoutHookV1) -> Option<[u8; 16]> {
let envelope = hook.envelope();
/// Envelope identity of a boundary's intent suggestion. Derived from the
/// boundary so it never shares the feedback suggestion's envelope identity.
pub fn context_scout_intent_envelope_id(
project_id: [u8; 16],
event_id: [u8; 16],
) -> Option<[u8; 16]> {
let digest = digest_bytes(canonical_sha256(&(
INTENT_ENVELOPE_DOMAIN,
envelope.project_id,
envelope.event_id,
project_id,
event_id,
)))?;
let mut envelope_id = [0; 16];
envelope_id.copy_from_slice(&digest[..16]);
(envelope_id != [0; 16]).then_some(envelope_id)
}

fn intent_envelope_id(hook: &AdmittedContextScoutHookV1) -> Option<[u8; 16]> {
let envelope = hook.envelope();
context_scout_intent_envelope_id(envelope.project_id, envelope.event_id)
}

/// Records one suggestion the pass decided and withheld, with the same
/// identity a delivery would carry.
async fn record_withheld(
Expand Down
25 changes: 22 additions & 3 deletions crates/tracedecay-agent-hosts/src/agents/context_scout/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ use super::{
ContextScoutModelExecutionV1, ContextScoutModelFuture, ContextScoutModelRequestV1,
ContextScoutMutationBindingV1, ContextScoutMutationResultV1,
ContextScoutMutationSettlementOutcomeV1, ContextScoutPublicMutationV1,
ContextScoutRecentReadOutcomeV1, ContextScoutRecentStateV1, ContextScoutRouteV1,
ContextScoutRuntimeOutcomeV1, ContextScoutSelectionInputV1, ContextScoutServiceStateV1,
ContextScoutStatusV1, ContextScoutSuppressionV1, ProjectContextScoutDurableStoreV1,
ContextScoutRecentDeliveryV1, ContextScoutRecentReadOutcomeV1, ContextScoutRecentStateV1,
ContextScoutRouteV1, ContextScoutRuntimeOutcomeV1, ContextScoutSelectionInputV1,
ContextScoutServiceStateV1, ContextScoutStatusV1, ContextScoutSuppressionV1,
ProjectContextScoutDurableStoreV1,
};
use tracedecay_runtime_core::db::Database;

Expand Down Expand Up @@ -816,6 +817,24 @@ impl ProjectContextScoutOwnerV1 {
}
}

/// Exact delivery proof for one durable address and envelope identity,
/// independent of the bounded recent-page projection.
pub async fn delivery_exact(
&self,
address: ContextScoutAddressV1,
envelope_id: [u8; 16],
) -> Result<Option<ContextScoutRecentDeliveryV1>, ContextScoutErrorV1> {
let configuration = self.configuration.read().await;
let revision = configuration
.as_ref()
.ok_or(ContextScoutErrorV1::ConfigurationUnavailable)?
.control()
.configuration_revision;
self.store
.delivery_exact(address, revision, envelope_id)
.await
}

pub async fn explain_exact(
&self,
address: ContextScoutAddressV1,
Expand Down
110 changes: 81 additions & 29 deletions crates/tracedecay-agent-hosts/src/agents/context_scout/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use super::{
ContextScoutAddressExt, ContextScoutAddressV1, ContextScoutDeliveryReceiptV1,
ContextScoutDeliveryWindowV1, ContextScoutDurableClaimOutcomeV1, ContextScoutDurableClaimV1,
ContextScoutDurableQueueEntryExt, ContextScoutDurableQueueEntryV1,
ContextScoutDurableStartupOutcomeV1, ContextScoutDurableStoreOutcomeV1, ContextScoutFeedbackV1,
ContextScoutLeaseExt, ContextScoutLeaseV1, ContextScoutMutationBindingV1,
ContextScoutMutationOperationV1, ContextScoutMutationResultV1,
ContextScoutDurableStartupOutcomeV1, ContextScoutDurableStoreOutcomeV1, ContextScoutErrorV1,
ContextScoutFeedbackV1, ContextScoutLeaseExt, ContextScoutLeaseV1,
ContextScoutMutationBindingV1, ContextScoutMutationOperationV1, ContextScoutMutationResultV1,
ContextScoutMutationSettlementOutcomeV1, ContextScoutMutationSettlementV1,
ContextScoutPublicMutationV1, ContextScoutRecentDeliveryV1, ContextScoutRecentReadOutcomeV1,
ContextScoutRecentStateV1, ContextScoutWorkV1, MAX_SCOUT_ACTIVE_ADDRESSES,
Expand Down Expand Up @@ -706,6 +706,26 @@ impl ProjectContextScoutDurableStoreV1 {
address.project_id == self.project_id && address.validate().is_ok()
}

async fn read_state(&self) -> Result<Option<StoredContextScoutStateV1>, ContextScoutErrorV1> {
let encoded = self
.database
.get_metadata(STORE_KEY_V1)
.await
.map_err(|_| ContextScoutErrorV1::ConfigurationUnavailable)?;
let Some(encoded) = encoded else {
return Ok(None);
};
if encoded.len() > MAX_STORED_STATE_BYTES_V1 {
return Err(ContextScoutErrorV1::ConfigurationUnavailable);
}
let state = serde_json::from_str::<StoredContextScoutStateV1>(&encoded)
.map_err(|_| ContextScoutErrorV1::ConfigurationUnavailable)?;
if !state.validate(self.project_id) || !state.has_complete_delivery_provenance() {
return Err(ContextScoutErrorV1::ConfigurationUnavailable);
}
Ok(Some(state))
}

// The shared read funnel behind `recent`, `recent_for_protected_session`,
// and `recent_project`: one static label for durable recent-state reads.
#[tracing::instrument(name = "context_scout_store_read", level = "trace", skip_all)]
Expand All @@ -723,33 +743,19 @@ impl ProjectContextScoutDurableStoreV1 {
{
return ContextScoutRecentReadOutcomeV1::Unavailable;
}
let Some(encoded) = self
.database
.get_metadata(STORE_KEY_V1)
.await
.ok()
.flatten()
else {
return ContextScoutRecentReadOutcomeV1::Ready(ContextScoutRecentStateV1 {
configuration_revision,
observed_at,
pending: Vec::new(),
deliveries: Vec::new(),
omitted: 0,
});
};
if encoded.len() > MAX_STORED_STATE_BYTES_V1 {
return ContextScoutRecentReadOutcomeV1::Unavailable;
}
let Ok(state) = serde_json::from_str::<StoredContextScoutStateV1>(&encoded) else {
return ContextScoutRecentReadOutcomeV1::Unavailable;
let state = match self.read_state().await {
Ok(Some(state)) => state,
Ok(None) => {
return ContextScoutRecentReadOutcomeV1::Ready(ContextScoutRecentStateV1 {
configuration_revision,
observed_at,
pending: Vec::new(),
deliveries: Vec::new(),
omitted: 0,
});
}
Err(_) => return ContextScoutRecentReadOutcomeV1::Unavailable,
};
if !state.validate(self.project_id) {
return ContextScoutRecentReadOutcomeV1::Unavailable;
}
if !state.has_complete_delivery_provenance() {
return ContextScoutRecentReadOutcomeV1::Unavailable;
}
let mut pending = state
.entries
.iter()
Expand Down Expand Up @@ -817,6 +823,52 @@ impl ProjectContextScoutDurableStoreV1 {
.await
}

/// Reads one exact delivered envelope without letting pending work or
/// newer receipts consume a recent-page limit.
pub(crate) async fn delivery_exact(
&self,
address: ContextScoutAddressV1,
configuration_revision: [u8; 32],
envelope_id: [u8; 16],
) -> Result<Option<ContextScoutRecentDeliveryV1>, ContextScoutErrorV1> {
if !self.in_scope(address) {
return Err(ContextScoutErrorV1::InvalidAddress);
}
if configuration_revision == [0; 32] {
return Err(ContextScoutErrorV1::ConfigurationUnavailable);
}
if envelope_id == [0; 16] {
return Err(ContextScoutErrorV1::ReceiptBindingMismatch);
}
let Some(state) = self.read_state().await? else {
return Ok(None);
};
let Some(binding) = state.delivery_addresses.iter().find(|binding| {
binding.address == address
&& binding.envelope_id == envelope_id
&& binding.entry.envelope.configuration_revision == configuration_revision
}) else {
return Ok(None);
};
let receipt = state
.receipts
.iter()
.find(|receipt| receipt.envelope_id == envelope_id)
.cloned()
.ok_or(ContextScoutErrorV1::ConfigurationUnavailable)?;
let feedback = state
.feedback
.iter()
.rev()
.find(|feedback| feedback.receipt_id == receipt.receipt_id)
.copied();
Ok(Some(ContextScoutRecentDeliveryV1 {
entry: binding.entry.clone(),
receipt,
feedback,
}))
}

pub(crate) async fn recent_for_protected_session(
&self,
protected_session_id: [u8; 32],
Expand Down
102 changes: 102 additions & 0 deletions crates/tracedecay-agent-hosts/src/agents/context_scout/store_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,108 @@ async fn restart_requeues_expired_claim_and_keeps_receipt_feedback_idempotent()
));
}

#[tokio::test]
async fn exact_delivery_lookup_is_not_hidden_by_pending_or_other_guidance() {
let (_temporary, database) = database().await;
let project_id = [8; 16];
let store =
ProjectContextScoutDurableStoreV1::from_project_database(database, project_id).unwrap();
let mut delivered = entry(project_id, 1);
delivered.envelope.candidate.expires_at = UtcMicros(4_000_000_000_000_000);
assert_eq!(
store.enqueue(delivered.clone()).await,
ContextScoutDurableStoreOutcomeV1::Stored
);
let claim = match store
.claim(delivered.work.address, UtcMicros(10), lease(50, 100))
.await
{
ContextScoutDurableClaimOutcomeV1::Claimed(claimed) => claimed,
other => panic!("expected delivery claim, got {other:?}"),
};
let receipt = ContextScoutDeliveryReceiptV1 {
receipt_id: context_scout_delivery_receipt_id([41; 16], delivered.envelope.envelope_id),
envelope_id: delivered.envelope.envelope_id,
delivered_at: UtcMicros(30),
outcome: ContextScoutDeliveryOutcomeV1::Attempted,
};
assert_eq!(
store.record_delivery(&claim, &receipt).await,
ContextScoutDurableStoreOutcomeV1::Stored
);

let mut pending = delivered.clone();
pending.work.generation = 2;
pending.work.input_watermark = [15; 32];
pending.envelope.envelope_id = [99; 16];
pending.envelope.input_watermark = [15; 32];
pending.envelope.candidate.dedupe_key = [19; 32];
assert_eq!(
store.enqueue(pending.clone()).await,
ContextScoutDurableStoreOutcomeV1::Stored
);
let recent = store
.recent(
delivered.work.address,
delivered.envelope.configuration_revision,
UtcMicros(31),
1,
)
.await;
assert!(matches!(
recent,
ContextScoutRecentReadOutcomeV1::Ready(ContextScoutRecentStateV1 {
pending: recent_pending,
deliveries,
..
}) if recent_pending == vec![pending] && deliveries.is_empty()
));

assert_eq!(
store
.delivery_exact(
delivered.work.address,
delivered.envelope.configuration_revision,
delivered.envelope.envelope_id,
)
.await
.unwrap(),
Some(ContextScoutRecentDeliveryV1 {
entry: delivered.clone(),
receipt,
feedback: None,
})
);
let other_address = ContextScoutAddressV1 {
logical_message_id: [90; 16],
..delivered.work.address
};
assert_eq!(
store
.delivery_exact(
other_address,
delivered.envelope.configuration_revision,
delivered.envelope.envelope_id,
)
.await
.unwrap(),
None,
"guidance at another lifecycle address is not intent proof"
);
assert_eq!(
store
.delivery_exact(
delivered.work.address,
delivered.envelope.configuration_revision,
[98; 16],
)
.await
.unwrap(),
None,
"another envelope is not the Stop's deterministic intent proof"
);
}

#[tokio::test]
async fn delivery_requires_the_current_claim_after_lease_takeover() {
let (_temporary, database) = database().await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ async fn hook_orchestration_runs_feedback_work_without_scout_lifecycle() {
false,
None,
None,
false,
);
ADMITTING_HOOK.set(false);
assert_eq!(admission, HookOrchestrationAdmissionV1::Enqueued);
Expand Down Expand Up @@ -514,6 +515,7 @@ async fn replayed_admission_after_retryable_failure_completes_a_fresh_cycle() {
Some(Arc::new(move |_| {
first_acknowledged.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
})),
false,
),
HookOrchestrationAdmissionV1::Enqueued
);
Expand Down Expand Up @@ -545,6 +547,7 @@ async fn replayed_admission_after_retryable_failure_completes_a_fresh_cycle() {
replay_acknowledged.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
replay_terminal.notify_one();
})),
false,
),
HookOrchestrationAdmissionV1::Enqueued,
"the settled failure must free its slot for the replay"
Expand Down
5 changes: 4 additions & 1 deletion crates/tracedecay-daemon-service/src/invocation/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ pub fn admit_registered_hook_orchestration(
explicit: bool,
admission_order: Option<u64>,
completion: Option<Arc<dyn Fn(HookOrchestrationSettlementV1) + Send + Sync + 'static>>,
intent_delivery_settled: bool,
) -> HookOrchestrationAdmissionV1 {
// Any other hook of a session that now carries a lifecycle is the event a
// boundary parked for that session waits on.
Expand All @@ -726,7 +727,9 @@ pub fn admit_registered_hook_orchestration(
runtime.resume_parked(request.hook.envelope(), lifecycle);
}
request.admission_order = admission_order;
let intent_companion = request.intent_companion();
let intent_companion = request
.intent_companion()
.filter(|_| !intent_delivery_settled);
request.completion = completion;
let admission = runtime.admit(request);
// The stop boundary's own admission is what the hook reports; its intent
Expand Down
Loading
Loading