Skip to content

fix(database): validate inputs and normalize timestamps in desktop previews - #20087

Closed
brandonstensby-dotcom wants to merge 2 commits into
BasedHardware:mainfrom
brandonstensby-dotcom:fix/database-desktop-previews-resilience
Closed

brandonstensby-dotcom wants to merge 2 commits into
BasedHardware:mainfrom
brandonstensby-dotcom:fix/database-desktop-previews-resilience

Conversation

@brandonstensby-dotcom

@brandonstensby-dotcom brandonstensby-dotcom commented Oct 1, 2026 •

Copy link
Copy Markdown

Closes #20086

Summary

Hardens target database module with defensive boundary checks and fail-fast validation:

  1. Strict validation on preview slug and hash strings.
  2. Explicit rejection of boolean expected_generation values.
  3. Timezone-aware UTC timestamp coercion.
  4. 7 hermetic unit tests in test_database_desktop_previews_resilience.py (7/7 PASS).

Review & Settlement

cc @Git-on-my-level for review!
Base USDC Coordinates: 0xbB9686b9684421A8e326AC0F8B3eCf88Df975120

Review in cubic

@cubic-dev-ai cubic-dev-ai 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.

2 issues found across 2 files

Confidence score: 4/5

  • In backend/database/desktop_previews.py, _publish_preview_transaction never passes updated_at, so the pointer always uses the current time and the new validation path is only exercised by the unit test; pass the intended timestamp or align the behavior and test.
  • In backend/tests/unit/test_database_desktop_previews_resilience.py, the fixture’s p0375d1f909 slug makes manifest normalization reject its identity fields, so the generation tests cannot use this fixture; update both identity values to match a valid manifest.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/database/desktop_previews.py">

<violation number="1" location="backend/database/desktop_previews.py:194">
P3: Only the new unit test exercises this block: the sole production caller `_publish_preview_transaction` never passes `updated_at`, so the pointer always falls back to `datetime.now(timezone.utc)` and this added validation/coercion is inert. Also note `replace(tzinfo=timezone.utc)` reinterprets a naive wall-clock value as already-UTC rather than converting it, so a caller passing local time would silently store the wrong instant. Either thread `updated_at` through `publish_preview` or document the UTC interpretation.</violation>
</file>

<file name="backend/tests/unit/test_database_desktop_previews_resilience.py">

<violation number="1" location="backend/tests/unit/test_database_desktop_previews_resilience.py:24">
P3: This fixture is not valid for `feature-test`: its slug derives `p0375d1f909`, so manifest normalization rejects these identity fields. Update both values so the generation tests use a valid manifest.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/database/desktop_previews.py Resolved
raise ValueError(f"generation mismatch: expected {expected_generation}, current {current_generation}")
if current.get("source_sha") == manifest["source_sha"]:
return current
if updated_at is not None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: Only the new unit test exercises this block: the sole production caller _publish_preview_transaction never passes updated_at, so the pointer always falls back to datetime.now(timezone.utc) and this added validation/coercion is inert. Also note replace(tzinfo=timezone.utc) reinterprets a naive wall-clock value as already-UTC rather than converting it, so a caller passing local time would silently store the wrong instant. Either thread updated_at through publish_preview or document the UTC interpretation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/database/desktop_previews.py, line 194:

<comment>Only the new unit test exercises this block: the sole production caller `_publish_preview_transaction` never passes `updated_at`, so the pointer always falls back to `datetime.now(timezone.utc)` and this added validation/coercion is inert. Also note `replace(tzinfo=timezone.utc)` reinterprets a naive wall-clock value as already-UTC rather than converting it, so a caller passing local time would silently store the wrong instant. Either thread `updated_at` through `publish_preview` or document the UTC interpretation.</comment>

