Skip to content

refactor: P0 hardening for model attribution in codex/kimi parsers#9

Merged
Miss-you merged 2 commits into
mainfrom
feat/model-attribution-p0-hardening
Feb 21, 2026
Merged

refactor: P0 hardening for model attribution in codex/kimi parsers#9
Miss-you merged 2 commits into
mainfrom
feat/model-attribution-p0-hardening

Conversation

@Miss-you

Copy link
Copy Markdown
Owner

Summary

  • Deliver P0 hardening for model attribution robustness in provider parsers.
  • Reduce false positives in Codex model extraction by replacing broad recursive heuristics with known-path extraction + candidate filtering.
  • Improve Kimi log fallback robustness by parsing flexible key-value model fields instead of relying on a single strict regex format.

P0 Plan (Implemented)

  • Parser hardening only (no CLI contract changes).
  • Keep backward compatibility for existing session formats.
  • Add focused regression tests for new extraction behavior.
  • Add design/acceptance document: docs/model-attribution-p0.md.

Acceptance Criteria

  • Kimi model fallback works for quote/spacing/key-name variations in Using LLM model lines.
  • Kimi fallback can keep latest model line for one session in a deterministic way.
  • Codex does not extract model from unrelated placeholder/metadata candidates.
  • Codex still extracts model from supported known payload paths.
  • Existing tests and build gates stay green.

Use Cases Covered

  • provider/kimi/parser_test.go: log line variants, latest-model mapping, legacy fallback path.
  • provider/codex/parser_test.go: known-path extraction with noisy metadata, placeholder rejection.

Changes

  • provider/codex/parser.go:
    • Replace generic recursive extraction with known model-path extraction.
    • Add lightweight candidate validation (default/auto/unknown/rate-limit rejection).
  • provider/kimi/parser.go:
    • Replace strict model='...' regex with key-value field parsing.
    • Accept model/model_name/model_id/modelid keys.
    • Keep latest model entry per session in log index.
  • provider/codex/parser_test.go:
    • Add regression tests for known-path preference and placeholder rejection.
  • provider/kimi/parser_test.go:
    • Add line-format variant tests and latest-model mapping test.
  • docs/model-attribution-p0.md:
    • Document context, scope, non-goals, acceptance criteria, and test cases.

Validation

  • go test ./provider/codex ./provider/kimi
  • go test ./stats ./cmd ./e2e
  • make test
  • make lint
  • make build
  • make vet
  • staged acceptance script:
    • run_staged_acceptance.sh
    • run_staged_acceptance.sh --run-tests

Risks / Notes

  • This P0 intentionally keeps path/key whitelists explicit; future upstream schema shifts may require extending known paths/keys and tests.
  • Alias normalization strategy (stats/aggregator.go) is out of scope for this P0 and remains a follow-up item.

Copilot AI review requested due to automatic review settings February 21, 2026 16:20

Copilot AI 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.

Pull request overview

P0 hardening of provider-side model attribution to reduce false positives and improve robustness when model names must be inferred from Codex JSON payloads or Kimi log fallback parsing.

Changes:

  • Codex: replace broad recursive model extraction with known-path lookup + placeholder rejection.
  • Kimi: replace strict model='...' regex with flexible key=value field parsing and “latest model wins” per session.
  • Add focused regression tests and a design/acceptance doc for the P0 scope.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
provider/codex/parser.go Introduces explicit model-path whitelist and candidate filtering for Codex model extraction.
provider/codex/parser_test.go Adds regression tests for known-path preference and placeholder rejection.
provider/kimi/parser.go Updates Kimi log fallback to parse key=value model fields and keep latest per session.
provider/kimi/parser_test.go Adds tests for log-line variants and latest-model behavior per session.
docs/model-attribution-p0.md Documents P0 scope, non-goals, acceptance criteria, and test coverage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread provider/codex/parser.go
Comment on lines 220 to 223
if info.ModelName == "" {
info.ModelName = strings.TrimSpace(msg.Model)
if info.ModelName == "" {
info.ModelName = extractModelFromRawJSON(msg.Info)

Copilot AI Feb 21, 2026

Copy link

Choose a reason for hiding this comment

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

parseCodexSession assigns info.ModelName directly from msg.Model without running it through the new placeholder/candidate filter. If msg.Model can be values like default/auto/unknown, the parser will lock in a placeholder and skip extracting the real model from msg.Info/other payloads. Apply isLikelyCodexModelName (or equivalent) to msg.Model before accepting it, and fall back to the JSON-path extraction when it’s not a valid model name.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 2dcce7b: msg.Model is now gated by isLikelyCodexModelName before assignment. If it is a placeholder (e.g. default), parser falls back to msg.Info/payload path extraction. Added regression test TestParseCodexSession_ModelExtractionSkipsPlaceholderMsgModel.

@Miss-you
Miss-you merged commit 6fa9ea9 into main Feb 21, 2026
7 checks passed
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