Publishing to a channel: draft, approval, delivery and reconciliation

Tie approval to an immutable post revision and recover delivery when a message may exist without an acknowledgement.

A departing boat and a route hidden by fog suggest delivery with an uncertain outcome.

An author approved a short telescope post for a science channel. While the job waited in a queue, someone changed the text or switched the destination channel. The worker loaded the current draft and sent it. Delivery might have succeeded technically, yet the channel received something the author had never approved. A second problem appears after a timeout: readers may already see the message even though the application received no acknowledgement.

These situations need a shared protocol. It must preserve the author's decision, support controlled delivery and represent an uncertain outcome honestly. Consider an independent teaching model with two fictional bots, two synthetic channels and short text posts. The application store and the local adapter's separate database run on MySQL 8.4/InnoDB through native PDO MySQL. The adapter stands in for the external channel and sends no real messages.

Approval belongs to a particular revision

A draft is mutable working material. An approved publication is a stored snapshot of a decision. In this example, the snapshot contains the draft identity, its revision, the bot, the channel and the exact text. A real post would also include formatting mode, buttons, media and link preview settings within that boundary: anything that changes the content or its delivery.

The worker receives the snapshot. It does not reload the current text using only a draft_id. Otherwise, editing the draft after clicking Approve would silently replace what the author agreed to. For media, storing a URL is insufficient if different bytes can appear there tomorrow; the attachment itself needs a stable revision.

In the model, note-a has revision 1, and the approved intent receives the identity release-a. Repeating approval for the same revision returns the same release. Uniqueness of the draft–revision pair also protects against another click carrying a different command key. This protection operates inside the teaching database and adds no capabilities to an external API.

Changing the text, bot or channel increases the revision. If the previous snapshot is still awaiting delivery, it becomes cancelled. The new revision needs new approval. The old snapshot retains its original values; a MySQL trigger also prevents updates to them by rejecting a violation with SIGNAL SQLSTATE '45000'. The error propagates to the caller, and the operation rolls back the transaction it owns. This helps expose a mistake in another write path, while database administrator access remains a separate trust boundary.

Permission and delivery outcomes have separate lives

Approved answers whether delivery of a particular snapshot may begin. It says nothing about a message being present in the channel. Even a single author benefits from this separation: they can permit an action now, execute it later and see exactly where it stopped.

Delivery state What is known Next step in the model
queued The intent and snapshot are stored A worker may claim the job
sending One attempt has permission to work Wait for its observation
waiting The attempt is known to have created no message; a later retry is permitted Wait until the specified time
uncertain A message may exist Reconcile without sending again
delivered An acceptable receipt exists for this snapshot and destination Show the known outcome
refused A final refusal occurred or the local retry budget was exhausted Return the reason to the author
cancelled Waiting was cancelled before the attempt was claimed Do not dispatch this revision

The two reasons behind refused are recorded separately as evidence. Exhausting a local budget does not mean the provider has permanently prohibited the operation. The interface should explain the specific reason rather than turning a shared state name into an invented diagnosis.

The outbox stores intent before a network action begins

Before the scenarios run, the shared App\Infrastructure\MysqlLab prepares isolated disposable schemas in the guarded MySQL lab fixture; a separate migrator explicitly creates the InnoDB tables, foreign keys, CHECK constraints and triggers. Initialization finishes before business transactions: MySQL DDL can commit implicitly, so this is neither an atomic schema upgrade nor automatic data migration from the old SQLite database. At runtime, the application performs DML only and has no CREATE, ALTER or DROP privileges. Approval and creation of the delivery record happen in one InnoDB transaction. Once it completes, the work has a durable identity even if the process stops before notifying the queue. The queue can wake a worker, while periodic outbox reading can recover a missed signal. Directly requesting a known release is sufficient for the small teaching example.

Before calling the adapter, the worker uses a short transaction to move the record to sending, increment its attempt count and obtain a random token. InnoDB row locks coordinate access to the record; a subsequent claim attempt checks the stored state. Saving an outcome checks the token against the current owner. Under REPEATABLE READ, a lock wait or deadlock can produce native MySQL errors 1205 or 1213; the InnoDB error-handling documentation explains their transaction behavior. The error propagates to the caller with rollback of the transaction the operation owns; it should not be recorded as a channel refusal.

The adapter runs after commit. Keeping the transaction open during a network wait would block local changes for longer without creating shared atomicity with the channel. The example's two separate databases make that boundary visible: storing the message and storing its delivery receipt have different commits.

A timeout leaves two possible worlds

In one world, the request never reached the provider. In the other, the provider created the message but the response was lost. Both can end in the same timeout for the client. An ordinary automatic retry has different consequences: it recovers the missing action or creates a duplicate.

RFC 9110, section 9.2.2 ties a safe automatic retry of a non-idempotent operation to additional knowledge about its semantics or its non-application. An HTTP method name or an internal job number does not supply that knowledge by itself.

