Worked Examples
Apply event and workflow provenance — Sustainable Catalyst Platform Core
Apply event and workflow provenance — Sustainable Catalyst Platform Core Application: Sustainable Catalyst Platform Core Status: Useful first draft, not a production-verified procedure. Purpose Preserve causal ordering, idempotenc
Application: Sustainable Catalyst Platform Core
Component: Event and workflow provenance; cross-service continuity
Source baseline: 59b8444365525a58fd4f6a7e29a20d712769e1a2 (repository main, November 7, 2026)
Documentation status: Source-reviewed operational guidance; staging acceptance pending
Estimated reading time: 17 minutes
Summary: Preserve the sequence and meaning of research-workflow changes across services. Use stable operation identities, explicit causal dependencies, provenance references and independently verified retry behavior so a duplicated request cannot create a second authoritative research event.
Goal
Establish an inspectable event history for a project, workflow and cross-service handoff while keeping execution attempts, authoritative state transitions, stream notifications and scientific evidence separate. The primary acceptance criterion is:
Replaying or retrying the same logical operation must not create another authoritative research event or silently change the accepted workflow state.
A trace ID identifies a request or span; it is not an idempotency guarantee. A timestamp helps locate an event; it is not sufficient to prove causal ordering. A hash checks the representation of content; it cannot establish that a scientific interpretation is correct.
Requirements
- Access to an approved isolated staging clone, plus an explicit change owner and deployment inventory. Use synthetic objects only.
- Exact project, workflow, service, actor and resource identifiers; a source commit, schema revision and rights/publication classification.
- Operator authorization for the required route. Some Core internal writes require
X-SC-API-Key; never expose this secret in public documentation. - Independent access to persisted state, workflow transition or event history, stream cursor, accepted outputs, and sanitized operational logs.
- A fixed logical operation ID or idempotency key, persisted alongside the result and enforced atomically by the authoritative writer. This is a proposed deployment control, not a verified universal Core feature.
Procedure
- Classify the action: Determine whether the event describes a workflow step, research transition, connector queue item, notification, approval or external computation.
- Locate authority: Identify which service and database owns the accepted state. Record its actual route, schema, commit and configured release; do not infer authority from a UI button or notification.
- Record intent: Capture the tenant/project/workflow, operation key, canonicalized request digest, expected prior state/revision, actor identity, source references, and required capability checks.
- Evaluate preconditions: Verify authorization, expected revision, prerequisites and required handoff evidence before a mutation.
- Commit once: The authoritative service must atomically reserve the operation key, apply a single transition, and persist the result and audit/outbox record; otherwise a crash can split state from its event.
- Handle retries: Repeating an accepted key with the same digest should return the original accepted result without a new authoritative event. A different digest under the same key must fail.
- Check causal order: Confirm parent operations exist, required dependencies finished, and immutable source/output references resolve to the accepted revisions.
- Independently retrieve: In a fresh permitted session, inspect the accepted state and history; compare authoritative event IDs, revisions and content hashes.
- Prove failure behavior: Repeat with a stale revision, revoked actor, foreign project, duplicate request and broken dependency. Confirm denied cases do not alter accepted records.
- Preserve evidence: Store a redacted receipt with source commits, test IDs, timestamps, actual status codes, state hashes, and explicit production limitations.
Symptoms
- Two workflow transitions or research events appear for one user action after retry.
- The stream shows a completion event but the authoritative project state remains incomplete—or the state changed but no notification appears.
- Subscribers lose events after reconnecting, or receive them more than once.
- An execution is marked complete despite a missing or unverified cross-runtime handoff.
- A dead-letter replay produces another work item whose output is wrongly counted as a second approved result.
- Event metadata references the wrong workflow, project, tenant, actor, revision or source object.
- Logs contain a successful HTTP response without an accepted-state receipt, or a failure without a stable request identifier.
Cause
Common causes include at-least-once delivery mistaken for exactly-once processing, absent operation-key uniqueness, a database commit preceding event/outbox persistence, nontransactional downstream effects, lease expiry while a worker is still running, unsafe automatic retries, incorrectly inferred causal order, mutable event references and conflated authorization/publication flags.
These mechanisms are separate in the inspected Core implementation. The reliability worker creates a fresh queued item for dead-letter replay. Stream events have persisted IDs suitable for cursor-based observation, but those IDs do not prove that a business operation executed exactly once. The cross-runtime package contract rejects duplicate event IDs within one package, but does not by itself enforce global deduplication across databases.
Troubleshooting
- Anchor the request. Correlate the sanitized
X-Request-ID(if available), workflow run, stage key, operation key, queue work-item ID and output hash. These IDs serve different purposes. - Confirm the authoritative write. Read the canonical workflow record and transition history before interpreting stream messages or cached UI state.
- Look for duplicate effects. Group transitions by logical operation identity and payload fingerprint; two distinct authoritative transitions indicate a release blocker until reconciled.
- Inspect ordered dependencies. Compare required step completion, declared transition, handoff state and evidence/revision references; do not equate monotonically increasing message IDs with cause.
- Check worker history. Review lease owner/expiry, attempts, pending/dead-letter states, replay count and ingestion run IDs; determine whether both attempts produced external effects.
- Differentiate errors. Resolve missing credentials, blocked prior steps, invalid transition or unavailable integration without blindly repeating writes.
- Verify disclosure. Inspect public projections and event streams for private objects and secret-like metadata, even if the top-level workflow is marked public.
Resolution
Contain first: suspend the affected mutating route, worker, replay or publication path through the approved runbook; retain the database and append-only logs; record the current state/hash. Do not delete history or replay a failed operation before establishing whether the first attempt committed.
Repair the cause: implement an atomic uniqueness constraint for the logical operation and tenant scope, use conditional revision updates, write an outbox record in the same transaction as the accepted state, and let consumers deduplicate by stable event identity. Add explicit handoff verification before advancing dependent stages. If an external effect cannot be rolled back, use a reviewed compensating action rather than rewriting research evidence.
Recover carefully: restore only on approved isolated staging with a verified backup and rollback point. Preserve original source snapshots and scientific lineage. After remediation, run the complete acceptance matrix and independently verify that the accepted result is unchanged across retries and sessions.
Verification
Pass requires an accepted-state readback, one and only one authoritative result per logical operation, no new accepted event on identical retry, a conflict on changed payload or stale revision, valid parent references, and zero unauthorized mutations or public disclosures. Include provenance and scientific/editorial review as separate gates.
9. Identify the distinct event and workflow services
| Inspected component | Owned responsibility | Boundary or limitation |
|---|---|---|
Workflow runs (/v1/workflow-runs) |
Stage transitions, run status, transition hashes, ledger records and webhook events | Rejects disallowed state changes; the inspected route does not establish a universal cross-service idempotency key |
Research orchestration (/v1/research/workflows) |
Declared stages, transitions, event timeline, provenance, handoffs, revisions and snapshots | Requires explicitly declared completion; Core does not autonomously execute specialist work |
Reliability (/v1/reliability) |
Connector work queue, leases, dead letters, replay and SSE stream | Replay creates a new work item; consumer-side duplicate prevention is still needed |
Cross-runtime workflow contract (/api/v1/cross-runtime-workflows)* |
DAG validation, typed handoffs, execution-event objects, fingerprints and readiness | Contract model only; execution and scheduler are owned by Workspace/hosts |
| Gateway and public API | Correlation IDs, proxy error context and public read scopes | Transport and observability do not prove authoritative write uniqueness |
*Use the precise route prefixes and method list from the pinned source before writing integration code. The cross-runtime routes expose contract validation rather than a live job scheduler.
10. Event identity is not workflow identity
Maintain distinct identifiers for the workflow definition, workflow run, step, logical operation, attempt, authoritative event, transport message and source/output artifact. A retry attempt is operational evidence but is not a second scientific result.
| Field in proposed evidence record | Purpose | Verification |
|---|---|---|
tenant_id / project_id / workflow_id |
Scope binding | Match trusted server-derived scope, not caller-supplied assertions |
idempotency_key / payload_sha256 |
Stable logical operation and request digest | One accepted result; different digest on existing key fails |
event_id / canonical_event_id |
Authoritative event versus replay attempt | Retries point to the original event |
parent_event_ids / sequence |
Causal dependencies and observation order | Parents exist and precede descendants |
actor_ref / source_refs |
Accountability and reproducibility | Rights, version and source identities independently checked |
publication_state |
Editorial access boundary | No automatic conversion from stored/delivered to public |
The table above is a recommended evidence contract used by the companion offline checker. It is not an assertion that these exact field names are present on Platform Core routes.
11. Implement an atomic acceptance boundary (proposed design)
For a service that owns the accepted state, use a transactionally unique operation key and bind the key to a hash of the canonicalized request. Never generate a new idempotency key on each retry of the same intent.
-- Illustration only: adapt to the actual owner schema and migration policy.
CREATE UNIQUE INDEX IF NOT EXISTS uq_authoritative_operation
ON authoritative_events (tenant_id, project_id, logical_operation_id);
-- In one transaction:
-- 1. Check trusted owner scope and expected_revision.
-- 2. Reserve logical_operation_id with canonical request_sha256.
-- 3. Apply exactly one authoritative state transition.
-- 4. Insert event / outbox intent and return the persisted receipt.
-- On duplicate key: compare request_sha256; return the stored receipt
-- if identical, else reject conflicting reuse. Never execute twice.
A unique index is necessary but insufficient unless the state change and event/outbox write share the same transaction. For multi-service effects, implement deduplicating consumers with durable inbox records and audited compensating procedures; a local transaction cannot make external networks atomic.
12. Causal ordering and temporal semantics
Order workflow steps using declared hard/data dependencies and signed/verified handoffs where required. Store timestamps in an unambiguous UTC format for diagnostics, but derive workflow causality from explicit parent IDs, expected revisions and dependency verification—not clock ordering. A stream sequence or SSE cursor is a delivery-order observation only.
# Proposed causal check; not an existing Platform Core method.
def parent_precedes_child(parent, child):
return (
parent["event_id"] in child["parent_event_ids"]
and parent["sequence"] < child["sequence"]
and parent["workflow_id"] == child["workflow_id"]
)
# Also verify parent accepted state, handoff evidence, and source hashes.
13. Inspected workflow transition semantics
The signature workflow service persists transitions, records a content hash and ledger entry, and emits a webhook event. It rejects starting a non-draft workflow (422), invalid step-status transitions (422) and starting a step before required predecessors complete (409). A completed or cancelled workflow cannot be transitioned again through the inspected run-state path.
The research workflow service exposes a separate apply_transition mechanism requiring declared_complete=true. The inspected function checks rejected/cancelled transitions but does not visibly short-circuit an already-applied transition before constructing another event. Check database constraints and staging behavior before claiming idempotency; do not use a repeated apply call as a harmless health probe.
14. Research workflow and snapshot provenance
Platform Core v2.90.0 maintains research workflow stages, handoffs, checkpoints, events, revisions, lineage and snapshots. Snapshot hashes preserve the recorded representation; an actual cross-product operation must be verified in the owner service. A declared handoff or completion is a record of claimed state, not proof that external computation occurred.
For a handoff from Workspace to Lab or Workbench, preserve the source artifact version, workflow run, step, input and output references, runtime adapter, schema and reviewed result. Do not advance publication state from the presence of an event alone.
15. Cross-runtime workflow readiness
The sc.core.cross-runtime-research-workflow.v1 model validates directed acyclic dependencies, runtime bindings, typed handoffs, event identities and verification fingerprints. A completed workflow requires a passed or warning-level verification object under its contract. This is a contract validation rule; scheduling, real execution and transport remain with Workspace or the relevant host.
For example, an R analysis result transferred to Julia may not unblock the Julia step until the declared handoff has verified its transfer and artifact references. A synthetic reference package illustrates this relationship but is not evidence that a remote job ran.
16. Event streams and cursor replay
The internal stream GET /v1/reliability/stream and scoped public stream GET /api/v1/reliability/stream accept after_id, event_type and once=true. The implementation also reads Last-Event-ID for resumable SSE delivery. Public stream events are filtered to records marked public and require a public API credential with data:read.
# Staging-only example; requires authorized staging access.
# Do not include private event data or real credentials in support tickets.
export SC_CORE_STAGING_URL="https://YOUR-APPROVED-STAGING-CORE"
curl --fail-with-body --silent --show-error "${SC_CORE_STAGING_URL}/v1/reliability/readiness"
# On a controlled fixture with approved credentials, SSE may be checked with:
# GET /v1/reliability/stream?after_id=0&once=true
# Reconnect with Last-Event-ID; verify duplicates are safely ignored.
Note: once=true yields a bounded snapshot, not a guarantee of all historical stream events; large streams may require subsequent cursor windows. The stream must not be treated as the canonical state store.
17. Queue leases, dead letters and replay
Queued connector work has a work-item ID, bounded attempts, lease owner/expiry, execution connector and ingestion-run ID. On expiration, a claimed item can return to pending. When attempts are exhausted, a dead-letter record is created. POST /v1/reliability/dead-letters/{dead_letter_id}/replay enqueues a new work item and retains replay metadata. Therefore two work-item IDs can legitimately represent the same originating intent; they must not automatically become two authoritative research events.
Before replay, inspect whether the original external operation actually completed; retain original dead-letter history. Replays should require operator authorization, idempotent downstream effects and an exact source/parameter compatibility check.
18. Actual inspection and control routes
| Actual route | Purpose | Safety guidance |
|---|---|---|
GET /v1/research/workflows/{workflow_id}/timeline |
Inspect declared research events and stages | Source-review access only; verify scope and public classification |
GET /v1/research/workflows/{workflow_id}/lineage |
Trace recorded dependencies | Do not confuse recorded lineage with verified external execution |
GET /v1/research/workflows/{workflow_id}/bundle |
Read workflow, events, revisions and snapshots | May include private material; no anonymous production probing |
GET /v1/workflow-runs/{run_id} |
Inspect signature workflow run and transitions | Compare accepted transition records |
GET /v1/reliability/queue |
Inspect work-item status | Do not infer authoritative research state |
GET /v1/reliability/dead-letters |
Inspect failed work before replay | Do not replay until original outcome resolved |
GET /api/v1/reliability/stream |
Public-scoped event stream | Only for explicitly public events with correct data:read scope |
POST /v1/research/workflows/{workflow_id}/transitions/{transition_key}/apply |
Apply a declared research transition | Write operation: not a diagnostic or safe retry probe |
Route names and handlers are source-reviewed, but their live exposure, upstream identity enforcement, database migrations and current deployment configuration are not verified here. Public /api/v1/research/workflows/... routes apply a top-level workflow visibility check; a separate payload-level privacy review is still required.
19. Error-to-action reference
| Observed condition | Meaning in inspected path | Safe next action |
|---|---|---|
401 internal write |
Invalid or missing Core write credential | Check authorized service credential outside logs; do not paste key |
403 or 404 public |
Missing public scope, unavailable or nonpublic object | Confirm identity and scope; do not disclose whether restricted object exists |
409 workflow step |
Earlier required steps incomplete | Retrieve blockers, reconcile evidence; do not bypass |
422 workflow step |
Invalid state transition or already closed | Read current run state; do not retry mutation |
422 research transition |
Missing declared_complete=true or invalid declaration |
Fix payload on isolated fixture after checking original commit |
503 research workflow |
Feature not enabled | Check staging feature gate and migrations |
dead_letter |
Queue attempts exhausted | Inspect original side effects and replay policy |
| SSE reconnect duplicate | Delivery may repeat after cursor reconnect | Deduplicate by durable event ID; check accepted state separately |
20. Reproducible offline evidence check
The accompanying evidence_checker.py is a local, synthetic checker for a proposed evidence packet (sc.kb.event-workflow-evidence.v1). It is not an import of Platform Core, not a live client, and does not certify production or scientific correctness.
cd sc-platform-core-event-workflow-provenance
python -m unittest -v test_evidence_checker.py
python evidence_checker.py synthetic-evidence.json
# Expected checker result:
# {"ok": true, "findings": [], "contract": "sc.kb.event-workflow-evidence.v1"}
# Both commands run offline; no credentials or network calls.
The tests intentionally mutate the synthetic fixture to detect duplicate accepted events, payload/key divergence, wrong project scope, missing source lineage, causal inversions, stale read-back, private publication, and missing negative-test receipts. They do not test database uniqueness or distributed transactions in Platform Core.
21. Staging acceptance matrix
| Test | Scenario | Acceptance condition |
|---|---|---|
EVP-01 |
First authorized transition | One accepted event and one persisted state update |
EVP-02 |
Same operation and digest retried | Same receipt; no additional accepted event |
EVP-03 |
Same key, changed payload digest | Conflict and unchanged accepted state |
EVP-04 |
Two concurrent identical requests | One authoritative commit under transactional uniqueness |
EVP-05 |
Stale expected revision | Reject and preserve current revision |
EVP-06 |
Unavailable parent event | Reject dependent transition |
EVP-07 |
Unverified hard/data handoff | Dependent stage remains blocked |
EVP-08 |
Worker lease expiry and reclaim | No duplicate authoritative result |
EVP-09 |
Original work completed, ack lost | Retry reuses outcome; no second scientific result |
EVP-10 |
Dead-letter replay | New work item linked to original, no automatic acceptance |
EVP-11 |
SSE replay from Last-Event-ID | No missed eligible events and consumer deduplicates |
EVP-12 |
Invalid workflow state transition | Expected typed error and no mutation |
EVP-13 |
Foreign tenant access | Denied with unchanged state and no object enumeration |
EVP-14 |
Revoked actor tries write | Denied and no authoritative event |
EVP-15 |
Public stream projection | No private IDs, secrets or restricted payload |
EVP-16 |
Approved external result handoff | Exact source, method, runtime and output hashes recorded |
EVP-17 |
Database fail before commit | No state or authoritative event committed |
EVP-18 |
Notification fails after state commit | Outbox retry sends notification without rewriting accepted state |
EVP-19 |
Fresh-session readback | Same accepted event IDs, project revision and state hash |
EVP-20 |
Rollback/restore drill | Restored state and audit/history match predeclared recovery point |
All 20 staging scenarios are not run in this guide. Execute using synthetic owner identities, disposable databases and approved staging workers; record actual request IDs, status codes, database counts, revisions and image digests. A single duplicate authoritative event is a release blocker.
22. Evidence and incident packet
A sanitized acceptance or incident packet should include repository commit and deployment image digest; schema/migration head; incident ID; exact project/workflow/operation IDs in pseudonymized form; actor role (not email or token); intended versus actual transitions; canonical request fingerprint; predecessor IDs; accepted event IDs and state hash; retry/lease/dead-letter history; trace IDs; tested disclosure boundaries; test timestamps; and the operator decision. Publish only a derivative suitable for its audience.
23. Change-control and rollback
- Pin the baseline build, database migration head and reversible feature flags.
- Reproduce on disposable PostgreSQL with synthetic runs and controlled concurrency.
- Verify a real off-host backup and an independent restore before altering event or workflow storage.
- Add idempotency/uniqueness changes in a migration that audits existing duplicates instead of silently discarding records.
- Enable guarded shadow comparison and monitor duplicate logical-operation counts, dead letters, outbox lag and wrong-tenant denials.
- Cut over only after independent approval; keep the rollback plan executable. Roll back the feature or traffic route, not immutable research evidence.
Do not treat a Core recovery checkpoint as a full backup. Readiness, backups and deployment signoff remain separate from scientific review.
24. Implementation assumptions and open gates
Confirmed in pinned source: workflow transitions and ledger/webhook entries; declared research workflow event/timeline/lineage/snapshot routes; SSE cursor support; queue leases and dead-letter replay; cross-runtime event-ID uniqueness within the validation package. Not established: a universal exactly-once distributed operation guarantee, tenant-scoped event enforcement across all routes, deployment-level transactional outbox behavior, current production migrations, or independent scientific validity. The acceptance matrix is the required evidence before claiming these stronger properties.
25. Technical references
- Workflow run transitions, ledger and webhook linkage —
backend/app/services/workflows.py - Signature workflow routes —
backend/app/routers/workflows.py - Research workflow events, transitions and snapshots —
backend/app/services/research_workflows.py - Research workflow routes and public projections —
backend/app/routers/research_workflows.py - Connector queue, leases and dead-letter replay —
backend/app/services/reliability.py - Event stream, replay, read and write routes —
backend/app/routers/reliability.py - Streaming and reliability boundaries —
docs/STREAMING_ALERTS_SOURCE_RELIABILITY_V290.md - Cross-runtime workflow contract and ownership —
docs/CROSS_RUNTIME_RESEARCH_WORKFLOW_V3_40_0.md - DAG, event identity and verification model —
backend/app/services/cross_runtime_research_workflow.py - Research workflow orchestration release note —
docs/RESEARCH_WORKFLOW_ORCHESTRATION_V2900.md - Public API scope and request ID middleware —
backend/app/public_api_auth.py - Recovery checkpoint versus actual backup —
docs/PRODUCTION_CERTIFICATION_MIGRATION_RECOVERY_V2170.md
Related reading: W3C PROV-O (provenance model); CloudEvents (event metadata); OpenTelemetry (distributed trace context). These are external technical references, not claims that Platform Core implements every standard.
