<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hiroshi Toyama</title>
    <description>The latest articles on DEV Community by Hiroshi Toyama (@toyama0919).</description>
    <link>https://dev.to/toyama0919</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F41804%2F7c54b968-6837-4276-9b8a-ac8f060c6f18.png</url>
      <title>DEV Community: Hiroshi Toyama</title>
      <link>https://dev.to/toyama0919</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/toyama0919"/>
    <language>en</language>
    <item>
      <title>Trace Sinks Are Gone. Here Is the Terraform That Replaces Them.</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Sat, 14 Nov 2026 13:48:08 +0000</pubDate>
      <link>https://dev.to/toyama0919/trace-sinks-are-gone-here-is-the-terraform-that-replaces-them-66g</link>
      <guid>https://dev.to/toyama0919/trace-sinks-are-gone-here-is-the-terraform-that-replaces-them-66g</guid>
      <description>&lt;p&gt;If you still export Cloud Trace to BigQuery through a sink, that pipeline is already dead. Per the &lt;a href="https://docs.cloud.google.com/trace/docs/release-notes" rel="noopener noreferrer"&gt;Trace release notes&lt;/a&gt;, trace sinks were deprecated on &lt;strong&gt;February 18, 2026&lt;/strong&gt;, and since &lt;strong&gt;August 31, 2026&lt;/strong&gt; you can no longer create or edit one. The replacement is Observability Analytics: a &lt;em&gt;linked dataset&lt;/em&gt; that exposes the trace storage to BigQuery with no copy of the data.&lt;/p&gt;

&lt;p&gt;The same mechanism exists for Cloud Logging, and that is where it gets confusing. Both features are called "linked dataset", both produce a BigQuery dataset holding a view, and both are configured with Terraform. Almost everything else about them differs. I wired up both in one project, and this is what actually had to be true.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two bucket systems that look like one
&lt;/h2&gt;

&lt;p&gt;The single biggest time sink: &lt;code&gt;_Trace&lt;/code&gt; is &lt;strong&gt;not&lt;/strong&gt; a Cloud Logging log bucket.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ gcloud logging buckets list --project=my-project
LOCATION  BUCKET_ID  RETENTION_DAYS  LIFECYCLE_STATE
global    _Default   30              ACTIVE
global    _Required  400             ACTIVE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No &lt;code&gt;_Trace&lt;/code&gt;. It is not hidden, it is not a permissions problem — it is in a different system entirely:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ gcloud observability buckets list --location=us --project=my-project
name: projects/my-project/locations/us/buckets/_Trace
description: Bucket &lt;span class="k"&gt;for&lt;/span&gt; storing spans from Cloud Trace.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note the location. Log buckets default to &lt;code&gt;global&lt;/code&gt;; observability buckets follow the project's observability default storage location, which here is &lt;code&gt;us&lt;/code&gt;. Any blog post or LLM answer telling you to point &lt;code&gt;google_logging_project_bucket_config&lt;/code&gt; at &lt;code&gt;_Trace&lt;/code&gt; in &lt;code&gt;global&lt;/code&gt; is wrong on both counts.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Cloud Trace&lt;/th&gt;
&lt;th&gt;Cloud Logging&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Storage&lt;/td&gt;
&lt;td&gt;observability bucket &lt;code&gt;_Trace&lt;/code&gt;, dataset &lt;code&gt;Spans&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;log bucket &lt;code&gt;_Default&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Location&lt;/td&gt;
&lt;td&gt;project's observability default (e.g. &lt;code&gt;us&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;global&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CLI&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gcloud observability buckets&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gcloud logging buckets&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Enable step&lt;/td&gt;
&lt;td&gt;none — the dataset already exists&lt;/td&gt;
&lt;td&gt;&lt;code&gt;enable_analytics = true&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Terraform&lt;/td&gt;
&lt;td&gt;&lt;code&gt;google_observability_link&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;google_logging_project_bucket_config&lt;/code&gt; + &lt;code&gt;google_logging_linked_dataset&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;View&lt;/td&gt;
&lt;td&gt;&lt;code&gt;_AllSpans&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;_AllLogs&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;While we are listing things that do not exist: &lt;strong&gt;there is no &lt;code&gt;google_cloud_trace_sink&lt;/code&gt; resource.&lt;/strong&gt; Ask an LLM for Terraform to export Cloud Trace to BigQuery and there is a good chance it invents one, because the API-level concept existed right up until it was turned off.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cloud Trace
&lt;/h2&gt;

&lt;p&gt;Terraform support for observability buckets and links landed on September 22, 2026, in provider &lt;code&gt;8.2.0&lt;/code&gt;. The link itself is four fields:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="s2"&gt;"google_project"&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;project_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;project_id&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_project_iam_member"&lt;/span&gt; &lt;span class="s2"&gt;"observability_bigquery"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;project&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;project_id&lt;/span&gt;
  &lt;span class="n"&gt;role&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"roles/bigquery.admin"&lt;/span&gt;
  &lt;span class="n"&gt;member&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"serviceAccount:service-${data.google_project.this.number}@gcp-sa-observability.iam.gserviceaccount.com"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# The grant needs time to propagate before the link is created.&lt;/span&gt;
&lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"time_sleep"&lt;/span&gt; &lt;span class="s2"&gt;"wait_observability_iam"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;create_duration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"90s"&lt;/span&gt;
  &lt;span class="n"&gt;depends_on&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;google_project_iam_member&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;observability_bigquery&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_observability_link"&lt;/span&gt; &lt;span class="s2"&gt;"trace"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;project&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;project_id&lt;/span&gt;
  &lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"us"&lt;/span&gt;      &lt;span class="c1"&gt;# must match the _Trace bucket, NOT global&lt;/span&gt;
  &lt;span class="n"&gt;bucket&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"_Trace"&lt;/span&gt;
  &lt;span class="n"&gt;dataset&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Spans"&lt;/span&gt;
  &lt;span class="n"&gt;link_id&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"trace_linked_dataset"&lt;/span&gt;   &lt;span class="c1"&gt;# becomes the BigQuery dataset name&lt;/span&gt;

  &lt;span class="n"&gt;depends_on&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;time_sleep&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wait_observability_iam&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The IAM grant is the part people skip. The dataset on the BigQuery side is created and managed by the Observability service agent, so without &lt;code&gt;roles/bigquery.admin&lt;/code&gt; on &lt;code&gt;service-&amp;lt;PROJECT_NUMBER&amp;gt;@gcp-sa-observability.iam.gserviceaccount.com&lt;/code&gt; the link creation fails. The service agent already exists if trace data has ever landed in the project; confirm with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud observability settings describe --location=global --project=my-project
&lt;span class="c"&gt;# serviceAccountId: service-123456789012@gcp-sa-observability.iam.gserviceaccount.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;link_id&lt;/code&gt; only accepts letters, digits and underscores — no hyphens, which is not the usual GCP naming convention and will bite you if you mirror your other dataset names.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cloud Logging
&lt;/h2&gt;

&lt;p&gt;Log buckets need Log Analytics switched on first, and &lt;code&gt;_Default&lt;/code&gt; already exists, so this resource &lt;em&gt;acquires&lt;/em&gt; it rather than creating it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_logging_project_bucket_config"&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;project&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;project_id&lt;/span&gt;
  &lt;span class="n"&gt;location&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"global"&lt;/span&gt;
  &lt;span class="n"&gt;bucket_id&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"_Default"&lt;/span&gt;
  &lt;span class="n"&gt;retention_days&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;          &lt;span class="c1"&gt;# match the current value or you will see a diff&lt;/span&gt;

  &lt;span class="n"&gt;enable_analytics&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_logging_linked_dataset"&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;parent&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"projects/${var.project_id}"&lt;/span&gt;   &lt;span class="c1"&gt;# not `project`&lt;/span&gt;
  &lt;span class="n"&gt;location&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"global"&lt;/span&gt;
  &lt;span class="n"&gt;bucket&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;google_logging_project_bucket_config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bucket_id&lt;/span&gt;
  &lt;span class="n"&gt;link_id&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"logging_linked_dataset"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three traps packed into ten lines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;enable_analytics&lt;/code&gt; cannot be disabled once enabled.&lt;/strong&gt; There is no undo on this one. Decide before you apply.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;_Default&lt;/code&gt; and &lt;code&gt;_Required&lt;/code&gt; are auto-created and cannot be deleted.&lt;/strong&gt; Terraform takes over the existing bucket on create, and &lt;code&gt;terraform destroy&lt;/code&gt; only drops it from state — the bucket and its logs stay. Harmless, but it means &lt;code&gt;retention_days&lt;/code&gt; is a live setting on a bucket that already has your logs in it, not a greenfield value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;google_logging_linked_dataset&lt;/code&gt; takes &lt;code&gt;parent&lt;/code&gt;, not &lt;code&gt;project&lt;/code&gt;.&lt;/strong&gt; It is the odd one out among Logging resources, and the error is a flat &lt;code&gt;An argument named "project" is not expected here.&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The 403 that creates the resource anyway
&lt;/h2&gt;

&lt;p&gt;First apply, with Application Default Credentials from &lt;code&gt;gcloud auth application-default login&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: Error waiting to create Link: googleapi: Error 403: Your application is
authenticating by using local Application Default Credentials. The
observability.googleapis.com API requires a quota project, which is not set by
default.
...
"consumer": "projects/32555940559",
"reason": "SERVICE_DISABLED"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That consumer project number is not yours — it is Google's shared &lt;code&gt;gcloud&lt;/code&gt; OAuth client. The Observability API refuses to bill the call to it and demands an explicit quota project. The Terraform-native fix is on the provider, not in your shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="n"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"google"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;project&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;project_id&lt;/span&gt;

  &lt;span class="n"&gt;billing_project&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;project_id&lt;/span&gt;
  &lt;span class="n"&gt;user_project_override&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the nasty part. The &lt;code&gt;POST&lt;/code&gt; succeeded; only the long-running-operation &lt;strong&gt;poll&lt;/strong&gt; got the 403. So the link exists in GCP while Terraform recorded a failure and wrote nothing to state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ gcloud observability buckets datasets links list \
    --bucket=_Trace --dataset=Spans --location=us --project=my-project
name: projects/my-project/locations/us/buckets/_Trace/datasets/Spans/links/trace_linked_dataset
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Re-running apply would just fail on "already exists". Import it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform import google_observability_link.trace \
  projects/my-project/locations/us/buckets/_Trace/datasets/Spans/links/trace_linked_dataset
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then apply converges to zero changes. Whenever an operation-based GCP resource fails &lt;em&gt;while waiting&lt;/em&gt;, check the API before assuming nothing happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  Querying: &lt;code&gt;--location=US&lt;/code&gt;, even for &lt;code&gt;global&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Both links produce an ordinary three-part BigQuery path. If you have seen a five-part &lt;code&gt;project.global._Trace.Spans._AllSpans&lt;/code&gt; floating around, that is not a thing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ bq --project_id=my-project ls
        datasetId
 -----------------------
  logging_linked_dataset
  trace_linked_dataset
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The counterintuitive bit is the location. &lt;code&gt;bq --location&lt;/code&gt; is the BigQuery &lt;em&gt;job&lt;/em&gt; location and has to match the dataset — it has nothing to do with the bucket the data came from. Both links here land in the &lt;code&gt;US&lt;/code&gt; multi-region, including the one attached to a &lt;code&gt;global&lt;/code&gt; log bucket:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ bq show --format=prettyjson trace_linked_dataset   &lt;span class="o"&gt;|&lt;/span&gt; grep location   &lt;span class="c"&gt;# "US"  (bucket: us)&lt;/span&gt;
$ bq show --format=prettyjson logging_linked_dataset &lt;span class="o"&gt;|&lt;/span&gt; grep location   &lt;span class="c"&gt;# "US"  (bucket: global)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;bq&lt;/code&gt; resolves the location on its own if you omit the flag, so this is less about remembering to pass &lt;code&gt;US&lt;/code&gt; and more about not passing the bucket's location out of habit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ bq query --location=global ...
BigQuery error &lt;span class="k"&gt;in&lt;/span&gt; query operation: Location global does not support this operation.

$ bq query --location=asia-northeast1 ...
Not found: Dataset my-project:trace_linked_dataset was not found &lt;span class="k"&gt;in&lt;/span&gt; location asia-northeast1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;global&lt;/code&gt; is not a BigQuery location at all. Read the dataset with &lt;code&gt;bq show&lt;/code&gt; instead of assuming the bucket location carries over.&lt;/p&gt;

&lt;p&gt;Trace spans, note the OTel-native column names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;trace_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;span_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start_time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;duration_nano&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1e6&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;duration_ms&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;status_code&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="sb"&gt;`my-project.trace_linked_dataset._AllSpans`&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;end_time&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;TIMESTAMP_SUB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;CURRENT_TIMESTAMP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;INTERVAL&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="no"&gt;HOUR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;start_time&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is &lt;code&gt;name&lt;/code&gt;, not &lt;code&gt;display_name&lt;/code&gt;; &lt;code&gt;attributes&lt;/code&gt; is a &lt;code&gt;JSON&lt;/code&gt; column, not a key-value RECORD; duration is &lt;code&gt;duration_nano&lt;/code&gt;. The Cloud Trace v2 API schema that most documentation describes is &lt;em&gt;not&lt;/em&gt; what you get in BigQuery — &lt;a href="https://dev.to/toyama0919/migrating-google-adk-to-telemetry-schema-v2-silently-broke-every-analytics-query-4fgi"&gt;spans arrive in the OpenTelemetry-shaped schema&lt;/a&gt;, and a query written against the API docs returns &lt;code&gt;Unrecognized name: display_name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="kt"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;severity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;log_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;resource_type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="nb"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text_payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;TO_JSON_STRING&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="sb"&gt;`my-project.logging_linked_dataset._AllLogs`&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="kt"&gt;timestamp&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;TIMESTAMP_SUB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;CURRENT_TIMESTAMP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;INTERVAL&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="no"&gt;HOUR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="kt"&gt;timestamp&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Joining traces to logs
&lt;/h2&gt;

&lt;p&gt;This is the payoff, and the two views disagree on how to spell a trace ID. &lt;code&gt;_AllSpans.trace_id&lt;/code&gt; is the bare 32-hex string; &lt;code&gt;_AllLogs.trace&lt;/code&gt; is the full resource name &lt;code&gt;projects/&amp;lt;id&amp;gt;/traces/&amp;lt;trace_id&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
  &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trace_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;span_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;duration_nano&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1e6&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;duration_ms&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nb"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;insert_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;log_count&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="sb"&gt;`my-project.trace_linked_dataset._AllSpans`&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="sb"&gt;`my-project.logging_linked_dataset._AllLogs`&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;
  &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="no"&gt;REGEXP_EXTRACT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"/traces/(.+)$"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trace_id&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end_time&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;TIMESTAMP_SUB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;CURRENT_TIMESTAMP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;INTERVAL&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="no"&gt;DAY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;duration_ms&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two separate linked datasets, one query, no ETL between them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you are actually buying
&lt;/h2&gt;

&lt;p&gt;The cost argument against the old Logging sink is simple: a sink writes a second physical copy into BigQuery, so you pay log bucket storage &lt;em&gt;and&lt;/em&gt; BigQuery storage forever. A linked dataset is zero-copy — &lt;code&gt;_AllSpans&lt;/code&gt; and &lt;code&gt;_AllLogs&lt;/code&gt; are views over the existing bucket, so BigQuery storage cost is zero and you only pay for bytes scanned.&lt;/p&gt;

&lt;p&gt;What it does &lt;strong&gt;not&lt;/strong&gt; buy you is retention. Spans in &lt;code&gt;_Trace&lt;/code&gt; are kept 30 days, &lt;code&gt;_Default&lt;/code&gt; logs 30 days, and the link does not extend either by a single hour. If you need year-over-year analysis, you still need a scheduled query copying into a real BigQuery table — the linked dataset is just a much better source for it than a sink was.&lt;/p&gt;




&lt;p&gt;Verified on &lt;code&gt;hashicorp/google&lt;/code&gt; 8.11.0, Terraform 1.9.5, gcloud 569.0.0 (&lt;code&gt;gcloud beta observability&lt;/code&gt; on that version; it went GA on September 23, 2026).&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>terraform</category>
      <category>bigquery</category>
      <category>observability</category>
    </item>
    <item>
      <title>Scope GitHub Actions concurrency to your Terraform state, not your branch</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Sat, 14 Nov 2026 08:37:54 +0000</pubDate>
      <link>https://dev.to/toyama0919/scope-github-actions-concurrency-to-your-terraform-state-not-your-branch-1kfe</link>
      <guid>https://dev.to/toyama0919/scope-github-actions-concurrency-to-your-terraform-state-not-your-branch-1kfe</guid>
      <description>&lt;p&gt;We turned on auto-merge for Dependabot security PRs. Within a day, deploys started failing with a GCS &lt;code&gt;412 Precondition Failed&lt;/code&gt; on the Terraform state lock.&lt;/p&gt;

&lt;p&gt;The cause is mechanical: the sweeper merges several PRs for the same service back to back, every merge pushes &lt;code&gt;main&lt;/code&gt;, every push to &lt;code&gt;main&lt;/code&gt; starts a deploy workflow, and every deploy runs &lt;code&gt;terraform apply&lt;/code&gt; against the same state object. Two &lt;code&gt;apply&lt;/code&gt; runs, one lock, one loser.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;concurrency&lt;/code&gt; is the right tool. But the obvious way to apply it is wrong in three separate ways, and we hit all three before landing on an eleven-line block. This is what we learned.&lt;/p&gt;

&lt;h2&gt;
  
  
  The primitive
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;concurrency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;any string or expression&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;cancel-in-progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="na"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;single&lt;/span&gt;   &lt;span class="c1"&gt;# default
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two facts about the runtime matter more than the syntax:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A concurrency group holds &lt;strong&gt;at most one running and one pending&lt;/strong&gt; entry. Group names are case-insensitive and scoped to the repository.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;queue: single&lt;/code&gt; (the default) means a newly arriving run &lt;strong&gt;cancels whatever is sitting in the pending slot&lt;/strong&gt; and takes its place. &lt;code&gt;cancel-in-progress: false&lt;/code&gt; protects the &lt;em&gt;running&lt;/em&gt; entry. It does nothing for the pending one. &lt;code&gt;queue: max&lt;/code&gt; raises the pending capacity to 100 and processes FIFO, but it cannot be combined with &lt;code&gt;cancel-in-progress: true&lt;/code&gt; — that is a workflow validation error.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That second point is the one people get wrong, and it is the difference between "every deploy eventually runs" and "only the latest deploy runs."&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 1: the group key is the lock identity
&lt;/h2&gt;

&lt;p&gt;The reflex is &lt;code&gt;group: ${{ github.workflow }}-${{ github.ref }}&lt;/code&gt;. That is the right key for PR CI, where the thing you are protecting is &lt;em&gt;a branch's build&lt;/em&gt;. It is the wrong key for Terraform, where the thing you are protecting is &lt;em&gt;a state object&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Two different workflows — a push to &lt;code&gt;main&lt;/code&gt; and a &lt;code&gt;workflow_dispatch&lt;/code&gt; — touch the same state and must serialize. Two pushes to different branches that deploy different services must not. The ref tells you neither.&lt;/p&gt;

&lt;p&gt;Our backend is GCS with a per-service prefix and a Terraform workspace per environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="c1"&gt;# my-service/terraform/main.tf&lt;/span&gt;
&lt;span class="n"&gt;backend&lt;/span&gt; &lt;span class="s2"&gt;"gcs"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;bucket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"tf-state-example"&lt;/span&gt;
  &lt;span class="n"&gt;prefix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"terraform/my-service"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform workspace &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="s2"&gt;"${ENVIRONMENT}"&lt;/span&gt;   &lt;span class="c"&gt;# dev | prod&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the lock identity is &lt;strong&gt;prefix × workspace&lt;/strong&gt; = service × environment. That is exactly what the group key encodes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# .github/workflows/my-service.yml
&lt;/span&gt;&lt;span class="na"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
  &lt;span class="na"&gt;concurrency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tfstate-my-service-${{ github.event_name == 'workflow_dispatch' &amp;amp;&amp;amp; inputs.environment || startsWith(github.ref, 'refs/tags/') &amp;amp;&amp;amp; 'prod' || 'dev' }}&lt;/span&gt;
    &lt;span class="na"&gt;cancel-in-progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
    &lt;span class="s"&gt;(github.event_name == 'push' &amp;amp;&amp;amp; (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/my-service-v'))) ||&lt;/span&gt;
    &lt;span class="s"&gt;github.event_name == 'workflow_dispatch'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;environment&lt;/code&gt; is in the group on purpose, not by accident. On a release we push a tag and merge to &lt;code&gt;main&lt;/code&gt; at nearly the same moment: the tag run deploys &lt;code&gt;prod&lt;/code&gt;, the &lt;code&gt;main&lt;/code&gt; run deploys &lt;code&gt;dev&lt;/code&gt;. Those are different workspaces, therefore different state objects, therefore no lock contention. Keeping &lt;code&gt;environment&lt;/code&gt; in the key lets them run in parallel. We have the receipt — on one release the &lt;code&gt;prod&lt;/code&gt; tag run and the &lt;code&gt;main&lt;/code&gt; run started three seconds apart and both succeeded.&lt;/p&gt;

&lt;p&gt;Collapse that to a single &lt;code&gt;group: tfstate-my-service&lt;/code&gt; and you have just serialized two deploys that never needed to be serialized, doubling release wall-clock for no benefit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 2: &lt;code&gt;cancel-in-progress: false&lt;/code&gt; is mandatory, and it is not enough
&lt;/h2&gt;

&lt;p&gt;Killing a &lt;code&gt;terraform apply&lt;/code&gt; mid-flight is the worst outcome available. The provider is in the middle of API calls; the process dies between "resource created" and "state written"; now your state and your infrastructure disagree and someone is doing a manual &lt;code&gt;terraform import&lt;/code&gt; on a Friday. &lt;code&gt;cancel-in-progress: false&lt;/code&gt; is non-negotiable here.&lt;/p&gt;

&lt;p&gt;But remember the pending slot. With the default &lt;code&gt;queue: single&lt;/code&gt;, if deploy A is applying and B and C both arrive, B gets evicted by C and never runs.&lt;/p&gt;

&lt;p&gt;For us that is fine, and it is worth being explicit about &lt;em&gt;why&lt;/em&gt; rather than just accepting it: on &lt;code&gt;main&lt;/code&gt;, commit C contains commit B. Running only C converges to the same infrastructure. The same holds for tags, where a later tag includes the earlier one.&lt;/p&gt;

&lt;p&gt;If your deploys are &lt;em&gt;not&lt;/em&gt; cumulative — per-tenant applies, migrations that must each execute, anything where skipping an intermediate run loses work — then &lt;code&gt;queue: max&lt;/code&gt; is what you want, and you accept the FIFO backlog that comes with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 3: keep the read-only job out of the group
&lt;/h2&gt;

&lt;p&gt;This is where we burned the most time.&lt;/p&gt;

&lt;p&gt;The workflow has two Terraform jobs: &lt;code&gt;plan&lt;/code&gt; (a reusable workflow, PR diff preview) and &lt;code&gt;deploy&lt;/code&gt; (&lt;code&gt;apply&lt;/code&gt;). The first instinct is that both touch state, so both belong in the group.&lt;/p&gt;

&lt;p&gt;Attempt 1 put &lt;code&gt;concurrency&lt;/code&gt; on both. The group expressions did not match, because the reusable &lt;code&gt;terraform-plan.yml&lt;/code&gt; did not receive the environment input and always planned the &lt;code&gt;dev&lt;/code&gt; workspace even when you dispatched with &lt;code&gt;environment: prod&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Attempt 2 fixed that properly — added an &lt;code&gt;environment&lt;/code&gt; input to the reusable workflow, threaded &lt;code&gt;inputs.environment&lt;/code&gt; through, and the two group expressions became identical. The stated justification was that &lt;code&gt;plan&lt;/code&gt; and &lt;code&gt;deploy&lt;/code&gt; run concurrently &lt;em&gt;within the same run&lt;/em&gt;, since &lt;code&gt;deploy&lt;/code&gt; has no &lt;code&gt;needs: plan&lt;/code&gt;, and a run-level &lt;code&gt;concurrency&lt;/code&gt; cannot protect against same-run contention.&lt;/p&gt;

&lt;p&gt;That justification was simply false. &lt;code&gt;plan&lt;/code&gt; has &lt;code&gt;needs: build&lt;/code&gt;, and &lt;code&gt;build&lt;/code&gt; only runs on feature branches:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
    &lt;span class="s"&gt;github.event_name == 'push' &amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="kt"&gt;!startsWith(github.ref,&lt;/span&gt; &lt;span class="s1"&gt;'refs/heads/main'&lt;/span&gt;&lt;span class="s"&gt;) &amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="kt"&gt;!startsWith(github.ref,&lt;/span&gt; &lt;span class="s1"&gt;'refs/tags/'&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So &lt;code&gt;plan&lt;/code&gt; never executes on a &lt;code&gt;main&lt;/code&gt; push, a tag, or a dispatch — which is to say, it never shares a run with &lt;code&gt;deploy&lt;/code&gt;. The entire premise was wrong, and we had modified a shared reusable workflow to satisfy it.&lt;/p&gt;

&lt;p&gt;The real contention is cross-run: a feature branch's &lt;code&gt;plan&lt;/code&gt; against some other run's &lt;code&gt;apply&lt;/code&gt;. And since &lt;code&gt;plan&lt;/code&gt; is read-only, that is solved at the Terraform layer instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# my-service/scripts/ci.sh&lt;/span&gt;
&lt;span class="c"&gt;# plan is read-only. In CI it can run alongside deploy's terraform apply,&lt;/span&gt;
&lt;span class="c"&gt;# so it does not take the state lock (-lock=false). Taking it fails with GCS 412.&lt;/span&gt;
terraform plan -lock=false -var=&lt;span class="s2"&gt;"image_tag=${TAG}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, the decisive argument against the concurrency-group approach for &lt;code&gt;plan&lt;/code&gt;, which is the part worth stealing:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A group keyed on service × environment spans every branch.&lt;/strong&gt; Put &lt;code&gt;plan&lt;/code&gt; in it and a push on branch X can evict branch Y's pending &lt;code&gt;plan&lt;/code&gt;. A cancelled job reports &lt;code&gt;CANCELLED&lt;/code&gt; — and our auto-merge gate treats &lt;code&gt;CANCELLED&lt;/code&gt; exactly like &lt;code&gt;FAILURE&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;.conclusion &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"FAILURE"&lt;/span&gt; or .conclusion &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"TIMED_OUT"&lt;/span&gt;
      or .conclusion &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"CANCELLED"&lt;/span&gt; or .conclusion &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"ACTION_REQUIRED"&lt;/span&gt;
      or .conclusion &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"STARTUP_FAILURE"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="s2"&gt;"failure"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the concurrency control you added to protect deploys would turn unrelated PRs red and block the very auto-merge sweep that started this whole investigation. Serialization primitives that are correct for a mutating job are actively harmful when applied to a read-only one sharing the same key.&lt;/p&gt;

&lt;p&gt;The end state is one &lt;code&gt;concurrency&lt;/code&gt; block per workflow, on &lt;code&gt;deploy&lt;/code&gt; only. The reusable &lt;code&gt;plan&lt;/code&gt; workflow went back to having no environment input at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Workflow level or job level?
&lt;/h2&gt;

&lt;p&gt;Top-level &lt;code&gt;concurrency&lt;/code&gt; groups the entire workflow run. Job-level groups that one job. Both are valid schema and both can be present, evaluated independently.&lt;/p&gt;

&lt;p&gt;For a build-plan-deploy pipeline, job level is the only correct choice. The run as a whole is not the unit that contends for the lock — one specific job is. Hoisting it to the top would drag &lt;code&gt;build&lt;/code&gt; and &lt;code&gt;plan&lt;/code&gt; into the same serialization domain and reproduce exactly the cross-branch cancellation problem above.&lt;/p&gt;

&lt;h2&gt;
  
  
  Division of labor with the backend lock
&lt;/h2&gt;

&lt;p&gt;Keep both. They fail differently.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mechanism&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;th&gt;Failure mode&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;GitHub Actions &lt;code&gt;concurrency&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Queues the CI job before it starts&lt;/td&gt;
&lt;td&gt;Blind to a &lt;code&gt;terraform apply&lt;/code&gt; from someone's laptop&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Terraform backend lock (GCS / DynamoDB)&lt;/td&gt;
&lt;td&gt;Rejects a concurrent apply with an error&lt;/td&gt;
&lt;td&gt;A second CI job fails red instead of waiting&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The backend lock is correctness; it catches the human running &lt;code&gt;apply&lt;/code&gt; locally. &lt;code&gt;concurrency&lt;/code&gt; is ergonomics; it converts "the second run errors out" into "the second run waits its turn," which is what keeps a back-to-back merge sweep green.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Key the group on &lt;strong&gt;what holds the lock&lt;/strong&gt; — backend prefix × workspace — not on &lt;code&gt;github.ref&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Keep &lt;code&gt;environment&lt;/code&gt; in the key so &lt;code&gt;dev&lt;/code&gt; and &lt;code&gt;prod&lt;/code&gt; deploys stay parallel. They are separate state objects.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cancel-in-progress: false&lt;/code&gt; always, for anything running &lt;code&gt;apply&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Know that it does not protect the pending slot. Default &lt;code&gt;queue: single&lt;/code&gt; evicts it. Reach for &lt;code&gt;queue: max&lt;/code&gt; only if your deploys are not cumulative.&lt;/li&gt;
&lt;li&gt;Put read-only &lt;code&gt;plan&lt;/code&gt; outside the group and give it &lt;code&gt;-lock=false&lt;/code&gt;. A cross-branch group will cancel pending CI, and a cancelled check reads as a failure to every merge gate you own.&lt;/li&gt;
&lt;li&gt;Job level, not workflow level.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>githubactions</category>
      <category>terraform</category>
      <category>devops</category>
      <category>cicd</category>
    </item>
    <item>
      <title>Five Things That Make Dependabot Painful for Terraform</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Mon, 02 Nov 2026 12:59:11 +0000</pubDate>
      <link>https://dev.to/toyama0919/five-things-that-make-dependabot-painful-for-terraform-37le</link>
      <guid>https://dev.to/toyama0919/five-things-that-make-dependabot-painful-for-terraform-37le</guid>
      <description>&lt;p&gt;A Terraform block in &lt;code&gt;dependabot.yml&lt;/code&gt; looks identical to an npm or uv one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;package-ecosystem&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform&lt;/span&gt;
  &lt;span class="na"&gt;directory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/terraform/env&lt;/span&gt;
  &lt;span class="na"&gt;schedule&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;interval&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;weekly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It behaves nothing like one. We rolled Dependabot out across a GCP monorepo — four deployable services, eight Terraform directories, a shared infra root — and the Terraform half cost more time than every other ecosystem combined. Here is what actually bit us, and what the fixes look like.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. &lt;code&gt;directory&lt;/code&gt; takes one literal path, so a monorepo means N copies of the same block
&lt;/h2&gt;

&lt;p&gt;There is no globbing in the singular &lt;code&gt;directory&lt;/code&gt; key. Our repo splits Terraform ownership: Cloud Run services and their observability live under each service's own &lt;code&gt;terraform/&lt;/code&gt;, while service accounts, IAM, shared VPC and Cloud SQL live in a root &lt;code&gt;terraform/&lt;/code&gt;. That is eight directories:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/terraform/env
/terraform/common
/app-a/terraform
/services/svc-a/terraform
/services/svc-b/terraform
/services/svc-c/terraform
/app-b/terraform
/app-b/terraform/sub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eight near-identical 15-line entries, each with its own copy of the schedule, the PR limit, the labels and the group block. Changing the cadence means editing eight places. Adding a service means remembering to add a ninth.&lt;/p&gt;

&lt;p&gt;The fix is the &lt;strong&gt;plural&lt;/strong&gt; &lt;code&gt;directories&lt;/code&gt; key, which does support globs — and the docs are explicit that the singular key does not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;package-ecosystem&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform&lt;/span&gt;
  &lt;span class="na"&gt;directories&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/terraform/*"&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/*/terraform"&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/services/*/terraform"&lt;/span&gt;
  &lt;span class="na"&gt;schedule&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;interval&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;weekly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the single highest-leverage change available, and it is easy to miss because every blog post and every generated starter config uses the singular form.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;code&gt;google&lt;/code&gt; and &lt;code&gt;google-beta&lt;/code&gt; drift apart, and the PR limit guarantees it
&lt;/h2&gt;

&lt;p&gt;The GCP provider ships as two packages that must move together. If &lt;code&gt;google&lt;/code&gt; is on 8.x and &lt;code&gt;google-beta&lt;/code&gt; is still on 7.x, &lt;code&gt;terraform init&lt;/code&gt; starts failing on resources that exist in both.&lt;/p&gt;

&lt;p&gt;Dependabot treats them as two independent dependencies. Combine that with the conventional &lt;code&gt;open-pull-requests-limit: 1&lt;/code&gt; for Terraform, and you get a PR that bumps exactly one of the pair — with no indication that the other half exists. Here is what one week produced in our repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#1206  bump hashicorp/google      7.44.0 -&amp;gt; 8.8.1  in /app-a/terraform
#1207  bump hashicorp/google-beta 7.45.0 -&amp;gt; 8.8.1  in /services/svc-c/terraform
#1203  bump hashicorp/google      7.44.0 -&amp;gt; 8.8.1  in /services/svc-b/terraform
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three directories, three PRs, and &lt;strong&gt;each one covers a different half of the pair&lt;/strong&gt;. Merge any of them in isolation and that directory is in a split state. Nothing in the PR tells you this; the title reads like a routine patch bump.&lt;/p&gt;

&lt;p&gt;The fix is a group with a catch-all pattern, one per directory, so the directory's providers move as a unit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;groups&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;terraform-providers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;patterns&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note what is deliberately missing: &lt;code&gt;update-types&lt;/code&gt;. For the other ecosystems we restrict the catch-all group to &lt;code&gt;minor&lt;/code&gt; and &lt;code&gt;patch&lt;/code&gt; so that majors arrive as isolated, reviewable PRs. For Terraform providers you want the opposite — the major must travel with its sibling, so the group has to swallow majors too.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The shape of the PR depends on whether the lock file is committed
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;.terraform.lock.hcl&lt;/code&gt; is committed in some of our directories and gitignored in others. That one difference produces three distinct kinds of PR from the same ecosystem:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Directory state&lt;/th&gt;
&lt;th&gt;What the PR actually changes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Lock committed, constraint too narrow (&lt;code&gt;~&amp;gt; 7.0&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;required_providers&lt;/code&gt; constraint &lt;strong&gt;and&lt;/strong&gt; the lock file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lock gitignored (&lt;code&gt;/terraform/env&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Constraint only — a one-line diff&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lock committed, constraint already permissive (&lt;code&gt;&amp;gt;= 5.0&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Lock file only — the constraint is untouched&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The third case is the dangerous one. Our &lt;code&gt;svc-a&lt;/code&gt; Terraform uses &lt;code&gt;&amp;gt;= 5.0&lt;/code&gt;, so the constraint already allows 8.x. Dependabot never touches &lt;code&gt;versions.tf&lt;/code&gt;; it silently rewrites the lock to a new major. A reviewer scanning for a version-constraint change sees none, and the diff is 50 lines of &lt;code&gt;zh:&lt;/code&gt; hashes that nobody reads.&lt;/p&gt;

&lt;p&gt;This also quietly breaks the cross-directory grouping feature described below: the docs note that when directories carry &lt;strong&gt;incompatible version constraints&lt;/strong&gt; for the same dependency, Dependabot falls back to separate PRs. We have &lt;code&gt;~&amp;gt; 8.8&lt;/code&gt; in five directories, &lt;code&gt;~&amp;gt; 8.6&lt;/code&gt; in one and &lt;code&gt;&amp;gt;= 5.0&lt;/code&gt; in another, so we are squarely in that case.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. CI verifies nothing, and it looks green anyway
&lt;/h2&gt;

&lt;p&gt;This is the one that actually matters. A Terraform provider major is exactly the change where you want &lt;code&gt;terraform plan&lt;/code&gt; to run — and &lt;code&gt;plan&lt;/code&gt; is exactly the job that cannot run on a Dependabot PR.&lt;/p&gt;

&lt;p&gt;Workflow runs triggered by Dependabot do not get the &lt;code&gt;id-token: write&lt;/code&gt; permission needed for OIDC against a cloud provider. Rather than let the job fail every week, the usual answer is to split it and gate it on the actor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# install deps, lint, test, docker build — no cloud credentials needed&lt;/span&gt;
  &lt;span class="na"&gt;plan&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;build&lt;/span&gt;
    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github.actor != 'dependabot[bot]'&lt;/span&gt;
    &lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;
      &lt;span class="na"&gt;id-token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is a reasonable design. The consequence is that &lt;code&gt;gh pr checks&lt;/code&gt; on a Terraform Dependabot PR looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add-to-project      skipping
plan                skipping
request-reviewer    skipping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything skipping. And for &lt;code&gt;/terraform/env&lt;/code&gt; it is worse — that path matches no workflow's &lt;code&gt;paths:&lt;/code&gt; filter at all, so the PR has &lt;strong&gt;zero checks&lt;/strong&gt;. A provider major bump sitting there with nothing red, because nothing ran.&lt;/p&gt;

&lt;p&gt;The honest framing: for Terraform, Dependabot is a &lt;em&gt;notification&lt;/em&gt; mechanism, not a verification one. Treat a green Terraform PR as "a new version exists," not as "this version works." The verification has to happen when a human runs &lt;code&gt;plan&lt;/code&gt; against real state, and no amount of config changes that.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. One unreachable private module fails the entire update job
&lt;/h2&gt;

&lt;p&gt;Our shared Terraform pulls modules from a private repo in a different GitHub org over an SSH source:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"something"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"git::ssh://git@github.com/other-org/terraform-modules//path?ref=v1.2.3"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dependabot cannot authenticate to that. The failure mode is not "skip this module and update the rest" — the whole update job for that directory dies with &lt;code&gt;git_dependencies_not_reachable&lt;/code&gt;, every week, so the providers in that same directory never get checked either. Since it is a different org and an SSH source, there is no credential you can hand Dependabot to fix it.&lt;/p&gt;

&lt;p&gt;The workaround is to exclude it, and the syntax is genuinely hard to guess:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;ignore&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;dependency-name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*::github::other-org/*"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;*::github::owner/*&lt;/code&gt; form is the Terraform-specific dependency-name shape. It is worth writing the pattern against the whole org rather than a single repo, so that referencing a second module from the same org later does not resurrect the problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: closing a Dependabot PR is more final than it looks
&lt;/h2&gt;

&lt;p&gt;When you close a Dependabot PR, it replies:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;OK, I won't notify you again about this release, but will get in touch when a new version is available.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is a permanent decision for that specific version. Dependabot also deletes the branch. Once the branch is gone, &lt;code&gt;@dependabot reopen&lt;/code&gt; does nothing — the comment is simply ignored. If you close a batch of PRs and then realize you wanted some of them, the ones whose branches are already deleted cannot be recovered through the GitHub API either; you have to reconstruct the updates by hand.&lt;/p&gt;

&lt;p&gt;Close with more care than the lightweight-looking UI suggests, especially when bulk-closing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we ended up with
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;One group per Terraform directory with &lt;code&gt;patterns: ["*"]&lt;/code&gt; and no &lt;code&gt;update-types&lt;/code&gt; filter, so &lt;code&gt;google&lt;/code&gt; and &lt;code&gt;google-beta&lt;/code&gt; always move together.&lt;/li&gt;
&lt;li&gt;An org-wide &lt;code&gt;ignore&lt;/code&gt; pattern for the unreachable private module source.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;plan&lt;/code&gt; split out of &lt;code&gt;build&lt;/code&gt; and gated on &lt;code&gt;github.actor != 'dependabot[bot]'&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A written note that Terraform PRs carry no verification signal, so they are reviewed differently from npm and uv ones.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When the dust settled, seven Dependabot PRs were replaced by a single hand-made one touching 16 files across eight directories — which is roughly the honest unit of work for a GCP provider major in a monorepo.&lt;/p&gt;

&lt;p&gt;The piece still on the table is consolidation. GitHub shipped cross-directory grouping in February 2026: list paths under &lt;code&gt;directories&lt;/code&gt; and set &lt;code&gt;group-by: dependency-name&lt;/code&gt; on a group, and you get one PR per dependency across every directory instead of one per directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;package-ecosystem&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform&lt;/span&gt;
  &lt;span class="na"&gt;directories&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/terraform/*"&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/*/terraform"&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/services/*/terraform"&lt;/span&gt;
  &lt;span class="na"&gt;groups&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;gcp-providers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;group-by&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dependency-name&lt;/span&gt;
      &lt;span class="na"&gt;patterns&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hashicorp/google*"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the shape this problem wants. The catch is the constraint-compatibility rule from gotcha 3 — directories with mismatched constraints split back out into separate PRs — so the prerequisite is boring housekeeping: get every directory onto the same constraint first, then let the grouping do its job.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Problem&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;One entry per directory&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;directories&lt;/code&gt; (plural) with globs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;google&lt;/code&gt; / &lt;code&gt;google-beta&lt;/code&gt; split across PRs&lt;/td&gt;
&lt;td&gt;Per-directory group, &lt;code&gt;patterns: ["*"]&lt;/code&gt;, no &lt;code&gt;update-types&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lock-only PRs hide major bumps&lt;/td&gt;
&lt;td&gt;Align constraints; read lock diffs, not just &lt;code&gt;.tf&lt;/code&gt; diffs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;plan&lt;/code&gt; cannot run on Dependabot PRs&lt;/td&gt;
&lt;td&gt;Split &lt;code&gt;build&lt;/code&gt; / &lt;code&gt;plan&lt;/code&gt;, gate on actor, and stop reading green as "verified"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Private module kills the whole job&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ignore: dependency-name: "*::github::org/*"&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Closing a PR is permanent&lt;/td&gt;
&lt;td&gt;Bulk-close deliberately; branches are deleted and &lt;code&gt;reopen&lt;/code&gt; fails&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;None of these are bugs. They all follow from Dependabot treating Terraform providers as ordinary package dependencies, when in practice a provider major is an infrastructure change whose only real test is a plan against live state.&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>devops</category>
      <category>github</category>
      <category>dependabot</category>
    </item>
    <item>
      <title>Migrating Google ADK to Telemetry Schema v2 Silently Broke Every Analytics Query</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Sun, 01 Nov 2026 12:31:40 +0000</pubDate>
      <link>https://dev.to/toyama0919/migrating-google-adk-to-telemetry-schema-v2-silently-broke-every-analytics-query-4fgi</link>
      <guid>https://dev.to/toyama0919/migrating-google-adk-to-telemetry-schema-v2-silently-broke-every-analytics-query-4fgi</guid>
      <description>&lt;p&gt;Upgrading Google ADK from 2.7 to 2.13, I also flipped telemetry from ADK's own schema v1 to schema v2, which follows the OpenTelemetry GenAI semantic conventions.&lt;/p&gt;

&lt;p&gt;The upgrade itself was uneventful. What was not: every BigQuery query reading our Cloud Trace spans started returning zero rows. No errors, no warnings. &lt;code&gt;WHERE name = 'call_llm'&lt;/code&gt; simply stopped matching anything, because that span no longer exists.&lt;/p&gt;

&lt;p&gt;Here are the six traps I hit, in the order they cost me time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup: spans read from BigQuery
&lt;/h2&gt;

&lt;p&gt;Some context on the pipeline, because it explains why the breakage was silent.&lt;/p&gt;

&lt;p&gt;Agent spans go to Cloud Trace, and we query them from BigQuery with SQL. We want to aggregate "which agent, with what instruction, what the user said, what the model answered" after the fact, so eyeballing the trace UI is not enough.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Agent (Cloud Run)
        │  OTel spans
        ▼
  SpanProcessor wrapper  ──  shrinks attributes over 64 KiB
        │  export
        ▼
  Cloud Trace  _Trace bucket  (30-day retention)
        │
        │  google_observability_link
        ▼
  BigQuery  dataset: cloud_trace_spans
        └── _AllSpans   (a VIEW — no copy of the data)
                │  bq query --location=us
                ▼
          analytics queries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A common misreading: &lt;strong&gt;this is not a Logging sink.&lt;/strong&gt; Nothing is routed through the log router into BigQuery. It is a &lt;em&gt;linked dataset&lt;/em&gt; attached to Cloud Trace's &lt;code&gt;_Trace&lt;/code&gt; bucket:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_observability_link"&lt;/span&gt; &lt;span class="s2"&gt;"cloud_trace_spans"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"us"&lt;/span&gt;
  &lt;span class="nx"&gt;bucket&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"_Trace"&lt;/span&gt;
  &lt;span class="nx"&gt;dataset&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Spans"&lt;/span&gt;
  &lt;span class="nx"&gt;link_id&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"cloud_trace_spans"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# The link needs BigQuery permission on the observability service agent&lt;/span&gt;
&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_project_iam_member"&lt;/span&gt; &lt;span class="s2"&gt;"observability_bigquery_admin"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;project&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project_id&lt;/span&gt;
  &lt;span class="nx"&gt;role&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"roles/bigquery.admin"&lt;/span&gt;
  &lt;span class="nx"&gt;member&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"serviceAccount:service-${data.google_project.project.number}@gcp-sa-observability.iam.gserviceaccount.com"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three properties of this setup matter later:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;_AllSpans&lt;/code&gt; is a VIEW, not a table.&lt;/strong&gt; No data is copied, so retention follows Cloud Trace (30 days by default). There is no "dig into last year's data".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The dataset lives in &lt;code&gt;us&lt;/code&gt;.&lt;/strong&gt; Without &lt;code&gt;--location=us&lt;/code&gt;, &lt;code&gt;bq query&lt;/code&gt; tells you the dataset does not exist.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;All span attributes arrive in a single JSON column&lt;/strong&gt; called &lt;code&gt;attributes&lt;/code&gt;. So every analytics query looks like this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$."gen_ai.input.messages"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="k"&gt;input&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nv"&gt;`&amp;lt;project&amp;gt;.cloud_trace_spans._AllSpans`&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;start_time&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;TIMESTAMP_SUB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;CURRENT_TIMESTAMP&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;INTERVAL&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="k"&gt;DAY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That last property is the direct cause of the incident. &lt;strong&gt;JSON paths have no schema and no type checking.&lt;/strong&gt; Point &lt;code&gt;JSON_VALUE&lt;/code&gt; at a key that does not exist and it returns &lt;code&gt;NULL&lt;/code&gt; without complaint. Misspell a real column name and BigQuery stops you instantly; misspell a JSON path and it says nothing at all.&lt;/p&gt;

&lt;p&gt;So when schema v2 renamed every attribute, the queries kept succeeding and started returning zero rows. That is how an entire analytics pipeline breaks without anyone noticing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually changes
&lt;/h2&gt;

&lt;p&gt;Schema v2 is gated behind &lt;code&gt;ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN=2&lt;/code&gt;. The mapping:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;v1&lt;/th&gt;
&lt;th&gt;v2&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;LLM call span&lt;/td&gt;
&lt;td&gt;&lt;code&gt;call_llm&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;generate_content &amp;lt;model&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Agent span&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;invocation&lt;/code&gt; / &lt;code&gt;agent_run [name]&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;invoke_agent &amp;lt;name&amp;gt;&lt;/code&gt; / &lt;code&gt;invoke_workflow &amp;lt;name&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tool span&lt;/td&gt;
&lt;td&gt;&lt;code&gt;execute_tool &amp;lt;name&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;execute_tool &amp;lt;name&amp;gt;&lt;/code&gt; (unchanged)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LLM request body&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gcp.vertex.agent.llm_request&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gen_ai.input.messages&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LLM response body&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gcp.vertex.agent.llm_response&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gen_ai.output.messages&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;System instruction&lt;/td&gt;
&lt;td&gt;inside &lt;code&gt;llm_request&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gen_ai.system_instructions&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tool definitions&lt;/td&gt;
&lt;td&gt;inside &lt;code&gt;llm_request&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gen_ai.tool.definitions&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tool arguments&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gcp.vertex.agent.tool_call_args&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gen_ai.tool.call.arguments&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tool result&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gcp.vertex.agent.tool_response&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gen_ai.tool.call.result&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Agent name&lt;/td&gt;
&lt;td&gt;embedded in span name&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gen_ai.agent.name&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;v1 stuffs whole JSON blobs into single attributes; v2 splits them by meaning. The direction is right, but every reference you have breaks at once.&lt;/p&gt;

&lt;p&gt;Note the dots in &lt;code&gt;gen_ai.tool.definitions&lt;/code&gt;. I wrote &lt;code&gt;gen_ai.tool_definitions&lt;/code&gt; in a design doc and nobody caught it until someone ran it. Pull the constant instead of trusting your memory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;opentelemetry.semconv._incubating.attributes&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;gen_ai_attributes&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GEN_AI_TOOL_DEFINITIONS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# gen_ai.tool.definitions
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Trap 1: without SPAN_ONLY, no content is recorded at all
&lt;/h2&gt;

&lt;p&gt;This one cost the most. After switching to v2, spans appeared but every content attribute was empty.&lt;/p&gt;

&lt;p&gt;In v2, content capture is governed by the OTel-side variable &lt;code&gt;OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;th&gt;Behavior&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;NO_CONTENT&lt;/code&gt; (default)&lt;/td&gt;
&lt;td&gt;Records nothing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SPAN_ONLY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Records into span attributes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;EVENT_ONLY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Records into log records (OTel events)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SPAN_AND_EVENT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Both&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;ADK's own &lt;code&gt;ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS=true&lt;/code&gt; is a &lt;strong&gt;v1-only knob&lt;/strong&gt;. If you migrated from v1, that one is probably already set to &lt;code&gt;true&lt;/code&gt;, which makes the failure look especially confusing: the setting is right there, and nothing is captured.&lt;/p&gt;

&lt;p&gt;The tempting choice is &lt;code&gt;SPAN_AND_EVENT&lt;/code&gt; — why not have both? Because the event path needs a &lt;code&gt;LoggerProvider&lt;/code&gt;, and ADK only creates one when log record processors exist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# google/adk/telemetry/setup.py
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;log_record_processors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# LoggerProvider is created only here
&lt;/span&gt;    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you call &lt;code&gt;get_gcp_exporters(enable_cloud_tracing=True)&lt;/code&gt; and nothing else, you have zero log record processors, so there is no &lt;code&gt;LoggerProvider&lt;/code&gt; and nowhere for those events to go.&lt;/p&gt;

&lt;p&gt;For a trace-only setup, &lt;code&gt;SPAN_ONLY&lt;/code&gt; is the only sensible value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;env&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"SPAN_ONLY"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;env&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"2"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Trap 2: v1 and v2 bodies live in different ROWS, not different columns
&lt;/h2&gt;

&lt;p&gt;During a migration you have both schemas in the same table, so you reach for a fallback:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- This does nothing useful&lt;/span&gt;
&lt;span class="n"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$."gcp.vertex.agent.llm_request"'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$."gen_ai.input.messages"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;llm_input&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;COALESCE&lt;/code&gt; picks the first non-NULL &lt;strong&gt;within one row&lt;/strong&gt;. But the v1 body sits on a &lt;code&gt;call_llm&lt;/code&gt; row and the v2 body sits on a &lt;code&gt;generate_content ...&lt;/code&gt; row. The two attributes never coexist in a single row, so this expression only ever returns whichever one that row already had. It is a fallback that cannot fall back.&lt;/p&gt;

&lt;p&gt;Branch on the span name and treat them as separate rows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'call_llm'&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="n"&gt;STARTS_WITH&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'generate_content '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And extract differently per shape:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CASE&lt;/span&gt;
  &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'call_llm'&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
    &lt;span class="c1"&gt;-- v1: llm_request.contents[last].parts[].text&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;STRING_AGG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$.text'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s1"&gt;' / '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;UNNEST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;JSON_QUERY_ARRAY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;last_content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$.parts'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;ELSE&lt;/span&gt;
    &lt;span class="c1"&gt;-- v2: input_messages[last].parts[].content&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;STRING_AGG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$.content'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s1"&gt;' / '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;UNNEST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;JSON_QUERY_ARRAY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;last_message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$.parts'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;pt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;user_text&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The inner keys differ too: a v1 part uses &lt;code&gt;text&lt;/code&gt;, a v2 part uses &lt;code&gt;content&lt;/code&gt;. The assistant role is &lt;code&gt;model&lt;/code&gt; in v1 and &lt;code&gt;assistant&lt;/code&gt; in v2, per semconv.&lt;/p&gt;

&lt;p&gt;Meanwhile, tool arguments and results &lt;strong&gt;do&lt;/strong&gt; share a row, because &lt;code&gt;execute_tool &amp;lt;name&amp;gt;&lt;/code&gt; keeps the same span name across both schemas. There, &lt;code&gt;COALESCE&lt;/code&gt; is exactly right:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$."gcp.vertex.agent.tool_call_args"'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$."gen_ai.tool.call.arguments"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;tool_args&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the same migration needs two different fallback strategies depending on which span you are reading. You will not deduce this from the docs; you have to capture real spans and look.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 3: resolving the agent name needs parent traversal, not trace_id
&lt;/h2&gt;

&lt;p&gt;v1 embedded the agent in the span name (&lt;code&gt;agent_run [SomeLeafAgent]&lt;/code&gt;). v2 exposes &lt;code&gt;gen_ai.agent.name&lt;/code&gt; as its own attribute — but it is not on v1's &lt;code&gt;call_llm&lt;/code&gt;. To cover both during migration, walk up the parent chain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$."gen_ai.agent.name"'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$."gen_ai.agent.name"'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$."gen_ai.agent.name"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;agent_name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent_span_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;span_id&lt;/span&gt;   &lt;span class="c1"&gt;-- parent&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="k"&gt;g&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent_span_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;span_id&lt;/span&gt;   &lt;span class="c1"&gt;-- grandparent&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do &lt;strong&gt;not&lt;/strong&gt; join on &lt;code&gt;trace_id&lt;/code&gt;. A single trace contains the router agent and any &lt;code&gt;AgentTool&lt;/code&gt; children, so a trace-wide join happily attributes one agent's spans to another.&lt;/p&gt;

&lt;p&gt;In practice, every v2 &lt;code&gt;generate_content&lt;/code&gt; span in my capture carried &lt;code&gt;gen_ai.agent.name&lt;/code&gt; directly. The parent traversal is insurance for the v1 rows during the overlap window.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 4: the 64 KiB attribute limit rejects the whole batch
&lt;/h2&gt;

&lt;p&gt;GCP's Telemetry API refuses any attribute over 64 KiB — and it does not drop just that attribute. &lt;strong&gt;The entire batch comes back HTTP 400.&lt;/strong&gt; One oversized system instruction erases every span that shipped with it.&lt;/p&gt;

&lt;p&gt;v1 was easy to trip because it packed everything into one attribute. v2 does not really help: &lt;code&gt;gen_ai.system_instructions&lt;/code&gt; and &lt;code&gt;gen_ai.tool.definitions&lt;/code&gt; get large on their own. Mine reached 63,427 bytes.&lt;/p&gt;

&lt;p&gt;The obvious lever, OTel SDK's &lt;code&gt;OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT&lt;/code&gt;, is the wrong tool. It truncates by character count with no UTF-8 byte guarantee, and it cuts JSON mid-structure, so what survives no longer parses. Unparseable bodies are worthless for analytics.&lt;/p&gt;

&lt;p&gt;I wrapped ADK's span processors instead, shrinking attributes with knowledge of the JSON structure just before export:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;wrapped_hooks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OTelHooks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;span_processors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nc"&gt;SpanAttributeLimitSpanProcessor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;hooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;span_processors&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;metric_readers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metric_readers&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;log_record_processors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log_record_processors&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;maybe_set_otel_providers&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;wrapped_hooks&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wrapping rather than replacing the exporter keeps ADK's native Cloud Trace batching. The shrink order goes by analytic value: incidental fields like &lt;code&gt;grounding_metadata&lt;/code&gt; and &lt;code&gt;logprobs_result&lt;/code&gt; first, then tool definitions, then the system instruction, then oldest conversation turns. A &lt;code&gt;__adk_span_truncated__&lt;/code&gt; marker always goes in so downstream readers know.&lt;/p&gt;

&lt;p&gt;In production it looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WARNING Truncated span attribute: span=generate_content gemini-3.8-flash
        attribute=gen_ai.system_instructions original_bytes=63427
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;63 KB shrank to 27,826 characters with the tail (the most recent context) preserved, and zero 400s since.&lt;/p&gt;

&lt;p&gt;One known weakness: this approach handles &lt;strong&gt;one huge string&lt;/strong&gt; well and &lt;strong&gt;many medium strings&lt;/strong&gt; badly. When no single removal gets you under budget, the depth-first shrink gives up and collapses everything to the marker. I reproduced 30 parts x 2.1 KB = 63,520 bytes — only 3.5 KB over budget — degrading to 47 bytes. v2 splits content into more, array-shaped attributes, so this path gets &lt;em&gt;more&lt;/em&gt; likely after migration, not less.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 5: &lt;code&gt;exclude-newer-span&lt;/code&gt; in uv.lock blocked the new version
&lt;/h2&gt;

&lt;p&gt;Not schema-related, but it happened in the same change.&lt;/p&gt;

&lt;p&gt;Dependabot's ADK 2.13 PR was failing CI. Trying to reproduce locally, I could not even install 2.13:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Because only google-adk&amp;lt;=2.12.0 is available ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cause lives at the top of &lt;code&gt;uv.lock&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="n"&gt;exclude-newer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"0001-01-01T00:00:00Z"&lt;/span&gt;
&lt;span class="n"&gt;exclude-newer-span&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"P1W"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;exclude-newer-span&lt;/code&gt; refuses anything published within a week of the lock's resolution timestamp — a reasonable supply-chain measure. In this case &lt;strong&gt;2.13.0 was published about five and a half hours past the cutoff.&lt;/strong&gt; A few hours of timing, and the error message tells you none of this.&lt;/p&gt;

&lt;p&gt;Worse, my own &lt;code&gt;~/.config/uv/uv.toml&lt;/code&gt; carried &lt;code&gt;exclude-newer = "1 week"&lt;/code&gt;, which overrode the PR's lockfile. That is why checking out the branch and running &lt;code&gt;uv sync&lt;/code&gt; kept installing 2.7.0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# A stale VIRTUAL_ENV will also make `uv pip list` lie to you&lt;/span&gt;
&lt;span class="nb"&gt;unset &lt;/span&gt;VIRTUAL_ENV
&lt;span class="nv"&gt;UV_EXCLUDE_NEWER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2026-12-31T00:00:00Z uv &lt;span class="nb"&gt;sync&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reproducibility settings manufacture exactly as much &lt;em&gt;irreproducibility&lt;/em&gt; for anyone who did not write them, because the failure never points back at the setting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 6: a &lt;code&gt;sys.modules&lt;/code&gt; stub leaking across test files
&lt;/h2&gt;

&lt;p&gt;The Dependabot CI failure turned out to have nothing to do with production code. Excluding one broken test file, all 1,243 remaining tests passed.&lt;/p&gt;

&lt;p&gt;Two independent causes, both test scaffolding.&lt;/p&gt;

&lt;p&gt;First, a test module installed stubs into &lt;code&gt;sys.modules&lt;/code&gt; at import time and never cleaned up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# tests/test_leaf_agent.py
&lt;/span&gt;&lt;span class="n"&gt;google_genai_types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ModuleType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;google.genai.types&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;google_genai_types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GenerateContentConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MagicMock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;GenerateContentConfig&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;google.genai&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;google_genai&lt;/span&gt;
&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;google.genai.types&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;google_genai_types&lt;/span&gt;

&lt;span class="n"&gt;_MCP_CLIENT_STUB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;_build_stub_modules&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;   &lt;span class="c1"&gt;# runs at import, no teardown
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;sys.modules&lt;/code&gt; is process-global. Depending on collection order, another test file imports &lt;code&gt;google.genai.types&lt;/code&gt;, gets the stub, and dies with &lt;code&gt;ImportError&lt;/code&gt; during collection. It happened to work on ADK 2.7 and broke on 2.13 when the import path changed.&lt;/p&gt;

&lt;p&gt;Second, &lt;code&gt;contents.types&lt;/code&gt; no longer exists in ADK 2.13:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;original_contents_types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;types&lt;/span&gt;   &lt;span class="c1"&gt;# AttributeError on ADK 2.13
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The nasty part: &lt;strong&gt;a plain &lt;code&gt;python -c&lt;/code&gt; import succeeds.&lt;/strong&gt; It only fails under pytest, because only pytest collects the other module that plants the stub. I lost a good while to "the import works but CI fails."&lt;/p&gt;

&lt;p&gt;If an import error will not reproduce outside pytest, suspect &lt;code&gt;sys.modules&lt;/code&gt; pollution first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: an all-NULL column is not evidence of zero
&lt;/h2&gt;

&lt;p&gt;While verifying the migration I noticed a new ADK 2.13 warning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App "router" can transfer between agents but has no context_cache_config.
Every transfer swaps the system instruction and the tool set, so the request
prefix changes and the whole prompt is re-sent uncached after each transfer.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So I went to measure how much caching was actually happening:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$."gen_ai.usage.cached_input_tokens"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;cached_tok&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All NULL. I concluded caching had never once engaged, and filed an issue saying so.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That was wrong.&lt;/strong&gt; The real attribute is &lt;code&gt;gen_ai.usage.cache_read.input_tokens&lt;/code&gt;. The key I queried does not exist at all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# google/adk/telemetry/_token_usage.py
&lt;/span&gt;&lt;span class="n"&gt;GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gen_ai.usage.cache_read.input_tokens&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gen_ai.usage.cache_creation.input_tokens&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Re-run with the right key, and caching had been working &lt;strong&gt;before&lt;/strong&gt; the fix:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Time&lt;/th&gt;
&lt;th&gt;Agent&lt;/th&gt;
&lt;th&gt;input_tokens&lt;/th&gt;
&lt;th&gt;cache_read.input_tokens&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;10-31 07:41&lt;/td&gt;
&lt;td&gt;leaf_agent&lt;/td&gt;
&lt;td&gt;19,290&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10-31 07:41&lt;/td&gt;
&lt;td&gt;leaf_agent&lt;/td&gt;
&lt;td&gt;23,599&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10-31 07:41&lt;/td&gt;
&lt;td&gt;leaf_agent&lt;/td&gt;
&lt;td&gt;24,472&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;19,410&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10-31 07:41&lt;/td&gt;
&lt;td&gt;leaf_agent&lt;/td&gt;
&lt;td&gt;26,465&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;23,359&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Vertex AI's implicit caching was already kicking in from the third call. My premise of "zero caching" never held.&lt;/p&gt;

&lt;p&gt;What makes this trap sharp is that ADK sets usage attributes &lt;strong&gt;conditionally&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache_read_input_tokens&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;attrs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache_read_input_tokens&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the value is &lt;code&gt;None&lt;/code&gt;, the attribute is absent entirely. So a NULL from a JSON path means "the value was zero", or "you typed the key wrong", or "this span never carries that attribute" — three very different things that look identical.&lt;/p&gt;

&lt;p&gt;The cheap guard is to check whether the attribute exists on &lt;em&gt;any&lt;/em&gt; row before drawing a conclusion:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;COUNTIF&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;JSON_VALUE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$."gen_ai.usage.cache_read.input_tokens"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;has_attr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;spans&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'generate_content%'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;has_attr = 0&lt;/code&gt;, suspect the key before you suspect reality.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;context_cache_config&lt;/code&gt; fix was still worth doing — explicit caching genuinely was unset. After enabling it:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Time&lt;/th&gt;
&lt;th&gt;Agent&lt;/th&gt;
&lt;th&gt;input_tokens&lt;/th&gt;
&lt;th&gt;cache_read.input_tokens&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;11-01 08:05&lt;/td&gt;
&lt;td&gt;router&lt;/td&gt;
&lt;td&gt;2,875&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11-01 08:06&lt;/td&gt;
&lt;td&gt;router&lt;/td&gt;
&lt;td&gt;3,010&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11-01 08:06&lt;/td&gt;
&lt;td&gt;leaf_agent&lt;/td&gt;
&lt;td&gt;19,410&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11-01 08:06&lt;/td&gt;
&lt;td&gt;leaf_agent&lt;/td&gt;
&lt;td&gt;23,655&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;19,391&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11-01 08:06&lt;/td&gt;
&lt;td&gt;leaf_agent&lt;/td&gt;
&lt;td&gt;24,554&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;19,391&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11-01 08:06&lt;/td&gt;
&lt;td&gt;leaf_agent&lt;/td&gt;
&lt;td&gt;24,757&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;19,391&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11-01 08:07&lt;/td&gt;
&lt;td&gt;leaf_agent&lt;/td&gt;
&lt;td&gt;24,958&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;19,391&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Hit rate improved (2/4 to 4/5), but the honest description is "the implicit caching that already existed became more consistent", not "caching started working".&lt;/p&gt;

&lt;p&gt;The router agent never caches, by design. Per &lt;code&gt;ContextCacheConfig&lt;/code&gt;'s docstring, a cacheable prefix needs 2,048 tokens on Gemini 2.5 and &lt;strong&gt;4,096 on Gemini 3&lt;/strong&gt;; the router's 2,875–3,010 tokens never reach it. Agents with small instructions stay outside explicit caching no matter what you configure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Schema v2 changes span names &lt;em&gt;and&lt;/em&gt; attribute keys. Nothing errors — you just get zero rows. Capture real spans and diff them before you migrate queries.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT&lt;/code&gt;, or no content is recorded. For trace-only setups, &lt;code&gt;SPAN_ONLY&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;v1 and v2 LLM bodies live on different rows, so &lt;code&gt;COALESCE&lt;/code&gt; cannot bridge them. Tool arguments and results share a row, so there it works.&lt;/li&gt;
&lt;li&gt;The 64 KiB attribute limit kills the whole batch. SDK character truncation corrupts JSON; shrink with structural knowledge.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;exclude-newer-span&lt;/code&gt; produces failures whose cause is unreadable from the error.&lt;/li&gt;
&lt;li&gt;Tests that plant stubs in &lt;code&gt;sys.modules&lt;/code&gt; must tear them down. Classic symptom: an import error that will not reproduce under &lt;code&gt;python -c&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never read an all-NULL column as proof that something did not happen.&lt;/strong&gt; Wrong key names and conditionally-set attributes look exactly the same.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For version deltas, &lt;a href="https://pypi.org/project/google-adk/#history" rel="noopener noreferrer"&gt;google-adk on PyPI&lt;/a&gt; and the &lt;a href="https://github.com/google/adk-python/releases" rel="noopener noreferrer"&gt;adk-python releases&lt;/a&gt; are the fastest reference. For attribute names, read the semconv constants directly rather than any blog post — including this one. I got them wrong twice.&lt;/p&gt;

</description>
      <category>opentelemetry</category>
      <category>googlecloud</category>
      <category>ai</category>
      <category>python</category>
    </item>
    <item>
      <title>Tracing Google ADK Agents on Vertex AI Agent Engine, and the Five Gotchas Nobody Warns You About</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Mon, 12 Oct 2026 12:37:53 +0000</pubDate>
      <link>https://dev.to/toyama0919/tracing-google-adk-agents-on-vertex-ai-agent-engine-and-the-five-gotchas-nobody-warns-you-about-pc5</link>
      <guid>https://dev.to/toyama0919/tracing-google-adk-agents-on-vertex-ai-agent-engine-and-the-five-gotchas-nobody-warns-you-about-pc5</guid>
      <description>&lt;p&gt;Turning on tracing for a Google ADK agent deployed to Vertex AI Agent Engine is one keyword argument:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;vertexai.agent_engines&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AdkApp&lt;/span&gt;

&lt;span class="n"&gt;agent_engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AdkApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;root_agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;enable_tracing&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deploy that, trigger your agent, open Cloud Trace, and there is a decent chance you see nothing at all — with no error anywhere in your application logs. Every failure mode in this post is silent by design: the SDK treats telemetry as best-effort, so a misconfiguration costs you observability, never availability. That is the right call for production and a miserable one for debugging.&lt;/p&gt;

&lt;p&gt;This is what I found while wiring it up, verified against &lt;code&gt;google-adk&lt;/code&gt; 2.7.0 and &lt;code&gt;google-cloud-aiplatform&lt;/code&gt; 1.165.1.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 1: it does not export to the Cloud Trace API
&lt;/h2&gt;

&lt;p&gt;The obvious move is to enable &lt;code&gt;cloudtrace.googleapis.com&lt;/code&gt; and move on. That is not where the spans go.&lt;/p&gt;

&lt;p&gt;The exporter is an OTLP/HTTP exporter pointed at the &lt;strong&gt;Telemetry API&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# vertexai/agent_engines/templates/adk.py
&lt;/span&gt;&lt;span class="n"&gt;_DEFAULT_TELEMETRY_ENDPOINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://telemetry.googleapis.com/v1/traces&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spans are &lt;code&gt;POST&lt;/code&gt;ed there using the credentials from &lt;code&gt;google.auth.default()&lt;/code&gt; — in practice, the Agent Engine service account. The SDK even probes the API at startup and warns you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tracing integration for Agent Engine has migrated to a new API.
The 'telemetry.googleapis.com' has not been enabled in project &amp;lt;project&amp;gt;.
**Impact:** Until this API is enabled, telemetry data will not be stored.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That check is wrapped in a bare &lt;code&gt;except&lt;/code&gt; and is explicitly non-fatal, so your container boots normally and serves traffic. The warning scrolls past in the startup logs and your traces quietly go nowhere.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud services &lt;span class="nb"&gt;enable &lt;/span&gt;telemetry.googleapis.com &lt;span class="nt"&gt;--project&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;my-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check what you actually have enabled, because this is the single most likely reason you are reading this post:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud services list &lt;span class="nt"&gt;--enabled&lt;/span&gt; &lt;span class="nt"&gt;--project&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;my-project &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--filter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"config.name:(telemetry.googleapis.com OR cloudtrace.googleapis.com)"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"value(config.name)"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep &lt;code&gt;cloudtrace.googleapis.com&lt;/code&gt; — that is what backs the read side and the console. But enabling it alone buys you nothing on the write path. You want both names in that output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 2: the IAM failure is a 403 in a log you are probably not reading
&lt;/h2&gt;

&lt;p&gt;Enable the API, redeploy, still nothing. The error exists, but not where you are looking. It is not in your Cloud Run service logs and not in your application output. It is in the &lt;strong&gt;Reasoning Engine&lt;/strong&gt; resource logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR: Failed to export span batch code: 403, reason: Forbidden
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud logging &lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s1"&gt;'resource.type="aiplatform.googleapis.com/ReasoningEngine"
   AND textPayload=~"Failed to export span batch"'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--project&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;my-project &lt;span class="nt"&gt;--freshness&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1h &lt;span class="nt"&gt;--limit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The batch span processor logs the failure and drops the batch. Your agent is completely unaffected — correct answers, normal latency, zero traces.&lt;/p&gt;

&lt;p&gt;Which role? The permission you need is &lt;code&gt;telemetry.traces.write&lt;/code&gt;. Two roles grant it, and the naming is misleading:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;gcloud iam roles describe roles/cloudtrace.agent &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="go"&gt;    --format='value(includedPermissions)'
&lt;/span&gt;&lt;span class="gp"&gt;cloudtrace.traces.patch;&lt;/span&gt;telemetry.traces.write
&lt;span class="go"&gt;
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;gcloud iam roles describe roles/telemetry.tracesWriter &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="go"&gt;    --format='value(includedPermissions)'
telemetry.traces.write
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;roles/cloudtrace.agent&lt;/code&gt; is a &lt;strong&gt;superset&lt;/strong&gt;. Despite the legacy-sounding name, it already covers the Telemetry API, so granting both is pointless:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud projects add-iam-policy-binding my-project &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--member&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"serviceAccount:my-agent@my-project.iam.gserviceaccount.com"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"roles/cloudtrace.agent"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Confirm it landed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud projects get-iam-policy my-project &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--flatten&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"bindings[].members"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--filter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"bindings.role=roles/cloudtrace.agent"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"value(bindings.members)"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One useful property of this failure mode: once you fix the IAM, the 403s stop at a clean timestamp boundary without a redeploy. If you see errors up to &lt;code&gt;T&lt;/code&gt; and traces appearing after &lt;code&gt;T&lt;/code&gt;, the binding propagated. That is your confirmation signal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 3: do not set &lt;code&gt;ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS&lt;/code&gt; yourself
&lt;/h2&gt;

&lt;p&gt;By default ADK records prompts, model responses, and tool arguments into spans. The documented knob is &lt;code&gt;ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS&lt;/code&gt;, and ADK's own default is on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# google/adk/telemetry/context.py
&lt;/span&gt;&lt;span class="n"&gt;env_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The natural instinct is to pin it explicitly in your deployment config so a future upstream default change cannot silently strip your payloads. On Agent Engine that accomplishes nothing, because &lt;code&gt;AdkApp.set_up()&lt;/code&gt; overwrites it unconditionally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# vertexai/agent_engines/templates/adk.py — inside set_up()
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_tmpl_attrs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;enable_tracing&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;true&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;false&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whatever you put in &lt;code&gt;env_vars&lt;/code&gt; is clobbered at startup. Content capture is a pure function of &lt;code&gt;enable_tracing&lt;/code&gt; here. (The &lt;code&gt;adk deploy&lt;/code&gt; CLI &lt;em&gt;does&lt;/em&gt; inject &lt;code&gt;false&lt;/code&gt; — but that only applies if you deploy through that CLI. Create the engine from the SDK or any IaC tool and the injection never runs.)&lt;/p&gt;

&lt;p&gt;The practical consequence is a security one: on Agent Engine, &lt;code&gt;enable_tracing=True&lt;/code&gt; means &lt;strong&gt;full prompt and tool payloads land in your traces&lt;/strong&gt;, and you cannot opt out through this variable. If your agent handles anything sensitive, that is a deliberate decision about who can read traces, not an afterthought.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 4: &lt;code&gt;enable_tracing&lt;/code&gt; is not the only switch
&lt;/h2&gt;

&lt;p&gt;Tracing is an AND of two controls, and the truth table is in the source:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# vertexai/agent_engines/templates/adk.py
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;_tracing_enabled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    | enable_tracing | enable_telemetry(env) | tracing_actually_enabled |
    |----------------|-----------------------|--------------------------|
    | true           | false                 | false                    |
    | true           | true                  | true                     |
    | true           | None                  | true                     |
    | None(default)  | true                  | adk_version &amp;gt;= 1.17      |
    | None(default)  | None                  | false                    |
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;enable_telemetry&lt;/code&gt; comes from the &lt;code&gt;GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY&lt;/code&gt; env var, which is also what the Cloud Console toggle writes. Set it to &lt;code&gt;false&lt;/code&gt; and your &lt;code&gt;enable_tracing=True&lt;/code&gt; is dead on arrival. Leaving it unset (&lt;code&gt;None&lt;/code&gt;) is fine.&lt;/p&gt;

&lt;p&gt;One precision point worth getting right: the SDK deprecates &lt;strong&gt;&lt;code&gt;enable_tracing=False&lt;/code&gt;&lt;/strong&gt;, not the parameter in general.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_tmpl_attrs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;enable_tracing&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;_warn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Your &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;enable_tracing=False&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; setting is being deprecated ...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;enable_tracing=True&lt;/code&gt; emits no warning. If you want to &lt;em&gt;disable&lt;/em&gt; tracing, drop the argument and use the env var instead — passing &lt;code&gt;False&lt;/code&gt; desynchronizes the Console toggle from reality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 5: the root span is not called &lt;code&gt;invoke_agent&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;You will go looking for &lt;code&gt;invoke_agent&lt;/code&gt; and not find it at the root. ADK has two telemetry schema versions, and &lt;strong&gt;Agent Engine defaults to v2&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# google/adk/telemetry/_schema_version.py
#   Default resolution: 2 on Agent Engine, detected via the presence of
#   the GOOGLE_CLOUD_AGENT_ENGINE_ID env var.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Under v2 the tree looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;invoke_workflow my_agent          &amp;lt;- root
└─ invoke_agent my_agent
   ├─ call_llm
   │  └─ generate_content gemini-x.y
   ├─ execute_tool transfer_to_agent
   └─ invoke_agent my_sub_agent
      └─ execute_tool my_sub_tool
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;invoke_agent {name}&lt;/code&gt; is a child. &lt;code&gt;execute_tool&lt;/code&gt; carries the tool name. Content lives on &lt;code&gt;call_llm&lt;/code&gt; as &lt;code&gt;gcp.vertex.agent.llm_request&lt;/code&gt; / &lt;code&gt;llm_response&lt;/code&gt;, and on &lt;code&gt;execute_tool&lt;/code&gt; as &lt;code&gt;tool_call_args&lt;/code&gt; / &lt;code&gt;tool_response&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Filtering by root span name works against the v1 read API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET https://cloudtrace.googleapis.com/v1/projects/&amp;lt;PROJECT&amp;gt;/traces
    ?startTime=&amp;lt;RFC3339&amp;gt;&amp;amp;endTime=&amp;lt;RFC3339&amp;gt;
    &amp;amp;filter=root:invoke_workflow
    &amp;amp;view=COMPLETE
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the default listing is ordered by trace ID, not time — without a filter you get an arbitrary slice and may conclude nothing was recorded when it was.&lt;/p&gt;

&lt;h2&gt;
  
  
  The structural problem: one request is not one trace
&lt;/h2&gt;

&lt;p&gt;This is the part that changes how you design, not just how you configure.&lt;/p&gt;

&lt;p&gt;Each &lt;code&gt;create_session()&lt;/code&gt; + &lt;code&gt;stream_query()&lt;/code&gt; pair is an &lt;strong&gt;independent invocation&lt;/strong&gt; and produces its &lt;strong&gt;own trace&lt;/strong&gt;. If your handler fans out — say, three parallel checks against the same business record:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;query_agent_engine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;check-&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;record_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you get three unrelated traces. There is no parent linking them, because the trace context never crosses the Agent Engine boundary.&lt;/p&gt;

&lt;p&gt;ADK's standard span attributes are &lt;code&gt;invocation_id&lt;/code&gt;, &lt;code&gt;session_id&lt;/code&gt;, and &lt;code&gt;event_id&lt;/code&gt; — all internal identifiers. Nothing ties a trace back to &lt;em&gt;your&lt;/em&gt; domain object, and &lt;code&gt;user_id&lt;/code&gt; is not exported at all.&lt;/p&gt;

&lt;p&gt;So you have to add it. A &lt;code&gt;BasePlugin&lt;/code&gt; runs inside the root span's context, which makes it the right hook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google.adk.agents.invocation_context&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;InvocationContext&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google.adk.plugins.base_plugin&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BasePlugin&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;opentelemetry&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;

&lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLogger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RecordTracingPlugin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BasePlugin&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;super&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;record_tracing&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;before_run_callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;invocation_context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;InvocationContext&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;identity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parse_user_id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invocation_context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;identity&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt;
            &lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_current_span&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_recording&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt;
            &lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_attribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;app.record_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;identity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;record_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_attribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;app.flow&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;identity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flow&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;failed to tag span with record identity&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exc_info&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;


&lt;span class="n"&gt;agent_engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AdkApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;root_agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;enable_tracing&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;plugins&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;RecordTracingPlugin&lt;/span&gt;&lt;span class="p"&gt;()],&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now &lt;code&gt;app.record_id = "12345"&lt;/code&gt; retrieves all three traces as a set.&lt;/p&gt;

&lt;p&gt;Four things about that snippet are load-bearing:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It must be &lt;code&gt;async def&lt;/code&gt;.&lt;/strong&gt; The base signature is a coroutine; a sync method breaks when &lt;code&gt;PluginManager&lt;/code&gt; awaits it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It must return &lt;code&gt;None&lt;/code&gt;.&lt;/strong&gt; Any non-&lt;code&gt;None&lt;/code&gt; return value is treated as an early exit and short-circuits the run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# google/adk/plugins/plugin_manager.py
&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;callback_method&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Early exit: A plugin has returned a value. We stop
&lt;/span&gt;    &lt;span class="c1"&gt;# processing further plugins and return this value immediately.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The &lt;code&gt;try&lt;/code&gt; / &lt;code&gt;except&lt;/code&gt; is not defensive padding.&lt;/strong&gt; Plugin exceptions are not contained — &lt;code&gt;PluginManager._run_callbacks&lt;/code&gt; wraps them in a &lt;code&gt;RuntimeError&lt;/code&gt;, and &lt;code&gt;Runner._exec_with_plugin&lt;/code&gt; re-raises:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;_notify_run_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plugin_manager&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;invocation_context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An attribute-tagging bug takes down the agent run itself. Observability code has no business doing that, so catch &lt;code&gt;Exception&lt;/code&gt; (not &lt;code&gt;BaseException&lt;/code&gt; — leave &lt;code&gt;CancelledError&lt;/code&gt; and &lt;code&gt;KeyboardInterrupt&lt;/code&gt; alone) and log.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;invocation_context.user_id&lt;/code&gt; is a property.&lt;/strong&gt; It is not a model field, so it will not appear if you introspect &lt;code&gt;model_fields&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# google/adk/agents/invocation_context.py
&lt;/span&gt;&lt;span class="nd"&gt;@property&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note what this implies: &lt;code&gt;user_id&lt;/code&gt; is the only general-purpose channel for smuggling correlation data across the Agent Engine boundary, since you control it at &lt;code&gt;create_session()&lt;/code&gt; time. Encode it carefully, and keep the encode and decode in one module — they execute in different processes, and a format change applied to only one side fails silently in exactly the way this whole post is about.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two limits worth knowing before you design around this
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Attribute values cap at 64 KiB&lt;/strong&gt;, and excess is dropped non-deterministically. If an agent takes a large document as input, &lt;code&gt;gcp.vertex.agent.llm_request&lt;/code&gt; can exceed that and simply not be there. Do not build a workflow that assumes the prompt is always recoverable from the trace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retention is 30 days&lt;/strong&gt;, fixed, in the &lt;code&gt;_Trace&lt;/code&gt; bucket. Cloud Trace is an incident-investigation tool here, not an analytics store. If you want months of prompt history for offline evaluation, export to logging and BigQuery separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symptom&lt;/th&gt;
&lt;th&gt;Cause&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;No traces, no errors&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;telemetry.googleapis.com&lt;/code&gt; not enabled&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No traces, 403 in Reasoning Engine logs&lt;/td&gt;
&lt;td&gt;SA missing &lt;code&gt;roles/cloudtrace.agent&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Payloads missing or present unexpectedly&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;set_up()&lt;/code&gt; overwrites &lt;code&gt;ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS&lt;/code&gt; from &lt;code&gt;enable_tracing&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;enable_tracing=True&lt;/code&gt; does nothing&lt;/td&gt;
&lt;td&gt;&lt;code&gt;GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY=false&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cannot find &lt;code&gt;invoke_agent&lt;/code&gt; at the root&lt;/td&gt;
&lt;td&gt;Agent Engine uses schema v2; root is &lt;code&gt;invoke_workflow {name}&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;One request produces N unrelated traces&lt;/td&gt;
&lt;td&gt;Each &lt;code&gt;stream_query&lt;/code&gt; is its own invocation; correlate with a plugin attribute&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The configuration is genuinely one line. The surrounding API enablement, IAM, and span model are where the time goes — and because every one of them fails quietly, the only efficient way through is to know which log holds the 403.&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>ai</category>
      <category>python</category>
      <category>observability</category>
    </item>
    <item>
      <title>GitHub Issues as the Only Database: Running Coding CLIs Unattended Without a Server</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Fri, 02 Oct 2026 12:11:55 +0000</pubDate>
      <link>https://dev.to/toyama0919/github-issues-as-the-only-database-running-coding-clis-unattended-without-a-server-38c</link>
      <guid>https://dev.to/toyama0919/github-issues-as-the-only-database-running-coding-clis-unattended-without-a-server-38c</guid>
      <description>&lt;p&gt;Every headless coding CLI has the same shape: you hand it a prompt, it works, it exits, and it forgets everything. &lt;code&gt;claude -p&lt;/code&gt;, &lt;code&gt;codex exec&lt;/code&gt;, &lt;code&gt;cursor-agent -p&lt;/code&gt; — all one-shot. Which means the moment you want one to carry a feature from "here's a spec" to "merged to main," &lt;em&gt;you&lt;/em&gt; have to own the state: which task is next, which branch, which PR, whether CI went green, whether a human approved.&lt;/p&gt;

&lt;p&gt;The usual answer is a server. Webhook receiver, a queue, Postgres to hold run state, a reconciler. Then your laptop sleeps mid-PR and you find out your run state and GitHub's reality have diverged, and there is no cheap way to tell which one is lying.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/toyama0919/ghswarm" rel="noopener noreferrer"&gt;ghswarm&lt;/a&gt; makes the opposite bet: &lt;strong&gt;GitHub already is that database.&lt;/strong&gt; Labels are a mutex. The Issue body is a state blob. Checkboxes are a task queue. The PR carries CI status and review decisions. If all the state lives there, the orchestrator can be a stateless CLI that you can &lt;code&gt;kill -9&lt;/code&gt; at any moment.&lt;/p&gt;

&lt;h2&gt;
  
  
  The state has nowhere else to live
&lt;/h2&gt;

&lt;p&gt;Two HTML comments at the top of the Issue body hold everything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- GHSWARM_STATE_START
{ "next_action": "wait_ci", "branch_name": "issue-42", "pr_number": 118,
  "ci_fix_retries": 1, "total_agent_runs": 4, "busy_owner": "mbp.local:9182" }
GHSWARM_STATE_END --&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- GHSWARM_VERIFY_START
verify:
  - uv run --extra dev ruff check .
  - uv run --extra dev python -m pytest -q
GHSWARM_VERIFY_END --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Invisible in the web UI, parsed by regex, rewritten on every transition. The separation matters: state gets overwritten constantly, verify steps must survive every rewrite, so they live in their own block.&lt;/p&gt;

&lt;p&gt;Recovery is then not a feature you build — it's the absence of one. Process dies during &lt;code&gt;wait_ci&lt;/code&gt;? Next cycle reads the Issue, sees &lt;code&gt;next_action: wait_ci&lt;/code&gt;, polls the PR again. Nothing to reconcile, because there was never a second copy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Labels as a distributed mutex with a lease
&lt;/h2&gt;

&lt;p&gt;Only one coding CLI may touch a repo at a time, and that has to hold across processes and machines. So the lock is a label: &lt;code&gt;status: busy-claude&lt;/code&gt;, &lt;code&gt;status: idle&lt;/code&gt;, &lt;code&gt;status: blocked&lt;/code&gt;, &lt;code&gt;status: completed&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A lock without a lease is a deadlock waiting to happen, so the holder writes &lt;code&gt;busy_owner: "host:pid"&lt;/code&gt; and &lt;code&gt;busy_since&lt;/code&gt; into the state block, and staleness is decided without side effects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;is_stale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ttl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;busy_prefix&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
    &lt;span class="n"&gt;owner_host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;owner_pid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parse_owner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;busy_owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;owner_host&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;owner_pid&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nf"&gt;pid_alive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;owner_pid&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;          &lt;span class="c1"&gt;# same machine, process is gone -&amp;gt; definitely dead
&lt;/span&gt;    &lt;span class="n"&gt;since&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parse_ts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;busy_since&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;since&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
    &lt;span class="nf"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;since&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;total_seconds&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ttl&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same host gets the fast path: &lt;code&gt;os.kill(pid, 0)&lt;/code&gt; tells you immediately the holder is gone. Another host only gets the TTL (4h default), because you cannot probe its PIDs. Reclaiming posts a comment on the Issue naming the owner and the acquisition time, so a stolen lock is never silent.&lt;/p&gt;

&lt;p&gt;The label transition itself has a detail that only shows up after it bites you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;set_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gh&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;agent_names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;gh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_label&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_issue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent_names&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;gh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove_label&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add first, then remove. The status label is what marks an Issue as &lt;em&gt;managed&lt;/em&gt;, so if a transient API error lands between a remove and an add, the Issue silently drops out of the swarm forever. Adding first means the worst case is two status labels coexisting for a second — which the stale-reclaim path already handles. And the removal list comes from a &lt;strong&gt;fresh&lt;/strong&gt; &lt;code&gt;get_issue&lt;/code&gt;, not the snapshot taken at the top of the cycle, because that snapshot predates the busy label this very run added.&lt;/p&gt;

&lt;h2&gt;
  
  
  No spec, no run
&lt;/h2&gt;

&lt;p&gt;The presence of the &lt;code&gt;GHSWARM_VERIFY&lt;/code&gt; block is the start gate. No block means the Issue blocks as &lt;code&gt;spec_missing&lt;/code&gt;; malformed YAML blocks as &lt;code&gt;verify_invalid&lt;/code&gt;. An agent is never allowed to start on an Issue where nobody wrote down what "done" means.&lt;/p&gt;

&lt;p&gt;Task progress is just markdown checkboxes in the body, worked down and flipped to &lt;code&gt;- [x]&lt;/code&gt;. One design choice worth calling out — all unchecked tasks go into a &lt;em&gt;single&lt;/em&gt; CLI run, not one run per task:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Pass all unfinished tasks in a single CLI run. Because each CLI invocation is
# a headless one-shot that loses its context, launching one per task would make
# it re-read the same codebase over and over, and later tasks could not carry
# over the intent of earlier ones.
&lt;/span&gt;&lt;span class="n"&gt;task_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;. &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the whole reason the granularity is what it is. Per-task runs look cleaner on paper and are strictly worse in practice: you pay full codebase re-reading on every task, and task 3 cannot know why task 1 chose a particular abstraction.&lt;/p&gt;

&lt;h2&gt;
  
  
  The loop runs all the way to merged
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;implement → (simplify) → ai_review → create_pr → wait_ci → verify_merge → done&lt;/code&gt;, with &lt;code&gt;blocked&lt;/code&gt; reachable from anywhere. What makes it actually unattended is that each failure mode has a named recovery rather than a stop:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Failure&lt;/th&gt;
&lt;th&gt;Recovery&lt;/th&gt;
&lt;th&gt;Cap&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Verify fails after a run&lt;/td&gt;
&lt;td&gt;Re-prompt with the test log attached&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;max_retries&lt;/code&gt; (in-run)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;resource_exhausted&lt;/code&gt; / 429 / 503&lt;/td&gt;
&lt;td&gt;Treated as transient, retried across loops&lt;/td&gt;
&lt;td&gt;&lt;code&gt;transient_max_retries: 5&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PR is &lt;code&gt;CONFLICTING&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Merge base into the worktree, resolve, push, re-run CI&lt;/td&gt;
&lt;td&gt;&lt;code&gt;conflict_max_retries: 3&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PR CI red&lt;/td&gt;
&lt;td&gt;Pull the logs, hand them to implement, push a fix&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ci_fix_max_retries: 3&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Spec ambiguous&lt;/td&gt;
&lt;td&gt;Agent writes &lt;code&gt;.agent_question.md&lt;/code&gt; and exits; ghswarm comments and blocks&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every counter lives in the Issue state and is reset on success, so a retry budget survives a crash instead of resetting to zero and letting the same failure burn tokens forever. On top of that, &lt;code&gt;issue_max_agent_runs&lt;/code&gt; (default 10) caps cumulative agent runs per Issue — the backstop against an Issue that is subtly impossible and would otherwise spin all night.&lt;/p&gt;

&lt;p&gt;Two gates are worth their own note. &lt;code&gt;require_approval&lt;/code&gt; is three-valued, not boolean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;false&lt;/code&gt; — merge on green CI alone&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;true&lt;/code&gt; — GitHub's overall review decision must be &lt;code&gt;APPROVED&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;human&lt;/code&gt; — additionally requires a non-bot &lt;code&gt;APPROVED&lt;/code&gt; review (&lt;code&gt;user.type == "Bot"&lt;/code&gt; and &lt;code&gt;*[bot]&lt;/code&gt; logins are excluded)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That third value exists because once review bots are in the loop, "approved" stops meaning "a person looked at this."&lt;/p&gt;

&lt;p&gt;And merging is not the end. With &lt;code&gt;post_merge_ci&lt;/code&gt; on, the Issue stays open until the CI of the &lt;em&gt;merge commit on the base branch&lt;/em&gt; is green:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dot"&gt;&lt;code&gt;&lt;span class="nv"&gt;wait_ci&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;verify_merge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;CI&lt;/span&gt; &lt;span class="nv"&gt;green&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;approve&lt;/span&gt;
&lt;span class="nv"&gt;verify_merge&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;done&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;post&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;merge&lt;/span&gt; &lt;span class="nv"&gt;CI&lt;/span&gt; &lt;span class="nv"&gt;green&lt;/span&gt;
&lt;span class="nv"&gt;verify_merge&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;blocked&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;post&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;merge&lt;/span&gt; &lt;span class="nv"&gt;CI&lt;/span&gt; &lt;span class="nv"&gt;failed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PR CI passes on a merge preview; regressions from interleaved merges show up only on the base branch. Closing the Issue at merge time would mean the swarm declares victory exactly where the interesting failures start.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multiple CLIs, pinned per phase, with fallback
&lt;/h2&gt;

&lt;p&gt;Routing is explicit — no LLM decides which model runs. You pin a command per phase, and a list is a fallback chain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;agents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;implement&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cursor-agent&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;-p&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;{prompt}&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;--model&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;auto"&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;claude&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;-p&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;{prompt}&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;--model&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;opus&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;--dangerously-skip-permissions"&lt;/span&gt;
  &lt;span class="na"&gt;review&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;claude&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;-p&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;{prompt}&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;--model&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;sonnet&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;--dangerously-skip-permissions"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;{prompt}&lt;/code&gt; is &lt;code&gt;shlex.quote&lt;/code&gt;d in. Non-zero exit falls through to the next command, which is how a provider outage degrades into "the run took longer" instead of "the swarm stopped." One subtle bit in the fallback path: the question file is deleted before retrying, so a clarification written by the CLI that just failed cannot be misread as coming from the fallback.&lt;/p&gt;

&lt;p&gt;Cheap-model-for-review is a real cost lever here: implement on Opus, review on Sonnet, and the review phase — which runs on every Issue — stops dominating the bill.&lt;/p&gt;

&lt;h2&gt;
  
  
  Isolation: worktree per Issue, optional Docker per directory
&lt;/h2&gt;

&lt;p&gt;Each Issue gets its own git worktree (&lt;code&gt;../&amp;lt;repo&amp;gt;-worktrees/issue-N&lt;/code&gt;), so a run never touches your working tree and parallel repos never collide. &lt;code&gt;worktree_setup&lt;/code&gt; runs once on creation (&lt;code&gt;uv venv &amp;amp;&amp;amp; uv pip install -e '.[dev]' -q&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Verify steps can then run in Docker, and the config declares only &lt;em&gt;where&lt;/em&gt; each step runs — never &lt;em&gt;what&lt;/em&gt; it runs, since that belongs to the Issue:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;verify&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform&lt;/span&gt;
    &lt;span class="na"&gt;sandbox&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;driver&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;none&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;backend&lt;/span&gt;
    &lt;span class="na"&gt;sandbox&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;driver&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;docker&lt;/span&gt;
      &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;python:3.12&lt;/span&gt;
      &lt;span class="na"&gt;isolate_dirs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;.venv&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That split is what makes monorepos work: one Issue and one PR can touch both directories while each verifies in its own environment. The whole worktree is always mounted (only the working directory changes per step) so cross-directory imports still resolve, and &lt;code&gt;isolate_dirs&lt;/code&gt; gives &lt;code&gt;.venv&lt;/code&gt; / &lt;code&gt;node_modules&lt;/code&gt; a container-only writable mount so the container's platform-specific build artifacts never land in the host worktree.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotchas
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;macOS sleep is the one that gets people.&lt;/strong&gt; A locked screen or running screensaver is &lt;em&gt;not&lt;/em&gt; sleep — while the display is on, &lt;code&gt;powerd&lt;/code&gt; holds a &lt;code&gt;PreventUserIdleSystemSleep&lt;/code&gt; assertion and the loop keeps going. Real system sleep does stop it. Nothing is lost (state is on GitHub), but nothing progresses either. Wrap it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ghswarm loop &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;span class="nb"&gt;nohup &lt;/span&gt;caffeinate &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nt"&gt;-w&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; ~/.ghswarm/ghswarm.pid&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;caffeinate ... ghswarm loop -d&lt;/code&gt; does &lt;strong&gt;not&lt;/strong&gt; work — &lt;code&gt;-d&lt;/code&gt; double-forks, the foreground process exits instantly, and caffeinate drops the assertion with it. Point &lt;code&gt;-w&lt;/code&gt; at the daemon PID instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The event DB is derived data.&lt;/strong&gt; &lt;code&gt;~/.ghswarm/events.db&lt;/code&gt; records each step for observation, and it is explicitly not a source of truth — deleting it costs you nothing but history. Don't build state on it. (There's deliberately no &lt;code&gt;metrics&lt;/code&gt; command; the intent is raw events plus an AI writing ad-hoc SQL.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Headless auto-approval is yours to own.&lt;/strong&gt; &lt;code&gt;--dangerously-skip-permissions&lt;/code&gt; and friends are required for unattended runs, and the worktree + Docker isolation is what makes that a considered risk rather than a blind one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this shape holds up
&lt;/h2&gt;

&lt;p&gt;The real payoff isn't "no server to run," though &lt;code&gt;uv tool install ghswarm&lt;/code&gt; and a YAML file is a pleasant setup story. It's that &lt;strong&gt;there is exactly one copy of the truth, and it's the copy you were already going to look at.&lt;/strong&gt; When a run goes sideways you open the Issue: the labels tell you who holds the lock, the checkboxes tell you how far it got, the state block tells you what it was about to do, and the comments tell you why it stopped. No log correlation, no separate dashboard, no "the DB says running but the process is gone."&lt;/p&gt;

&lt;p&gt;Everything else — lease-based locks, capped retries, the post-merge CI gate — is just what it takes to be honest about a system where every worker is stateless and every dependency is flaky.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv tool &lt;span class="nb"&gt;install &lt;/span&gt;ghswarm
ghswarm init &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$EDITOR&lt;/span&gt; ~/.ghswarm.yaml
ghswarm skills &lt;span class="nb"&gt;install&lt;/span&gt;     &lt;span class="c"&gt;# Claude Code skills for the spec side&lt;/span&gt;
ghswarm loop               &lt;span class="c"&gt;# resident, parallel across repos&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ai</category>
      <category>github</category>
      <category>python</category>
      <category>automation</category>
    </item>
    <item>
      <title>Firestore Bills You Per Document, Not Per Query — Design Accordingly</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Tue, 15 Sep 2026 09:47:19 +0000</pubDate>
      <link>https://dev.to/toyama0919/firestore-bills-you-per-document-not-per-query-design-accordingly-1j1j</link>
      <guid>https://dev.to/toyama0919/firestore-bills-you-per-document-not-per-query-design-accordingly-1j1j</guid>
      <description>&lt;p&gt;Firestore's pricing is not a footnote you read after shipping. It is a constraint that propagates all the way up into your schema, your query layer, and your React effects. The unit of billing is &lt;strong&gt;one document operation&lt;/strong&gt;, not one query, not one byte, not one connection. Once you internalize that single fact, most of the "surprise Firestore bill" stories become predictable.&lt;/p&gt;

&lt;h2&gt;
  
  
  The billing model in one paragraph
&lt;/h2&gt;

&lt;p&gt;You pay for document reads, writes, and deletes by count; for stored bytes by GiB-month; and for egress. A query returning 100 documents costs 100 reads regardless of document size. A query returning 0 documents costs a minimum charge, not zero. Indicative Blaze rates (us multi-region) are roughly $0.06 / 100k reads, $0.18 / 100k writes, $0.02 / 100k deletes, $0.18 / GiB-month storage. Free tier is 50k reads / 20k writes / 20k deletes per day, 1 GiB stored.&lt;/p&gt;

&lt;p&gt;Those read numbers look cheap until you multiply them by &lt;em&gt;users × screens × documents per screen&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  N+1 is not a latency problem here, it is a line item
&lt;/h2&gt;

&lt;p&gt;In an RDB, N+1 is a latency and connection-pool concern. In Firestore it is literally arithmetic on your invoice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// 20 posts&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;postsSnapshot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doc&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;postsSnapshot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;docs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="c1"&gt;// + 1 read each, serially&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userDoc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;userDoc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;40 reads per timeline render. At 1,000 daily active users opening the timeline three times each, that is 120,000 reads/day — you blew through the free tier before lunch, and you did it to display a display name.&lt;/p&gt;

&lt;p&gt;Three escape hatches, in increasing order of commitment:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Batch the lookups.&lt;/strong&gt; Collect the unique author IDs and use an &lt;code&gt;in&lt;/code&gt; query. Same read count for the user docs, but one round trip instead of N, and deduplication actually cuts reads when authors repeat:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;))];&lt;/span&gt;
&lt;span class="c1"&gt;// `in` takes up to 30 values per query&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;__name__&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;in&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;flatMap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;docs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Denormalize the display fields into the parent.&lt;/strong&gt; This is the NoSQL-native answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;posts/post_&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Firestore cost model"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"user_abc"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Taro Yamada"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"avatarUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://..."&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;20 reads instead of 40. The cost moves to writes: renaming a user means fanning out an update across their historical posts. That trade is good when reads dominate writes by an order of magnitude, which for a social timeline they do. It is bad for fields that change often or must be strictly consistent — do not denormalize an email address you use for auth decisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Accept the join and cache it.&lt;/strong&gt; Author documents are small, stable, and heavily reused. The client SDK cache handles this for free (below).&lt;/p&gt;

&lt;h2&gt;
  
  
  Never count by fetching
&lt;/h2&gt;

&lt;p&gt;The single most expensive mistake is computing a count client-side:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// 1,000 likes = 1,000 reads, to display the number "1000"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;likes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;likes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;likes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the aggregation query instead — it is billed at one read per 1,000 index entries scanned, not per document:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getCountFromServer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;firebase/firestore&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;snap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getCountFromServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;likes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;snap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For hot counters that appear in list views, keep a materialized &lt;code&gt;likeCount&lt;/code&gt; field on the post and maintain it with &lt;code&gt;FieldValue.increment(1)&lt;/code&gt;. A single document has a sustained write limit of roughly 1 write/second, so shard the counter if a post can go viral.&lt;/p&gt;

&lt;h2&gt;
  
  
  onSnapshot bills you while you are not looking
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;get()&lt;/code&gt; costs money when &lt;em&gt;you&lt;/em&gt; ask. &lt;code&gt;onSnapshot&lt;/code&gt; costs money when &lt;em&gt;the data changes&lt;/em&gt; — which is a fundamentally different risk profile, because the cost is driven by other people's write traffic and by how long your tab stays open.&lt;/p&gt;

&lt;p&gt;The listener charges the initial result set once, then one read per changed document delivered. The failure mode compounds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A post document carries a &lt;code&gt;likeCount&lt;/code&gt; that updates in real time.&lt;/li&gt;
&lt;li&gt;100 users like it → 100 document updates → 100 reads delivered to &lt;em&gt;each&lt;/em&gt; open listener.&lt;/li&gt;
&lt;li&gt;1,000 users have that screen open → 100,000 reads in a few seconds.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rules that keep this bounded:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;onSnapshot&lt;/code&gt; only where realtime is the product (chat, presence, collaborative editing). Settings screens, archives, and list views get &lt;code&gt;get()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Always unsubscribe. A leaked listener is a meter that keeps running after the user navigated away:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;unsubscribe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;onSnapshot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;docRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;snap&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;snap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;unsubscribe&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;// not optional&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;docRef&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Keep volatile fields out of documents that are widely listened to. If &lt;code&gt;likeCount&lt;/code&gt; lives on the post document, every like re-delivers the whole post to every listener. Move it to a sibling document that only the detail view subscribes to.&lt;/li&gt;
&lt;li&gt;Detach listeners on &lt;code&gt;visibilitychange&lt;/code&gt; for background tabs if your app is long-lived.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Client cache is a first-class cost lever
&lt;/h2&gt;

&lt;p&gt;The web and mobile SDKs will serve repeat reads from local storage instead of the network:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;initializeFirestore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;persistentLocalCache&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;firebase/firestore&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;initializeFirestore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;localCache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;persistentLocalCache&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigating back to a screen you already loaded becomes free. You can also opt individual reads into cache-first behavior with &lt;code&gt;getDocFromCache&lt;/code&gt;, with a network fallback. This is the cheapest optimization available and it requires no schema change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Provisioning it with Terraform
&lt;/h2&gt;

&lt;p&gt;Firestore, its composite indexes, and its security rules are all declarable. Note &lt;code&gt;deletion_policy&lt;/code&gt; — set it to &lt;code&gt;ABANDON&lt;/code&gt;/delete-protected in production so a &lt;code&gt;terraform destroy&lt;/code&gt; in the wrong workspace does not take the database with it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_firestore_database"&lt;/span&gt; &lt;span class="s2"&gt;"database"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;project&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project_id&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"(default)"&lt;/span&gt;
  &lt;span class="nx"&gt;location_id&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"asia-northeast1"&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;                        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"FIRESTORE_NATIVE"&lt;/span&gt;
  &lt;span class="nx"&gt;concurrency_mode&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"OPTIMISTIC"&lt;/span&gt;
  &lt;span class="nx"&gt;app_engine_integration_mode&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"DISABLED"&lt;/span&gt;
  &lt;span class="nx"&gt;deletion_policy&lt;/span&gt;             &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ABANDON"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_firestore_index"&lt;/span&gt; &lt;span class="s2"&gt;"posts_status_created_at"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;project&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;google_firestore_database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;
  &lt;span class="nx"&gt;database&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;google_firestore_database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;collection&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"posts"&lt;/span&gt;

  &lt;span class="nx"&gt;fields&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;field_path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"status"&lt;/span&gt;
    &lt;span class="nx"&gt;order&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ASCENDING"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;fields&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;field_path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"created_at"&lt;/span&gt;
    &lt;span class="nx"&gt;order&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"DESCENDING"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_firebaserules_ruleset"&lt;/span&gt; &lt;span class="s2"&gt;"firestore"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;project&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project_id&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;files&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;name&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"firestore.rules"&lt;/span&gt;
      &lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"${path.module}/firestore.rules"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_firebaserules_release"&lt;/span&gt; &lt;span class="s2"&gt;"firestore"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;project&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project_id&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"cloud.firestore"&lt;/span&gt;
  &lt;span class="nx"&gt;ruleset_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;google_firebaserules_ruleset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firestore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;FIRESTORE_NATIVE&lt;/code&gt; versus &lt;code&gt;DATASTORE_MODE&lt;/code&gt; is the one decision you cannot walk back: the mode is fixed at database creation. Native mode gives you realtime listeners, direct client SDK access, and security rules; Datastore mode exists for compatibility with legacy Cloud Datastore and is controlled by IAM only. New projects should pick Native mode unconditionally, even for backend-only access.&lt;/p&gt;

&lt;h2&gt;
  
  
  Security rules are the only perimeter for client access
&lt;/h2&gt;

&lt;p&gt;If the browser talks to Firestore directly, rules are not defense in depth — they are the entire defense. Default-deny, then grant narrowly, and validate the shape of writes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;rules_version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;service&lt;/span&gt; &lt;span class="nx"&gt;cloud&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firestore&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;databases&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sr"&gt;/documents &lt;/span&gt;&lt;span class="err"&gt;{
&lt;/span&gt;
    &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="o"&gt;=**&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;allow&lt;/span&gt; &lt;span class="nx"&gt;read&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;write&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;allow&lt;/span&gt; &lt;span class="na"&gt;read&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;allow&lt;/span&gt; &lt;span class="na"&gt;write&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;uid&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;allow&lt;/span&gt; &lt;span class="na"&gt;read&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="nx"&gt;allow&lt;/span&gt; &lt;span class="na"&gt;create&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authorId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;uid&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="nx"&gt;allow&lt;/span&gt; &lt;span class="nx"&gt;update&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
                            &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authorId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;uid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things people get wrong:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;resource.data&lt;/code&gt; is the document &lt;em&gt;before&lt;/em&gt; the write; &lt;code&gt;request.resource.data&lt;/code&gt; is what the client is proposing. Ownership checks on update read the former; field validation reads the latter.&lt;/li&gt;
&lt;li&gt;Rules are not filters. A rule that allows reading only your own documents does not make &lt;code&gt;collection('posts').get()&lt;/code&gt; return a filtered set — it makes the whole query fail. The query must be constrained to match the rule.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And note that the Admin SDK &lt;strong&gt;bypasses rules entirely&lt;/strong&gt;. Any backend holding those credentials is fully trusted; give its service account &lt;code&gt;roles/datastore.user&lt;/code&gt;, never &lt;code&gt;roles/datastore.owner&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Count reads per screen render in the network log, then multiply by expected DAU × sessions.&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;await get()&lt;/code&gt; inside a loop. Batch with &lt;code&gt;in&lt;/code&gt;, or denormalize.&lt;/li&gt;
&lt;li&gt;Never &lt;code&gt;.get()&lt;/code&gt; a collection to call &lt;code&gt;.size&lt;/code&gt; — use &lt;code&gt;count()&lt;/code&gt; or a maintained counter field.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;onSnapshot&lt;/code&gt; only where realtime is the feature, and always with an unsubscribe.&lt;/li&gt;
&lt;li&gt;Keep hot-updating fields out of widely-listened documents.&lt;/li&gt;
&lt;li&gt;Turn on persistent local cache.&lt;/li&gt;
&lt;li&gt;Set a budget alert before you need one.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>firestore</category>
      <category>gcp</category>
      <category>nosql</category>
      <category>terraform</category>
    </item>
    <item>
      <title>Making Refresh Tokens Actually Work in a FastMCP Google OAuth Server</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Tue, 08 Sep 2026 12:08:38 +0000</pubDate>
      <link>https://dev.to/toyama0919/making-refresh-tokens-actually-work-in-a-fastmcp-google-oauth-server-3bp9</link>
      <guid>https://dev.to/toyama0919/making-refresh-tokens-actually-work-in-a-fastmcp-google-oauth-server-3bp9</guid>
      <description>&lt;p&gt;If you stand up an MCP server with &lt;code&gt;GoogleProvider&lt;/code&gt;, OAuth works on the first try. Clients authorize, tools run, and refresh appears to work — until the server restarts.&lt;/p&gt;

&lt;p&gt;That is not a bug you fix after the fact. It is a configuration decision you make up front, because of how &lt;code&gt;OAuthProxy&lt;/code&gt; implements refresh. This post covers what refresh actually requires from your deployment, and how to satisfy it.&lt;/p&gt;

&lt;p&gt;Verified against &lt;code&gt;fastmcp==3.4.2&lt;/code&gt; and &lt;code&gt;py-key-value-aio==0.4.5&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Refresh in OAuthProxy is a storage lookup
&lt;/h2&gt;

&lt;p&gt;The key thing to understand: &lt;code&gt;GoogleProvider&lt;/code&gt; extends &lt;code&gt;OAuthProxy&lt;/code&gt;, and the token your MCP client holds is &lt;strong&gt;not&lt;/strong&gt; the upstream Google token. The proxy issues its own credential, which is a &lt;em&gt;reference into a key-value store&lt;/em&gt;. Google's tokens stay server-side.&lt;/p&gt;

&lt;p&gt;That design is what makes the proxy useful — clients never see upstream credentials, and the proxy can refresh upstream tokens on their behalf. It also means refresh has a hard requirement: the store must still contain the entry.&lt;/p&gt;

&lt;p&gt;In FastMCP 3.4.2 the proxy keeps six collections:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;default_collection&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mcp-upstream-tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;        &lt;span class="c1"&gt;# upstream Google access/refresh tokens
&lt;/span&gt;&lt;span class="n"&gt;default_collection&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mcp-oauth-proxy-clients&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;    &lt;span class="c1"&gt;# DCR client registrations
&lt;/span&gt;&lt;span class="n"&gt;default_collection&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mcp-oauth-transactions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;     &lt;span class="c1"&gt;# in-flight IdP callbacks
&lt;/span&gt;&lt;span class="n"&gt;default_collection&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mcp-authorization-codes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;default_collection&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mcp-jti-mappings&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;default_collection&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mcp-refresh-tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;         &lt;span class="c1"&gt;# refresh token metadata, keyed by hash
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a refresh arrives, the proxy hashes the incoming refresh token and looks up its metadata:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;token_hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;_hash_token&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;refresh_token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;metadata&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_refresh_token_store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;token_hash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Refresh token not found for client=%s (token_hash=%s); it was &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;already rotated, expired, or revoked. Rejecting with invalid_grant, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;which forces the client to re-authenticate.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;...&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No entry, no refresh. &lt;code&gt;invalid_grant&lt;/code&gt;, and the client falls back to a full re-authorization. Two of those six collections gate every refresh: &lt;code&gt;mcp-refresh-tokens&lt;/code&gt; for the grant itself, and &lt;code&gt;mcp-oauth-proxy-clients&lt;/code&gt; for the Dynamic Client Registration the grant belongs to.&lt;/p&gt;

&lt;p&gt;So "supporting refresh tokens" reduces to one question: &lt;strong&gt;where does that store live, and who can see it?&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The default store answers that question badly for servers
&lt;/h2&gt;

&lt;p&gt;If you never pass &lt;code&gt;client_storage&lt;/code&gt;, the proxy builds one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# fastmcp/server/auth/oauth_proxy/proxy.py
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;client_storage&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;storage_encryption_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;derive_jwt_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;high_entropy_material&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;jwt_signing_key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="n"&gt;salt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fastmcp-storage-encryption-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;key_fingerprint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;storage_encryption_key&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;hexdigest&lt;/span&gt;&lt;span class="p"&gt;()[:&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;storage_dir&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;oauth-proxy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;key_fingerprint&lt;/span&gt;
    &lt;span class="n"&gt;storage_dir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exist_ok&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;file_store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FileTreeStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data_directory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;storage_dir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...)&lt;/span&gt;

    &lt;span class="n"&gt;client_storage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FernetEncryptionWrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;key_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;file_store&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;fernet&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Fernet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;storage_encryption_key&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;raise_on_decryption_error&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An encrypted file store on local disk. Ideal for a long-lived single process; wrong for anything that redeploys or scales horizontally. On Cloud Run, Fly, ECS or Kubernetes the container filesystem is per-revision and per-replica, so refresh state is either erased on deploy or invisible to the instance handling the request.&lt;/p&gt;

&lt;p&gt;Worth noting because it makes the failure counterintuitive: the JWT signing key is &lt;em&gt;not&lt;/em&gt; ephemeral.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;jwt_signing_key&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;upstream_client_secret&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
    &lt;span class="n"&gt;jwt_signing_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;derive_jwt_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;high_entropy_material&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;upstream_client_secret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;salt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fastmcp-jwt-signing-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is derived deterministically from the upstream client secret, which lives in your secret manager. So tokens still verify after a restart — they just resolve to nothing. You see a &lt;code&gt;401&lt;/code&gt; on &lt;code&gt;/token&lt;/code&gt;, not a signature error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;12:53:44  200  /.well-known/oauth-authorization-server
12:53:44  401  https://mcp-dev.example.com/token     &amp;lt;- refresh rejected
12:54:37  401  /mcp
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And because the same store backs every instance, the identical failure shows up under scale-out with no deploy involved.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure a shared store
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;client_storage&lt;/code&gt; accepts any &lt;code&gt;AsyncKeyValue&lt;/code&gt; from &lt;a href="https://pypi.org/project/py-key-value-aio/" rel="noopener noreferrer"&gt;py-key-value-aio&lt;/a&gt;, which FastMCP already depends on. Version 0.4.5 ships stores for Firestore, PostgreSQL, Redis, S3, DynamoDB and MongoDB, so the backend is a deployment choice, not a code change.&lt;/p&gt;

&lt;p&gt;We chose Firestore: it authenticates with ADC from the runtime service account, so there is no connection string and no additional secret to rotate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;cryptography.fernet&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Fernet&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastmcp.server.auth.jwt_issuer&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;derive_jwt_key&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;key_value.aio.protocols&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AsyncKeyValue&lt;/span&gt;

&lt;span class="n"&gt;_JWT_SIGNING_KEY_SALT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fastmcp-jwt-signing-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;_STORAGE_ENCRYPTION_KEY_SALT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fastmcp-storage-encryption-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;_derive_storage_encryption_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client_secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Reproduce FastMCP&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s own key derivation chain.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;jwt_signing_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;derive_jwt_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;high_entropy_material&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;client_secret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;salt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;_JWT_SIGNING_KEY_SALT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;derive_jwt_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;high_entropy_material&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;jwt_signing_key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="n"&gt;salt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;_STORAGE_ENCRYPTION_KEY_SALT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;build_client_storage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;client_secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;AsyncKeyValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;key_value.aio.stores.firestore&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;FirestoreStore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;FirestoreV1CollectionSanitizationStrategy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;FirestoreV1KeySanitizationStrategy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;key_value.aio.wrappers.encryption&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FernetEncryptionWrapper&lt;/span&gt;
    &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;key_value.aio.wrappers.prefix_collections&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;PrefixCollectionsWrapper&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;FernetEncryptionWrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;key_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;PrefixCollectionsWrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;key_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;FirestoreStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;key_sanitization_strategy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;FirestoreV1KeySanitizationStrategy&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
                &lt;span class="n"&gt;collection_sanitization_strategy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;FirestoreV1CollectionSanitizationStrategy&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;fernet&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Fernet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;_derive_storage_encryption_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client_secret&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
        &lt;span class="n"&gt;raise_on_decryption_error&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wire it into the provider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;auth_provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;GoogleProvider&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_ID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;client_secret&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_SECRET&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;FASTMCP_SERVER_AUTH_GOOGLE_BASE_URL&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;client_storage&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;build_client_storage&lt;/span&gt;&lt;span class="p"&gt;(...),&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every layer in that stack is load-bearing. Here is why each one is there.&lt;/p&gt;

&lt;h3&gt;
  
  
  Re-apply encryption yourself
&lt;/h3&gt;

&lt;p&gt;Look at where &lt;code&gt;FernetEncryptionWrapper&lt;/code&gt; sits in the default path: &lt;strong&gt;inside the &lt;code&gt;if client_storage is None&lt;/code&gt; branch&lt;/strong&gt;. Pass your own store and that wrapper is never applied. Upstream Google access and refresh tokens then land in &lt;code&gt;mcp-upstream-tokens&lt;/code&gt; in whatever form the backend writes — plaintext documents, for Firestore.&lt;/p&gt;

&lt;p&gt;Deriving the key from the same client secret keeps the number of managed secrets at zero, and it rotates with the credential it protects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pass &lt;code&gt;raise_on_decryption_error=False&lt;/code&gt; explicitly
&lt;/h3&gt;

&lt;p&gt;FastMCP passes &lt;code&gt;False&lt;/code&gt; to its own wrapper. &lt;code&gt;FernetEncryptionWrapper&lt;/code&gt; defaults to &lt;code&gt;True&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The difference only surfaces when you rotate the upstream client secret: with &lt;code&gt;True&lt;/code&gt;, stale ciphertext raises and you serve 500s; with &lt;code&gt;False&lt;/code&gt; it counts as a cache miss, so clients re-register and re-authenticate. Degraded beats broken — match FastMCP.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sanitize keys for your backend
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;OAuthProxy&lt;/code&gt; enables CIMD (Client ID Metadata Document) by default (&lt;code&gt;enable_cimd: bool = True&lt;/code&gt;), and CIMD client IDs are URLs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_cimd_manager&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_cimd_manager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_cimd_client_id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;cimd_client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_cimd_manager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;cimd_client&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_client_store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cimd_client&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That URL becomes a storage key verbatim, and a Firestore document ID cannot contain &lt;code&gt;/&lt;/code&gt;. &lt;code&gt;FirestoreStore&lt;/code&gt; defaults to passthrough sanitization, so you must opt in. FastMCP's own default explicitly passes &lt;code&gt;FileTreeV1KeySanitizationStrategy&lt;/code&gt; for the same reason — whichever backend you pick, check what its key constraints are.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prefix collections if a database is shared
&lt;/h3&gt;

&lt;p&gt;Those six collection names are constants. Two MCP servers pointed at one database share &lt;code&gt;mcp-oauth-proxy-clients&lt;/code&gt; and everything else. &lt;code&gt;PrefixCollectionsWrapper(prefix=&amp;lt;service&amp;gt;)&lt;/code&gt; namespaces them, which is what makes a single shared database viable when you expect to run more than one Google-OAuth MCP server.&lt;/p&gt;

&lt;h3&gt;
  
  
  Never fall back to the ephemeral store
&lt;/h3&gt;

&lt;p&gt;It is tempting to catch storage errors and degrade to the default file store. Don't. A silent fallback restores precisely the behavior you configured the store to avoid, except now it is invisible — the service looks healthy and quietly drops every session on the next deploy. Fail loudly at startup on misconfiguration and let runtime storage errors surface.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In &lt;code&gt;OAuthProxy&lt;/code&gt;, the token a client holds is a reference into a key-value store; refresh is a lookup in &lt;code&gt;mcp-refresh-tokens&lt;/code&gt; plus the client registration in &lt;code&gt;mcp-oauth-proxy-clients&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The default store is a container-local file store, so refresh survives neither redeploys nor scale-out. The JWT signing key is derived from the client secret and &lt;em&gt;does&lt;/em&gt; survive, which is why the symptom is a &lt;code&gt;/token&lt;/code&gt; 401 rather than a signature failure.&lt;/li&gt;
&lt;li&gt;Supporting refresh means passing a shared &lt;code&gt;client_storage&lt;/code&gt; — then re-applying the encryption wrapper, matching &lt;code&gt;raise_on_decryption_error=False&lt;/code&gt;, and sanitizing keys for the backend.&lt;/li&gt;
&lt;li&gt;Prefix collections when a database is shared across servers, and never silently fall back to the ephemeral store.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>oauth</category>
      <category>mcp</category>
      <category>gcp</category>
    </item>
    <item>
      <title>A Layered Evaluation Strategy for LLM Agents (Google ADK's 12 Criteria)</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Sat, 01 Aug 2026 04:17:14 +0000</pubDate>
      <link>https://dev.to/toyama0919/a-layered-evaluation-strategy-for-llm-agents-google-adks-12-criteria-6cf</link>
      <guid>https://dev.to/toyama0919/a-layered-evaluation-strategy-for-llm-agents-google-adks-12-criteria-6cf</guid>
      <description>&lt;p&gt;Google's &lt;a href="https://adk.dev/evaluate/criteria/" rel="noopener noreferrer"&gt;Agent Development Kit (ADK)&lt;/a&gt; ships 12 evaluation criteria for testing agent behavior: tool-call trajectories, final response quality, hallucination detection, safety, multi-turn task success, and more. The natural instinct is to wire all 12 into your PR pipeline and call it done. That instinct is wrong, and the reason why is worth understanding before you build an eval suite for any agent, ADK or not.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 12 criteria, grouped by what they actually measure
&lt;/h2&gt;

&lt;p&gt;ADK's criteria split cleanly along two axes: does it need a golden reference or rubric, and does it call an LLM-as-a-Judge.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Criteria&lt;/th&gt;
&lt;th&gt;Golden Reference&lt;/th&gt;
&lt;th&gt;Rubric&lt;/th&gt;
&lt;th&gt;LLM Judge&lt;/th&gt;
&lt;th&gt;User Simulation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;tool_trajectory_avg_score&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;response_match_score&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;final_response_match_v2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;rubric_based_final_response_quality_v1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;rubric_based_tool_use_quality_v1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;rubric_based_multi_turn_trajectory_quality_v1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;hallucinations_v1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;safety_v1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;per_turn_user_simulator_quality_v1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;multi_turn_task_success_v1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;multi_turn_trajectory_quality_v1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;multi_turn_tool_use_quality_v1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Ten out of twelve depend on an LLM Judge. That single fact is why "run everything on every PR" doesn't survive contact with a real pipeline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why full coverage in CI breaks down
&lt;/h2&gt;

&lt;p&gt;Three structural constraints show up as soon as you try:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Latency.&lt;/strong&gt; LLM-as-a-Judge and User Simulation cases take tens of seconds to minutes each. Multiply by a real test matrix and PR turnaround goes from minutes to an hour-plus.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost.&lt;/strong&gt; For N test cases and T turns, a User Simulation + Judge suite costs roughly &lt;code&gt;O(N × T)&lt;/code&gt; in tokens. Running that on every commit is not something FinOps will sign off on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flakiness.&lt;/strong&gt; Even at &lt;code&gt;temperature=0.0&lt;/code&gt;, Judge and Simulator outputs drift. A red CI run stops meaning "the code is broken" — it might just mean the Judge had an off moment. Once developers can't trust red, they start ignoring it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There's also a subtler problem with the two deterministic criteria (&lt;code&gt;tool_trajectory_avg_score&lt;/code&gt;, &lt;code&gt;response_match_score&lt;/code&gt;). &lt;code&gt;response_match_score&lt;/code&gt; uses ROUGE-1 — raw unigram overlap — which is brittle against formatting or phrasing changes and produces false negatives whenever you touch a prompt. And &lt;code&gt;tool_trajectory_avg_score&lt;/code&gt; in &lt;code&gt;EXACT&lt;/code&gt; or &lt;code&gt;IN_ORDER&lt;/code&gt; mode punishes an agent for finding a more efficient (e.g., parallelized) tool-call order after a model upgrade. Strict matching modes actively discourage improvement.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: layer by execution frequency and determinism
&lt;/h2&gt;

&lt;p&gt;The resolution is a three-layer pyramid, ordered by how often it runs and how deterministic it is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 Layer 3: E2E / Scenario Eval        [weekly / pre-release]
                 - User Simulation                    high cost / non-deterministic
                 - multi_turn_task_success
            ------------------------------------
              Layer 2: Nightly / Quality &amp;amp; Safety     [daily]
              - hallucinations_v1 / safety_v1          medium cost / LLM Judge
              - rubric_based_final_response
            ------------------------------------
            Layer 1: PR / Pre-commit (deterministic CI) [per commit/PR]
            - tool_trajectory_avg_score (ANY_ORDER)     low cost / deterministic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Layer 1 — PR gate: no LLM calls at all
&lt;/h3&gt;

&lt;p&gt;The only criterion here is &lt;code&gt;tool_trajectory_avg_score&lt;/code&gt;, run in &lt;code&gt;ANY_ORDER&lt;/code&gt; (not &lt;code&gt;EXACT&lt;/code&gt;) mode — asserting only that the required tools fired, not the exact sequence. External APIs are mocked. Zero LLM calls, zero dollars, sub-minute runtime.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pytest&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google.adk.evaluation&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AgentEvaluator&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;my_agent.agent&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;root_agent&lt;/span&gt;

&lt;span class="nd"&gt;@pytest.mark.asyncio&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_layer1_tool_trajectory&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;PR/CI gate: deterministic tool-call check, no LLM involved.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;evaluator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AgentEvaluator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;root_agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;config_path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tests/eval_cases/layer1_ci.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;evaluator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run_evaluation&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;case_results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool_trajectory_avg_score&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt;
        &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Failed case &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;case_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: score=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;layer1_ci.json&lt;/code&gt; pins the config that makes this deterministic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"criteria"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"tool_trajectory_avg_score"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"threshold"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"match_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ANY_ORDER"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Layer 2 — Nightly: quality, hallucination, safety
&lt;/h3&gt;

&lt;p&gt;This is where LLM-as-a-Judge enters, against a fixed, versioned dataset (hundreds of cases, not the full corpus). Two things matter for keeping this layer trustworthy: pin the Judge model and its temperature, and track score deltas over time rather than just absolute thresholds.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;evaluator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AgentEvaluator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;root_agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;config_path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tests/eval_cases/layer2_nightly.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;judge_model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gemini-1.5-pro&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;judge_model_config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;temperature&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;evaluator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run_evaluation&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;case_results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hallucinations_v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.9&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;safety_v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;
    &lt;span class="n"&gt;rubric&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rubric_based_final_response_quality_v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;rubric&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rubric&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reasoning&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A rubric criterion needs an explicit, weighted rubric — not a vague adjective. This is the part teams get wrong most often:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"rubric_based_final_response_quality_v1"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"threshold"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"rubrics"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"conclusion_first"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Does the first 1-2 sentences state a clear conclusion?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"weight"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"formatting_structure"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Is the response structured with Markdown lists/headings?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"weight"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"technical_explanation"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Are technical terms briefly defined in context?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"weight"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Write rubric items as objectively checkable conditions, not subjective adjectives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bad: "explained in an easy-to-understand way"&lt;/li&gt;
&lt;li&gt;Good: "each technical term is followed by a one-sentence definition, either in parentheses or the next sentence"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Judge LLM receives the query, the response, and the weighted rubric list, and returns per-item scores plus a weighted average — so a failing assertion comes with a &lt;code&gt;reasoning&lt;/code&gt; string you can read directly, not just a number.&lt;/p&gt;

&lt;h3&gt;
  
  
  Layer 3 — pre-release E2E: multi-turn simulation
&lt;/h3&gt;

&lt;p&gt;This layer runs a User Simulator LLM against the agent across several turns and checks goal completion (&lt;code&gt;multi_turn_task_success_v1&lt;/code&gt;) plus process quality (&lt;code&gt;multi_turn_trajectory_quality_v1&lt;/code&gt;, &lt;code&gt;multi_turn_tool_use_quality_v1&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;evaluator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AgentEvaluator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;root_agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;config_path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tests/eval_cases/layer3_e2e.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;user_simulator_model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gemini-1.5-flash&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;judge_model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gemini-1.5-pro&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;judge_model_config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;temperature&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;evaluator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run_evaluation&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;case_results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;sim_quality&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;per_turn_user_simulator_quality_v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sim_quality&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;pytest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;skip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Simulator degraded in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;case_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;multi_turn_task_success_v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;multi_turn_trajectory_quality_v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note the &lt;code&gt;pytest.skip&lt;/code&gt; guard on &lt;code&gt;per_turn_user_simulator_quality_v1&lt;/code&gt;. This layer has a structural gotcha worth calling out explicitly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The gotcha: meta-evaluation error propagation
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;per_turn_user_simulator_quality_v1&lt;/code&gt; exists because this layer has three LLMs talking past each other: a Simulator LLM playing the user, the Agent under test, and a Judge LLM scoring the outcome. That's a "Judge judging a Judge" structure — if the Simulator goes off-script (loops, ignores its own goal, hallucinates a constraint), the resulting &lt;code&gt;task_success&lt;/code&gt; score reflects the Simulator's failure, not the agent's. Skipping low-quality-simulation sessions before asserting on task success is not optional defensive coding — without it, a bad night for the Simulator model silently fails your agent's release gate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wiring it into CI/CD
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Agent Evaluation Pipeline&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;main&lt;/span&gt; &lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="na"&gt;schedule&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;cron&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;18&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;*'&lt;/span&gt;  &lt;span class="c1"&gt;# nightly&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;layer1-ci&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-python@v5&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;python-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3.11'&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pip install -r requirements.txt&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pytest tests/test_layer1_ci.py&lt;/span&gt;

  &lt;span class="na"&gt;layer2-layer3-nightly&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github.event_name == 'schedule'&lt;/span&gt;
    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;layer1-ci&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;GEMINI_API_KEY&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.GEMINI_API_KEY }}&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-python@v5&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;python-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3.11'&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pip install -r requirements.txt&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pytest tests/test_layer2_nightly.py&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pytest tests/test_layer3_e2e.py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only Layer 1 blocks the PR. Layers 2 and 3 run on schedule, against main, and their failures route to a human triage step rather than a red PR check.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to put the eval code
&lt;/h2&gt;

&lt;p&gt;A recurring question: does eval code belong under &lt;code&gt;tests/&lt;/code&gt;? The honest answer is that &lt;code&gt;tests/&lt;/code&gt; and &lt;code&gt;evals/&lt;/code&gt; are different disciplines and benefit from being separated at the top level:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
├── src/
│   └── my_agent/
├── tests/                 # deterministic, mocked, no API calls
│   ├── test_tools.py
│   └── test_state_management.py
└── evals/                 # probabilistic, real API/Simulator calls
    ├── datasets/
    ├── metrics/            # custom rubric definitions
    └── run_evals.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;tests/&lt;/code&gt; should stay fast and free so a developer can run it locally without worrying about API spend. If eval code does live under &lt;code&gt;tests/&lt;/code&gt;, mark it explicitly (&lt;code&gt;pytest.mark.eval&lt;/code&gt;) so &lt;code&gt;pytest -m "not eval"&lt;/code&gt; stays the default local loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Only 1-2 of ADK's 12 criteria are realistic PR-blocking gates — &lt;code&gt;tool_trajectory_avg_score&lt;/code&gt; in &lt;code&gt;ANY_ORDER&lt;/code&gt; mode, backed by deterministic assertions and mocks. Everything that touches an LLM Judge or a User Simulator belongs in a nightly or pre-release layer, versioned against a fixed dataset, with the Judge model and temperature pinned for reproducibility. If your eval suite tries to be a single flat list run on every commit, expect flaky red builds and a PR queue nobody trusts — the fix isn't a better assertion, it's a different pyramid.&lt;/p&gt;

</description>
      <category>llm</category>
      <category>testing</category>
      <category>agents</category>
      <category>devops</category>
    </item>
    <item>
      <title>Editing an ext4 Partition Directly from macOS (No Linux VM Required)</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Thu, 30 Jul 2026 13:30:27 +0000</pubDate>
      <link>https://dev.to/toyama0919/editing-an-ext4-partition-directly-from-macos-no-linux-vm-required-3mic</link>
      <guid>https://dev.to/toyama0919/editing-an-ext4-partition-directly-from-macos-no-linux-vm-required-3mic</guid>
      <description>&lt;p&gt;I lost the private key for a Raspberry Pi and needed to add a new public key to &lt;code&gt;/root/.ssh/authorized_keys&lt;/code&gt;. The Pi's SD card was plugged into a Mac via a USB reader, so &lt;code&gt;diskutil list&lt;/code&gt; could see the partitions fine — but the root filesystem was ext4, which macOS cannot mount. No spare Linux box, no VM set up, just Docker Desktop (which, on Apple Silicon, only gives you a Linux &lt;em&gt;kernel&lt;/em&gt; inside its VM — it doesn't let a container touch a host block device like &lt;code&gt;/dev/disk5s3&lt;/code&gt;). This is the path that worked without either of those.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trick: e2fsprogs is userspace
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;e2fsck&lt;/code&gt;, &lt;code&gt;debugfs&lt;/code&gt;, and friends from &lt;code&gt;e2fsprogs&lt;/code&gt; don't rely on the kernel's ext4 driver at all — they implement the ext2/3/4 on-disk format entirely in userspace and just do &lt;code&gt;read()&lt;/code&gt;/&lt;code&gt;write()&lt;/code&gt;/&lt;code&gt;lseek()&lt;/code&gt; on whatever path you give them. That means they work identically whether the target is a regular file, a disk image, or — critically — a raw device node on macOS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;e2fsprogs
&lt;span class="c"&gt;# keg-only, so call it by full path or add it to PATH&lt;/span&gt;
&lt;span class="nv"&gt;DEBUGFS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/opt/homebrew/opt/e2fsprogs/sbin/debugfs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;diskutil list&lt;/code&gt; showed the target as &lt;code&gt;disk5&lt;/code&gt;, with the Linux root filesystem on the third slice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/dev/disk5 (external, physical):
   1: Windows_FAT_32   ...   disk5s1
   2: Linux_Swap       ...   disk5s2
   3: Linux            ...   disk5s3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read-only exploration works immediately, no mount required:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$DEBUGFS&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"ls -l /root/.ssh"&lt;/span&gt; /dev/rdisk5s3
&lt;span class="nv"&gt;$DEBUGFS&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"dump /root/.ssh/authorized_keys ./authorized_keys.bak"&lt;/span&gt; /dev/rdisk5s3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ls -l&lt;/code&gt;, &lt;code&gt;stat&lt;/code&gt;, and &lt;code&gt;dump&lt;/code&gt; give you inode numbers, permissions, timestamps, and file contents without ever mounting the partition. For a simple edit — appending one line to an existing file — I dumped the file, merged in the new key locally, and wrote it back with &lt;code&gt;debugfs -w&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$DEBUGFS&lt;/span&gt; &lt;span class="nt"&gt;-w&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"rm /root/.ssh/authorized_keys"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"write ./authorized_keys.merged /root/.ssh/authorized_keys"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"sif /root/.ssh/authorized_keys mode 0100600"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"sif /root/.ssh/authorized_keys uid 0"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"sif /root/.ssh/authorized_keys gid 0"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            /dev/rdisk5s3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the whole mechanism. Two things went wrong on the way there, and both are worth knowing before you try this on a filesystem you actually care about.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 1: chained &lt;code&gt;-R&lt;/code&gt; commands don't share a working directory
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;debugfs -w&lt;/code&gt; accepts multiple &lt;code&gt;-R&lt;/code&gt; flags to run several commands in one invocation. I assumed &lt;code&gt;cd&lt;/code&gt; would set the working directory for the rest of the chain, the way it would in an interactive &lt;code&gt;debugfs&lt;/code&gt; session:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$DEBUGFS&lt;/span&gt; &lt;span class="nt"&gt;-w&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"cd /root/.ssh"&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"write ./authorized_keys.merged authorized_keys"&lt;/span&gt; /dev/rdisk5s3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It silently wrote the file to &lt;code&gt;/authorized_keys&lt;/code&gt; (filesystem root) instead of &lt;code&gt;/root/.ssh/authorized_keys&lt;/code&gt;. The &lt;code&gt;cd&lt;/code&gt; had no effect across the command boundary. Lesson: when scripting &lt;code&gt;debugfs -w&lt;/code&gt; with multiple &lt;code&gt;-R&lt;/code&gt; flags, always give &lt;code&gt;write&lt;/code&gt;/&lt;code&gt;rm&lt;/code&gt;/&lt;code&gt;sif&lt;/code&gt; a full path. Don't rely on &lt;code&gt;cd&lt;/code&gt; persisting — verify with &lt;code&gt;ls -l&lt;/code&gt; after every mutating step instead of trusting the command succeeded as intended.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha 2: raw device + journal replay can undo your own edits
&lt;/h2&gt;

&lt;p&gt;The bigger issue: after the edit, I ran a routine consistency check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;e2fsck &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; /dev/rdisk5s3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This printed &lt;code&gt;recovering journal&lt;/code&gt;, then &lt;code&gt;unable to set superblock flags on /dev/rdisk5s3&lt;/code&gt; and aborted with errors still present. A subsequent read of the file showed its inode had been reverted to an &lt;em&gt;unrelated, long-deleted file's metadata&lt;/em&gt; — wrong owner, &lt;code&gt;dtime&lt;/code&gt; set, zero links. My freshly-written &lt;code&gt;authorized_keys&lt;/code&gt; was gone, even though the data block itself was untouched.&lt;/p&gt;

&lt;p&gt;Here's what actually happened. &lt;code&gt;debugfs -w&lt;/code&gt; writes directly to blocks and bypasses the ext4 journal entirely. A live ext4 filesystem almost always has a non-empty journal — this is completely normal, not a sign of an unclean shutdown. As long as nothing tries to &lt;em&gt;replay&lt;/em&gt; that journal, an empty or stale journal is harmless. But &lt;code&gt;e2fsck -y&lt;/code&gt; does replay it, and if a journaled transaction happens to touch the same inode table block or bitmap you just hand-edited, replay wins: it overwrites your change with whatever stale state was recorded in the journal.&lt;/p&gt;

&lt;p&gt;The specific failure to write the superblock flags turned out to be a macOS quirk: &lt;code&gt;/dev/rdiskN&lt;/code&gt; is the &lt;em&gt;character&lt;/em&gt; (raw) device, and some of the small, oddly-sized writes e2fsprogs issues when finalizing (clearing the "needs recovery" flag, in this case) get rejected with &lt;code&gt;EINVAL&lt;/code&gt; because macOS raw devices require I/O aligned to the device's sector size. Switching to the &lt;em&gt;block&lt;/em&gt; device node fixed it — no code changes, just a different path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;e2fsck &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; /dev/disk5s3   &lt;span class="c"&gt;# buffered block device, not /dev/rdisk5s3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Through the buffered device, the kernel's buffer cache absorbs the unaligned writes, and both the journal replay and the superblock update completed cleanly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The correct order of operations
&lt;/h2&gt;

&lt;p&gt;Putting the two gotchas together, the safe procedure for hand-editing a live ext4 image via &lt;code&gt;debugfs -w&lt;/code&gt; is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Recover the journal first&lt;/strong&gt;, before touching anything by hand: &lt;code&gt;e2fsck -y -f /dev/diskNsM&lt;/code&gt; (buffered device). This flushes any pending journaled transactions so they can't later clobber your edits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make your edits&lt;/strong&gt; with &lt;code&gt;debugfs -w&lt;/code&gt;, using absolute paths for every command, verifying each mutation with a read-only &lt;code&gt;ls -l&lt;/code&gt; / &lt;code&gt;stat&lt;/code&gt; immediately after.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verify with a read-only check&lt;/strong&gt;: &lt;code&gt;e2fsck -n -f /dev/diskNsM&lt;/code&gt;. If it comes back clean, you're done — resist the urge to run &lt;code&gt;e2fsck -y&lt;/code&gt; again "just to be safe"; there's nothing left for it to fix, and re-running it adds risk for no benefit.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. clean baseline&lt;/span&gt;
e2fsck &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; /dev/disk5s3

&lt;span class="c"&gt;# 2. edit (absolute paths only)&lt;/span&gt;
debugfs &lt;span class="nt"&gt;-w&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"write ./authorized_keys.merged /root/.ssh/authorized_keys"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"sif /root/.ssh/authorized_keys mode 0100600"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"sif /root/.ssh/authorized_keys uid 0"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s2"&gt;"sif /root/.ssh/authorized_keys gid 0"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            /dev/disk5s3

&lt;span class="c"&gt;# 3. confirm, read-only, no further writes&lt;/span&gt;
e2fsck &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; /dev/disk5s3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;e2fsprogs&lt;/code&gt; (&lt;code&gt;debugfs&lt;/code&gt;, &lt;code&gt;e2fsck&lt;/code&gt;) implements ext2/3/4 entirely in userspace, so it works against a raw macOS device node with no kernel ext4 driver and no Linux VM.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;debugfs -w&lt;/code&gt;'s chained &lt;code&gt;-R&lt;/code&gt; commands do not share a working directory — always use absolute paths and verify after each mutation.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;debugfs -w&lt;/code&gt; bypasses the journal. Running &lt;code&gt;e2fsck -y&lt;/code&gt; afterward replays it, and can silently revert your hand-edits if they share a block with a pending journaled transaction. Recover the journal &lt;em&gt;before&lt;/em&gt; you edit, not after.&lt;/li&gt;
&lt;li&gt;On macOS, prefer the buffered block device (&lt;code&gt;/dev/diskN&lt;/code&gt;) over the raw character device (&lt;code&gt;/dev/rdiskN&lt;/code&gt;) for &lt;code&gt;e2fsck&lt;/code&gt;/&lt;code&gt;debugfs&lt;/code&gt; writes — the raw device's alignment requirements can reject small metadata writes with &lt;code&gt;EINVAL&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>linux</category>
      <category>macos</category>
      <category>filesystems</category>
      <category>raspberrypi</category>
    </item>
    <item>
      <title>Stop Symlinking Your Cursor and Claude Code Rules — Generate Them Instead</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Sun, 12 Jul 2026 11:58:52 +0000</pubDate>
      <link>https://dev.to/toyama0919/stop-symlinking-your-cursor-and-claude-code-rules-generate-them-instead-3c9n</link>
      <guid>https://dev.to/toyama0919/stop-symlinking-your-cursor-and-claude-code-rules-generate-them-instead-3c9n</guid>
      <description>&lt;p&gt;If you use both Cursor and Claude Code on the same repo, you have probably noticed both tools support a &lt;code&gt;rules/&lt;/code&gt; directory of persistent instructions. The obvious move is to make them share one directory with a symlink. Don't. The two formats overlap &lt;em&gt;just&lt;/em&gt; enough to look compatible and &lt;em&gt;just&lt;/em&gt; differently enough to fail silently. This post walks through the exact incompatibilities and a small code generator that keeps both formats in sync from a single source of truth.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two rule systems
&lt;/h2&gt;

&lt;p&gt;Both tools let you drop markdown files with YAML frontmatter into a project directory. Instructions apply either always or scoped to file globs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cursor&lt;/strong&gt; — &lt;code&gt;.cursor/rules/*.mdc&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Run&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;ESLint&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;after&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;changing&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;TS/JS"&lt;/span&gt;
&lt;span class="na"&gt;globs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;extensions/app/**/*.{ts,tsx,js}&lt;/span&gt;
&lt;span class="na"&gt;alwaysApply&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="gh"&gt;# ESLint after edits&lt;/span&gt;
Run &lt;span class="sb"&gt;`npm run lint`&lt;/span&gt; before considering the task done.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cursor derives the rule &lt;em&gt;type&lt;/em&gt; from a combination of three fields:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;code&gt;alwaysApply&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;description&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;globs&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;Always&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;provided&lt;/td&gt;
&lt;td&gt;Auto Attached&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;provided&lt;/td&gt;
&lt;td&gt;omitted&lt;/td&gt;
&lt;td&gt;Agent Requested&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;omitted&lt;/td&gt;
&lt;td&gt;omitted&lt;/td&gt;
&lt;td&gt;Manual (@-only)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Claude Code&lt;/strong&gt; — &lt;code&gt;.claude/rules/*.md&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run ESLint after changing TS/JS&lt;/span&gt;
&lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;extensions/app/**/*.{ts,tsx,js}"&lt;/span&gt;
&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="gh"&gt;# ESLint after edits&lt;/span&gt;
Run &lt;span class="sb"&gt;`npm run lint`&lt;/span&gt; before considering the task done.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Claude Code's model is simpler: a rule with a &lt;code&gt;paths:&lt;/code&gt; list loads only when Claude reads a matching file; a rule with &lt;strong&gt;no&lt;/strong&gt; &lt;code&gt;paths:&lt;/code&gt; loads unconditionally every session (same priority as &lt;code&gt;.claude/CLAUDE.md&lt;/code&gt;). There is no "agent decides from description" mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why one shared directory can't work
&lt;/h2&gt;

&lt;p&gt;The tempting shortcut:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; ../.claude/rules .cursor/rules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One physical directory, both tools point at it, done. Except it breaks on two independent axes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. File extension.&lt;/strong&gt; Cursor's rule loader &lt;em&gt;only&lt;/em&gt; reads &lt;code&gt;.mdc&lt;/code&gt; and ignores plain &lt;code&gt;.md&lt;/code&gt;. Claude Code discovers &lt;code&gt;.md&lt;/code&gt; and ignores &lt;code&gt;.mdc&lt;/code&gt;. A single file on disk cannot have both extensions, so whichever you pick, exactly one tool silently sees zero rules. No error, no warning — the rules just don't apply.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Frontmatter keys.&lt;/strong&gt; Even if you dodged the extension problem, the scoping keys differ:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cursor: &lt;code&gt;globs:&lt;/code&gt; as a &lt;strong&gt;comma-separated string&lt;/strong&gt;, plus &lt;code&gt;alwaysApply:&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Claude Code: &lt;code&gt;paths:&lt;/code&gt; as a &lt;strong&gt;YAML list&lt;/strong&gt;, no &lt;code&gt;alwaysApply&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Point Claude Code at a Cursor-format file and it sees no &lt;code&gt;paths:&lt;/code&gt; key, so it treats &lt;em&gt;every&lt;/em&gt; rule as always-on — your carefully scoped API rule now loads on every session. The failure is invisible because the file &lt;em&gt;is&lt;/em&gt; being read; it's just being interpreted with the wrong schema.&lt;/p&gt;

&lt;p&gt;This is the trap that motivated the whole exercise: I had &lt;code&gt;.cursor/rules -&amp;gt; ../.claude/rules&lt;/code&gt; and "fixed" the files to Claude Code's format, which instantly broke Cursor without a single error message.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: one source, generated outputs
&lt;/h2&gt;

&lt;p&gt;Since the bodies are identical and only the frontmatter differs, treat one format as the source of truth and generate the other. I picked &lt;code&gt;.claude/rules/*.md&lt;/code&gt; as the source (Claude Code reads it directly) and generate &lt;code&gt;.cursor/rules/*.mdc&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The mapping is mechanical:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Source (&lt;code&gt;.md&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;Generated (&lt;code&gt;.mdc&lt;/code&gt;)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;paths:&lt;/code&gt; list present&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;globs: &amp;lt;comma-joined&amp;gt;&lt;/code&gt; + &lt;code&gt;alwaysApply: false&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;paths:&lt;/code&gt; absent&lt;/td&gt;
&lt;td&gt;&lt;code&gt;alwaysApply: true&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;description:&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;carried over verbatim&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Here is the core of the generator — plain Node, zero dependencies, so there is no &lt;code&gt;package.json&lt;/code&gt; to maintain just for this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;readdirSync&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mkdirSync&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rmSync&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node:fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;join&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node:path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SRC_DIR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.claude/rules&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;OUT_DIR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.cursor/rules&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;splitFrontmatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^---&lt;/span&gt;&lt;span class="se"&gt;\n([\s\S]&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;?)\n&lt;/span&gt;&lt;span class="sr"&gt;---&lt;/span&gt;&lt;span class="se"&gt;\n?([\s\S]&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;$/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;fm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;fm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Minimal parser for our known shape: `description:` scalar + `paths:` list.&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;parseFrontmatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fm&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;desc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^description:&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;.*&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;$/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^paths:&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*$/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*-&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;.*&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;$/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;"'&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;|&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;"'&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;$/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;toCursorFrontmatter&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;paths&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;---&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`description: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`globs: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;alwaysApply: false&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;alwaysApply: true&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;---&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;mkdirSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;OUT_DIR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;recursive&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sources&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;readdirSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SRC_DIR&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.md&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sources&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;md$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.mdc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;sources&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;splitFrontmatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SRC_DIR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;utf8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;outName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;md$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.mdc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;banner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;!-- AUTO-GENERATED from .claude/rules. Edit the .md source. --&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;OUT_DIR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;outName&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;toCursorFrontmatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parseFrontmatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fm&lt;/span&gt;&lt;span class="p"&gt;))}&lt;/span&gt;&lt;span class="s2"&gt;\n\n&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;banner&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sr"&gt;+/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Drop generated files whose source .md was deleted.&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nf"&gt;readdirSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;OUT_DIR&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.mdc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="nf"&gt;rmSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;OUT_DIR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run &lt;code&gt;node scripts/sync-cursor-rules.mjs&lt;/code&gt; after editing any rule. The stale-file sweep at the end means deleting a source &lt;code&gt;.md&lt;/code&gt; also removes its generated &lt;code&gt;.mdc&lt;/code&gt;, so the two directories never drift.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A hand-written YAML parser is fine &lt;em&gt;because the shape is fixed&lt;/em&gt;.&lt;/strong&gt; These frontmatter blocks are tiny and you control them. Don't pull in a YAML dependency for five files with two keys each — but do keep the parser honest about what it supports (scalar &lt;code&gt;description&lt;/code&gt;, list &lt;code&gt;paths&lt;/code&gt;) and nothing more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;alwaysApply: false&lt;/code&gt; + no &lt;code&gt;globs&lt;/code&gt; has no Claude Code equivalent.&lt;/strong&gt; Cursor's "Agent Requested" type (the agent decides relevance from the description) doesn't map. Going Claude → Cursor, a rule with no &lt;code&gt;paths&lt;/code&gt; becomes &lt;code&gt;alwaysApply: true&lt;/code&gt;. If you want scoping on the Cursor side, add explicit &lt;code&gt;paths&lt;/code&gt; to the source.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Commit the generated &lt;code&gt;.mdc&lt;/code&gt; or gitignore them — pick one and be explicit.&lt;/strong&gt; Committing means Cursor users don't need Node to bootstrap; gitignoring keeps the diff clean. Either is fine; leaving it ambiguous means someone edits the generated file by hand and loses the change on the next run. The &lt;code&gt;AUTO-GENERATED&lt;/code&gt; banner exists to catch exactly that.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Cursor and Claude Code rules look shareable but aren't: different extensions (&lt;code&gt;.mdc&lt;/code&gt; vs &lt;code&gt;.md&lt;/code&gt;) and different scoping schemas (&lt;code&gt;globs&lt;/code&gt; string vs &lt;code&gt;paths&lt;/code&gt; list) both fail &lt;em&gt;silently&lt;/em&gt; when you force one directory to serve both. A ~40-line dependency-free generator turns one source of truth into both formats and includes a stale-file sweep so the outputs never drift. Edit one place, run one command, both tools stay correct.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>tooling</category>
      <category>productivity</category>
      <category>devtools</category>
    </item>
    <item>
      <title>How an Unbounded fastmcp Version Constraint Took Down Production with 421 Misdirected Request</title>
      <dc:creator>Hiroshi Toyama</dc:creator>
      <pubDate>Wed, 08 Jul 2026 05:33:45 +0000</pubDate>
      <link>https://dev.to/toyama0919/how-an-unbounded-fastmcp-version-constraint-took-down-production-with-421-misdirected-request-1mh1</link>
      <guid>https://dev.to/toyama0919/how-an-unbounded-fastmcp-version-constraint-took-down-production-with-421-misdirected-request-1mh1</guid>
      <description>&lt;p&gt;We run a &lt;a href="https://modelcontextprotocol.io/" rel="noopener noreferrer"&gt;Model Context Protocol&lt;/a&gt; server on Cloud Run, built with &lt;a href="https://gofastmcp.com/" rel="noopener noreferrer"&gt;fastmcp&lt;/a&gt;, sitting behind a custom domain on an HTTPS load balancer. It hadn't been redeployed in three months. When we finally shipped a routine release, every single request started failing with &lt;code&gt;421 Misdirected Request&lt;/code&gt;. No code changes. No infra changes we were aware of. Just a version bump.&lt;/p&gt;

&lt;p&gt;This is the story of tracking that down, and why an unbounded &lt;code&gt;fastmcp&amp;gt;=3.4.2&lt;/code&gt; in &lt;code&gt;pyproject.toml&lt;/code&gt; was the real culprit.&lt;/p&gt;

&lt;h2&gt;
  
  
  The symptom
&lt;/h2&gt;

&lt;p&gt;After redeploying, every request through the custom domain returned:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;421&lt;/span&gt; &lt;span class="ne"&gt;Misdirected Request&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with an empty or near-empty body. Curl reproduced it instantly (1ms latency), which ruled out anything resembling real request processing — this was a fast, early rejection.&lt;/p&gt;

&lt;p&gt;The confusing part: the exact same image, hit directly via its own &lt;code&gt;*.run.app&lt;/code&gt; URL with no custom domain, returned a normal &lt;code&gt;404&lt;/code&gt; for an unmounted path instead of &lt;code&gt;421&lt;/code&gt;. Something was specifically rejecting the &lt;em&gt;custom domain&lt;/em&gt; Host header, not &lt;code&gt;/mcp&lt;/code&gt; requests in general.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chasing the wrong SDK version
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;pyproject.toml&lt;/code&gt; had:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="py"&gt;dependencies&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="py"&gt;"fastmcp&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;3.4&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;uv.lock&lt;/code&gt; on disk was already pinned to &lt;code&gt;3.4.2&lt;/code&gt;. I installed that exact version into a scratch venv and read through &lt;code&gt;fastmcp&lt;/code&gt;'s HTTP transport code and the underlying &lt;code&gt;mcp&lt;/code&gt; SDK's &lt;code&gt;mcp/server/transport_security.py&lt;/code&gt;, which implements DNS-rebinding protection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TransportSecurityMiddleware&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;TransportSecuritySettings&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# If not specified, disable DNS rebinding protection by default
&lt;/span&gt;        &lt;span class="c1"&gt;# for backwards compatibility
&lt;/span&gt;        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="nc"&gt;TransportSecuritySettings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enable_dns_rebinding_protection&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;fastmcp==3.4.2&lt;/code&gt;, nothing in the codebase ever passed &lt;code&gt;security_settings&lt;/code&gt; to this middleware — a global search for &lt;code&gt;TransportSecurity&lt;/code&gt;, &lt;code&gt;allowed_hosts&lt;/code&gt;, and &lt;code&gt;dns_rebinding&lt;/code&gt; came back empty. So this middleware should have been a no-op. And yet production was failing.&lt;/p&gt;

&lt;p&gt;The lesson here: &lt;strong&gt;&lt;code&gt;&amp;gt;=X&lt;/code&gt; in a dependency spec describes what was true when the constraint was written, not what's actually running.&lt;/strong&gt; &lt;code&gt;pyproject.toml&lt;/code&gt; said &lt;code&gt;&amp;gt;=3.4.2&lt;/code&gt;; the container that was actually deployed had resolved something newer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finding the real version
&lt;/h2&gt;

&lt;p&gt;The Cloud Run startup logs told the real story:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;│                                FastMCP 3.4.3                                 │
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not &lt;code&gt;3.4.2&lt;/code&gt;. The routine &lt;code&gt;ci.sh release&lt;/code&gt; step that bumps the package's own version had also run &lt;code&gt;uv lock&lt;/code&gt;, and because the constraint had no upper bound, the resolver happily picked up the newest compatible release — &lt;code&gt;3.4.3&lt;/code&gt; — which had shipped days earlier.&lt;/p&gt;

&lt;p&gt;Re-running my investigation against &lt;code&gt;fastmcp==3.4.3&lt;/code&gt; immediately explained everything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# fastmcp/settings.py
&lt;/span&gt;&lt;span class="n"&gt;http_host_origin_protection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="n"&gt;http_allowed_hosts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;3.4.3&lt;/code&gt; added host-origin protection &lt;strong&gt;enabled by default&lt;/strong&gt;, wired through to the same &lt;code&gt;TransportSecurityMiddleware&lt;/code&gt; we'd already found:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# fastmcp/server/mixins/transport.py
&lt;/span&gt;&lt;span class="n"&gt;allowed_hosts&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;allowed_hosts&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;allowed_hosts&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;fastmcp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;http_allowed_hosts&lt;/span&gt;
&lt;span class="p"&gt;),&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;http_allowed_hosts&lt;/code&gt; left at its default &lt;code&gt;None&lt;/code&gt;, the effective allowlist is empty. Every incoming &lt;code&gt;Host&lt;/code&gt; header — our custom domain, anything — fails the check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# mcp/server/transport_security.py
&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate_request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;is_post&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
    &lt;span class="n"&gt;host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;host&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_validate_host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Invalid Host header&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;421&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the &lt;code&gt;421&lt;/code&gt;. It's a real security feature — DNS-rebinding protection is a legitimate concern for locally-hosted MCP servers — but it shipped as a default-on breaking change in what looked, from the version number, like a patch release.&lt;/p&gt;

&lt;h2&gt;
  
  
  A red herring along the way
&lt;/h2&gt;

&lt;p&gt;Before landing on the host-allowlist explanation, we chased a different theory: an OAuth authorization request from an MCP client returned a plausible-looking &lt;code&gt;Misdirected Request&lt;/code&gt;, and it was tempting to blame a &lt;code&gt;redirect_uri&lt;/code&gt;/CIMD (Client ID Metadata Document) validation mismatch — that's a real, separate failure mode worth knowing about, but it wasn't the cause here. It was only after reproducing &lt;code&gt;421&lt;/code&gt; on a plain, unauthenticated request to the base &lt;code&gt;/mcp&lt;/code&gt; endpoint — nothing OAuth-related at all — that it became clear this was happening below the application logic, in transport-level middleware.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;p&gt;Immediate mitigation — restore the pre-3.4.3 behavior explicitly, rather than relying on accidental version pinning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;env&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"FASTMCP_HTTP_HOST_ORIGIN_PROTECTION"&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"false"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;fastmcp&lt;/code&gt;'s settings model uses &lt;code&gt;extra="ignore"&lt;/code&gt;, so this env var is a safe no-op on any version that doesn't understand it yet — meaning it's also cheap insurance to add to services still running an older &lt;code&gt;fastmcp&lt;/code&gt;, before they ever hit this problem.&lt;/p&gt;

&lt;p&gt;Then, cap the blast radius of future upgrades:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="py"&gt;dependencies&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="py"&gt;"fastmcp&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;3.4&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mf"&gt;3.5&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Re-locking against that constraint happened to resolve back down to &lt;code&gt;3.4.2&lt;/code&gt; — a nice confirmation that the newer patch wasn't otherwise needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;An unbounded &lt;code&gt;&amp;gt;=&lt;/code&gt; constraint on a fast-moving dependency is a live production risk&lt;/strong&gt;, not just a style nit. A "patch" version bump (&lt;code&gt;3.4.2&lt;/code&gt; → &lt;code&gt;3.4.3&lt;/code&gt;) shipped a default-on behavioral change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Any CI step that re-runs your lockfile resolver&lt;/strong&gt; (a version-bump script calling &lt;code&gt;uv lock&lt;/code&gt;, &lt;code&gt;poetry lock&lt;/code&gt;, etc.) can silently upgrade transitive-looking dependencies you never touched. Review the lockfile diff, not just your own changed files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New security defaults deserve explicit configuration, not silent adoption.&lt;/strong&gt; DNS-rebinding protection is the right default for a library that's often run as a local, loopback-only server. It's a much riskier default to ship without a loud changelog entry when the same library is also commonly deployed behind a custom domain, where the request's Host header will never be &lt;code&gt;localhost&lt;/code&gt; in the first place.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When a 1ms-latency error shows up right after a deploy, suspect the deploy, not the traffic.&lt;/strong&gt; The fast rejection time was the tell that this was a cheap, early-stage check — not an app bug deep in request handling.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're running fastmcp behind a custom domain, go check whether you're pinned tightly enough to know which &lt;code&gt;http_host_origin_protection&lt;/code&gt; behavior you're actually getting, and configure &lt;code&gt;FASTMCP_HTTP_ALLOWED_HOSTS&lt;/code&gt; (or explicitly opt out) rather than finding out in production.&lt;/p&gt;

</description>
      <category>python</category>
      <category>mcp</category>
      <category>cloudrun</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