The local fake therefore has two distinct modes: store a message and lose the acknowledgement, or return ambiguity without storing anything. Both leave uncertain. An empty inspection result in the second mode does not enable an automatic retry: in a real integration, a search could be incomplete and the previous attempt could still be running.

The model chooses a conservative trade-off: uncertain delivery also blocks editing that logical post. Otherwise, new approval could bypass the prohibition on retrying the old one. A separate correction or a deliberate resend needs a domain decision that explains the possibility of a duplicate.

A receipt must belong to the right message

Telegram sendMessage returns a Message on success. In this model, acceptable confirmation contains a positive message identifier and a link to the specific release, bot, channel and snapshot. A plain success label is insufficient.

A result for another channel cannot confirm the current delivery. Likewise, a receipt from an earlier post with identical text must not close a new intent. These relationships are explicit fields in the fake. In a real adapter, some context comes from the request and some from the validated response; that correspondence needs its own contract.

The transport supplies an observation, and the model determines the permitted transition. A known final refusal ends the attempt. A temporary refusal with no external effect may permit waiting. An HTTP code, exception or delay hint alone cannot establish that a message was definitely not created. An unexpected or contradictory result preserves uncertainty.

Retries have a bounded budget

The teaching policy permits at most three attempts for one release. After a temporary refusal, the fake asks for a wait of 10 synthetic seconds. The time check happens before the record can be claimed again, so frequent deliveries of the same queued job cannot bypass the pause.

These numbers were chosen to make the example understandable. They are not Telegram limits. ResponseParameters describes retry_after; a real integration must account for its meaning alongside its own rate and budget constraints. Permission to retry is determined separately from the time of the next attempt.

If the author edits the draft while its release is waiting, the old record is cancelled. Redelivering the old job does not revive it. The transport pause remains attached to specific approved content.

Cancellation has a timing boundary

While a record is queued or waiting, cancellation can reliably prohibit its next claim. If a worker moved it to sending first, local cancellation can no longer promise that no message will appear. The teaching model rejects that command with an explanation of the boundary.

Editing or deleting an already sent message is a different operation. It needs its own permission, message address and outcome tracking. Cancel in an admin interface should not simultaneously mean stopping a wait and silently deleting something readers might already have seen.

Claim expiry is not evidence of non-execution either. On expiry, sending becomes uncertain. A new worker receives no permission to resend. The late original worker cannot overwrite that state through ordinary completion; a useful receipt must pass through reconciliation.

Reconciling an uncertain outcome

The model supports only positive reconciliation: a confirmed message can be linked to the same approved intent and recorded as delivered. In the local exercise, inspection of the separate fake database provides the evidence. It deliberately has more information than an ordinary HTTP call.

That inspection does not represent a Telegram method for looking up a message by our release_id. Such a capability cannot be assumed without a separate contract. In a product, an operator may need to inspect the channel, use a stored identifier, correlate an event or obtain other reliable evidence. Simply failing to find the message leaves the question open, particularly while the previous worker might still be active.

The fake intentionally inserts a new row for every accepted call. Bypassing the model and calling it twice creates two messages. This helps test that protection comes from the application's decision order rather than hidden idempotency in the test substitute.

How recovery was tested

On MySQL 8.4, the example ran 27 PHP scenarios and a separate recovery scenario with four child PHP processes, which exited with codes 0, 73, 0 and 0. Exit 73 marked a stop after the fake channel committed the message but before delivery was finished in the application database. Fresh independent reads through native PDO MySQL showed queued → sending → uncertain → delivered: attempt counts were 0, 1, 1, 1 and fake-channel message counts were 0, 1, 1, 1. Positive reconciliation did not cause another send.

The scenarios cover a changed destination, a contradictory receipt, cancellation in both orders, a late worker and retry exhaustion. Two sequential claim attempts through separate native connections to the same MySQL schema check stored state. The exercise uses separate InnoDB stores for the application and the fake, with positive evidence from the fake. This tests recovery after a process stops; it does not establish behavior for real Telegram, provider lookup, simultaneous worker execution or power loss.

Integrating the model into an application still requires authentication, the author's current permissions, an approval interface, a transport adapter, content constraints and an evidence retention policy. The teaching model operates at a trusted application boundary. Its main value is a clear answer at each stage: what content may be delivered, who currently owns the attempt and exactly what is known about the message afterwards.

The shared MySQL fixture and its files are introduced in the transaction chapter. Run commands from the single article_demo root; do not create a separate Symfony application for each article.

Check the current example against an owned disposable MySQL schema:

bash fixtures/mysql_labs/run.sh php vendor/bin/phpunit tests/ChannelReleaseLab
  1. Databases The article was saved but the event was not sent: why use a transactional outbox
  2. Platform Engineering Timeout after an external request: when the outcome is unknown
  3. Knowledge & AI AI prepares the publication, a human decides: preserving the exact approved version