Skip to content

feat(taskspawner): taskTemplate labels and annotations with template rendering#810

Open
aslakknutsen wants to merge 1 commit intokelos-dev:mainfrom
aslakknutsen:issue-1-task-template-labels
Open

feat(taskspawner): taskTemplate labels and annotations with template rendering#810
aslakknutsen wants to merge 1 commit intokelos-dev:mainfrom
aslakknutsen:issue-1-task-template-labels

Conversation

@aslakknutsen
Copy link
Contributor

@aslakknutsen aslakknutsen commented Mar 26, 2026

What type of PR is this?

/kind feature

What this PR does / why we need it:

Introduce spec.taskTemplate.labels and spec.taskTemplate.annotations on TaskSpawner. Each label and annotation value is expanded with source.RenderTemplate using the same work-item variables as branch and promptTemplate. Spawned Tasks still get kelos.dev/taskspawner; label values are fully rendered before applying metadata.

Annotation values are merged after rendering; GitHub source annotations are applied on top so reserved keys stay consistent.

Regenerate CRD and deepcopy. Add spawner unit tests for label and annotation rendering.

Which issue(s) this PR is related to:

N/A

Special notes for your reviewer:

Does this PR introduce a user-facing change?

You can now configure a TaskTemplate with `labels` and `annotations` expressions which will be available on the Task  

Summary by cubic

Add spec.taskTemplate.labels and spec.taskTemplate.annotations to TaskSpawner with template rendering from work items. Spawned Tasks always get the kelos.dev/taskspawner label; GitHub source annotations override conflicts.

  • New Features
    • Render label and annotation values via source.RenderTemplate using the same variables as branch and promptTemplate.
    • Always set kelos.dev/taskspawner to the TaskSpawner name (overrides any user value).
    • Merge rendered annotations, then apply GitHub source annotations last to preserve reserved keys.
    • Regenerated CRD and deepcopy; added unit tests; updated docs and example.

Written for commit b2a35bf. Summary will update on new commits.

…rendering

Introduce spec.taskTemplate.labels and spec.taskTemplate.annotations on
TaskSpawner. Each label and annotation value is expanded with
source.RenderTemplate using the same work-item variables as branch and
promptTemplate. Spawned Tasks still get kelos.dev/taskspawner; label
values are fully rendered before applying metadata.

Annotation values are merged after rendering; GitHub source annotations
are applied on top so reserved keys stay consistent.

Regenerate CRD and deepcopy. Add spawner unit tests for label and
annotation rendering.

Made-with: Cursor
Signed-off-by: Aslak Knutsen <aslak@4fs.no>
@aslakknutsen aslakknutsen force-pushed the issue-1-task-template-labels branch from e749d97 to b2a35bf Compare March 26, 2026 13:33
@CLAassistant
Copy link

CLAassistant commented Mar 26, 2026

CLA assistant check
All committers have signed the CLA.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 7 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="cmd/kelos-spawner/main_test.go">

<violation number="1" location="cmd/kelos-spawner/main_test.go:955">
P2: The new annotation-template test does not validate conflict precedence for reserved source annotations, so merge-order regressions could slip through.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment on lines +955 to +956
"example.com/issue": "{{.Number}}",
"example.com/note": "Issue-{{.Number}}",
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new annotation-template test does not validate conflict precedence for reserved source annotations, so merge-order regressions could slip through.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At cmd/kelos-spawner/main_test.go, line 955:

<comment>The new annotation-template test does not validate conflict precedence for reserved source annotations, so merge-order regressions could slip through.</comment>

<file context>
@@ -856,6 +912,83 @@ func TestRunCycleWithSource_BranchTemplateRendered(t *testing.T) {
+func TestRunCycleWithSource_AnnotationTemplateRendered(t *testing.T) {
+	ts := newTaskSpawner("spawner", "default", nil)
+	ts.Spec.TaskTemplate.Annotations = map[string]string{
+		"example.com/issue": "{{.Number}}",
+		"example.com/note":  "Issue-{{.Number}}",
+	}
</file context>
Suggested change
"example.com/issue": "{{.Number}}",
"example.com/note": "Issue-{{.Number}}",
reporting.AnnotationSourceKind: "user-overridden",
reporting.AnnotationSourceNumber: "999",
"example.com/issue": "{{.Number}}",
"example.com/note": "Issue-{{.Number}}",
Fix with Cubic

@gjkim42
Copy link
Collaborator

gjkim42 commented Mar 26, 2026

Thanks for the PR.
Before reviewing this, Why do we need this? What's the usage?

@aslakknutsen
Copy link
Contributor Author

@gjkim42 tldr; makes it quick to experiment with/prototype new features by exposing additional metadata on task level for other Controllers to read/react to, as appose to expanding the Spec surface for everything.

In my specific case I've built a set of features on top of Kelos;

  • Long term Task storage including activity logs
  • A Web UI with an opinionated idea around the Journey of an Issue, tracks the Agent "Personas" involved, how they routed the request and what they did. Live and historical
  • A agent wrapper with a custom agent protocol for things like human-in-the-loop, ci or retries on failure

The ability to add a little bit more metadata to the Task makes this richer and easier.

Screenshot From 2026-03-26 23-48-08 Screenshot From 2026-03-26 23-47-52 Screenshot From 2026-03-26 23-47-32 Screenshot From 2026-03-26 23-40-54 Screenshot From 2026-03-26 23-40-24 Screenshot From 2026-03-26 23-40-15

Copy link
Collaborator

@gjkim42 gjkim42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great

Can we add those in podOverrides.metadata.labels and annotations?

@aslakknutsen
Copy link
Contributor Author

aslakknutsen commented Mar 27, 2026

@gjkim42 The "Render" would still need to happen in the TaskSpawner; so the metadata could be found on Task.Spec.podOverrides.metadata.labels/annotations instead of Task.metadata.labels/annotations, correct? That should be just fine for my usecase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants