Skip to content

Record each model call's subject and outcome in traces; trace just eval; add scripts/export_training_data.py - #68

Merged
strickvl merged 9 commits into
mainfrom
claude/project-thread-f1f2bt
Nov 3, 2026
Merged

strickvl merged 9 commits into
mainfrom
claude/project-thread-f1f2bt

Conversation

@strickvl

@strickvl strickvl commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Requested by Alex · project thread

Why

Before the ~150-article Luna pilot, make sure its traces can be turned into training data for small local models later. The traces from #63 already hold every prompt, reply, tool-call argument and token count. What they lacked was a label on each call: which entity or candidate it was about, how it ended, which prompt file produced it, and, for eval runs, the gold answer. Without those, the pilot's thousands of calls would be prompts and replies with no way to tell the good ones from the bad.

What changes

  • annotate(**attrs) in src/utils/tracing.py sets hinbox.* attributes on the current step span. Steps record:
    • extract.<type>: entity type, article id, final count, QC flags, whether the repair retry was used. Each attempt also gets its own span with its own count, QC flags and attempt_selected.
    • match_check: both names, entity type, is_match, confidence, which prompt answered, and whether the memo answered.
    • relevance: the verdict and which prompt answered.
    • dispute: both names, similarity, the action taken, confidence.
    • profile.update and profile.create: entity, article id, approach, characters before and after, edits applied/appended/skipped, disagreements, QC result.
  • request_span() wraps each structured request, with all of Instructor's retries, and each sectioned call plus its parsing. It ends with hinbox.request_ok, so a request that never produced a valid answer is marked failed even though each model call inside it returned normally.
  • DomainConfig.prompt_path() adds <file>@<hash> to the step's hinbox.prompt_files list. Every LLM span also gets hinbox.step and a hash of its system prompt.
  • Resource attributes: run id, domain, --local, git commit (with -dirty), and every HINBOX_* setting except keys, tokens and secrets.
  • Span limits are raised to 4096. OpenTelemetry's default of 128 would silently cut long conversations.
  • Instructor retry turns are traced in full, including the nested function shape and tool-call ids.
  • just eval and just eval-replay are traced. Each eval item is its own trace with eval_label, eval_prediction and eval_correct, or eval_passed and eval_scores for profile updates. Profile-update eval calls and the fact-list stages get their own steps.
  • Article spans record source_type when the row has one, so book data can be kept apart later.
  • scripts/export_training_data.py (just export-training <traces...> --out <dir>) writes one <task>.jsonl per task of {"messages", "tools", "metadata"} rows, in the shape TRL, Unsloth and Axolotl read:
    • By default each row is the original prompt plus the final good reply. --keep-retry-turns keeps Instructor's rejected turns too.
    • Calls are dropped if they raised, hit the token limit, or sit under a failed request or step. --keep-failed keeps them.
    • Tool-call arguments are decoded to dicts, and Anthropic tools and content blocks are converted to OpenAI form.
    • The hinbox.* notes from the call, step, article and eval-item spans are merged into metadata.

Nothing changes what the pipeline does; these are extra attributes and spans only.

Tests

  • tests/test_training_export.py has 14 tests:
    • an eval match check round-trips into a labelled example;
    • tool-call extraction, where a truncated try is dropped;
    • an Instructor retry, exported both with and without its retry turns;
    • extraction attempts and which one was kept;
    • a request that gave up is dropped;
    • an unreadable sectioned reply is marked failed;
    • prompt files are listed;
    • Anthropic tools and blocks are converted;
    • eval updater calls land in the right steps.
  • just ci equivalent (ruff check and format, file-length check, pytest -m "not asyncio"): 583 passed.

Not measured: trace file size on a real run. Expect tens of MB for 150 articles, because the full article text is in every extraction prompt.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FomNXensfhyR2ji8FxW2xu

…add `scripts/export_training_data.py`

Steps now note what their model call was about and how it ended
(`annotate()`), prompt files and hashes are recorded, eval and replay runs
are traced with gold labels and scores, span limits are raised, and an
exporter turns traces into TRL-style chat examples per task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FomNXensfhyR2ji8FxW2xu
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T12:53:54.711677Z 83ad69f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@strickvl strickvl self-assigned this Nov 3, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 34c152bf5b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/export_training_data.py Resolved
Comment thread src/evals/profile_update.py Resolved
Edit and fact-list updates scored by `just eval profile-update` called the
updaters directly, so their model calls had no step and exported as
`(no step)`. Wrap them in `profile.update` (annotated with the entity) and
each fact-list stage in its own step (`fact_extract`, `fact_compare`, ...).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FomNXensfhyR2ji8FxW2xu
Instructor's reask messages nest tool-call name/arguments under `function`
and link the tool reply by `tool_call_id`; the flattener read them from the
top level and dropped the ids. Read both shapes, record ids, and have the
exporter rebuild input messages from the lossless `input.value`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FomNXensfhyR2ji8FxW2xu

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6304b6a1a7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/export_training_data.py Resolved
Comment thread src/utils/tracing.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b1cd6882f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/engine/article_processor.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f1e7e391f7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/export_training_data.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 46269e9118

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/export_training_data.py Resolved
Instructor validates after the SDK call returns, so a request that exhausts
its retries left clean model-call spans. `request_span()` around
`_structured_generation()` records `hinbox.request_ok` (and ERROR on raise);
the exporter treats calls under a failed request or step as failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FomNXensfhyR2ji8FxW2xu

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c8ed5c190

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/export_training_data.py Resolved
Comment thread scripts/export_training_data.py Resolved
…ic retry blocks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FomNXensfhyR2ji8FxW2xu

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14ec27b2f0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/export_training_data.py Resolved
…y-turns` keeps the rest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FomNXensfhyR2ji8FxW2xu
@strickvl
strickvl merged commit 0d7d76c into main Nov 3, 2026
2 checks passed
@strickvl
strickvl deleted the claude/project-thread-f1f2bt branch November 3, 2026 12:54
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