Grab 如何通过安全处理 AI 生成代码变更激增,提升移动应用稳定性
原题How Grab Improved Mobile App Stability by Safely Handling Surge in AI-Generated Code Changes
读前速览
Grab 通过结合静态分析、上线前测试、分阶段发布和实时监控的多层防护策略,安全应对 AI 生成代码变更激增,同时保障移动应用在大规模运行中的稳定性。
AI 编程助手能加快开发速度,但代码变更量增加也带来了更高的崩溃风险和更多引入缺陷的机会。
对于 Grab 这样的规模而言,各产品团队频繁提交合并请求,且功能开关可以独立切换,因此存在多个可能引入崩溃的环节。传统质量关卡已不足以应对 AI 加速开发的需求。
多层防护策略通过静态分析、测试和上线前验证,将问题拦截在左移流程中,避免代码影响终端用户。
合并前的防护措施包括使用 Android Lint 和 SwiftLint 执行平台专属及自定义 lint 规则、开展全面的自动化和人工测试,以及通过 Grab Early Access(GEA)向内部用户分发应用。内部用户充当早期崩溃检测者,帮助避免问题在生产环境造成重大影响。
分阶段发布和功能开关可以控制生产环境中的功能开放范围,并迅速遏制有问题的代码或功能。
新版本最初只向一小部分用户发布,以便监测崩溃情况;功能开关则让团队能够逐步启用功能,并在某项功能的崩溃率超过预设阈值时立即将其关闭,无需重新发布应用。
实时崩溃监控和自动分流有助于在发布后快速响应事件并分析根本原因。
Firebase Crashlytics 和 BigQuery 会在构建版本发布后立即检测异常;自动分流会汇总崩溃元数据和堆栈跟踪,将崩溃关联到具体 PR。团队还会根据事件经验完善 lint 规则并扩大测试覆盖范围,形成反馈闭环。
完整摘要
面对 AI 生成代码增加所带来的崩溃风险,Grab 在整个开发生命周期中实施了多层防护策略。代码合并前,团队使用静态代码分析工具(Android Lint、SwiftLint),并进行自动化和人工测试;随后通过 Grab Early Access(GEA)向内部用户分发应用,以便及早发现崩溃。发布期间,分阶段发布和功能开关可控制生产环境中的功能开放范围,并能立即关闭有问题的功能。发布后,团队借助 Firebase Crashlytics 和 BigQuery 实时监控,快速响应事件、自动分流问题,并通过丰富的诊断信息将崩溃与具体 PR 关联起来。这种左移策略能及早发现崩溃,避免影响用户,并在 AI 辅助开发加快的情况下维持应用稳定性。
Grab 表示,AI 编码助手的日益普及加快了开发进程,也增加了每次发布的代码变更量,从而提高了出现缺陷和崩溃的可能性。为应对这些挑战,他们实施了分层防御策略,在整个开发和发布生命周期中预防、检测并控制崩溃。The growing adoption of AI coding assistants has accelerated development and increased the volume of code changes per release, bringing more opportunities for defects and crashes, says Grab. To address these challenges, they implemented a layered defense strategy to prevent, detect, and contain crashes throughout the development and release lifecycle.
Grab 指出:“AI 正在加快代码编写速度;分层防御则让这种速度变得安全。”:Grab observes that "AI is speeding up how fast code is written; the layered defense is what makes that speed safe":
以 [Grab] 的规模,崩溃问题流入生产环境始终是一项持续存在的风险。每周,众多产品团队都会提交大量合并请求,其中许多团队发布的功能都由独立于版本发布流程的功能开关控制。任何一项变更都可能引入崩溃。At [Grab's] scale, crashes leaking into production are an ongoing risk. A high volume of merge requests lands every week across many product teams, many shipping features behind flags that are switched on independently of releases. Any one of those changes can introduce a crash.
除了降低用户体验外,移动应用崩溃还会拉低无崩溃会话率,进而影响应用在 Google Play 上的排名。它还会带来更高的成本,因为并非所有用户都会启用自动更新,这意味着“已发布的移动应用崩溃会在用户设备上持续存在更长时间”。此外,并非所有崩溃都会附带清晰且已符号化的堆栈跟踪,这意味着“要找到原因,就必须交叉比对版本发布时间线、功能标志的逐步推出情况以及会话元数据”。Beyond degrading the user's experience, a mobile app's crash reduces crash-free session rates and, as a consequence, the app's Google Play ranking. It also has an increased cost because not all users enable automatic updates, meaning that "a mobile crash that ships stays on users' devices" for longer. Furthermore, not all crashes come with clean, symbolicated stack trace, which means that "finding the cause means cross-referencing release timelines, flag rollouts, and session metadata".
Grab 的分层防御采用左移策略,旨在通过贯穿开发周期各阶段的一系列防护措施,尽早发现崩溃:从合并前到预生产阶段,再到发布管控和发布后响应。Grab's layered defense follows a shift-left strategy aimed at catching crashes as early as possible through a series of safeguards along the development cycle phases: pre-merge through pre-production, release control, and post-release response.
在从合并前到预生产阶段,目标是预防,Grab 将其称为“首要防线”。为此,Grab 工程师会使用 Android Lint 和 SwiftLint 等静态代码分析工具,通过特定平台、社区维护和自定义的 lint 规则,在代码合并前发现问题;开展自动化和手动测试,包括单元测试、UI 测试和质量保证(QA)检查;并使用 Grab Early Access(GEA)这一预生产关卡,将早期构建版本分发给内部用户,并主动监控崩溃情况:During the pre-merge to pre-production phase, the goal is prevention, which Grab describes as its "primary line of defense". To achieve this, Grab engineers use static code analyzers such as Android Lint and SwiftLint to catch issues before code even merges via platform-specific, community-based, and custom lint rules; automated and manual testing, including unit tests, UI tests, and quality assurance (QA) checks; and Grab Early Access (GEA), a pre-production gate where early builds are distributed to internal users and actively monitored for crashes:
在 GEA 中只有少数内部用户遇到的崩溃,若发生在生产环境中,就会导致崩溃率大幅飙升、增加支持团队的工作量,还可能需要发布热修复。在这些崩溃影响到生产环境用户之前将其发现并拦截,使 GEA 成为我们最重要的稳定性关卡之一。A crash that only a handful of internal users see in GEA would, at production scale, translate into a substantial spike in the crash rate, extra support load, and potentially a hotfix. Catching these crashes before they ever reach production users makes GEA one of our most important stability gates.
在发布阶段,Grab 采用分阶段推出和功能标志来控制生产环境中的崩溃风险。分阶段推出可以让新版本的应用最初只覆盖一小部分用户,以便工程师监控崩溃情况,并在发现崩溃率异常时暂停推出。功能标志则允许团队逐步启用功能,同时监控这些功能对崩溃率的影响。如果某项功能导致崩溃率超过预设阈值,就可以立即停用,无需发布新版本。During the release phase, Grab uses staged rollout and feature flags to control production exposure to crashes. Staged rollout enables a new app version to reach only a small percentage of users initially, so engineers can monitor its crashes and possibly pause the rollout if an abnormal crash rate is detected. Features flags, in turn, allow teams to activate features gradually while monitoring their impact on crash rates. If a feature causes crash rates to exceed predefined thresholds, it be disabled immediately without requiring a new release.
在发布后阶段,Grab 专注于快速响应事件,并通过相关机制检测、调查和控制生产环境中的崩溃。这些机制包括:利用 Firebase Crashlytics 和 BigQuery 实时监控崩溃,以便在构建版本上线后立即发现异常;自动分流并丰富诊断信息,汇总崩溃元数据和堆栈跟踪,帮助团队将崩溃定位到具体的 PR;以及通过反馈闭环和事后分析,扩展 lint 规则并提高测试覆盖率。During the post-release phase, Grab focuses on rapid incident response using mechanisms to detect, investigate, and contain production crashes. These include real-time crash monitoring using Firebase Crashlytics and BigQuery to identify anomalies as soon as a build goes live; automated triage and enriched diagnostics to aggregate crash metadata and stack traces, helping teams to map crashes to specific PRs; and feedback loops and post-mortem analysis to extend lint rules and test coverage.
Grab 的分层防御方法远不止本文所能涵盖的内容。请务必阅读完整文章,了解所有详情。There is much more to Grab's layered defense approach than can be covered here. Be sure to read the full article for all the details.