Skip to content

fix(chat): show no raw tool name or tool call in an answer, and say when the data's instructions weren't followed - #2061

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/chat-deterministic-guards
Nov 3, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/chat-deterministic-guards

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Three things the engine now fixes in a Chat answer, whatever the model wrote. Chat's model test set (W4-35) found each in real runs of GPT and Gemini models:

  • A tool's raw name never shows.
    • What the test set found: Gemini 4 Argon wrote "(explain_change)" in a Turkish answer.
    • Fix: a name in the answer becomes its tool's Settings name, here "Explain why a number changed". One with no Settings name (the engine's own: next moves, questions, skills, the out-of-permission answer) is removed, with any empty "()" it leaves.
    • Exempt: a fenced code block, and a name the person wrote in their own message.
    • Streaming: the answer streams with its last word held until the next chunk, so a name split across chunks is still caught.
  • A tool call written out as text goes.
    • What the test set found: GPT-6.1 Terra answered "hi" with "…opportunity.waswo to=functions.suggest_next_moves 银航 {"moves":[…]} call".
    • Fix: from the junk word before the to=functions. marker, the rest of that reply's text is dropped.
  • The injection notice is never missing.
    • What the test set found: when the data read for an answer held instructions for AI assistants, untrusted.ts flagged it and the model was told to say so (INJECTION_NOTE). In the test set all six GPT and Gemini models skipped the line.
    • Fix: if the answer doesn't already say so, the run ends with "Note: the data I read included instructions for AI assistants. I didn't follow them." (chatEngine.answer.injectionNotice). If the model wrote the notice itself, in English or Turkish, no second one is added.

The rules are in a new pure module, web/src/lib/chat/answer-guards.ts. TextOut and finish in engine.ts use them. They apply to every model, Claude included.

Related issue

None. Found by the Chat Wave 4 model test set (W4-35).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd web && yarn vitest run src/lib/chat/answer-guards.test.ts src/lib/chat/engine.test.ts -t "puts right". Covered:
    • names becoming Settings names, or removed;
    • code blocks and the person's own words kept;
    • a call written as text dropped;
    • the notice added once, and not after the model's own.
  2. In Chat, ask "What does get_plan_facts do?": the name stays, because you wrote it.

No migration. No new environment variables. One new string in web/messages/en.json. No Help change.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

CI passed on this branch (9f6283a), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41599155172): schema is up to date; web format:check, lint, typecheck, all tests and yarn build pass; server lint, format:check and all tests pass.

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits November 3, 2026 01:29
…hen the data's instructions weren't followed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
# Conflicts:
#	web/messages/en.json

@gkhngyk gkhngyk 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.

LGTM

@gkhngyk
gkhngyk merged commit 6398a16 into ansvisor:main Nov 3, 2026
5 checks passed
gkhngyk pushed a commit that referenced this pull request Nov 3, 2026
… run makes (#2108)

#2061 masks a tool's name in Chat's answer, so the harness test that
expected the leak check to fail on the answer went red on main after #2072.
The test now writes the name into a draft's page, which the engine doesn't
mask, and checks the answer is masked and the leak check still fails there.

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants