spec icon indicating copy to clipboard operation
spec copied to clipboard

Proposal: Add predicate `queued` to `taskRun` to indicate that task is planned to be started in future

Open BaLiKfromUA opened this issue 8 months ago • 12 comments

Hi folks!

I've been working with CDEvents, specifically "Core Events", and would like to propose extending taskRun predicates to have a queued predicate.

Some consumers want to know not only that a task has started or finished, but that it's been planned to start in the future.

The simplest use case is displaying upcoming tasks on a dashboard, so users see not just completed and in-progress work but also what's coming next. There are more involved infrastructure use cases as well.

Based on my experience with specification, I noticed that the only predicate that indicates something that would happen in the future is queued. Moreover, pipelineRun already has one, so it might make sense to add one to taskRun to have symmetric sets of predicates.

It also makes sense because the pipeline run can already be started, but some task takes lots of time/compute to complete, so other tasks are "queued," and event consumers are notified about it.

Similar to pipelineRun, we could say:

Adopters can choose to ignore these events if they don't apply to their use cases.

I've also noticed that testSuiteRun from "Testing Events" already has a queued predicate. Since a task could represent a test run, IIUC the specification, having this predicate for taskRun seems consistent.

Let me know what the community thinks about it!

P.S. I am happy to elaborate on my motivation via virtual catch-up according to the cdEvents calendar if needed. Just assumed that the proposal is small enough to discuss here :)

BaLiKfromUA avatar Apr 04 '26 17:04 BaLiKfromUA

@BaLiKfromUA, we spoke at the conference and came to the consensus that proposing a Scheduler mechanic could address this and extend to scheduling different types of tool-specific events. It should be noted that this would in no way supersede the queue event, which is where you are scheduling a pipeline run to be put into a queue. The action is not yet queued; it is scheduled to enter the queue in the future, with information about the scheduled action, the scheduler, and the timestamp for when it will be placed in the execution queue.

@davidB @xibz @afrittoli cc

sol-duara avatar May 19 '26 18:05 sol-duara

Just to avoid confusion, I think the scope of this discussion can be split into two topics:

  • Original: Add a queued predicate to taskRun to indicate that a task is waiting to run. This would address the current inconsistency, assuming everyone agrees that it is an inconsistency.
  • Additional: Add the concept of a Scheduler to the spec, along with an initial set of scheduler-related events.

Based on my conversation with Dadisi, the Scheduler concept would be more expressive for my system’s use case. I was not aware that there was interest in supporting such a concept in CDEvents, so I originally proposed the queued predicate with the idea that I would express scheduling intent through custom data. That approach would work, but it is not ideal for my use case.

P.S. I also realized that I did not explicitly state my commitment to this issue. I am happy to open PRs for the queued predicate, since that looks relatively straightforward.

I am also happy to help start the Scheduler work if the maintainers are interested. However, I would probably need some additional context first, especially if there have already been prior discussions on this topic.

BaLiKfromUA avatar May 20 '26 12:05 BaLiKfromUA

It is not immediate clear to me how this could work in CDEvents.

Clearly not everything can be scheduled. So how do ensure that we can enforce those constraints to particular resources? That seems more complicated than just adding queued?

Im open to hearing the design but I dont want to introduce something more complicated, so whatever abstraction we add needs to have clear benefits

xibz avatar May 24 '26 17:05 xibz

@xibz Sorry, I missed your reply in my inbox. Thank you for the feedback!

TL;DR: I don't think there's opposition to adding queued to taskRun, so I'll prepare that PR this week to unblock my use case (expressing the "scheduled" part via custom data for now). Separately, I'd love to keep the scheduled discussion going.

I agree a brand-new Scheduler abstraction would add complexity to the spec and to event-support validation. My initial idea was lighter: an optional scheduled predicate to address your concern about enforcing constraints, and we could add it to taskRun as the initial use case. That said, I get the sense @sol-duara has a different approach in mind, and I'm looking forward to hearing more about it.

To clarify why I think scheduled might be a good addition:

  1. IIUC, queued implies that some process (pipeline, task) is admitted and ready. And the only blocker to start execution is capacity or async communications between parts of the system. There is no indication of start time; the queued event will start ASAP.

  2. On the other side, I want to express a different idea: my system has a capacity to execute a given task, but there are some external time constraints to do it now. There are many examples: "baking" period between stages, market hours, code freeze/lockdown. So I schedule my task to run later.

  3. Ofc I could express the event from point 2 using custom data, but it would add ambiguity to the main part of the event. Additionally, I believe that having a separate predicate is beneficial for other cdEvents adopters because many financial companies do have restrictions for production changes during market hours or increased market volatility. But there are many more use cases outside of the financial domain.

P.S. It looks like @sol-duara and @xibz may have discussed this during the recent sync on June 30, but I couldn't find any minutes capturing the feedback. Would appreciate it if you could share them here, along with any relevant links.

BaLiKfromUA avatar Jul 07 '26 02:07 BaLiKfromUA

@BaLiKfromUA I think the conceptual distinction between queued and scheduled makes sense to me.

Where I’m still struggling is the consumer contract. A bare *.scheduled or some schedule.* tells me that something is intended to run later, but I’m not sure what a consumer can reliably do with that unless the event also standardizes some scheduling semantics.

For example, is the consumer suppose to know:

  • when the task is expected to start,
  • the earliest time it is allowed to start,
  • the scheduling window,
  • the reason it was deferred,
  • whether starting earlier would violate policy,
  • or whether failing to start by some time is meaningful?

Without that kind of contract, scheduled feels like it may just expose an internal implementation state. With that contract, I can see stronger use cases around upcoming-work visibility, policy validation, and detecting missed scheduled starts.

So maybe the question is not only whether scheduled is different from queued, but what minimum information a standard scheduled predicate would need to carry for consumers to act on it consistently. Note the plural. We want to ensure that any consumer downstream knows how to use the information provided by scheduled events.

xibz avatar Jul 07 '26 03:07 xibz

@BaLiKfromUA @xibz starting with the queued predicate makes sense, if there is general agreement on adding that predicate and it's a quick win. WRT to scheduled events, I think it's worth considering them, but I would like to better understand the use case for them. Maybe that topic can be covered in a separate issue?

afrittoli avatar Jul 07 '26 08:07 afrittoli

Apologies for the delay. I have the drafts on hackmd.io. I can open a PR now for the things or wait a beat to incorporate any changes for major concerns. But it lands in this place:

Proposed Vocabulary Addition: scheduledExecution

1. Summary

Adds the subject scheduledExecution: a registered intent to enqueue a target execution (a build, a deployment, a change window opening, etc.) at a future time. It captures the lifecycle before the existing .queued predicates, which today are the earliest representable moment ("accepted, waiting for a runner"). A scheduled execution exists from the moment it is registered until it is triggered, cancelled, or missed.

This subject standardizes the audit answers an operator needs about scheduled work: who scheduled it, whether and by whom it was changed, whether and by whom it was cancelled, and whether it actually fired (and when).


2. Rationale

The existing .queued predicates (build.queued, service.deploymentQueued, taskRun queued) represent work that has already been accepted into an execution queue. They cannot represent work registered now to be enqueued later, the pre-queued state. An operator running scheduled deployments has no standard way to observe the schedule's own lifecycle: the schedule is invisible until it materializes as a queued execution, at which point the "who/when/changed/cancelled" history is already lost.

scheduledExecution makes the schedule itself a first-class subject, so the registration, mutation, cancellation, and firing of scheduled work are observable occurrences. The triggered predicate is the hand-off point: it is what subsequently produces the existing .queued event for the target.

Identity stance

Every "who" attribute on this subject is an author reference, a consistent addressing key identifying who the producing system attributes the action to. CDEvents records attributed identity, not authenticated identity; the event does not prove the actor. Authentication is the producer's responsibility and is out of scope for the vocabulary.


sol-duara avatar Jul 07 '26 16:07 sol-duara

@sol-duara thanks, this helps clarify the shape of the proposal. scheduledExecution is conceptually different from queued, and modeling the schedule as a first class subject seems cleaner than adding a bare *.scheduled predicate to each execution type.

I do not think this fully answers the consumer-contract question yet.

For consumers to use this portably, I think the spec needs to define what a consumer can reliably infer from a scheduledExecution event. Is the consumer supposed to know the expected trigger/start time, the earliest allowed start time, a scheduling window, the reason the work was deferred, whether starting earlier would violate policy, or whether failing to start by some time is meaningful?

The proposed lifecycle of registered/changed/cancelled/triggered/missed is useful, but missed especially implies some deadline or expected trigger semantics. I think those semantics need to be explicit, otherwise consumers may interpret the same event differently.

I also think the handoff to the target execution needs to be clearly defined. If scheduledExecution.triggered later produces a *.queued event, what is the required correlation contract between the schedule and the queued execution?

I’m supportive of exploring this, but I think the next step should be defining the minimum portable contract for scheduledExecution, not just the lifecycle predicates. So if the hackmd.io proposal addresses this, then I think surfacing that, and perhaps in a new github issue would be a good next steps.

xibz avatar Jul 07 '26 16:07 xibz

@xibz I am not following your meaning of "consumer-contract". An event is a marker in time. This thing happens at "X" moment in time. If a consumer is consuming the event, wouldn't it already know "why" it was consuming the event? No event can infer how an organization consumes it; each comes with its own set of rules and concerns.

Are you saying that the project now dictates the use of the events or the events are a common expression of something a tool or process actually does?

sol-duara avatar Jul 07 '26 16:07 sol-duara

I did not say CDEvents should dictate how an organization consumes the event or what business rules it applies. So want to be explicit in that wasnt the intent.

By consumer contract, I mean the portable meaning a consumer can rely on when it sees a standard event. The consumer decides what to do with the event, but the spec should still define what the event means consistently across producers.

For example, if we define scheduledExecution.missed, then “missed” needs a standard meaning. Missed relative to what? An expected trigger time, a latest allowed trigger time, or a producer-specific deadline? Different organizations can react differently to that information, but the event itself should have a consistent meaning.

So I am not saying the project dictates usage. I am saying the project should define the common expression precisely enough that independent producers and consumers can interoperate and know exactly what is meant when any keyword is mentioned within cdevents.

xibz avatar Jul 07 '26 16:07 xibz

Just some quick feedback on the recent discussion. I will play around with current ideas more.

I received some draft notes from Dadisi regarding scheduled events. I am planning to write a separate, more detailed iteration of feedback once I get back to the office next week and have an opportunity to brainstorm content and semantics internally.

First of all, I agree with https://github.com/cdevents/spec/issues/305#issuecomment-4901757339 that it would be useful to create a separate issue to continue the Scheduler discussion there with summarized feedback so far, and maybe transfer some of the draft content from Dadisi's work to keep it in 1 place. @sol-duara will you have time to do it?

I agree with @xibz idea that "not everything can be scheduled" and it should be somehow restricted. Looking at the current draft, I see that target.type is meant to carry this information, but in the schema it's a free-form string rather than an enum — so the draft doesn't actually restrict what can be scheduled. I assume this will be refined; just flagging it

I also agree with the questions asked in https://github.com/cdevents/spec/issues/305#issuecomment-4899813482

Answering this from a consumer/use-case perspective could help to define more mature content for initial events. Based on my current domain experience, I fully agree that these questions must be answered in potential schedule created or modified events:

  • when the task is expected to start,
  • the earliest time it is allowed to start,
  • the scheduling window,
  • the reason it was deferred,

In addition, I also think that the semantics of events/consumer contract should be defined. One of the simple examples discussed back at cdCon is "what should a consumer do in case of multiple modified events? Rescheduling is a pretty common operation that could happen multiple times," but I didn't find the answer in the current draft (maybe I missed it).

Separately, I was initially confused about how consumers could understand which event to expect once the schedule got triggered.

But I see that draft actually links in both directions: triggeredExecution inside the triggered event (forward), and the trigger.type: schedule attribution in the downstream .queued or .started event (reverse). Both are currently optional, though.

In my opinion, at least one direction should be mandatory (most likely, the forward one). Otherwise, independent producers can't guarantee consumers a way to join the schedule to its execution.

That said, the current idea of reverse link in the subsequent event allows starting Scheduler work with a smaller scope first, e.g., only with created and modified events. This could work because missed and triggered events could be "reconstructed" by the consumer if there is enough information in initial scheduler events and a link to the schedule in non-scheduler events. However, missed is the harder one to reconstruct, since it requires the consumer to define their own deadline semantics.

I understand that it is not ideal, but it could give some benefits because the scope of the initial work is smaller. And later we can build on top of it.

BaLiKfromUA avatar Jul 09 '26 04:07 BaLiKfromUA

@xibz @afrittoli I created a small PR (https://github.com/cdevents/spec/pull/317) which should be hopefully straightforward to review.

Could you please trigger CI so I could check that I haven't missed anything obvious?

Thank you!

BaLiKfromUA avatar Jul 15 '26 15:07 BaLiKfromUA