Skip to content

feat(memory): take the memory block render off the turn's critical path - #708

Merged
senamakel merged 1 commit into
epic/712-tool-tokensfrom
epic-712-oh707-memory-block
Nov 7, 2026
Merged

senamakel merged 1 commit into
epic/712-tool-tokensfrom
epic-712-oh707-memory-block

Conversation

@senamakel

Copy link
Copy Markdown
Owner

Closes #707
Part of tinyhumansai/chottu-core#712

What changed

  • Where the ~6 s goes (found by reading the code, not timed against production). engine::resolve is already cached per config fingerprint and does no I/O for Chottu's bound (host or registered) engine, so it is not the cost. What is left is two sequential network round trips to the hosted engine, beliefs then list, each seconds long. They are now read concurrently (memory/lifecycle/memory_block.rs), which pays the latency once. A per-step breakdown is logged at debug as [memory_block] read resolve_ms beliefs_ms list_ms, and [memory_block] rendered|empty|error now carry elapsed_ms. The remaining latency is the engine's own (the same slowness behind [memory:prefetch] automatic refresh timed out); that belongs in tinymemory/CortexDB and is not filed from here.
  • Deadline with deferral. New [memory] memory_block_deadline_ms (default unset, behaviour unchanged). A generation start waits that long for the render. When it lapses the turn keeps the recorded block (a cold thread sends none), logs [memory_block] deferred, and the render finishes in the background (under the session's core context) into a process-wide store (runtime_session/memory_block_ready.rs, keyed by workspace, memory identity and token budget; taken once, 1 h max age, 256 entries). The next generation start takes it ([memory_block] ready), so the current generation's prefix is never changed mid-turn.
  • Prewarm seam. OpenHumanSessionHost::prewarm_memory_block() -> MemoryBlockPrewarm and, for embedders, Agent::prewarm_memory_block(thread_id). MemoryBinding::memory_block_deadline(Duration) maps onto the config key.
  • Not done: turn-setup timing event. Skipped by agreement with the coordinator; chottu-core#69 will handle it. TurnObservation lives in tinyagents, so it needs a separate leaf.

Gates (inside vendor/openhuman; the package is openhuman, openhuman-core is the binary in openhuman-cli)

  • cargo fmt --all -- --check: pass
  • cargo test -p openhuman --lib memory_block: 37 passed (existing memory_block_tests.rs unchanged and passing; new: memory_block_render_respects_deadline, deferred_memory_block_is_used_next_generation, prewarmed_memory_block_skips_render_on_turn, concurrency, store tests)
  • cargo test -p openhuman --lib config::schema::memory: 19 passed; cargo test -p openhuman-embed --lib spec: 11 passed
  • cargo clippy -p openhuman-embed --all-targets -- -D warnings: pass
  • cargo clippy -p openhuman --all-targets -- -D warnings: fails on 23 pre-existing lints in unrelated files (e.g. scheduler_host_agent_tests.rs, security/egress/privacy.rs); none in changed files
  • cargo test -p openhuman-embed --test memory_block and --test runtime_agents: fail identically with and without this change (the runtime does not build in this environment), so the one added assertion in runtime_agents.rs (deadline reaches config().memory) was not run.
  • Changed-line coverage gate not run locally.

Read beliefs and learnings concurrently, log elapsed_ms for each render,
bound a generation start's wait with [memory] memory_block_deadline_ms
(deferred renders land in a process-wide store taken by the next
generation start), and add OpenHumanSessionHost::prewarm_memory_block and
embed Agent::prewarm_memory_block plus MemoryBinding::memory_block_deadline.

Co-authored-by: Medulla <medulla@tinyhumans.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant