Skip to content

fix(claude-code): remove incorrect agent_visible filter on user message#7931

Merged
codefromthecrypt merged 2 commits intomainfrom
fix/claude-code-empty-message-7930
Mar 16, 2026
Merged

fix(claude-code): remove incorrect agent_visible filter on user message#7931
codefromthecrypt merged 2 commits intomainfrom
fix/claude-code-empty-message-7930

Conversation

@blackgirlbytes
Copy link
Contributor

@blackgirlbytes blackgirlbytes commented Mar 16, 2026

Summary

Fixes #7930 - Claude Code provider silently drops user messages in CLI

Reported in Discord by community member https://discord.com/channels/1287729918100246654/1287729920319033345/1483114312720584794

Problem

The last_user_content_blocks function finds the last user message to send to Claude Code CLI, but then incorrectly filters it by is_agent_visible(). Since we explicitly selected this message to send, the visibility filter should not apply.

When a message has agent_visible: false in its metadata, the filter removes it entirely, resulting in empty content being sent to Claude. This causes the CLI to appear to hang with no response.

Root Cause

This was introduced in commit 4abf91e (PR #7108, Feb 10, 2026) when refactoring from messages_to_content_blocks to last_user_content_blocks. The original function iterated over all messages (where filtering made sense), but the new function only processes the single last user message - the filter was incorrectly preserved.

Fix

Remove the .filter(|m| m.is_agent_visible()) since we explicitly want to send the user's input regardless of visibility metadata.

Testing

  • Existing tests pass
  • The fix is a one-line change with clear semantics

@blackgirlbytes
Copy link
Contributor Author

/goose review this PR . Tell me if there's any issues you found in this change.

@blackgirlbytes blackgirlbytes requested review from DOsinga and codefromthecrypt and removed request for codefromthecrypt March 16, 2026 16:20
@github-actions
Copy link
Contributor

Summary: This PR removes a redundant is_agent_visible() filter from last_user_content_blocks in the Claude Code provider. The change is correct - filtering a single explicitly-selected message makes no semantic sense. However, the impact described in the PR may be overstated since upstream code already filters messages before they reach this point.

✅ Highlights

  1. Correct fix for a logic error (claude_code.rs:286): The original code first finds the last user message, then filters it by visibility - which effectively discards it if agent_visible: false. Since the function explicitly selects this message to send, the filter should not apply.

  2. Minimal, surgical change: Single-line removal that correctly addresses the issue without collateral changes.

🟢 Suggestions

  1. PR description accuracy (LOW confidence):

    The PR claims this bug causes "CLI to appear to hang with no response." However, I traced the code path and found that stream_response_from_provider in reply_parts.rs (line ~25) already filters messages to only agent-visible ones before passing them to any provider:

    let filtered_messages: Vec<Message> = messages
        .iter()
        .filter(|m| m.is_agent_visible())  // Already filtered here
        .map(|m| m.agent_visible_content())
        .collect();

    This means in normal execution, non-visible messages would never reach last_user_content_blocks. The fix is still correct (removes dead code that's semantically wrong), but the described bug scenario may not occur in practice through the normal agent flow. The issue could only manifest through:

    • Direct unit tests
    • Future code paths that bypass stream_response_from_provider

    Consider adjusting the PR description to reflect this is primarily a code clarity/correctness fix rather than a critical bug fix.

  2. Consider adding a test case (optional):

    The existing test_last_user_content_blocks test cases don't include a message with agent_visible: false. Consider adding a test to prevent regression:

    #[test_case(
        vec![Message::user().with_text("Hello").user_only()],
        &[json!({"type":"text","text":"Human: Hello"})]
        ; "user_only_message_still_processed"
    )]

Review generated by goose

@blackgirlbytes blackgirlbytes force-pushed the fix/claude-code-empty-message-7930 branch from 8de0a49 to 7fa2995 Compare March 16, 2026 16:32
The last_user_content_blocks function finds the last user message to send
to Claude Code CLI, but then incorrectly filtered it by is_agent_visible().
Since we explicitly selected this message to send, the visibility filter
should not apply - it would cause messages with agent_visible: false to
be silently dropped, resulting in empty content being sent to Claude.

The filter is preserved for the fallback case (no user message found) where
we iterate over the full conversation history - in that case we still want
to exclude user-only messages.

This was introduced in commit 4abf91e when refactoring from
messages_to_content_blocks to last_user_content_blocks.

Fixes #7930
@blackgirlbytes blackgirlbytes force-pushed the fix/claude-code-empty-message-7930 branch from 7fa2995 to 8536d00 Compare March 16, 2026 17:05
@angiejones angiejones requested a review from michaelneale March 16, 2026 18:12
@codefromthecrypt codefromthecrypt self-assigned this Mar 16, 2026
Remove the filter entirely instead of using a boolean conditional.
Add test for user_only message not being dropped.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Copy link
Collaborator

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

@codefromthecrypt
Copy link
Collaborator

ps I added a commit to feed the bot, but I think we should soon plan getting off double-maintenance of both acp and non-acp variants of the claude provider. a lot of this hairy stuff should be in one place (in the acp adapter we use as a lib)

@codefromthecrypt codefromthecrypt added this pull request to the merge queue Mar 16, 2026
Merged via the queue into main with commit 707dc5f Mar 16, 2026
23 checks passed
@codefromthecrypt codefromthecrypt deleted the fix/claude-code-empty-message-7930 branch March 16, 2026 23:18
lifeizhou-ap added a commit that referenced this pull request Mar 17, 2026
* main:
  Add DCO git commit command to AGENTS.md (#7945)
  fix(claude-code): remove incorrect agent_visible filter on user message (#7931)
  No Check do Check (#7942)
  Log 500 errors and also show error for direct download (#7936)
  fix: retry on authentication failure with credential refresh (#7812)
  Remove java/.ai-usage-marker directory (#7925)
  test(acp): add terminal delegation fixtures and fix shell singleton (#7923)
  fix: bump pctx_code_mode to 0.3.0 for iterator type checking fix (#7892)
  feat: persist GooseMode per-session via session DB (#7854)
  feat(otel): propagate session.id to spans and log records (#7490)
  fix(test): add env_lock to is_openai_reasoning_model tests (#7917)
  fix(acp): pass session_id when loading extensions so skills are discovered (#7868)
jh-block added a commit that referenced this pull request Mar 17, 2026
* origin/main:
  feat: adversarial agent for preventing leaking of info and more  (#7948)
  Update contributing.md (#7927)
  docs: add credit balance monitoring section (#7952)
  docs: add Cerebras provider to supported providers list (#7953)
  docs: add TUI client documentation to ACP clients guide (#7950)
  fix: removed double dash in pnpm command (#7951)
  docs: polish ACP docs (#7946)
  claude adaptive thinking (#7944)
  feat: new onboarding flow (#7266)
  Add DCO git commit command to AGENTS.md (#7945)
  fix(claude-code): remove incorrect agent_visible filter on user message (#7931)
  No Check do Check (#7942)
  Log 500 errors and also show error for direct download (#7936)
  fix: retry on authentication failure with credential refresh (#7812)
  Remove java/.ai-usage-marker directory (#7925)
  test(acp): add terminal delegation fixtures and fix shell singleton (#7923)
  fix: bump pctx_code_mode to 0.3.0 for iterator type checking fix (#7892)
  feat: persist GooseMode per-session via session DB (#7854)
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.

Claude Code provider drops user messages with agent_visible: false metadata

2 participants