Skip to content

perf(core): box async fns compiled into several distinct copies - #7159

Merged
senamakel merged 4 commits into
tinyhumansai:mainfrom
senamakel:box-async-fns
Oct 9, 2026
Merged

senamakel merged 4 commits into
tinyhumansai:mainfrom
senamakel:box-async-fns

Conversation

@senamakel

@senamakel senamakel commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Problem

An async fn body is re-instantiated in every crate / codegen unit that awaits it. These four are large and awaited from several places (core CGUs, openhuman-rpc, -embed, -tinyhumans), so each leaves several copies that mold --icf=safe cannot fold.

Solution

Boxed at the nearest fn that callers await, so one copy is compiled in the core crate:

  • fetch_connected_integrations_uncached (integrations/composio/connected_integrations/fetch_uncached.rs)
  • ApprovalGate::intercept_audited_inner (security/approval/gate_intercept.rs; body now intercept_audited_inner_body)
  • run_flow_body (flows/ops/execution.rs; 'static, all params owned)
  • run_turn_via_tinyagents_inner (agent/tinyagents/turn_runner.rs; body now run_turn_via_tinyagents_body). The boxed wrapper lives in a new turn_runner_boxed.rs because turn_runner.rs would otherwise exceed the 750-line layout limit. Both run_turn_via_tinyagents_shared and run_root_turn_via_hosted_agent go through it.

None skipped; all futures are Send.

Measurement (release, strip=false, product features; per-fn numbers are distinct addresses of <fn>::{{closure}} text symbols in the mold --icf=safe relink, excluding drop_in_place):

fn before after
fetch_connected_integrations_uncached 4 copies, 140.1 KiB (max 49.9) 1 copy, 50.6 KiB
intercept_audited_inner 4 copies, 110.0 KiB (max 27.5) 1 copy, 28.2 KiB
run_flow_body 3 copies, 78.1 KiB (max 30.7) 1 copy, 20.0 KiB
run_turn_via_tinyagents_inner 2 copies, 129.1 KiB (max 70.7) 1 copy, 58.4 KiB

.text (cargo-bloat text-section-size): 81,029,408 -> 79,874,528 B.

Submission Checklist

  • Tests added or updated: N/A, mechanical wrapper change with no behavior change; covered by existing suites
  • Diff coverage >= 80%: N/A, wrappers are exercised by the existing tests of the wrapped fns
  • Coverage matrix updated: N/A: behaviour-only change
  • Affected feature IDs listed: N/A
  • No new external network dependencies introduced: yes, none
  • Manual smoke checklist updated: N/A
  • Linked issue closed: N/A

Impact

  • Binary size / compile output only: about 1.1 MiB less .text. One extra heap allocation per call of these (already coarse-grained, long-running) fns.

Related


AI Authored PR Metadata

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: box-async-fns
  • Commit SHA: 8c6d95c

Validation Run

  • pnpm --filter openhuman-app format:check: N/A (no frontend change)
  • pnpm typecheck: N/A
  • Focused tests: full RUST_MIN_STACK=16777216 scripts/ci-cancel-aware.sh cargo test -p openhuman --lib --no-default-features --features <product>: 8684 passed, 1 failed (mcp::registry::tools::tests::list_tools_errors_for_unconnected_server, order-dependent; passes in isolation, unrelated to this change)
  • Rust fmt/check: rustfmt --edition 2021 on changed files; clippy on core with product features (--all-targets) clean except the pre-existing voice/live/ws_tests.rs unused-import warnings; cargo check OK for openhuman-cli --tests (product features), openhuman-embed --tests --features inference,mcp,skills, and crates/openhuman-app/Cargo.toml; node scripts/ci/check-openhuman-rust-layout.mjs passes; node scripts/ci/check-agent-runtime-boundary.mjs passes
  • Tauri fmt/check: covered by the app manifest cargo check above

Validation Blocked

  • command: N/A
  • error: N/A
  • impact: N/A

Behavior Changes

  • Intended behavior change: none
  • User-visible effect: none

Parity Contract

  • Legacy behavior preserved: yes, same params, same output, same .await call sites
  • Guard/fallback/dispatch parity checks: bodies untouched

Duplicate / Superseded PR Handling

  • Duplicate PR(s): none
  • Canonical PR: this
  • Resolution: N/A

Summary by CodeRabbit

  • Refactor
    • Updated internal processing for agent turns, flows, connected integrations, and approval checks. Existing behavior and results remain unchanged, so no user-facing functionality has changed.

senamakel and others added 4 commits October 9, 2026 06:54
Adds a fetch path that bypasses the cache when retrieving connected
Composio integrations, so callers can force a fresh read when cached
data may be stale.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Several large async functions were being re-instantiated in every crate or codegen unit that awaited them, bloating compile times and binary size. Each is now wrapped in an #[inline(never)] function that returns a boxed future, so the state machine is compiled once in its defining crate.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
The Ok arm of the active workspace snapshot match now builds its tuple on a single line instead of a block, with no change in behaviour.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
The boxed wrapper and body of the tinyagents turn runner now live in a
dedicated turn_runner_boxed module, with the body made visible to its
parent so the existing call sites keep working. This isolates the large
async state machine in one compilation unit without changing behaviour.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
@tinysweeper

tinysweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

Tiny Sweeper reviewed this change across 6 lane(s) and found 0 active actionable finding(s). Detailed lane evidence and any incomplete work are listed below.

State: Reviewing pending checks
Priority: low
Reviewed head: 8c6d95cabe72
Updated: 1791520000 (Unix time)

Review snapshot

Change surface Files Review signal Count
Production 6 Active findings 0
Tests 0 Noted findings 0
Documentation 0 Resolved findings 0
Configuration 0 Pending checks/questions 4

Completeness: Complete
Test assessment: No supported feature-to-test mapping was available; this does not mean tests are absent or passed.

What changed

The review could not produce a supported behavioral summary; inspect the cited changed surface and lane details below.

Features

None identified with supported citations.

Tests

No supported feature-to-test mapping was produced. Test execution is not inferred.

Findings

No active actionable findings.

Pending checks: Rust E2E (mock backend), Build Playwright E2E Artifact, E2E (Playwright / web lane), Desktop E2E (full suite, 3 OS)

Before merge

  • Wait for Rust E2E (mock backend), Build Playwright E2E Artifact, E2E (Playwright / web lane), Desktop E2E (full suite, 3 OS).

How this fits together

flowchart LR
  n0["notify_pending_approval"]:::impacted
  n1["format"]:::impacted
  n2["assemble_turn_harness"]:::impacted
  n3["run_flow_body"]:::impacted
  n4["fetch_connected_integrations_uncached"]:::impacted
  n5["run_turn_via_tinyagents_shared"]:::impacted
  n0 -->|calls| n1
  n2 -->|calls| n1
  n3 -->|calls| n0
  n3 -->|calls| n1
  n4 -->|calls| n1
  n5 -->|calls| n1
  classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
  classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
  classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
  classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Loading
Agent review details

critique

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: Reviewed 6 files; 0 findings. _Code retrieval was unavailable (model: ladder embeddings returned 400 Bad Request: {"error":{"message":"unknown ladder vectors; known ladders are flash (also chat-v1, flash-v1), instant (also no-think, instant-v1), reasoning (also deepseek), max-reasoning (also max-reasoning-v1), deepseek-flash (also reasoning-v1, agentic-v1), deep (also luna), scribe, uncensored, vectors-oai3 (also embeddings-oai3-v1), vision (also vision-v1, multimodal-v1), image (also images-v1, image-v1), vi), so this review saw the diff alone._ _Memory was unavailable (model: cortex: v1/recall: error sending request for url (http://cortexdb:3141/v1/recall\)\), so this review ran without it._

security

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: Reviewed 6 files; 0 findings. _Code retrieval was unavailable (model: ladder embeddings returned 400 Bad Request: {"error":{"message":"unknown ladder vectors; known ladders are flash (also chat-v1, flash-v1), instant (also no-think, instant-v1), reasoning (also deepseek), max-reasoning (also max-reasoning-v1), deepseek-flash (also reasoning-v1, agentic-v1), deep (also luna), scribe, uncensored, vectors-oai3 (also embeddings-oai3-v1), vision (also vision-v1, multimodal-v1), image (also images-v1, image-v1), vi), so this review saw the diff alone._ _Memory was unavailable (model: cortex: v1/recall: error sending request for url (http://cortexdb:3141/v1/recall\)\), so this review ran without it._

tests

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: This is a pure compile-size refactor: four large async fns are boxed behind #[inline(never)] wrappers with bodies unchanged, plus a formatting fix. No behaviour changed, so no tests are needed; the only defect is a stale doc reference left by the rename. Safe to merge. _Code retrieval was unavailable (model: ladder embeddings returned 400 Bad Request: {"error":{"message":"unknown ladder vectors; known ladders are flash (also chat-v1, flash-v1), instant (also no-think, instant-v1), reasoning (also deepseek), max-reasoning (also max-reasoning-v1), deepseek-flash (also reasoning-v1, agentic-v1), deep (also luna), scribe, uncensored, vectors-oai3 (also embeddings-oai3-v1), vision (also vision-v1, multimodal-v1), image (also images-v1, image-v1), vi), so this review saw the diff alone._ _Memory was unavailable (model: cortex: v1/recall: error sending request for url (http://cortexdb:3141/v1/recall\)\), so this review ran without it._

commits

  • Conclusion: Neutral
  • Scope reviewed: all assigned evidence
  • Lane summary: Nothing sensitive found in what this pull request commits.

description

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: The description accurately matches the diff: all four boxed async-fn wrappers are present as described, including the new turn_runner_boxed.rs module and the renamed bodies, and the mechanical changes are consistent with the stated no-behavior-change claim. Looks safe to merge. _Code retrieval was unavailable (model: ladder embeddings returned 400 Bad Request: {"error":{"message":"unknown ladder vectors; known ladders are flash (also chat-v1, flash-v1), instant (also no-think, instant-v1), reasoning (also deepseek), max-reasoning (also max-reasoning-v1), deepseek-flash (also reasoning-v1, agentic-v1), deep (also luna), scribe, uncensored, vectors-oai3 (also embeddings-oai3-v1), vision (also vision-v1, multimodal-v1), image (also images-v1, image-v1), vi), so this review saw the diff alone._ _Memory was unavailable (model: cortex: v1/recall: error sending request for url (http://cortexdb:3141/v1/recall\)\), so this review ran without it._

e2e

  • Conclusion: Neutral
  • Scope reviewed: all assigned evidence
  • Lane summary: This change is a pure internal refactor: it wraps existing async bodies in boxed, #[inline(never)] futures (plus a file split to satisfy the layout limit) with no external surface change. Existing e2e suites that already drive agent turns, flow runs, and approval interception exercise the same paths, and the pending CI jobs run them; nothing here needs a new end-to-end test and the change looks sound. Waiting on end-to-end jobs: `Rust E2E (mock backend)`, `Build Playwright E2E Artifact`, `E2E (Playwright / web lane)`, `Desktop E2E (full suite, 3 OS)`.
  • Unresolved questions/checks: Rust E2E (mock backend), Build Playwright E2E Artifact, E2E (Playwright / web lane), Desktop E2E (full suite, 3 OS)
Evidence and run details
  • Models: gpt-5.6-luna, glm-5.3-flash
  • Spend: $0.007416
  • Tokens: 157096 input · 8383 output · 15480 cached · 0 embedding
Head State Pass summary
8c6d95cabe72 pending 0 active finding(s), 0 resolved finding(s) (at 1791520000)

tinysweeper 0.1.0

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T04:28:33.810587Z 8c6d95c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 82e6339c-3ff2-422e-bff6-43751fef268d
📥 Commits

Reviewing files that changed from the base of the PR and between eac4579 and 8c6d95c.

📒 Files selected for processing (6)
  • crates/openhuman-core/src/agent/tinyagents/mod.rs
  • crates/openhuman-core/src/agent/tinyagents/turn_runner.rs
  • crates/openhuman-core/src/agent/tinyagents/turn_runner_boxed.rs
  • crates/openhuman-core/src/flows/ops/execution.rs
  • crates/openhuman-core/src/integrations/composio/connected_integrations/fetch_uncached.rs
  • crates/openhuman-core/src/security/approval/gate_intercept.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

Four async entry points now return boxed futures and delegate their existing work to async implementation functions. The tinyagents module adds the wrapper module, and the workspace-resolution match arm is reformatted without a behavior change.

Changes

Boxed future boundaries

Layer / File(s) Summary
Tinyagents turn wrapper
crates/openhuman-core/src/agent/tinyagents/...
The turn implementation is renamed and made visible to its sibling module. A wrapper returns its result as a boxed future and forwards the inputs to that implementation.
Flow execution wrapper
crates/openhuman-core/src/flows/ops/execution.rs
run_flow_body now returns a boxed 'static future and delegates to the async run_flow_body_inner.
Integration and approval wrappers
crates/openhuman-core/src/integrations/composio/connected_integrations/fetch_uncached.rs, crates/openhuman-core/src/security/approval/gate_intercept.rs
The fetch and approval interception functions now return boxed futures and delegate to async inner functions. The workspace-resolution match arm is reformatted without a behavior change.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: m3ga-mind

Merge Risk

Merge Risk: ⚪ Minimal · up to 8c6d9

The boxed entry points preserve the described behavior, with no identified issue requiring a fix before merge.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to 8c6d9

The changes preserve existing callers, authority inputs, approval controls, and cancellation handling. No material security risk introduced or worsened by this PR was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The affected paths retain their existing access to turn tools and hosted capabilities, flow state, pending approval records, and configured integration routes. The wrappers add no observed external caller, credential source, tenant selector, or privilege grant, so the effective exposure of these paths is not expanded by this PR.

Trust Boundaries and Controls

  • observed — Approval interception preserves origin checks, forced-call handling, waiter registration before persistence, and persistence before notification. Decision, timeout, bounded abandonment, and cancellation teardown remain in the unchanged body. Bounded abandonment intentionally leaves the durable approval row open while removing in-memory routing; this behavior predates the PR.
  • observed — Integration fetching still resolves the configured backend or direct route and returns unavailable when route resolution fails. Its consumer retains the local-session credential exclusion, avoids caching unavailable results, and checks the invalidation generation under the cache write lock before insertion. These identity and concurrency controls are unchanged.

Resilience and Maintainability Implications

  • observed — Flow cancellation ownership is still registered before the run is published, and the guard is forwarded unchanged. The body retains failure and timeout settlement, cancellation checkpoint cleanup, approval-resume graph correlation, and terminal-row writes. Its row finalizer remains armed before the first await and reconciles interruption on drop unless disarmed after settlement.
  • observed — Turn execution retains body-owned terminal signaling, steering-forwarder drop cleanup, error mapping, and outcome finalization. Boxing introduces no alternate completion or cleanup path.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: boxing async functions in the core crate to reduce duplicate compilation.
Docstring Coverage Passed Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 6 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit hops where futures flow,
In tidy boxes, off they go.
The turn and flow keep tasks in sight,
Fetch and approval join the flight.
My paws applaud this async night.

Comment @coderabbitai help to get the list of available commands.

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tinysweeper found nothing blocking. Approving.

             $0.0074 · 157,096 in / 8,383 out · 15,480 cached (10%) · gpt-5.6-luna, glm-5.3-flash
critique:    $0.0037 · 62,840 in  / 4,231 out · 8,228 cached (13%)  · gpt-5.6-luna
security:    $0.0035 · 67,857 in  / 2,380 out · 7,252 cached (11%)  · gpt-5.6-luna
tests:       $0.0001 · 6,612 in   / 507 out   · 0 cached (0%)       · glm-5.3-flash
description: $0.0001 · 7,163 in   / 198 out   · 0 cached (0%)       · glm-5.3-flash
e2e:         $0.0001 · 7,480 in   / 131 out   · 0 cached (0%)       · glm-5.3-flash

@tinysweeper tinysweeper Bot added the priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect. label Oct 9, 2026
@senamakel
senamakel merged commit 69187d2 into tinyhumansai:main Oct 9, 2026
25 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant