Skip to content

feat: Await signals with Approval demo tab - #6

Open
themusicman wants to merge 17 commits into
mainfrom
feat/await-signals
Open

feat: Await signals with Approval demo tab#6
themusicman wants to merge 17 commits into
mainfrom
feat/await-signals

Conversation

@themusicman

@themusicman themusicman commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add PgFlow.Context.await_signal/2 and PgFlow.signal/3,4 so Job and Flow handlers can park as waiting and resume from a JSON payload (Oban-style buffer, last-write-wins, wait_for timeout).
  • Helpers V05: waiting on step_tasks, task_signals store, park/signal/consume/expire SQL. Parking does not consume a retry; stalled recovery still ignores waiting.
  • Emit [:pgflow, :worker, :task, :waiting]; PubSub maps it to {:task_waiting, ...} so LiveViews can show the parked state.
  • Demo: third homepage Approval tab (create_order → await_approval → charge) with Approve / Reject calling Client.signal/3. Reconcile overlays step_tasks.status = waiting if the live event is missed.

This is unrelated to signal_strategy / PgFlow.Signal.Notify (pgmq worker wake-ups).

Test plan

  • mix test test/pgflow/await_signals_test.exs test/pgflow/telemetry/pubsub_test.exs test/pgflow/context_await_signal_test.exs test/pgflow/queries/signals_test.exs test/pgflow/migrations/versions/v05_test.exs test/pgflow/client_test.exs
  • cd demo && mix test test/pgflow_demo_web/live/flow_demo_live_test.exs test/pgflow_demo/approval_flow_test.exs
  • After pull: recreate the test DB if helpers were at v04 (MIX_ENV=test mix ecto.drop && MIX_ENV=test mix ecto.create). Existing demo DBs need the same for V05.
  • Manual: cd demo && mix phx.server → Approval tab → Start Flow → Approve / Reject.

Notes

  • Timeout and early-buffer are in the handler source only (no homepage controls).
  • Dashboard waiting badge is out of scope for this change.

Capture the approved design for Oban-style await_signal/signal on
PgFlow: mid-handler pause, durable buffer, park as waiting, and
resume by run_id + step_slug.
Break the approved await-signals design into TDD tasks: helpers V05,
Queries.Signals, Context/Client API, worker park catch, timeout sweeper,
and Job/Flow coverage.
Park tasks with Context.await_signal/2, deliver payloads via
PgFlow.signal/3, and recover expired waits. Context includes
flow_slug/message_id for Worker.Server construction.
After merging step_states, overlay step_tasks with status waiting so
Approve/Reject still appear if the PubSub event was missed. Snapshot
started remains running.
@themusicman themusicman changed the title docs: Spec and plan awaiting signals feat: Await signals with Approval demo tab Aug 22, 2026
themusicman and others added 8 commits August 22, 2026 07:06
Keep the scheduled article_flow_cleanup job off Article, Onboarding, and Approval pages.
- Make signal consumption and parking atomic with fenced retries and timeout-safe delivery
- Settle terminal waits, recover expired tasks, and preserve claimed payloads across retries
- Add version-aware V05 upgrades, rollback safeguards, and startup schema compatibility checks
- Harden signal APIs, worker handling, demo reconciliation, and public documentation
- Cover concurrency, migration, recovery, and approval flows with database-backed tests
@themusicman
themusicman marked this pull request as ready for review August 27, 2026 20:22

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

ℹ️ 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".

</form>

<div class="mt-4 flex items-center justify-between">
<form

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Build the approval form with the shared form component

When the Approval tab renders, this new raw <form> bypasses the demo application's required Phoenix.Component.form/1 abstraction, leaving this flow inconsistent with the shared form behavior and future field/error handling. Replace it with the imported <.form> component while preserving the ID and submit event.

AGENTS.md reference: demo/AGENTS.md:L140-L140

Useful? React with 👍 / 👎.

Comment on lines +42 to +43
%{id: :await_approval, lines: 24..32, clickable: true},
%{id: :charge, lines: 34..43, clickable: true}

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 Align the approval DSL slices with the source

When the Approval tab displays its DSL, these ranges do not match approval_flow.ex: await_approval continues through line 34, while charge starts at line 36 and continues through line 47. The current slices therefore omit the await handler's closing lines, attach an unrelated end to the charge segment, and truncate most of the charge result, so users see malformed and incomplete example code.

Useful? React with 👍 / 👎.

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.

2 participants