Skip to content

Rulebook activation restart fails with stale source_mappings hash after project sync to new Git ref #1542

Description

@amasolov

Bug Summary

When an EDA project's scm_branch is updated to a different Git tag (e.g. v1.0.0 to v1.1.0) and the project is synced, existing rulebook activations with event stream source mappings cannot be restarted. The API returns:

{'source_mappings': 'Rulebook has changed since the sources were mapped. Please reattach event streams'}

The root cause is that _sync_rulebook() in services/project/imports.py updates Rulebook.rulesets and Activation.rulebook_rulesets but never updates the rulebook_hash embedded inside Activation.source_mappings. The stale hash then fails the comparison in _validate_sources_with_event_streams().

Environment

  • eda-server (main branch)

Steps to reproduce

  1. Create an EDA project pointing to a Git repo at tag v1.0.0
  2. Create an event stream
  3. Create a rulebook activation using a rulebook from that project, with event stream source mappings attached (the API stores a rulebook_hash inside source_mappings)
  4. Confirm the activation runs successfully
  5. Update the EDA project's scm_branch from v1.0.0 to v1.1.0 (where the rulebook file has any text change, even a comment or whitespace)
  6. Sync the project
  7. Attempt to restart the activation

Actual results

Restart fails with HTTP 400:

{"errors": "{'source_mappings': 'Rulebook has changed since the sources were mapped. Please reattach event streams'}"}

The activation is set to error state. The user must manually edit the activation and re-attach event streams, even when the source definitions are functionally identical.

Expected results

When a project sync updates a rulebook's content, the rulebook_hash stored inside source_mappings on affected activations should be updated to match. Restart and enable operations should continue to work without manual re-attachment when the sources are structurally unchanged.

Additional information

Root cause spans two code paths:

  1. src/aap_eda/services/project/imports.py, _sync_rulebook(): updates rulebook.rulesets and Activation.rulebook_rulesets via bulk update(), but does not touch Activation.source_mappings.

  2. src/aap_eda/api/serializers/activation.py, _validate_sources_with_event_streams(): recomputes get_rulebook_hash(rulebook.rulesets) and compares it against the now-stale rulebook_hash in source_mappings.

Proposed fix: In _sync_rulebook(), when the content has changed, iterate over affected activations and rewrite the rulebook_hash inside each source_mappings entry to match the new hash. A draft patch is available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions