Skip to content

fix(agent): skip super context for context-free first turns#4403

Open
YOMXXX wants to merge 4 commits into
tinyhumansai:mainfrom
YOMXXX:fix/GH-4361-tool-mismapping
Open

fix(agent): skip super context for context-free first turns#4403
YOMXXX wants to merge 4 commits into
tinyhumansai:mainfrom
YOMXXX:fix/GH-4361-tool-mismapping

Conversation

@YOMXXX

@YOMXXX YOMXXX commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Skip the first-turn super-context graph node for obvious context-free greetings such as Ciao and hello!.
  • Skip super context for simple local folder/directory creation requests that do not reference prior context or integrations.
  • Preserve super context for first-turn requests that include context hints, attachments, or prior-discussion cues.
  • Keep the gate in the orchestrator-only first-turn path, now wired to the tinyagents SuperContextMiddleware graph node.

Problem

Solution

  • Add super_context_skip_reason() as a pure gate helper for greetings and simple local folder/directory creation prompts.
  • Extend should_run_super_context() to require that no skip reason applies.
  • Log the skip reason when the base first-turn orchestrator gate matches but the prompt is context-free.
  • Update unit coverage for greetings, simple local folder creation, and context-hinted local actions.

Submission Checklist

  • Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
  • Diff coverage ≥ 80% — changed lines (Vitest + cargo-llvm-cov merged via diff-cover) meet the gate enforced by .github/workflows/pr-ci.yml. CI coverage gate will enforce this PR; focused Rust tests were run locally.
  • N/A: Coverage matrix updated — behavior-only agent gate change, no feature row added/removed/renamed.
  • N/A: All affected feature IDs from the matrix are listed in the PR description under ## Related — no matrix feature row applies.
  • No new external network dependencies introduced (mock backend used per Testing Strategy)
  • N/A: Manual smoke checklist updated if this touches release-cut surfaces — no release smoke surface changed.
  • Linked issue closed via Closes #NNN in the ## Related section

Impact

  • Runtime impact is limited to orchestrator first-turn chat gating.
  • Reduces unnecessary context-scout/tool activity for context-free first turns.
  • Keeps existing super-context behavior for requests that likely benefit from prior context, memory, attachments, or integrations.
  • No persistence, migration, frontend, or external network changes.

Related


AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

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

Commit & Branch

  • Branch: fix/GH-4361-tool-mismapping
  • Commit SHA: 673b72837

Validation Run

  • N/A: pnpm --filter openhuman-app format:check — Rust-only change.
  • N/A: pnpm typecheck — Rust-only change.
  • Focused tests: GGML_NATIVE=OFF cargo test --manifest-path Cargo.toml --lib super_context_gate_tests -- --nocapture (pre-merge: 11 passed; after upstream merge: 10 passed)
  • Rust fmt/check (if changed): cargo fmt --all -- --check; git diff --check; GGML_NATIVE=OFF cargo check --manifest-path Cargo.toml
  • N/A: Tauri fmt/check (if changed) — no Tauri changes.

Validation Blocked

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

Behavior Changes

  • Intended behavior change: context-free first-turn greetings and simple local folder/directory creation no longer install the super-context graph node.
  • User-visible effect: fewer unrelated scout/tool/integration suggestions before handling trivial first-turn prompts.

Parity Contract

  • Legacy behavior preserved: super context still runs for first-turn orchestrator prompts that can benefit from prior context.
  • Guard/fallback/dispatch parity checks: non-orchestrator, later turns, cold resumed threads, attachment-first new threads, greetings, simple local folder creation, and context-hinted local actions covered by super_context_gate_tests.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): N/A
  • Canonical PR: this PR
  • Resolution (closed/superseded/updated): N/A

Summary by CodeRabbit

  • Bug Fixes
    • Improved first-turn behavior by avoiding unnecessary extra context loading when the user message is effectively empty, a simple greeting/thanks/acknowledgement, or a basic local folder/file request without supporting context.
    • Preserved enhanced context handling for messages that reference earlier discussion or include clear app/tool-related intent.
    • Refined behavior for resumed conversations and attachment-led starts so context usage is more consistent and predictable.

@YOMXXX YOMXXX requested a review from a team July 2, 2026 09:52
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 769c28b3-afb4-4780-836e-aaf8085fceaf

📥 Commits

Reviewing files that changed from the base of the PR and between 0781ebd and 063a8ed.

📒 Files selected for processing (1)
  • src/openhuman/agent/harness/session/turn/core.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openhuman/agent/harness/session/turn/core.rs

