Skip to content

feat(tier3): add tier3 feedback chat over a completed run - #341

Merged
rng1995 merged 11 commits into
mainfrom
naren/port-tier3-feedback-chat
Nov 5, 2026
Merged

rng1995 merged 11 commits into
mainfrom
naren/port-tier3-feedback-chat

Conversation

@rng1995

@rng1995 rng1995 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • New expert command skillevaluator tier3 feedback RUN_DIR [--skill PATH]. It opens a terminal chat about one completed Tier 3 run, so a skill author can ask follow-up questions and get advice on skill changes without running the evaluation again or calling the Insights judge again.
  • The chat is grounded in the run's own evidence: scores, with-skill and baseline comparisons per agent, skill activation, failure scope and up to 5 execution errors per agent, measured agent tokens and seconds (resources), and one row per agent and dataset case with every with-skill and baseline attempt and its per-metric scores. The report feedback saved in result.json (tier3_feedback, schema 1.0) is included only when that file's run_id names the run directory.
  • The payload is built with agent_eval_result_from_directory(use_llm_judge=False, enforce_embedded_size=False), so there is no second judge call and every agent's trials are kept.
  • The evaluated skill comes from the run: result.json publication_target.skill_name when its run_id matches the directory, otherwise skill_name. An explicit --skill must name that skill, compared on the NFC name and ignoring case, so a decomposed (NFD) macOS path still matches. When the skill's digest differs from the recorded publication_target.skill_digest, the chat says the skill has changed since the run.
  • What is sent: compact JSON in the system message, so user and assistant turns alternate as strict chat templates require. The run is named by its ID. In every text field (errors, warnings, case questions and ground truth, dimension explanations, saved feedback), any absolute path that ends in the run's directory is replaced with that ID, and credential-shaped text is redacted, before the text is shortened. A cut cannot leave a token or path prefix behind. A final redact_sensitive_text pass covers the fields that are never shortened.
  • Path masking covers this run's own path, spaces included, and the path a copied run had where it first ran: POSIX, ~/, UNC and drive-letter paths, escaped or not, that end in a segment equal to the run ID. A prefix such as --output= is kept. Relative paths and names such as <run_id>_old or <run_id>.log are left alone. A path from another machine that contains a space is not recognized, and the docs say so.
  • Shortened fields end in ...<truncated>. Text with no whitespace after its limit, such as a compact JSON ground truth or a minified provider error, is masked over a 65,536-character window, so it keeps a masked prefix up to its limit instead of being blanked.
  • Case rows share a 300,000-character budget. It is spent one case at a time across agents, so a large multi-agent run keeps the same leading cases for every agent instead of dropping whole agents. Rows left out are counted per agent in cases_omitted (for example {"opencode": 31}), and the system prompt asks the model to say whose cases are missing.
  • Session behavior: a turn is added to the history only together with its answer, so a failed or interrupted question leaves the history unchanged. A failed turn prints a short message (refusal, output limit, provider not configured, or llm_failure_diagnostic for SDK errors such as HTTP 401), never a provider response body, and the chat keeps running.
  • Terminal behavior: model text is printed as literal Text after strip_terminal_controls, never as Rich markup. Run and skill paths in the panel are printed literally too. exit, quit, q, :q or Ctrl-D end the chat. Ctrl-C during an answer discards that question.
  • No request is sent before the first question, so empty stdin exits 0 at once. Piped input sends one question per line. Exit code 1 means the run or provider configuration could not be used, or questions were asked and every one failed. Nothing is written to disk.
  • LLMClient.chat(messages) adds multi-turn requests. completions() now calls a shared _complete_messages(system, turns) helper with one user turn, so both paths use the same retries, typed refusal/truncation/empty-reply errors, Anthropic server-side fallback headers and ADC token refresh. Anthropic gets the system text in system=, while Bedrock (litellm) and OpenAI-compatible endpoints get it as a leading system message. An invalid history raises LLMClientError before any client is created.
  • TIER3_FEEDBACK_CHAT_MODEL, _MAX_TOKENS, _TEMPERATURE and _REASONING_EFFORT alias the Insights judge settings. As with the judge, SKILL_EVAL_LLM_PROVIDER and SKILL_EVAL_LLM_MODEL select the provider and model.
  • Docs: a tier3 feedback section, a command-map row and the tier3 member list in docs/cli-reference.mdx. The section says that tier3 feedback always opens the chat, so a skill folder named feedback is evaluated with tier3 ./feedback or tier3 evaluate feedback. There is also a short entry under "Browse results" in docs/reports.mdx, a pointer after viewing results in docs/tier3-live-evaluation.mdx, and a CHANGELOG entry under Unreleased > Added.

Why

After a live run, the report says what happened, but turning that into a skill change usually needs follow-up questions, for example "Which cases explain the lower score?" or "What should I change if agent time matters more than token cost?". Today the only way to get new advice is to run the evaluation again. The chat answers these questions from the evidence the run already saved and treats proposed changes as hypotheses for the next run.

Kept from public

  • Typed error handling in _checked_content and _extract_choice_content (LLMClientRefusedError, LLMClientTruncatedError, EmptyLLMResponseError) is reused by chat() and not duplicated. The same goes for retry_call_with_backoff, the Claude 5.5+ server-side fallback on native Anthropic endpoints and the ADC refresh. Request kwargs for completions() are unchanged.
  • SDK exceptions are still raised unchanged after retries. The chat session turns them into a sanitized message with the existing llm_failure_diagnostic, so the client gets no second error mapping.
  • Terminal safety uses utils/rich_markup.strip_terminal_controls, and rich_markup is unchanged. A DCS payload such as ESC P q#0 ESC \ loses its escape bytes and shows the inert payload as plain text, as everywhere else in the CLI.
  • Run identity follows tier3_report._run_truth_metadata: result.json is bound by run_id == run_dir.name and not by the absolute run_dir, so a copied run keeps its saved feedback. The saved-feedback binding lives in the new module, and tier3_report.py is not edited.
  • Name matching uses publication_identity.publication_target_name and publication_target_from_path. Completed runs are detected with run_directory_sort_key(require_completed_result=True). Provider checks use resolve_llm_provider / ProviderConfigurationError.
  • Credentials are redacted with redact_sensitive_text on string values. Key-based redact_sensitive_data would also blank the measured tokens totals. Shortened fields call it with the bounded max_input_chars window used by tier3/plugin_evidence.py, which drops a token cut at the window's edge.
  • Case findings from what_to_fix already reach the chat through the saved feedback's recommendations, so they are not read a second time.
  • Like the other expert-only commands, run_feedback_chat is exported from tier3/commands.py but is not added to the lazy tier3/__init__.py export list.

Tests

  • New tests/evaluation/test_tier3_feedback_chat.py (57 tests). It fails on main at collection, because the module does not exist there. It covers:
    • skill resolution: publication target, a target from another run, missing hint, explicit --skill checks, case and NFD spellings
    • run context: agent resources, invalid runtimes, comparisons and saved feedback, other agents' failure scope, run ID instead of host path, credential redaction with token totals kept, a GitHub token, an AWS key and the run path placed across each field's limit (warnings, errors, questions, ground truth, explanations, feedback), and a dimension explanation that is not text
    • text without spaces: a 1,141-character compact JSON ground truth, minified errors with and without a leading word, a question and a warning keep a masked prefix of exactly their limit; a GitHub token inside such text is still redacted; a 100,000-character token becomes ...<truncated>
    • copied run: the run directory is under Downloads, and the evidence names /home/ci-runner/..., C:\Users\... (plain and JSON-escaped) and ~/... paths ending in the run ID; each becomes the ID, and a path= prefix and the part after the run ID are kept; a relative path, <run_id>_old and <run_id>.log are unchanged
    • case summaries: every dataset case, every attempt, per-metric scores, compact evidence for 100 cases x 2 agents x 2 attempts, the size cap, and a capped 3-agent run that keeps cases for every agent and counts omissions per agent
    • session: answers, alternating roles, failure messages (refusal, truncation, HTTP 401 without the body, plain and wrapped provider configuration, unexpected error), Ctrl-C, and an openai.AuthenticationError followed by a working turn
    • loader: saved feedback restored only for this run and schema 1.0, no judge call, and a real Harbor run directory read without writing to it
    • CLI: help, a skill folder named feedback (tier3 feedback opens the chat; tier3 ./feedback and tier3 evaluate feedback evaluate the folder), literal model text, provider misconfiguration before the first question, incomplete run, mismatched skill, escape stripping, Ctrl-C, bracketed paths, EOF exits 0 with no client created, alternating history for a real run, exit 1 when every question fails, and the changed and unchanged skill notice
  • tests/inference/test_llm_client.py::TestChat (14 tests): empty and invalid histories rejected before a client exists; OpenAI-compatible, Anthropic (system split out, fallback headers kept) and Bedrock requests; no system message; completions() still sends one system and one user message; truncation raised as a typed error and not retried; empty choices raise EmptyLLMResponseError. On main, 13 of them fail and the completions() guard passes.
  • tests/golden/cli_surface.json gains the tier3 feedback entry.
  • With the PR's own tests, on the branch: tests/evaluation/test_tier3_feedback_chat.py, tests/inference, tests/golden, tests/test_cli.py, tests/test_commands.py, tests/test_llm_client_retry.py, tests/test_llm_judge.py, tests/test_retry_provider_transport.py, tests/test_tier3_compare.py, tests/test_tier3_progress.py, tests/test_evaluation_service.py, tests/test_verifier_error_redaction.py, tests/test_harbor_scaffold_transactions.py, tests/test_benchmark_source_provenance.py, tests/tier3/test_skip_with_skill.py, tests/reporting/test_rich_markup_escaping.py, tests/reporting/test_unified_tier3_report.py, tests/test_ci_workflows.py, and the docs and CHANGELOG readers (test_oss_packaging.py, test_ci_change_classifier.py, test_accuracy_arithmetic.py, test_benchmark_rollout_docs.py, test_tier3_public_runtime.py, tests/ci/test_image_build.py), plus tests/cli/test_tier_workflows.py: 1988 passed with -n 8.
  • ruff check is clean on the changed Python files, and scripts/check_oss_boundary.py passed. ruff format --check is clean on them except tests/inference/test_llm_client.py, where it reports only two long monkeypatch.setattr lines that are already on main (it fails there too). Open PR fix(inference): recover one JSON object wrapped in LLM prose #297 wraps those lines, so this PR leaves them alone. CI runs ruff check only.

🤖 Generated with Claude Code

rng1995 and others added 2 commits November 5, 2026 00:50
chat(messages) takes an OpenAI-style history: optional leading system
messages, then user and assistant turns. completions() now calls the same
private _complete_messages helper with one user turn, so both paths share
the retries, the typed refusal, truncation and empty-reply errors, the
Anthropic server-side fallback headers and the ADC token refresh.
Anthropic receives the system text in its separate system field; Bedrock
and OpenAI-compatible endpoints receive it as a leading system message.
An invalid history raises LLMClientError before any client is created.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`skillevaluator tier3 feedback RUN_DIR [--skill PATH]` opens a terminal
chat about one completed Tier 3 run. Answers are grounded in the run's
scores, with-skill and baseline comparisons, measured agent tokens and
seconds, execution errors, every case's attempts with per-metric scores,
and the report feedback saved in result.json when its run_id names the
run directory. The payload is built without a second judge call.

The skill is inferred from the run's publication target; an explicit
--skill must match it (NFC, case-insensitive), and a changed skill digest
is pointed out. Each question sends compact evidence to the configured
provider with the run ID instead of its host path and with credential-
shaped text redacted. Model text is printed literally with terminal
controls removed. Failed turns print a sanitized message and leave the
history unchanged; Ctrl-C discards the current question. No request is
sent before the first question, empty stdin exits 0, and the command
exits 1 when every question failed. Nothing is written to disk.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated review: 4 findings (0 P1, 1 P2, 3 P3); 4 posted inline.

