Skip to content

refactor: tighten source provider and ingestion emission seams - #266

Merged
Sinity merged 2 commits into
masterfrom
feature/refactor/source-provider-ingestion-emission-seams
Apr 20, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/refactor/source-provider-ingestion-emission-seams

Conversation

@Sinity

@Sinity Sinity commented Apr 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • tighten provider-facing message adapters for Claude Code, Codex, and Gemini payloads
  • unify ingest parsing around explicit parse-plan helpers instead of duplicated stream/envelope control flow
  • normalize JSONL emission and provider-specific parser follow-through over the renewed ingestion contracts

Problem

The remaining source/provider seam was still carrying path-dependent payload branching across three adjacent layers:

  • provider message adapters mixed open dict plumbing with ad hoc normalization
  • ingest_worker duplicated grouped-stream versus envelope parsing control flow
  • the JSONL emitter and Codex/Drive parsers repeated provider detection and metadata shaping in slightly different forms

That code was strict-mypy-cleanable, but it still hid runtime meaning behind loosely shaped containers and repeated branches.

Solution

  • rebuild the provider message adapters in polylogue/sources/providers/claude_code_models.py, polylogue/sources/providers/claude_code_record.py, polylogue/sources/providers/codex.py, and polylogue/sources/providers/gemini_message.py around explicit helper aliases and normalization helpers
  • refactor polylogue/pipeline/services/ingest_worker.py to use typed parse-plan/context records so grouped stream parsing and envelope parsing share one orchestration path
  • restructure polylogue/sources/emitter.py so grouped JSONL, individual payload, and raw-capture handling all flow through one resolved payload path
  • carry the contract shape through polylogue/sources/parsers/codex.py and polylogue/sources/parsers/drive.py

Ref #262

Verification

  • ruff check polylogue/sources/providers/claude_code_models.py polylogue/sources/providers/claude_code_record.py polylogue/sources/providers/codex.py polylogue/sources/providers/gemini_message.py
  • mypy polylogue/sources/providers/claude_code_models.py polylogue/sources/providers/claude_code_record.py polylogue/sources/providers/codex.py polylogue/sources/providers/gemini_message.py
  • pytest -q tests/unit/sources/test_models.py -k 'Gemini or ClaudeCode or Codex'
  • ruff check polylogue/sources/parsers/codex.py polylogue/sources/parsers/drive.py polylogue/sources/emitter.py polylogue/pipeline/services/ingest_worker.py
  • mypy polylogue/sources/parsers/codex.py polylogue/sources/parsers/drive.py polylogue/sources/emitter.py polylogue/pipeline/services/ingest_worker.py
  • pytest -q tests/unit/pipeline/test_quarantine_fixtures.py tests/unit/pipeline/test_resilience.py tests/unit/pipeline/test_ingest_batch.py -k 'ingest_record or malformed_jsonl or zero_length_blob or schema_resolution or streams_codex_jsonl or iter_ingest_results_sync'
  • pytest -q tests/unit/sources/test_models.py tests/unit/sources/test_source_laws.py tests/unit/pipeline/test_quarantine_fixtures.py tests/unit/pipeline/test_resilience.py tests/unit/pipeline/test_ingest_batch.py -k 'Gemini or ClaudeCode or Codex or conversation_emitter or ingest_record or malformed_jsonl or zero_length_blob or schema_resolution or streams_codex_jsonl or iter_ingest_results_sync'
  • devtools verify

@coderabbitai

coderabbitai Bot commented Apr 20, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 35 minutes and 32 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 35 minutes and 32 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ecd5bc16-8f50-4d74-93f5-dd36909a2059

📥 Commits

Reviewing files that changed from the base of the PR and between 67a65d6 and 18e5b28.

📒 Files selected for processing (8)
  • polylogue/pipeline/services/ingest_worker.py
  • polylogue/sources/emitter.py
  • polylogue/sources/parsers/codex.py
  • polylogue/sources/parsers/drive.py
  • polylogue/sources/providers/claude_code_models.py
  • polylogue/sources/providers/claude_code_record.py
  • polylogue/sources/providers/codex.py
  • polylogue/sources/providers/gemini_message.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/source-provider-ingestion-emission-seams

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

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

@Sinity
Sinity merged commit 6d58b50 into master Apr 20, 2026
12 checks passed
@Sinity
Sinity deleted the feature/refactor/source-provider-ingestion-emission-seams branch April 20, 2026 10:29

@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: 18e5b2807f

ℹ️ 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 on lines +468 to +470
if resolved_schema is None and plan.artifact.schema_eligible:
resolved_schema = _resolve_schema_resolution(
plan.provider,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard schema lookup behind payload mode

_parse_plan_conversations resolves schema before checking plan.mode, so stream plans now call _resolve_schema_resolution(...) even though parse_stream_payload never uses a schema resolution. That adds avoidable schema-registry work to JSONL ingestion and makes validation_mode='off' still incur schema-resolution overhead; move this lookup into the payload-only branch (or after the stream early return) to restore the previous stream fast path.

Useful? React with 👍 / 👎.

Sinity added a commit that referenced this pull request Apr 22, 2026
## Summary
- tighten provider-facing message adapters for Claude Code, Codex, and Gemini payloads
- unify ingest parsing around explicit parse-plan helpers instead of duplicated stream/envelope control flow
- normalize JSONL emission and provider-specific parser follow-through over the renewed ingestion contracts

## Problem
The remaining source/provider seam was still carrying path-dependent payload branching across three adjacent layers:
- provider message adapters mixed open dict plumbing with ad hoc normalization
- `ingest_worker` duplicated grouped-stream versus envelope parsing control flow
- the JSONL emitter and Codex/Drive parsers repeated provider detection and metadata shaping in slightly different forms

That code was strict-mypy-cleanable, but it still hid runtime meaning behind loosely shaped containers and repeated branches.

## Solution
- rebuild the provider message adapters in `polylogue/sources/providers/claude_code_models.py`, `polylogue/sources/providers/claude_code_record.py`, `polylogue/sources/providers/codex.py`, and `polylogue/sources/providers/gemini_message.py` around explicit helper aliases and normalization helpers
- refactor `polylogue/pipeline/services/ingest_worker.py` to use typed parse-plan/context records so grouped stream parsing and envelope parsing share one orchestration path
- restructure `polylogue/sources/emitter.py` so grouped JSONL, individual payload, and raw-capture handling all flow through one resolved payload path
- carry the contract shape through `polylogue/sources/parsers/codex.py` and `polylogue/sources/parsers/drive.py`

Ref #262

## Verification
- `ruff check polylogue/sources/providers/claude_code_models.py polylogue/sources/providers/claude_code_record.py polylogue/sources/providers/codex.py polylogue/sources/providers/gemini_message.py`
- `mypy polylogue/sources/providers/claude_code_models.py polylogue/sources/providers/claude_code_record.py polylogue/sources/providers/codex.py polylogue/sources/providers/gemini_message.py`
- `pytest -q tests/unit/sources/test_models.py -k 'Gemini or ClaudeCode or Codex'`
- `ruff check polylogue/sources/parsers/codex.py polylogue/sources/parsers/drive.py polylogue/sources/emitter.py polylogue/pipeline/services/ingest_worker.py`
- `mypy polylogue/sources/parsers/codex.py polylogue/sources/parsers/drive.py polylogue/sources/emitter.py polylogue/pipeline/services/ingest_worker.py`
- `pytest -q tests/unit/pipeline/test_quarantine_fixtures.py tests/unit/pipeline/test_resilience.py tests/unit/pipeline/test_ingest_batch.py -k 'ingest_record or malformed_jsonl or zero_length_blob or schema_resolution or streams_codex_jsonl or iter_ingest_results_sync'`
- `pytest -q tests/unit/sources/test_models.py tests/unit/sources/test_source_laws.py tests/unit/pipeline/test_quarantine_fixtures.py tests/unit/pipeline/test_resilience.py tests/unit/pipeline/test_ingest_batch.py -k 'Gemini or ClaudeCode or Codex or conversation_emitter or ingest_record or malformed_jsonl or zero_length_blob or schema_resolution or streams_codex_jsonl or iter_ingest_results_sync'`
- `devtools verify`
@Sinity Sinity added area:parser Parser area:pipeline Pipeline tool:claude Claude type:refactor Code restructuring labels Apr 22, 2026
Sinity added a commit that referenced this pull request Apr 22, 2026
The source/provider seam carried path-dependent payload branching
across three adjacent layers: provider message adapters mixed open
dict plumbing with ad hoc normalization; `ingest_worker` duplicated
grouped-stream vs envelope parsing control flow; and the JSONL
emitter and Codex/Drive parsers repeated provider detection and
metadata shaping in slightly different forms. Strict-mypy-cleanable
but hiding runtime meaning behind loosely shaped containers and
repeated branches.

Rebuilds the provider message adapters in
`sources/providers/claude_code_models.py`,
`claude_code_record.py`, `codex.py`, and `gemini_message.py` around
explicit helper aliases and normalization helpers. Refactors
`pipeline/services/ingest_worker.py` to use typed parse-plan /
context records so grouped stream parsing and envelope parsing
share one orchestration path. Restructures `sources/emitter.py` so
grouped JSONL, individual payload, and raw-capture handling all
flow through one resolved payload path. Carries the contract shape
through `sources/parsers/codex.py` and `sources/parsers/drive.py`.

Verification: ruff + mypy + pytest over provider models, source
laws, quarantine fixtures, resilience, and ingest-batch suites;
devtools verify green.

Ref #262
Sinity added a commit that referenced this pull request Apr 22, 2026
The source/provider seam carried path-dependent payload branching
across three adjacent layers: provider message adapters mixed open
dict plumbing with ad hoc normalization; `ingest_worker` duplicated
grouped-stream vs envelope parsing control flow; and the JSONL
emitter and Codex/Drive parsers repeated provider detection and
metadata shaping in slightly different forms. Strict-mypy-cleanable
but hiding runtime meaning behind loosely shaped containers and
repeated branches.

Rebuilds the provider message adapters in
`sources/providers/claude_code_models.py`,
`claude_code_record.py`, `codex.py`, and `gemini_message.py` around
explicit helper aliases and normalization helpers. Refactors
`pipeline/services/ingest_worker.py` to use typed parse-plan /
context records so grouped stream parsing and envelope parsing
share one orchestration path. Restructures `sources/emitter.py` so
grouped JSONL, individual payload, and raw-capture handling all
flow through one resolved payload path. Carries the contract shape
through `sources/parsers/codex.py` and `sources/parsers/drive.py`.

Verification: ruff + mypy + pytest over provider models, source
laws, quarantine fixtures, resilience, and ingest-batch suites;
devtools verify green.

Ref #262
Sinity added a commit that referenced this pull request Apr 22, 2026
The source/provider seam carried path-dependent payload branching
across three adjacent layers: provider message adapters mixed open
dict plumbing with ad hoc normalization; `ingest_worker` duplicated
grouped-stream vs envelope parsing control flow; and the JSONL
emitter and Codex/Drive parsers repeated provider detection and
metadata shaping in slightly different forms. Strict-mypy-cleanable
but hiding runtime meaning behind loosely shaped containers and
repeated branches.

Rebuilds the provider message adapters in
`sources/providers/claude_code_models.py`,
`claude_code_record.py`, `codex.py`, and `gemini_message.py` around
explicit helper aliases and normalization helpers. Refactors
`pipeline/services/ingest_worker.py` to use typed parse-plan /
context records so grouped stream parsing and envelope parsing
share one orchestration path. Restructures `sources/emitter.py` so
grouped JSONL, individual payload, and raw-capture handling all
flow through one resolved payload path. Carries the contract shape
through `sources/parsers/codex.py` and `sources/parsers/drive.py`.

Verification: ruff + mypy + pytest over provider models, source
laws, quarantine fixtures, resilience, and ingest-batch suites;
devtools verify green.

Ref #262
@Sinity
Sinity requested a review from Copilot May 1, 2026 00:43
@Sinity
Sinity requested review from Copilot and removed request for Copilot May 1, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:parser Parser area:pipeline Pipeline tool:claude Claude type:refactor Code restructuring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant