Skip to content

fix: order OTel span conflicts by canonical content - #5537

Merged
Sinity merged 1 commit into
masterfrom
fix/otel-span-canonical-tiebreak
Sep 25, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/otel-span-canonical-tiebreak

Conversation

@Sinity

@Sinity Sinity commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Choose conflicting OTel span copies by canonical span JSON after schema rank and start time, with schema URL as the final tie break.

Problem

The existing key compared schema URL before span JSON. Two copies with the same resource, trace ID, span ID, schema rank, and start time could therefore select a different conversation based on the schema URL, changing the derived session identity. This contradicted the original duplicate span rule.

Solution

Reorder the variant key and update the duplicate identity index. Add a parser regression with opposing schema URL and canonical JSON order, and document the resulting precedence.

Verification

  • devtools test tests/unit/sources/parsers/test_otel_genai.py: devtools test: PASSED exit=0 diagnosis=pytest_passed; devtools why reported selected 11 test(s).
  • devtools schema closure polylogue/sources/parsers/otel_genai.py: IN; this parser change moves the derived schema identity and requires normal reconvergence after landing.
  • git diff --check origin/master...HEAD: passed.
  • Commit hook: format and lint passed.

Residual: The focused test selection does not claim full corpus coverage.

Summary by CodeRabbit

  • Bug Fixes
    • Improved consistency when choosing between duplicate OpenTelemetry GenAI spans. When spans have matching priority and start times, the canonical span content now determines which copy is selected, rather than the schema URL.
    • Parsing produces consistent results regardless of scope order, while other distinct copies remain available as conflict evidence.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 25, 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-09-25T17:48:50.617638Z 2f0b5f0 PR opened
🔒 Security Review ✅ Completed 2026-09-25T17:50:21.778660Z 2f0b5f0 PR opened
ℹ️ 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.

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: aa9e0506-68af-48fd-8821-6f51e5e08804

📥 Commits

Reviewing files that changed from the base of the PR and between 2527f36 and 2f0b5f0.

📒 Files selected for processing (3)
  • docs/provider-origin-identity.md
  • polylogue/sources/parsers/otel_genai.py
  • tests/unit/sources/parsers/test_otel_genai.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The OpenTelemetry GenAI parser now compares canonical span JSON before schema URL when ordering span variants. Conflict detection uses the serialized span content to distinguish variants. The regression test checks selection, scope-order independence, and retained conflict evidence.

Changes

Span variant ordering

Layer / File(s) Summary
Variant ordering and conflict detection
polylogue/sources/parsers/otel_genai.py, tests/unit/sources/parsers/test_otel_genai.py, docs/provider-origin-identity.md
The parser orders variants by serialized span JSON before schema URL and uses the serialized span content to distinguish conflicts. The test checks order-independent selection and retained conflict evidence. The documentation records the updated tie-break order.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 2f0b5

The span-selection change and its regression coverage present no identified issue that needs resolution before merging.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 2f0b5

The change adds a source of archived session data and changes which evidence-only records are admitted. Duplicate selection is deterministic in the focused test, but the end-to-end exposure and recovery behavior of the new source are not fully established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Configured OTLP files can supply span attributes and identifiers that become archived session evidence and, for supported or absent schemas, normalized messages. The visible change does not establish a network receiver.

Trust Boundaries and Controls

  • observed — OTel shape detection requires a span with a gen_ai attribute under the supported or an absent schema URL. Parsing retains unsupported-schema span evidence but skips its message normalization.

Resilience and Maintainability Implications

  • inferred — Ordering and conflict identity are deterministic for the tested reversed-scope case. Recovery after interrupted ingestion and downstream handling of persisted evidence were not established by that test.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: ordering OTel span conflicts by canonical content.
Description check ✅ Passed The description includes complete Summary, Problem, Solution, and Verification sections. It explains the behavior change, affected modules, regression test, validation commands, and residual test-cove…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each span in line
And sorts the JSON by design
The schema breaks a final tie
While conflict notes are saved nearby
Then hops beneath the moonlit sky

Comment @coderabbitai help to get the list of available commands.

@Sinity
Sinity enabled auto-merge (squash) September 25, 2026 17:54
@Sinity
Sinity merged commit 8d2d31c into master Sep 25, 2026
3 checks passed
@Sinity
Sinity deleted the fix/otel-span-canonical-tiebreak branch September 25, 2026 17:58
Sinity added a commit that referenced this pull request Sep 28, 2026
## Summary

Ports the still-relevant tests from the orphaned custody branch
`wip/reindex-readiness-only-20260927` (bead polylogue-gtqzv). Each test
was adapted to run against master's current production route. Porting
the MCP judge test exposed one defect, fixed here: a daemon-required
refusal reached MCP clients under the generic `polylogue_error` code.

## Problem

- Master's OTel GenAI parser (#5530, #5537, #5654) has no tests for live
acquisition from a configured root, replay-stable identity, duplicate
and conflicting span copies, one span id reused across traces, trace-id
fallback, explicit-empty attributes over compatibility events, late
parents, schema-url status, or redacted/truncated/missing fidelity.
- The MCP declaration inventory had no test that makes a new privileged
capability fail until someone reviews it.
- The MCP `judge` route now writes through the daemon. Without a running
daemon it raises `FacadeDaemonRequiredError`, whose code is
`daemon_required`, but `mcp_error_payload` reported it as
`polylogue_error`.

## Solution

- `tests/unit/sources/parsers/test_otel_genai_contract.py`: the nine
branch contracts. All pass against master's parser as written. The only
changes are fixture typing.
- `tests/unit/mcp/test_mcp_writer_boundary.py`: the capability inventory
test, plus a judge test on the current route. The real MCP `judge`
handler must refuse with `daemon_required` and leave `user.db`
byte-identical, with the candidate still unjudged.
- `polylogue/mcp/server_support.py`: maps `FacadeDaemonRequiredError` to
its own code.

Dropped as obsolete, with a reason recorded on the bead:
- The requested-fields tests.
`test_query_units_selects_message_fields_without_materializing_full_rows`
already covers the same route through the facade.
- The SLO failed-benchmark test. Master's
`test_failed_benchmark_with_valid_json_is_not_scored_and_keeps_diagnostics`
covers it.
- The Claude artifact observation at raw admission.
`archive/artifact_taxonomy/runtime.py` classifies these now.

## Verification

- `devtools test tests/unit/sources/parsers/test_otel_genai_contract.py
tests/unit/sources/parsers/test_otel_genai.py
tests/unit/mcp/test_mcp_writer_boundary.py
tests/unit/mcp/test_tool_error_isolation.py`: `PASSED exit=0`
- `devtools gate layering`: passed. mypy passes on the changed files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[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.

1 participant