Skip to content

Reproduce runaway User-Agent accumulation under context reuse (regression test)#5809

Draft
renaudhartert-db wants to merge 5 commits into
mainfrom
deco-ua-tripwire
Draft

Reproduce runaway User-Agent accumulation under context reuse (regression test)#5809
renaudhartert-db wants to merge 5 commits into
mainfrom
deco-ua-tripwire

Conversation

@renaudhartert-db

@renaudhartert-db renaudhartert-db commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Changes

Adds a regression test (common.TestUserAgentAccumulatesWhenContextReused) that reproduces the extremely long User-Agent headers reported from the integration-test probe (tf-integration-tests/... sdk/sdkv2 resource/directory repeated hundreds of times, which trip context-integrity checks and fire false Sev0s).

Root cause: addContext (common/context.go) appends sdk/sdkv2 and resource/<name> to the context's user-agent data via useragent.InContext, which appends without deduplication. The normal Terraform flow hands each CRUD a fresh per-RPC context, so exactly one pair is added (bounded). When a caller reuses the enriched context across operations — a long-lived process threading one context — the pairs accumulate linearly into a multi-kilobyte header. The runaway surfaces on the GCP account->workspace token-exchange request (gcpWorkspaceBrowserLogin, auth/google-credentials), which inherits the resource operation's context.

The test asserts both halves: a fresh context per operation stays at one pair; 50 reused-context operations yield 50 repeats (matching the observed shape). It passes today (documents the accumulation) and will keep the header bounded once the SDK adds dedup at the builder (databricks/databricks-sdk-go#1718).

Tests

  • make test (the new unit test) run locally
  • relevant change in docs/ folder
  • covered with integration tests in internal/acceptance
  • using Go SDK
  • using TF Plugin Framework
  • has entry in NEXT_CHANGELOG.md file

Integration tests emit a User-Agent that repeats "sdk/sdkv2 resource/<name>"
many times, tripping context-integrity checks. addContext only branches the
context and passes it down, so it cannot duplicate dimensions on its own; a long
User-Agent arriving here means a caller upstream re-applies the wrap to an
already-enriched context. Log a stack trace the first few times the incoming
User-Agent already exceeds 256 bytes to identify that caller.

Co-authored-by: Isaac
@github-actions

Copy link
Copy Markdown
Contributor

Please ensure that the NEXT_CHANGELOG.md file is updated with any relevant changes.
If this is not necessary for your PR, please include the following in your PR description:
NO_CHANGELOG=true
and rerun the job.

…T MERGE)

The CI -json reporter drops passing-test output, so a log-only tripwire is
invisible unless the test fails. Trigger precisely (a healthy context has
exactly one "sdk/sdkv2"; >=2 means addContext ran on an already-enriched
context) and return a diag error so the offending test fails and the runner
echoes the captured stack.

Co-authored-by: Isaac
Replaces the diagnostic tripwire with a regression test. addContext appends
"sdk/sdkv2 resource/<name>" to the context user-agent via useragent.InContext
(append, no dedup). With a fresh per-RPC context (normal Terraform flow) exactly
one pair is added; when a caller reuses the enriched context across operations,
the pairs accumulate linearly, producing the multi-kilobyte header seen on the
heatseeker probe's gcpWorkspaceBrowserLogin requests. The test asserts both: the
fresh path stays at 1, and 50 reused-context operations yield 50 repeats.

Co-authored-by: Isaac
@renaudhartert-db renaudhartert-db changed the title debug: User-Agent tripwire to locate runaway growth in integration tests (DO NOT MERGE) Reproduce runaway User-Agent accumulation under context reuse (regression test) Jun 15, 2026
…T MERGE)

The full integration suite emits User-Agents that repeat sdk/sdkv2 resource/<name>
hundreds of times. addContext only branches the context, so a fresh wrap should
never see an incoming context already carrying resource/ dimensions. Log a stack
trace the first 40 times it does, to identify the caller threading an enriched
context back into the wrap.

Co-authored-by: Isaac
…MERGE)

Log lines are dropped by the -json reporter and the long UA never appears in
client TF_LOG, so the only reliable surface is a failing test. Fail the op and
embed runtime.Stack the first 6 times a wrap sees an incoming context already
carrying a resource/ dimension (the onset of accumulation), pinpointing the
caller that threads an enriched context back into the wrap.

Co-authored-by: Isaac
@github-actions

Copy link
Copy Markdown
Contributor

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/terraform

Inputs:

  • PR number: 5809
  • Commit SHA: b4d109263be937ae4c01c5d926734abc57307fa0

Checks will be approved automatically on success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant