Skip to content

agents: preserve indexed Pydantic text replacements - #966

Merged
yisding merged 2 commits into
mainfrom
agent/pydantic-text-part-replacement
Aug 9, 2026
Merged

agents: preserve indexed Pydantic text replacements#966
yisding merged 2 commits into
mainfrom
agent/pydantic-text-part-replacement

Conversation

@yisding

@yisding yisding commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Problem

PR #961 restored initial PydanticAI TextPart content, but the bridge still
normalized every part start as an append-only text_delta and discarded
PartStartEvent.index. PydanticAI may emit another start for the same index as
a replacement, so consumers could retain stale text or append duplicate text.

What changed

  • extend AgentBridgeEvent with indexed text events and a text_replace kind
  • preserve PydanticAI part indexes for starts and deltas, including repeated
    same-index starts and graph-local index namespaces
  • use one canonical text-part accumulator across bridge, runner, stage, text,
    and voice consumers so transcripts and history preserve replacement semantics
  • expose replacement metadata through AgentDelta and journal records
  • define TTS behavior: repair replacements while text is buffered; once speech
    is admitted, cancel and clear stale playback and suppress further TTS for the
    turn while allowing the corrected transcript and history to complete
  • document the bridge contract and add regression coverage for same-index starts,
    buffering, playback cutoff, graph streams, and consumer history

Impact

Ordinary unindexed text_delta streams remain append-only. Indexed bridges must
use indexed deltas consistently within a turn. A divergent replacement after
TTS admission fails closed instead of replaying corrected text over speech the
caller may already have heard.

Verification

  • 368 passed across the focused bridge, PydanticAI, stage, session consumer,
    event, and lifecycle suites
  • just guard-contracts (218 passed)
  • .venv/bin/ruff check src tests
  • .venv/bin/ruff format --check src tests
  • .venv/bin/mypy src/easycat (289 source files)

Follow-up to #961.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@yisding, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a4259ca3-6b5d-410a-816a-a63b162327ee

📥 Commits

Reviewing files that changed from the base of the PR and between 5c22bb1 and adf36ca.

📒 Files selected for processing (41)
  • docs/architecture.md
  • docs/development/04-agents-and-interruption.md
  • docs/extending/agent-bridge.md
  • docs/public-api.md
  • docs/reference/events.md
  • docs/reference/journal-records.md
  • perf/bench_agent_delta_tts_overlap.py
  • src/easycat/debug/_turn_timeline.py
  • src/easycat/events.py
  • src/easycat/integrations/agents/_agent_runner.py
  • src/easycat/integrations/agents/_pydantic_ai_events.py
  • src/easycat/integrations/agents/_text_stream.py
  • src/easycat/integrations/agents/base.py
  • src/easycat/integrations/agents/pydantic_ai.py
  • src/easycat/integrations/agents/template.py
  • src/easycat/session/_journal_sink.py
  • src/easycat/session/_session.py
  • src/easycat/session/_streaming.py
  • src/easycat/session/_turn_runner.py
  • src/easycat/session/_wiring.py
  • src/easycat/stages/agent.py
  • src/easycat/testing/_bridge_lifecycle.py
  • src/easycat/testing/contracts.py
  • tests/debug/test_turn_timeline.py
  • tests/events/test_events.py
  • tests/integrations/agents/examples/test_example_pydantic_ai_agent.py
  • tests/integrations/agents/examples/test_example_pydantic_ai_graph.py
  • tests/integrations/agents/test_agent_runner.py
  • tests/integrations/agents/test_bridge_protocol.py
  • tests/integrations/agents/test_bridge_transitions.py
  • tests/integrations/agents/test_pydantic_ai_bridge_cancellation.py
  • tests/integrations/agents/test_pydantic_ai_v2.py
  • tests/ratchets/complexity-baseline.json
  • tests/ratchets/turn-commit-manifest.json
  • tests/runtime/test_journal_record_contract.py
  • tests/session/_wiring_helpers.py
  • tests/session/test_journal_sink.py
  • tests/session/test_session_lifecycle_teardown.py
  • tests/session/test_session_streaming_behavior.py
  • tests/session/test_session_streaming_consumer.py
  • tests/testing/test_contract_kit.py

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.

@yisding
yisding marked this pull request as ready for review August 8, 2026 05:15

@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: ffa659a17c

ℹ️ 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/easycat/integrations/agents/pydantic_ai.py Outdated
Comment thread src/easycat/session/_session.py
- namespace part indexes per model-request node stream in iter mode so a
  post-tool response cannot replace already-spoken text and silence the turn
- allocate fresh parts for v1 one-arg graph events (stream boundaries are
  undetectable there) sharing one run-scoped counter with v2 streams
- reconstruct fallback transcripts with part semantics so TEXT_REPLACE
  journal records are honored by debugger and bundle tooling
- update the shared wiring test helper for the new replacement cutoff field
- clear playback suppression when a spoken application turn is admitted
- refresh the perf benchmark baseline hook, turn-commit and complexity
  ratchets, and the journal record catalog snapshot

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@yisding
yisding merged commit cbdaf54 into main Aug 9, 2026
18 checks passed
@yisding
yisding deleted the agent/pydantic-text-part-replacement branch August 9, 2026 01:44
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