Skip to content

Annotation cache evicts existing target annotations when another annotation is absent, losing custom query options #951

Open

Description

Summary

EdmVocabularyAnnotationExtensions.GetOrAddCached replaces a target's existing annotation dictionary when a lookup for another, uncached annotation returns null. This discards cached records and mutations previously merged into them. In Graph conversion it removes custom query options from five operations, leading to generated C# API removals.

Observed with Hidi 3.11.1 / Microsoft.OpenApi.OData 3.2.1; the same controlled experiment using Hidi 1.6.31 / Microsoft.OpenApi.OData 1.7.6 preserves the records/options.

Root cause

The nullable-reference migration in commit 93f46f09b2204e3f18ec19b68850ec7acd209e65, included in #676, changed the existing-target cache branch from caching/returning the lookup result to:

else if (createFunc() is T ret)
{
    value[qualifiedName] = ret;
    return ret;
}

When createFunc() returns null, execution falls through to the first-target initialization code:

value = new Dictionary<string, object>();
_cachedAnnotations[target] = value;

That replaces the entire dictionary even though the target was already cached. See the pinned implementation.

Focused reproduction

Using a single parsed EDM model and target:

  1. Read and cache a target's ReadRestrictions record.
  2. Merge its navigation-property custom query options into that record, as normal navigation GET generation does.
  3. Query an unrelated annotation that is absent on the same target.
  4. Read the original ReadRestrictions again.

Expected: the original cached instance and merged options survive.

Actual in 3.11.1: a new record is loaded from the original annotation; the merged options are gone. Exact extracted assemblies were exercised: the 1.6.31 record survives by reference identity and retains includeHiddenFolders; the 3.11.1 record does not survive and loses the option.

Full Graph reproduction and impact

Inputs are the complete v1.0 CSDL and conversion settings at msgraph-metadata commit 06a4f0cac6c8e5bcb7c9149bcfaa32a6e360a174, converted with identical settings using Hidi 1.6.31 and 3.11.1, OAS 3.0 YAML.

GET operation Missing custom query options
/me/mailFolders/$count includeHiddenFolders
/me/mailFolders/{mailFolder-id}/childFolders/$count includeHiddenFolders
/me/messages/$count includeHiddenMessages
/me/messages/{message-id}/$value includeHiddenMessages
/solutions/bookingBusinesses/{bookingBusiness-id}/calendarView/$count start, end

The options remain in the unchanged navigation-property NavigationRestrictions.RestrictedProperties.ReadRestrictions.CustomQueryOptions. Path-specific read restrictions contain descriptions but not these options. Collection GET generation merges them into cached path records; later handlers lose the merged state because of the eviction. Parent collection operations retain the options.

A controlled complete conversion with the exact latest assemblies and a reflection-installed cache wrapper that only preserves existing entries when the library replaces a target dictionary restores precisely these six parameters across the five operations. No converter assembly was modified. Downstream Kiota 1.38.0 otherwise removes the corresponding query-parameter properties and URL-template entries.

Acceptance criteria

  • Looking up an absent annotation must not discard other annotations already cached for that target.
  • Preserve cached instance identity/merged state when another term lookup returns null.
  • Regression tests should cover both existing and first-time targets, absent terms, and model changes/cache reset.
  • Include an integration case where merged custom options survive into subsequent $count generation.

The shared mutation of restriction records is an existing fragility; cache correctness should not depend on querying annotations in a particular order. Restoring legacy option propagation does not independently establish whether the service accepts each inherited option (especially on $value). Numeric-width compatibility and intentional optional request bodies are out of scope.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions