Repository navigation
Conversation
…ts workflow Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rite changes a template rewrite_email_asset_url saved message template content directly, so a transactional template's workflow kept its old copy. Template saves from the API, the design patch and the rewrite now share one locked save-and-sync path in services/template_saves.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d draft Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A draft saved before a rewrite kept the old URL, and publishing it brought that URL back. The rewrite now finds and rewrites draft_content too. A draft-only rewrite saves the draft alone and writes no workflow version, because sends never read the draft. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rl rewrites The command rewrote workflows first, so by the time a transactional template synced its workflow the actions already matched and no new version was written. Message templates now run first, in every run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- when message templates are rewritten in the same run, the hog_flows pass rewrites only the drafts of workflows linked to a live template, so a template that fails keeps its workflow on the old URL and a rerun writes the new URL as a new version - save_locked_template takes an already-changed template; access checks and the change stay in save_template - --dry-run says it skips the sendability check - the new messaging code carries no docstrings or comments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- the hog_flows pass leaves only the workflows of templates this run matched to the template rewrite, so a drifted workflow or a run with --id <workflow id> rewrites the workflow's live actions - restore the comments and facade docstrings the template save move kept applicable Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e sync - the hog_flows pass protects the workflows of templates whose published content holds the old url, found before the run; a template matched only by its draft never syncs, so its workflow's live actions get rewritten in place Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pass - the hog_flows pass reads which workflows a template content rewrite syncs once the template pass is done, so a template deleted during the run no longer keeps its workflow's live actions on the old url - name the facade lookup after the rule it encodes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
🤖 CI report
|
| File | Comment lines | Added lines |
|---|---|---|
products/messaging/backend/services/template_saves.py |
7 | 85 |
products/workflows/backend/management/commands/rewrite_email_asset_url.py |
5 | 51 |
products/messaging/backend/services/message_templates.py |
3 | 19 |
products/messaging/backend/services/transactional_email.py |
1 | 10 |
This check does not block merging. It updates on every push and clears when the share drops.
✅ Hogbox preview — ready, open the preview
▶ Open the preview
| 🔑 Login | test@posthog.com / 12345678 (demo data) |
| 🧩 Running | this PR's backend on the PostHog :master base (frontend unchanged by this PR) |
| 🔗 Link | stable across rebuilds: a re-push swaps the box underneath, the URL stays |
| 🔒 Access | tailnet only (PostHog VPN) |
| 🛠️ Admin | inspect & debug state in hogland |
| 💤 Idle | sleeps after ~30 min idle (snapshot to S3, zero node cost) and wakes on your next visit in ~30s, behind a brief "waking up" screen |
commit a12f65d · box box-aca742611c74 · ready in 1770s (push → usable) · build log · rebuilds on every push, torn down on close
HostHog preview —
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lock The asset rewrite command decided once per pass which transactional workflows their template still owned. A template save between that lookup and a workflow's rewrite could put the old URL back into the template and its new workflow version, and the workflow pass then rewrote that version in place. The template kept the old URL while the workflow sent the new one. Each workflow row now locks the live template that syncs into it, checks its published content, and only then locks the workflow. That is the lock order a template save uses. A dry run makes the same check without the lock. Also covers a design edit of a transactional template that can no longer send: it is rejected and rolls back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With --id set to a workflow id, the template pass matches no template, so no template sync writes the workflow's new version. The per-row ownership check still found the linked template and rewrote only the workflow's draft, which left live sends on the old URL. The check now narrows templates by the same --id as the template pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 99b51d8: 1 Should fix.
See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.
… team An --all-teams rewrite checked each matched workflow against every message template, because transactional_hog_flow_id has no index. A template only syncs into a workflow of its own team, so filter on the workflow's team and use the team_id index instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Michael Closing: no user hits this today. It only affects a narrowed manual run of the asset URL rewrite command, and a default run already rewrites the workflows. The fix would reroute every template save, which isn't worth the risk. |
Moved from Silthus#571. It first opened as #118965.
Problem
rewrite_email_asset_url, a transactional template's sends can keep the old asset URL.--targets message_templatesor--id <template id>. A default run rewriteshog_flowsin place, so sends get fixed there, but the workflow gets no new version.Impact
Keeps transactional sends on the asset URL their template shows, after an operator moves an asset. Not measured; the command runs by hand. Expected move: none on a metric. Run cost: n/a.
Merge Danger
Caution
🔴 Merge risk: high · two-way door (merge-risk rubric)
Changes
services/template_saves.py: the API update, the design patch, and the rewrite command. It locks the template row, checks the workflow-editor permission, checks the template can still send, saves, and syncs the workflow.draft_content, added in feat(workflows): draft and publish edits to transactional email templates #118664). Before, a draft saved before a rewrite kept the old URL, and publishing it brought that URL back.team_idindex on an--all-teamsrun. When that template's published content still holds the old URL, the pass rewrites only the draft. Every other workflow gets its live actions and draft rewritten in place.--list-rowsand the summaries follow that order.--dry-runskips the check that a transactional template can still send: that check runs while the workflow version is built, which a dry run never writes.lock_transactional_workflow_id,check_transactional_update,update_templateandedit_content_lockedare gone. Nothing else called them.Rebase note
services/template_saves.pyuses the file, names and signatures Silthus/posthog#548 planned for the same orchestration. Silthus/posthog#548 is closed, so a later PR that adds a write intent or a content hash extends these functions. #118664's draft save keeps its own path, and a content save through the shared path still clears the draft.How did you test this code?
Lane gate on
a12f65d0cd, 2026-11-03: the rewrite command, template API and transactional email tests on a private database (133 passed), ruff, mypy on the changed files,tachandproduct:lintfor messaging and workflows. Not rerun on this head: repo-wide mypy and the frontend typecheck, which this backend-only change does not reach.CI report: comment density sits at the 3% warn line (16 of 486). Ten of the added comment lines are master's comments on the moved save code. The others say why a deleted workflow link stops restricting a template, why messaging rewrites its own rows, and why the workflow pass decides ownership per row under the template lock, within the run's
--id.Test rationale: one case in
TestTransactionalEmail(products/messaging/backend/tests/api/test_transactional_email.py) catches a rewrite that saves the template without syncing its workflow. The closest existing test,test_saving_a_transactional_template_writes_a_new_workflow_version, covers the API update only. The rewrite command tests inproducts/workflows/backend/test/test_rewrite_email_asset_url.pynever make a template transactional.rewrite_template_content, the messaging facade function the command calls for message templates, and the command itself for drafts.TestRewriteEmailAssetUrl(products/workflows/backend/test/test_rewrite_email_asset_url.py) catches a rewrite that skips a template whose draft alone holds the URL. Red before the fix: the command matched 0 rows.test_a_run_writes_one_new_version_of_a_transactional_templates_workflowintest_rewrite_email_asset_url.pyruns the real command twice, with the default targets and with--targets hog_flows,message_templates, and expects version 2 with the new URL. Red beforecc06f9d913(assert 1 == 2).test_a_failed_template_leaves_its_workflow_for_a_rerun_to_versionfails a template on an unverified sender, then reruns: version 1 with the old URL after the failure, version 2 with the new URL after the rerun. Red before9ad607cdf3: version 1 with the new URL.test_rewrites_a_transactional_workflow_in_place_when_its_template_sync_does_notcovers a default run, a--id <workflow id>run, and a template whose draft alone holds the old URL, each with a workflow whose live actions still hold it. Red before6b4248a7e8andea7ba66dfa: the workflow kept the old URL. Its fourth case runs--id <workflow id>while the template also holds the old URL. Red before99b51d88a6: only the draft changed.test_keeps_a_workflow_on_its_template_when_a_save_puts_the_old_url_back_mid_runsaves the old URL back into the template after the template pass. Red beforee220b6dd53: the workflow pass rewrote the save's new version in place.design_edit_after_the_category_became_marketingintest_rejects_an_update_that_would_stop_a_transactional_template_sending: a design edit of a template that can no longer send returns 400 and changes nothing. With the check stubbed out it returns 200.test_rewrites_the_workflow_of_a_template_deleted_during_the_rundeletes the template in place of its rewrite. Red beforea62991ca21: the workflow kept the old URL.assert 1 == 2).87d1b6befe: the rewrite command, template API and transactional email tests (128 passed), ruff, and the commit hook's ruff, format and ty checks.Live run
At
a12f65d0cd, 2026-11-03: the real command throughcall_commandon a migrated local database, with three templates made transactional first. The URLs arehttps://assets.example.com/live/{old,new}.png.--dry-run--id <workflow C>, template C still oldAn
--all-teamsrun over templates in two projects gives the same results: the dry run counts only the templates, each workflow gets version 2 through its template sync, and--id <workflow>rewrites in place.Earlier heads, on a local database, each template made transactional first. URLs are
https://assets.example.com/{old,new}.png.--id A--id B, row written by base code--targets message_templates, row written by HEADA second run covers a transactional template whose draft alone holds
https://assets.example.com/draft-old.png.--id A--id BNot run: the plugin server, so the worker reload after commit was not observed. It is scheduled with
on_commit, as the API save already does.Proofs (per
qa-swarmPROOF.md)a12f65d0cd(first table above). The two earlier tables come from earlier heads.Follow-ups
--from-urlwould make that visible.Release status
Docs update
None. The command's behavior is documented in its own help text, which is unchanged.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Agent: Claude Code, Claude Opus 5.5 (claude-opus-5-5)
tdd,/writing-tests,/writing-pr-descriptions,pr-description,modernize-pr,merge-risk.example.comURLs).Decisions
template_saves.pynames and signatures, so the rebase is a straight conflict resolution--targetssays, so the template sync writes the workflow versionInvolvement: no grilling rounds, no prototypes. Review: one GPT-6.1 Sol review (high effort) on
c90e0ca, no findings; one note on sender reuse corrected this description. Final GPT-6.1 Sol reads (high effort) of the rebase onto #118664 and of the draft rewrite found nothing. After the restack: GPT-6.1 Sol round 1 (one finding on the target order, fixed test-first) and a clean read of the fix. QA swarm on 2026-11-01: full panels in rounds 2 and 3 and a fixes panel in round 4 (GPT-6.1 Sol review lanes, Claude Opus 5.5 fresh eyes), every finding fixed test-first or answered, then final reads. After the move: a judge found the mid-run save race and the untested design-edit rejection, both fixed; a final read found the--idscope gap, fixed; PostHog Review found an unindexed per-row lookup, fixed; the last final read found nothing. Proof: a live run ata12f65d0cd, a production template read, and the shadow diff gap accepted.More context for AI agents
Revisions on the fork, before the move:
43333f81da9on 2026-10-31. Master added template tags in the same view and service; the API update now writes them through the shared save path, and6b455d0d27tests a save with tags and other fields.044401fec2names the draft-only save of a rewrite.cc06f9d913: the command now rewritesmessage_templatesbeforehog_flows, whatever order--targetsgives. Before, a default run rewrote the workflow in place first, so the template's sync found nothing to change and the workflow kept its version.9ad607cdf3,6b4248a7e8,ea7ba66dfaanda62991ca21, QA swarm 2026-11-01:hog_flowspass rewrites only the draft of a workflow whose live template's published content still holds the old URL when the pass starts. A template that fails keeps its workflow on the old URL, and a rerun writes the new URL as a new workflow version.--id <workflow id>run, still gets its live actions rewritten in place, as before this PR.save_locked_templatetakes an already-changed template; the access check and the change stay insave_template.--dry-runhelp says it skips the check that a transactional template can still send.After the move:
e220b6dd53: each workflow row checks its template underselect_for_updatebefore it locks the workflow, through the messaging facade'ssynced_content_contains. The pass-wide ownership lookup is gone.99b51d88a6: that check narrows templates by the run's--id, the same scope as the template pass.a12f65d0cd, for a PostHog Review finding: that check filters on the workflow's own team, not the run's teams, so an--all-teamsrun no longer scans every template per workflow. A template only syncs into a workflow of its own team, so no answer changes.🤖 Generated with Claude Code