Hold jsg::Weak's kj::WeakRc in a generic kj-rs KjWeakRc #8759
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 280 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.337
Real PR Conversation Timeline
1 comments
"Review active on #8759"
general
weight: 0.35
nathanwhit
This is a follow-up to #8689, addressing this review comment:
jsg::Weak'skj::WeakRc<Wrappable>now uses a genericKjWeakRc<T>in kj-rs instead of a jsg-specific mirror and shims.Add KjWeakRc to kj-rs
kj_rs::KjWeakRc<T>mirrorskj::WeakRc<T>the wayKjRcmirrorskj::Rc. You get one fromKjRc::downgrade(). It hastry_get(),is_alive(),upgrade()andClone, and dropping it releases its reference to the weak cell.KjRchelpers, the C++ helpers treat the referent askj::byte. That works becausekj::WeakRc<T>holds the owner's weak cell and the referent pointer, and reaches the owner only through the cell. Astatic_assertchecks its size and alignment.KjWeakRcisn't a bridge type, so the cxx code generator is unchanged.upgrade()isunsafe.KjRc::get_mut()counts only strong references, askj::Refcounted::isShared()does, and KJ keeps the weak count private, soget_mut()can't refuse a referent that has weak references. The precondition is that no reference returned byget_mut()is live. Onceupgrade()returns, the referent is shared andget_mut()refuses it.KjWeakRc<T>is invariant inT, likeKjRc<T>, because theKjRc<T>thatupgrade()returns can write aT.Hold a KjWeakRc in jsg::Weak
WrappableWeakRclayout mirror (Rust and C++), the fivewrappable_weak_*shims andWrappable::toWeakRc().is_alive()calls the existingwrappable_is_condemned()on the referenttry_get()returns, andupgrade()still callstry_condemn(). Nothing callsKjRc::get_mut()on aWrappable, which satisfiesupgrade()'s precondition.is_alive()is now two FFI calls instead of one. I haven't benchmarked this.Testing
test_weak_rccovers downgrade,try_get, upgrade, clone, and expiry after the lastRcis dropped, including cloning an expired reference.//src/rust/...,//src/workerd/jsg/...and//src/workerd/api/tests:allpass, with and without--config=rust-debug. Clippy is clean on//src/rust/....//src/rust/cxx/...on its own.