Skip to content

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

Commits on main

cb93b86
feat(turn-origin): a spawn that cannot lose the turn origin\n\n`capture`/`propagate`/`with_inherited_origin` already carry the origin across a\n`tokio::spawn`, and five sites already use them. What they do not do is make\nthe correct call shape the easy one.\n\nBoth of these compile, neither warns, and only the first works:\n\n tokio::spawn(turn_origin::propagate(work));\n tokio::spawn(async move { turn_origin::propagate(work).await });\n\n`propagate` reads the origin when it is *called*, so it has to be called on the\nspawning task. The second form captures inside the new task, where the\ntask-local is already gone; it scopes nothing, and every external-effect tool\nthe child calls is refused by the approval gate as `Unknown`. That the existing\nsites get it right rests on a hand-written comment at each one saying to\ncapture "here, on the spawning task" — correctness held up by reviewer\nattention at every future call site.\n\n`turn_origin::spawn` takes the ordering out of the caller's hands: the capture\nhappens inside, before the spawn, and no argument order can get it wrong. It\ndelegates to `propagate`, so the fail-closed guarantee is inherited rather than\nre-implemented — no ambient origin in, no origin out, and never a fabricated\none.\n\n`turn_origin::spawn_unlabelled(reason, fut)` is a plain `tokio::spawn` with a\nname. Dropping the origin is sometimes right, but a bare `tokio::spawn` looks\nthe same whether that was decided or never considered; the name and the reason\nmake the choice legible in review and greppable, and the reason rides on a\n`trace` line.\n\nNeither is adopted here. Nothing calls them, no call site changes, no origin\nlabel changes, and no behaviour changes — the labelling decision belongs to the\nowner on the linked issue.\n\nThe test that earns the change writes both forms in one scope and asserts the\nhand-written one loses the origin while the helper keeps it, so a refactor that\nreintroduces the ordering requirement fails instead of regressing quietly.\n\nRefs tinyhumansai/openhuman#5634\nRefs tinyhumansai/openhuman#5746\n
M3gA-Mind committed 3 months ago
283bfbe
fix(app_state): back off the current-user fetch when the backend is unreachable\n\n`fetch_current_user_cached` cached successes and nothing else. The `?` on the\nfetch returned early, so the cache write below it never ran on failure, and on a\ntimeout the whole future was dropped mid-flight before it could run at all. The\nclient therefore kept no memory that the backend had just failed.\n\nThe cost of that is arithmetic rather than bad luck. The frontend polls\n`app_state_snapshot` about every 5s, the caller wraps each attempt in a 5s\n`AUTH_FETCH_TIMEOUT`, and the positive-cache TTL is also 5s — equal to the\ntimeout, so an attempt that times out can never be deduped by the cache that\nfollows it. While the backend is unreachable essentially every poll re-attempts\nthe fetch and re-pays the full five seconds, which is what 51 timeouts in one\nsession looks like.\n\nAdd a negative counterpart to `CURRENT_USER_CACHE`: the last availability\nfailure, keyed on `(api_base, token)` exactly as the positive cache is, with a\nwindow that doubles from 10s and saturates at 60s. Inside that window the fetch\nreplays the recorded error instead of going to the network, so the caller\nreaches its existing stored-snapshot fallback in microseconds rather than five\nseconds. The caller itself is unchanged.\n\nThree details are load-bearing:\n\n- The timeout is applied by the caller, around the whole of\n `fetch_current_user_cached`, so recording only on that function's error path\n would miss the case this issue is actually about. The two timeout arms record\n too.\n- An auth rejection is never recorded. It is the backend answering, in time,\n that the token is no good; it drives the deferred-session cleanup at the\n snapshot caller, and replaying it from a cache would delay that cleanup or\n hand the caller a variant the backend never produced.\n- The record is cleared on every success and on sign-out. A record outliving\n its cause is the failure mode that matters here — it would strand the app on\n the stored snapshot after the backend had already recovered.\n\nThe first backoff step is deliberately larger than both the fetch timeout and\nthe poll interval; a shorter one would let the next poll find the window already\nclosed and pay the timeout again, which is the bug rather than the fix. A test\npins that relationship.\n\nEight tests cover the window, the key, the rejection carve-out, the clear, and\nthe widening. One of them drives `fetch_current_user_cached` itself against a\nclosed loopback port: with the probe removed it returns\n`request failed: error sending request for url (http://127.0.0.1:9/auth/me)`\ninstead of the seeded marker, which is the same error string this issue reports.\n
M3gA-Mind committed 3 months ago
0f72eb9
refactor(memory): finish the preference migration, and stop naming the engine for its re-exports\n\nTwo more engine references shed per file the ratchet tracks, and its\nstale-entry check drove both deletions.\n\nThe host preferences module has existed since the guard rewrite and its own\ndocs say the engine copy was never the engine's — but three session call\nsites (two in turn/context.rs, one in turn/core.rs) still called\n`tinymemory_core::preferences`. They now use session-handle twins\n(`load_general_preferences_on`, `recall_situational_preferences_on`) added\nbeside the guard-shaped originals: the agent session binds its memory once\nand threads the `Arc<dyn Memory>` through the turn, and resolving a guard\nambiently there could disagree with the handle the session actually writes\nthrough. `Memory` is the contract trait (`tinymemory_core::traits` is a\nre-export of `tinymemory_api`), and `recall_relevant_by_vector` is a\ncontract-trait method, so both twins are engine-neutral.\n\nOne deliberate behaviour alignment: the general loader uses the host\nmodule's blank-skip rule — the budget is spent only on kept values — where\nthe engine's `take(limit)`-first order let a single blank newest entry\nstarve the prompt block of a real preference one row behind it. The host\nmodule documents that rule as the fix; the migrated callers now get it too.\n\nThe `memory::*` alias surface stops naming the engine for the trait and its\nvalue types: `tinymemory_core::traits` re-exports the contract's items, so\nthe alias now names `api::traits::Memory` and `api::types::*` directly.\nSame items, proven by the compiler; one fewer compile-time reason the crate\nstays in the build (#5560).\n\nRatchet: −2 files (turn/context.rs, turn/core.rs — fully off the engine);\nturn_tests' namespace constant repointed with them.\n\n
Shanu committed 3 months ago
9a554e2
fix(socket): keep the claim latched, and make the emit gate atomic\n\nTwo review findings, both correct.\n\nThe unconditional `release_call` was wrong. Every pre-existing release is on\nthe dispatch-FAILED path, where nothing happened; this one was on the\nsucceeded-but-undeliverable path, where the effect already ran. Releasing it\nmakes the backend's redelivery re-execute work that succeeded —\n`execute_send_dm` reaches `handle_tinyplace_signal_send_message` with no\n`call_id`, so a peer receives the Signal message twice, and a local-execution\n`orch:tool_call` spawns a second sub-agent. Only `persist_reply` is idempotent\n(`message_id = "reply:{call_id}"`).\n\nSo the claim stays latched, as it did before. The cost is that the redelivery\nis answered with the synthetic `duplicate/running` frame and the turn does not\ncomplete — unchanged from before this guard, so not a regression, and the\nlesser harm: a stalled turn is recoverable, a duplicate message to a person is\nnot. The suppression itself is kept, and the log becomes a `warn!` naming the\nstranded `call_id` so the stall is diagnosable rather than silent. Fixing the\nstall needs the result cached for replay, or a server-side deadline on the\ntool call; neither belongs in this change.\n\nThe check and the send were also not atomic. A handler could read a live token,\nthe socket loop could then end the generation and drain an empty channel, and\nthe handler's send would land afterwards — surviving into the next connection,\nwhich is what the guard exists to prevent. `with_live_connection` holds the\ngeneration read guard across both: `end_connection_generation` needs the write\nguard, so either the message is queued before the drain that discards it, or\nthe token is already cancelled when the handler looks.\n\nStamping a generation onto the queued frame would be the more general answer\nbut changes the channel payload for every emitter; the race is between two\noperations already serialized by an existing lock.\n
M3gA-Mind committed 3 months ago
e5d1f48
test(e2e): assert mounted memory graph canvas
Steven Enamakel committed 3 months ago
d9494a3
test(e2e): assert mounted memory graph canvas\n\n
Steven Enamakel committed 3 months ago
5ab412c
fix(socket): don't emit a hosted-brain result onto the next connection\n\nThe outbound channel outlives the connection. `emit_tx`/`emit_rx` is created\nonce per `connect()` and passed by `&mut` into every `run_connection` inside\nthe reconnect loop, so a message queued while the socket is down is not\ndropped — it is flushed onto the next socket, which has a different sid and\nwhose roster the backend has already cleared. Nobody is waiting for it there.\n\nThe three hosted-brain handlers spawn their work and emit through that channel\nwith no connection guard, so a device tool still running when the socket drops\nsends its result into a connection that never asked for it.\n\nThe second half is what makes that unrecoverable rather than merely lossy.\n`orch:tool_call` is at-least-once with server-side redelivery, guarded by a\n`call_id` claimed on entry and released only when dispatch fails. A call that\nSUCCEEDS stays latched forever — so when the result never reaches the wire,\nthe redelivery hits the latch and is answered with the synthetic\n`{"accepted": true, "status": "running", "duplicate": true}` frame instead of\nthe real result, and the brain waits on a `tool_completion` that can never\narrive. The code already names this hazard for the dispatch-failure path; it\njust did not cover the succeeded-but-undeliverable path.\n\nSo suppressing the orphaned emit alone would be worse than the bug: it would\nstrand the brain permanently rather than delivering to the wrong place. Both\nhalves are needed.\n\n- `emit_result_if_connected` gates the emit on a snapshot of the connection\n generation taken before the spawn, and releases the `call_id` when the\n result cannot be sent. Used by all three `orch:*` handlers.\n- `connection_generation()` widens from `pub(super)` to the whole `socket`\n module, matching `begin_`/`end_connection_generation` on the two lines\n below it. `event_handlers` is a sibling of `socket::medulla`, not a child.\n- `drain_pending_emits` discards whatever is still queued when a connection\n ends, covering the window between an emit and the cancellation.\n\nThe tool future is deliberately not `select!`ed against the token, unlike the\nregistration reads in `medulla::workflows`: dropping it mid-flight would\nabandon a side-effecting call with its `call_id` latched and no result, which\nis the failure being fixed. Only the emit is gated.\n\nBehaviour change: a plain `emit()` queued during a disconnect goes from\n"delivered late on the next socket" to "dropped". That is the intended\nsemantic — the backend replaces a socket's whole entry on each registration —\nbut it is a real change, and it also affects the one `emit_with_ack` caller,\nwhose waiter is already cancelled at the same point while its message sits\nqueued.\n\nCloses #5638\n
M3gA-Mind committed 3 months ago
2edaffd