Comment thread docs/cli-reference.mdx Resolved
Comment thread tests/inference/test_llm_client.py Resolved
rng1995 and others added 6 commits November 5, 2026 22:32
Warnings, execution errors, case questions and ground truth, dimension
explanations and saved feedback were cut to their limits before the run
path was replaced and credentials were redacted. A token or path that
crossed the limit lost the part a redaction pattern needs, and its prefix
reached the provider.

Each string now has the run path replaced with the run ID and goes
through redact_sensitive_text with max_len and a bounded input window,
as the plugin evidence helpers do, before it is shortened. The final pass
over the whole context stays for fields that are never shortened. A
dimension explanation that is not text is dropped instead of sliced.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Case rows were kept in agent order until the 300,000-character budget
ran out, so a large multi-agent run could send every case for the agents
that sort first and none for the last one. cases_omitted was one number
and did not say whose cases were missing.

The budget is now spent one case at a time across agents, so each agent
keeps the same leading cases. Kept rows are still listed by agent and
case, and cases_omitted counts the rows left out per agent. The system
prompt asks the model to say which agent's cases are missing.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
tier3 checks its registered commands before it treats the first argument
as a skill path, so `tier3 feedback` opens the chat even when the current
directory has a skill folder named feedback. The tier3 feedback section
now says to run `tier3 ./feedback` or `tier3 evaluate feedback` to
evaluate that skill, and a test pins both routes.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Restore the two long monkeypatch.setattr lines in the Vertex ADC tests
as they are on main. Wrapping them belongs to the open change that
reformats this file; this branch only adds the chat tests.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each shortened field is masked over a window of limit * 4 + 256
characters, cut back to the window's last whitespace so a credential
split at the edge is dropped. Text with no whitespace after its limit,
such as a compact JSON ground truth or a minified provider error, was
cut back to its last space or to nothing. The model saw an empty ground
truth or error with no sign that text was left out.

Such text is now masked over a 65,536-character window instead, so it
keeps a masked prefix up to its limit. When a window still drops text,
the field ends in ...<truncated>, the same marker as other shortened
fields.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The feedback chat replaced only the run directory's current path with
the run ID. A run copied from another machine keeps its ID, and its
errors and warnings still name the original location, for example
/home/<user>/work/<skill>/evals/results/<run_id>/jobs/t1. That path,
with the user and skill names in it, reached the provider unchanged.
JSON-escaped Windows paths and other spellings of the same directory
were missed too.

Any absolute path (POSIX, home, UNC or drive letter, escaped or not)
that ends in a path segment equal to the run ID is now replaced with
the ID. The path starts at the first absolute-path root after the
preceding whitespace or quote, so a prefix such as --output= is kept.
Relative paths and names such as <run_id>_old or <run_id>.log are left
as they are. The scan is linear in the text length.

The CLI reference now says which paths are replaced, that a path from
another machine containing a space is not recognized, and that a
shortened field ends in ...<truncated>.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rng1995
rng1995 marked this pull request as ready for review November 5, 2026 18:29
rng1995 and others added 3 commits November 5, 2026 10:39
Conflicts: src/skillevaluator/inference/client.py and tests/inference/test_llm_client.py.
Kept both sides; the model_used reset from main now runs at the start of
_complete_messages, so chat() and completions() both record provenance.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
main's model provenance (#308) leaves LLMClient.model_used as None after a
failed call. chat() validated the history before _complete_messages
cleared it, so an invalid history raised LLMClientError while model_used
still named the model from the previous call. chat() now clears it first;
no client is created, so an invalid history still fails before any
provider call. The model_used and chat() docstrings name chat() too.

A new provenance test checks that chat() reports the server-side fallback
model after a success and None after an empty history. It fails without
this change.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rng1995
rng1995 enabled auto-merge (squash) November 5, 2026 20:39
@rng1995
rng1995 merged commit ea147c1 into main Nov 5, 2026
22 checks passed
@rng1995
rng1995 deleted the naren/port-tier3-feedback-chat branch November 5, 2026 21:07
@rng1995

rng1995 commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Post-merge review: 4 finding(s) (P3). Follow-up PR: #364.

🤖 Generated with Claude Code

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.

1 participant