Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(ci): scope GH_TOKEN to the step that needs it and guard the mongo script

Steven Enamakel0ad9d117b662
diff --git a/.github/workflows/storage-mongodb.yml b/.github/workflows/storage-mongodb.yml
index 97e80449bf..40481d85d0 100644
--- a/.github/workflows/storage-mongodb.yml
+++ b/.github/workflows/storage-mongodb.yml
@@ -72,8 +72,6 @@ concurrency:
cancel-in-progress: true
env:
- # Consumed by scripts/ci-cancel-aware.sh's cancellation watchdog.
- GH_TOKEN: ${{ github.token }}
CI_IMAGE: ghcr.io/tinyhumansai/openhuman_ci:latest
# The replica set start-mongo-replset.sh brings up (published on 27017).
# directConnection: the member advertises `localhost`, not a resolvable name.
@@ -98,6 +96,14 @@ jobs:
- name: Check out submodules
run: bash scripts/ci/checkout-submodules.sh
+ - name: Verify the replica-set script was checked out
+ run: |
+ script=vendor/tinyagents/vendor/tinystoragedrivers/.github/scripts/start-mongo-replset.sh
+ if [ ! -f "$script" ]; then
+ echo "::error::$script is missing: scripts/ci/checkout-submodules.sh did not populate vendor/tinyagents/vendor/tinystoragedrivers"
+ exit 1
+ fi
+
- name: Start a MongoDB replica set
# tinystoragedrivers' own script: GitHub service containers cannot pass
# `--replSet` to mongod, and a replica set is what lets the driver
@@ -115,6 +121,10 @@ jobs:
storage-mongodb-${{ runner.os }}-
- name: Test the storage targets and the session store with the MongoDB driver
+ env:
+ # Consumed by scripts/ci-cancel-aware.sh's cancellation watchdog;
+ # only this step needs it, not the submodule script above.
+ GH_TOKEN: ${{ github.token }}
# Runs in the CI image (toolchain, mold, system libraries) on the host
# network, so 127.0.0.1:27017 reaches the replica set above.
run: |
diff --git a/crates/openhuman-rpc/src/session_store/mod_tests.rs b/crates/openhuman-rpc/src/session_store/mod_tests.rs
index c2ac990c46..5022e54546 100644
--- a/crates/openhuman-rpc/src/session_store/mod_tests.rs
+++ b/crates/openhuman-rpc/src/session_store/mod_tests.rs
@@ -146,6 +146,27 @@ async fn the_file_backend_keeps_agents_apart() {
driver_backed_store_keeps_agents_apart(url, "file").await;
}
+/// Whether every seed host of a MongoDB URL is exactly the local machine
+/// (`localhost`, `127.0.0.1` or `::1`); a prefix match would accept
+/// `127.0.0.1.example.com`. Same rule as the root suites' helper
+/// (`tests/support/storage_drivers.rs`).
+#[cfg(feature = "storage-mongodb")]
+fn is_loopback_mongo_url(url: &str) -> bool {
+ let rest = url.split_once("://").map_or(url, |(_, rest)| rest);
+ let authority = rest.split(['/', '?']).next().unwrap_or_default();
+ let hosts = authority.rsplit_once('@').map_or(authority, |(_, h)| h);
+ !hosts.is_empty()
+ && !url.starts_with("mongodb+srv://")
+ && hosts.split(',').all(|host| {
+ let name = if let Some(v6) = host.strip_prefix('[') {
+ v6.split(']').next().unwrap_or_default()
+ } else {
+ host.rsplit_once(':').map_or(host, |(name, _)| name)
+ };
+ matches!(name, "localhost" | "127.0.0.1" | "::1")
+ })
+}
+
/// Runs against `TSD_MONGO_URL` (a throwaway local replica set, as the
/// `Storage (MongoDB)` workflow starts) in a database of its own; skipped
/// when it is unset or names a host other than this machine.
@@ -159,13 +180,7 @@ async fn the_mongodb_backend_keeps_agents_apart() {
eprintln!("skipped mongodb: TSD_MONGO_URL is not set");
return;
};
- let rest = base.split_once("://").map_or(base.as_str(), |(_, r)| r);
- let host = rest.split(['/', '?']).next().unwrap_or_default();
- let host = host.rsplit_once('@').map_or(host, |(_, h)| h);
- if !(host.starts_with("127.0.0.1")
- || host.starts_with("localhost")
- || host.starts_with("[::1]"))
- {
+ if !is_loopback_mongo_url(&base) {
eprintln!("skipped mongodb: TSD_MONGO_URL must name a local server");
return;
}
diff --git a/gitbooks/developing/architecture/storage.md b/gitbooks/developing/architecture/storage.md
index e10e53a04a..e96378475b 100644
--- a/gitbooks/developing/architecture/storage.md
+++ b/gitbooks/developing/architecture/storage.md
@@ -50,7 +50,7 @@ The host opens the configured backend before the core boots and installs it with
## Scopes
-Every record lives in a scope, and two scopes on one backend never see each other's data. A single-user install scopes by **agent id**, and a SaaS host scopes by **profile** (the tenant). `storage::scope_for_agent` and `storage::scope_for_profile` are the single mappings, and the session store uses the same ones, so every domain agrees.
+Every record lives in a scope, and two scopes on one backend never see each other's data. A single-user install scopes by **agent id**, and a SaaS host scopes by **profile** (the tenant). `storage::scope_for_agent` and `storage::scope_for_profile` are the single mappings, and the session store uses the same ones, so every domain agrees. An agent's scope is its id when that is a valid scope name, else `sha256:<hex digest of the id>` (TinyAgents' `DriverSessionStores::scope_for`). A profile's scope is `profile:<id>`, or `profile-sha256:<hex digest of the id>` when that is not a valid scope name. The prefixes keep the two kinds of key from colliding, and `local` is the literal operator scope.
`storage::current_scope()` resolves the scope of the current call from the task's tenant (`storage::scope_from(profile, agent, saas)`), in this order:
@@ -64,7 +64,7 @@ A backend decides how it enforces the scope. SQLite and the file driver keep eac
### Background work
-Background work runs under the process default context, which names no agent, and on its own would only see `local`. `storage::agents` closes the gap. Agents are known when they are live (`AgentContextRegistry`) or when an earlier process recorded their id in the `local` scope (`storage_agents`). `for_each_scope` runs a step once for `local` and once under each known agent. The cron scheduler's agent pass (`cron::scheduler::tick_live_agents`) runs each live agent's due jobs under that agent's own context, so their results are recorded in the agent's own scope. A recorded agent that is not live waits until it is live again, because its jobs need its host tools and prompt.
+Background work runs under the process default context, which names no agent, and on its own would only see `local`. `storage::agents` closes the gap. Agents are known when they are live (`AgentContextRegistry`) or when an earlier process recorded their id in the `local` scope (`storage_agents`). `for_each_scope` runs a step once for `local` and once under each known agent. The cron scheduler's agent pass (`cron::scheduler::tick_live_agents`, driven in tests through the public `cron::scheduler::run_live_agent_pass`) runs each live agent's due jobs under that agent's own context, so their results are recorded in the agent's own scope. A recorded agent that is not live waits until it is live again, because its jobs need its host tools and prompt.
On a shared backend (MongoDB) other processes may write the same records, so boot-time recovery such as the orphaned-run sweep is skipped (`storage::installed_is_shared`).