Skip to content

[release/10.0.4xx] Fix OpenCode environment detection - #56835

Open
baronfel wants to merge 1 commit into
release/10.0.4xxfrom
baronfel-opencode-10-servicing-backport
Open

baronfel wants to merge 1 commit into
release/10.0.4xxfrom
baronfel-opencode-10-servicing-backport

Conversation

@baronfel

@baronfel baronfel commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Semantic backport of #56820 (merge commit a7d7d44).

Correct the OpenCode marker from OPENCODE_AI to OPENCODE, preserving the existing nonempty-presence rule. Commands launched by OpenCode now receive the existing opencode classification and LLM-aware behavior; the obsolete marker alone no longer triggers detection.

Upstream evidence: OpenCode explicitly sets invocation.env.OPENCODE = "1" before launching commands:
https://github.com/anomalyco/opencode/blob/77a0fd6f3b247235b09941d55ff0faf72be1dae4/packages/core/src/tool/plugin/shell.ts#L214

Conflict resolution and branch differences

The automated backport conflicted because this release branch has the older static detector rather than main's injectable environment accessor. Only the marker correction is applied to the branch's existing rule; main's refactors are not included.

The main-only files test/dotnet.Tests/TelemetryTests/TelemetryCommonPropertiesTests.cs and test/dotnet.Tests/CommandTests/Test/GivenDotnetTestOutput.cs do not exist here. The existing xUnit data in test/dotnet.Tests/TelemetryCommonPropertiesTests.cs is updated instead, covering OPENCODE=1, OPENCODE=0, empty OPENCODE, and obsolete OPENCODE_AI=1. Both markers are cleared and restored with the branch's existing ambient-environment isolation helper. No missing main-only files are copied.

Validation on release/10.0.4xx

  • Bootstrapped repo-local SDK 10.0.401.
  • Attempted .\.dotnet\dotnet.exe build test\dotnet.Tests\dotnet.Tests.csproj -c Debug /bl:1.binlog -v:quiet. Blocked by an unrelated compile error in src/Cli/dotnet/Commands/Run/CSharpCompilerCommand.cs(9,30): CS0234, Microsoft.CodeAnalysis.CommandLine namespace missing. Binary log loaded and confirmed one error; no full xUnit run or SDK/redist build is claimed.
  • Fallback validation: a temporary, source-linked net10.0 harness outside the repository compiled the actual release-branch detector, interface, environment rules, and boolean parser. It read all 44 LLM theory rows directly from the changed branch test file, checked both GetLLMEnvironment() and IsLLMEnvironment(), and passed all 44 rows, including all four OpenCode regressions. Harness build: 0 warnings, 0 errors (2.binlog). This is source-level validation, not an execution of the xUnit assembly.
  • git diff --check passed.

Main's reported 81 passing tests are upstream evidence only, not validation of this branch.

Tactics

Summary

The SDK checks OPENCODE_AI, but OpenCode sets OPENCODE=1 when launching commands, so its environment is not identified by the OpenCode rule. This backport replaces that marker with OPENCODE while retaining the existing nonempty-presence rule. The one-line production correction is suitable for servicing because it fixes the integration without importing main's detector refactors.

Customer Impact

Users running SDK commands through OpenCode on the affected release/10.0.4xx code miss the existing opencode telemetry classification and LLM-aware CLI behavior unless another agent marker also matches. Ordinary non-agent invocations are unaffected. Exact affected shipped SDK versions and customer-report frequency have not been established; no customer-tested workaround is recorded. After this correction, OPENCODE_AI alone no longer identifies OpenCode.

Regression?

Unknown — not enough information to determine the introducing PR or first affected SDK version.

Testing

  • Updated the branch's existing xUnit theory and environment isolation for OPENCODE=1, OPENCODE=0, empty OPENCODE, and rejected OPENCODE_AI=1.
  • The local xUnit project build was blocked by the unrelated CS0234 compilation error documented above; the full xUnit suite and redist build were not completed.
  • A source-linked harness compiled the actual branch detector and passed all 44 LLM theory rows, checking both classification and boolean detection. This is not an xUnit assembly run.
  • git diff --check passed. CI results should be reviewed before merging; no successful branch CI result is asserted here. Main's 81 passing tests are upstream evidence only.

Risk

Low. Production changes are limited to one environment-variable name in the existing OpenCode rule; other agent rules and matching semantics are unchanged. Tests cover positive, empty, nonempty, and obsolete-marker cases. Local full-project validation remains limited by the unrelated build error, so branch CI is required to close that validation gap.

Backport #56820 to the release branch's static detector and xUnit theory data.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 13:51
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.
@baronfel

Copy link
Copy Markdown
Member Author

/tactics

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the targeted OpenCode detection backport.

No open issues 🎉

What changed in this PR

Backports the OpenCode detection fix to the release branch’s existing static detector without importing main-branch refactors.

Changes:

  • Detects OpenCode through OPENCODE instead of OPENCODE_AI, preserving nonempty-value semantics.
  • Adds regression cases for nonempty, empty, and obsolete markers, and isolates both environment variables during tests.
File Description
test/​dotnet.Tests/​TelemetryCommonPropertiesTests.cs Adds OpenCode regression cases and updates environment isolation.
src/​Cli/​dotnet/​Telemetry/​LLMEnvironmentDetectorForTelemetry.cs Corrects the marker used for the existing opencode classification.

Review effort: Balanced

This branch has not been deployed

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

2 participants