Skip to content

feat: [CR] Summary Data Improvements (MR-78)#256

Closed
miguelccodev wants to merge 5 commits into
mainfrom
mr-78--feat--timestamp-fields
Closed

feat: [CR] Summary Data Improvements (MR-78)#256
miguelccodev wants to merge 5 commits into
mainfrom
mr-78--feat--timestamp-fields

Conversation

@miguelccodev
Copy link
Copy Markdown

@miguelccodev miguelccodev commented May 22, 2026

Changes

  • removed old timestamp
  • added created_at
  • added updated_at
  • added schema_version
  • minor refactor

Ref: MR-78

Summary by CodeRabbit

  • Refactor

    • Improved payload validation and normalization for more consistent handling of summary and session data
    • Revised how session and summary records are created and updated to reliably include metadata (timestamps and schema info)
  • Chore

    • Increased Android minimum SDK level for the app
  • New Fields

    • Added a payload schema_version field to carry schema version information

Review Change Stack

@miguelccodev miguelccodev requested a review from Rajesh1041 May 22, 2026 12:25
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

Handler changes standardize created_at/updated_at/schema_version handling and route "summary_data" explicitly; summary document creation is delegated to createNewSummaryDoc. Also adds AppEventPayload.schema_version and raises app minSdk to 26.

Changes

Metadata field standardization in event payload handler

Layer / File(s) Summary
Validation and collection infrastructure
app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java
Added Instant import, removed timestamp from required-field validation, adjusted accepted-payload debug logging, and mapped "summary_data" to COLLECTION_SUMMARY in normalizeCollection.
User session data persistence
app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java
storeUserSessionPayload now writes created_at and schema_version into persisted records instead of storing the incoming timestamp.
Summary data creation and update logic
app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java
New-summary flow passes minimal identifiers to createNewSummaryDoc, which now constructs the created document including collection, data, created_at, and schema_version. Update path adds updated_at and logs the updated document id; query-failure no longer pre-populates metadata before delegation.

Build config and payload schema

Layer / File(s) Summary
Android minSdk bump
app/build.gradle
Increased android.defaultConfig.minSdk from 24 to 26.
Payload schema_version field
app/src/main/java/org/curiouslearning/container/core/subapp/payload/AppEventPayload.java
Added public String schema_version to the payload type.

Possibly related PRs

  • curiouslearning/CRcontainer#246: Overlaps on user_sessions_data and summary_data persistence, particularly createNewSummaryDoc construction and update/merge logic.
  • curiouslearning/CRcontainer#247: Modifies the same summary data persistence logic for querying, merging, creating, and updating records with metadata field changes.
  • curiouslearning/CRcontainer#253: Overlaps on explicit normalization and routing of summary_data via normalizeCollection and success logging including document ID.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 I hopped through code with careful paw,
Metadata trimmed, and schema in my straw,
Created, updated, versions shine,
Logs cleaned up and records fine,
A small carrot for each passing test.

🚥 Pre-merge checks | ✅ 4 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Tests & Lint & Coverage ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately reflects the main changes: adding schema_version field and new timestamp fields (created_at, updated_at) for summary data improvements, and includes the required MR-78 reference.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mr-78--feat--timestamp-fields

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java (3)

44-51: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Syntax error: Incomplete condition removal.

The timestamp validation was removed but left invalid syntax—line 46 ends with || and line 47 has only a closing ). This will not compile, as confirmed by the static analysis parse error.

🐛 Proposed fix
         if (payload.cr_user_id == null || payload.cr_user_id.trim().isEmpty() ||
                 payload.app_id == null || payload.app_id.trim().isEmpty() ||
-                normalizedCollection == null || normalizedCollection.isEmpty() ||
-            ) {
+                normalizedCollection == null || normalizedCollection.isEmpty()) {
 
             Log.e(TAG, "Invalid payload — missing or blank required fields");
             return;
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java`
around lines 44 - 51, The if-condition in DefaultAppEventPayloadHandler has a
trailing logical operator and an extra parenthesis causing a syntax error; edit
the conditional that references payload.cr_user_id, payload.app_id and
normalizedCollection to remove the stray "||" and the unmatched ")" so the
expression is a single well-formed boolean check (or, if you intended to
validate payload.timestamp, reintroduce that check properly instead of leaving
dangling tokens); keep the existing Log.e(TAG, ...) and return behavior
unchanged.

186-215: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Variable shadowing: record parameter is unused.

Line 201 declares a new Map<String, Object> record that shadows the method parameter. The parameter passed from lines 176 and 182 is completely ignored.

Since the method now builds its own complete record, remove the parameter entirely:

🔧 Proposed fix
     private void createNewSummaryDoc(
             FirebaseFirestore db,
-            AppEventPayload payload,
-            Map<String, Object> record
+            AppEventPayload payload
     ) {
 
         if (!(payload.data instanceof Map)) {

Then update the call sites:

-                        createNewSummaryDoc(db, payload, record);
+                        createNewSummaryDoc(db, payload);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java`
around lines 186 - 215, The createNewSummaryDoc method currently declares and
populates a new local Map named record that shadows and never uses the method
parameter record; remove the unused parameter from the method signature (delete
the Map<String, Object> record parameter) and update all call sites that pass a
record to call createNewSummaryDoc(FirebaseFirestore db, AppEventPayload
payload) instead; ensure the method still constructs the local record Map, uses
payload fields (cr_user_id, app_id, collection, data, schema_version) and
performs db.collection(payload.collection).add(record) unchanged.

179-183: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Compilation error: record is out of scope in failure callback.

The record variable is defined at line 150 inside the addOnSuccessListener lambda, but line 182 attempts to reference it from the addOnFailureListener lambda—a separate scope where record does not exist.

🐛 Proposed fix

Create the record inside the failure handler or extract it to the enclosing method scope:

                 .addOnFailureListener(e -> {
 
                     Log.w(TAG, "Query failed — creating new summary record", e);
-                    createNewSummaryDoc(db, payload, record);
+                    Map<String, Object> record = new HashMap<>();
+                    record.put("cr_user_id", payload.cr_user_id);
+                    record.put("app_id", payload.app_id);
+                    createNewSummaryDoc(db, payload, record);
                 });

Alternatively, since createNewSummaryDoc now builds its own record (lines 201-207), consider whether the record parameter is still needed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java`
around lines 179 - 183, The failure callback in DefaultAppEventPayloadHandler's
addOnFailureListener references the local variable record that is only defined
inside the addOnSuccessListener lambda, causing a compile error; fix by moving
creation of the SummaryRecord (the same object named record) into the
addOnFailureListener scope before calling createNewSummaryDoc, or if
createNewSummaryDoc already builds its own record (per lines ~201-207), remove
the record parameter from createNewSummaryDoc and all callers (including the
addOnSuccessListener) and update its signature so callers simply call
createNewSummaryDoc(db, payload) from the failure handler; update references to
the record variable accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java`:
- Around line 162-171: The current update in DefaultAppEventPayloadHandler is
using document(...).set(record) which overwrites the whole document and will
drop existing fields like created_at and schema_version; change this to either
merge the new fields into the existing document by calling set(record,
SetOptions.merge()) or explicitly copy created_at and schema_version from
existingDoc into record before calling set, ensuring you still update updated_at
and data while preserving metadata; update the code around
db.collection(payload.collection).document(existingDoc.getId()).set(...)
accordingly.

---

Outside diff comments:
In
`@app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java`:
- Around line 44-51: The if-condition in DefaultAppEventPayloadHandler has a
trailing logical operator and an extra parenthesis causing a syntax error; edit
the conditional that references payload.cr_user_id, payload.app_id and
normalizedCollection to remove the stray "||" and the unmatched ")" so the
expression is a single well-formed boolean check (or, if you intended to
validate payload.timestamp, reintroduce that check properly instead of leaving
dangling tokens); keep the existing Log.e(TAG, ...) and return behavior
unchanged.
- Around line 186-215: The createNewSummaryDoc method currently declares and
populates a new local Map named record that shadows and never uses the method
parameter record; remove the unused parameter from the method signature (delete
the Map<String, Object> record parameter) and update all call sites that pass a
record to call createNewSummaryDoc(FirebaseFirestore db, AppEventPayload
payload) instead; ensure the method still constructs the local record Map, uses
payload fields (cr_user_id, app_id, collection, data, schema_version) and
performs db.collection(payload.collection).add(record) unchanged.
- Around line 179-183: The failure callback in DefaultAppEventPayloadHandler's
addOnFailureListener references the local variable record that is only defined
inside the addOnSuccessListener lambda, causing a compile error; fix by moving
creation of the SummaryRecord (the same object named record) into the
addOnFailureListener scope before calling createNewSummaryDoc, or if
createNewSummaryDoc already builds its own record (per lines ~201-207), remove
the record parameter from createNewSummaryDoc and all callers (including the
addOnSuccessListener) and update its signature so callers simply call
createNewSummaryDoc(db, payload) from the failure handler; update references to
the record variable accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 26bbc3f6-b89e-4889-978b-398e30964746

📥 Commits

Reviewing files that changed from the base of the PR and between ab6b654 and a7ddd7f.

📒 Files selected for processing (2)
  • app/fastlane/debug_apks/app-debug.apk
  • app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java

@miguelccodev miguelccodev changed the title feat: [CR] Summary Data Improvements feat: [CR] Summary Data Improvements (MR-78) May 27, 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.

4 participants