📝 Walkthrough

Walkthrough

Adds message-based skip logic for super context, threads it through the turn gate, and updates unit tests for greeting, attachment-first, and local folder creation cases.

Changes

Super Context Gating

Layer / File(s) Summary
Skip reason classification and gate signature
src/openhuman/agent/harness/session/turn/core.rs
Adds super_context_skip_reason(user_message) to classify empty, greeting, and simple local folder creation messages; updates should_run_super_context to accept user_message and consult the skip reason.
Turn logic wiring
src/openhuman/agent/harness/session/turn/core.rs
Agent::turn() computes the skip reason, logs it when the base gate holds, and passes user_message into should_run_super_context for the runtime decision.
Gate test updates
src/openhuman/agent/harness/session/turn/core.rs
Updates the gate tests to the new signature and adds coverage for greeting skipping, cold-resumed thread skipping, attachment-first behavior, and contextual-hint folder creation.

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

Suggested labels: agent, bug

Suggested reviewers: M3gA-Mind

Poem

A tiny hello drifts through the gate,
The rabbit checks if it should wait.
For folders plain, with no clue in sight,
It hops away and keeps things light.
But if the hints are old and near,
Super context leaps back here. 🐇

🚥 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 accurately summarizes the main change: skipping super context on context-free first turns.
Linked Issues check ✅ Passed The PR addresses the reported regression by gating super context for greetings and simple local actions, matching the issue's core fix.
Out of Scope Changes check ✅ Passed The changes stay focused on first-turn super-context gating and related tests, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot added agent Built-in agents, prompts, orchestration, and agent runtime in src/openhuman/agent/. bug labels Jul 2, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/openhuman/agent/harness/session/turn/core.rs (1)

87-119: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Prefix-only matching misses common phrasings of folder-creation requests.

starts_with on the literal action phrases (e.g. "create a folder ") only catches messages that begin exactly with the command. Realistic first-turn prompts like "please create a folder for…" or "can you make a directory named…" won't match, so the skip won't apply and super context still runs — undercutting the PR's stated goal of skipping "simple local folder/directory creation requests" for such phrasings. This degrades gracefully (extra scout run, not an incorrect skip), so it's a coverage gap rather than a correctness bug.

Consider stripping a small set of common leading filler words/phrases ("please", "can you", "could you", "hey") before the starts_with check, or switching to a light keyword+position heuristic, to broaden coverage.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/agent/harness/session/turn/core.rs` around lines 87 - 119, The
simple local filesystem detection in core.rs only matches folder-creation
phrases at the very start of the normalized input, so common requests with
leading filler like “please” or “can you” are missed. Update the logic around
starts_like_local_folder_action to handle a small set of leading polite phrases
before checking the existing prefixes, or replace the strict starts_with gate
with a lightweight keyword/position heuristic. Keep the current context_hints
filter and simple_local_filesystem_action return path intact so the broader
behavior remains the same.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openhuman/agent/harness/session/turn/core.rs`:
- Around line 688-699: The super-context gating logic is duplicated in
core::agent_loop between the logging block and should_run_super_context, so
extract and reuse a shared helper or the existing classifier result to keep the
base gate consistent. Update the super_context_base_gate check to derive from
the same logic used by should_run_super_context, and rename the local
super_context_skip_reason binding in the same scope to avoid shadowing the
super_context_skip_reason function and reduce confusion.

---

Nitpick comments:
In `@src/openhuman/agent/harness/session/turn/core.rs`:
- Around line 87-119: The simple local filesystem detection in core.rs only
matches folder-creation phrases at the very start of the normalized input, so
common requests with leading filler like “please” or “can you” are missed.
Update the logic around starts_like_local_folder_action to handle a small set of
leading polite phrases before checking the existing prefixes, or replace the
strict starts_with gate with a lightweight keyword/position heuristic. Keep the
current context_hints filter and simple_local_filesystem_action return path
intact so the broader behavior remains the same.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6b40c172-52fb-4f38-b908-0533f4604cf8

📥 Commits

Reviewing files that changed from the base of the PR and between 734ee1a and 673b728.

📒 Files selected for processing (1)
  • src/openhuman/agent/harness/session/turn/core.rs

Comment thread src/openhuman/agent/harness/session/turn/core.rs Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Built-in agents, prompts, orchestration, and agent runtime in src/openhuman/agent/. bug

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

[Bug][Regression] v0.58.0 beta: Agent stuck in tool mis-mapping loop and triggering unrelated connections (Calendar)

1 participant