Skip to content

fix(backend): don't stamp rossoctl.io/type on Shipwright-finalized workloads (#2489) - #2507

Merged
mrsabath merged 4 commits into
mainfrom
fix/2489-deployment-label-403
Sep 1, 2026
Merged

mrsabath merged 4 commits into
mainfrom
fix/2489-deployment-label-403

Conversation

@mrsabath

@mrsabath mrsabath commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #2489 — importing an agent with Workload Type: Deployment succeeded at build time but silently created no Deployment, pod, or AgentRuntime. E2E on Kind uncovered two independent bugs on the Deployment finalize path; both are fixed here.

Bug 1 — rossoctl.io/type label 403 (the reported symptom)

finalize_shipwright_build re-applied all rossoctl.io/* labels from the Shipwright Build onto the raw workload, including rossoctl.io/type. The agent-label-protection ValidatingAdmissionPolicy only lets the operator SA set that label (via AgentRuntime reconciliation), so the create was rejected with 403.

Fix: new pure helper _carryover_workload_labels() (agents_manifests.py) carries every rossoctl.io/* label except rossoctl.io/type — mirroring _build_common_labels, which already omits it. Used in the Deployment / StatefulSet / Job branches of finalize_shipwright_build. The operator stamps rossoctl.io/type afterwards from the AgentRuntime CR. Sandbox and Service paths unchanged.

Bug 2 — AttributeError: contexts → 500 (found during E2E)

With bug 1 fixed, finalize still 500'd: finalize_shipwright_build reads request.contexts unconditionally, but the router-split refactor added the k8sResourceLimits/k8sResourceRequests mirror fields to FinalizeShipwrightBuildRequest and missed contexts. Every Deployment/StatefulSet/Job finalize raised AttributeError before any workload was created (and looped in the build reconciler).

Fix: mirror CreateAgentRequest.contexts on FinalizeShipwrightBuildRequest (Optional, default None).

UI — silent-failure UX

The build-progress auto-finalize useEffect re-fired on every poll tick after a finalize error (phase stays Succeeded), hammering the backend and preventing the error Alert from stabilizing — matching the issue's "build re-triggers, consuming resources." New shouldAutoFinalize() helper + a hasAutoFinalized latch make it fire at most once per build; the user re-runs via the existing Retry button. Applied to BuildProgressPage.tsx and ToolBuildProgressPage.tsx.

Testing

  • Backend: test_shipwright_finalize_labels.py (label-strip + contexts field regression); full suite 782 passed; ruff clean. (Pre-existing unrelated test_migration.py collection error not touched.)
  • UI: buildFinalize.test.ts (fire-once / no-retrigger); all 93 vitest pass; tsc -b + build pass; eslint clean.
  • Kind E2E (verified): agent imported as Workload Type Deployment finalizes cleanly. Backend log:
    Created ServiceAccount 'weather-deploy-test2'
    Created Deployment 'weather-deploy-test2' with image '...:v0.0.1'
    Created Service 'weather-deploy-test2'
    Created AgentRuntime 'weather-deploy-test2'
    Successfully finalized orphaned build 'team1/weather-deploy-test2'
    
    Result: Deployment 1/1, AgentRuntime type=agent READY, pod Running 1/1, no agent-label-protection 403, no AttributeError.

Assisted-By: Claude Code

…rkloads

Selecting Workload Type "Deployment" for an agent import made
finalize_shipwright_build create a raw Deployment carrying the
rossoctl.io/type label (copied from the Build's labels). The
agent-label-protection ValidatingAdmissionPolicy only lets the
rossoctl-operator set that label (via AgentRuntime reconciliation), so
the create was rejected with a 403 and no workload, pod, or AgentRuntime
was produced. The failure was silent in the UI.

Add _carryover_workload_labels(), which copies every rossoctl.io/* label
from the Build except rossoctl.io/type, and use it in the Deployment,
StatefulSet, and Job branches of finalize_shipwright_build. This mirrors
_build_common_labels, which already omits the label for the same reason.
The operator stamps rossoctl.io/type afterwards from the AgentRuntime CR
that finalize creates, so the running workload ends up correctly
labeled. The Sandbox and Service paths are unchanged (a Sandbox is an
operator-owned CR the policy does not match; the Service is not covered).

Also fix the silent-failure UX: the build-progress auto-finalize effect
re-fired on every poll tick after a finalize error (the phase stays
"Succeeded"), hammering the backend and preventing the error Alert from
stabilizing. Gate it behind a hasAutoFinalized latch (shouldAutoFinalize
helper) so it fires at most once per build; the user re-runs finalize
via the existing Retry button. Applied to both the agent and tool
build-progress pages.

Fixes #2489

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>
…quest

finalize_shipwright_build reads request.contexts unconditionally, but the
router-split refactor added the k8sResourceLimits/k8sResourceRequests
mirror fields to FinalizeShipwrightBuildRequest and missed contexts. Every
Deployment/StatefulSet/Job finalize therefore raised

  AttributeError: 'FinalizeShipwrightBuildRequest' object has no attribute 'contexts'

before any workload was created, returning 500 (and looping in the build
reconciler). This blocked the Deployment import path independently of the
rossoctl.io/type label 403 -- both had to be fixed for #2489.

Mirror CreateAgentRequest.contexts on the finalize model (Optional, default
None) so the access is valid and the stored-config fallback applies.

Verified on Kind: with both fixes, an agent imported as Workload Type
"Deployment" finalizes cleanly -- Deployment, Service, and AgentRuntime are
created, the operator stamps rossoctl.io/type=agent, and the pod runs 1/1.

Refs #2489

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>
CI lint (ruff 0.15.12) collapses the dict comprehension in the new
_carryover_workload_labels helper onto a single line. Whitespace only;
no behavior change. Fixes the failing lint (3.11)/(3.12) checks on #2507.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>
@mrsabath
mrsabath marked this pull request as ready for review August 31, 2026 22:25

@esnible esnible left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Summary

Fixes two independent, verified bugs blocking the Deployment/StatefulSet/Job finalize path (#2489): a 403 from carrying rossoctl.io/type onto raw workloads (violates the agent-label-protection admission policy), and a missing contexts field on FinalizeShipwrightBuildRequest causing an AttributeError → 500. Also fixes a UI retrigger loop where auto-finalize hammered the backend after a finalize error. Both backend claims were independently verified against origin/main (the label-omission pattern already used in _build_common_labels, and the unconditional request.contexts access in finalize_shipwright_build) and hold up. New tests cover the regression on both backend (pytest) and frontend (vitest).

Author: mrsabath (MEMBER — maintainer)
Areas reviewed: Python (backend routers/models/tests), Frontend (TSX pages, new util + test)
Agent/IDE config (.claude/.vscode): none
Commits: 4 commits (3 substantive + 1 merge), all substantive commits signed-off: yes
CI status: passing (E2E HyperShift and Deploy & Test are pending manual /run-e2e trigger — not blocking; all required checks green)

No blocking issues. Clean, well-scoped fix with good regression coverage.

@mrsabath
mrsabath merged commit df87a6f into main Sep 1, 2026
24 of 25 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Sep 1, 2026
@mrsabath
mrsabath deleted the fix/2489-deployment-label-403 branch September 1, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Agent import with Workload Type 'Deployment' fails: 403 from agent-label-protection policy, no workload created

3 participants