Skip to content

workloads create: failed rollback leaks per-user quota when Context Service is unavailable #601

Closed

Description

@evaline-ju

Summary

When mocactl workloads create fails because Context Service is unreachable, the harness logs show both createContext and the subsequent rollbackCreate → deleteContext failing with the same ContextServiceError: Context Service is unreachable: TypeError: fetch failed. The user-visible symptom is 502 context_service_error, but the lasting damage is that the per-user quota counter (sh:wl-quota:<user-hash> in Redis) stays incremented — leaking a slot that the user cannot recover with any mocactl command.

Reproduction

Reproduced against upstream main at c94ef27b, with a local kind deployment via deploy/k8s/setup.sh --target kind --build.

export SH_CONTROL_PLANE_URL=http://127.0.0.1:8090
export SH_HARNESS_URL=http://127.0.0.1:8080

# Clean baseline — all workloads deleted, quota counter = 0
mocactl workloads create --context /tmp/probe.context --json   # expect: ready
mocactl workloads delete <id>                                   # expect: deleted

# Scale Context Service to 0 to force the failure deterministically
kubectl -n context-service scale deploy/context-service --replicas=0
sleep 3

# Trigger the failure
mocactl workloads create --context /tmp/probe.context --json
# → the harness refused: 502 context_service_error

# Bring Context Service back
kubectl -n context-service scale deploy/context-service --replicas=1

# Count fresh successful creates — baseline is 5, we now only get 4

Harness logs during repro

workload create failed: ContextServiceError: Context Service is unreachable: TypeError: fetch failed
    at createContext (/app/packages/knative-server/src/context-service.ts:156:20)
    at createWorkload (/app/packages/knative-server/src/workloads.ts:385:21)

workload create rollback could not delete Context w-...: ContextServiceError: Context Service is unreachable: TypeError: fetch failed
    at deleteContext (/app/packages/knative-server/src/context-service.ts:179:3)
    at rollbackCreate (/app/packages/knative-server/src/workloads.ts:409:5)
    at createWorkload (/app/packages/knative-server/src/workloads.ts:395:5)

Direct Redis evidence

After one failed-create cycle, with every reachable workload deleted:

$ redis-cli get sh:wl-quota:239be512b174999aaa31cd04a2aaf3f0
3

Three slots consumed, zero workloads reachable to the user, no mocactl command to drop the counter.

Suggested fix

  • Retry createContext and deleteContext with short bounded backoff (e.g. 3 × 500ms) inside the harness before surfacing to the client. The transient blips we observed in historical logs would succeed on retry.
  • When the rollback also fails, do not leave the quota counter incremented. Either (a) increment only after createContext succeeds, so a failed create never consumes a slot; or (b) make the counter a derived value from the current set of sh:wl:<user>:<id> records whose status != deleted.
  • Consider returning a distinct error code when rollback fails (502 context_service_error_quota_leaked vs 502 context_service_error) so the operator knows the slot is lost until recovery.

Related

Independent of this bug, there is no mocactl workloads list today (tracked in #552), so a leaked slot is invisible to the operator until they count against the quota. Fixing the rollback (this issue) stops new leaks; #552 lets operators recover from any that have already happened.

Activity

  1. added
    bug
    on Oct 23, 2026
  2. evaline-ju commented on Oct 26, 2026

    @evaline-ju
    ContributorAuthor

    #603 (merged) addresses the transient half: rollbackCreate now retries its Context Service cleanup while Context Service is unreachable (default 3 × 500 ms, both tunable). A brief Context Service blip no longer leaks the slot — the rollback succeeds on a retry and the record reaches deleted.

    Still open: sustained outages past the retry budget leak as before, and the owner has no way to find the stuck id without mocactl workloads list (#552). The pair that fully closes this is #552 + either a longer retry budget or server-side reclaim; keeping this issue open for that until decided.

  3. pdettori commented on Nov 16, 2026

    @pdettori
    Member

    Fixed by #603 (bounded rollback retries, MOCA_CONTEXT_ROLLBACK_RETRY_ATTEMPTS / _BACKOFF_MS) and #675 (mocactl workloads list).

    A rollback that outlasts the retry budget now leaves the record in deleting, keeping its quota unit, and the owner's DELETE retries it. Because the index behind workloads list is the quota-unit set, a stuck slot is visible in mocactl workloads list and is reclaimed with mocactl workloads delete <id>.

    If automatic server-side reclaim is wanted, please open a separate issue.

  4. added this to the v0.11.0 milestone on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions