Skip to content

Refactor Mirabuf Loading System [AARD-2060] #1273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from

Conversation

rutmanz
Copy link
Member

@rutmanz rutmanz commented Aug 14, 2025

Task

AARD-2060 - Refactor mirabuf caching service

AARD-2069 - Make uploading local mirabuf files enforce correct miratype (with gamepieces we can't just infer miratype completely)

Symptom

The current MirabufCachingService made a few decisions that made it hard to understand and had some key limitations:

  • The id field was unique but not consistent (it was based on the time that you first downloaded the file to your cache). This was the impetus for changing this, as we needed consistent IDs for multiplayer.
  • The cacheKey field was either the name of the APS project, the remote download URL, or the hash of the locally uploaded file
  • The MirabufCacheInfo type was used both to store information about the OPFS files and to store in-memory references to the ArrayBuffers
  • Everything was split by type, so there were two versions of every datastructure, one for robots, one for fields (and gamepieces added a third). There's no actual reason to require this as one model should never appear as both a field and a robot
  • There was a bunch of duplicate code
  • It didn't actually work when OPFS was unavailable

Solution

  • When OPFS is unavailable (some old browsers, insecure contexts), it will gracefully fall back and avoid producing errors.
  • The id field has been replaced with a hash field, that is the SHA-1 hash of the assembly (consistent and unique)
  • Removed unnecesssary and duplicate code
  • Uses one map and OPFS folder for all assets
  • Checks on load that all the assets are still there and removes any extras
  • Fields aren't randomly optional (looking at you name), and there is a single source of truth for asset metadata

Verification

Note

Your mirabuf cache will be cleared every time you switch between Synthesis on this branch and Synthesis not on this branch

  • Test that downloading mirabuf assets works (and stays after reload)
  • Test that uploading mirabuf assets works (and stays after reload)
  • Test that downloading APS mirabuf assets works (and stays after reload)
  • Test that deleting assets works and removes them from OPFS
  • Test that messing around in your browser's dev tools and deleting files/localstorage items doesn't cause undefined behavior

Before merging, ensure the following criteria are met:

  • All acceptance criteria outlined in the ticket are met.
  • Necessary test cases have been added and updated.
  • A feature toggle or safe disable path has been added (if applicable).
  • User-facing polish:
    • Ask: "Is this ready-looking?"
  • Cross-linking between Jira and GitHub:
    • PR links to the relevant Jira issue.
    • Jira ticket has a comment referencing this PR.

@rutmanz rutmanz self-assigned this Aug 14, 2025
@rutmanz rutmanz added the refactor The most important part of software development. label Aug 14, 2025
@rutmanz rutmanz marked this pull request as ready for review August 14, 2025 17:19
@rutmanz rutmanz requested review from a team as code owners August 14, 2025 17:19
@autodesk-chorus
Copy link

Chorus detected one or more security issues with this pull request. See the Checks tab for more details.

As a reminder, please follow the secure code review process as part of the Secure Coding Non-Negotiable requirement.

@rutmanz rutmanz force-pushed the zachr/2060/mirabuf-refactor branch from edf84e2 to 91d228d Compare August 19, 2025 17:53
fix: try to make unit tests work

fix: actually make unit tests work

feat: add unit tests for default assets

fix: tsconfig issues again
@rutmanz rutmanz force-pushed the zachr/2060/mirabuf-refactor branch from 91d228d to edee81d Compare August 19, 2025 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor The most important part of software development.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants