← Back to Pull requests

Him188/revise on demand scope #2645

Merged
Him188 merged 24 files (1717 lines) on May 04, 2023 15:36 UTC
View on GitHub
Him188 Him188 commented on Apr 22, 2023 11:46 UTC
Author

挪到 mirai-core-utils, 重新审查状态设计 (降低复杂度), 增加文档 (注释), 增加测试

close #2633

Diff: 1717 lines (+1252 / -465) across 24 files Reviewer: Karlatemp Review duration: 17510m
All Vouch review confidence checks passed
Residual risk 0.11 = Change Risk (0.72) × (1 − Review Confidence (0.85)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.72 · 1717 lines diff across 24 files
0.72
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.79 · 5 substantive comment(s)
0.79
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
85%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Diff Size diff_size
0.400
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
7 items
Him188 Him188 commented on Apr 22, 2023 15:20 UTC
Author

java.lang.VerifyError: Bad type on operand stack |  
-- | --
  | Exception Details: |  
  | Location: |  
  | net/mamoe/mirai/utils/channels/CoroutineOnDemandReceiveChannel.receiveOrNull(Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @103: getfield |  
  | Reason: |  
  | Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'net/mamoe/mirai/utils/channels/CoroutineOnDemandReceiveChannel' |  
  | Current Frame: |  
  | bci: @103 |  
  | flags: { } |  
  | locals: { 'net/mamoe/mirai/utils/channels/CoroutineOnDemandReceiveChannel', 'kotlin/coroutines/Continuation', 'java/lang/Object', integer, top, top, top, top, top, top, top, 'java/lang/Object', 'net/mamoe/mirai/utils/channels/CoroutineOnDemandReceiveChannel$receiveOrNull$1', 'java/lang/Object' } |  
  | stack: { 'java/lang/Object' } |  
  | Bytecode:

https://scans.gradle.com/s/esafjm3w3klog/tests/:mirai-core:jvmTest/net.mamoe.mirai.internal.network.component.BotAuthControlTest/auth%20test()?top-execution=1

interesting

Him188 Him188 commented on Apr 23, 2023 13:25 UTC
Author

基本好了

  • 删除了 CreatingProducer 状态, 与 ProducerReady 合并, 因此修复了 producer 有可能会启动多次问题 (有可能不是, 具体忘了) (2.15.0-M1 受影响)

  • 修复了 producer 出异常会导致内存泄露问题 (2.15.0-M1 受影响)

  • 修复 expectMore 在 Producing state 不会抛异常的问题

  • 调整了异常的 mesage 以及 cause

  • 调整了 close (以前叫 finish) 的行为, 现在它与 Job.cancel 行为相似, 重复 close 不会抛出异常
  • producer 抛异常不会立即 close channel, 在下一次 receiveOrNull 时才会 close.
    假如 producer 抛异常时碰巧有人调用 close, 异常会被忽略.
    如果 producer 抛了异常, 而 receiver 没有 receiveOrNull 而 close, 异常也会被忽略.
    异常会被包装成 ProducerFailureException, 像这样:

    net.mamoe.mirai.utils.channels.ProducerFailureException: Producer failed to produce a value, see cause
    	at net.mamoe.mirai.utils.channels.CoroutineOnDemandReceiveChannel.receiveOrNull(OnDemandChannelImpl.kt:164)
    	at net.mamoe.mirai.utils.channels.CoroutineOnDemandReceiveChannel$receiveOrNull$1.invokeSuspend(OnDemandChannelImpl.kt)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    	at kotlinx.coroutines.test.TestBuildersKt.runTest$default(Unknown Source)
    	at net.mamoe.mirai.utils.channels.OnDemandChannelTest.producer exception(OnDemandChannelTest.kt:273)
    	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
    Caused by: java.util.NoSuchElementException: Oops
    	at net.mamoe.mirai.utils.channels.OnDemandChannelTest$producer exception$1$channel$1.invokeSuspend(OnDemandChannelTest.kt:275)
    	at net.mamoe.mirai.utils.channels.OnDemandChannelTest$producer exception$1$channel$1.invoke(OnDemandChannelTest.kt)
    	at net.mamoe.mirai.utils.channels.OnDemandChannelTest$producer exception$1$channel$1.invoke(OnDemandChannelTest.kt)
    	at net.mamoe.mirai.utils.channels.CoroutineOnDemandReceiveChannel$Producer$1.invokeSuspend(OnDemandChannelImpl.kt:46)
    	(Coroutine boundary)
    	at net.mamoe.mirai.utils.channels.CoroutineOnDemandReceiveChannel.receiveOrNull(OnDemandChannelImpl.kt:162)
    	at net.mamoe.mirai.utils.channels.OnDemandChannelTest$producer exception$1.invokeSuspend(OnDemandChannelTest.kt:280)
    	at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTestCoroutine$2.invokeSuspend(TestBuilders.kt:212)
    Caused by: java.util.NoSuchElementException: Oops
      ...
    

    在 BotAuth 时会最终以 BotAuthorizationException 之类的在 Bot.login 抛出

    TODO:

  • ~[ ] 测试 cancellation~

  • ~[ ] stress test~
  • UPDATE: 留到第二个 PR 再做

    Him188 Him188 commented on May 01, 2023 22:25 UTC
    Author

    @Karlatemp 你想 review 吗

    Karlatemp Karlatemp commented on code on May 02, 2023 15:22 UTC
    Code Review
    mirai-core/src/commonMain/kotlin/BotAccount.kt:1
    @@ -17,8 +17,13 @@ import net.mamoe.mirai.utils.TestOnly
     
     internal class BotAccount(
         internal val id: Long,
    -    val authorization: BotAuthorization,
    +    authorization: BotAuthorization,
     ) {
    +    var authorization: BotAuthorization = authorization
    +        // Making this mutable is very bad. 
    +        // But I had to do this because the current test framework is bad, and I don't have time to do a major rewrite. 
    +        @TestOnly set
    +

    //FIXME

    Karlatemp Karlatemp commented on May 02, 2023 15:34 UTC
    Reviewer

    没看具体实现, 看了一遍 test 感觉没啥问题, 实际登录测试过?

    Him188 Him188 commented on May 04, 2023 08:59 UTC
    Author

    e: file:///Users/runner/work/mirai/mirai/mirai-core-
    utils/src/commonMain/kotlin/UtilsLogger.kt:69:42 This can only be used in tests.
    
    e: file:///Users/runner/work/mirai/mirai/mirai-core-utils/src/commonMain/kotlin/UtilsLogger.kt:69:42 This can only be used in tests
    

    Reviewers
    Assignees
    Him188 Him188
    Labels
    risk: low confidence: 85.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.5% (HIGH) · Higher = larger blast radius
    71.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 85.1% · Lower = rushed or shallow review
    85.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 10.6% · Safe to merge
    10.6%
    Repository