Skip to content

Commit 90e660f

Browse files
TheSentinel454Elrondclaude
committed
Pin ban-denial WARN expiry through the production cache constructor
The logging regression built its own cache and checked only immediate repetition, so dropping the production TTL would have suppressed a workflow's ban WARN until eviction or restart without failing it. The engine and the test now share `ban_denial_warn_cache`, and the test proves WARN, then suppression, then WARN again after the interval. Also records buzz-workflow's new `sqlx` dev-dependency in Cargo.lock. Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Luke Tornquist <[email protected]>
1 parent 1941b36 commit 90e660f

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/buzz-workflow/src/lib.rs‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ impl WorkflowEngine {
128128
.max_capacity(10_000)
129129
.time_to_live(std::time::Duration::from_secs(10))
130130
.build(),
131-
ban_denial_warned: moka::sync::Cache::builder()
132-
.max_capacity(10_000)
133-
.time_to_live(BAN_DENIAL_WARN_INTERVAL)
134-
.build(),
131+
ban_denial_warned: ban_denial_warn_cache(BAN_DENIAL_WARN_INTERVAL),
135132
}
136133
}
137134

@@ -798,6 +795,18 @@ impl WorkflowEngine {
798795
}
799796
}
800797

798+
/// The cache behind [`WorkflowEngine::ban_denial_warned`]: an entry expires
799+
/// `warn_interval` after the WARN that inserted it, so the next ban denial
800+
/// for that workflow warns again.
801+
fn ban_denial_warn_cache(
802+
warn_interval: std::time::Duration,
803+
) -> moka::sync::Cache<(CommunityId, Uuid), ()> {
804+
moka::sync::Cache::builder()
805+
.max_capacity(10_000)
806+
.time_to_live(warn_interval)
807+
.build()
808+
}
809+
801810
/// Whether an owner-authority denial for this workflow logs at WARN. A ban
802811
/// denial warns only when no warning for the same workflow is still inside
803812
/// `warned`'s TTL; every other denial always warns.
@@ -2242,10 +2251,8 @@ steps:
22422251

22432252
#[test]
22442253
fn ban_denial_warns_once_per_interval_while_other_denials_always_warn() {
2245-
let warned = moka::sync::Cache::builder()
2246-
.max_capacity(16)
2247-
.time_to_live(BAN_DENIAL_WARN_INTERVAL)
2248-
.build();
2254+
let interval = std::time::Duration::from_millis(500);
2255+
let warned = ban_denial_warn_cache(interval);
22492256
let community = CommunityId::from_uuid(Uuid::new_v4());
22502257
let (wf_a, wf_b) = (Uuid::new_v4(), Uuid::new_v4());
22512258
let banned = WorkflowError::OwnerBanned;
@@ -2270,6 +2277,16 @@ steps:
22702277
should_warn_owner_denial(&warned, community, wf_a, &lookup_failed),
22712278
"a failed lookup is never rate-limited"
22722279
);
2280+
2281+
std::thread::sleep(interval * 2);
2282+
assert!(
2283+
should_warn_owner_denial(&warned, community, wf_a, &banned),
2284+
"a ban denial warns again once the interval has passed"
2285+
);
2286+
assert!(
2287+
!should_warn_owner_denial(&warned, community, wf_a, &banned),
2288+
"and is suppressed again for the next interval"
2289+
);
22732290
}
22742291

22752292
fn schedule_def(name: &str) -> String {

0 commit comments

Comments
 (0)