Description
remove() in pkg/unikontainers/utils.go removes an element from a slice by swapping it with the last element before truncating. This is an O(1) unordered removal. It is used in handleQueueProxy to remove SERVING_READINESS_PROBE from spec.Process.Env and in unikontainers.go to remove VACCEL_RPC_ADDRESS. The swap reorders the remaining elements, which is surprising behavior for any caller that expects stable ordering. Some processes depend on environment variable ordering, and the reordering can cause subtle breakage in queue-proxy integration where the env slice is serialized to spec.json.
Steps to reproduce
Add a test that calls remove and checks the resulting order:
go test ./pkg/unikontainers/ -v -run TestRemovePreservesOrder
The test calls remove([]string{"a", "b", "c", "d"}, 0) and asserts the result is ["b", "c", "d"]. Before the fix, the result is ["d", "b", "c"] and the assertion fails.
Expected behavior: remove() returns a slice with the target element removed and all other elements in their original order.
Current behavior: remove() swaps the target element with the last element before truncating, destroying the original ordering of remaining elements.
Proposed solution: Replace the swap-and-truncate implementation with an ordered removal that copies elements after the removed index one position forward.
Description
remove()inpkg/unikontainers/utils.goremoves an element from a slice by swapping it with the last element before truncating. This is an O(1) unordered removal. It is used inhandleQueueProxyto removeSERVING_READINESS_PROBEfromspec.Process.Envand inunikontainers.goto removeVACCEL_RPC_ADDRESS. The swap reorders the remaining elements, which is surprising behavior for any caller that expects stable ordering. Some processes depend on environment variable ordering, and the reordering can cause subtle breakage in queue-proxy integration where the env slice is serialized tospec.json.Steps to reproduce
Add a test that calls
removeand checks the resulting order:go test ./pkg/unikontainers/ -v -run TestRemovePreservesOrderThe test calls
remove([]string{"a", "b", "c", "d"}, 0)and asserts the result is["b", "c", "d"]. Before the fix, the result is["d", "b", "c"]and the assertion fails.Expected behavior:
remove()returns a slice with the target element removed and all other elements in their original order.Current behavior:
remove()swaps the target element with the last element before truncating, destroying the original ordering of remaining elements.Proposed solution: Replace the swap-and-truncate implementation with an ordered removal that copies elements after the removed index one position forward.