add-autogate

작성자: cloudflare

위험한 변경 사항을 점진적으로 롤아웃하기 위해 workerd에 새 자동 게이트를 추가하는 단계별 가이드(열거형 등록, 문자열 매핑, 사용 패턴 및 … 포함)

npx skills add https://github.com/cloudflare/workerd --skill add-autogate

Adding an Autogate

Autogates enable gradual rollout of risky code changes independent of binary releases. Unlike compatibility flags (which are permanent, date-based behavioral changes), autogates are temporary gates that can be toggled on/off via internal tooling during rollout, then removed once the change is stable.

When to use an autogate vs a compat flag

Use an autogate when...Use a compat flag when...
Rolling out a risky internal change graduallyChanging user-visible behavior permanently
You need a kill switch during rolloutThe change is tied to a compatibility date
The gate will be removed once stableUsers need to opt in or out explicitly

Autogates and compat flags are separate mechanisms — an autogate does not become a compat flag.

Step 1: Add the enum value

Edit src/workerd/util/autogate.h. Add a new entry to the AutogateKey enum before NumOfKeys:

enum class AutogateKey {
  TEST_WORKERD,
  // ... existing gates ...
  // Brief description of what this gate controls.
  MY_NEW_FEATURE,
  NumOfKeys  // Reserved for iteration.
};

Naming convention: SCREAMING_SNAKE_CASE for the enum value.

Step 2: Add the string mapping

Edit src/workerd/util/autogate.c++. Add a case to the KJ_STRINGIFY switch before the NumOfKeys case:

kj::StringPtr KJ_STRINGIFY(AutogateKey key) {
  switch (key) {
    // ... existing cases ...
    case AutogateKey::MY_NEW_FEATURE:
      return "my-new-feature"_kj;
    case AutogateKey::NumOfKeys:
      KJ_FAIL_ASSERT("NumOfKeys should not be used in getName");
  }
}

Naming convention: kebab-case for the string name. This string is what appears in runtime configuration (prefixed with workerd-autogate-). The enum name and string name should match to avoid confusion.

Step 3: Guard your code

Use Autogate::isEnabled() to conditionally execute the new code path:

#include <workerd/util/autogate.h>

// At the point where behavior should change:
if (util::Autogate::isEnabled(util::AutogateKey::MY_NEW_FEATURE)) {
  // New code path
} else {
  // Old code path (keep until gate is removed)
}

Step 4: Test

Three ways to test autogated code:

A. The @all-autogates test variant (automatic):

Every wd_test() and kj_test() generates a @all-autogates variant that enables all gates. If your feature is tested by existing tests, they'll automatically run with the gate enabled:

just stream-test //src/workerd/api/tests:my-test@all-autogates

B. Targeted C++ test setup:

In a C++ test file, enable specific gates:

#include <workerd/util/autogate.h>

// In test setup:
util::Autogate::initAutogateNamesForTest({"my-new-feature"_kj});

// In test teardown:
util::Autogate::deinitAutogate();

C. Environment variable:

Set WORKERD_ALL_AUTOGATES=1 to enable all gates when no explicit config is provided.

Step 5: Build and verify

just build
just stream-test //path/to:my-test@               # Old behavior (gate off)
just stream-test //path/to:my-test@all-autogates   # New behavior (gate on)

Step 6: Remove the gate (after rollout)

Once the human user explicitly confirms that the feature is stable and fully rolled out:

  1. Remove the AutogateKey enum value from autogate.h
  2. Remove the case from KJ_STRINGIFY in autogate.c++
  3. Remove all Autogate::isEnabled() checks, keeping only the new code path

Checklist

  • Enum value added to AutogateKey in autogate.h (before NumOfKeys)
  • Comment describes what the gate controls
  • String mapping added to KJ_STRINGIFY in autogate.c++
  • Code guarded with Autogate::isEnabled()
  • Old code path preserved (for rollback)
  • @all-autogates test variant passes
  • Tests cover both gated and ungated paths

Files touched

FileWhat to do
src/workerd/util/autogate.hAdd enum value with comment
src/workerd/util/autogate.c++Add case to KJ_STRINGIFY
Your feature file(s)Guard code with Autogate::isEnabled()

cloudflare의 다른 스킬

workerd-api-review
cloudflare
workerd 코드 리뷰를 위한 성능 최적화, API 설계 및 호환성, 보안 취약점, 표준 사양 준수. tcmalloc 인식…
official
workerd-safety-review
cloudflare
메모리 안전성, 스레드 안전성, 동시성, 그리고 workerd 코드 리뷰를 위한 중요 탐지 패턴. V8/KJ 경계 위험 요소, 수명 관리 등을 다룹니다.
official
module-registry
cloudflare
workerd에서 모듈 레지스트리를 작업할 때 로드 — 모듈 해석, 컴파일, 평가, 등록을 읽기, 수정, 디버깅, 검토하는 경우…
official
reproduce
cloudflare
cloudflare/agents GitHub 이슈를 재현하기 위해 최소한의 Agents/Worker 프로젝트를 스캐폴딩하고 임시 Cloudflare 계정에 배포한 후 보고합니다…
official
local-explorer
cloudflare
로컬 탐색기 또는 로컬 API에 제품/리소스를 추가하는 방법. 새로운 로컬 API나 UI 라우트를 구현할 때 사용합니다.
official
commit-categories
cloudflare
커밋을 체인지로그와 "새로운 기능" 요약으로 분류하는 규칙입니다. 체인지로그 또는 whats-new 명령에서 커밋을 분류하기 전에 반드시 로드되어야 합니다. 제공하는 기능:
official
architecture
cloudflare
코드베이스를 처음 탐색할 때, 새 클라이언트 메서드를 추가할 때, 새 컨테이너 핸들러/서비스를 추가할 때, 또는 요청 흐름을 이해할 때 사용합니다.
official
changesets
cloudflare
변경셋을 생성하거나, 릴리즈를 준비하거나, 버전을 올릴 때 사용합니다. 참조할 패키지, 사용자 대상 변경셋 설명 작성 방법 등을 다룹니다.
official