Skip to content

Add debug-level summary log of back-compatibility changes in http-client-csharp generator#10415

Open
Copilot wants to merge 9 commits intomainfrom
copilot/create-back-compatibility-changes-logs
Open

Add debug-level summary log of back-compatibility changes in http-client-csharp generator#10415
Copilot wants to merge 9 commits intomainfrom
copilot/create-back-compatibility-changes-logs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

Back-compatibility adjustments driven by a library's LastContractView (parameter reorders, renamed/preserved params, collection type preservation, constructor promotions, enum reorders, added api-version members, model-factory shims, etc.) were hard to spot in generator run logs. This adds a single human-readable summary listing every such change at the end of generation, emitted through the existing logging pipeline.

Changes

  • Extended Emitter (Microsoft.TypeSpec.Generator.EmitterRpc) with categorized, buffered logging:
    • New overloads Info(string, BackCompatibilityChangeCategory), Debug(string, BackCompatibilityChangeCategory), Verbose(string, BackCompatibilityChangeCategory) that buffer messages and dedup them per (level, category).
    • New WriteBufferedMessages() API that emits a single grouped trace per level via the existing JSON-RPC channel.
    • Buffered messages are also auto-flushed on Emitter.Dispose as a safety net.
    • Header wording uses conditional singular/plural based on the count (e.g. 1 message across 1 category vs N messages across M categories).
  • New BackCompatibilityChangeCategory enum (Microsoft.TypeSpec.Generator.EmitterRpc): strongly-typed set of categories used by the buffered overloads; display names are mapped centrally inside Emitter.
  • CSharpGen.ExecuteAsync: calls Emitter.WriteBufferedMessages() after all ProcessTypeForBackCompatibility runs.
  • Instrumented back-compat sites to record their decisions (each call now goes through Emitter.Debug/Info with a BackCompatibilityChangeCategory value):
    • ClientProvider — method parameter reordering
    • RestClientProvider — paging param name preservation (top, maxPageSize casing)
    • ScmModelProviderAdditionalProperties shape preservation
    • ModelProvider — collection property type preservation; abstract-model ctor modifier promotion
    • ModelFactoryProvider — back-compat method add / replace / skip
    • FixedEnumProvider — enum member reordering
    • ApiVersionEnumProvider — api version members carried over from last contract
  • Unit tests added to EmitterTests covering buffering, dedup, null/empty handling, level separation, and reset.

Example output

Summary of grouped 'debug' messages: 4 messages across 3 categories.
  Method Parameter Reordering (2):
    - Reordered parameters of 'FooClient.GetData' to match last contract.
    - Reordered parameters of 'FooClient.UpdateData' to match last contract.
  Parameter Name Preserved (1):
    - Preserved parameter name 'top' on 'FooClient' from last contract (instead of 'maxCount').
  Collection Property Type Preserved (1):
    - Changed property 'Bar.Items' type to 'IReadOnlyList<string>' to match last contract.

Back-compat summaries are emitted at debug level, so they are surfaced only when logLevel: debug (or verbose) is set on the emitter.

…y changes

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/b2456212-73e8-4f37-b9e5-de37fa8f42d5

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Apr 17, 2026
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/b2456212-73e8-4f37-b9e5-de37fa8f42d5

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI changed the title [WIP] Add debug level summary logs for back compatibility changes Add debug-level summary log of back-compatibility changes in http-client-csharp generator Apr 17, 2026
Copilot AI requested a review from jorgerangel-msft April 17, 2026 18:08
Comment thread .chronus/changes/feature-back-compat-changes-summary-log-2026-4-17.md Outdated
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/357d37d4-17ca-47cc-aeb3-f6585651cbe9

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/67866439-1d0c-40a7-924d-f83a39135c1c

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 17, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@10415

commit: 221ab52

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/7c6d8338-34c2-426d-bf0a-8503bfc13355

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot AI requested a review from JoshLove-msft April 17, 2026 19:32
@JoshLove-msft JoshLove-msft marked this pull request as ready for review April 17, 2026 21:35
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/3ef978ca-05c9-4720-b536-e9b068a289d8

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/1cb1f965-9936-49a9-8b75-7e402188b812

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@JoshLove-msft JoshLove-msft enabled auto-merge April 18, 2026 00:47
return;
}

snapshot = new Dictionary<string, Dictionary<BackCompatibilityChangeCategory, SortedSet<string>>>(_bufferedMessages, StringComparer.Ordinal);
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.

🫨

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.

why can't we just read the bufferedMessages directly instead of creating another copy of it?

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.

Done in 221ab52 — removed the snapshot copy. The loop now iterates _bufferedMessages directly under the lock and clears it at the end. --generated by Copilot

}

snapshot = new Dictionary<string, Dictionary<BackCompatibilityChangeCategory, SortedSet<string>>>(_bufferedMessages, StringComparer.Ordinal);
_bufferedMessages.Clear();
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.

should we move this to the dispose?

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.

Done in 221ab52 — removed the explicit WriteBufferedMessages() call from CSharpGen.ExecuteAsync. Dispose already flushes the buffer, so that's the single point where the summary is emitted now. --generated by Copilot

…to flush

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

No changes needing a change description found.

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

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Back Compatibility Changes Summary Logs

3 participants