Skip to content

refactor(pedagogy): split dialogue_manager turn.rs into responsibility submodules#320

Merged
hherb merged 4 commits into
mainfrom
refactor/split-dialogue-manager-turn
Jul 2, 2026
Merged

refactor(pedagogy): split dialogue_manager turn.rs into responsibility submodules#320
hherb merged 4 commits into
mainfrom
refactor/split-dialogue-manager-turn

Conversation

@hherb

@hherb hherb commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Behaviour-preserving split of primer-pedagogy/src/dialogue_manager/turn.rs (746 lines — the largest un-feature-gated production file after #305/#318) into a directory module, following the same recipe as the wiring.rs (#305) and state_machine.rs (#318) splits. Every file is under the 500-line guideline:

file lines contents
turn/mod.rs 138 module doc + respond_to / respond_to_streaming orchestrator
turn/prompt.rs 132 record_child_turn, build_turn_prompt, record_primer_turn
turn/stream.rs 137 StreamOutcome, stream_inference_response, run_recovery_loop
turn/persist.rs 98 persist_turn, spawn_embedding_task
turn/spawn_tasks.rs 284 spawn_classification_task, spawn_post_response_task

All method bodies and doc comments are verbatim relocations. Only three kinds of mechanical change:

  • Imports — the deeper submodules use absolute crate::dialogue_manager::… paths instead of the old parent-relative super::… (per the established recipe, avoiding super::super:: chains).
  • Visibilitybuild_turn_prompt widens from pub(super) to pub(in crate::dialogue_manager): the old pub(super) resolved to dialogue_manager (where tests/turn_tests.rs calls it directly); after moving one level deeper the explicit path restores the same effective reach. stream_inference_response narrows to file-private (its only caller, run_recovery_loop, moved with it). Everything else keeps pub(super), now resolving to turn.
  • Zero churn in test filesturn_tests.rs (1178 lines) untouched.

CLAUDE.md: the dialogue_manager module-layout note now describes the turn/ sub-split, and two stale turn.rs path references were fixed (the i18n stream_inference_response note and the small-context-budget call-site list). README/ROADMAP need no change (internal refactor; verified no references).

Verification

  • cargo test -p primer-pedagogy: 216 passed / 0 failed — identical to the pre-split baseline recorded before touching anything.
  • External pub-surface diff (old turn.rs vs concatenated new submodules, incl. type): empty (respond_to, respond_to_streaming).
  • cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo fmt --all -- --check: clean.
  • Full cargo test --workspace: 51 × test result: ok, 0 failures (matches the prior session's count).

🤖 Generated with Claude Code

…y submodules

Behaviour-preserving split of the 746-line per-turn hot path into a
directory module, every file under 500 lines:

- turn/mod.rs (138) — module doc + the respond_to / respond_to_streaming
  orchestrator.
- turn/prompt.rs (132) — record_child_turn, build_turn_prompt,
  record_primer_turn. build_turn_prompt is exercised directly by
  dialogue_manager/tests/turn_tests.rs, so its visibility widens from
  pub(super) to pub(in crate::dialogue_manager) — same effective reach
  as before the move (the old pub(super) resolved to dialogue_manager).
- turn/stream.rs (137) — StreamOutcome, stream_inference_response
  (now file-private; its only caller moved with it), run_recovery_loop.
- turn/persist.rs (98) — persist_turn + spawn_embedding_task.
- turn/spawn_tasks.rs (284) — spawn_classification_task +
  spawn_post_response_task.

All method bodies and doc comments are verbatim relocations; only
imports, visibility qualifiers, and the previously parent-relative
super:: paths (now crate::dialogue_manager::…) changed. External pub
surface identical (respond_to, respond_to_streaming). Zero churn in the
test files.

Verification: cargo test -p primer-pedagogy 216 passed / 0 failed
(identical to pre-split baseline); workspace clippy -D warnings clean;
fmt clean; full workspace suite 51 x "test result: ok", 0 failures;
pub-surface diff empty.

CLAUDE.md: dialogue_manager module-layout note updated + two stale
turn.rs path references fixed (stream_inference_response,
effective_context_window_turns call site).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 2, 2026

Copy link
Copy Markdown

Deploying primer with  Cloudflare Pages  Cloudflare Pages

Latest commit: e8c6232
Status: ✅  Deploy successful!
Preview URL: https://368f9aaa.primer-10b.pages.dev
Branch Preview URL: https://refactor-split-dialogue-mana.primer-10b.pages.dev

View logs

hherb and others added 3 commits July 2, 2026 23:03
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Two findings from the PR #320 review:

- StreamOutcome's pub(super) was a carry-over from the flat turn.rs;
  after the split its only producer (stream_inference_response,
  file-private) and consumer (run_recovery_loop, returns
  Result<String>) both live in stream.rs, so plain private is the
  accurate visibility.

- CLAUDE.md's dialogue_manager bullet still told future sessions to
  use pub(super) for cross-module access unconditionally, but inside
  turn/ submodules pub(super) resolves to turn, not dialogue_manager;
  amended with the pub(in crate::dialogue_manager) escape hatch for
  helpers a top-level sibling or the tests/ files must reach.

Verified: cargo test -p primer-pedagogy 216/0, workspace clippy
-D warnings clean, fmt clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@hherb hherb merged commit 621ba35 into main Jul 2, 2026
11 checks passed
@hherb hherb deleted the refactor/split-dialogue-manager-turn branch July 2, 2026 22:30
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