From 6b77170e0f55fc1f3fb1dcf4dba099e2ebcf6c3b Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Fri, 23 Aug 2024 18:05:51 +0530 Subject: [PATCH 1/4] chore: Improve isSubjectInstance method with retry logic for better reliability --- core/src/perspectives/PerspectiveProxy.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 } From d7360ae400fc159ef2ea84e082bf283bfb117459 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Fri, 30 Aug 2024 14:10:10 +0530 Subject: [PATCH 2/4] chore: Update crate imports in perspective_instance.rs --- .../src/perspectives/perspective_instance.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rust-executor/src/perspectives/perspective_instance.rs b/rust-executor/src/perspectives/perspective_instance.rs index 83c07daa6..f5b4251d5 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, did}; use crate::graphql::graphql_types::{ DecoratedPerspectiveDiff, ExpressionRendered, JsResultType, LinkMutations, LinkQuery, LinkStatus, NeighbourhoodSignalFilter, OnlineAgent, PerspectiveExpression, PerspectiveHandle, @@ -888,8 +888,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() @@ -904,7 +911,7 @@ impl PerspectiveInstance { }); sdna_links.push(Link { - source: literal_name, + source: literal_name.clone(), predicate: Some("ad4m://sdna".to_string()), target: sdna_code, }); From f418d5f41df8c734d5d92c0b068f5b42fabb3919 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 2 Sep 2024 18:46:04 +0200 Subject: [PATCH 3/4] changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) 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: From f71c4e0b0887819cda2d374a0eb50f4306b2e78c Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 2 Sep 2024 18:47:26 +0200 Subject: [PATCH 4/4] warning-- --- rust-executor/src/perspectives/perspective_instance.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-executor/src/perspectives/perspective_instance.rs b/rust-executor/src/perspectives/perspective_instance.rs index 991af9c2e..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::{self, create_signed_expression, did}; +use crate::agent::{self, create_signed_expression}; use crate::graphql::graphql_types::{ DecoratedPerspectiveDiff, ExpressionRendered, JsResultType, LinkMutations, LinkQuery, LinkStatus, NeighbourhoodSignalFilter, OnlineAgent, PerspectiveExpression, PerspectiveHandle,