Skip to content

Final review#60

Closed
lisajulia wants to merge 2 commits into
mainfrom
final-review
Closed

Final review#60
lisajulia wants to merge 2 commits into
mainfrom
final-review

Conversation

@lisajulia

Copy link
Copy Markdown
Contributor

@lisajulia lisajulia requested a review from a team as a code owner June 9, 2026 19:19
@hyperspace-insights

Copy link
Copy Markdown

Summary

The following content is AI-generated and provides a summary of the pull request:


Make Prediction Cache Tenant-Specific and Document Manual SAP_Recommendations Setup

Bug Fix / Documentation

🐛 Fixed the per-entity prediction cache to be tenant-specific, and 📝 documented how to manually add the SAP_Recommendations navigation property without the CDS plugin.

Changes

  • README.md: Updated prerequisites to clarify that SAP_Recommendations can be added either via the @cap-js/ai CDS plugin or manually. Added a new #### Adding the SAP_Recommendations navigation property manually section with a CDS code example showing how to define RecommendationItem_* types and extend entities with a SAP_Recommendations composition. Also removed a redundant warning about predictions not being serialized (now covered in prerequisites).

  • FioriRecommendationHandler.java: Renamed entitiesWithoutPredictions cache to entitiesWithoutPredictionsPerTenant and changed cache keys from "<entityName>" to "<tenantId>:<entityName>" so that per-tenant CDS model differences are respected. Added invalidateTenant(String tenantId) and a tenantKey() helper method to support cache invalidation when a tenant's model changes.

  • RecommendationConfiguration.java: Registers the new RecommendationModelChangedHandler alongside the existing FioriRecommendationHandler so model-change events trigger cache invalidation.

  • RecommendationModelChangedHandler.java (new): A new EventHandler that listens for ExtensibilityService.EVENT_MODEL_CHANGED events and calls FioriRecommendationHandler.invalidateTenant() with the affected tenant ID, ensuring the cache is cleared when a tenant's CDS model is updated.

  • FioriRecommendationHandlerTest.java: Added invalidateTenant_removesOnlyThatTenantsEntries test to verify that invalidating one tenant's cache entries does not affect other tenants. Added runInTenant() helper method to execute test code within a specific tenant context.


  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.22.4

  • Correlation ID: af542b3f-56b7-45fb-b507-c6e9482682f7
  • Output Template: Default Template
  • LLM: anthropic--claude-4.6-sonnet
  • Event Trigger: pull_request.opened
  • Summary Prompt: Default Prompt
  • File Content Strategy: Full file content

@hyperspace-insights hyperspace-insights Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The PR is generally well-structured: the cache is correctly made tenant-aware, the RecommendationModelChangedHandler cleanly wires in cache invalidation on model changes, and the new documentation section for manual SAP_Recommendations addition is a useful addition. A few issues were flagged: a typo in the README, a clarity/formatting problem with the misplaced warning note, and a potential composite cache-key collision if tenant IDs happen to contain the colon separator character.

PR Bot Information

Version: 1.22.4

  • LLM: anthropic--claude-4.6-sonnet
  • Event Trigger: pull_request.opened
  • File Content Strategy: Full file content
  • Correlation ID: af542b3f-56b7-45fb-b507-c6e9482682f7

Comment on lines +46 to +47
void invalidateTenant(String tenantId) {
String prefix = tenantKey(tenantId) + ":";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: invalidateTenant prefix collision — a tenant whose ID is a prefix of another tenant's ID will incorrectly evict the other tenant's cache entries.

For example, if two tenants are named "t" and "t2", calling invalidateTenant("t") builds the prefix "t:". The key for tenant "t2" is "t2:<entity>" which does not start with "t:", so this particular pair is actually safe. However, consider tenants "tenant" and "tenant-extended": after invalidateTenant("tenant"), the prefix is "tenant:" and any key beginning with "tenant:" will be removed — that is correct. But consider two tenants "a" and "ab": prefix "a:" will only match "a:…", not "ab:…", because of the colon separator, so the colon already prevents simple substring collisions.

The real remaining risk is that a malicious or misconfigured tenant ID that itself contains ":" (e.g. "t:en") would produce tenantKey("t:en") + ":" = "t:en:", which could match cache keys for tenant "t" whose entity name starts with "en:…". While that is an edge case, the separator character used for the composite key should be one that cannot appear in either component, or the components should be length-prefixed / otherwise escaped.

Consider using a separator that cannot appear in tenant IDs and entity names, or use a Map<String, Map<String, Boolean>> (tenant → entity-name → flag) to avoid any composite-key ambiguity entirely.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

- The `@cap-js/ai` CDS plugin must be installed (provides the model enhancement that adds `SAP_Recommendations` as a navigation property)
- The `SAP_Recommendations` navigation property must be added to the entities that should receive recommendations by
- either installing the `@cap-js/ai` CDS plugin (automatically provides the model enhancement that adds `SAP_Recommendations` as a navigation property)
- or adding the `SAP_Recommendations`property manually.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Typo: Missing space before "property" in the bullet point.

SAP_Recommendationspropertyshould beSAP_Recommendations property (space before "property").

Suggested change
- or adding the `SAP_Recommendations`property manually.
- or adding the `SAP_Recommendations` property manually.

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

- The `SAP_Recommendations` navigation property must be added to the entities that should receive recommendations by
- either installing the `@cap-js/ai` CDS plugin (automatically provides the model enhancement that adds `SAP_Recommendations` as a navigation property)
- or adding the `SAP_Recommendations`property manually.
Without the `SAP_Recommendations` navigation property, the predictions will be computed but not serialized in OData responses.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clarity: The warning about missing SAP_Recommendations navigation property is misplaced. It is indented at the same level as the sub-bullets, but it applies to the overall prerequisite and should be visually separated from the list items so readers don't mistake it for a third option.

Consider placing it as a standalone note below the two sub-bullets, or dedenting it to the parent bullet level, e.g.:

- The `SAP_Recommendations` navigation property must be added to the entities that should receive recommendations by
  - either installing the `@cap-js/ai` CDS plugin (automatically provides the model enhancement that adds `SAP_Recommendations` as a navigation property)
  - or adding the `SAP_Recommendations` property manually.

  > **Note:** Without the `SAP_Recommendations` navigation property, the predictions will be computed but not serialized in OData responses.

Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

@lisajulia

Copy link
Copy Markdown
Contributor Author

Closing this, opened #67 and #68 instead.

@lisajulia lisajulia closed this Jun 10, 2026
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