feat(seo): atomic directive fencing and transactional blog publication
Deploy Canina / deploy (push) Successful in 4m45s

This commit is contained in:
Canina Automation committed 2026-10-28 08:02:30 +00:00
1 parent 0a156fd7b4
commit fb1deadbbc
10 files changed
+353 -187

No files matched your search

+23 -25
View File
@@ -89,7 +89,7 @@ class Consumer:
if packet.get('ceoFeedback') is not None and not isinstance(packet['ceoFeedback'], str):
raise Blocked('Invalid directive')
def publish(self, run, packet, draft, review, publisher_create):
def publish(self, run, packet, draft, review, publication_preflight):
"""Caller must preserve existing ownership/QA/backup/quota/intent guards.
packet is the complete research/directive supplied to Content before drafting.
@@ -111,39 +111,37 @@ class Consumer:
('claiming', digest(draft), json.dumps(review), run, 'prepared')).rowcount
if changed != 1:
raise Blocked('Another consumer owns action')
# Atomic Backend predicate rejects edits between fetch and claim.
claim = self.api('PATCH', BASE + '/' + packet['id'] + '/action',
dict(expectedVersion=packet['version'], feedbackVersion=packet['feedbackVersion'], actionId=run))
self.check_packet(claim)
if claim['feedbackVersion'] != packet['feedbackVersion']:
raise Blocked('Unexpected claim response')
# Preflight MUST preserve existing ownership/QA/backup/quota/intent
# guards, but must NOT create a Blog. Only this atomic endpoint writes.
reviewed_hash = digest(draft)
payload = publication_preflight(draft)
if not isinstance(payload, dict) or digest(payload) != reviewed_hash:
raise Blocked('Preflight must return the exact reviewed Blog payload')
with self.db() as db:
db.execute('UPDATE runs SET state=? WHERE run=?', ('publication_intent', run))
blog = publisher_create(draft) # No retry on exception or uncertain result.
if not isinstance(blog, str) or not blog:
raise Blocked('Missing blog identity; reconcile publication intent')
result = self.api('POST', BASE + '/' + packet['id'] + '/publication',
dict(expectedVersion=packet['version'],
feedbackVersion=packet['feedbackVersion'], actionId=run, blog=payload))
blog = result.get('blog', {}).get('id')
if (not isinstance(blog, str) or not blog or
result.get('consumedFeedbackVersion') != packet['feedbackVersion']):
raise Blocked('Missing committed publication identity; reconcile, never retry')
with self.db() as db:
db.execute('UPDATE runs SET state=?,blog=? WHERE run=?', ('created', blog, run))
self.reconcile_link(run)
db.execute('UPDATE runs SET state=?,blog=? WHERE run=?', ('linked', blog, run))
return blog
def reconcile_link(self, run):
"""Read-only repair of an ambiguous response; never creates or relinks."""
row = self.row(run)
if row['state'] == 'linked':
return row['blog']
if row['state'] != 'created' or not row['blog']:
raise Blocked('No confirmed created article; authenticated reconciliation required')
packet = json.loads(row['packet'])
if row['state'] != 'publication_intent':
raise Blocked('No publication intent; independent reconciliation required')
current = self.api('GET', BASE + '/' + row['finding'])
self.check_packet(current)
if current['feedbackVersion'] != packet['feedbackVersion']:
raise Blocked('Directive changed after create: retain blog, independent repair required')
if current.get('blogId') not in (None, row['blog']):
raise Blocked('Finding already linked to another article')
if current.get('blogId') != row['blog']:
self.api('PATCH', BASE + '/' + row['finding'] + '/action',
dict(expectedVersion=current['version'], feedbackVersion=current['feedbackVersion'],
actionId=run, blogId=row['blog']))
if current.get('actionId') != run or not current.get('blogId'):
raise Blocked('No matching committed action; never retry automatically')
with self.db() as db:
db.execute('UPDATE runs SET state=? WHERE run=?', ('linked', run))
return row['blog']
db.execute('UPDATE runs SET state=?,blog=? WHERE run=?',
('linked', current['blogId'], run))
return current['blogId']