← Back to Pull requests

feat(crash): flag recovered crash context and cache it per key #1341

Open
unknown opened this pull request with 467 lines diff across 5 files
View on GitHub
unknown unknown commented on Dec 02, 2026 07:21 UTC
Author

Summary

Two changes to KSCrashInstrumentation that came out of #1337.

Per-key user info. The crash context was written through KSCrash.userInfo, which KSCrash 2.6 deprecates in favour of the per-key API in KSCrash+UserInfo.h. That API writes to a memory-mapped sidecar with no crash-time cost, and KSCrash merges it into the report's user section on the next launch, so recoverCrashContext reads it as before, and reports written by earlier versions still recover. Each key is now set on its own: a session without a predecessor removes session.previous_id instead of keeping the last one. Every KSCrash version the package allows (upToNextMinor(from: "2.6.0")) has the API. It is also what #1337's proposal needs, since each context provider can then update its own key without rewriting the others.

crash.context.recovered. When the crashed run's timestamp and session can't be read back, the crash gets the reporting launch's time and session, and nothing on the record says so. Every device.crash record now carries crash.context.recovered, true or false, as suggested in this comment.

Refs #1337

Testing

  • The recovery tests assert the flag in both cases; both fail on main.

  • The per-key store has no getter, so the cache tests read the values back from a real report KSCrash writes. A new test checks that a session without a predecessor drops the old session.previous_id. testCacheCrashContext is renamed testReporterCachesCrashContext so it sorts after testInstallMethod, because per-key writes are ignored before install.

  • The crash stress tests pass with OTEL_CONCURRENCY_TESTS=1.

  • The integration tests assert that the crash reported on the next launch says its context was recovered. In a make integ-tests-ios run of this branch, all 12 CrashTests assertions pass against the crash and crash-report launches, so the session written through the per-key API survives a real crash. The run itself stopped later, at the app-start-background launch: my simulator (Xcode 27.2) rejects the silent push with UNErrorDomain 1401, which is unrelated to this change, so I ran the crash assertions on the collected output.

  • swift test --enable-all-traits passes locally.
  • Limitations

  • crash.context.recovered is not a semantic convention. The name is a proposal and easy to change before a release.

  • The crashed build's app and OS versions are not handled here. service.version and os.version come from the resource, which describes the reporting launch, so a crash from before an app or iOS update is reported under the new versions. KSCrash records the crashed build's versions in the report, but service.version is only defined as a resource attribute, so how to carry it on the record belongs in the #1337 discussion.

  • Caching the other tracked attributes, #1337's main proposal, is out of scope.
  • Checklist

  • swift test --enable-all-traits passes locally

  • Unit tests added or updated for the change

  • Instrumentation and event changes only: the integration tests in

  • Tests/IntegrationTests are updated. Anything that adds, removes or
    renames a span, log record, event name, or attribute emitted by an
    instrumentation (Sources/Instrumentation/**) must be exercised by
    IntegrationTestScenario in Examples/HackerNewsDemo and asserted on
    in Tests/IntegrationTests/Assertions. Run make integ-tests-ios to
    verify, and see Tests/IntegrationTests/README.md.
  • Documentation updated (README, doc comments) where behavior changed
  • 🤖 Generated with Claude Code

    Diff: 467 lines (+350 / -117) across 5 files Reviewer: aranhave Review duration: 4323m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.46) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 467 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.368
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1341"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 24.3% · Safe to merge
    24.3%