Repository navigation
Description
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 4Harness 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
createContextanddeleteContextwith 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
createContextsucceeds, so a failed create never consumes a slot; or (b) make the counter a derived value from the current set ofsh:wl:<user>:<id>records whosestatus != deleted. - Consider returning a distinct error code when rollback fails (
502 context_service_error_quota_leakedvs502 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
evaline-ju commentedon Oct 26, 2026
#603 (merged) addresses the transient half:
rollbackCreatenow 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 reachesdeleted.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.feat(mocactl): add `workloads list` (rossoctl#552)
pdettori commentedon Nov 16, 2026
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'sDELETEretries it. Because the index behindworkloads listis the quota-unit set, a stuck slot is visible inmocactl workloads listand is reclaimed withmocactl workloads delete <id>.If automatic server-side reclaim is wanted, please open a separate issue.