Skip to content

test(connectors): deterministic connector oracle in MultiConnectorAnalysisShouldDecreaseCostsAsync - #73

Closed
jsboige wants to merge 1 commit into
mainfrom
fix/72-deterministic-connector-oracle
Closed

jsboige wants to merge 1 commit into
mainfrom
fix/72-deterministic-connector-oracle

Conversation

@jsboige

@jsboige jsboige commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix the flaky wall-clock oracle in MultiConnectorAnalysisShouldDecreaseCostsAsync. The test already verified arithmetic results and effective costs, then compared wall-clock durations collected with Stopwatch around async calls. On Windows CI the second pass observed ~27-51 ms for the scenarios expecting a 10x gain and exceeded the bound derived from the first pass; the timing depends on runner load, not the business contract.

The analysis already exposes its deterministic outcome through optimizationResults.SuggestedSettings. For a given job, GetPromptSettings(job).SelectAppropriateTextCompletion(job, completions, SuggestedSettings.ConnectorComparer) returns the connector chosen by the weighted comparer. This PR asserts the identity of that selected connector instead of a wall-clock ratio.

Only dotnet/src/Connectors/Connectors.UnitTests/MultiConnector/TextCompletion/MultiConnectorTextCompletionTests.cs is touched. No skip, no extra retry, no widened timing tolerance, no parallel re-implementation of the routing.

Changes

  • Three theory rows now carry expectedConnector (string) instead of expectedPerfGain:
    • better cost and duration -> the specialized secondary connector is selected;
    • secondary faster but more expensive, cost + duration weights -> the primary is selected;
    • zero cost weight -> the specialized secondary connector is selected.
  • Removed firstPassDurationAfterWarmup / secondPassDurationAfterWarmup and the Assert.InRange wall-clock ratio assertion.
  • Replaced it with a deterministic loop that, for each job, derives the chosen connector from optimizationResults.SuggestedSettings through the production routing and asserts its Name.
  • The existing arithmetic-result and effective-cost assertions are unchanged.

Validation

  • dotnet test dotnet/src/Connectors/Connectors.UnitTests/Connectors.UnitTests.csproj -c Release --filter "FullyQualifiedName~MultiConnectorTextCompletion" locally:
    • under the .NET 6.0 SDK (current main target, net6.0): 9 passed, 0 failed (946 ms);
    • under the .NET 8.0 SDK (target net8.0): 9 passed, 0 failed (963 ms).
  • No Stopwatch.Elapsed, machine-load, or arbitrary-tolerance assertion remains.

Notes

…lysisShouldDecreaseCostsAsync

Replace the wall-clock Stopwatch.Elapsed ratio assertion with a deterministic
assertion on the connector chosen via the production routing: from the analysis's
optimizationResults.SuggestedSettings, GetPromptSettings(job).SelectAppropriateTextCompletion(job,
completions, SuggestedSettings.ConnectorComparer) returns the named connector selected
by the weighted comparer. The wall-clock measure depends on machine load and flaked on
Windows CI; the identity of the selected connector is the stable contract. Arithmetic
result and cost assertions are kept unchanged. No skip, no extra retry, no widened
timing tolerance.

See #69. Tested locally under the .NET 6.0 SDK (net6.0, current main target) and the
.NET 8.0 SDK (net8.0): 9/9 passed in both cases.

Co-Authored-By: Claude-Code <noreply@anthropic.com>
@jsboige

jsboige commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

CI status on current main

The dotnet-build-and-test Windows jobs on this PR fail at the Build step, before any test runs. The errors are pre-existing on main and unrelated to this change (this PR only rewrites the final assertion of MultiConnectorAnalysisShouldDecreaseCostsAsync in Connectors.UnitTests):

  • error CS9057: The analyzer assembly 'Roslynator...4.6.2' references version '4.4.0.0' of the compiler, which is newer than the currently running version '4.3.0.0' — the .NET 6.0 SDK ships Roslyn 4.3; Roslynator 4.6.2 requires 4.4. This is in samples/ConsoleSamples (untouched here).
  • Microsoft.Build.Tasks.Git: Unsupported repository version 1 / Unable to locate repository ... Connectors.AI.Oobabooga — SourceLink git-version incompatibility, unrelated to this change.
  • error CS0618: 'Kernel.Builder' is obsolete under /warnaserror in samples/ConsoleSamples.

None of these touch Connectors.UnitTests or the file in this PR. They are the exact breakage that #71 (modernize the SDK matrix to .NET 8 LTS / .NET 9) resolves — with the newer SDK the Roslyn compiler is 4.4+, compatible with Roslynator 4.6.2, and the build passes (confirmed by the manual run referenced in #72).

Local validation

Connectors.UnitTests passes 9/9 locally (this test, the deterministic oracle) under both:

  • .NET 6.0 SDK (net6.0, the current main target): 9 passed, 0 failed.
  • .NET 8.0 SDK (net8.0): 9 passed, 0 failed.

The fix is validated regardless of the pre-existing build breakage: the deterministic assertion does not depend on wall-clock, machine load, or an arbitrary tolerance. A Windows CI run on .NET 8/9 will exercise this test once #71's SDK-modernized matrix is in place.

@jsboige jsboige left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Preflight adjoint — COMMENTED, head 6333b7dec0e34056ebf58d8246c66a34eec18234.

Lecture complète effectuée : issue #72, body/commentaires/reviews/commits/checks de #73, diff complet, 0 thread inline ; #71 relue au head 3d4d5c547ab6d1af5298426a6fa40c9fb4c63bf8 avec son diff et 0 thread.

Le changement de #73 respecte le scope et l'oracle demandés : un seul fichier de test, suppression du ratio wall-clock, conservation des assertions arithmétiques et de coûts, puis sélection via optimizationResults.SuggestedSettings.GetPromptSettings(...).SelectAppropriateTextCompletion(..., ConnectorComparer). Les trois lignes attendent bien Secondary / Primary / Secondary, et aucun skip, retry ou élargissement de tolérance n'est introduit. La validation ciblée rapportée est 9/9 sous SDK 6 et 9/9 sous SDK 8.

Les rouges actuels ne contredisent pas ce diff : les jambes dotnet-build-and-test échouent à l'étape Build avant les tests sur des erreurs préexistantes (Microsoft.Build.Tasks.Git repository version, Roslynator/CS9057 sous SDK 6, Kernel.Builder/CS0618 sous /warnaserror). Le link-check échoue aussi sur des liens Oobabooga/README préexistants et aucun fichier Markdown n'est modifié ici.

Il reste toutefois un critère d'acceptance non observé : exécution Windows de ce test sous la matrice .NET 8/9. Il y a une dépendance circulaire de validation : #73 hérite encore de la matrice EOL de main, tandis que #71 échoue précisément sur l'ancien oracle absent de son head. Recommandation : produire une branche de validation éphémère combinant les heads #71 + #73, sans retarget ni modification des deux PRs, puis lancer dotnet-ci.yml. Si les 3 jambes Windows et les 3 jambes Docker passent, ai-01 pourra décider l'ordre de merge sur une preuve intégrée plutôt que sur confiance.

Aucun finding de code bloquant nouveau dans #73 ; statut de preflight : code conforme, preuve Windows .NET 8/9 encore à matérialiser.

@jsboige jsboige left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Follow-up preflight adjoint — COMMENTED, PR head 6333b7dec0e34056ebf58d8246c66a34eec18234.

La preuve Windows .NET 8/9 demandée dans la review précédente est désormais matérialisée par le run intégré 33987068397, déclenché sur la branche éphémère validate/pr73+pr71-combined, head 420b5b03428c25a1dafa6afc271ae90e5c24eedf.

Vérification firsthand du run : conclusion success; les six jambes ont passé leurs étapes Build et Run Tests :

  • Docker .NET 8 Release — success ;
  • Docker .NET 9 Debug — success ;
  • Docker .NET 9 Release — success ;
  • Windows .NET 8.x Release — success ;
  • Windows .NET 9.x Debug — success ;
  • Windows .NET 9.x Release — success.

Vérification du contenu combiné contre la base 168fd5d8bef5301a8f849d95492e815a38af8afb : exactement deux commits et deux fichiers. Le premier commit (fb28a350, cherry-pick du patch #71@3d4d5c54) modifie uniquement .github/workflows/dotnet-ci.yml; le second (420b5b03, cherry-pick de #73@6333b7de) modifie uniquement MultiConnectorTextCompletionTests.cs. Aucun troisième changement, aucun retarget et aucune modification des deux PRs.

Le critère restant de #72 est donc satisfait : l'oracle déterministe de #73 passe sur Windows sous .NET 8 et .NET 9 avec la matrice de #71. Aucun finding de code bloquant nouveau.

Séquence recommandée à ai-01 : merger #73 d'abord, mettre ensuite #71 à jour sur main et relancer dotnet-ci.yml sur sa tête exacte, puis merger #71 si les six jambes restent vertes. Cette dernière relance transforme la preuve d'intégration éphémère en preuve attachée à la tête finale de #71, sans élargir le scope de l'une ou l'autre PR.

@jsboige

jsboige commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Fermeture avec renvoi : ce correctif est reporte sur la ligne vivante stable-from-v0343 dans #121 (commit 40d9067, pique avec -x depuis 6333b7d ; trois hunks resolus cote correctif, la base ayant une forme plus ancienne du test). main ne reçoit plus de travail neuf.

Le portage seul ne suffit pas a rendre le test stable : la course qui le fait echouer est dans le helper RedirectOutput, traitee dans #122.

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