Skip to content

[Parked] Source/Consumer block relationship — reference branch for Jared#174

Draft
dconnenc wants to merge 1 commit into
mainfrom
block-sources-refactor
Draft

[Parked] Source/Consumer block relationship — reference branch for Jared#174
dconnenc wants to merge 1 commit into
mainfrom
block-sources-refactor

Conversation

@dconnenc

Copy link
Copy Markdown
Owner

Status: Draft, parked

This branch is a fully-working implementation of a Source/Consumer block model. It's pushed as a draft for context, not for merging. The simpler parent/child + flatten approach lives in #173 (block-lifecycle-decouple) — that's the one to review for the immediate need.

I'm posting this branch as reference in case the parent/child approach turns out to be limiting later, or to inform whatever direction GuessWho's overhaul takes.

Context (for @jared)

You mentioned that the original codebase had a graph-style model (variables + bindings) that you intentionally simplified down to parent/child because the upkeep wasn't paying off. When I came in not knowing that history, my first instinct was to build a Source/Consumer model — essentially the same direction you'd already moved away from.

After you flagged this, we changed course: I parked this branch and took your suggested path — try parent/child + ordering first, and only revisit the heavier model if friction shows up. That work is in #173.

The original requirements from the user were:

  1. Broadcast FamilyFeud questions earlier in the experience (independent of when FamilyFeud itself runs)
  2. Allow GuessWho to consume the same questions/answers

Requirement 1 is met by the parent/child + lifecycle-decouple approach in #173. Requirement 2 is already satisfied today through GuessWho's existing slides[].block_id payload references and ParticipantSubmissions.for_user, which query all blocks regardless of nesting.

What this branch contains

If we ever need cross-consumer reuse of source blocks (one Poll feeding both a FamilyFeud and a GuessWho simultaneously, surfaced in the UI), this branch has a working implementation:

Schema

  • Adds source to the block_link_relationship enum on ExperienceBlockLink
  • Drops the global unique constraint on child_block_id so a block can be linked from multiple consumers
  • Adds position for ordering within a consumer

Backend

  • New sources/consumers associations on ExperienceBlock (scoped to the source relationship; existing children/parents stay scoped to depends_on)
  • Orchestrator#attach_source!, #detach_source!, #reorder_sources! endpoints under /blocks/:id/sources
  • start_family_feud_playing! reads from block.sources rather than block.child_blocks

Frontend

  • Core/SourcesPanel — pure presentational component with attach/detach/reorder, plus Storybook stories
  • useBlockSources hook
  • Wired into EditBlock for FamilyFeud — host can attach Question/Poll blocks as sources

Tests

  • 344 specs pass on this branch (the snapshot when I pushed); tsc + storybook clean

When this might be worth revisiting

  • GuessWho overhaul lands and needs explicit "use these specific questions as sources" semantics
  • A new block kind needs many-to-many fan-in (multiple consumers reading from the same source)
  • Visual UI for "which blocks does this consumer depend on" becomes a user-facing requirement

For now, the simpler change in #173 is the recommended path.

🤖 Generated with Claude Code

Adds a "source" relationship type on ExperienceBlockLink alongside
the existing "depends_on". A consumer block (e.g. FamilyFeud) can
have many top-level blocks attached as sources, allowing those
source blocks to be sequenced and broadcast independently of when
the consumer runs.

Backend
- Migrations: add "source" to the relationship enum, drop the global
  unique constraint on child_block_id (sources can feed multiple
  consumers), add position column for ordering within a consumer.
- ExperienceBlockLink: scopes + uniqueness scoped per relationship;
  cycle/depth/parent_id-sync gated to depends_on only.
- ExperienceBlock: new sources/consumers associations; existing
  children/parents scoped to depends_on.
- Orchestrator: add_block_with_dependencies! accepts source_block_ids;
  new attach_source!, detach_source!, reorder_sources! verbs;
  FamilyFeud lifecycle methods read from sources, not child_blocks.
- Visibility: dag_metadata exposes source_block_ids, consumer_block_ids,
  and serialized sources. responded_participant_ids includes source
  responses for active consumers.
- Routes/controller: /blocks/:id/sources endpoints; question-response
  broadcast finds FamilyFeud consumers via consumer_links.

Frontend
- Types: BlockLink.relationship adds 'source'; BaseBlock gets
  source_block_ids/consumer_block_ids/sources.
- New Core/SourcesPanel with attach/detach/reorder + Storybook stories.
- New useBlockSources hook.
- EditBlock renders a SourcesPanel for FamilyFeud blocks.
- FamilyFeudManager + EditBlockContext read from block.sources.

Tests
- Factory updates source attachment.
- Spec updates: FamilyFeud open/close/hide no longer cascade to source
  questions (independent lifecycle by design).
- 344 specs pass; tsc clean; storybook builds.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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