Fix inline JSON being incorrectly detected as tool call

The bug was caused by mark_tool_calls_consumed() being called after
displaying each chunk, which advanced last_consumed_position to the
end of the current buffer. When the next chunk arrived with JSON,
the unchecked_buffer started at position 0 of the slice, causing
is_on_own_line() to return true (position 0 is always "on its own line").

Removed the problematic mark_tool_calls_consumed() call from the
"no tool executed" branch. The remaining call after actual tool
execution is correct and necessary.

Added integration test that verifies inline JSON in prose is not
detected as a tool call.
This commit is contained in:
Dhanji R. Prasanna
2026-01-19 14:35:01 +05:30
parent 292a3aa48d
commit 5caa101b84
4 changed files with 311 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
# Project Memory
> Updated: 2026-01-15T00:50:41Z | Size: 12.9k chars
> Updated: 2026-01-19T08:32:03Z | Size: 14.0k chars
### Remember Tool Wiring
- `crates/g3-core/src/tools/memory.rs` [0..5000] - `execute_remember()`, `get_memory_path()`, `merge_memory()`
@@ -229,4 +229,27 @@ Injects agent+language-specific guidance when running in agent mode in a workspa
To add a new agent+lang prompt:
1. Create `prompts/langs/<agent>.<lang>.md`
2. Add entry to `AGENT_LANGUAGE_PROMPTS` in `language_prompts.rs` with `include_str!`
2. Add entry to `AGENT_LANGUAGE_PROMPTS` in `language_prompts.rs` with `include_str!`
### MockProvider for Testing
Configurable mock LLM provider for integration testing without real API calls.
- `crates/g3-providers/src/mock.rs`
- `MockProvider` [220..320] - mock provider with response queue, request tracking
- `MockResponse` [35..200] - configurable response with chunks and usage
- `MockChunk` [45..100] - individual streaming chunk (content, finished, tool_calls)
- `scenarios` module [410..480] - preset scenarios: `text_only_response()`, `multi_turn()`, `tool_then_response()`
- `crates/g3-core/tests/mock_provider_integration_test.rs`
- `test_butler_bug_scenario()` - reproduces consecutive user messages bug
- `test_text_only_response_saves_to_context()` - verifies text responses saved
- `test_multi_turn_text_only_maintains_alternation()` - verifies user/assistant alternation
Usage pattern:
```rust
let provider = MockProvider::new()
.with_response(MockResponse::text("Hello!"));
let mut registry = ProviderRegistry::new();
registry.register(provider);
let agent = Agent::new_for_test(config, NullUiWriter, registry).await?;
```