diff --git a/CHANGELOG b/CHANGELOG index d8155323d..36b5bb76e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ This project _loosely_ adheres to [Semantic Versioning](https://semver.org/spec/ - Show an error when the code is wrong. [PR#502](https://github.com/coasys/ad4m/pull/502) - Error handling in connect when hosting is not working [PR#502](https://github.com/coasys/ad4m/pull/502) - Make new Rust create_subject() implementation wait for Prolog engine to be updated, reflecting the new instance to avoid race conditions [PR#520](https://github.com/coasys/ad4m/pull/520) +- Fix problems with Subject Classes created by other non-progenitor agents, and make isSubjectInstance() more stable agains race conditions [PR#521](https://github.com/coasys/ad4m/pull/521) ### Added - Prolog predicates needed in new Flux mention notification trigger: diff --git a/core/src/perspectives/PerspectiveProxy.ts b/core/src/perspectives/PerspectiveProxy.ts index 26bdb0171..b47b24cef 100644 --- a/core/src/perspectives/PerspectiveProxy.ts +++ b/core/src/perspectives/PerspectiveProxy.ts @@ -365,7 +365,16 @@ export class PerspectiveProxy { */ async isSubjectInstance(expression: string, subjectClass: T): Promise { let className = await this.stringOrTemplateObjectToSubjectClass(subjectClass) - return await this.infer(`subject_class("${className}", C), instance(C, "${expression}")`) + let isInstance = false; + const maxAttempts = 5; + let attempts = 0; + + while (attempts < maxAttempts && !isInstance) { + isInstance = await this.infer(`subject_class("${className}", C), instance(C, "${expression}")`); + attempts++; + } + + return isInstance } diff --git a/rust-executor/src/perspectives/perspective_instance.rs b/rust-executor/src/perspectives/perspective_instance.rs index 8f6aa7207..8afaa1165 100644 --- a/rust-executor/src/perspectives/perspective_instance.rs +++ b/rust-executor/src/perspectives/perspective_instance.rs @@ -3,7 +3,7 @@ use super::update_perspective; use super::utils::{ prolog_get_all_string_bindings, prolog_get_first_string_binding, prolog_resolution_to_string, }; -use crate::agent::create_signed_expression; +use crate::agent::{self, create_signed_expression}; use crate::graphql::graphql_types::{ DecoratedPerspectiveDiff, ExpressionRendered, JsResultType, LinkMutations, LinkQuery, LinkStatus, NeighbourhoodSignalFilter, OnlineAgent, PerspectiveExpression, PerspectiveHandle, @@ -889,8 +889,15 @@ impl PerspectiveInstance { }) .await?; + let author = agent::did(); + let mut sdna_links: Vec = Vec::new(); + let links = links + .into_iter() + .filter(|l| l.author == author) + .collect::>(); + if (Literal::from_url(sdna_code.clone())).is_err() { sdna_code = Literal::from_string(sdna_code) .to_url() @@ -905,7 +912,7 @@ impl PerspectiveInstance { }); sdna_links.push(Link { - source: literal_name, + source: literal_name.clone(), predicate: Some("ad4m://sdna".to_string()), target: sdna_code, });