Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/scripts/start_attention_broker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -euo pipefail

# Extra arguments are forwarded to bazelisk before the build verb, for example:
# BAZELISK_HOME=... .github/scripts/start_attention_broker.sh --output_user_root=...

REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "${REPO_ROOT}/src"

PORT=40001
ADDRESS="0.0.0.0:${PORT}"
Comment thread
andre-senna marked this conversation as resolved.
Resolved
PID_FILE=/tmp/attention-broker.pid
LOG_FILE=/tmp/attention-broker.log

das-cli attention-broker stop || true
if [[ -f "${PID_FILE}" ]]; then
kill "$(cat "${PID_FILE}")" >/dev/null 2>&1 || true
Comment thread
andre-senna marked this conversation as resolved.
Resolved
rm -f "${PID_FILE}"
fi

./scripts/bazel_exec.sh "$@" build --noshow_progress //:attention_broker_service

setsid nohup ./bazel-bin/attention_broker_service "${ADDRESS}" >"${LOG_FILE}" 2>&1 </dev/null &
echo $! > "${PID_FILE}"

for _ in $(seq 1 60); do
if (echo >/dev/tcp/127.0.0.1/"${PORT}") >/dev/null 2>&1; then
echo "Attention broker ready on port ${PORT}"
exit 0
Comment thread
andre-senna marked this conversation as resolved.
Resolved
fi
if ! kill -0 "$(cat "${PID_FILE}")" >/dev/null 2>&1; then
echo "Attention broker exited" >&2
cat "${LOG_FILE}" >&2 || true
exit 1
fi
echo "Waiting for attention broker..."
sleep 1
done

echo "Attention broker failed to start" >&2
cat "${LOG_FILE}" >&2 || true
exit 1
2 changes: 1 addition & 1 deletion .github/workflows/run-coverage-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
run: das-cli metta load /tmp/animals.metta

- name: Starting Attention Broker
run: das-cli attention-broker start
run: .github/scripts/start_attention_broker.sh

- name: Starting MORK Server and Load Knowledge Base
run: |-
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-unit-tests-no-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ jobs:

- name: Build production binaries
working-directory: ./src
run: ./scripts/bazel_exec.sh build --noshow_progress //:ci_binaries
run: ./scripts/bazel_exec.sh build --noshow_progress //:ci_binaries
1 change: 1 addition & 0 deletions src/agents/link_creation_agent/link_creators/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cc_library(
"//agents/query_engine:pattern_matching_query_proxy",
"//agents/query_engine:query_answer",
"//atomdb:atomdb_singleton",
"//atomdb:atomdbutils",
"//attention_broker:attention_broker_lib",
"//commons:commons_lib",
"//hasher:hasher_lib",
Expand Down
4 changes: 2 additions & 2 deletions src/agents/link_creation_agent/link_creators/LinkCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LinkCreator::AddLinkStatus LinkCreator::add_or_update_link(const vector<string>&
this->newly_created_links.push_back(handle);
if (log_new_links()) {
LOG_INFO("ADD LINK: [" + std::to_string(strength) + "] " +
new_link->metta_representation(*decoder()));
new_link->metta_representation(decoder));
}
vector<string> determiners = {handle};
determiners.insert(determiners.end(), targets.begin(), targets.end());
Expand Down Expand Up @@ -83,7 +83,7 @@ void LinkCreator::save_link_metta(shared_ptr<Link> link) {
file.open(get_log_file(), ios::app);
if (file.is_open()) {
file << link->custom_attributes.get_or<double>("strength", 1.0) << ","
<< link->metta_representation(*decoder()) << endl;
<< link->metta_representation(decoder) << endl;
file.close();
} else {
RAISE_ERROR("Couldn't open file for writing: " + get_log_file());
Expand Down
4 changes: 3 additions & 1 deletion src/agents/link_creation_agent/link_creators/LinkCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>

#include "AtomDBSingleton.h"
#include "AtomDBUtils.h"
#include "QueryAnswer.h"
#include "tags.h"

Expand Down Expand Up @@ -162,11 +163,12 @@ class LinkCreator {
vector<string> newly_created_links;

protected:
AtomDBUtils decoder;

inline void visit(const string& key) { this->_visited.insert(key); }
inline bool visited(const string& key) { return (this->_visited.find(key) != this->_visited.end()); }
inline double strength_threshold() { return this->_strength_threshold; }
inline shared_ptr<AtomDB> atomdb() { return AtomDBSingleton::get_instance(); }
inline HandleDecoder* decoder() { return static_pointer_cast<HandleDecoder>(atomdb()).get(); }
inline void add_determiners(vector<string>& entry) { this->_buffer_determiners.push_back(entry); }

AddLinkStatus add_or_update_link(const vector<string>& targets, double strength);
Expand Down
2 changes: 1 addition & 1 deletion src/agents/query_engine/query_element/Chain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ bool Chain::thread_one_step() {
}
{
#if LOG_LEVEL >= DEBUG_LEVEL
lock_guard<mutex> semaphore(this->thread_debug_mutex);
lock_guard<mutex> semaphore_debug(this->thread_debug_mutex);
#endif
lock_guard<mutex> semaphore(this->feeding_mutex);
if ((answer = dynamic_cast<QueryAnswer*>(this->input_buffer[0]->pop_query_answer())) != NULL) {
Expand Down
5 changes: 2 additions & 3 deletions src/atomdb/AtomDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <vector>

#include "AtomDBAPITypes.h"
#include "HandleDecoder.h"
#include "LinkSchema.h"
#include "Merger.h"
#include "Properties.h"
Expand All @@ -19,7 +18,7 @@ namespace atomdb {

enum class AtomDBType { RedisMongoDB, MorkDB, InMemoryDB, RemoteAtomDB, AdapterDB };

class AtomDB : public HandleDecoder {
class AtomDB {
public:
AtomDB() = default;
explicit AtomDB(const string& uid) : uid_(uid) {}
Expand Down Expand Up @@ -61,7 +60,7 @@ class AtomDB : public HandleDecoder {
virtual bool composite_type_enabled() const = 0;
virtual atomdb_api_types::ProtectionMode get_protection_mode() const = 0;

virtual shared_ptr<Atom> get_atom(const string& handle) = 0; // HandleDecoder interface
virtual shared_ptr<Atom> get_atom(const string& handle) = 0;
virtual shared_ptr<Node> get_node(const string& handle) = 0;
virtual shared_ptr<Link> get_link(const string& handle) = 0;

Expand Down
4 changes: 3 additions & 1 deletion src/atomdb/AtomDBFactory.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "AtomDBFactory.h"

#include "AdapterDB.h"
#include "AtomDBSingleton.h"
#include "InMemoryDB.h"
#include "MorkDB.h"
#include "ProtectedAtomDB.h"
Expand Down Expand Up @@ -103,6 +104,7 @@ shared_ptr<AtomDB> AtomDBFactory::create_composite_atomdb(const JsonConfig& conf
RAISE_ERROR("AtomDBFactory: adapterdb backend requires a nonempty uid");
}
auto basic_atomdb = create_basic_atomdb(atomdb_backend_config);
AtomDBSingleton::provide(basic_atomdb);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
atomdb = make_shared<AdapterDB>(config, basic_atomdb);
} else {
RAISE_ERROR("AtomDBFactory: '" + atomdb_type + "' is not a composite AtomDB type");
Expand All @@ -127,4 +129,4 @@ shared_ptr<AtomDB> AtomDBFactory::wrap_if_protected(shared_ptr<AtomDB> atomdb) {
} else {
RAISE_ERROR("AtomDBFactory::wrap_if_protected() encountered unknown protection mode");
}
}
}
4 changes: 2 additions & 2 deletions src/atomdb/AtomDBSingleton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ shared_ptr<AtomDB> AtomDBSingleton::get_instance() {
}
}

void AtomDBSingleton::provide(shared_ptr<AtomDB> atom_db) {
if (AtomDBSingleton::initialized) {
void AtomDBSingleton::provide(shared_ptr<AtomDB> atom_db, bool unit_test) {
if (AtomDBSingleton::initialized && !unit_test) {
RAISE_ERROR(
"AtomDBSingleton already initialized. AtomDBInitializer::init() should be called only "
"once.");
Expand Down
10 changes: 1 addition & 9 deletions src/atomdb/AtomDBSingleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ using namespace std;

namespace atomdb {

// -------------------------------------------------------------------------------------------------
// NOTE TO REVIEWER:
//
// This class will be replaced/integrated by/with classes already implemented in das-atom-db.
//
// I think it's pointless to make any further documentation while we don't make this integration.
// -------------------------------------------------------------------------------------------------

class AtomDBSingleton {
public:
~AtomDBSingleton() {}
Expand All @@ -27,7 +19,7 @@ class AtomDBSingleton {
*
* Fails if the singleton is already initialized.
*/
static void provide(shared_ptr<AtomDB> atom_db);
static void provide(shared_ptr<AtomDB> atom_db, bool unit_test = false);

private:
AtomDBSingleton() {}
Expand Down
Loading
Loading