<file context>
@@ -164,11 +179,23 @@ def _build_preview_pointer(
+            raise ValueError(f"generation mismatch: expected {expected_generation}, current {current_generation}")
     if current.get("source_sha") == manifest["source_sha"]:
         return current
+    if updated_at is not None:
+        if not isinstance(updated_at, datetime):
+            raise ValueError("updated_at must be a datetime")
</file context>

"slug": "feature-test",
"source_sha": "0123456789abcdef0123456789abcdef01234567",
"app_name": "Omi Preview (feature-test)",
"bundle_id": "com.omi.preview.p48ec788481",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: This fixture is not valid for feature-test: its slug derives p0375d1f909, so manifest normalization rejects these identity fields. Update both values so the generation tests use a valid manifest.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/tests/unit/test_database_desktop_previews_resilience.py, line 24:

<comment>This fixture is not valid for `feature-test`: its slug derives `p0375d1f909`, so manifest normalization rejects these identity fields. Update both values so the generation tests use a valid manifest.</comment>

<file context>
@@ -0,0 +1,104 @@
+        "slug": "feature-test",
+        "source_sha": "0123456789abcdef0123456789abcdef01234567",
+        "app_name": "Omi Preview (feature-test)",
+        "bundle_id": "com.omi.preview.p48ec788481",
+        "url_scheme": "omi-preview-p48ec788481",
+        "built_at": "2026-09-30T12:00:00Z",
</file context>

@brandonstensby-dotcom

Copy link
Copy Markdown
Author

Resolved cubic-dev-ai review issues:

  • Cleanly normalized aware timestamps to UTC with .astimezone(timezone.utc) and properly handled optional updated_at.
  • Updated test fixture �undle_id and url_scheme to match manifest normalization hash p0375d1f909.
  • Added unit test covering aware non-UTC updated_at conversion. All tests passing (8/8).

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @brandonstensby-dotcom — this is a tidy, genuinely useful hardening pass on the desktop preview manifest path. Reviewed both files:

backend/database/desktop_previews.py

  • The new isinstance/dict guards (_required_string, _optional_string, normalize_preview_manifest, _build_preview_pointer) all raise before any Firestore access, so fail-fast ordering is correct and the tests stay hermetic.
  • _slug/_source_sha/_sha256 now strip before the regex and return the normalized value; slightly more permissive on input but the pattern checks still apply post-strip, so nothing is weakened. (The slug.strip() at the delist/get call sites is now redundant but harmless.)
  • expected_generation validation (rejecting bool, non-int, negative) is consistent across publish_preview, delist_preview, and _build_preview_pointer; the duplication is fine as defense in depth.
  • updated_at handling: the aware-datetime astimezone(timezone.utc) conversion is right, and 'updated_at is not None' vs the old 'or' is behavior-equivalent for datetimes. One choice to be aware of: naive datetimes are silently assumed UTC via replace(tzinfo=utc) rather than rejected — defensible default, just flagging it as a deliberate semantics decision for maintainers.
  • _timestamp catching TypeError as well as ValueError is a harmless belt-and-suspenders addition.

backend/tests/unit/test_database_desktop_previews_resilience.py

  • 8 focused hermetic tests covering the non-dict, non-string, bad-generation, and timezone-coercion paths; importing the private helpers (_slug, _source_sha, _sha256, _build_preview_pointer) is acceptable for boundary-level unit tests. The aware non-UTC conversion test asserting both tzinfo and the shifted wall time is a nice touch.

No CI check runs are visible on this PR yet, so please make sure they trigger (or rebase if the fork gate needs it). Since this touches validation of preview distribution manifest data (dmg_url, dmg_sha256, source_sha), I'm leaving the merge call to a human maintainer.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added security-review Touches auth, provider routing, secrets, or security-sensitive surfaces backend Backend Task (python) labels Oct 1, 2026
@omiagent

omiagent Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Thanks for this fix, @brandonstensby-dotcom! Your commits are being carried forward in #22207 (cherry-picked with your original authorship intact) so they can land with the current CI and repo conventions. Closing this in favor of that branch — your contribution is credited there and in the git history.

@omiagent omiagent Bot closed this Oct 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @brandonstensby-dotcom 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

kodjima33 pushed a commit that referenced this pull request Oct 19, 2026
…tamps in desktop previews (#22207)

* fix(backend): validate inputs and normalize timestamps in database desktop previews

* fix(database): cleanly normalize aware timestamps to UTC and update preview fixture identities

---------

Co-authored-by: brandonstensby-dotcom <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) security-review Touches auth, provider routing, secrets, or security-sensitive surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Desktop previews lack slug validation and boolean generation protection

2 participants