basyx-python-sdk icon indicating copy to clipboard operation
basyx-python-sdk copied to clipboard

sdk/basyx/aas/backend/local_file.py: Fix `discard()` in `LocalFileObjectStore`

Open moritzsommer opened this issue 1 year ago • 10 comments

Current Situation

The _object_cache of the LocalFileObjectStore is not initialised when a new instance of the class is created. This means that the Identifiables from the local .json files are not loaded initially:

https://github.com/eclipse-basyx/basyx-python-sdk/blob/e622edcc9ae11493fb231e44d80d74828426f0f4/sdk/basyx/aas/backend/local_file.py#L34-L49

The cache is designed to operate efficiently, i.e. it is only filled with a specific Identifiable from a local .json file when the user searches for or adds it. Consequently, calling discard() on a newly initialised LocalFileObjectStore raises a KeyError whenever the Identifiable to delete exists in a local .json file, but is not present in the initially empty cache:

https://github.com/eclipse-basyx/basyx-python-sdk/blob/e622edcc9ae11493fb231e44d80d74828426f0f4/sdk/basyx/aas/backend/local_file.py#L112-L125

Proposed Change

Ensure that the discard() method can handle an empty _object_cache by catching potential KeyErrors.

moritzsommer avatar Nov 29 '25 18:11 moritzsommer

Reminder: Remove the quick temporary fix in AbstractObjectStore.sync after fixing this properly.

s-heppner avatar Feb 09 '26 08:02 s-heppner

Agent run 54ce26dd46d64554b9d30c00e0528153 started.

AlwaysTwilight avatar Feb 23 '26 04:02 AlwaysTwilight

Agent run 54ce26dd46d64554b9d30c00e0528153 failed: Command '['docker', 'run', '--rm', '--cpus', '1.0', '--memory', '2g', '-v', 'D:\SWE_Agents\.work\54ce26dd46d64554b9d30c00e0528153\repo:/work', '-w', '/work', 'python:3.11-slim', 'sh', '-lc', 'if ! command -v git >/dev/null 2>&1; then apt-get update -y >/dev/null 2>&1 && apt-get install -y git >/dev/null 2>&1; fi; git diff --numstat']' timed out after 30 seconds

AlwaysTwilight avatar Feb 23 '26 04:02 AlwaysTwilight

Agent run dca4d6d2008048378ca95c186e464b79 started.

AlwaysTwilight avatar Feb 23 '26 04:02 AlwaysTwilight

Agent run dca4d6d2008048378ca95c186e464b79 failed: Command '['docker', 'run', '--rm', '--cpus', '1.0', '--memory', '2g', '-v', 'D:\SWE_Agents\.work\dca4d6d2008048378ca95c186e464b79\repo:/work', '-w', '/work', 'python:3.11-slim', 'sh', '-lc', 'if ! command -v git >/dev/null 2>&1; then apt-get update -y >/dev/null 2>&1 && apt-get install -y git >/dev/null 2>&1; fi; git diff --numstat']' timed out after 30 seconds

AlwaysTwilight avatar Feb 23 '26 04:02 AlwaysTwilight

Okay, this is kind of scary. An AI coding agent has gone rogue and is crawling its way through GitHub, posting all status messages in this issue thread. Apparently, I triggered it via the GitHub API when I edited the issue text. Is this common? What should we do? 😅

moritzsommer avatar Feb 23 '26 04:02 moritzsommer

Fun. I suspect this is someone's personal agent (possibly openclaw.ai), considering the path's its running from is a local Windows machine (D:\SWE_Agents\...). If this is the only time this happens, I think we'll ignore it, otherwise we report the GitHub user as spamming and block it from writing issues to our project. I'm afraid there's no way of figuring out whoever let this agent loose on our repo, I've skimmed openclaw's documentation, there’s no apparent official way to report “misbehaving OpenClaw bots” anywhere.

s-heppner avatar Feb 23 '26 08:02 s-heppner

guys chill i was just testing something from my local system nothing scary is going on 😂😅.

AlwaysTwilight avatar Feb 23 '26 09:02 AlwaysTwilight

Thanks for the clarification.

For future reference, please don’t run experiments that post automated output into open source project issues. It creates noise and makes it harder to track real discussions.

If you’d like to experiment with the project, feel free to fork it or open a draft PR instead.

s-heppner avatar Feb 23 '26 10:02 s-heppner

While fixing this issue, I noticed that the _object_cache is always updated but never used as an actual lookup cache. None of the operations of the LocalFileIdentifiableStore require the cache, it just runs alongside:

https://github.com/eclipse-basyx/basyx-python-sdk/blob/e622edcc9ae11493fb231e44d80d74828426f0f4/sdk/basyx/aas/backend/local_file.py#L64-L85

Or is the cache actually intended to work as an identity map, so that one .json file is represented by exactly one and only one canonical in-memory instance? In this case, I just got confused by the naming.

Another issue we should address is that we write to _object_cache outside the lock.

moritzsommer avatar Feb 23 '26 17:02 moritzsommer