Skip to content

Record runs as a PROV bundle with file and MariaDB stores - #2

Open
vamsikalagaturu wants to merge 16 commits into
mainfrom
feat/prov-run-record
Open

vamsikalagaturu wants to merge 16 commits into
mainfrom
feat/prov-run-record

Conversation

@vamsikalagaturu

@vamsikalagaturu vamsikalagaturu commented Oct 7, 2026 •

Copy link
Copy Markdown
  • A run is recorded as a PROV bundle (prov:Bundle, attributed to rec's purl): a prov-ext:Execution and an oslc_auto:AutomationResult with its OSLC state and verdict, wall-clock instants and host, written with the rdf-utils helpers (create_bundle, load_pkg_prov, load_execution_prov, add_wall_instant)
  • Run(store, run_id, base) is one handle on a run: queue(), start(), beat(), end(verdict, fail_trace), cancel(), lifecycle(); run(work) does the steps around a plain function, beating while it runs and ending it as passed, failed or error
  • Each step edits the bundle the store parsed under its lock: it checks the run's state once and changes only its own triples, so a start and a cancel cannot both succeed across processes
  • A queued run that is cancelled never starts; a run in progress asked to stop ends canceled, or keeps its verdict if its work raised; an interrupt is raised again once recorded
  • FileStore keeps a run's bundle as <run_id>.ld.json under an flock; MariaDBStore keeps it as JSON-LD in a row of <prefix>_runs, locking the row by inserting it, with case-sensitive run ids
  • What a run executes, the software and files it uses or generates, and its steps are left to the tool that knows them, in its own bundle
  • examples/robot_runs.py records runs in files and in MariaDB: passed, failed, cancelled while queued, stopped while running
  • rdflib and rdf-utils (pinned to bad7c02) become dependencies; MariaDB stays an extra; the observers, Feature and Scenario are replaced by the run handle and stores

- RunRecord (rec.record) is what rec knows of a run: OSLC state and verdict, times, result and fail trace, program and recording software, trigger, host, agents, sources, repositories, dependencies, resources, artefacts and metrics
- Observer(store) records every event once for any store: load the record, change it, save it; a run cancelled in the store does not start, only a run that has not started can be cancelled, and a step logged again replaces its value
- A store is any object with load, save, run_ids and close (rec.stores.Store); FileStore keeps a run as its PROV document (fmt="rdf") or its record as JSON (fmt="json"), MariaDBStore as one row with state and verdict columns, migrating the previous release's table
- rec.provenance maps a record to PROV with the rdf-utils helpers and back: an unstarted run is a prov:Activity, a started one a prov-ext:Execution associated with rec whose plan is the file defining the run; files are entities, relative paths prov-ext:RelativeLocation under the directory they were logged from
- Run records the program it ran, stops the heartbeat before completion, and runs post-run hooks after it, so a hook that raises no longer rewrites the verdict
- rdflib and rdf-utils become dependencies; MariaDB stays an extra; observers are replaced by the observer and stores

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The dependency reference currently breaks imports, and lifecycle concurrency, migration, and PROV round-trip defects remain.

Review effort: Balanced
Findings: 3 High severity · 4 Medium severity

Open (7)
What changed in this PR

Introduces store-agnostic run records, JSON/PROV persistence, and MariaDB migration support.

Changes:

  • Adds RunRecord, lifecycle-aware observers, and pluggable stores.
  • Adds bidirectional PROV mapping and richer run metadata.
  • Replaces legacy observers and adds integration/conformance tests.
File Description
rec/​__init__.py Defines lifecycle states and verdicts.
rec/​record.py Defines the store-independent record model.
rec/​observer.py Applies run events to stored records.
rec/​run.py Records execution lifecycle and metadata.
rec/​provenance.py Converts records to and from PROV.
rec/​stores/​__init__.py Defines the store protocol.
rec/​stores/​file_store.py Adds JSON and RDF file storage.
rec/​stores/​mariadb_store.py Adds database storage and migration.
rec/​observers/​base.py Removes the legacy observer interface.
rec/​observers/​mariadb_observer.py Removes the legacy MariaDB observer.
rec/​observers/​__init__.py Retains the legacy package namespace.
tests/​test_run.py Tests lifecycle, PROV, and file stores.
tests/​test_mariadb_store.py Tests database storage and migration.
examples/​decentral_run.py Updates the MariaDB example.
README.md Documents records, stores, and tests.
pyproject.toml Updates dependencies and extras.
.github/​workflows/​tests.yml Adds Python and MariaDB CI coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pyproject.toml Resolved
Comment thread rec/observer.py Resolved
Comment thread rec/run.py Resolved
Comment thread rec/provenance.py Resolved
Comment thread rec/provenance.py Resolved
Comment thread rec/provenance.py Resolved
Comment thread rec/stores/mariadb_store.py Resolved
- Store.edit(run_id) replaces save: FileStore holds an flock on <id>.lock, MariaDBStore a SELECT ... FOR UPDATE transaction, so a start and a cancel from separate observers cannot both succeed
- A run starts only when new or queued, in Run.run and Observer.log_started_run
- Run ids are percent-encoded in run IRIs
- A list or mapping result is an rdf:JSON literal and reads back as itself
- Drop the migration of MariaDBObserver's table and its test
- Drop Run's unused ingredients, scenario and **kwargs
- The start refusal names the run's state, canceled, so the test matches "is canceled"

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

RDF round-tripping, legacy database migration, metric indexing, heartbeat cleanup, and dependency reproducibility have unresolved issues.

Review effort: Balanced
Findings: 4 High severity · 1 Medium severity

Open (5)
Resolved since last review (4)
Previously missed (3)

In code that hasn't changed since last review

Medium severity Pin VCS dependency to a released or immutable version

pyproject.toml:11

Depending on the moving main branch makes installations and CI non-reproducible; an upstream change can break this package without any REC commit, especially because the code imports an underscore-prefixed helper from this dependency. Use a released version or pin the VCS reference to an immutable commit/tag.

Medium severity Select next step above the maximum existing metric step

rec/​observer.py:96

Counting existing metrics does not reliably select a new step. For example, after explicitly logging step 1, the next call without a step also chooses 1 and silently replaces it; sparse explicit steps have the same problem. Choose one greater than the maximum existing step for this metric.

Medium severity Guard missing run start before RDF trigger lookup

rec/​provenance.py:218

When a run has no qualified start, start is None; in rdflib, g.value(None, PROV.entity) searches for a subject with that predicate rather than returning None. A run with resources but no trigger can therefore deserialize a prov:Usage node as its trigger, breaking the RDF/record round trip. Guard both lookups with if start.

Comment thread rec/run.py Resolved
Comment thread rec/stores/mariadb_store.py Resolved
- The heartbeat stops in a finally around the hooks and main, so SystemExit no longer leaves its non-daemon thread running
- MariaDBStore.number had no caller; the id column stays to order runs
- Only a new run can be queued and only a queued run cancelled, so a finished run cannot be queued and run again, and cancelling an unknown id creates nothing
- Run queues and cancels only once its stores accept, as it already started
- A record with a value JSON cannot keep is refused for every store, so a result or metric no longer passes in one store and fails in another
- add_agent accepts only PROV-O's agent classes
- MariaDBStore serializes its threads on its one connection; the observer no longer locks
- Queueing, starting, cancelling and ending hold every store's record at once, so a refusal by one store leaves all unchanged; observers sharing a store are refused
- Ending a run and its heartbeat require it in progress
- The observer keeps lists in one order and refuses a change JSON or PROV would not give back unchanged: lossy JSON values, NaN, empty strings, an entity logged twice
- A file is generated once per run (PROV-Constraints generation-uniqueness)
- provenance.record reads only the requested run, and a file's IRI includes its root
- The heartbeat is a daemon thread, so one stuck on a store cannot keep the process alive
- FileStore.save is private to edit
- README states the multi-store limits: no two-phase commit, and opposite store orders can deadlock
- graph() types a run prov-ext:Execution and oslc_auto:AutomationResult whatever its state; a started run adds its start time and association
- A queued or cancelled run conforms with no start time, association or usage
- The shapes refuse a run without a verdict, a queued run with a start time, and a run that is not an execution or not an automation result
- README describes the run's types
- MariaDBStore keeps a run as a row of <prefix>_runs and a row per list item, from rec/stores/mariadb.sql, instead of a JSON blob
- Run reads state and verdict from the store; a Run with a stored run_id goes on from there and the store decides each step
- cancel() ends a queued run as canceled; a run in progress becomes canceling and ends as canceled once main returns
- Keep what main returned as rec:result
- Add run steps: add_activity records a prov-extension activity dcterms:isPartOf the run; a resource or artefact may only name a step of its run
- Compare stores by PROV graph isomorphism and drop the sorting of record lists
- Remove log_sources, info(), the pre/post run hooks, Scenario, Feature and the decentralized example
- Build with hatchling and take the version from git tags
- Fix reading agents back from MariaDB, whose id column was dropped
- Add file, MariaDB and all-stores examples; rewrite the README around snippets
- Test cancelling a run in progress, run steps, and files of unknown steps
- Write a run as a prov:Bundle attributed to rec's purl, with rdf-utils load_pkg_prov, load_execution_prov and add_wall_instant
- Keep the bundle id in the record, minted on the run's first edit
- Record the packages a run used as rdf-utils PackageInfo (log_packages), replacing repositories and dependencies
- Drop agents, activities, resources, artefacts, metrics, program, trigger and result: tools record their files and steps in their own bundles
- FileStore writes any rdf-utils DatasetFormat; drop the JSON record format
- MariaDB keeps runs and packages tables, the recorder flagged
- Keep queue, cancel and heartbeat
@vamsikalagaturu vamsikalagaturu changed the title Record runs as a store-agnostic record with a PROV view Record runs as a PROV bundle with file and MariaDB stores Nov 12, 2026
- prov:used takes a prov:Entity; load_pkg_prov types a package as a software agent, spdx package and location only
- Drop packages, log_packages and add_package: the calling tool records the software it ran in its own bundle
- Keep rec as the run's recorder; MariaDB keeps it in recorder_* columns of the runs table and drops the packages table
- Remove the all-stores example
- One example records runs in a bundle file and in MariaDB: passed, failed, cancelled while queued, stopped while running
- PickPlaceRun checks for a stop request between motions; DrawerOpeningRun fails on an unreachable handle
- The runs table holds a run's id and its bundle as JSON-LD; edit and load go through the same provenance functions as FileStore
- Drop the per-field columns, the column mapping and MariaDBRun; run_ids filters by state from the bundles
- Both stores yield a RunRecord, so the RunHandle protocol goes
- A store's edit yields the run's parsed Dataset under its lock and writes it back; the Observer checks the state and sets only the event's triples
- rdf-utils writes the bundle, rec as software agent, the execution and its instants once each; RunRecord and the record-bundle round trip go
- A run has one observer and store; the run is associated with the rec that started it, the bundle attributed to the rec that first recorded it
- MariaDB locks a new run's row by inserting it and keeps run ids case-sensitive; the table is created in code
- An interrupt ends the run as error and is raised again; a failed heartbeat is logged and the next tried; a run that fails while canceling keeps its verdict
- A run cancelled while queued has no beginning or end; times without a zone and files outside the store's directory are refused
- Drop TriG and N-Quads files, run_ids, the warning verdict, the store protocols and the close forwarders; base moves to the Observer

Copilot AI 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.

🟡 Changes recommended

Host-metadata failures can leave runs stuck in progress and block retries, while incorrect PROV bundle selection can crash lifecycle updates or misplace host metadata.

2 open issues
5 resolved since last review

Review effort: Balanced

Comment thread rec/run.py Resolved
Comment thread rec/observer.py Resolved
…un's own bundle

- run() records the host inside the guarded block, so a failure there ends the started run as failed; the heartbeat is joined only if it started
- The Observer finds the run's bundle by the run's state, not the first prov:Bundle, and refuses a dataset holding a run under another base
- Run(store, run_id, base) queues, starts, beats, ends, cancels and reads its lifecycle; run(work) does the steps around a plain function, replacing the Observer and subclassed main
- Each step checks the state once in _step, stamps its time under the store's lock and changes only its triples; the host is recorded with the start
- end refuses an unavailable verdict and a trace on a passed run; an interrupt is raised again even when the end cannot be recorded; the heartbeat join is bounded
- MariaDB refuses a prefix that is not a table name; a stored run holds only rec's bundle
- Follow rdf-utils add_wall_instant(graph, stamp, instant_id=) and pin rdf-utils to bad7c02, which no release tag includes yet
- The example records fresh runs on every invocation

This branch has not been deployed

No deployments
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.

2 participants